comparison os2/dw.c @ 546:dac29596615d

Added icon support to dw_bitmapbutton_from_file() but it seems to be using the large icon sizes which are too big for the Rexx/DW test program.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 04 Apr 2004 18:39:17 +0000
parents 11e3d5e3543c
children 291f3eae2c25
comparison
equal deleted inserted replaced
545:11e3d5e3543c 546:dac29596615d
3004 3004
3005 MRESULT EXPENTRY _button_draw(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2, PFNWP oldproc, int indent) 3005 MRESULT EXPENTRY _button_draw(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2, PFNWP oldproc, int indent)
3006 { 3006 {
3007 HPIXMAP pixmap = (HPIXMAP)dw_window_get_data(hwnd, "_dw_hpixmap"); 3007 HPIXMAP pixmap = (HPIXMAP)dw_window_get_data(hwnd, "_dw_hpixmap");
3008 HPIXMAP disable = (HPIXMAP)dw_window_get_data(hwnd, "_dw_hpixmap_disabled"); 3008 HPIXMAP disable = (HPIXMAP)dw_window_get_data(hwnd, "_dw_hpixmap_disabled");
3009 HPOINTER icon = (HPOINTER)dw_window_get_data(hwnd, "_dw_button_icon");
3009 MRESULT res; 3010 MRESULT res;
3010 3011
3011 if(!oldproc) 3012 if(!oldproc)
3012 res = WinDefWindowProc(hwnd, msg, mp1, mp2); 3013 res = WinDefWindowProc(hwnd, msg, mp1, mp2);
3013 res = oldproc(hwnd, msg, mp1, mp2); 3014 res = oldproc(hwnd, msg, mp1, mp2);
3014 3015
3015 if(pixmap) 3016 if(icon)
3017 {
3018 ULONG halftone = DP_NORMAL;
3019 HPS hps = WinGetPS(hwnd);
3020
3021 if(dw_window_get_data(hwnd, "_dw_disabled"))
3022 halftone = DP_HALFTONED;
3023
3024 WinDrawPointer(hps, 5, 5, icon, halftone);
3025 WinReleasePS(hps);
3026 }
3027 else if(pixmap)
3016 { 3028 {
3017 unsigned long width, height; 3029 unsigned long width, height;
3018 int x, y; 3030 int x, y;
3019 3031
3020 dw_window_get_pos_size(hwnd, NULL, NULL, &width, &height); 3032 dw_window_get_pos_size(hwnd, NULL, NULL, &width, &height);
4643 id, 4655 id,
4644 NULL, 4656 NULL,
4645 NULL); 4657 NULL);
4646 char *file = alloca(strlen(filename) + 5); 4658 char *file = alloca(strlen(filename) + 5);
4647 HPIXMAP pixmap = NULL, disabled = NULL; 4659 HPIXMAP pixmap = NULL, disabled = NULL;
4660 HPOINTER icon = 0;
4648 4661
4649 if(file && (pixmap = calloc(1,sizeof(struct _hpixmap)))) 4662 if(file && (pixmap = calloc(1,sizeof(struct _hpixmap))))
4650 { 4663 {
4651 int z, j, lim; 4664 int z, j, lim, len;
4652 LONG fore; 4665 LONG fore;
4653 4666
4654 strcpy(file, filename); 4667 strcpy(file, filename);
4655 4668
4656 /* check if we can read from this file (it exists and read permission) */ 4669 /* check if we can read from this file (it exists and read permission) */
4657 if(access(file, 04) != 0) 4670 if(access(file, 04) == 0)
4658 { 4671 {
4659 /* Try with .bmp extention */ 4672 len = strlen( file );
4660 strcat(file, ".bmp"); 4673 if(len > 4)
4661 if(access(file, 04) != 0)
4662 { 4674 {
4663 #if 0 /* don't free pixmap if bitmap doesn't exist; causes crash several lines below */ 4675 if(stricmp(file + len - 4, ".ico") == 0)
4664 free(pixmap); 4676 icon = WinLoadFileIcon(file, FALSE);
4665 pixmap = NULL; 4677 else
4666 #endif 4678 _load_bitmap_file(file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height);
4667 } 4679 }
4668 } 4680 }
4669 4681 else
4670 /* Try to load the bitmap from file */ 4682 {
4671 if(pixmap) 4683 /* Try with .ico extension first...*/
4672 _load_bitmap_file(file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height); 4684 strcat(file, ".ico");
4673 4685 if(access(file, 04) == 0)
4674 /* Create a disabled style pixmap */ 4686 icon = WinLoadFileIcon(file, FALSE);
4675 disabled = dw_pixmap_new(tmp, pixmap->width, pixmap->height, dw_color_depth_get()); 4687 else
4676 dw_pixmap_bitblt(0, disabled, 0, 0, pixmap->width, pixmap->height, 0, pixmap, 0, 0); 4688 {
4677 4689 strcpy(file, filename);
4678 fore = _foreground; 4690 strcat(file, ".bmp");
4679 dw_color_foreground_set(DW_CLR_PALEGRAY); 4691 if(access(file, 04) == 0)
4680 lim = pixmap->width/2; 4692 _load_bitmap_file(file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height);
4681 for(j=0;j<pixmap->height;j++) 4693 }
4682 { 4694 }
4683 int mod = j%2; 4695
4684 4696 if(icon)
4685 for(z=0;z<lim;z++) 4697 {
4686 dw_draw_point(0, disabled, (z*2)+mod, j); 4698 free(pixmap);
4687 } 4699 pixmap = NULL;
4688 _foreground = fore; 4700 }
4701 else
4702 {
4703 /* Create a disabled style pixmap */
4704 disabled = dw_pixmap_new(tmp, pixmap->width, pixmap->height, dw_color_depth_get());
4705 dw_pixmap_bitblt(0, disabled, 0, 0, pixmap->width, pixmap->height, 0, pixmap, 0, 0);
4706
4707 fore = _foreground;
4708 dw_color_foreground_set(DW_CLR_PALEGRAY);
4709 lim = pixmap->width/2;
4710 for(j=0;j<pixmap->height;j++)
4711 {
4712 int mod = j%2;
4713
4714 for(z=0;z<lim;z++)
4715 dw_draw_point(0, disabled, (z*2)+mod, j);
4716 }
4717 _foreground = fore;
4718 }
4689 } 4719 }
4690 4720
4691 bubble->id = id; 4721 bubble->id = id;
4692 strncpy(bubble->bubbletext, text, BUBBLE_HELP_MAX - 1); 4722 strncpy(bubble->bubbletext, text, BUBBLE_HELP_MAX - 1);
4693 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0'; 4723 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0';
4694 bubble->pOldProc = WinSubclassWindow(tmp, _BtProc); 4724 bubble->pOldProc = WinSubclassWindow(tmp, _BtProc);
4695 4725
4696 WinSetWindowPtr(tmp, QWP_USER, bubble); 4726 WinSetWindowPtr(tmp, QWP_USER, bubble);
4697 4727
4698 dw_window_set_data(tmp, "_dw_hpixmap", (void *)pixmap); 4728 if(icon)
4699 dw_window_set_data(tmp, "_dw_hpixmap_disabled", (void *)disabled); 4729 dw_window_set_data(tmp, "_dw_button_icon", (void *)icon);
4730 else
4731 {
4732 dw_window_set_data(tmp, "_dw_hpixmap", (void *)pixmap);
4733 dw_window_set_data(tmp, "_dw_hpixmap_disabled", (void *)disabled);
4734 }
4700 dw_window_set_data(tmp, "_dw_bitmapbutton", (void *)1); 4735 dw_window_set_data(tmp, "_dw_bitmapbutton", (void *)1);
4701 return tmp; 4736 return tmp;
4702 } 4737 }
4703 4738
4704 /* 4739 /*