Mercurial > dwindows
comparison gtk/dw.c @ 278:df0665ba147f
Initial code for dw_bitmapbutton_new_from_file and added filename parameter
to dw_window_set_bitmap().
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 14 Mar 2003 18:03:35 +0000 |
parents | 95bfcd2deb94 |
children | 984db8aefd7f |
comparison
equal
deleted
inserted
replaced
277:d706e0dbb0cb | 278:df0665ba147f |
---|---|
1691 } | 1691 } |
1692 | 1692 |
1693 /* | 1693 /* |
1694 * Create a bitmap object to be packed. | 1694 * Create a bitmap object to be packed. |
1695 * Parameters: | 1695 * Parameters: |
1696 * id: An ID to be used with WinWindowFromID() or 0L. | 1696 * id: An ID to be used with dw_window_from_id() or 0L. |
1697 */ | 1697 */ |
1698 HWND dw_bitmap_new(unsigned long id) | 1698 HWND dw_bitmap_new(unsigned long id) |
1699 { | 1699 { |
1700 #if GTK_MAJOR_VERSION < 2 | 1700 #if GTK_MAJOR_VERSION < 2 |
1701 GdkPixmap *pixmap = NULL; | 1701 GdkPixmap *pixmap = NULL; |
2141 | 2141 |
2142 /* | 2142 /* |
2143 * Create a new static text window (widget) to be packed. | 2143 * Create a new static text window (widget) to be packed. |
2144 * Parameters: | 2144 * Parameters: |
2145 * text: The text to be display by the static text widget. | 2145 * text: The text to be display by the static text widget. |
2146 * id: An ID to be used with WinWindowFromID() or 0L. | 2146 * id: An ID to be used with dw_window_from_id() or 0L. |
2147 */ | 2147 */ |
2148 HWND dw_text_new(char *text, unsigned long id) | 2148 HWND dw_text_new(char *text, unsigned long id) |
2149 { | 2149 { |
2150 GtkWidget *tmp; | 2150 GtkWidget *tmp; |
2151 int _locked_by_me = FALSE; | 2151 int _locked_by_me = FALSE; |
2164 | 2164 |
2165 /* | 2165 /* |
2166 * Create a new status text window (widget) to be packed. | 2166 * Create a new status text window (widget) to be packed. |
2167 * Parameters: | 2167 * Parameters: |
2168 * text: The text to be display by the static text widget. | 2168 * text: The text to be display by the static text widget. |
2169 * id: An ID to be used with WinWindowFromID() or 0L. | 2169 * id: An ID to be used with dw_window_from_id() or 0L. |
2170 */ | 2170 */ |
2171 HWND dw_status_text_new(char *text, ULONG id) | 2171 HWND dw_status_text_new(char *text, ULONG id) |
2172 { | 2172 { |
2173 GtkWidget *tmp, *frame; | 2173 GtkWidget *tmp, *frame; |
2174 int _locked_by_me = FALSE; | 2174 int _locked_by_me = FALSE; |
2190 } | 2190 } |
2191 | 2191 |
2192 /* | 2192 /* |
2193 * Create a new Multiline Editbox window (widget) to be packed. | 2193 * Create a new Multiline Editbox window (widget) to be packed. |
2194 * Parameters: | 2194 * Parameters: |
2195 * id: An ID to be used with WinWindowFromID() or 0L. | 2195 * id: An ID to be used with dw_window_from_id() or 0L. |
2196 */ | 2196 */ |
2197 HWND dw_mle_new(unsigned long id) | 2197 HWND dw_mle_new(unsigned long id) |
2198 { | 2198 { |
2199 GtkWidget *tmp, *tmpbox, *scroller; | 2199 GtkWidget *tmp, *tmpbox, *scroller; |
2200 int _locked_by_me = FALSE; | 2200 int _locked_by_me = FALSE; |
2230 | 2230 |
2231 /* | 2231 /* |
2232 * Create a new Entryfield window (widget) to be packed. | 2232 * Create a new Entryfield window (widget) to be packed. |
2233 * Parameters: | 2233 * Parameters: |
2234 * text: The default text to be in the entryfield widget. | 2234 * text: The default text to be in the entryfield widget. |
2235 * id: An ID to be used with WinWindowFromID() or 0L. | 2235 * id: An ID to be used with dw_window_from_id() or 0L. |
2236 */ | 2236 */ |
2237 HWND dw_entryfield_new(char *text, unsigned long id) | 2237 HWND dw_entryfield_new(char *text, unsigned long id) |
2238 { | 2238 { |
2239 GtkWidget *tmp; | 2239 GtkWidget *tmp; |
2240 int _locked_by_me = FALSE; | 2240 int _locked_by_me = FALSE; |
2253 | 2253 |
2254 /* | 2254 /* |
2255 * Create a new Entryfield (password) window (widget) to be packed. | 2255 * Create a new Entryfield (password) window (widget) to be packed. |
2256 * Parameters: | 2256 * Parameters: |
2257 * text: The default text to be in the entryfield widget. | 2257 * text: The default text to be in the entryfield widget. |
2258 * id: An ID to be used with WinWindowFromID() or 0L. | 2258 * id: An ID to be used with dw_window_from_id() or 0L. |
2259 */ | 2259 */ |
2260 HWND dw_entryfield_password_new(char *text, ULONG id) | 2260 HWND dw_entryfield_password_new(char *text, ULONG id) |
2261 { | 2261 { |
2262 GtkWidget *tmp; | 2262 GtkWidget *tmp; |
2263 int _locked_by_me = FALSE; | 2263 int _locked_by_me = FALSE; |
2277 | 2277 |
2278 /* | 2278 /* |
2279 * Create a new Combobox window (widget) to be packed. | 2279 * Create a new Combobox window (widget) to be packed. |
2280 * Parameters: | 2280 * Parameters: |
2281 * text: The default text to be in the combpbox widget. | 2281 * text: The default text to be in the combpbox widget. |
2282 * id: An ID to be used with WinWindowFromID() or 0L. | 2282 * id: An ID to be used with dw_window_from_id() or 0L. |
2283 */ | 2283 */ |
2284 HWND dw_combobox_new(char *text, unsigned long id) | 2284 HWND dw_combobox_new(char *text, unsigned long id) |
2285 { | 2285 { |
2286 GtkWidget *tmp; | 2286 GtkWidget *tmp; |
2287 SignalHandler *work = malloc(sizeof(SignalHandler)); | 2287 SignalHandler *work = malloc(sizeof(SignalHandler)); |
2306 | 2306 |
2307 /* | 2307 /* |
2308 * Create a new button window (widget) to be packed. | 2308 * Create a new button window (widget) to be packed. |
2309 * Parameters: | 2309 * Parameters: |
2310 * text: The text to be display by the static text widget. | 2310 * text: The text to be display by the static text widget. |
2311 * id: An ID to be used with WinWindowFromID() or 0L. | 2311 * id: An ID to be used with dw_window_from_id() or 0L. |
2312 */ | 2312 */ |
2313 HWND dw_button_new(char *text, unsigned long id) | 2313 HWND dw_button_new(char *text, unsigned long id) |
2314 { | 2314 { |
2315 GtkWidget *tmp; | 2315 GtkWidget *tmp; |
2316 int _locked_by_me = FALSE; | 2316 int _locked_by_me = FALSE; |
2340 tmp = gtk_button_new(); | 2340 tmp = gtk_button_new(); |
2341 bitmap = dw_bitmap_new(id); | 2341 bitmap = dw_bitmap_new(id); |
2342 | 2342 |
2343 if(bitmap) | 2343 if(bitmap) |
2344 { | 2344 { |
2345 dw_window_set_bitmap(bitmap, id); | 2345 dw_window_set_bitmap(bitmap, id, NULL); |
2346 gtk_container_add (GTK_CONTAINER(tmp), bitmap); | 2346 gtk_container_add (GTK_CONTAINER(tmp), bitmap); |
2347 } | 2347 } |
2348 gtk_widget_show(tmp); | 2348 gtk_widget_show(tmp); |
2349 if(text) | 2349 if(text) |
2350 { | 2350 { |
2356 DW_MUTEX_UNLOCK; | 2356 DW_MUTEX_UNLOCK; |
2357 return tmp; | 2357 return tmp; |
2358 } | 2358 } |
2359 | 2359 |
2360 /* | 2360 /* |
2361 * Create a new bitmap button window (widget) to be packed from a file. | |
2362 * Parameters: | |
2363 * text: Bubble help text to be displayed. | |
2364 * id: An ID to be used with dw_window_from_id() or 0L. | |
2365 * filename: Name of the file, omit extention to have | |
2366 * DW pick the appropriate file extension. | |
2367 * (BMP on OS/2 or Windows, XPM on Unix) | |
2368 */ | |
2369 HWND dw_bitmapbutton_new_from_file(char *text, unsigned long id, char filename) | |
2370 { | |
2371 GtkWidget *tmp; | |
2372 GtkWidget *bitmap; | |
2373 GtkTooltips *tooltips; | |
2374 int _locked_by_me = FALSE; | |
2375 | |
2376 DW_MUTEX_LOCK; | |
2377 tmp = gtk_button_new(); | |
2378 bitmap = dw_bitmap_new(id); | |
2379 | |
2380 if(bitmap) | |
2381 { | |
2382 dw_window_set_bitmap(bitmap, 0, filename); | |
2383 gtk_container_add (GTK_CONTAINER(tmp), bitmap); | |
2384 } | |
2385 gtk_widget_show(tmp); | |
2386 if(text) | |
2387 { | |
2388 tooltips = gtk_tooltips_new(); | |
2389 gtk_tooltips_set_tip(tooltips, tmp, text, NULL); | |
2390 gtk_object_set_data(GTK_OBJECT(tmp), "tooltip", (gpointer)tooltips); | |
2391 } | |
2392 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); | |
2393 DW_MUTEX_UNLOCK; | |
2394 return tmp; | |
2395 } | |
2396 | |
2397 /* | |
2361 * Create a new spinbutton window (widget) to be packed. | 2398 * Create a new spinbutton window (widget) to be packed. |
2362 * Parameters: | 2399 * Parameters: |
2363 * text: The text to be display by the static text widget. | 2400 * text: The text to be display by the static text widget. |
2364 * id: An ID to be used with WinWindowFromID() or 0L. | 2401 * id: An ID to be used with dw_window_from_id() or 0L. |
2365 */ | 2402 */ |
2366 HWND dw_spinbutton_new(char *text, unsigned long id) | 2403 HWND dw_spinbutton_new(char *text, unsigned long id) |
2367 { | 2404 { |
2368 GtkAdjustment *adj; | 2405 GtkAdjustment *adj; |
2369 GtkWidget *tmp; | 2406 GtkWidget *tmp; |
2382 | 2419 |
2383 /* | 2420 /* |
2384 * Create a new radiobutton window (widget) to be packed. | 2421 * Create a new radiobutton window (widget) to be packed. |
2385 * Parameters: | 2422 * Parameters: |
2386 * text: The text to be display by the static text widget. | 2423 * text: The text to be display by the static text widget. |
2387 * id: An ID to be used with WinWindowFromID() or 0L. | 2424 * id: An ID to be used with dw_window_from_id() or 0L. |
2388 */ | 2425 */ |
2389 HWND dw_radiobutton_new(char *text, ULONG id) | 2426 HWND dw_radiobutton_new(char *text, ULONG id) |
2390 { | 2427 { |
2391 /* This will have to be fixed in the future. */ | 2428 /* This will have to be fixed in the future. */ |
2392 GtkWidget *tmp; | 2429 GtkWidget *tmp; |
2404 /* | 2441 /* |
2405 * Create a new slider window (widget) to be packed. | 2442 * Create a new slider window (widget) to be packed. |
2406 * Parameters: | 2443 * Parameters: |
2407 * vertical: TRUE or FALSE if slider is vertical. | 2444 * vertical: TRUE or FALSE if slider is vertical. |
2408 * increments: Number of increments available. | 2445 * increments: Number of increments available. |
2409 * id: An ID to be used with WinWindowFromID() or 0L. | 2446 * id: An ID to be used with dw_window_from_id() or 0L. |
2410 */ | 2447 */ |
2411 HWND dw_slider_new(int vertical, int increments, ULONG id) | 2448 HWND dw_slider_new(int vertical, int increments, ULONG id) |
2412 { | 2449 { |
2413 GtkWidget *tmp; | 2450 GtkWidget *tmp; |
2414 GtkAdjustment *adjustment; | 2451 GtkAdjustment *adjustment; |
2433 /* | 2470 /* |
2434 * Create a new scrollbar window (widget) to be packed. | 2471 * Create a new scrollbar window (widget) to be packed. |
2435 * Parameters: | 2472 * Parameters: |
2436 * vertical: TRUE or FALSE if scrollbar is vertical. | 2473 * vertical: TRUE or FALSE if scrollbar is vertical. |
2437 * increments: Number of increments available. | 2474 * increments: Number of increments available. |
2438 * id: An ID to be used with WinWindowFromID() or 0L. | 2475 * id: An ID to be used with dw_window_from_id() or 0L. |
2439 */ | 2476 */ |
2440 HWND dw_scrollbar_new(int vertical, int increments, ULONG id) | 2477 HWND dw_scrollbar_new(int vertical, int increments, ULONG id) |
2441 { | 2478 { |
2442 GtkWidget *tmp; | 2479 GtkWidget *tmp; |
2443 GtkAdjustment *adjustment; | 2480 GtkAdjustment *adjustment; |
2459 } | 2496 } |
2460 | 2497 |
2461 /* | 2498 /* |
2462 * Create a new percent bar window (widget) to be packed. | 2499 * Create a new percent bar window (widget) to be packed. |
2463 * Parameters: | 2500 * Parameters: |
2464 * id: An ID to be used with WinWindowFromID() or 0L. | 2501 * id: An ID to be used with dw_window_from_id() or 0L. |
2465 */ | 2502 */ |
2466 HWND dw_percent_new(unsigned long id) | 2503 HWND dw_percent_new(unsigned long id) |
2467 { | 2504 { |
2468 GtkWidget *tmp; | 2505 GtkWidget *tmp; |
2469 int _locked_by_me = FALSE; | 2506 int _locked_by_me = FALSE; |
2478 | 2515 |
2479 /* | 2516 /* |
2480 * Create a new checkbox window (widget) to be packed. | 2517 * Create a new checkbox window (widget) to be packed. |
2481 * Parameters: | 2518 * Parameters: |
2482 * text: The text to be display by the static text widget. | 2519 * text: The text to be display by the static text widget. |
2483 * id: An ID to be used with WinWindowFromID() or 0L. | 2520 * id: An ID to be used with dw_window_from_id() or 0L. |
2484 */ | 2521 */ |
2485 HWND dw_checkbox_new(char *text, unsigned long id) | 2522 HWND dw_checkbox_new(char *text, unsigned long id) |
2486 { | 2523 { |
2487 GtkWidget *tmp; | 2524 GtkWidget *tmp; |
2488 int _locked_by_me = FALSE; | 2525 int _locked_by_me = FALSE; |
2496 } | 2533 } |
2497 | 2534 |
2498 /* | 2535 /* |
2499 * Create a new listbox window (widget) to be packed. | 2536 * Create a new listbox window (widget) to be packed. |
2500 * Parameters: | 2537 * Parameters: |
2501 * id: An ID to be used with WinWindowFromID() or 0L. | 2538 * id: An ID to be used with dw_window_from_id() or 0L. |
2502 * multi: Multiple select TRUE or FALSE. | 2539 * multi: Multiple select TRUE or FALSE. |
2503 */ | 2540 */ |
2504 HWND dw_listbox_new(unsigned long id, int multi) | 2541 HWND dw_listbox_new(unsigned long id, int multi) |
2505 { | 2542 { |
2506 GtkWidget *tmp, *list; | 2543 GtkWidget *tmp, *list; |
2544 gdk_window_set_icon(handle->window, NULL, icon_pixmap, bitmap); | 2581 gdk_window_set_icon(handle->window, NULL, icon_pixmap, bitmap); |
2545 | 2582 |
2546 DW_MUTEX_UNLOCK; | 2583 DW_MUTEX_UNLOCK; |
2547 } | 2584 } |
2548 | 2585 |
2586 HPIXMAP dw_pixmap_new_from_file(HWND handle, char *filename) | |
2587 { | |
2588 int _locked_by_me = FALSE; | |
2589 HPIXMAP pixmap; | |
2590 #ifndef USE_IMLIB | |
2591 GdkBitmap *bitmap = NULL; | |
2592 #endif | |
2593 #if GTK_MAJOR_VERSION > 1 | |
2594 GdkPixbuf *pixbuf; | |
2595 #elif defined(USE_IMLIB) | |
2596 GdkImlibImage *image; | |
2597 #endif | |
2598 char *file = alloca(strlen(filename) + 5); | |
2599 | |
2600 if (!file || !(pixmap = calloc(1,sizeof(struct _hpixmap)))) | |
2601 return NULL; | |
2602 | |
2603 strcpy(file, filename); | |
2604 | |
2605 /* check if we can read from this file (it exists and read permission) */ | |
2606 if(access(file, 04) != 0) | |
2607 { | |
2608 /* Try with .xpm extention */ | |
2609 strcat(file, ".xpm"); | |
2610 if(access(file, 04) != 0) | |
2611 { | |
2612 free(pixmap); | |
2613 return NULL; | |
2614 } | |
2615 } | |
2616 | |
2617 DW_MUTEX_LOCK; | |
2618 #if GTK_MAJOR_VERSION > 1 | |
2619 pixbuf = gdk_pixbuf_new_from_file(file, NULL); | |
2620 | |
2621 pixmap->width = gdk_pixbuf_get_width(pixbuf); | |
2622 pixmap->height = gdk_pixbuf_get_height(pixbuf); | |
2623 | |
2624 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap->pixmap, &bitmap, 1); | |
2625 g_object_unref(pixbuf); | |
2626 #elif defined(USE_IMLIB) | |
2627 image = gdk_imlib_load_image(file); | |
2628 | |
2629 pixmap->width = image->rgb_width; | |
2630 pixmap->height = image->rgb_height; | |
2631 | |
2632 gdk_imlib_render(image, pixmap->width, pixmap->height); | |
2633 pixmap->pixmap = gdk_imlib_copy_image(image); | |
2634 gdk_imlib_destroy_image(image); | |
2635 #else | |
2636 pixmap->pixmap = gdk_pixmap_create_from_xpm(handle->window, &bitmap, &_colors[DW_CLR_PALEGRAY], file); | |
2637 #endif | |
2638 pixmap->handle = handle; | |
2639 DW_MUTEX_UNLOCK; | |
2640 return pixmap; | |
2641 } | |
2549 /* | 2642 /* |
2550 * Sets the bitmap used for a given static window. | 2643 * Sets the bitmap used for a given static window. |
2551 * Parameters: | 2644 * Parameters: |
2552 * handle: Handle to the window. | 2645 * handle: Handle to the window. |
2553 * id: An ID to be used to specify the icon. | 2646 * id: An ID to be used to specify the icon, |
2554 */ | 2647 * (pass 0 if you use the filename param) |
2555 void dw_window_set_bitmap(HWND handle, unsigned long id) | 2648 * filename: a path to a file (Bitmap on OS/2 or |
2649 * Windows and a pixmap on Unix, pass | |
2650 * NULL if you use the id param) | |
2651 */ | |
2652 void dw_window_set_bitmap(HWND handle, unsigned long id, char *filename) | |
2556 { | 2653 { |
2557 GdkBitmap *bitmap = NULL; | 2654 GdkBitmap *bitmap = NULL; |
2558 GdkPixmap *tmp; | 2655 GdkPixmap *tmp; |
2559 int _locked_by_me = FALSE; | 2656 int _locked_by_me = FALSE; |
2560 | 2657 |
2561 DW_MUTEX_LOCK; | 2658 if(!id && !filename) |
2562 tmp = _find_pixmap(&bitmap, id, handle, NULL, NULL); | 2659 return; |
2660 | |
2661 DW_MUTEX_LOCK; | |
2662 if(id) | |
2663 tmp = _find_pixmap(&bitmap, id, handle, NULL, NULL); | |
2664 else | |
2665 { | |
2666 char *file = alloca(strlen(filename) + 5); | |
2667 #if GTK_MAJOR_VERSION > 1 | |
2668 GdkPixbuf *pixbuf; | |
2669 #elif defined(USE_IMLIB) | |
2670 GdkImlibImage *image; | |
2671 #endif | |
2672 | |
2673 if (!file) | |
2674 { | |
2675 DW_MUTEX_UNLOCK; | |
2676 return; | |
2677 } | |
2678 | |
2679 strcpy(file, filename); | |
2680 | |
2681 /* check if we can read from this file (it exists and read permission) */ | |
2682 if(access(file, 04) != 0) | |
2683 { | |
2684 /* Try with .xpm extention */ | |
2685 strcat(file, ".xpm"); | |
2686 if(access(file, 04) != 0) | |
2687 { | |
2688 DW_MUTEX_UNLOCK; | |
2689 return NULL; | |
2690 } | |
2691 } | |
2692 #if GTK_MAJOR_VERSION > 1 | |
2693 pixbuf = gdk_pixbuf_new_from_file(file, NULL); | |
2694 | |
2695 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &tmp, &bitmap, 1); | |
2696 g_object_unref(pixbuf); | |
2697 #elif defined(USE_IMLIB) | |
2698 image = gdk_imlib_load_image(file); | |
2699 | |
2700 gdk_imlib_render(image, image->rgb_width, image->rgb_height); | |
2701 tmp = gdk_imlib_copy_image(image); | |
2702 gdk_imlib_destroy_image(image); | |
2703 #else | |
2704 tmp = gdk_pixmap_create_from_xpm(handle->window, &bitmap, &_colors[DW_CLR_PALEGRAY], file); | |
2705 #endif | |
2706 } | |
2707 | |
2563 if(tmp) | 2708 if(tmp) |
2564 #if GTK_MAJOR_VERSION > 1 | 2709 #if GTK_MAJOR_VERSION > 1 |
2565 gtk_image_set_from_pixmap(GTK_IMAGE(handle), tmp, bitmap); | 2710 gtk_image_set_from_pixmap(GTK_IMAGE(handle), tmp, bitmap); |
2566 #else | 2711 #else |
2567 gtk_pixmap_set(GTK_PIXMAP(handle), tmp, bitmap); | 2712 gtk_pixmap_set(GTK_PIXMAP(handle), tmp, bitmap); |