comparison os2/dw.c @ 637:9fa3cb5b3290

Bring OS/2 functionality up to latest
author mhessling@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 11 Apr 2009 04:54:51 +0000
parents f6f887d2c5aa
children 9ab89d89e6b4
comparison
equal deleted inserted replaced
636:f6f887d2c5aa 637:9fa3cb5b3290
4296 * title: The title text on the menu item to be added. 4296 * title: The title text on the menu item to be added.
4297 * id: An ID to be used for message passing. 4297 * id: An ID to be used for message passing.
4298 * flags: Extended attributes to set on the menu. 4298 * flags: Extended attributes to set on the menu.
4299 * end: If TRUE memu is positioned at the end of the menu. 4299 * end: If TRUE memu is positioned at the end of the menu.
4300 * check: If TRUE menu is "check"able. 4300 * check: If TRUE menu is "check"able.
4301 * flags: Extended attributes to set on the menu.
4301 * submenu: Handle to an existing menu to be a submenu or NULL. 4302 * submenu: Handle to an existing menu to be a submenu or NULL.
4302 */ 4303 */
4303 HWND API dw_menu_append_item(HMENUI menux, char *title, ULONG id, ULONG flags, int end, int check, HMENUI submenu) 4304 HWND API dw_menu_append_item(HMENUI menux, char *title, ULONG id, ULONG flags, int end, int check, HMENUI submenu)
4304 { 4305 {
4305 MENUITEM miSubMenu; 4306 MENUITEM miSubMenu;
4306 char buffer[15]; 4307 char buffer[30];
4307 4308 int is_checked, is_disabled;
4308 check = check; /* keep compiler happy */ 4309
4309 if(!menux || id > 65536) 4310 if ( !menux || id > 65536 )
4310 return NULLHANDLE; 4311 return NULLHANDLE;
4311 4312
4312 if(end) 4313 if ( end )
4313 miSubMenu.iPosition=MIT_END; 4314 miSubMenu.iPosition=MIT_END;
4314 else 4315 else
4315 miSubMenu.iPosition=0; 4316 miSubMenu.iPosition=0;
4316 4317 /*
4317 if(strlen(title) == 0) 4318 * Handle flags
4318 miSubMenu.afStyle=MIS_SEPARATOR | flags; 4319 */
4319 else 4320 miSubMenu.afAttribute = 0;
4320 miSubMenu.afStyle=MIS_TEXT | flags; 4321 is_checked = (flags & DW_MIS_CHECKED) ? 1 : 0;
4321 miSubMenu.afAttribute=0; 4322 if ( is_checked )
4322 miSubMenu.id=id; 4323 miSubMenu.afAttribute |= MIA_CHECKED;
4323 miSubMenu.hwndSubMenu = submenu; 4324 is_disabled = (flags & DW_MIS_DISABLED) ? 1 : 0;
4324 miSubMenu.hItem=NULLHANDLE; 4325 if ( is_disabled )
4325 4326 miSubMenu.afAttribute |= MIA_DISABLED;
4326 WinSendMsg(menux, 4327
4327 MM_INSERTITEM, 4328 if ( strlen( title ) == 0 )
4328 MPFROMP(&miSubMenu), 4329 miSubMenu.afStyle = MIS_SEPARATOR;
4329 MPFROMP(title)); 4330 else
4330 4331 miSubMenu.afStyle = MIS_TEXT;
4331 sprintf(buffer, "_dw_id%d", (int)id); 4332 miSubMenu.id=id;
4332 dw_window_set_data(hwndApp, buffer, (void *)menux); 4333 miSubMenu.hwndSubMenu = submenu;
4333 4334 miSubMenu.hItem=NULLHANDLE;
4334 if(submenu) 4335
4335 dw_window_set_data(submenu, "_dw_owner", (void *)menux); 4336 WinSendMsg(menux, MM_INSERTITEM, MPFROMP(&miSubMenu), MPFROMP(title));
4336 return (HWND)id; 4337
4338 sprintf(buffer, "_dw_id%d", (int)id);
4339 dw_window_set_data(hwndApp, buffer, (void *)menux);
4340 sprintf(buffer, "_dw_checkable%ld", id);
4341 dw_window_set_data( hwndApp, buffer, (void *)check );
4342 sprintf(buffer, "_dw_ischecked%ld", id);
4343 dw_window_set_data( hwndApp, buffer, (void *)is_checked );
4344 sprintf(buffer, "_dw_isdisabled%ld", id);
4345 dw_window_set_data( hwndApp, buffer, (void *)is_disabled );
4346
4347 if ( submenu )
4348 dw_window_set_data(submenu, "_dw_owner", (void *)menux);
4349 return (HWND)id;
4337 } 4350 }
4338 4351
4339 /* 4352 /*
4340 * Sets the state of a menu item check. 4353 * Sets the state of a menu item check.
4354 * Deprecated; use dw_menu_item_set_state()
4341 * Parameters: 4355 * Parameters:
4342 * menu: The handle the the existing menu. 4356 * menu: The handle the the existing menu.
4343 * id: Menuitem id. 4357 * id: Menuitem id.
4344 * check: TRUE for checked FALSE for not checked. 4358 * check: TRUE for checked FALSE for not checked.
4345 */ 4359 */
4346 void API dw_menu_item_set_check(HMENUI menux, unsigned long id, int check) 4360 void API dw_menu_item_set_check(HMENUI menux, unsigned long id, int check)
4347 { 4361 {
4348 if(check) 4362 if ( check )
4349 WinSendMsg(menux, MM_SETITEMATTR, MPFROM2SHORT(id, TRUE), 4363 WinSendMsg(menux, MM_SETITEMATTR, MPFROM2SHORT(id, TRUE),MPFROM2SHORT(MIA_CHECKED, MIA_CHECKED));
4350 MPFROM2SHORT(MIA_CHECKED, MIA_CHECKED)); 4364 else
4351 else 4365 WinSendMsg(menux, MM_SETITEMATTR, MPFROM2SHORT(id, TRUE),MPFROM2SHORT(MIA_CHECKED, 0));
4352 WinSendMsg(menux, MM_SETITEMATTR, MPFROM2SHORT(id, TRUE), 4366 }
4353 MPFROM2SHORT(MIA_CHECKED, 0)); 4367
4368 /*
4369 * Sets the state of a menu item.
4370 * Parameters:
4371 * menu: The handle to the existing menu.
4372 * id: Menuitem id.
4373 * flags: DW_MIS_ENABLED/DW_MIS_DISABLED
4374 * DW_MIS_CHECKED/DW_MIS_UNCHECKED
4375 */
4376 void API dw_menu_item_set_state( HMENUI menux, unsigned long id, unsigned long state)
4377 {
4378 char buffer1[30],buffer2[30];
4379 int check;
4380 int disabled;
4381 USHORT fAttribute=0;
4382
4383 sprintf( buffer1, "_dw_ischecked%ld", id );
4384 check = (int)dw_window_get_data( hwndApp, buffer1 );
4385 sprintf( buffer2, "_dw_isdisabled%ld", id );
4386 disabled = (int)dw_window_get_data( hwndApp, buffer2 );
4387
4388 if ( (state & DW_MIS_CHECKED) || (state & DW_MIS_UNCHECKED) )
4389 {
4390 /*
4391 * If we are changing state of "checked" base our setting on the passed flag...
4392 */
4393 if ( state & DW_MIS_CHECKED )
4394 {
4395 fAttribute |= MIA_CHECKED;
4396 check = 1;
4397 }
4398 else
4399 {
4400 check = 0;
4401 }
4402 }
4403 else
4404 {
4405 /*
4406 * ...otherwise base our setting on the current "checked" state.
4407 */
4408 if ( check )
4409 {
4410 fAttribute |= MIA_CHECKED;
4411 }
4412 }
4413 if ( (state & DW_MIS_ENABLED) || (state & DW_MIS_DISABLED) )
4414 {
4415 if ( state & DW_MIS_DISABLED )
4416 {
4417 fAttribute |= MIA_DISABLED;
4418 disabled = 1;
4419 }
4420 else
4421 {
4422 disabled = 0;
4423 }
4424 }
4425 else
4426 {
4427 /*
4428 * ...otherwise base our setting on the current "disabled" state.
4429 */
4430 if ( disabled )
4431 {
4432 fAttribute |= MIA_DISABLED;
4433 }
4434 }
4435 WinSendMsg( menux, MM_SETITEMATTR, MPFROM2SHORT(id, TRUE), MPFROM2SHORT( MIA_CHECKED|MIA_DISABLED, fAttribute ) );
4436 /*
4437 * Keep our internal checked state consistent
4438 */
4439 dw_window_set_data( hwndApp, buffer1, (void *)check );
4440 dw_window_set_data( hwndApp, buffer2, (void *)disabled );
4354 } 4441 }
4355 4442
4356 /* 4443 /*
4357 * Pops up a context menu at given x and y coordinates. 4444 * Pops up a context menu at given x and y coordinates.
4358 * Parameters: 4445 * Parameters:
4764 * DW pick the appropriate file extension. 4851 * DW pick the appropriate file extension.
4765 * (BMP on OS/2 or Windows, XPM on Unix) 4852 * (BMP on OS/2 or Windows, XPM on Unix)
4766 */ 4853 */
4767 HWND API dw_bitmapbutton_new_from_file(char *text, unsigned long id, char *filename) 4854 HWND API dw_bitmapbutton_new_from_file(char *text, unsigned long id, char *filename)
4768 { 4855 {
4769 BubbleButton *bubble = calloc(sizeof(BubbleButton), 1); 4856 BubbleButton *bubble = calloc(sizeof(BubbleButton), 1);
4770 HWND tmp = WinCreateWindow(HWND_OBJECT, 4857 HWND tmp = WinCreateWindow(HWND_OBJECT,
4771 WC_BUTTON, 4858 WC_BUTTON,
4772 "", 4859 "",
4773 WS_VISIBLE | BS_PUSHBUTTON | 4860 WS_VISIBLE | BS_PUSHBUTTON |
4774 BS_AUTOSIZE | BS_NOPOINTERFOCUS, 4861 BS_AUTOSIZE | BS_NOPOINTERFOCUS,
4775 0,0,2000,1000, 4862 0,0,2000,1000,
4776 NULLHANDLE, 4863 NULLHANDLE,
4777 HWND_TOP, 4864 HWND_TOP,
4778 id, 4865 id,
4779 NULL, 4866 NULL,
4780 NULL); 4867 NULL);
4781 char *file = alloca(strlen(filename) + 5); 4868 char *file = alloca(strlen(filename) + 5);
4782 HPIXMAP pixmap = NULL, disabled = NULL; 4869 HPIXMAP pixmap = NULL, disabled = NULL;
4783 HPOINTER icon = 0; 4870 HPOINTER icon = 0;
4784 4871
4785 if(file && (pixmap = calloc(1,sizeof(struct _hpixmap)))) 4872 if(file && (pixmap = calloc(1,sizeof(struct _hpixmap))))
4786 { 4873 {
4787 int z, j, lim, len; 4874 int z, j, lim, len;
4788 LONG fore; 4875 LONG fore;
4789 4876
4790 strcpy(file, filename); 4877 strcpy(file, filename);
4791 4878
4792 /* check if we can read from this file (it exists and read permission) */ 4879 /* check if we can read from this file (it exists and read permission) */
4793 if(access(file, 04) == 0) 4880 if(access(file, 04) == 0)
4794 { 4881 {
4795 len = strlen( file ); 4882 len = strlen( file );
4796 if(len > 4) 4883 if(len > 4)
4797 { 4884 {
4798 if(stricmp(file + len - 4, ".ico") == 0) 4885 if(stricmp(file + len - 4, ".ico") == 0)
4799 icon = WinLoadFileIcon(file, FALSE); 4886 icon = WinLoadFileIcon(file, FALSE);
4800 else 4887 else
4801 _load_bitmap_file(file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height); 4888 _load_bitmap_file(file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height);
4802 } 4889 }
4803 } 4890 }
4804 else 4891 else
4805 { 4892 {
4806 /* Try with .ico extension first...*/ 4893 /* Try with .ico extension first...*/
4807 strcat(file, ".ico"); 4894 strcat(file, ".ico");
4808 if(access(file, 04) == 0) 4895 if(access(file, 04) == 0)
4809 icon = WinLoadFileIcon(file, FALSE); 4896 icon = WinLoadFileIcon(file, FALSE);
4810 else 4897 else
4811 { 4898 {
4812 strcpy(file, filename); 4899 strcpy(file, filename);
4813 strcat(file, ".bmp"); 4900 strcat(file, ".bmp");
4814 if(access(file, 04) == 0) 4901 if(access(file, 04) == 0)
4815 _load_bitmap_file(file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height); 4902 _load_bitmap_file(file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height);
4816 } 4903 }
4817 } 4904 }
4818 4905
4819 if(icon) 4906 if(icon)
4820 { 4907 {
4821 free(pixmap); 4908 free(pixmap);
4822 pixmap = NULL; 4909 pixmap = NULL;
4823 } 4910 }
4824 else 4911 else
4825 { 4912 {
4826 /* Create a disabled style pixmap */ 4913 /* Create a disabled style pixmap */
4827 disabled = dw_pixmap_new(tmp, pixmap->width, pixmap->height, dw_color_depth_get()); 4914 disabled = dw_pixmap_new(tmp, pixmap->width, pixmap->height, dw_color_depth_get());
4828 dw_pixmap_bitblt(0, disabled, 0, 0, pixmap->width, pixmap->height, 0, pixmap, 0, 0); 4915 dw_pixmap_bitblt(0, disabled, 0, 0, pixmap->width, pixmap->height, 0, pixmap, 0, 0);
4829 4916
4830 fore = _foreground; 4917 fore = _foreground;
4831 dw_color_foreground_set(DW_CLR_PALEGRAY); 4918 dw_color_foreground_set(DW_CLR_PALEGRAY);
4832 lim = pixmap->width/2; 4919 lim = pixmap->width/2;
4833 for(j=0;j<pixmap->height;j++) 4920 for(j=0;j<pixmap->height;j++)
4834 { 4921 {
4835 int mod = j%2; 4922 int mod = j%2;
4836 4923
4837 for(z=0;z<lim;z++) 4924 for(z=0;z<lim;z++)
4838 dw_draw_point(0, disabled, (z*2)+mod, j); 4925 dw_draw_point(0, disabled, (z*2)+mod, j);
4839 } 4926 }
4840 _foreground = fore; 4927 _foreground = fore;
4841 } 4928 }
4842 } 4929 }
4843 4930
4844 bubble->id = id; 4931 bubble->id = id;
4845 strncpy(bubble->bubbletext, text, BUBBLE_HELP_MAX - 1); 4932 strncpy(bubble->bubbletext, text, BUBBLE_HELP_MAX - 1);
4846 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0'; 4933 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0';
4847 bubble->pOldProc = WinSubclassWindow(tmp, _BtProc); 4934 bubble->pOldProc = WinSubclassWindow(tmp, _BtProc);
4848 4935
4849 WinSetWindowPtr(tmp, QWP_USER, bubble); 4936 WinSetWindowPtr(tmp, QWP_USER, bubble);
4850 4937
4851 if(icon) 4938 if(icon)
4852 dw_window_set_data(tmp, "_dw_button_icon", (void *)icon); 4939 dw_window_set_data(tmp, "_dw_button_icon", (void *)icon);
4853 else 4940 else
4854 { 4941 {
4855 dw_window_set_data(tmp, "_dw_hpixmap", (void *)pixmap); 4942 dw_window_set_data(tmp, "_dw_hpixmap", (void *)pixmap);
4856 dw_window_set_data(tmp, "_dw_hpixmap_disabled", (void *)disabled); 4943 dw_window_set_data(tmp, "_dw_hpixmap_disabled", (void *)disabled);
4857 } 4944 }
4858 dw_window_set_data(tmp, "_dw_bitmapbutton", (void *)1); 4945 dw_window_set_data(tmp, "_dw_bitmapbutton", (void *)1);
4859 return tmp; 4946 return tmp;
4947 }
4948
4949 /*
4950 * Create a new bitmap button window (widget) to be packed from data.
4951 * Parameters:
4952 * text: Bubble help text to be displayed.
4953 * id: An ID to be used with dw_window_from_id() or 0L.
4954 * data: The contents of the image
4955 * (BMP or ICO on OS/2 or Windows, XPM on Unix)
4956 * len: length of str
4957 */
4958 HWND API dw_bitmapbutton_new_from_data(char *text, unsigned long id, char *data, int len)
4959 {
4960 FILE *fp;
4961 BubbleButton *bubble = calloc(sizeof(BubbleButton), 1);
4962 HWND tmp = WinCreateWindow(HWND_OBJECT,
4963 WC_BUTTON,
4964 "",
4965 WS_VISIBLE | BS_PUSHBUTTON |
4966 BS_AUTOSIZE | BS_NOPOINTERFOCUS,
4967 0,0,2000,1000,
4968 NULLHANDLE,
4969 HWND_TOP,
4970 id,
4971 NULL,
4972 NULL);
4973 char *file;
4974 HPIXMAP pixmap = NULL, disabled = NULL;
4975 HPOINTER icon = 0;
4976
4977 if ( ( pixmap = calloc( 1, sizeof(struct _hpixmap) ) ) )
4978 {
4979 int z, j, lim;
4980 LONG fore;
4981 file = tmpnam( NULL );
4982 if ( file != NULL )
4983 {
4984 fp = fopen( file, "wb" );
4985 if ( fp != NULL )
4986 {
4987 fwrite( data, 1, len, fp );
4988 fclose( fp );
4989 if ( len > 1 && data[0] == 'B' && data[1] == 'M' ) /* first 2 chars of data is BM, then its a BMP */
4990 {
4991 _load_bitmap_file( file, tmp, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height );
4992 }
4993 else /* otherwise its assumed to be an ico */
4994 {
4995 icon = WinLoadFileIcon(file, FALSE);
4996 }
4997 }
4998 else
4999 {
5000 unlink( file );
5001 return 0;
5002 }
5003 unlink( file );
5004 }
5005
5006 if ( icon )
5007 {
5008 free(pixmap);
5009 pixmap = NULL;
5010 }
5011 else
5012 {
5013 /* Create a disabled style pixmap */
5014 disabled = dw_pixmap_new(tmp, pixmap->width, pixmap->height, dw_color_depth_get());
5015 dw_pixmap_bitblt(0, disabled, 0, 0, pixmap->width, pixmap->height, 0, pixmap, 0, 0);
5016
5017 fore = _foreground;
5018 dw_color_foreground_set(DW_CLR_PALEGRAY);
5019 lim = pixmap->width/2;
5020 for(j=0;j<pixmap->height;j++)
5021 {
5022 int mod = j%2;
5023
5024 for(z=0;z<lim;z++)
5025 dw_draw_point(0, disabled, (z*2)+mod, j);
5026 }
5027 _foreground = fore;
5028 }
5029 }
5030
5031 bubble->id = id;
5032 strncpy(bubble->bubbletext, text, BUBBLE_HELP_MAX - 1);
5033 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0';
5034 bubble->pOldProc = WinSubclassWindow(tmp, _BtProc);
5035
5036 WinSetWindowPtr(tmp, QWP_USER, bubble);
5037
5038 if(icon)
5039 dw_window_set_data(tmp, "_dw_button_icon", (void *)icon);
5040 else
5041 {
5042 dw_window_set_data(tmp, "_dw_hpixmap", (void *)pixmap);
5043 dw_window_set_data(tmp, "_dw_hpixmap_disabled", (void *)disabled);
5044 }
5045 dw_window_set_data(tmp, "_dw_bitmapbutton", (void *)1);
5046 return tmp;
4860 } 5047 }
4861 5048
4862 /* 5049 /*
4863 * Create a new spinbutton window (widget) to be packed. 5050 * Create a new spinbutton window (widget) to be packed.
4864 * Parameters: 5051 * Parameters:
5179 * Windows and a pixmap on Unix, pass 5366 * Windows and a pixmap on Unix, pass
5180 * NULL if you use the id param) 5367 * NULL if you use the id param)
5181 */ 5368 */
5182 void API dw_window_set_bitmap(HWND handle, unsigned long id, char *filename) 5369 void API dw_window_set_bitmap(HWND handle, unsigned long id, char *filename)
5183 { 5370 {
5184 HBITMAP hbm; 5371 HBITMAP hbm;
5185 HPS hps; 5372 HPS hps;
5186 5373
5187 /* Destroy any old bitmap data */ 5374 /* Destroy any old bitmap data */
5188 _free_bitmap(handle); 5375 _free_bitmap(handle);
5189 5376
5190 /* If id is non-zero use the resource */ 5377 /* If id is non-zero use the resource */
5191 if(id) 5378 if ( id )
5192 { 5379 {
5193 hps = WinGetPS(handle); 5380 hps = WinGetPS( handle );
5194 5381 hbm = GpiLoadBitmap( hps, NULLHANDLE, id, 0, 0 );
5195 hbm = GpiLoadBitmap(hps, NULLHANDLE, id, 0, 0); 5382 }
5196 } 5383 else if ( filename )
5197 else if(filename) 5384 {
5198 { 5385 HDC hdc;
5199 HDC hdc; 5386 unsigned long width, height;
5200 unsigned long width, height; 5387 char *file = alloca(strlen(filename) + 5);
5201 char *file = alloca(strlen(filename) + 5); 5388
5202 5389 if(!file)
5203 if(!file) 5390 return;
5204 return; 5391
5205 5392 strcpy(file, filename);
5206 strcpy(file, filename); 5393
5207 5394 /* check if we can read from this file (it exists and read permission) */
5208 /* check if we can read from this file (it exists and read permission) */ 5395 if(access(file, 04) != 0)
5209 if(access(file, 04) != 0) 5396 {
5210 { 5397 /* Try with .bmp extention */
5211 /* Try with .bmp extention */ 5398 strcat(file, ".bmp");
5212 strcat(file, ".bmp"); 5399 if(access(file, 04) != 0)
5213 if(access(file, 04) != 0) 5400 return;
5214 return; 5401 }
5215 } 5402
5216 5403 if(!_load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height))
5217 if(!_load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height)) 5404 return;
5218 return; 5405
5219 5406 dw_window_set_data(handle, "_dw_hps", (void *)hps);
5220 dw_window_set_data(handle, "_dw_hps", (void *)hps); 5407 dw_window_set_data(handle, "_dw_hdc", (void *)hdc);
5221 dw_window_set_data(handle, "_dw_hdc", (void *)hdc); 5408 dw_window_set_data(handle, "_dw_width", (void *)width);
5222 dw_window_set_data(handle, "_dw_width", (void *)width); 5409 dw_window_set_data(handle, "_dw_height", (void *)height);
5223 dw_window_set_data(handle, "_dw_height", (void *)height); 5410 }
5224 } 5411 else
5225 else 5412 return;
5226 return; 5413
5227 5414 WinSetWindowBits(handle,QWL_STYLE,SS_BITMAP,SS_BITMAP | 0x7f);
5228 WinSetWindowBits(handle,QWL_STYLE,SS_BITMAP,SS_BITMAP | 0x7f); 5415 WinSendMsg( handle, SM_SETHANDLE, MPFROMP(hbm), NULL );
5229 WinSendMsg( handle, SM_SETHANDLE, MPFROMP(hbm), NULL ); 5416 if ( id )
5230 if(id) 5417 WinReleasePS(hps);
5231 WinReleasePS(hps); 5418 dw_window_set_data(handle, "_dw_bitmap", (void *)hbm);
5232 dw_window_set_data(handle, "_dw_bitmap", (void *)hbm); 5419 }
5420
5421 /*
5422 * Sets the bitmap used for a given static window.
5423 * Parameters:
5424 * handle: Handle to the window.
5425 * id: An ID to be used to specify the icon,
5426 * (pass 0 if you use the filename param)
5427 * filename: a path to a file (Bitmap on OS/2 or
5428 * Windows and a pixmap on Unix, pass
5429 * NULL if you use the id param)
5430 */
5431 void API dw_window_set_bitmap_from_data(HWND handle, unsigned long id, char *data, int len)
5432 {
5433 HBITMAP hbm;
5434 HPS hps;
5435 HDC hdc;
5436 unsigned long width, height;
5437 char *file;
5438 FILE *fp;
5439
5440 /* Destroy any old bitmap data */
5441 _free_bitmap(handle);
5442
5443 /* If id is non-zero use the resource */
5444 if ( id )
5445 {
5446 hps = WinGetPS( handle );
5447 hbm = GpiLoadBitmap( hps, NULLHANDLE, id, 0, 0 );
5448 }
5449 else if ( data )
5450 {
5451 file = tmpnam( NULL );
5452 if ( file != NULL )
5453 {
5454 fp = fopen( file, "wb" );
5455 if ( fp != NULL )
5456 {
5457 fwrite( data, 1, len, fp );
5458 fclose( fp );
5459 if ( len > 1 && data[0] == 'B' && data[1] == 'M' ) /* first 2 chars of data is BM, then its a BMP */
5460 _load_bitmap_file(file, handle, &hbm, &hdc, &hps, &width, &height);
5461 else /* otherwise its assumed to be an ico */
5462 {
5463 /* con't use ICO ? */
5464 unlink( file );
5465 return;
5466 }
5467 }
5468 else
5469 {
5470 unlink( file );
5471 return;
5472 }
5473 unlink( file );
5474 }
5475
5476 dw_window_set_data(handle, "_dw_hps", (void *)hps);
5477 dw_window_set_data(handle, "_dw_hdc", (void *)hdc);
5478 dw_window_set_data(handle, "_dw_width", (void *)width);
5479 dw_window_set_data(handle, "_dw_height", (void *)height);
5480 }
5481 else
5482 return;
5483
5484 WinSetWindowBits(handle,QWL_STYLE,SS_BITMAP,SS_BITMAP | 0x7f);
5485 WinSendMsg( handle, SM_SETHANDLE, MPFROMP(hbm), NULL );
5486 if ( id )
5487 WinReleasePS(hps);
5488 dw_window_set_data(handle, "_dw_bitmap", (void *)hbm);
5233 } 5489 }
5234 5490
5235 /* 5491 /*
5236 * Sets the text used for a given window. 5492 * Sets the text used for a given window.
5237 * Parameters: 5493 * Parameters:
5512 * Parameters: 5768 * Parameters:
5513 * handle: Window (widget) handle. 5769 * handle: Window (widget) handle.
5514 * x: X location from the bottom left. 5770 * x: X location from the bottom left.
5515 * y: Y location from the bottom left. 5771 * y: Y location from the bottom left.
5516 */ 5772 */
5517 void API dw_window_set_pos(HWND handle, ULONG x, ULONG y) 5773 void API dw_window_set_pos(HWND handle, LONG x, LONG y)
5518 { 5774 {
5519 int myy = _get_frame_height(handle) - (y + _get_height(handle)); 5775 int myy = _get_frame_height(handle) - (y + _get_height(handle));
5520 5776
5521 WinSetWindowPos(handle, NULLHANDLE, x, myy, 0, 0, SWP_MOVE); 5777 WinSetWindowPos(handle, NULLHANDLE, x, myy, 0, 0, SWP_MOVE);
5522 } 5778 }
5528 * x: X location from the bottom left. 5784 * x: X location from the bottom left.
5529 * y: Y location from the bottom left. 5785 * y: Y location from the bottom left.
5530 * width: Width of the widget. 5786 * width: Width of the widget.
5531 * height: Height of the widget. 5787 * height: Height of the widget.
5532 */ 5788 */
5533 void API dw_window_set_pos_size(HWND handle, ULONG x, ULONG y, ULONG width, ULONG height) 5789 void API dw_window_set_pos_size(HWND handle, LONG x, LONG y, ULONG width, ULONG height)
5534 { 5790 {
5535 int myy = _get_frame_height(handle) - (y + height); 5791 int myy = _get_frame_height(handle) - (y + height);
5536 5792
5537 WinSetWindowPos(handle, NULLHANDLE, x, myy, width, height, SWP_MOVE | SWP_SIZE | SWP_SHOW); 5793 WinSetWindowPos(handle, NULLHANDLE, x, myy, width, height, SWP_MOVE | SWP_SIZE | SWP_SHOW);
5538 } 5794 }
5544 * x: X location from the bottom left. 5800 * x: X location from the bottom left.
5545 * y: Y location from the bottom left. 5801 * y: Y location from the bottom left.
5546 * width: Width of the widget. 5802 * width: Width of the widget.
5547 * height: Height of the widget. 5803 * height: Height of the widget.
5548 */ 5804 */
5549 void API dw_window_get_pos_size(HWND handle, ULONG *x, ULONG *y, ULONG *width, ULONG *height) 5805 void API dw_window_get_pos_size(HWND handle, LONG *x, LONG *y, ULONG *width, ULONG *height)
5550 { 5806 {
5551 SWP swp; 5807 SWP swp;
5552 WinQueryWindowPos(handle, &swp); 5808 WinQueryWindowPos(handle, &swp);
5553 if(x) 5809 if(x)
5554 *x = swp.x; 5810 *x = swp.x;
6584 * DW pick the appropriate file extension. 6840 * DW pick the appropriate file extension.
6585 * (ICO on OS/2 or Windows, XPM on Unix) 6841 * (ICO on OS/2 or Windows, XPM on Unix)
6586 */ 6842 */
6587 unsigned long API dw_icon_load_from_file(char *filename) 6843 unsigned long API dw_icon_load_from_file(char *filename)
6588 { 6844 {
6589 char *file = alloca(strlen(filename) + 5); 6845 char *file = alloca(strlen(filename) + 5);
6590 6846
6591 if(!file) 6847 if(!file)
6592 return 0; 6848 return 0;
6593 6849
6594 strcpy(file, filename); 6850 strcpy(file, filename);
6595 6851
6596 /* check if we can read from this file (it exists and read permission) */ 6852 /* check if we can read from this file (it exists and read permission) */
6597 if(access(file, 04) != 0) 6853 if(access(file, 04) != 0)
6598 { 6854 {
6599 /* Try with .bmp extention */ 6855 /* Try with .bmp extention */
6600 strcat(file, ".ico"); 6856 strcat(file, ".ico");
6601 if(access(file, 04) != 0) 6857 if(access(file, 04) != 0)
6602 return 0; 6858 return 0;
6603 } 6859 }
6604 return WinLoadFileIcon(file, FALSE); 6860 return WinLoadFileIcon(file, FALSE);
6861 }
6862
6863 /*
6864 * Obtains an icon from data
6865 * Parameters:
6866 * filename: Name of the file, omit extention to have
6867 * DW pick the appropriate file extension.
6868 * (ICO on OS/2 or Windows, XPM on Unix)
6869 */
6870 unsigned long API dw_icon_load_from_data(char *data, int len)
6871 {
6872 unsigned long icon=0;
6873 char *file;
6874 FILE *fp;
6875
6876 if ( !data )
6877 return 0;
6878 file = tmpnam( NULL );
6879 if ( file != NULL )
6880 {
6881 fp = fopen( file, "wb" );
6882 if ( fp != NULL )
6883 {
6884 fwrite( data, 1, len, fp );
6885 fclose( fp );
6886 icon = WinLoadFileIcon( file, FALSE );
6887 }
6888 else
6889 {
6890 unlink( file );
6891 return 0;
6892 }
6893 unlink( file );
6894 }
6895 return icon;
6605 } 6896 }
6606 6897
6607 /* 6898 /*
6608 * Frees a loaded resource in OS/2 and Windows. 6899 * Frees a loaded resource in OS/2 and Windows.
6609 * Parameters: 6900 * Parameters:
6610 * handle: Handle to icon returned by dw_icon_load(). 6901 * handle: Handle to icon returned by dw_icon_load().
6611 */ 6902 */
6612 void API dw_icon_free(unsigned long handle) 6903 void API dw_icon_free(unsigned long handle)
6613 { 6904 {
6614 WinDestroyPointer(handle); 6905 WinDestroyPointer(handle);
6615 } 6906 }
6616 6907
6617 /* 6908 /*
6618 * Allocates memory used to populate a container. 6909 * Allocates memory used to populate a container.
6619 * Parameters: 6910 * Parameters:
7693 */ 7984 */
7694 void API dw_draw_polygon( HWND handle, HPIXMAP pixmap, int fill, int npoints, int *x, int *y ) 7985 void API dw_draw_polygon( HWND handle, HPIXMAP pixmap, int fill, int npoints, int *x, int *y )
7695 { 7986 {
7696 HPS hps; 7987 HPS hps;
7697 int thisheight; 7988 int thisheight;
7698 POINTL *ptl[2]; 7989 POINTL *pptl;
7699 POINTL start; 7990 POINTL start;
7991 int i;
7700 7992
7701 if(handle) 7993 if(handle)
7702 { 7994 {
7703 hps = _set_colors(handle); 7995 hps = _set_colors(handle);
7704 thisheight = _get_height(handle); 7996 thisheight = _get_height(handle);
7705 } 7997 }
7706 else if(pixmap) 7998 else if(pixmap)
7707 { 7999 {
7708 hps = _set_hps(pixmap->hps); 8000 hps = _set_hps(pixmap->hps);
7709 thisheight = pixmap->height; 8001 thisheight = pixmap->height;
7710 } 8002 }
7711 else 8003 else
8004 return;
8005 if ( npoints == 0 )
8006 return;
8007 pptl = (POINTL *)malloc(sizeof(POINTL)*npoints);
8008 if ( pptl == NULL )
7712 return; 8009 return;
7713 /* 8010 /*
7714 * For a filled polygon we need to start an area 8011 * For a filled polygon we need to start an area
7715 */ 8012 */
7716 if ( fill ) 8013 if ( fill )
7726 /* 8023 /*
7727 * Convert the remainder of the x and y points 8024 * Convert the remainder of the x and y points
7728 */ 8025 */
7729 for ( i = 1; i < npoints; i++ ) 8026 for ( i = 1; i < npoints; i++ )
7730 { 8027 {
7731 ptl[i-1].x = x[i]; 8028 pptl[i-1].x = x[i];
7732 ptl[i-1].y = y[i]; 8029 pptl[i-1].y = y[i];
7733 } 8030 }
7734 GpiPolyLine( hps, npoints-1, &ptl ); 8031 GpiPolyLine( hps, npoints-1, pptl );
7735 8032
7736 if ( fill ) 8033 if ( fill )
7737 GpiEndArea( hps ); 8034 GpiEndArea( hps );
7738 } 8035 }
7739 if ( !pixmap ) 8036 if ( !pixmap )
7740 WinReleasePS(hps); 8037 WinReleasePS(hps);
8038 free( pptl );
7741 } 8039 }
7742 8040
7743 /* Draw a rectangle on a window (preferably a render window). 8041 /* Draw a rectangle on a window (preferably a render window).
7744 * Parameters: 8042 * Parameters:
7745 * handle: Handle to the window. 8043 * handle: Handle to the window.
7858 * Returns: 8156 * Returns:
7859 * A handle to a pixmap or NULL on failure. 8157 * A handle to a pixmap or NULL on failure.
7860 */ 8158 */
7861 HPIXMAP API dw_pixmap_new_from_file(HWND handle, char *filename) 8159 HPIXMAP API dw_pixmap_new_from_file(HWND handle, char *filename)
7862 { 8160 {
7863 HPIXMAP pixmap; 8161 HPIXMAP pixmap;
7864 char *file = alloca(strlen(filename) + 5); 8162 char *file = alloca(strlen(filename) + 5);
7865 8163
7866 if(!file || !(pixmap = calloc(1,sizeof(struct _hpixmap)))) 8164 if ( !file || !(pixmap = calloc(1,sizeof(struct _hpixmap))) )
7867 return NULL; 8165 return NULL;
7868 8166
7869 strcpy(file, filename); 8167 strcpy(file, filename);
7870 8168
7871 /* check if we can read from this file (it exists and read permission) */ 8169 /* check if we can read from this file (it exists and read permission) */
7872 if(access(file, 04) != 0) 8170 if ( access(file, 04) != 0 )
7873 { 8171 {
7874 /* Try with .bmp extention */ 8172 /* Try with .bmp extention */
7875 strcat(file, ".bmp"); 8173 strcat(file, ".bmp");
7876 if(access(file, 04) != 0) 8174 if ( access(file, 04) != 0 )
7877 { 8175 {
7878 free(pixmap); 8176 free(pixmap);
7879 return NULL; 8177 return NULL;
7880 } 8178 }
7881 } 8179 }
7882 8180
7883 /* Try to load the bitmap from file */ 8181 /* Try to load the bitmap from file */
7884 if(!_load_bitmap_file(file, handle, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height)) 8182 if ( !_load_bitmap_file(file, handle, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height) )
7885 { 8183 {
7886 free(pixmap); 8184 free(pixmap);
7887 return NULL; 8185 return NULL;
7888 } 8186 }
7889 8187
7890 /* Success fill in other values */ 8188 /* Success fill in other values */
7891 pixmap->handle = handle; 8189 pixmap->handle = handle;
7892 8190
7893 return pixmap; 8191 return pixmap;
8192 }
8193
8194 /*
8195 * Creates a pixmap from memory.
8196 * Parameters:
8197 * handle: Window handle the pixmap is associated with.
8198 * data: Source of the image data
8199 * (BMP on OS/2 or Windows, XPM on Unix)
8200 * le: length of data
8201 * Returns:
8202 * A handle to a pixmap or NULL on failure.
8203 */
8204 HPIXMAP API dw_pixmap_new_from_data(HWND handle, char *data, int len)
8205 {
8206 HPIXMAP pixmap;
8207 char *file;
8208 FILE *fp;
8209
8210 if ( !(pixmap = calloc(1,sizeof(struct _hpixmap))) )
8211 return NULL;
8212
8213 file = tmpnam( NULL );
8214 if ( file != NULL )
8215 {
8216 fp = fopen( file, "wb" );
8217 if ( fp != NULL )
8218 {
8219 fwrite( data, 1, len, fp );
8220 fclose( fp );
8221 if ( len > 1 && data[0] == 'B' && data[1] == 'M' ) /* first 2 chars of data is BM, then its a BMP */
8222 {
8223 /* Try to load the bitmap from file */
8224 if ( !_load_bitmap_file(file, handle, &pixmap->hbm, &pixmap->hdc, &pixmap->hps, &pixmap->width, &pixmap->height) )
8225 {
8226 free(pixmap);
8227 return NULL;
8228 }
8229 }
8230 else /* otherwise its assumed to be an ico */
8231 {
8232 /* con't use ICO ? */
8233 unlink( file );
8234 return NULL;
8235 }
8236 }
8237 else
8238 {
8239 unlink( file );
8240 return NULL;
8241 }
8242 unlink( file );
8243 }
8244
8245 /* Success fill in other values */
8246 pixmap->handle = handle;
8247
8248 return pixmap;
8249 }
8250
8251 /*
8252 * Creates a bitmap mask for rendering bitmaps with transparent backgrounds
8253 */
8254 void API dw_pixmap_set_transparent_color( HPIXMAP pixmap, ULONG color )
8255 {
8256 if ( pixmap )
8257 {
8258 pixmap->transcolor = _internal_color(color);
8259 }
7894 } 8260 }
7895 8261
7896 /* 8262 /*
7897 * Creates a pixmap from internal resource graphic specified by id. 8263 * Creates a pixmap from internal resource graphic specified by id.
7898 * Parameters: 8264 * Parameters:
8752 { 9118 {
8753 WindowData *blah = (WindowData *)WinQueryWindowPtr(window, QWP_USER); 9119 WindowData *blah = (WindowData *)WinQueryWindowPtr(window, QWP_USER);
8754 9120
8755 if(blah) 9121 if(blah)
8756 blah->clickdefault = next; 9122 blah->clickdefault = next;
9123 }
9124
9125 /*
9126 * Gets the contents of the default clipboard as text.
9127 * INCOMPLETE
9128 * Parameters:
9129 * None.
9130 * Returns:
9131 * Pointer to an allocated string of text or NULL if clipboard empty or contents could not
9132 * be converted to text.
9133 */
9134 char *dw_clipboard_get_text()
9135 {
9136 return "";
9137 }
9138
9139 /*
9140 * Sets the contents of the default clipboard to the supplied text.
9141 * INCOMPLETE
9142 * Parameters:
9143 * Text.
9144 */
9145 void dw_clipboard_set_text( char *str, int len )
9146 {
9147 return;
8757 } 9148 }
8758 9149
8759 /* 9150 /*
8760 * Returns some information about the current operating environment. 9151 * Returns some information about the current operating environment.
8761 * Parameters: 9152 * Parameters:
9629 dw_window_set_color(tmp, DW_CLR_BLACK, DW_CLR_PALEGRAY); 10020 dw_window_set_color(tmp, DW_CLR_BLACK, DW_CLR_PALEGRAY);
9630 WinSetWindowText(tmp, text); 10021 WinSetWindowText(tmp, text);
9631 return tmp; 10022 return tmp;
9632 } 10023 }
9633 10024
9634 void API dw_calendar_set_date( HWND window, int year, int month, int day ) 10025 /*
10026 * The following are stubs
10027 */
10028 void API dw_calendar_set_date( HWND window, unsigned int year, unsigned int month, unsigned int day )
9635 { 10029 {
9636 char tmp[30]; 10030 char tmp[30];
9637 sprintf( tmp, "%4.4d-%2.2d-%2.2d", year, month, day); 10031 sprintf( tmp, "%4.4d-%2.2d-%2.2d", year, month, day);
9638 WinSetWindowText(window, tmp); 10032 WinSetWindowText(window, tmp);
9639 } 10033 }
9640 void API dw_calendar_get_date( HWND window, int *year, int *month, int *day ) 10034
10035 void API dw_calendar_get_date( HWND window, unsigned int *year, unsigned int *month, unsigned int *day )
9641 { 10036 {
9642 *year = *month = *day = 0; 10037 *year = *month = *day = 0;
9643 } 10038 }