comparison win/dw.c @ 614:0ab21b3b1d52

Attempt auto resizing of window based on widget sizes; not very successful. Add *from_data() functions
author mhessling@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 23 Mar 2008 05:14:32 +0000
parents c5e5671dec8f
children 4d1d9aeb0bbc
comparison
equal deleted inserted replaced
613:f7d318cffc3e 614:0ab21b3b1d52
3166 3166
3167 /* This function determines the handle for a supplied image filename 3167 /* This function determines the handle for a supplied image filename
3168 */ 3168 */
3169 int _dw_get_image_handle(char *filename, HANDLE *icon, HBITMAP *hbitmap) 3169 int _dw_get_image_handle(char *filename, HANDLE *icon, HBITMAP *hbitmap)
3170 { 3170 {
3171 int len, windowtype = 0; 3171 int len, windowtype = 0;
3172 char *file = malloc(strlen(filename) + 5); 3172 char *file = malloc(strlen(filename) + 5);
3173 3173
3174 *hbitmap = 0; 3174 *hbitmap = 0;
3175 *icon = 0; 3175 *icon = 0;
3176 3176
3177 if(!file) 3177 if (!file)
3178 { 3178 {
3179 return 0; 3179 return 0;
3180 } 3180 }
3181 3181
3182 strcpy(file, filename); 3182 strcpy(file, filename);
3183 3183
3184 /* check if we can read from this file (it exists and read permission) */ 3184 /* check if we can read from this file (it exists and read permission) */
3185 if(access(file, 04) == 0) 3185 if (access(file, 04) == 0)
3186 { 3186 {
3187 len = strlen( file ); 3187 len = strlen( file );
3188 if ( len < 4 ) 3188 if ( len < 4 )
3189 { 3189 {
3190 free(file); 3190 free(file);
3191 return 0; 3191 return 0;
3192 } 3192 }
3193 if ( stricmp( file + len - 4, ".ico" ) == 0 ) 3193 if ( stricmp( file + len - 4, ".ico" ) == 0 )
3194 { 3194 {
3195 *icon = LoadImage(NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE); 3195 *icon = LoadImage(NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
3196 windowtype = BS_ICON; 3196 windowtype = BS_ICON;
3197 } 3197 }
3198 else if ( stricmp( file + len - 4, ".bmp" ) == 0 ) 3198 else if ( stricmp( file + len - 4, ".bmp" ) == 0 )
3199 { 3199 {
3200 *hbitmap = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); 3200 *hbitmap = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
3201 windowtype = BS_BITMAP; 3201 windowtype = BS_BITMAP;
3202 } 3202 }
3203 free(file); 3203 free(file);
3204 } 3204 }
3205 else 3205 else
3206 { 3206 {
3207 /* Try with .ico extension first...*/ 3207 /* Try with .ico extension first...*/
3208 strcat(file, ".ico"); 3208 strcat(file, ".ico");
3209 if(access(file, 04) == 0) 3209 if (access(file, 04) == 0)
3210 { 3210 {
3211 *icon = LoadImage(NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE); 3211 *icon = LoadImage(NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
3212 windowtype = BS_ICON; 3212 windowtype = BS_ICON;
3213 } 3213 }
3214 else 3214 else
3215 { 3215 {
3216 strcpy(file, filename); 3216 strcpy(file, filename);
3217 strcat(file, ".bmp"); 3217 strcat(file, ".bmp");
3218 if(access(file, 04) == 0) 3218 if (access(file, 04) == 0)
3219 { 3219 {
3220 *hbitmap = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); 3220 *hbitmap = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
3221 windowtype = BS_BITMAP; 3221 windowtype = BS_BITMAP;
3222 } 3222 }
3223 } 3223 }
3224 free(file); 3224 free(file);
3225 } 3225 }
3226 3226 return windowtype;
3227 return windowtype;
3228 } 3227 }
3229 3228
3230 /* 3229 /*
3231 * Initializes the Dynamic Windows engine. 3230 * Initializes the Dynamic Windows engine.
3232 * Parameters: 3231 * Parameters:
3508 * ...: Additional variables for use in the format. 3507 * ...: Additional variables for use in the format.
3509 */ 3508 */
3510 int API dw_messagebox(char *title, int flags, char *format, ...) 3509 int API dw_messagebox(char *title, int flags, char *format, ...)
3511 { 3510 {
3512 va_list args; 3511 va_list args;
3513 char outbuf[256]; 3512 char outbuf[1024];
3514 int rc; 3513 int rc;
3515 3514
3516 va_start(args, format); 3515 va_start(args, format);
3517 vsprintf(outbuf, format, args); 3516 vsprintf(outbuf, format, args);
3518 va_end(args); 3517 va_end(args);
4233 * id: Menuitem id. 4232 * id: Menuitem id.
4234 * check: TRUE for checked FALSE for not checked. 4233 * check: TRUE for checked FALSE for not checked.
4235 */ 4234 */
4236 void API dw_menu_item_set_check(HMENUI menux, unsigned long id, int check) 4235 void API dw_menu_item_set_check(HMENUI menux, unsigned long id, int check)
4237 { 4236 {
4238 MENUITEMINFO mii; 4237 MENUITEMINFO mii;
4239 HMENU mymenu = (HMENU)menux; 4238 HMENU mymenu = (HMENU)menux;
4240 4239
4241 if(IsWindow(menux) && !IsMenu(mymenu)) 4240 if (IsWindow(menux) && !IsMenu(mymenu))
4242 mymenu = (HMENU)dw_window_get_data(menux, "_dw_menu"); 4241 mymenu = (HMENU)dw_window_get_data(menux, "_dw_menu");
4243 4242
4244 mii.cbSize = sizeof(MENUITEMINFO); 4243 memset( &mii, 0, sizeof(MENUITEMINFO) );
4245 mii.fMask = MIIM_STATE; 4244 mii.cbSize = sizeof(MENUITEMINFO);
4246 if(check) 4245 mii.fMask = MIIM_STATE;
4247 mii.fState = MFS_CHECKED; 4246 if (check)
4248 else 4247 mii.fState = MFS_CHECKED;
4249 mii.fState = MFS_UNCHECKED; 4248 else
4250 SetMenuItemInfo(mymenu, id, FALSE, &mii); 4249 mii.fState = MFS_UNCHECKED;
4250 SetMenuItemInfo( mymenu, id, FALSE, &mii );
4251 } 4251 }
4252 4252
4253 #if 0 4253 #if 0
4254 /* 4254 /*
4255 * TBD 4255 * TBD
4592 * text: The text to be display by the static text widget. 4592 * text: The text to be display by the static text widget.
4593 * id: An ID to be used with dw_window_from_id() or 0L. 4593 * id: An ID to be used with dw_window_from_id() or 0L.
4594 */ 4594 */
4595 HWND API dw_button_new(char *text, ULONG id) 4595 HWND API dw_button_new(char *text, ULONG id)
4596 { 4596 {
4597 BubbleButton *bubble = calloc(1, sizeof(BubbleButton)); 4597 BubbleButton *bubble = calloc(1, sizeof(BubbleButton));
4598 4598
4599 HWND tmp = CreateWindow(BUTTONCLASSNAME, 4599 HWND tmp = CreateWindow(BUTTONCLASSNAME,
4600 text, 4600 text,
4601 WS_CHILD | BS_PUSHBUTTON | 4601 WS_CHILD | BS_PUSHBUTTON |
4602 WS_VISIBLE | WS_CLIPCHILDREN, 4602 WS_VISIBLE | WS_CLIPCHILDREN,
4603 0,0,2000,1000, 4603 0,0,2000,1000,
4604 DW_HWND_OBJECT, 4604 DW_HWND_OBJECT,
4605 (HMENU)id, 4605 (HMENU)id,
4606 DWInstance, 4606 DWInstance,
4607 NULL); 4607 NULL);
4608 4608
4609 bubble->id = id; 4609 bubble->id = id;
4610 bubble->bubbletext[0] = '\0'; 4610 bubble->bubbletext[0] = '\0';
4611 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); 4611 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc);
4612 4612
4613 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble); 4613 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble);
4614 dw_window_set_font(tmp, DefaultFont); 4614 dw_window_set_font(tmp, DefaultFont);
4615 return tmp; 4615 return tmp;
4616 } 4616 }
4617 4617
4618 /* 4618 /*
4619 * Create a new bitmap button window (widget) to be packed. 4619 * Create a new bitmap button window (widget) to be packed.
4620 * Parameters: 4620 * Parameters:
4676 BubbleButton *bubble; 4676 BubbleButton *bubble;
4677 HBITMAP hbitmap = 0; 4677 HBITMAP hbitmap = 0;
4678 HANDLE icon = 0; 4678 HANDLE icon = 0;
4679 int windowtype = 0, len; 4679 int windowtype = 0, len;
4680 4680
4681 if(!(bubble = calloc(1, sizeof(BubbleButton)))) 4681 if (!(bubble = calloc(1, sizeof(BubbleButton))))
4682 return 0; 4682 return 0;
4683 4683
4684 windowtype = _dw_get_image_handle(filename, &icon, &hbitmap); 4684 windowtype = _dw_get_image_handle(filename, &icon, &hbitmap);
4685 4685
4686 tmp = CreateWindow(BUTTONCLASSNAME, 4686 tmp = CreateWindow( BUTTONCLASSNAME,
4687 "", 4687 "",
4688 WS_CHILD | BS_PUSHBUTTON | 4688 // label_text,
4689 windowtype | WS_CLIPCHILDREN | 4689 // WS_CHILD | BS_OWNERDRAW | WS_CLIPCHILDREN | WS_VISIBLE,
4690 WS_VISIBLE, 4690 windowtype | WS_CHILD | BS_PUSHBUTTON | WS_CLIPCHILDREN | WS_VISIBLE,
4691 0,0,2000,1000, 4691 0,0,2000,1000,
4692 DW_HWND_OBJECT, 4692 DW_HWND_OBJECT,
4693 (HMENU)id, 4693 (HMENU)id,
4694 DWInstance, 4694 DWInstance,
4695 NULL); 4695 NULL);
4696 4696
4697 bubble->id = id; 4697 bubble->id = id;
4698 strncpy(bubble->bubbletext, text, BUBBLE_HELP_MAX - 1); 4698 strncpy(bubble->bubbletext, text, BUBBLE_HELP_MAX - 1);
4699 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0'; 4699 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0';
4700 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); 4700 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc);
4701 4701
4702 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble); 4702 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble);
4703 4703
4704 if(icon) 4704 if (icon)
4705 { 4705 {
4706 SendMessage(tmp, BM_SETIMAGE, 4706 SendMessage(tmp, BM_SETIMAGE,(WPARAM) IMAGE_ICON,(LPARAM) icon);
4707 (WPARAM) IMAGE_ICON,
4708 (LPARAM) icon);
4709 } 4707 }
4710 else if(hbitmap) 4708 else if (hbitmap)
4711 { 4709 {
4712 SendMessage(tmp, BM_SETIMAGE, 4710 SendMessage(tmp, BM_SETIMAGE,(WPARAM) IMAGE_BITMAP, (LPARAM) hbitmap);
4713 (WPARAM) IMAGE_BITMAP, 4711 }
4714 (LPARAM) hbitmap); 4712 return tmp;
4713 }
4714
4715 /*
4716 * Create a new bitmap button window (widget) to be packed from data.
4717 * Parameters:
4718 * text: Bubble help text to be displayed.
4719 * id: An ID to be used with dw_window_from_id() or 0L.
4720 * data: The contents of the image
4721 * (BMP or ICO on OS/2 or Windows, XPM on Unix)
4722 * len: length of str
4723 */
4724 HWND API dw_bitmapbutton_new_from_data(char *text, unsigned long id, char *data, int len)
4725 {
4726 HWND tmp;
4727 BubbleButton *bubble;
4728 HBITMAP hbitmap = 0;
4729 HANDLE icon = 0;
4730 char *file;
4731 FILE *fp;
4732 int windowtype;
4733
4734 if ( !(bubble = calloc(1, sizeof(BubbleButton))) )
4735 return 0;
4736 file = tmpnam( NULL );
4737 if ( file != NULL )
4738 {
4739 fp = fopen( file, "wb" );
4740 if ( fp != NULL )
4741 {
4742 fwrite( data, 1, len, fp );
4743 fclose( fp );
4744 if ( len > 1 && data[0] == 'B' && data[1] == 'M' ) /* first 2 chars of data is BM, then its a BMP */
4745 {
4746 hbitmap = (HBITMAP)LoadImage( NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
4747 windowtype = BS_BITMAP;
4748 }
4749 else /* otherwise its assumed to be an ico */
4750 {
4751 icon = LoadImage( NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE );
4752 windowtype = BS_ICON;
4753 }
4754 }
4755 else
4756 {
4757 unlink( file );
4758 return 0;
4759 }
4760 unlink( file );
4761 }
4762
4763 tmp = CreateWindow( BUTTONCLASSNAME,
4764 "",
4765 WS_CHILD | BS_PUSHBUTTON |
4766 windowtype | WS_CLIPCHILDREN |
4767 WS_VISIBLE,
4768 0,0,2000,1000,
4769 DW_HWND_OBJECT,
4770 (HMENU)id,
4771 DWInstance,
4772 NULL );
4773
4774 bubble->id = id;
4775 strncpy( bubble->bubbletext, text, BUBBLE_HELP_MAX - 1 );
4776 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0';
4777 bubble->pOldProc = (WNDPROC)SubclassWindow( tmp, _BtProc );
4778
4779 SetWindowLongPtr( tmp, GWLP_USERDATA, (LONG_PTR)bubble );
4780
4781 if ( icon )
4782 {
4783 SendMessage( tmp, BM_SETIMAGE,
4784 (WPARAM) IMAGE_ICON,
4785 (LPARAM) icon);
4786 }
4787 else if( hbitmap )
4788 {
4789 SendMessage( tmp, BM_SETIMAGE,
4790 (WPARAM) IMAGE_BITMAP,
4791 (LPARAM) hbitmap);
4715 } 4792 }
4716 return tmp; 4793 return tmp;
4717 } 4794 }
4718 4795
4719 /* 4796 /*
4941 5018
4942 SendMessage(handle, WM_SETICON, 5019 SendMessage(handle, WM_SETICON,
4943 (WPARAM) IMAGE_ICON, 5020 (WPARAM) IMAGE_ICON,
4944 (LPARAM) hicon); 5021 (LPARAM) hicon);
4945 } 5022 }
5023
4946 /* 5024 /*
4947 * Sets the bitmap used for a given static window. 5025 * Sets the bitmap used for a given static window.
4948 * Parameters: 5026 * Parameters:
4949 * handle: Handle to the window. 5027 * handle: Handle to the window.
4950 * id: An ID to be used to specify the icon, 5028 * id: An ID to be used to specify the icon,
4993 5071
4994 if(hbitmap && oldbitmap) 5072 if(hbitmap && oldbitmap)
4995 DeleteObject(oldbitmap); 5073 DeleteObject(oldbitmap);
4996 else if(icon && oldicon) 5074 else if(icon && oldicon)
4997 DeleteObject(oldicon); 5075 DeleteObject(oldicon);
5076 }
5077
5078 /*
5079 * Sets the bitmap used for a given static window from data.
5080 * Parameters:
5081 * handle: Handle to the window.
5082 * id: An ID to be used to specify the icon,
5083 * (pass 0 if you use the data param)
5084 * data: the image from meory
5085 * Bitmap on Windows and a pixmap on Unix, pass
5086 * NULL if you use the id param)
5087 * len: length of data
5088 */
5089 void API dw_window_set_bitmap_from_data(HWND handle, unsigned long id, char *data, int len)
5090 {
5091 HBITMAP hbitmap=0;
5092 HBITMAP oldbitmap = (HBITMAP)SendMessage(handle, STM_GETIMAGE, IMAGE_BITMAP, 0);
5093 HICON icon=0;
5094 HICON oldicon = (HICON)SendMessage(handle, STM_GETIMAGE, IMAGE_ICON, 0);
5095 char *file;
5096 FILE *fp;
5097
5098 if ( id )
5099 {
5100 hbitmap = LoadBitmap( DWInstance, MAKEINTRESOURCE(id) );
5101 icon = LoadImage( DWInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, LR_SHARED );
5102 }
5103 else if (data)
5104 {
5105 file = tmpnam( NULL );
5106 if ( file != NULL )
5107 {
5108 fp = fopen( file, "wb" );
5109 if ( fp != NULL )
5110 {
5111 fwrite( data, 1, len, fp );
5112 fclose( fp );
5113 if ( len > 1 && data[0] == 'B' && data[1] == 'M' ) /* first 2 chars of data is BM, then its a BMP */
5114 hbitmap = (HBITMAP)LoadImage( NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
5115 else /* otherwise its assumed to be an ico */
5116 icon = LoadImage( NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE );
5117 }
5118 else
5119 {
5120 unlink( file );
5121 return;
5122 }
5123 unlink( file );
5124 }
5125 if (icon == 0 && hbitmap == 0)
5126 return;
5127 }
5128
5129 if ( icon )
5130 {
5131 SendMessage( handle, BM_SETIMAGE,
5132 (WPARAM) IMAGE_ICON,
5133 (LPARAM) icon );
5134 SendMessage( handle, STM_SETIMAGE,
5135 (WPARAM) IMAGE_ICON,
5136 (LPARAM) icon );
5137 }
5138 else if ( hbitmap )
5139 {
5140 SendMessage( handle, BM_SETIMAGE,
5141 (WPARAM) IMAGE_BITMAP,
5142 (LPARAM) hbitmap );
5143 SendMessage( handle, STM_SETIMAGE,
5144 (WPARAM) IMAGE_BITMAP,
5145 (LPARAM) hbitmap );
5146 }
5147
5148 if( hbitmap && oldbitmap )
5149 DeleteObject( oldbitmap );
5150 else if ( icon && oldicon )
5151 DeleteObject( oldicon );
4998 } 5152 }
4999 5153
5000 5154
5001 /* 5155 /*
5002 * Sets the text used for a given window. 5156 * Sets the text used for a given window.
5188 * width: New width in pixels. 5342 * width: New width in pixels.
5189 * height: New height in pixels. 5343 * height: New height in pixels.
5190 */ 5344 */
5191 void API dw_window_set_size(HWND handle, ULONG width, ULONG height) 5345 void API dw_window_set_size(HWND handle, ULONG width, ULONG height)
5192 { 5346 {
5193 SetWindowPos(handle, (HWND)NULL, 0, 0, width, height, SWP_SHOWWINDOW | SWP_NOZORDER | SWP_NOMOVE); 5347 int usedx = 0, usedy = 0, depth = 0, usedpadx = 0, usedpady = 0;
5348 Box *thisbox;
5349 /*
5350 * The following is an attempt to dynamically size a window based on the size of its
5351 * children before realization. Only applicable when width or height is zero.
5352 * It doesn't work vey well :-(
5353 */
5354 thisbox = (Box *)GetWindowLongPtr(handle, GWLP_USERDATA);
5355 if ( thisbox )
5356 {
5357 _resize_box(thisbox, &depth, 0, 0, &usedx, &usedy, 1, &usedpadx, &usedpady);
5358 _resize_box(thisbox, &depth, usedx, usedy, &usedx, &usedy, 2, &usedpadx, &usedpady);
5359 }
5360 if ( width == 0 ) width = usedx;
5361 if ( height == 0 ) height = usedy;
5362 SetWindowPos(handle, (HWND)NULL, 0, 0, width, height, SWP_SHOWWINDOW | SWP_NOZORDER | SWP_NOMOVE);
5194 } 5363 }
5195 5364
5196 /* 5365 /*
5197 * Returns the width of the screen. 5366 * Returns the width of the screen.
5198 */ 5367 */
5244 * width: Width of the widget. 5413 * width: Width of the widget.
5245 * height: Height of the widget. 5414 * height: Height of the widget.
5246 */ 5415 */
5247 void API dw_window_set_pos_size(HWND handle, ULONG x, ULONG y, ULONG width, ULONG height) 5416 void API dw_window_set_pos_size(HWND handle, ULONG x, ULONG y, ULONG width, ULONG height)
5248 { 5417 {
5249 SetWindowPos(handle, (HWND)NULL, x, y, width, height, SWP_NOZORDER | SWP_SHOWWINDOW | SWP_NOACTIVATE); 5418 int usedx = 0, usedy = 0, depth = 0, usedpadx = 0, usedpady = 0;
5419 Box *thisbox;
5420 /*
5421 * The following is an attempt to dynamically size a window based on the size of its
5422 * children before realization. Only applicable when width or height is zero.
5423 * It doesn't work vey well :-(
5424 */
5425 thisbox = (Box *)GetWindowLongPtr(handle, GWLP_USERDATA);
5426 if ( thisbox )
5427 {
5428 _resize_box(thisbox, &depth, 0, 0, &usedx, &usedy, 1, &usedpadx, &usedpady);
5429 _resize_box(thisbox, &depth, usedx, usedy, &usedx, &usedy, 2, &usedpadx, &usedpady);
5430 }
5431 SetWindowPos(handle, (HWND)NULL, x, y, width, height, SWP_NOZORDER | SWP_SHOWWINDOW | SWP_NOACTIVATE);
5250 } 5432 }
5251 5433
5252 /* 5434 /*
5253 * Gets the position and size of a given window (widget). 5435 * Gets the position and size of a given window (widget).
5254 * Parameters: 5436 * Parameters:
6663 } 6845 }
6664 } 6846 }
6665 icon = LoadImage(NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE); 6847 icon = LoadImage(NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
6666 free(file); 6848 free(file);
6667 return (unsigned long)icon; 6849 return (unsigned long)icon;
6850 }
6851
6852 /*
6853 * Obtains an icon from data
6854 * Parameters:
6855 * data: Source of icon data
6856 * DW pick the appropriate file extension.
6857 * (ICO on OS/2 or Windows, XPM on Unix)
6858 */
6859 unsigned long API dw_icon_load_from_data(char *data, int len)
6860 {
6861 HANDLE icon;
6862 char *file;
6863 FILE *fp;
6864
6865 if ( !data )
6866 return 0;
6867 file = tmpnam( NULL );
6868 if ( file != NULL )
6869 {
6870 fp = fopen( file, "wb" );
6871 if ( fp != NULL )
6872 {
6873 fwrite( data, 1, len, fp );
6874 fclose( fp );
6875 icon = LoadImage( NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE );
6876 }
6877 else
6878 {
6879 unlink( file );
6880 return 0;
6881 }
6882 unlink( file );
6883 }
6884 return (unsigned long)icon;
6668 } 6885 }
6669 6886
6670 /* 6887 /*
6671 * Frees a loaded resource in OS/2 and Windows. 6888 * Frees a loaded resource in OS/2 and Windows.
6672 * Parameters: 6889 * Parameters:
7723 ReleaseDC(handle, hdc); 7940 ReleaseDC(handle, hdc);
7724 7941
7725 free(file); 7942 free(file);
7726 7943
7727 return pixmap; 7944 return pixmap;
7945 }
7946
7947 /*
7948 * Creates a pixmap from memory.
7949 * Parameters:
7950 * handle: Window handle the pixmap is associated with.
7951 * data: Source of the image data
7952 * (BMP on OS/2 or Windows, XPM on Unix)
7953 * le: length of data
7954 * Returns:
7955 * A handle to a pixmap or NULL on failure.
7956 */
7957 HPIXMAP API dw_pixmap_new_from_data(HWND handle, char *data, int len)
7958 {
7959 HPIXMAP pixmap;
7960 BITMAP bm;
7961 HDC hdc;
7962 char *file;
7963 FILE *fp;
7964
7965 if ( !(pixmap = calloc(1,sizeof(struct _hpixmap))) )
7966 {
7967 return NULL;
7968 }
7969
7970 hdc = GetDC(handle);
7971
7972 pixmap->handle = handle;
7973
7974 file = tmpnam( NULL );
7975 if ( file != NULL )
7976 {
7977 fp = fopen( file, "wb" );
7978 if ( fp != NULL )
7979 {
7980 fwrite( data, 1, len, fp );
7981 fclose( fp );
7982 pixmap->hbm = (HBITMAP)LoadImage( NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
7983 }
7984 else
7985 {
7986 unlink( file );
7987 free( pixmap );
7988 return NULL;
7989 }
7990 unlink( file );
7991 }
7992
7993 if ( !pixmap->hbm )
7994 {
7995 free( pixmap );
7996 ReleaseDC( handle, hdc );
7997 return NULL;
7998 }
7999
8000 pixmap->hdc = CreateCompatibleDC( hdc );
8001
8002 GetObject( pixmap->hbm, sizeof(bm), &bm );
8003
8004 pixmap->width = bm.bmWidth; pixmap->height = bm.bmHeight;
8005
8006 SelectObject( pixmap->hdc, pixmap->hbm );
8007
8008 ReleaseDC( handle, hdc );
8009
8010 return pixmap;
7728 } 8011 }
7729 8012
7730 /* 8013 /*
7731 * Creates a pixmap from internal resource graphic specified by id. 8014 * Creates a pixmap from internal resource graphic specified by id.
7732 * Parameters: 8015 * Parameters: