~ubuntu-branches/ubuntu/warty/xmedcon/warty

« back to all changes in this revision

Viewing changes to source/ximages.c

  • Committer: Bazaar Package Importer
  • Author(s): Roland Marcus Rutschmann
  • Date: 2004-06-07 09:00:14 UTC
  • Revision ID: james.westby@ubuntu.com-20040607090014-t39n52qc9zjqqqkh
Tags: upstream-0.9.6
ImportĀ upstreamĀ versionĀ 0.9.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 
2
 * filename: ximages.c                                                     *
 
3
 *                                                                         *
 
4
 * UTIL C-source: Medical Image Conversion Utility                         *
 
5
 *                                                                         *
 
6
 * purpose      : image routines                                           *
 
7
 *                                                                         *
 
8
 * project      : (X)MedCon by Erik Nolf                                   *
 
9
 *                                                                         *
 
10
 * Functions    : XMdcRemovePreviousImages()   - Remove old X images       *
 
11
 *                XMdcImagesSetCursor()        - Set cursor over X images  *
 
12
 *                XMdcImagesCallbackExpose()   - Images Expose  callback   *
 
13
 *                XMdcImagesCallbackClicked()  - Images Clicked callback   *
 
14
 *                XMdcBuildCurrentImages()     - Build images for display  *
 
15
 *                XMdcDisplayImages()          - Display the images        *
 
16
 *                XMdcImagesView()             - Show the images (viewer)  *
 
17
 *                                                                         *
 
18
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
19
/* $Id: ximages.c,v 1.17 2004/05/09 22:48:04 enlf Exp $
 
20
 */
 
21
 
 
22
/*
 
23
   Copyright (C) 1997-2004 by Erik Nolf
 
24
 
 
25
   This program is free software; you can redistribute it and/or modify it
 
26
   under the terms of the GNU General Public License as published by the
 
27
   Free Software Foundation; either version 2, or (at your option) any later
 
28
   version.
 
29
 
 
30
   This program is distributed in the hope that it will be useful, but
 
31
   WITHOUT ANY WARRANTY; without even the implied warranty of
 
32
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
 
33
   Public License for more details.
 
34
 
 
35
   You should have received a copy of the GNU General Public License along
 
36
   with this program; if not, write to the Free Software Foundation, Inc.,
 
37
   59 Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
38
 
 
39
/****************************************************************************
 
40
                              H E A D E R S
 
41
****************************************************************************/
 
42
 
 
43
#include <stdio.h>
 
44
 
 
45
#include "xmedcon.h"
 
46
 
 
47
/****************************************************************************
 
48
                            F U N C T I O N S
 
49
****************************************************************************/
 
50
 
 
51
#ifdef MDC_USE_SIGNAL_BLOCKER
 
52
/* 
 
53
 * MARK: dirty fix of bad button-press-event behaviour in _WIN32
 
54
 *
 
55
 * The button-press-events of our image's drawing areas seems to be
 
56
 * "propagated" over all our widgets ... We got for example zoom or info
 
57
 * windows by clicking on places we wouldn't expect this to happen.
 
58
 *
 
59
 * So we 're blocking this button-press-event whenever we leave the 
 
60
 * corresponding drawing area (and ofcourse, reallowing when entering)
 
61
 *
 
62
 * However, the gtk_signal_handler_block() function increments a number
 
63
 * instead of using a simple boolean. Whenever the "enter_notify_event"
 
64
 * is missed ... this number will never drop to zero again. And it does
 
65
 * happen when widgets come in front of our drawing areas which are rebuild
 
66
 * because of a color correction or colormap change.
 
67
 *
 
68
 * Our SignalBlocker struct should prevent the gtk_signal_handler_block()
 
69
 * function being called several times ...
 
70
 *
 
71
 * Actual struct defined in xdefs.h: 
 
72
typedef struct SignalBlocker_t{
 
73
 
 
74
  guint id;
 
75
  gboolean blocked;
 
76
 
 
77
}SignalBlocker;
 
78
 *
 
79
 */
 
80
 
 
81
static gboolean XMdcSignalBlock(GtkWidget *widget, gpointer data)
 
82
{
 
83
  SignalBlocker *signal;
 
84
 
 
85
  signal = (SignalBlocker *)gtk_object_get_data(GTK_OBJECT(widget),"signal");
 
86
 
 
87
  if (!signal->blocked) {
 
88
    gtk_signal_handler_block(GTK_OBJECT(widget),signal->id);
 
89
    signal->blocked = TRUE;
 
90
  }
 
91
 
 
92
  return(TRUE);
 
93
 
 
94
}
 
95
 
 
96
static gboolean XMdcSignalUnblock(GtkWidget *widget, gpointer data)
 
97
{
 
98
  SignalBlocker *signal;
 
99
 
 
100
  signal = (SignalBlocker *)gtk_object_get_data(GTK_OBJECT(widget),"signal");
 
101
 
 
102
  if (signal->blocked) {
 
103
    gtk_signal_handler_unblock(GTK_OBJECT(widget),signal->id);
 
104
    signal->blocked = FALSE;
 
105
  }
 
106
 
 
107
  return(TRUE);
 
108
 
 
109
}
 
110
#endif
 
111
 
 
112
void XMdcRemovePreviousImages(void)
 
113
{
 
114
  Uint32 i;
 
115
 
 
116
  for (i=0; i<my.real_images_on_page; i++) {
 
117
     gtk_widget_hide(my.image[i]);
 
118
     gdk_pixbuf_unref(my.im[i]); my.im[i] = NULL;
 
119
  }
 
120
}
 
121
 
 
122
void XMdcImagesSetCursor(GtkWidget *widget, gpointer data)
 
123
{
 
124
  if (widget->window != NULL) 
 
125
    gdk_window_set_cursor (widget->window, handcursor);
 
126
}
 
127
 
 
128
 
 
129
gboolean XMdcImagesCallbackExpose(GtkWidget *widget, GdkEventExpose *event, Uint32 *nr)
 
130
{
 
131
  GdkGC *gc = widget->style->white_gc;
 
132
  Uint32 i = (Uint32)(*nr);
 
133
  gint ex, ey, ew, eh, iw, ih, rw, rh;
 
134
 
 
135
  if ( my.im[i] == NULL ) return(TRUE);
 
136
 
 
137
  /* repaint the polluted drawable */
 
138
  iw = gdk_pixbuf_get_width(my.im[i]);
 
139
  ih = gdk_pixbuf_get_height(my.im[i]);
 
140
 
 
141
  ex = event->area.x;     ey = event->area.y;
 
142
  ew = event->area.width; eh = event->area.height;
 
143
 
 
144
  if ((ex < iw) && (ey < ih)) {
 
145
    rw = iw - ex; rh = ih - ey;
 
146
    gdk_pixbuf_render_to_drawable(my.im[i], widget->window, gc,
 
147
                                  ex, ey, ex, ey, rw, rh,
 
148
                                  sRenderSelection.Dither, 0, 0);
 
149
  }
 
150
 
 
151
  if ((ex + ew) > iw) {
 
152
    rw = (ex + ew) - iw; rh = eh;
 
153
    gdk_window_clear_area(widget->window, iw, ey, rw, rh); 
 
154
 
 
155
  }
 
156
  if ((ey + eh) > ih) {
 
157
    rh = (ey + eh) - ih; rw = ew;
 
158
    gdk_window_clear_area(widget->window, ex, ih, rw, rh);
 
159
  } 
 
160
 
 
161
  if (sLabelSelection.CurState == MDC_YES) {
 
162
    XMdcPrintImageLabelIndex(widget,i);
 
163
    XMdcPrintImageLabelTimes(widget,i);
 
164
  }
 
165
 
 
166
  return(TRUE);
 
167
}
 
168
 
 
169
gboolean XMdcImagesCallbackClicked(GtkWidget *widget, GdkEventButton *button, Uint32 *nr) 
 
170
{
 
171
 
 
172
  if (button->button == 1) {
 
173
    /* zoom the image */
 
174
    XMdcImagesZoom(widget,(Uint32)(*nr));
 
175
  }
 
176
 
 
177
  if (button->button == 2) {
 
178
    /* print image info */
 
179
    XMdcImagesInfo(widget,(Uint32)(*nr));
 
180
  } 
 
181
 
 
182
  if (button->button == 3) {
 
183
    /* color correction */
 
184
    XMdcColGbcCorrectSel(widget,(Uint32)(*nr));
 
185
  }
 
186
 
 
187
  return(TRUE);
 
188
 
 
189
}
 
190
 
 
191
void XMdcBuildCurrentImages(void)
 
