comparison gtk/dw.c @ 773:d57561c34c3a

Add dw_scrollbox_get_pos() and dw_scrollbox_get_range() Change font for groupbox to default to bold font Enable dw_window_set_bitmap() to work with bitmap buttons (allows changing icon on a button) Some checks for NULL pointers before freeing
author mhessling@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 19 Mar 2011 01:19:59 +0000
parents f25ed69adb47
children 19a632499344
comparison
equal deleted inserted replaced
772:b28ec71cfc88 773:d57561c34c3a
2391 char **xpm_data = NULL; 2391 char **xpm_data = NULL;
2392 int x, y, extra_width=0,text_width,text_height; 2392 int x, y, extra_width=0,text_width,text_height;
2393 int width,height; 2393 int width,height;
2394 2394
2395 va_start(args, format); 2395 va_start(args, format);
2396 vsprintf(outbuf, format, args); 2396 vsnprintf(outbuf, 999, format, args);
2397 va_end(args); 2397 va_end(args);
2398 2398
2399 entrywindow = dw_window_new(HWND_DESKTOP, title, flStyle); 2399 entrywindow = dw_window_new(HWND_DESKTOP, title, flStyle);
2400 mainbox = dw_box_new(DW_VERT, 10); 2400 mainbox = dw_box_new(DW_VERT, 10);
2401 dw_box_pack_start(entrywindow, mainbox, 0, 0, TRUE, TRUE, 0); 2401 dw_box_pack_start(entrywindow, mainbox, 0, 0, TRUE, TRUE, 0);
3219 gtk_widget_show(tmp); 3219 gtk_widget_show(tmp);
3220 DW_MUTEX_UNLOCK; 3220 DW_MUTEX_UNLOCK;
3221 return tmp; 3221 return tmp;
3222 } 3222 }
3223 3223
3224 #ifdef INCOMPLETE 3224 #ifndef INCOMPLETE
3225 /* 3225 /*
3226 * Create a new scrollable Box to be packed. 3226 * Create a new scrollable Box to be packed.
3227 * Parameters: 3227 * Parameters:
3228 * type: Either DW_VERT (vertical) or DW_HORZ (horizontal). 3228 * type: Either DW_VERT (vertical) or DW_HORZ (horizontal).
3229 * pad: Number of pixels to pad around the box. 3229 * pad: Number of pixels to pad around the box.
3253 gtk_widget_show(tmp); 3253 gtk_widget_show(tmp);
3254 3254
3255 DW_MUTEX_UNLOCK; 3255 DW_MUTEX_UNLOCK;
3256 return tmp; 3256 return tmp;
3257 } 3257 }
3258
3259 /*
3260 * Returns the position of the scrollbar in the scrollbox
3261 * Parameters:
3262 * handle: Handle to the scrollbox to be queried.
3263 * orient: The vertical or horizontal scrollbar.
3264 */
3265 int dw_scrollbox_get_pos(HWND handle, int orient)
3266 {
3267 int val = -1, _locked_by_me = FALSE;
3268 GtkAdjustment *adjustment;
3269
3270 if (!handle)
3271 return -1;
3272
3273 DW_MUTEX_LOCK;
3274 if ( orient == DW_HORZ )
3275 adjustment = gtk_scrolled_window_get_hadjustment( handle );
3276 else
3277 adjustment = gtk_scrolled_window_get_vadjustment( handle );
3278 if (adjustment)
3279 val = _round_value(adjustment->value);
3280 DW_MUTEX_UNLOCK;
3281 return val;
3282 }
3283
3284 /*
3285 * Gets the range for the scrollbar in the scrollbox.
3286 * Parameters:
3287 * handle: Handle to the scrollbox to be queried.
3288 * orient: The vertical or horizontal scrollbar.
3289 */
3290 int API dw_scrollbox_get_range(HWND handle, int orient)
3291 {
3292 int range = -1, _locked_by_me = FALSE;
3293 GtkAdjustment *adjustment;
3294
3295 if (!handle)
3296 return -1;
3297
3298 DW_MUTEX_LOCK;
3299 if ( orient == DW_HORZ )
3300 adjustment = gtk_scrolled_window_get_hadjustment( handle );
3301 else
3302 adjustment = gtk_scrolled_window_get_vadjustment( handle );
3303 if (adjustment)
3304 {
3305 range = _round_value(adjustment->upper);
3306 }
3307 DW_MUTEX_UNLOCK;
3308 return range;
3309 }
3258 #endif 3310 #endif
3259 3311
3260 /* 3312 /*
3261 * Create a new Group Box to be packed. 3313 * Create a new Group Box to be packed.
3262 * Parameters: 3314 * Parameters:
3264 * pad: Number of pixels to pad around the box. 3316 * pad: Number of pixels to pad around the box.
3265 * title: Text to be displayined in the group outline. 3317 * title: Text to be displayined in the group outline.
3266 */ 3318 */
3267 HWND dw_groupbox_new(int type, int pad, char *title) 3319 HWND dw_groupbox_new(int type, int pad, char *title)
3268 { 3320 {
3269 GtkWidget *tmp, *frame; 3321 GtkWidget *tmp, *frame, *label;
3322 PangoFontDescription *pfont;
3323 PangoContext *pcontext;
3270 int _locked_by_me = FALSE; 3324 int _locked_by_me = FALSE;
3271 3325
3272 DW_MUTEX_LOCK; 3326 DW_MUTEX_LOCK;
3273 frame = gtk_frame_new(NULL); 3327 frame = gtk_frame_new(NULL);
3274 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN); 3328 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN);
3275 gtk_frame_set_label(GTK_FRAME(frame), title && *title ? title : NULL); 3329 gtk_frame_set_label(GTK_FRAME(frame), title && *title ? title : NULL);
3330 /*
3331 * Get the current font for the frame's label and make it bold
3332 */
3333 label = gtk_frame_get_label_widget(GTK_FRAME(frame));
3334 pcontext = gtk_widget_get_pango_context( label );
3335 if ( pcontext )
3336 {
3337 pfont = pango_context_get_font_description( pcontext );
3338 if ( pfont )
3339 {
3340 pango_font_description_set_weight( pfont, PANGO_WEIGHT_BOLD );
3341 gtk_widget_modify_font( label, pfont );
3342 }
3343 }
3344
3276 tmp = gtk_table_new(1, 1, FALSE); 3345 tmp = gtk_table_new(1, 1, FALSE);
3277 gtk_container_border_width(GTK_CONTAINER(tmp), pad); 3346 gtk_container_border_width(GTK_CONTAINER(tmp), pad);
3278 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_boxtype", GINT_TO_POINTER(type)); 3347 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_boxtype", GINT_TO_POINTER(type));
3279 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_boxpad", GINT_TO_POINTER(pad)); 3348 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_boxpad", GINT_TO_POINTER(pad));
3280 gtk_object_set_data(GTK_OBJECT(frame), "_dw_boxhandle", (gpointer)tmp); 3349 gtk_object_set_data(GTK_OBJECT(frame), "_dw_boxhandle", (gpointer)tmp);
3281 gtk_container_add(GTK_CONTAINER(frame), tmp); 3350 gtk_container_add(GTK_CONTAINER(frame), tmp);
3282 gtk_widget_show(tmp); 3351 gtk_widget_show(tmp);
3283 gtk_widget_show(frame); 3352 gtk_widget_show(frame);
3284 DW_MUTEX_UNLOCK; 3353 DW_MUTEX_UNLOCK;
3285 return frame; 3354 return frame;
3355
3286 } 3356 }
3287 3357
3288 /* 3358 /*
3289 * Create a new MDI Frame to be packed. 3359 * Create a new MDI Frame to be packed.
3290 * Parameters: 3360 * Parameters:
4415 #else 4485 #else
4416 tmp = gdk_pixmap_create_from_xpm(handle->window, &bitmap, &_colors[DW_CLR_PALEGRAY], file); 4486 tmp = gdk_pixmap_create_from_xpm(handle->window, &bitmap, &_colors[DW_CLR_PALEGRAY], file);
4417 #endif 4487 #endif
4418 } 4488 }
4419 4489
4420 if(tmp) 4490 if (tmp)
4421 { 4491 {
4492 if ( GTK_IS_BUTTON(handle) )
4493 {
4494 #if GTK_MAJOR_VERSION < 2
4495 GtkWidget *pixmap = GTK_BUTTON(handle)->child;
4496 gtk_pixmap_set(GTK_PIXMAP(pixmap), tmp, bitmap);
4497 #else
4498 GtkWidget *pixmap = gtk_button_get_image( GTK_BUTTON(handle) );
4499 gtk_image_set_from_pixmap(GTK_IMAGE(pixmap), tmp, bitmap);
4500 #endif
4501 }
4502 else
4503 {
4422 #if GTK_MAJOR_VERSION > 1 4504 #if GTK_MAJOR_VERSION > 1
4423 gtk_image_set_from_pixmap(GTK_IMAGE(handle), tmp, bitmap); 4505 gtk_image_set_from_pixmap(GTK_IMAGE(handle), tmp, bitmap);
4424 #else 4506 #else
4425 gtk_pixmap_set(GTK_PIXMAP(handle), tmp, bitmap); 4507 gtk_pixmap_set(GTK_PIXMAP(handle), tmp, bitmap);
4426 #endif 4508 #endif
4509 }
4427 } 4510 }
4428 DW_MUTEX_UNLOCK; 4511 DW_MUTEX_UNLOCK;
4429 } 4512 }
4430 4513
4431 /* 4514 /*
6340 memcpy(&newtitles[1], titles, sizeof(char *) * count); 6423 memcpy(&newtitles[1], titles, sizeof(char *) * count);
6341 memcpy(&newflags[1], flags, sizeof(unsigned long) * count); 6424 memcpy(&newflags[1], flags, sizeof(unsigned long) * count);
6342 6425
6343 _dw_container_setup(handle, newflags, newtitles, count + 1, 1, 1); 6426 _dw_container_setup(handle, newflags, newtitles, count + 1, 1, 1);
6344 6427
6345 free(newtitles); 6428 if ( newtitles) free(newtitles);
6346 free(newflags); 6429 if ( newflags ) free(newflags);
6347 return TRUE; 6430 return TRUE;
6348 } 6431 }
6349 6432
6350 /* 6433 /*
6351 * Obtains an icon from a module (or header in GTK). 6434 * Obtains an icon from a module (or header in GTK).
8097 if ( gc ) 8180 if ( gc )
8098 { 8181 {
8099 /* 8182 /*
8100 * If we have a bitmap (mask) in the source pixmap, then set the clipping region 8183 * If we have a bitmap (mask) in the source pixmap, then set the clipping region
8101 */ 8184 */
8102 if ( srcp->bitmap ) 8185 if ( srcp && srcp->bitmap )
8103 { 8186 {
8104 gdk_gc_set_clip_mask( gc, srcp->bitmap ); 8187 gdk_gc_set_clip_mask( gc, srcp->bitmap );
8105 gdk_gc_set_clip_origin( gc, xdest, ydest ); 8188 gdk_gc_set_clip_origin( gc, xdest, ydest );
8106 } 8189 }
8107 gdk_draw_pixmap( dest ? dest->window : destp->pixmap, gc, src ? src->window : srcp->pixmap, xsrc, ysrc, xdest, ydest, width, height ); 8190 gdk_draw_pixmap( dest ? dest->window : destp->pixmap, gc, src ? src->window : srcp->pixmap, xsrc, ysrc, xdest, ydest, width, height );
8108 /* 8191 /*
8109 * Reset the clipping region 8192 * Reset the clipping region
8110 */ 8193 */
8111 if ( srcp->bitmap ) 8194 if ( srcp && srcp->bitmap )
8112 { 8195 {
8113 gdk_gc_set_clip_mask( gc, NULL ); 8196 gdk_gc_set_clip_mask( gc, NULL );
8114 gdk_gc_set_clip_origin( gc, 0, 0 ); 8197 gdk_gc_set_clip_origin( gc, 0, 0 );
8115 } 8198 }
8116 gdk_gc_unref( gc ); 8199 gdk_gc_unref( gc );