comparison win/dw.c @ 1392:943266c86aed

Refactoring OS/2 and Windows code... eliminating BubbleButton... BubbleButton was no longer really used in Windows since I switched to native tooltips... However parts of it were still hanging around. Merging BubbleButton into WindowData on OS/2 to prepare for generic tooltip support. More coming very soon.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 26 Nov 2011 22:47:20 +0000
parents 0512fbb08abf
children 2ccf7eacedf5
comparison
equal deleted inserted replaced
1391:614fb124d2e2 1392:943266c86aed
3390 * Abstract: Subclass procedure for buttons 3390 * Abstract: Subclass procedure for buttons
3391 */ 3391 */
3392 3392
3393 BOOL CALLBACK _BtProc(HWND hwnd, ULONG msg, WPARAM mp1, LPARAM mp2) 3393 BOOL CALLBACK _BtProc(HWND hwnd, ULONG msg, WPARAM mp1, LPARAM mp2)
3394 { 3394 {
3395 BubbleButton *bubble; 3395 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
3396 WNDPROC pOldProc; 3396 WNDPROC pOldProc;
3397 3397
3398 bubble = (BubbleButton *)GetWindowLongPtr(hwnd, GWLP_USERDATA); 3398 if ( !cinfo )
3399
3400 if ( !bubble )
3401 return DefWindowProc(hwnd, msg, mp1, mp2); 3399 return DefWindowProc(hwnd, msg, mp1, mp2);
3402 3400
3403 /* We must save a pointer to the old 3401 /* We must save a pointer to the old
3404 * window procedure because if a signal 3402 * window procedure because if a signal
3405 * handler attached here destroys this 3403 * handler attached here destroys this
3406 * window it will then be invalid. 3404 * window it will then be invalid.
3407 */ 3405 */
3408 pOldProc = bubble->pOldProc; 3406 pOldProc = cinfo->pOldProc;
3409 3407
3410 switch(msg) 3408 switch(msg)
3411 { 3409 {
3412 case WM_CTLCOLORSTATIC: 3410 case WM_CTLCOLORSTATIC:
3413 case WM_CTLCOLORLISTBOX: 3411 case WM_CTLCOLORLISTBOX:
3433 int (*clickfunc)(HWND, void *) = tmp->signalfunction; 3431 int (*clickfunc)(HWND, void *) = tmp->signalfunction;
3434 3432
3435 /* Make sure it's the right window, and the right ID */ 3433 /* Make sure it's the right window, and the right ID */
3436 if(tmp->window == hwnd) 3434 if(tmp->window == hwnd)
3437 { 3435 {
3438 if(bubble->checkbox) 3436 int checkbox = DW_POINTER_TO_INT(dw_window_get_data(hwnd, "_dw_checkbox"));
3437
3438 if(checkbox)
3439 in_checkbox_handler = 1; 3439 in_checkbox_handler = 1;
3440 3440
3441 clickfunc(tmp->window, tmp->data); 3441 clickfunc(tmp->window, tmp->data);
3442 3442
3443 if(bubble->checkbox) 3443 if(checkbox)
3444 in_checkbox_handler = 0; 3444 in_checkbox_handler = 0;
3445 tmp = NULL; 3445 tmp = NULL;
3446 } 3446 }
3447 } 3447 }
3448 if(tmp) 3448 if(tmp)
5577 * text: The text to be display by the static text widget. 5577 * text: The text to be display by the static text widget.
5578 * id: An ID to be used with dw_window_from_id() or 0L. 5578 * id: An ID to be used with dw_window_from_id() or 0L.
5579 */ 5579 */
5580 HWND API dw_button_new(char *text, ULONG id) 5580 HWND API dw_button_new(char *text, ULONG id)
5581 { 5581 {
5582 BubbleButton *bubble = calloc(1, sizeof(BubbleButton)); 5582 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo));
5583 5583
5584 HWND tmp = CreateWindow(BUTTONCLASSNAME, 5584 HWND tmp = CreateWindow(BUTTONCLASSNAME,
5585 text, 5585 text,
5586 WS_CHILD | BS_PUSHBUTTON | 5586 WS_CHILD | BS_PUSHBUTTON |
5587 WS_VISIBLE | WS_CLIPCHILDREN, 5587 WS_VISIBLE | WS_CLIPCHILDREN,
5588 0,0,0,0, 5588 0,0,0,0,
5589 DW_HWND_OBJECT, 5589 DW_HWND_OBJECT,
5590 (HMENU)id, 5590 (HMENU)id,
5591 DWInstance, 5591 DWInstance,
5592 NULL); 5592 NULL);
5593 bubble->cinfo.fore = bubble->cinfo.back = -1; 5593 cinfo->fore = cinfo->back = -1;
5594 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); 5594 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc);
5595 5595
5596 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble); 5596 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
5597 dw_window_set_font(tmp, DefaultFont); 5597 dw_window_set_font(tmp, DefaultFont);
5598 return tmp; 5598 return tmp;
5599 } 5599 }
5600 5600
5601 /* 5601 /*
5605 * id: An ID of a bitmap in the resource file. 5605 * id: An ID of a bitmap in the resource file.
5606 */ 5606 */
5607 HWND API dw_bitmapbutton_new(char *text, ULONG id) 5607 HWND API dw_bitmapbutton_new(char *text, ULONG id)
5608 { 5608 {
5609 HWND tmp; 5609 HWND tmp;
5610 BubbleButton *bubble = calloc(1, sizeof(BubbleButton)); 5610 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo));
5611 HBITMAP hbitmap = LoadBitmap(DWInstance, MAKEINTRESOURCE(id)); 5611 HBITMAP hbitmap = LoadBitmap(DWInstance, MAKEINTRESOURCE(id));
5612 HICON icon = LoadImage(DWInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, LR_SHARED); 5612 HICON icon = LoadImage(DWInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, LR_SHARED);
5613 5613
5614 tmp = CreateWindow(BUTTONCLASSNAME, 5614 tmp = CreateWindow(BUTTONCLASSNAME,
5615 "", 5615 "",
5620 DW_HWND_OBJECT, 5620 DW_HWND_OBJECT,
5621 (HMENU)id, 5621 (HMENU)id,
5622 DWInstance, 5622 DWInstance,
5623 NULL); 5623 NULL);
5624 5624
5625 bubble->cinfo.fore = bubble->cinfo.back = -1; 5625 cinfo->fore = cinfo->back = -1;
5626 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); 5626 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc);
5627 5627
5628 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble); 5628 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
5629 5629
5630 _create_tooltip(tmp, text); 5630 _create_tooltip(tmp, text);
5631 5631
5632 if(icon) 5632 if(icon)
5633 { 5633 {
5650 * (BMP or ICO on OS/2 or Windows, XPM on Unix) 5650 * (BMP or ICO on OS/2 or Windows, XPM on Unix)
5651 */ 5651 */
5652 HWND API dw_bitmapbutton_new_from_file(char *text, unsigned long id, char *filename) 5652 HWND API dw_bitmapbutton_new_from_file(char *text, unsigned long id, char *filename)
5653 { 5653 {
5654 HWND tmp; 5654 HWND tmp;
5655 BubbleButton *bubble; 5655 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo));
5656 HBITMAP hbitmap = 0; 5656 HBITMAP hbitmap = 0;
5657 HANDLE hicon = 0; 5657 HANDLE hicon = 0;
5658 int windowtype = 0; 5658 int windowtype = 0;
5659 5659
5660 if (!(bubble = calloc(1, sizeof(BubbleButton)))) 5660 if (!cinfo)
5661 return 0; 5661 return 0;
5662 5662
5663 #ifdef GDIPLUS 5663 #ifdef GDIPLUS
5664 if((hicon = _dw_load_icon(filename))) 5664 if((hicon = _dw_load_icon(filename)))
5665 windowtype = BS_ICON; 5665 windowtype = BS_ICON;
5679 DW_HWND_OBJECT, 5679 DW_HWND_OBJECT,
5680 (HMENU)id, 5680 (HMENU)id,
5681 DWInstance, 5681 DWInstance,
5682 NULL); 5682 NULL);
5683 5683
5684 bubble->cinfo.fore = bubble->cinfo.back = -1; 5684 cinfo->fore = cinfo->back = -1;
5685 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); 5685 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc);
5686 5686
5687 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble); 5687 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
5688 5688
5689 _create_tooltip(tmp, text); 5689 _create_tooltip(tmp, text);
5690 5690
5691 if (hicon) 5691 if (hicon)
5692 { 5692 {
5709 * len: length of str 5709 * len: length of str
5710 */ 5710 */
5711 HWND API dw_bitmapbutton_new_from_data(char *text, unsigned long id, char *data, int len) 5711 HWND API dw_bitmapbutton_new_from_data(char *text, unsigned long id, char *data, int len)
5712 { 5712 {
5713 HWND tmp; 5713 HWND tmp;
5714 BubbleButton *bubble; 5714 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo));
5715 HBITMAP hbitmap = 0; 5715 HBITMAP hbitmap = 0;
5716 HANDLE hicon = 0; 5716 HANDLE hicon = 0;
5717 char *file; 5717 char *file;
5718 FILE *fp; 5718 FILE *fp;
5719 int windowtype = BS_BITMAP; 5719 int windowtype = BS_BITMAP;
5720 5720
5721 if ( !(bubble = calloc(1, sizeof(BubbleButton))) ) 5721 if (!cinfo)
5722 return 0; 5722 return 0;
5723
5723 file = _tempnam( _dw_alternate_temp_dir, "dw" ); 5724 file = _tempnam( _dw_alternate_temp_dir, "dw" );
5724 if ( file != NULL ) 5725 if ( file != NULL )
5725 { 5726 {
5726 fp = fopen( file, "wb" ); 5727 fp = fopen( file, "wb" );
5727 if ( fp != NULL ) 5728 if ( fp != NULL )
5762 DW_HWND_OBJECT, 5763 DW_HWND_OBJECT,
5763 (HMENU)id, 5764 (HMENU)id,
5764 DWInstance, 5765 DWInstance,
5765 NULL ); 5766 NULL );
5766 5767
5767 bubble->cinfo.fore = bubble->cinfo.back = -1; 5768 cinfo->fore = cinfo->back = -1;
5768 bubble->pOldProc = (WNDPROC)SubclassWindow( tmp, _BtProc ); 5769 cinfo->pOldProc = (WNDPROC)SubclassWindow( tmp, _BtProc );
5769 5770
5770 SetWindowLongPtr( tmp, GWLP_USERDATA, (LONG_PTR)bubble ); 5771 SetWindowLongPtr( tmp, GWLP_USERDATA, (LONG_PTR)cinfo );
5771 5772
5772 _create_tooltip(tmp, text); 5773 _create_tooltip(tmp, text);
5773 5774
5774 if ( hicon ) 5775 if ( hicon )
5775 { 5776 {
5852 0,0,0,0, 5853 0,0,0,0,
5853 DW_HWND_OBJECT, 5854 DW_HWND_OBJECT,
5854 (HMENU)id, 5855 (HMENU)id,
5855 DWInstance, 5856 DWInstance,
5856 NULL); 5857 NULL);
5857 BubbleButton *bubble = calloc(1, sizeof(BubbleButton)); 5858 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo));
5858 bubble->cinfo.fore = bubble->cinfo.back = -1; 5859 cinfo->fore = cinfo->back = -1;
5859 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); 5860 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc);
5860 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble); 5861 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
5861 dw_window_set_font(tmp, DefaultFont); 5862 dw_window_set_font(tmp, DefaultFont);
5862 return tmp; 5863 return tmp;
5863 } 5864 }
5864 5865
5865 5866
5942 * text: The text to be display by the static text widget. 5943 * text: The text to be display by the static text widget.
5943 * id: An ID to be used with dw_window_from_id() or 0L. 5944 * id: An ID to be used with dw_window_from_id() or 0L.
5944 */ 5945 */
5945 HWND API dw_checkbox_new(char *text, ULONG id) 5946 HWND API dw_checkbox_new(char *text, ULONG id)
5946 { 5947 {
5947 BubbleButton *bubble = calloc(1, sizeof(BubbleButton)); 5948 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo));
5948 HWND tmp = CreateWindow(BUTTONCLASSNAME, 5949 HWND tmp = CreateWindow(BUTTONCLASSNAME,
5949 text, 5950 text,
5950 WS_CHILD | BS_AUTOCHECKBOX | 5951 WS_CHILD | BS_AUTOCHECKBOX |
5951 BS_TEXT | WS_CLIPCHILDREN | WS_VISIBLE, 5952 BS_TEXT | WS_CLIPCHILDREN | WS_VISIBLE,
5952 0,0,0,0, 5953 0,0,0,0,
5953 DW_HWND_OBJECT, 5954 DW_HWND_OBJECT,
5954 (HMENU)id, 5955 (HMENU)id,
5955 DWInstance, 5956 DWInstance,
5956 NULL); 5957 NULL);
5957 bubble->checkbox = 1; 5958 cinfo->fore = cinfo->back = -1;
5958 bubble->cinfo.fore = bubble->cinfo.back = -1; 5959 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc);
5959 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); 5960 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
5960 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble); 5961 dw_window_set_data(tmp, "_dw_checkbox", DW_INT_TO_POINTER(1));
5961 dw_window_set_font(tmp, DefaultFont); 5962 dw_window_set_font(tmp, DefaultFont);
5962 return tmp; 5963 return tmp;
5963 } 5964 }
5964 5965
5965 /* 5966 /*
7620 7621
7621 GetClassName(handle, tmpbuf, 99); 7622 GetClassName(handle, tmpbuf, 99);
7622 7623
7623 if(strnicmp(tmpbuf, BUTTONCLASSNAME, strlen(BUTTONCLASSNAME)+1)==0) 7624 if(strnicmp(tmpbuf, BUTTONCLASSNAME, strlen(BUTTONCLASSNAME)+1)==0)
7624 { 7625 {
7625 BubbleButton *bubble= (BubbleButton *)GetWindowLongPtr(handle, GWLP_USERDATA); 7626 if(!dw_window_get_data(handle, "_dw_checkbox"))
7626
7627 if(bubble && !bubble->checkbox)
7628 SendMessage(handle, BM_SETCHECK, 0, 0); 7627 SendMessage(handle, BM_SETCHECK, 0, 0);
7629 } 7628 }
7630 return TRUE; 7629 return TRUE;
7631 } 7630 }
7632 /* 7631 /*
7635 * handle: Handle to the checkbox to be queried. 7634 * handle: Handle to the checkbox to be queried.
7636 * value: TRUE for checked, FALSE for unchecked. 7635 * value: TRUE for checked, FALSE for unchecked.
7637 */ 7636 */
7638 void API dw_checkbox_set(HWND handle, int value) 7637 void API dw_checkbox_set(HWND handle, int value)
7639 { 7638 {
7640 BubbleButton *bubble= (BubbleButton *)GetWindowLongPtr(handle, GWLP_USERDATA); 7639 if(!dw_window_get_data(handle, "_dw_checkbox"))
7641
7642 if(bubble && !bubble->checkbox)
7643 { 7640 {
7644 HWND parent = GetParent(handle); 7641 HWND parent = GetParent(handle);
7645 7642
7646 if(parent) 7643 if(parent)
7647 EnumChildWindows(parent, _uncheck_radios, 0); 7644 EnumChildWindows(parent, _uncheck_radios, 0);