]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/menu.cpp
1. status bar can now be positioned on top (and anywhere, in fact)
[wxWidgets.git] / src / os2 / menu.cpp
index 023870332c4af2c5f8c7818ac7d77381936154db..a08ced90aabcdf072021ef778c21781cca29312d 100644 (file)
@@ -71,28 +71,36 @@ void wxMenu::Init()
     m_bDoBreak = FALSE;
 
     //
-    // Create the menu
-    //
-    m_hMenu = ::WinCreateWindow( HWND_DESKTOP // parent
-                                ,WC_MENU      // type
-                                ,"Menu"       // a generic name
-                                ,0L           // no style flag
-                                ,0L,0L,0L,0L  // no position
-                                ,NULLHANDLE   // no owner
-                                ,NULLHANDLE   // no insertion position
-                                ,0L           // no ID needed for dynamic creation
-                                ,NULL         // no control data
-                                ,NULL         // no presentation params
-                               );
-    if (!m_hMenu)
+    // Create the menu (to be used as a submenu or a popup)
+    //
+    if ((m_hMenu =  ::WinCreateWindow( HWND_DESKTOP
+                                      ,(const wxChar*)WC_MENU
+                                      ,"Menu"
+                                      ,0L
+                                      ,0L
+                                      ,0L
+                                      ,0L
+                                      ,0L
+                                      ,NULLHANDLE
+                                      ,HWND_TOP
+                                      ,0L
+                                      ,NULL
+                                      ,NULL
+                                     )) == 0)
     {
         wxLogLastError("WinLoadMenu");
     }
+    m_vMenuData.iPosition   = 0;
+    m_vMenuData.afStyle     = MIS_SUBMENU | MIS_TEXT;
+    m_vMenuData.afAttribute = (USHORT)0;
+    m_vMenuData.id          = (USHORT)0;
+    m_vMenuData.hwndSubMenu = m_hMenu;
+    m_vMenuData.hItem       = NULLHANDLE;
 
     //
     // If we have a title, insert it in the beginning of the menu
     //
