Mercurial > dwindows
comparison os2/dw.c @ 365:eb86c22a9328
Implemented dw_bitmapbutton_new_from_file() on OS/2, and fixed
_load_bitmap_file() so it correctly loads OS/2 1.x bitmaps.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 27 Apr 2003 05:39:05 +0000 |
parents | eaebef97fc4f |
children | 4ed3b13ee48c |
comparison
equal
deleted
inserted
replaced
364:aa827971da39 | 365:eb86c22a9328 |
---|---|
31 #define QWP_USER 0 | 31 #define QWP_USER 0 |
32 | 32 |
33 MRESULT EXPENTRY _run_event(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2); | 33 MRESULT EXPENTRY _run_event(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2); |
34 void _do_resize(Box *thisbox, int x, int y); | 34 void _do_resize(Box *thisbox, int x, int y); |
35 void _handle_splitbar_resize(HWND hwnd, float percent, int type, int x, int y); | 35 void _handle_splitbar_resize(HWND hwnd, float percent, int type, int x, int y); |
36 int _load_bitmap_file(char *file, HWND handle, HBITMAP *hbm, HDC *hdc, HPS *hps, unsigned long *width, unsigned long *height); | |
36 | 37 |
37 char ClassName[] = "dynamicwindows"; | 38 char ClassName[] = "dynamicwindows"; |
38 char SplitbarClassName[] = "dwsplitbar"; | 39 char SplitbarClassName[] = "dwsplitbar"; |
39 char *DefaultFont = "9.WarpSans"; | 40 char *DefaultFont = "9.WarpSans"; |
40 | 41 |
251 void _free_bitmap(HWND handle) | 252 void _free_bitmap(HWND handle) |
252 { | 253 { |
253 HBITMAP hbm = (HBITMAP)dw_window_get_data(handle, "_dw_bitmap"); | 254 HBITMAP hbm = (HBITMAP)dw_window_get_data(handle, "_dw_bitmap"); |
254 HPS hps = (HPS)dw_window_get_data(handle, "_dw_hps"); | 255 HPS hps = (HPS)dw_window_get_data(handle, "_dw_hps"); |
255 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"); | |
258 | |
259 if(pixmap) | |
260 dw_pixmap_destroy(pixmap); | |
256 | 261 |
257 if(hps) | 262 if(hps) |
258 { | 263 { |
259 GpiSetBitmap(hps, NULLHANDLE); | 264 GpiSetBitmap(hps, NULLHANDLE); |
260 GpiAssociate(hps, NULLHANDLE); | 265 GpiAssociate(hps, NULLHANDLE); |
2769 WinReleasePS(hpsTemp); | 2774 WinReleasePS(hpsTemp); |
2770 } | 2775 } |
2771 return res; | 2776 return res; |
2772 } | 2777 } |
2773 | 2778 |
2779 MRESULT EXPENTRY _button_draw(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2, PFNWP oldproc) | |
2780 { | |
2781 HPIXMAP pixmap = (HPIXMAP)dw_window_get_data(hwnd, "_dw_hpixmap"); | |
2782 MRESULT res; | |
2783 | |
2784 if(!oldproc) | |
2785 res = WinDefWindowProc(hwnd, msg, mp1, mp2); | |
2786 res = oldproc(hwnd, msg, mp1, mp2); | |
2787 | |
2788 if(pixmap) | |
2789 { | |
2790 unsigned long width, height; | |
2791 int x, y; | |
2792 | |
2793 dw_window_get_pos_size(hwnd, NULL, NULL, &width, &height); | |
2794 | |
2795 x = (width - pixmap->width)/2; | |
2796 y = (height - pixmap->height)/2; | |
2797 | |
2798 dw_pixmap_bitblt(hwnd, 0, x, y, pixmap->width, pixmap->height, 0, pixmap, 0, 0); | |
2799 } | |
2800 return res; | |
2801 } | |
2802 | |
2774 /* Function: BtProc | 2803 /* Function: BtProc |
2775 * Abstract: Subclass procedure for buttons | 2804 * Abstract: Subclass procedure for buttons |
2776 */ | 2805 */ |
2777 | 2806 |
2778 MRESULT EXPENTRY _BtProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) | 2807 MRESULT EXPENTRY _BtProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) |
2787 | 2816 |
2788 oldproc = bubble->pOldProc; | 2817 oldproc = bubble->pOldProc; |
2789 | 2818 |
2790 switch(msg) | 2819 switch(msg) |
2791 { | 2820 { |
2821 case WM_PAINT: | |
2822 case WM_BUTTON2UP: | |
2823 case WM_BUTTON3UP: | |
2824 return _button_draw(hwnd, msg, mp1, mp2, oldproc); | |
2792 case WM_SETFOCUS: | 2825 case WM_SETFOCUS: |
2793 if(mp2) | 2826 if(mp2) |
2794 _run_event(hwnd, msg, mp1, mp2); | 2827 _run_event(hwnd, msg, mp1, mp2); |
2795 else | 2828 else |
2796 WinSendMsg(hwnd, BM_SETDEFAULT, 0, 0); | 2829 WinSendMsg(hwnd, BM_SETDEFAULT, 0, 0); |
2801 case WM_BUTTON1DBLCLK: | 2834 case WM_BUTTON1DBLCLK: |
2802 case WM_BUTTON2DBLCLK: | 2835 case WM_BUTTON2DBLCLK: |
2803 case WM_BUTTON3DBLCLK: | 2836 case WM_BUTTON3DBLCLK: |
2804 if(dw_window_get_data(hwnd, "_dw_disabled")) | 2837 if(dw_window_get_data(hwnd, "_dw_disabled")) |
2805 return (MRESULT)FALSE; | 2838 return (MRESULT)FALSE; |
2806 break; | 2839 return _button_draw(hwnd, msg, mp1, mp2, oldproc); |
2807 case WM_BUTTON1UP: | 2840 case WM_BUTTON1UP: |
2808 { | 2841 { |
2809 SignalHandler *tmp = Root; | 2842 SignalHandler *tmp = Root; |
2810 | 2843 |
2811 if(WinIsWindowEnabled(hwnd) && !dw_window_get_data(hwnd, "_dw_disabled")) | 2844 if(WinIsWindowEnabled(hwnd) && !dw_window_get_data(hwnd, "_dw_disabled")) |
2831 if(tmp) | 2864 if(tmp) |
2832 tmp= tmp->next; | 2865 tmp= tmp->next; |
2833 } | 2866 } |
2834 } | 2867 } |
2835 } | 2868 } |
2836 break; | 2869 return _button_draw(hwnd, msg, mp1, mp2, oldproc); |
2837 case WM_USER: | 2870 case WM_USER: |
2838 { | 2871 { |
2839 SignalHandler *tmp = (SignalHandler *)mp1; | 2872 SignalHandler *tmp = (SignalHandler *)mp1; |
2840 int (* API clickfunc)(HWND, void *) = NULL; | 2873 int (* API clickfunc)(HWND, void *) = NULL; |
2841 | 2874 |
4283 * DW pick the appropriate file extension. | 4316 * DW pick the appropriate file extension. |
4284 * (BMP on OS/2 or Windows, XPM on Unix) | 4317 * (BMP on OS/2 or Windows, XPM on Unix) |
4285 */ | 4318 */ |
4286 HWND dw_bitmapbutton_new_from_file(char *text, unsigned long id, char *filename) | 4319 HWND dw_bitmapbutton_new_from_file(char *text, unsigned long id, char *filename) |
4287 { | 4320 { |
4288 /* TODO: Actually get it to draw the bitmap */ | |
4289 BubbleButton *bubble = calloc(sizeof(BubbleButton), 1); | 4321 BubbleButton *bubble = calloc(sizeof(BubbleButton), 1); |
4290 HWND tmp = WinCreateWindow(HWND_OBJECT, | 4322 HWND tmp = WinCreateWindow(HWND_OBJECT, |
4291 WC_BUTTON, | 4323 WC_BUTTON, |
4292 "", | 4324 "", |
4293 WS_VISIBLE | BS_PUSHBUTTON | | 4325 WS_VISIBLE | BS_PUSHBUTTON | |
4294 BS_BITMAP | BS_AUTOSIZE | | 4326 BS_AUTOSIZE | BS_NOPOINTERFOCUS, |
4295 BS_NOPOINTERFOCUS, | |
4296 0,0,2000,1000, | 4327 0,0,2000,1000, |
4297 NULLHANDLE, | 4328 NULLHANDLE, |
4298 HWND_TOP, | 4329 HWND_TOP, |
4299 id, | 4330 id, |
4300 NULL, | 4331 NULL, |
4301 NULL); | 4332 NULL); |
4333 char *file = alloca(strlen(filename) + 5); | |
4334 HPIXMAP pixmap; | |
4335 | |
4336 if(file && (pixmap = calloc(1,sizeof(struct _hpixmap)))) | |
4337 { | |
4338 strcpy(file, filename); | |
4339 | |
4340 /* check if we can read from this file (it exists and read permission) */ | |
4341 if(access(file, 04) != 0) | |
4342 { | |
4343 /* Try with .bmp extention */ | |
4344 strcat(file, ".bmp"); | |
4345 if(access(file, 04) != 0) | |
4346 { | |
4347 free(pixmap); | |
4348 pixmap = NULL; | |
4349 } | |
4350 } | |
4351 | |
4352 /* Try to load the bitmap from file */ | |
4353 if(pixmap) | |
4354 _load_bitmap_file(file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height); | |
4355 } | |
4302 | 4356 |
4303 bubble->id = id; | 4357 bubble->id = id; |
4304 strncpy(bubble->bubbletext, text, BUBBLE_HELP_MAX - 1); | 4358 strncpy(bubble->bubbletext, text, BUBBLE_HELP_MAX - 1); |
4305 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0'; | 4359 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0'; |
4306 bubble->pOldProc = WinSubclassWindow(tmp, _BtProc); | 4360 bubble->pOldProc = WinSubclassWindow(tmp, _BtProc); |
4307 | 4361 |
4308 WinSetWindowPtr(tmp, QWP_USER, bubble); | 4362 WinSetWindowPtr(tmp, QWP_USER, bubble); |
4363 | |
4364 dw_window_set_data(tmp, "_dw_hpixmap", (void *)pixmap); | |
4309 return tmp; | 4365 return tmp; |
4310 } | 4366 } |
4311 | 4367 |
4312 /* | 4368 /* |
4313 * Create a new spinbutton window (widget) to be packed. | 4369 * Create a new spinbutton window (widget) to be packed. |
4578 pBitmapInfoHeader = &pBitmapFileHeader->bmp2; | 4634 pBitmapInfoHeader = &pBitmapFileHeader->bmp2; |
4579 | 4635 |
4580 /* find out if it's the new 2.0 format or the old format */ | 4636 /* find out if it's the new 2.0 format or the old format */ |
4581 /* and query number of lines */ | 4637 /* and query number of lines */ |
4582 if(pBitmapInfoHeader->cbFix == sizeof(BITMAPINFOHEADER)) | 4638 if(pBitmapInfoHeader->cbFix == sizeof(BITMAPINFOHEADER)) |
4583 ScanLines = (ULONG)((PBITMAPINFOHEADER)pBitmapInfoHeader)->cy; | 4639 { |
4640 *height = ScanLines = (ULONG)((PBITMAPINFOHEADER)pBitmapInfoHeader)->cy; | |
4641 *width = (ULONG)((PBITMAPINFOHEADER)pBitmapInfoHeader)->cx; | |
4642 } | |
4584 else | 4643 else |
4585 ScanLines = pBitmapInfoHeader->cy; | 4644 { |
4645 *height = ScanLines = pBitmapInfoHeader->cy; | |
4646 *width = pBitmapInfoHeader->cx; | |
4647 } | |
4586 | 4648 |
4587 /* now we need a presentation space, get it from static control */ | 4649 /* now we need a presentation space, get it from static control */ |
4588 hps1 = WinGetPS(handle); | 4650 hps1 = WinGetPS(handle); |
4589 | 4651 |
4590 hdc1 = GpiQueryDevice(hps1); | 4652 hdc1 = GpiQueryDevice(hps1); |
4591 ulFlags = GpiQueryPS(hps1, &sizl); | 4653 ulFlags = GpiQueryPS(hps1, &sizl); |
4592 | 4654 |
4593 *hdc = DevOpenDC(dwhab, OD_MEMORY, "*", 0L, NULL, hdc1); | 4655 *hdc = DevOpenDC(dwhab, OD_MEMORY, "*", 0L, NULL, hdc1); |
4594 *hps = GpiCreatePS (dwhab, *hdc, &sizl, ulFlags | GPIA_ASSOC); | 4656 *hps = GpiCreatePS (dwhab, *hdc, &sizl, ulFlags | GPIA_ASSOC); |
4595 | |
4596 *width = pBitmapInfoHeader->cx; *height = pBitmapInfoHeader->cy; | |
4597 | 4657 |
4598 /* create bitmap now using the parameters from the info block */ | 4658 /* create bitmap now using the parameters from the info block */ |
4599 *hbm = GpiCreateBitmap(*hps, pBitmapInfoHeader, 0L, NULL, NULL); | 4659 *hbm = GpiCreateBitmap(*hps, pBitmapInfoHeader, 0L, NULL, NULL); |
4600 | 4660 |
4601 /* select the new bitmap into presentation space */ | 4661 /* select the new bitmap into presentation space */ |