192
{
 
193
  Uint32 i, r, c, ri;
 
194
  Uint32 real_images;
 
195
  float progress;
 
196
 
 
197
  MdcDebugPrint("Building current images ...");
 
198
 
 
199
  real_images = XMdcPagesGetNrImages();
 
200
 
 
201
  /* get real_images_per_page and number of the beginning image */
 
202
  if (real_images < my.images_per_page) {
 
203
    /* always lesser images on page */
 
204
    my.real_images_on_page = real_images;
 
205
    my.startimage = my.curpage * real_images;
 
206
  }else{
 
207
    if (my.curpage == my.number_of_pages - 1) {
 
208
      /* last page, probably less images on it */
 
209
      my.real_images_on_page = my.fi->number - (my.curpage*my.images_per_page);
 
210
      my.startimage = my.curpage * my.images_per_page;
 
211
    }else{
 
212
      /* other pages completely filled out */
 
213
      my.real_images_on_page = my.images_per_page;
 
214
      my.startimage = my.curpage * my.images_per_page;
 
215
    }
 
216
  }
 
217
 
 
218
  progress = 1./(float)(my.real_images_on_page + 1);
 
219
 
 
220
  /* build the images */
 
221
  i = my.startimage; ri=0;
 
222
  for (r=0; r<my.images_vertical; r++)  
 
223
  for (c=0; c<my.images_horizontal; c++,i++, ri++) {
 
224
 
 
225
#ifdef MDC_USE_SIGNAL_BLOCKER
 
226
     SignalBlocker *signal = (SignalBlocker *)&my.sblkr[ri];
 
227
#endif
 
228
 
 
229
     progress += 1./(float)(my.real_images_on_page + 1);
 
230
 
 
231
     if (ri == my.real_images_on_page) break; /* get OUT, got all images */
 
232
 
 
233
     my.realnumber[ri] = i;
 
234
 
 
235
     my.im[ri] = XMdcBuildGdkPixbufFI(my.fi,i,sGbc.mod.vgbc,MDC_YES);
 
236
 
 
237
     if (my.image[ri] == NULL) {
 
238
 
 
239
       my.image[ri] = gtk_drawing_area_new();
 
240
 
 
241
       gtk_drawing_area_size(GTK_DRAWING_AREA(my.image[ri])
 
242
           ,(gint)(XMdcResize(my.fi->mwidth)  + XMDC_IMAGE_BORDER)
 
243
           ,(gint)(XMdcResize(my.fi->mheight) + XMDC_IMAGE_BORDER));
 
244
 
 
245
       gtk_widget_set_events (my.image[ri], GDK_EXPOSURE_MASK
 
246
                                          | GDK_BUTTON_PRESS_MASK
 
247
#ifdef MDC_USE_SIGNAL_BLOCKER 
 
248
                                          | GDK_ENTER_NOTIFY_MASK
 
249
                                          | GDK_LEAVE_NOTIFY_MASK 
 
250
#endif
 
251
                                          );
 
252
 
 
253
       gtk_table_attach(GTK_TABLE(my.imgstable),my.image[ri],c,c+1,r,r+1,
 
254
                        GTK_FILL,GTK_FILL, 0, 0);
 
255
 
 
256
#ifdef MDC_USE_SIGNAL_BLOCKER
 
257
       signal->id =
 
258
#endif
 
259
       gtk_signal_connect (GTK_OBJECT(my.image[ri]), "button_press_event",
 
260
                           GTK_SIGNAL_FUNC(XMdcImagesCallbackClicked),
 
261
                           (Uint32 *)&my.imagenumber[ri]);
 
262
       
 
263
       gtk_signal_connect (GTK_OBJECT(my.image[ri]),"expose_event",
 
264
                           GTK_SIGNAL_FUNC(XMdcImagesCallbackExpose),
 
265
                           (Uint32 *)&my.imagenumber[ri]);
 
266
 
 
267
#ifdef MDC_USE_SIGNAL_BLOCKER
 
268
       gtk_signal_connect (GTK_OBJECT(my.image[ri]),"enter_notify_event",
 
269
                           GTK_SIGNAL_FUNC(XMdcSignalUnblock), NULL);
 
270
 
 
271
       gtk_signal_connect (GTK_OBJECT(my.image[ri]),"leave_notify_event",
 
272
                           GTK_SIGNAL_FUNC(XMdcSignalBlock), NULL);
 
273
 
 
274
       gtk_object_set_data(GTK_OBJECT(my.image[ri]),"signal",signal);
 
275
 
 
276
       XMdcSignalBlock(my.image[ri],NULL);
 
277
#endif
 
278
 
 
279
       XMdcImagesSetCursor(my.image[ri],NULL);
 
280
 
 
281
     }
 
282
 
 
283
     gtk_widget_show(my.image[ri]);
 
284
 
 
285
 
 
286
     if (GTK_WIDGET_VISIBLE(my.viewwindow)) {
 
287
       if (my.images_horizontal < 10) {
 
288
         /* update after each two rows */
 
289
         if (((ri+1)%(my.images_horizontal*2)) == 0)
 
290
           XMdcProgressBar(MDC_PROGRESS_SET,progress,NULL);
 
291
       }else{
 
292
         /* update after each five rows */
 
293
         if (((ri+1)%(my.images_horizontal*5)) == 0)
 
294
           XMdcProgressBar(MDC_PROGRESS_SET,progress,NULL);
 
295
       }
 
296
     }else{
 
297
       /* update after each image */
 
298
        XMdcProgressBar(MDC_PROGRESS_SET,progress,NULL);
 
299
     }
 
300
  } 
 
301
}
 
302
 
 
303
void XMdcDisplayImages(void)
 
304
{
 
305
  XMdcProgressBar(MDC_PROGRESS_BEGIN,0.,"Preparing Viewer:");
 
306
  XMdcGetBoardDimensions();
 
307
  XMdcHandleBoardDimensions();
 
308
  XMdcBuildViewerWindow();
 
309
  XMdcBuildColorMap();
 
310
  XMdcBuildCurrentImages();
 
311
  XMdcResizeNeeded();
 
312
  gtk_container_foreach(GTK_CONTAINER(my.imgstable),
 
313
                          (GtkCallback)XMdcImagesSetCursor,NULL);
 
314
}
 
315
 
 
316
void XMdcImagesView(GtkWidget *widget, gpointer data)
 
317
{
 
318
  if (XMdcNoFileOpened()) return;
 
319
  XMdcViewerShow();
 
320
}
 
321