changeset 1371:896347a9be19

Initial versions of dw_menu_delete_item() on OS/2 and Windows.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 22 Nov 2011 20:46:37 +0000
parents e705051d841c
children 8e27dd96a97e
files dw.h dwtest.c os2/dw.c os2/dw.def readme template/dw.c win/dw-mingw.def win/dw.c win/dw.def
diffstat 9 files changed, 90 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/dw.h	Sun Nov 20 16:34:44 2011 +0000
+++ b/dw.h	Tue Nov 22 20:46:37 2011 +0000
@@ -1624,9 +1624,7 @@
 HMENUI API dw_menu_new(unsigned long id);
 HMENUI API dw_menubar_new(HWND location);
 HWND API dw_menu_append_item(HMENUI menu, char *title, unsigned long id, unsigned long flags, int end, int check, HMENUI submenu);
-#ifdef INCOMPLETE
-void API dw_menu_delete_item(HMENUI menu, unsigned long id);
-#endif
+int API dw_menu_delete_item(HMENUI menu, unsigned long id);
 void API dw_menu_item_set_check(HMENUI menu, unsigned long id, int check);
 void API dw_menu_item_set_state( HMENUI menux, unsigned long id, unsigned long state);
 void API dw_menu_popup(HMENUI *menu, HWND parent, int x, int y);
--- a/dwtest.c	Sun Nov 20 16:34:44 2011 +0000
+++ b/dwtest.c	Tue Nov 22 20:46:37 2011 +0000
@@ -554,6 +554,7 @@
         dw_menu_item_set_state( changeable_menu, NONCHECKABLE_MENUITEMID, DW_MIS_ENABLED );
         menu_enabled = 1;
     }
+    dw_menu_delete_item( changeable_menu, 2003 );
     return 0;
 }
 
--- a/os2/dw.c	Sun Nov 20 16:34:44 2011 +0000
+++ b/os2/dw.c	Tue Nov 22 20:46:37 2011 +0000
@@ -4351,12 +4351,27 @@
  */
 int API dw_window_destroy(HWND handle)
 {
-   HWND frame, menu, parent = WinQueryWindow(handle, QW_PARENT);
-   Box *thisbox = WinQueryWindowPtr(parent, QWP_USER);
+   HWND frame, menu, parent;
+   Box *thisbox;
 
    if(!handle)
-      return -1;
-
+      return DW_ERROR_UNKNOWN;
+
+   /* Handle special case for menu handle */
+   if(handle < 65536)
+   {
+      char buffer[30];
+      
+      sprintf(buffer, "_dw_id%ld", handle);
+      menu = dw_window_get_data(hwndApp, buffer);
+      
+      if(menu && WinIsWindow(dwhab, menu))
+          return dw_menu_delete_item((HEMNUI)menu, handle);
+      return DW_ERROR_UNKNOWN;
+   }
+   
+   parent = WinQueryWindow(handle, QW_PARENT);
+   thisbox = WinQueryWindowPtr(parent, QWP_USER);
    frame = (HWND)dw_window_get_data(handle, "_dw_combo_box");
 
    if((menu = WinWindowFromID(handle, FID_MENU)) != NULLHANDLE)
@@ -5198,6 +5213,24 @@
 }
 
 /*
+ * Deletes the menu item specified
+ * Parameters:
+ *       menu: The handle to the  menu in which the item was appended.
+ *       id: Menuitem id.
+ * Returns: 
+ *       DW_ERROR_NONE (0) on success or DW_ERROR_UNKNOWN on failure.
+ */
+int API dw_menu_delete_item(HMENUI menux, unsigned long id)
+{
+   if(id < 65536)
+   {
+      WinSendMsg(menux, MM_DELETEITEM, MPFROM2SHORT(id, FALSE), 0);
+      return DW_ERROR_NONE;
+   }
+   return DW_ERROR_UNKNOWN;
+}
+
+/*
  * Pops up a context menu at given x and y coordinates.
  * Parameters:
  *       menu: The handle the the existing menu.
--- a/os2/dw.def	Sun Nov 20 16:34:44 2011 +0000
+++ b/os2/dw.def	Tue Nov 22 20:46:37 2011 +0000
@@ -179,6 +179,7 @@
   dw_menu_popup                          @284
   dw_menu_destroy                        @285
   dw_menu_item_set_state                 @286
+  dw_menu_delete_item                    @287
 
   dw_pointer_query_pos                   @290
   dw_pointer_set_pos                     @291
--- a/readme	Sun Nov 20 16:34:44 2011 +0000
+++ b/readme	Tue Nov 22 20:46:37 2011 +0000
@@ -1,4 +1,4 @@
-This is a stable release of Dynamic Windows version 2.2.0.
+This is a preview release of Dynamic Windows version 2.3.
 
 The current Dynamic Windows source base is considered stable on:
 OS/2, Mac, Windows, Linux, FreeBSD and Solaris.
@@ -31,45 +31,9 @@
 not support it by default. Looking into importing functionality 
 from available libraries (Firefox, Webkit, Qt, etc).
 
-Changes from version 2.1:
-Added printing support via dw_print_new, dw_print_run and dw_print_cancel.
-Added pixmap font override support. In prior versions when drawing
-   text to pixmaps the font set on the associated window handle is used.
-   dw_pixmap_set_font() can now override that font setting, and now
-   pixmaps without associated windows are supported and used in printing.
-Added dw_pixmap_stretch_bitblt() which allows for scaling during bitblt.
-   This function is necessary largely for very hi-res printer contexts.   
-Added dw_mutex_trylock() function to try to obtain a mutex without blocking.
-Added DW_TIMEOUT_INFINITE which can now be used with dw_event_wait() in 
-   addition to dw_named_event_wait(), to block until the event is posted.
-Added DW_PERCENT_INDETERMINATE which can be passed to dw_percent_set_pos().
-   This should work on all platforms except old versions of Windows. 
-Added the subversion revision number as the third Dynamic Windows version 
-   number when building from a subversion source tree.
-Added dw_container_set_row_data() and dw_container_change_row_data() macros
-   which just call dw_container_set/change_row_title() but with (void *).
-Added dw_container_set_stripe() to set alternating row colors.
-   Currently Mac, Win and GTK are supported.
-Added taskbar support on the Mac, GTK (Gnome) and OS/2 (e/XCenter+Systray).
-Added PNG/JPG/GIF/TIFF support on Windows via GDI+.
-Added support for GdkPixbuf inline images in GTK 2 and 3.
-Added dw_draw_arc() function for drawing arcs, ellipses and circles.
-Added DW_DRAW_DEFAULT, DW_DRAW_FILL and DW_DRAW_FULL flags which can be passed
-   to dw_draw_arc(), dw_draw_rect() and dw_draw_polygon().  The fill parameter
-   in the latter two has been replaced with flags where DW_DRAW_FILL is the
-   same as TRUE so code using the old scheme should still work unchanged.
-Added DW_MENU_AUTO and DW_MENU_POPUP constants for autogenerating menu IDs.
-Added dw_debug() function for sending debug messages to the console.
-Added path and/or filename support to dw_file_browse() on OS/2, Windows,
-   GTK2, GTK3 and Mac 10.6 or higher.
-Added custom calendar widget for OS/2, leaving only the HTML widget missing.
-Improved container optimization on Mac, header width now taken into account.
-Fixes for incorrect return codes from the dw_event_* functions on Windows.
-Fixes for incorrect behavior on key_press callbacks on Mac and Windows.
-Fixes for MDI support in GTK3. 
-Fixes for problems with multiple sliders/percent widgets in a box on OS/2.
-Fixes for lots of GTK3 layout and window positioning issues... 
-   although minimum size issues are still present.
+Changes from version 2.2:
+Added dw_menu_delete_item() for removing menu items.
+    Now you can use dw_window_destroy() on menu items handles also.
 
 Dynamic Windows Documentation is available at:
 
--- a/template/dw.c	Sun Nov 20 16:34:44 2011 +0000
+++ b/template/dw.c	Tue Nov 22 20:46:37 2011 +0000
@@ -2415,6 +2415,19 @@
 }
 
 /*
+ * Deletes the menu item specified.
+ * Parameters:
+ *       menu: The handle to the  menu in which the item was appended.
+ *       id: Menuitem id.
+ * Returns: 
+ *       DW_ERROR_NONE (0) on success or DW_ERROR_UNKNOWN on failure.
+ */
+int API dw_menu_delete_item(HMENUI menux, unsigned long id)
+{
+   return DW_ERROR_UNKNOWN;
+}
+
+/*
  * Pops up a context menu at given x and y coordinates.
  * Parameters:
  *       menu: The handle the the existing menu.
--- a/win/dw-mingw.def	Sun Nov 20 16:34:44 2011 +0000
+++ b/win/dw-mingw.def	Tue Nov 22 20:46:37 2011 +0000
@@ -176,6 +176,7 @@
   dw_menu_popup                          @284
   dw_menu_destroy                        @285
   dw_menu_item_set_state                 @286
+  dw_menu_delete_item                    @287
 
   dw_pointer_query_pos                   @290
   dw_pointer_set_pos                     @291
--- a/win/dw.c	Sun Nov 20 16:34:44 2011 +0000
+++ b/win/dw.c	Tue Nov 22 20:46:37 2011 +0000
@@ -4050,10 +4050,28 @@
  */
 int API dw_window_destroy(HWND handle)
 {
-   HWND parent = GetParent(handle);
-   Box *thisbox = (Box *)GetWindowLongPtr(parent, GWLP_USERDATA);
-   HMENU menu = GetMenu(handle);
-
+   HWND parent;
+   Box *thisbox;
+   HMENU menu;
+
+   /* Handle special case for menu handle */
+   if(handle < (HWND)65536)
+   {
+      char buffer[31] = {0};
+      ULONG id = (ULONG)handle;
+      
+      _snprintf(buffer, 30, "_dw_id%ld", id);
+      menu = (HMENU)dw_window_get_data(DW_HWND_OBJECT, buffer);
+      
+      if(menu && IsMenu(menu))
+         return dw_menu_delete_item((HMENUI)menu, id);
+      return DW_ERROR_UNKNOWN;
+   }
+   
+   parent = GetParent(handle);
+   thisbox = (Box *)GetWindowLongPtr(parent, GWLP_USERDATA);
+   menu = GetMenu(handle);
+   
    if(menu)
       _free_menu_data(menu);
 
@@ -5183,13 +5201,14 @@
 }
 
 /*
- * INCOMPLETE
  * Deletes the menu item specified
  * Parameters:
  *       menu: The handle to the  menu in which the item was appended.
  *       id: Menuitem id.
- */
-void API dw_menu_delete_item(HMENUI menux, unsigned long id)
+ * Returns: 
+ *       DW_ERROR_NONE (0) on success or DW_ERROR_UNKNOWN on failure.
+ */
+int API dw_menu_delete_item(HMENUI menux, unsigned long id)
 {
    HMENU mymenu = (HMENU)menux;
 
@@ -5197,12 +5216,11 @@
       mymenu = (HMENU)dw_window_get_data(menux, "_dw_menu");
 
    if ( DeleteMenu(mymenu, id, MF_BYCOMMAND) == 0 )
-   {
-      char lasterror[257];
-      FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT), lasterror, 256, NULL);
-      fprintf(stderr, "Error deleting menu: %s", lasterror);
-   }
-   DrawMenuBar(menux);
+      return DW_ERROR_UNKNOWN;
+   
+   if( (HMENU)menux != mymenu )
+      DrawMenuBar(menux);
+   return DW_ERROR_NONE;
 }
 
 /*
--- a/win/dw.def	Sun Nov 20 16:34:44 2011 +0000
+++ b/win/dw.def	Tue Nov 22 20:46:37 2011 +0000
@@ -176,6 +176,7 @@
   dw_menu_popup                          @284
   dw_menu_destroy                        @285
   dw_menu_item_set_state                 @286
+  dw_menu_delete_item                    @287
 
   dw_pointer_query_pos                   @290
   dw_pointer_set_pos                     @291