comparison win/dw.c @ 1667:9dbd2984c1e5

Initial implementation of dw_box_remove() and dw_box_remove_at_index() for OS/2, Windows and template. Mac and GTK2/3 versions coming soon.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 26 Apr 2012 20:33:39 +0000
parents a76fb5f1a6c8
children 36a090da4cb1
comparison
equal deleted inserted replaced
1666:df25fee81502 1667:9dbd2984c1e5
4321 * handle: The window handle to destroy. 4321 * handle: The window handle to destroy.
4322 */ 4322 */
4323 int API dw_window_destroy(HWND handle) 4323 int API dw_window_destroy(HWND handle)
4324 { 4324 {
4325 HWND parent; 4325 HWND parent;
4326 Box *thisbox;
4327 HMENU menu; 4326 HMENU menu;
4328 4327
4329 /* Handle special case for menu handle */ 4328 /* Handle special case for menu handle */
4330 if(handle < (HWND)65536) 4329 if(handle < (HWND)65536)
4331 { 4330 {
4339 return dw_menu_delete_item((HMENUI)menu, id); 4338 return dw_menu_delete_item((HMENUI)menu, id);
4340 return DW_ERROR_UNKNOWN; 4339 return DW_ERROR_UNKNOWN;
4341 } 4340 }
4342 4341
4343 parent = GetParent(handle); 4342 parent = GetParent(handle);
4344 thisbox = (Box *)GetWindowLongPtr(parent, GWLP_USERDATA);
4345 menu = GetMenu(handle); 4343 menu = GetMenu(handle);
4346 4344
4347 if(menu) 4345 if(menu)
4348 _free_menu_data(menu); 4346 _free_menu_data(menu);
4349 4347
4350 /* If it is a desktop window let WM_DESTROY handle it */ 4348 /* If it is a desktop window let WM_DESTROY handle it */
4351 if(parent != HWND_DESKTOP) 4349 if(parent != HWND_DESKTOP)
4352 { 4350 {
4353 /* If the parent box has items... 4351 dw_box_remove(handle);
4354 * try to remove it from the layout
4355 */
4356 if(thisbox && thisbox->count)
4357 {
4358 int z, index = -1;
4359 Item *tmpitem, *thisitem = thisbox->items;
4360
4361 for(z=0;z<thisbox->count;z++)
4362 {
4363 if(thisitem[z].hwnd == handle)
4364 index = z;
4365 }
4366
4367 if(index == -1)
4368 return 0;
4369
4370 tmpitem = malloc(sizeof(Item)*(thisbox->count-1));
4371
4372 /* Copy all but the current entry to the new list */
4373 for(z=0;z<index;z++)
4374 {
4375 tmpitem[z] = thisitem[z];
4376 }
4377 for(z=index+1;z<thisbox->count;z++)
4378 {
4379 tmpitem[z-1] = thisitem[z];
4380 }
4381
4382 thisbox->items = tmpitem;
4383 free(thisitem);
4384 thisbox->count--;
4385 /* Queue a redraw on the top-level window */
4386 _dw_redraw(_toplevel_window(handle), TRUE);
4387 }
4388 _free_window_memory(handle, 0); 4352 _free_window_memory(handle, 0);
4389 EnumChildWindows(handle, _free_window_memory, 0); 4353 EnumChildWindows(handle, _free_window_memory, 0);
4390 } 4354 }
4391 return DestroyWindow(handle); 4355 return DestroyWindow(handle);
4392 } 4356 }
7007 _dw_redraw(_toplevel_window(item), TRUE); 6971 _dw_redraw(_toplevel_window(item), TRUE);
7008 } 6972 }
7009 } 6973 }
7010 6974
7011 /* 6975 /*
6976 * Remove windows (widgets) from the box they are packed into.
6977 * Parameters:
6978 * handle: Window handle of the item to be back.
6979 * Returns:
6980 * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure.
6981 */
6982 int API dw_box_remove(HWND handle)
6983 {
6984 HWND parent = GetParent(handle);
6985
6986 if(handle && parent != HWND_DESKTOP)
6987 {
6988 Box *thisbox = (Box *)GetWindowLongPtr(parent, GWLP_USERDATA);
6989
6990 /* If the parent box has items...
6991 * try to remove it from the layout
6992 */
6993 if(thisbox && thisbox->count)
6994 {
6995 int z, index = -1;
6996 Item *tmpitem, *thisitem = thisbox->items;
6997
6998 for(z=0;z<thisbox->count;z++)
6999 {
7000 if(thisitem[z].hwnd == handle)
7001 index = z;
7002 }
7003
7004 if(index == -1)
7005 return DW_ERROR_GENERAL;
7006
7007 tmpitem = malloc(sizeof(Item)*(thisbox->count-1));
7008
7009 /* Copy all but the current entry to the new list */
7010 for(z=0;z<index;z++)
7011 {
7012 tmpitem[z] = thisitem[z];
7013 }
7014 for(z=index+1;z<thisbox->count;z++)
7015 {
7016 tmpitem[z-1] = thisitem[z];
7017 }
7018
7019 thisbox->items = tmpitem;
7020 free(thisitem);
7021 thisbox->count--;
7022 SetParent(handle, DW_HWND_OBJECT);
7023 /* Queue a redraw on the top-level window */
7024 _dw_redraw(_toplevel_window(handle), TRUE);
7025 return DW_ERROR_NONE;
7026 }
7027 }
7028 return DW_ERROR_GENERAL;
7029 }
7030
7031 /*
7032 * Remove windows (widgets) from a box at an arbitrary location.
7033 * Parameters:
7034 * box: Window handle of the box to be removed from.
7035 * index: 0 based index of packed items.
7036 * Returns:
7037 * Handle to the removed item on success, 0 on failure.
7038 */
7039 HWND API dw_box_remove_at_index(HWND box, int index)
7040 {
7041 Box *thisbox = (Box *)GetWindowLongPtr(box, GWLP_USERDATA);
7042
7043 /* Try to remove it from the layout */
7044 if(thisbox && index > -1 && index < thisbox->count)
7045 {
7046 int z;
7047 Item *tmpitem, *thisitem = thisbox->items;
7048 HWND handle = thisitem[index].hwnd;
7049
7050 tmpitem = malloc(sizeof(Item)*(thisbox->count-1));
7051
7052 /* Copy all but the current entry to the new list */
7053 for(z=0;z<index;z++)
7054 {
7055 tmpitem[z] = thisitem[z];
7056 }
7057 for(z=index+1;z<thisbox->count;z++)
7058 {
7059 tmpitem[z-1] = thisitem[z];
7060 }
7061
7062 thisbox->items = tmpitem;
7063 free(thisitem);
7064 thisbox->count--;
7065 /* If it isn't padding, reset the parent */
7066 if(handle)
7067 SetParent(handle, DW_HWND_OBJECT);
7068 /* Queue a redraw on the top-level window */
7069 _dw_redraw(_toplevel_window(handle), TRUE);
7070 return DW_ERROR_NONE;
7071 }
7072 return DW_ERROR_GENERAL;
7073 }
7074
7075 /*
7012 * Pack windows (widgets) into a box at an arbitrary location. 7076 * Pack windows (widgets) into a box at an arbitrary location.
7013 * Parameters: 7077 * Parameters:
7014 * box: Window handle of the box to be packed into. 7078 * box: Window handle of the box to be packed into.
7015 * item: Window handle of the item to be back. 7079 * item: Window handle of the item to pack.
7016 * index: 0 based index of packed items. 7080 * index: 0 based index of packed items.
7017 * width: Width in pixels of the item or -1 to be self determined. 7081 * width: Width in pixels of the item or -1 to be self determined.
7018 * height: Height in pixels of the item or -1 to be self determined. 7082 * height: Height in pixels of the item or -1 to be self determined.
7019 * hsize: TRUE if the window (widget) should expand horizontally to fill space given. 7083 * hsize: TRUE if the window (widget) should expand horizontally to fill space given.
7020 * vsize: TRUE if the window (widget) should expand vertically to fill space given. 7084 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
7027 7091
7028 /* 7092 /*
7029 * Pack windows (widgets) into a box from the start (or top). 7093 * Pack windows (widgets) into a box from the start (or top).
7030 * Parameters: 7094 * Parameters:
7031 * box: Window handle of the box to be packed into. 7095 * box: Window handle of the box to be packed into.
7032 * item: Window handle of the item to be back. 7096 * item: Window handle of the item to pack.
7033 * width: Width in pixels of the item or -1 to be self determined. 7097 * width: Width in pixels of the item or -1 to be self determined.
7034 * height: Height in pixels of the item or -1 to be self determined. 7098 * height: Height in pixels of the item or -1 to be self determined.
7035 * hsize: TRUE if the window (widget) should expand horizontally to fill space given. 7099 * hsize: TRUE if the window (widget) should expand horizontally to fill space given.
7036 * vsize: TRUE if the window (widget) should expand vertically to fill space given. 7100 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
7037 * pad: Number of pixels of padding around the item. 7101 * pad: Number of pixels of padding around the item.
7046 7110
7047 /* 7111 /*
7048 * Pack windows (widgets) into a box from the end (or bottom). 7112 * Pack windows (widgets) into a box from the end (or bottom).
7049 * Parameters: 7113 * Parameters:
7050 * box: Window handle of the box to be packed into. 7114 * box: Window handle of the box to be packed into.
7051 * item: Window handle of the item to be back. 7115 * item: Window handle of the item to pack.
7052 * width: Width in pixels of the item or -1 to be self determined. 7116 * width: Width in pixels of the item or -1 to be self determined.
7053 * height: Height in pixels of the item or -1 to be self determined. 7117 * height: Height in pixels of the item or -1 to be self determined.
7054 * hsize: TRUE if the window (widget) should expand horizontally to fill space given. 7118 * hsize: TRUE if the window (widget) should expand horizontally to fill space given.
7055 * vsize: TRUE if the window (widget) should expand vertically to fill space given. 7119 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
7056 * pad: Number of pixels of padding around the item. 7120 * pad: Number of pixels of padding around the item.