comparison os2/dw.c @ 367:f19440c0ff71

Bitmap buttons now display properly when disabled. Also fixes to bitmap buttons from file when the button highlite state changes.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 27 Apr 2003 16:56:25 +0000
parents 4ed3b13ee48c
children 72fbd1ee8150
comparison
equal deleted inserted replaced
366:4ed3b13ee48c 367:f19440c0ff71
253 { 253 {
254 HBITMAP hbm = (HBITMAP)dw_window_get_data(handle, "_dw_bitmap"); 254 HBITMAP hbm = (HBITMAP)dw_window_get_data(handle, "_dw_bitmap");
255 HPS hps = (HPS)dw_window_get_data(handle, "_dw_hps"); 255 HPS hps = (HPS)dw_window_get_data(handle, "_dw_hps");
256 HDC hdc = (HDC)dw_window_get_data(handle, "_dw_hdc"); 256 HDC hdc = (HDC)dw_window_get_data(handle, "_dw_hdc");
257 HPIXMAP pixmap = (HPIXMAP)dw_window_get_data(handle, "_dw_hpixmap"); 257 HPIXMAP pixmap = (HPIXMAP)dw_window_get_data(handle, "_dw_hpixmap");
258 HPIXMAP disable = (HPIXMAP)dw_window_get_data(handle, "_dw_hpixmap_disabled");
258 259
259 if(pixmap) 260 if(pixmap)
260 dw_pixmap_destroy(pixmap); 261 dw_pixmap_destroy(pixmap);
262
263 if(disable)
264 dw_pixmap_destroy(disable);
261 265
262 if(hps) 266 if(hps)
263 { 267 {
264 GpiSetBitmap(hps, NULLHANDLE); 268 GpiSetBitmap(hps, NULLHANDLE);
265 GpiAssociate(hps, NULLHANDLE); 269 GpiAssociate(hps, NULLHANDLE);
2777 } 2781 }
2778 2782
2779 MRESULT EXPENTRY _button_draw(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2, PFNWP oldproc, int indent) 2783 MRESULT EXPENTRY _button_draw(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2, PFNWP oldproc, int indent)
2780 { 2784 {
2781 HPIXMAP pixmap = (HPIXMAP)dw_window_get_data(hwnd, "_dw_hpixmap"); 2785 HPIXMAP pixmap = (HPIXMAP)dw_window_get_data(hwnd, "_dw_hpixmap");
2786 HPIXMAP disable = (HPIXMAP)dw_window_get_data(hwnd, "_dw_hpixmap_disabled");
2782 MRESULT res; 2787 MRESULT res;
2783 2788
2784 if(!oldproc) 2789 if(!oldproc)
2785 res = WinDefWindowProc(hwnd, msg, mp1, mp2); 2790 res = WinDefWindowProc(hwnd, msg, mp1, mp2);
2786 res = oldproc(hwnd, msg, mp1, mp2); 2791 res = oldproc(hwnd, msg, mp1, mp2);
2793 dw_window_get_pos_size(hwnd, NULL, NULL, &width, &height); 2798 dw_window_get_pos_size(hwnd, NULL, NULL, &width, &height);
2794 2799
2795 x = (width - pixmap->width)/2; 2800 x = (width - pixmap->width)/2;
2796 y = (height - pixmap->height)/2; 2801 y = (height - pixmap->height)/2;
2797 2802
2798 dw_pixmap_bitblt(hwnd, 0, x + indent, y + indent, pixmap->width, pixmap->height, 0, pixmap, 0, 0); 2803 if(disable && dw_window_get_data(hwnd, "_dw_disabled"))
2804 dw_pixmap_bitblt(hwnd, 0, x + indent, y + indent, pixmap->width, pixmap->height, 0, disable, 0, 0);
2805 else
2806 dw_pixmap_bitblt(hwnd, 0, x + indent, y + indent, pixmap->width, pixmap->height, 0, pixmap, 0, 0);
2799 } 2807 }
2800 return res; 2808 return res;
2801 } 2809 }
2802 2810
2803 /* Function: BtProc 2811 /* Function: BtProc
2817 oldproc = bubble->pOldProc; 2825 oldproc = bubble->pOldProc;
2818 2826
2819 switch(msg) 2827 switch(msg)
2820 { 2828 {
2821 case WM_PAINT: 2829 case WM_PAINT:
2822 case WM_BUTTON2UP:
2823 case WM_BUTTON3UP:
2824 return _button_draw(hwnd, msg, mp1, mp2, oldproc, 0); 2830 return _button_draw(hwnd, msg, mp1, mp2, oldproc, 0);
2831 case BM_SETHILITE:
2832 return _button_draw(hwnd, msg, mp1, mp2, oldproc, (int)mp1);
2825 case WM_SETFOCUS: 2833 case WM_SETFOCUS:
2826 if(mp2) 2834 if(mp2)
2827 _run_event(hwnd, msg, mp1, mp2); 2835 _run_event(hwnd, msg, mp1, mp2);
2828 else 2836 else
2829 WinSendMsg(hwnd, BM_SETDEFAULT, 0, 0); 2837 WinSendMsg(hwnd, BM_SETDEFAULT, 0, 0);
2834 case WM_BUTTON1DBLCLK: 2842 case WM_BUTTON1DBLCLK:
2835 case WM_BUTTON2DBLCLK: 2843 case WM_BUTTON2DBLCLK:
2836 case WM_BUTTON3DBLCLK: 2844 case WM_BUTTON3DBLCLK:
2837 if(dw_window_get_data(hwnd, "_dw_disabled")) 2845 if(dw_window_get_data(hwnd, "_dw_disabled"))
2838 return (MRESULT)FALSE; 2846 return (MRESULT)FALSE;
2839 return _button_draw(hwnd, msg, mp1, mp2, oldproc, 1);
2840 case WM_BUTTON1UP: 2847 case WM_BUTTON1UP:
2841 { 2848 {
2842 SignalHandler *tmp = Root; 2849 SignalHandler *tmp = Root;
2843 2850
2844 if(WinIsWindowEnabled(hwnd) && !dw_window_get_data(hwnd, "_dw_disabled")) 2851 if(WinIsWindowEnabled(hwnd) && !dw_window_get_data(hwnd, "_dw_disabled"))
2864 if(tmp) 2871 if(tmp)
2865 tmp= tmp->next; 2872 tmp= tmp->next;
2866 } 2873 }
2867 } 2874 }
2868 } 2875 }
2869 return _button_draw(hwnd, msg, mp1, mp2, oldproc, 0); 2876 break;
2870 case WM_USER: 2877 case WM_USER:
2871 { 2878 {
2872 SignalHandler *tmp = (SignalHandler *)mp1; 2879 SignalHandler *tmp = (SignalHandler *)mp1;
2873 int (* API clickfunc)(HWND, void *) = NULL; 2880 int (* API clickfunc)(HWND, void *) = NULL;
2874 2881
4302 strncpy(bubble->bubbletext, text, BUBBLE_HELP_MAX - 1); 4309 strncpy(bubble->bubbletext, text, BUBBLE_HELP_MAX - 1);
4303 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0'; 4310 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0';
4304 bubble->pOldProc = WinSubclassWindow(tmp, _BtProc); 4311 bubble->pOldProc = WinSubclassWindow(tmp, _BtProc);
4305 4312
4306 WinSetWindowPtr(tmp, QWP_USER, bubble); 4313 WinSetWindowPtr(tmp, QWP_USER, bubble);
4314 dw_window_set_data(tmp, "_dw_bitmapbutton", (void *)1);
4307 return tmp; 4315 return tmp;
4308 } 4316 }
4309 4317
4310 /* 4318 /*
4311 * Create a new bitmap button window (widget) to be packed from a file. 4319 * Create a new bitmap button window (widget) to be packed from a file.
4329 HWND_TOP, 4337 HWND_TOP,
4330 id, 4338 id,
4331 NULL, 4339 NULL,
4332 NULL); 4340 NULL);
4333 char *file = alloca(strlen(filename) + 5); 4341 char *file = alloca(strlen(filename) + 5);
4334 HPIXMAP pixmap; 4342 HPIXMAP pixmap = NULL, disabled = NULL;
4335 4343
4336 if(file && (pixmap = calloc(1,sizeof(struct _hpixmap)))) 4344 if(file && (pixmap = calloc(1,sizeof(struct _hpixmap))))
4337 { 4345 {
4346 int z, j, lim;
4347 LONG fore;
4348
4338 strcpy(file, filename); 4349 strcpy(file, filename);
4339 4350
4340 /* check if we can read from this file (it exists and read permission) */ 4351 /* check if we can read from this file (it exists and read permission) */
4341 if(access(file, 04) != 0) 4352 if(access(file, 04) != 0)
4342 { 4353 {
4350 } 4361 }
4351 4362
4352 /* Try to load the bitmap from file */ 4363 /* Try to load the bitmap from file */
4353 if(pixmap) 4364 if(pixmap)
4354 _load_bitmap_file(file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height); 4365 _load_bitmap_file(file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height);
4366
4367 /* Create a disabled style pixmap */
4368 disabled = dw_pixmap_new(tmp, pixmap->width, pixmap->height, dw_color_depth());
4369 dw_pixmap_bitblt(0, disabled, 0, 0, pixmap->width, pixmap->height, 0, pixmap, 0, 0);
4370
4371 fore = _foreground;
4372 dw_color_foreground_set(DW_CLR_PALEGRAY);
4373 lim = pixmap->width/2;
4374 for(j=0;j<pixmap->height;j++)
4375 {
4376 int mod = j%2;
4377
4378 for(z=0;z<lim;z++)
4379 dw_draw_point(0, disabled, (z*2)+mod, j);
4380 }
4381 _foreground = fore;
4355 } 4382 }
4356 4383
4357 bubble->id = id; 4384 bubble->id = id;
4358 strncpy(bubble->bubbletext, text, BUBBLE_HELP_MAX - 1); 4385 strncpy(bubble->bubbletext, text, BUBBLE_HELP_MAX - 1);
4359 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0'; 4386 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0';
4360 bubble->pOldProc = WinSubclassWindow(tmp, _BtProc); 4387 bubble->pOldProc = WinSubclassWindow(tmp, _BtProc);
4361 4388
4362 WinSetWindowPtr(tmp, QWP_USER, bubble); 4389 WinSetWindowPtr(tmp, QWP_USER, bubble);
4363 4390
4364 dw_window_set_data(tmp, "_dw_hpixmap", (void *)pixmap); 4391 dw_window_set_data(tmp, "_dw_hpixmap", (void *)pixmap);
4392 dw_window_set_data(tmp, "_dw_hpixmap_disabled", (void *)disabled);
4393 dw_window_set_data(tmp, "_dw_bitmapbutton", (void *)1);
4365 return tmp; 4394 return tmp;
4366 } 4395 }
4367 4396
4368 /* 4397 /*
4369 * Create a new spinbutton window (widget) to be packed. 4398 * Create a new spinbutton window (widget) to be packed.
4800 dw_signal_connect(handle, DW_SIGNAL_BUTTON_PRESS, DW_SIGNAL_FUNC(_null_key), (void *)100); 4829 dw_signal_connect(handle, DW_SIGNAL_BUTTON_PRESS, DW_SIGNAL_FUNC(_null_key), (void *)100);
4801 if(hwnd) 4830 if(hwnd)
4802 dw_window_set_data(hwnd, "_dw_disabled", (void *)1); 4831 dw_window_set_data(hwnd, "_dw_disabled", (void *)1);
4803 return; 4832 return;
4804 case 3: 4833 case 3:
4805 _dw_window_set_color(handle, DW_CLR_DARKGRAY, DW_CLR_PALEGRAY); 4834 if(dw_window_get_data(handle, "_dw_bitmapbutton") && !dw_window_get_data(handle, "_dw_hpixmap"))
4835 WinEnableWindow(handle, FALSE);
4836 else if(dw_window_get_data(handle, "_dw_bitmapbutton") && dw_window_get_data(handle, "_dw_hpixmap_disabled"))
4837 WinInvalidateRect(handle, NULL, FALSE);
4838 else
4839 _dw_window_set_color(handle, DW_CLR_DARKGRAY, DW_CLR_PALEGRAY);
4806 dw_signal_connect(handle, DW_SIGNAL_KEY_PRESS, DW_SIGNAL_FUNC(_null_key), (void *)100); 4840 dw_signal_connect(handle, DW_SIGNAL_KEY_PRESS, DW_SIGNAL_FUNC(_null_key), (void *)100);
4807 dw_signal_connect(handle, DW_SIGNAL_BUTTON_PRESS, DW_SIGNAL_FUNC(_null_key), (void *)100); 4841 dw_signal_connect(handle, DW_SIGNAL_BUTTON_PRESS, DW_SIGNAL_FUNC(_null_key), (void *)100);
4808 return; 4842 return;
4809 } 4843 }
4810 } 4844 }
4827 dw_window_set_data(hwnd, "_dw_disabled", 0); 4861 dw_window_set_data(hwnd, "_dw_disabled", 0);
4828 if(fore && back) 4862 if(fore && back)
4829 _dw_window_set_color(hwnd ? hwnd : handle, fore-1, back-1); 4863 _dw_window_set_color(hwnd ? hwnd : handle, fore-1, back-1);
4830 dw_signal_disconnect_by_data(handle, (void *)100); 4864 dw_signal_disconnect_by_data(handle, (void *)100);
4831 WinEnableWindow(handle, TRUE); 4865 WinEnableWindow(handle, TRUE);
4866 if(dw_window_get_data(handle, "_dw_bitmapbutton") && dw_window_get_data(handle, "_dw_hpixmap_disabled"))
4867 WinInvalidateRect(handle, NULL, FALSE);
4832 } 4868 }
4833 4869
4834 /* 4870 /*
4835 * Gets the child window handle with specified ID. 4871 * Gets the child window handle with specified ID.
4836 * Parameters: 4872 * Parameters: