comparison win/dw.c @ 671:c60a4f6cfae8

Implemented icon support on the Mac. In the process created a new HICN type. The existing implementation works well on OS/2 but it is kind of bad on the other platforms. I should revisit the Windows and GTK implementations. The typedef currently in use should be backwards compatible for now.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 27 Feb 2011 19:01:40 +0000
parents 2b260f4309bb
children 388f2a48aaae
comparison
equal deleted inserted replaced
670:0b920d0dc13e 671:c60a4f6cfae8
1 /* 1 /*
2 * Dynamic Windows: 2 * Dynamic Windows:
3 * A GTK like implementation of the Win32 GUI 3 * A GTK like implementation of the Win32 GUI
4 * 4 *
5 * (C) 2000-2005 Brian Smith <dbsoft@technologist.com> 5 * (C) 2000-2011 Brian Smith <brian@dbsoft.org>
6 * (C) 2003-2005 Mark Hessling <m.hessling@qut.edu.au> 6 * (C) 2003-2005 Mark Hessling <m.hessling@qut.edu.au>
7 * 7 *
8 */ 8 */
9 #define _WIN32_IE 0x0500 9 #define _WIN32_IE 0x0500
10 #define WINVER 0x500 10 #define WINVER 0x500
7052 * title: The text title of the entry. 7052 * title: The text title of the entry.
7053 * icon: Handle to coresponding icon. 7053 * icon: Handle to coresponding icon.
7054 * parent: Parent handle or 0 if root. 7054 * parent: Parent handle or 0 if root.
7055 * itemdata: Item specific data. 7055 * itemdata: Item specific data.
7056 */ 7056 */
7057 HTREEITEM API dw_tree_insert_after(HWND handle, HTREEITEM item, char *title, unsigned long icon, HTREEITEM parent, void *itemdata) 7057 HTREEITEM API dw_tree_insert_after(HWND handle, HTREEITEM item, char *title, HICN icon, HTREEITEM parent, void *itemdata)
7058 { 7058 {
7059 TVITEM tvi; 7059 TVITEM tvi;
7060 TVINSERTSTRUCT tvins; 7060 TVINSERTSTRUCT tvins;
7061 HTREEITEM hti; 7061 HTREEITEM hti;
7062 void **ptrs= malloc(sizeof(void *) * 2); 7062 void **ptrs= malloc(sizeof(void *) * 2);
7086 * title: The text title of the entry. 7086 * title: The text title of the entry.
7087 * icon: Handle to coresponding icon. 7087 * icon: Handle to coresponding icon.
7088 * parent: Parent handle or 0 if root. 7088 * parent: Parent handle or 0 if root.
7089 * itemdata: Item specific data. 7089 * itemdata: Item specific data.
7090 */ 7090 */
7091 HTREEITEM API dw_tree_insert(HWND handle, char *title, unsigned long icon, HTREEITEM parent, void *itemdata) 7091 HTREEITEM API dw_tree_insert(HWND handle, char *title, HICN icon, HTREEITEM parent, void *itemdata)
7092 { 7092 {
7093 TVITEM tvi; 7093 TVITEM tvi;
7094 TVINSERTSTRUCT tvins; 7094 TVINSERTSTRUCT tvins;
7095 HTREEITEM hti; 7095 HTREEITEM hti;
7096 void **ptrs= malloc(sizeof(void *) * 2); 7096 void **ptrs= malloc(sizeof(void *) * 2);
7119 * handle: Handle to the tree containing the item. 7119 * handle: Handle to the tree containing the item.
7120 * item: Handle of the item to be modified. 7120 * item: Handle of the item to be modified.
7121 * title: The text title of the entry. 7121 * title: The text title of the entry.
7122 * icon: Handle to coresponding icon. 7122 * icon: Handle to coresponding icon.
7123 */ 7123 */
7124 void API dw_tree_item_change(HWND handle, HTREEITEM item, char *title, unsigned long icon) 7124 void API dw_tree_item_change(HWND handle, HTREEITEM item, char *title, HICN icon)
7125 { 7125 {
7126 TVITEM tvi; 7126 TVITEM tvi;
7127 void **ptrs; 7127 void **ptrs;
7128 7128
7129 tvi.mask = TVIF_HANDLE; 7129 tvi.mask = TVIF_HANDLE;
7399 * module: Handle to module (DLL) in OS/2 and Windows. 7399 * module: Handle to module (DLL) in OS/2 and Windows.
7400 * id: A unsigned long id int the resources on OS/2 and 7400 * id: A unsigned long id int the resources on OS/2 and
7401 * Windows, on GTK this is converted to a pointer 7401 * Windows, on GTK this is converted to a pointer
7402 * to an embedded XPM. 7402 * to an embedded XPM.
7403 */ 7403 */
7404 unsigned long API dw_icon_load(unsigned long module, unsigned long id) 7404 HICN API dw_icon_load(unsigned long module, unsigned long id)
7405 { 7405 {
7406 return (unsigned long)LoadIcon(DWInstance, MAKEINTRESOURCE(id)); 7406 return (HICN)LoadIcon(DWInstance, MAKEINTRESOURCE(id));
7407 } 7407 }
7408 7408
7409 /* 7409 /*
7410 * Obtains an icon from a file. 7410 * Obtains an icon from a file.
7411 * Parameters: 7411 * Parameters:
7412 * filename: Name of the file, omit extention to have 7412 * filename: Name of the file, omit extention to have
7413 * DW pick the appropriate file extension. 7413 * DW pick the appropriate file extension.
7414 * (ICO on OS/2 or Windows, XPM on Unix) 7414 * (ICO on OS/2 or Windows, XPM on Unix)
7415 */ 7415 */
7416 unsigned long API dw_icon_load_from_file(char *filename) 7416 HICN API dw_icon_load_from_file(char *filename)
7417 { 7417 {
7418 char *file = malloc(strlen(filename) + 5); 7418 char *file = malloc(strlen(filename) + 5);
7419 HANDLE icon; 7419 HANDLE icon;
7420 7420
7421 if(!file) 7421 if(!file)
7434 return 0; 7434 return 0;
7435 } 7435 }
7436 } 7436 }
7437 icon = LoadImage(NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE); 7437 icon = LoadImage(NULL, file, IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
7438 free(file); 7438 free(file);
7439 return (unsigned long)icon; 7439 return (HICN)icon;
7440 } 7440 }
7441 7441
7442 /* 7442 /*
7443 * Obtains an icon from data 7443 * Obtains an icon from data
7444 * Parameters: 7444 * Parameters:
7445 * data: Source of icon data 7445 * data: Source of icon data
7446 * DW pick the appropriate file extension. 7446 * DW pick the appropriate file extension.
7447 * (ICO on OS/2 or Windows, XPM on Unix) 7447 * (ICO on OS/2 or Windows, XPM on Unix)
7448 */ 7448 */
7449 unsigned long API dw_icon_load_from_data(char *data, int len) 7449 HICN API dw_icon_load_from_data(char *data, int len)
7450 { 7450 {
7451 HANDLE icon; 7451 HANDLE icon;
7452 char *file; 7452 char *file;
7453 FILE *fp; 7453 FILE *fp;
7454 7454
7469 unlink( file ); 7469 unlink( file );
7470 return 0; 7470 return 0;
7471 } 7471 }
7472 unlink( file ); 7472 unlink( file );
7473 } 7473 }
7474 return (unsigned long)icon; 7474 return (HICN)icon;
7475 } 7475 }
7476 7476
7477 /* 7477 /*
7478 * Frees a loaded resource in OS/2 and Windows. 7478 * Frees a loaded resource in OS/2 and Windows.
7479 * Parameters: 7479 * Parameters:
7480 * handle: Handle to icon returned by dw_icon_load(). 7480 * handle: Handle to icon returned by dw_icon_load().
7481 */ 7481 */
7482 void API dw_icon_free(unsigned long handle) 7482 void API dw_icon_free(HICN handle)
7483 { 7483 {
7484 DestroyIcon((HICON)handle); 7484 DestroyIcon((HICON)handle);
7485 } 7485 }
7486 7486
7487 /* 7487 /*
7572 * pointer: Pointer to the allocated memory in dw_container_alloc(). 7572 * pointer: Pointer to the allocated memory in dw_container_alloc().
7573 * column: Zero based column of data being set. 7573 * column: Zero based column of data being set.
7574 * row: Zero based row of data being set. 7574 * row: Zero based row of data being set.
7575 * data: Pointer to the data to be added. 7575 * data: Pointer to the data to be added.
7576 */ 7576 */
7577 void API dw_filesystem_set_file(HWND handle, void *pointer, int row, char *filename, unsigned long icon) 7577 void API dw_filesystem_set_file(HWND handle, void *pointer, int row, char *filename, HICN icon)
7578 { 7578 {
7579 LV_ITEM lvi; 7579 LV_ITEM lvi;
7580 7580
7581 lvi.iItem = row; 7581 lvi.iItem = row;
7582 lvi.iSubItem = 0; 7582 lvi.iSubItem = 0;
7734 * pointer: Pointer to the allocated memory in dw_container_alloc(). 7734 * pointer: Pointer to the allocated memory in dw_container_alloc().
7735 * column: Zero based column of data being set. 7735 * column: Zero based column of data being set.
7736 * row: Zero based row of data being set. 7736 * row: Zero based row of data being set.
7737 * data: Pointer to the data to be added. 7737 * data: Pointer to the data to be added.
7738 */ 7738 */
7739 void API dw_filesystem_change_file(HWND handle, int row, char *filename, unsigned long icon) 7739 void API dw_filesystem_change_file(HWND handle, int row, char *filename, HICN icon)
7740 { 7740 {
7741 dw_filesystem_set_file(handle, NULL, row, filename, icon); 7741 dw_filesystem_set_file(handle, NULL, row, filename, icon);
7742 } 7742 }
7743 7743
7744 /* 7744 /*
8094 * Parameters: 8094 * Parameters:
8095 * handle: Window handle that will handle taskbar icon messages. 8095 * handle: Window handle that will handle taskbar icon messages.
8096 * icon: Icon handle to display in the taskbar. 8096 * icon: Icon handle to display in the taskbar.
8097 * bubbletext: Text to show when the mouse is above the icon. 8097 * bubbletext: Text to show when the mouse is above the icon.
8098 */ 8098 */
8099 void API dw_taskbar_insert(HWND handle, unsigned long icon, char *bubbletext) 8099 void API dw_taskbar_insert(HWND handle, HICN icon, char *bubbletext)
8100 { 8100 {
8101 NOTIFYICONDATA tnid; 8101 NOTIFYICONDATA tnid;
8102 8102
8103 tnid.cbSize = sizeof(NOTIFYICONDATA); 8103 tnid.cbSize = sizeof(NOTIFYICONDATA);
8104 tnid.hWnd = handle; 8104 tnid.hWnd = handle;
8118 * Deletes an icon from the taskbar. 8118 * Deletes an icon from the taskbar.
8119 * Parameters: 8119 * Parameters:
8120 * handle: Window handle that was used with dw_taskbar_insert(). 8120 * handle: Window handle that was used with dw_taskbar_insert().
8121 * icon: Icon handle that was used with dw_taskbar_insert(). 8121 * icon: Icon handle that was used with dw_taskbar_insert().
8122 */ 8122 */
8123 void API dw_taskbar_delete(HWND handle, unsigned long icon) 8123 void API dw_taskbar_delete(HWND handle, HICN icon)
8124 { 8124 {
8125 NOTIFYICONDATA tnid; 8125 NOTIFYICONDATA tnid;
8126 8126
8127 tnid.cbSize = sizeof(NOTIFYICONDATA); 8127 tnid.cbSize = sizeof(NOTIFYICONDATA);
8128 tnid.hWnd = handle; 8128 tnid.hWnd = handle;