-    if (!!m_title)
+    if (!m_title.IsEmpty())
     {
         Append( idMenuTitle
                ,m_title
@@ -205,6 +213,9 @@ bool wxMenu::DoInsertOrAppend(
 , size_t                            nPos
 )
 {
+    ERRORID                         vError;
+    wxString                        sError;
+
 #if wxUSE_ACCEL
     UpdateAccel(pItem);
 #endif // wxUSE_ACCEL
@@ -230,13 +241,13 @@ bool wxMenu::DoInsertOrAppend(
     //
 
     wxMenu*                         pSubmenu = pItem->GetSubMenu();
-    MENUITEM                        vItem;
 
-    if (pSubmenu != NULL )
+    if (pSubmenu != NULL)
     {
         wxASSERT_MSG(pSubmenu->GetHMenu(), wxT("invalid submenu"));
         pSubmenu->SetParent(this);
 
+        m_vMenuData.iPosition = 0; // submenus have a 0 position
         m_vMenuData.id = (USHORT)pSubmenu->GetHMenu();
         m_vMenuData.afStyle |= MIS_SUBMENU;
     }
@@ -253,6 +264,7 @@ bool wxMenu::DoInsertOrAppend(
         //
         // Want to get {Measure|Draw}Item messages?
         // item draws itself, pass pointer to it in data parameter
+        // Will eventually need to set the image handle somewhere into m_vMenuData.hItem
         //
         m_vMenuData.afStyle |= MIS_OWNERDRAW;
         pData = (BYTE*)pItem;
@@ -267,41 +279,29 @@ bool wxMenu::DoInsertOrAppend(
         pData = (char*)pItem->GetText().c_str();
     }
 
-    BOOL                            bOk;
+    APIRET                          rc;
+
+    m_vMenuData.hwndSubMenu = NULLHANDLE;
+    m_vMenuData.hItem       = NULLHANDLE;
 
     //
-    // -1 means this is a sub menu not a menuitem
+    // -1 means append at end
     //
     if (nPos == (size_t)-1)
     {
-        HWND                        hSubMenu = ::WinCreateWindow( HWND_DESKTOP // parent
-                                                                 ,WC_MENU      // type
-                                                                 ,"Menu"       // a generic name
-                                                                 ,0L           // no style flag
-                                                                 ,0L,0L,0L,0L  // no position
-                                                                 ,NULLHANDLE   // no owner
-                                                                 ,NULLHANDLE   // no insertion position
-                                                                 ,0L           // no ID needed for dynamic creation
-                                                                 ,NULL         // no control data
-                                                                 ,NULL         // no presentation params
-                                                                );
-
-        m_vMenuData.iPosition   = 0;
-        m_vMenuData.hwndSubMenu = hSubMenu;
-        m_vMenuData.hItem       = NULLHANDLE;
-
-        bOk = (bool)::WinSendMsg(GetHmenu(), MM_INSERTITEM, (MPARAM)&vItem, (MPARAM)NULL);
+        m_vMenuData.iPosition = MIT_END;
     }
     else
     {
         m_vMenuData.iPosition   = nPos;
-        m_vMenuData.hwndSubMenu = NULLHANDLE;
-        m_vMenuData.hItem       = NULLHANDLE;
-        bOk = (bool)::WinSendMsg(GetHmenu(), MM_INSERTITEM, (MPARAM)&vItem, (MPARAM)pData);
     }
 
-    if (!bOk)
+    rc = (APIRET)::WinSendMsg(GetHmenu(), MM_INSERTITEM, (MPARAM)&m_vMenuData, (MPARAM)pData);
+    if (rc == MIT_MEMERROR || rc == MIT_ERROR)
     {
+        vError = ::WinGetLastError(vHabmain);
+        sError = wxPMErrorToStr(vError);
+        wxLogError("Error inserting or appending a menuitem. Error: %s\n", sError);
         wxLogLastError("Insert or AppendMenu");
         return FALSE;
     }
@@ -609,33 +609,44 @@ void wxMenuBar::Refresh()
 {
     wxCHECK_RET( IsAttached(), wxT("can't refresh unatteched menubar") );
 
-//    DrawMenuBar(GetHwndOf(m_menuBarFrame));
-}
+    WinSendMsg(GetWinHwnd(m_pMenuBarFrame), WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0);
+} // end of wxMenuBar::Refresh
 
 WXHMENU wxMenuBar::Create()
 {
     MENUITEM                        vItem;
+    HWND                            hFrame;
+    HWND                            hMenuBar = NULLHANDLE;
 
     if (m_hMenu != 0 )
         return m_hMenu;
 
     wxCHECK_MSG(!m_hMenu, TRUE, wxT("menubar already created"));
 
+    //
+    // Menubars should be associated with a frame otherwise they are popups
+    //
+    if (m_pMenuBarFrame != NULL)
+        hFrame = GetWinHwnd(m_pMenuBarFrame);
+    else
+        hFrame = HWND_DESKTOP;
     //
     // Create an empty menu and then fill it with insertions
     //
-    m_hMenu = ::WinCreateWindow( HWND_DESKTOP // parent
-                                ,WC_MENU      // type
-                                ,"Menu"       // a generic name
-                                ,0L           // no style flag
-                                ,0L,0L,0L,0L  // no position
-                                ,NULLHANDLE   // no owner
-                                ,NULLHANDLE   // no insertion position
-                                ,0L           // no ID needed for dynamic creation
-                                ,NULL         // no control data
-                                ,NULL         // no presentation params
-                               );
-    if (!m_hMenu)
+    if (!wxWindow::OS2Create( hFrame
+                             ,WC_MENU
+                             ,"Menu"
+                             ,MS_ACTIONBAR | WS_SYNCPAINT | WS_VISIBLE
+                             ,0L
+                             ,0L
+                             ,0L
+                             ,0L
+                             ,hFrame
+                             ,HWND_TOP
+                             ,FID_MENU
+                             ,(PVOID)NULL
+                             ,(PVOID)NULL
+                            ))
     {
         wxLogLastError("CreateMenu");
     }
@@ -643,19 +654,13 @@ WXHMENU wxMenuBar::Create()
     {
         size_t                      nCount = GetMenuCount();
 
+        hMenuBar = GetHwnd();
         for (size_t i = 0; i < nCount; i++)
         {
-            vItem.iPosition   = 0;
-            vItem.afStyle     = MIS_SUBMENU | MIS_TEXT;
-            vItem.afAttribute = (USHORT)0;
-            vItem.id          = (USHORT)0;
-            vItem.hwndSubMenu = m_menus[i]->GetHMenu();
-            vItem.hItem       = NULLHANDLE;
-
-            ::WinSendMsg(GetHmenu(), MM_INSERTITEM, (MPARAM)&vItem, (MPARAM)m_titles[i].c_str());
+            ::WinSendMsg(hMenuBar, MM_INSERTITEM, (MPARAM)&m_menus[i]->m_vMenuData, (MPARAM)m_titles[i].c_str());
         }
     }
-    return m_hMenu;
+    return hMenuBar;
 } // end of wxMenuBar::Create
 
 // ---------------------------------------------------------------------------