]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/wince/tbarwce.cpp
1.
[wxWidgets.git] / src / msw / wince / tbarwce.cpp
index 554b07da26cc1b1ee493a34175af2da424db8fec..a1be85a8c6ee174c7b5c412fc72c5624a13f9ffd 100644 (file)
@@ -17,7 +17,7 @@
 // headers
 // ----------------------------------------------------------------------------
 
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
     #pragma implementation "tbarwce.h"
 #endif
 
@@ -52,6 +52,7 @@
 #include <windowsx.h>
 #include <tchar.h>
 #include <ole2.h>
+#include <shellapi.h>
 #include <commctrl.h>
 #include <aygshell.h>
 
 // wxWin macros
 // ----------------------------------------------------------------------------
 
-IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarBase)
+IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
 
 BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase)
     EVT_MOUSE_EVENTS(wxToolBar::OnMouseEvent)
@@ -261,7 +262,11 @@ bool wxToolBar::MSWCreateToolbar(const wxPoint& pos, const wxSize& size, wxMenuB
     memset (&mbi, 0, sizeof (SHMENUBARINFO));
     mbi.cbSize     = sizeof (SHMENUBARINFO);
     mbi.hwndParent = (HWND) GetParent()->GetHWND();
+#if wxUSE_SMARTPHONE
+    mbi.nToolBarId = 5002;
+#else
     mbi.nToolBarId = 5000;
+#endif
     mbi.nBmpId     = 0;
     mbi.cBmpImages = 0;
     mbi.dwFlags = 0 ; // SHCMBF_EMPTYBAR;
@@ -285,44 +290,7 @@ bool wxToolBar::MSWCreateToolbar(const wxPoint& pos, const wxSize& size, wxMenuB
 
     if (menuBar)
         menuBar->Create();
-#if 0
-    {
-        HMENU hMenu = (HMENU)::SendMessage(mbi.hwndMB, SHCMBM_GETMENU, (WPARAM)0, (LPARAM)0);
-        if (hMenu)
-        {
-            TBBUTTON tbButton; 
-            memset(&tbButton, 0, sizeof(TBBUTTON));
-            tbButton.iBitmap = I_IMAGENONE;
-            tbButton.fsState = TBSTATE_ENABLED;
-            tbButton.fsStyle = TBSTYLE_DROPDOWN | TBSTYLE_NO_DROPDOWN_ARROW | TBSTYLE_AUTOSIZE;
-            
-            size_t i;
-            for (i = 0; i < menuBar->GetMenuCount(); i++)
-            {
-                HMENU hPopupMenu = (HMENU) menuBar->GetMenu(i)->GetHMenu() ;
-                tbButton.dwData = (DWORD)hPopupMenu;
-                wxString label = wxStripMenuCodes(menuBar->GetLabelTop(i));
-                tbButton.iString = (int) label.c_str();
-
-                tbButton.idCommand = NewControlId();
-                if (!::SendMessage((HWND) GetHWND(), TB_INSERTBUTTON, i, (LPARAM)&tbButton))
-                {
-                    wxLogLastError(wxT("TB_INSERTBUTTON"));
-                }
-            }
-        }
-    }
-#endif
     
-#if 0
-    CommandBar_AddToolTips(    hwndCB,    uNumSmallTips,szSmallTips);
-    
-    CommandBar_AddBitmap(hwndCB, HINST_COMMCTRL, IDB_STD_SMALL_COLOR,
-        15, 16, 16);
-    // Add buttons in tbSTDButton to Commandbar
-    CommandBar_AddButtons(hwndCB, sizeof(tbSTDButton)/sizeof(TBBUTTON),
-        tbSTDButton);
-#endif    
     return TRUE;
 }
 
@@ -378,6 +346,9 @@ void wxToolBar::Recreate()
 
 wxToolBar::~wxToolBar()
 {
+    if (GetMenuBar())
+        GetMenuBar()->SetToolBar(NULL);
+
     // we must refresh the frame size when the toolbar is deleted but the frame
     // is not - otherwise toolbar leaves a hole in the place it used to occupy
     wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
@@ -548,6 +519,69 @@ bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool)
     return TRUE;
 }
 
+struct wxToolBarIdMapping
+{
+    int m_wxwinId;
+    int m_winceId;
+};
+
+static wxToolBarIdMapping sm_ToolBarIdMappingArray[] =
+{
+    { wxID_COPY, STD_COPY },
+    { wxID_CUT, STD_CUT },
+    { wxID_FIND, STD_FIND },
+    { wxID_PASTE, STD_PASTE },
+    { wxID_NEW, STD_FILENEW },
+    { wxID_OPEN, STD_FILEOPEN },
+    { wxID_SAVE, STD_FILESAVE },
+    { wxID_PRINT, STD_PRINT },
+    { wxID_PREVIEW, STD_PRINTPRE },
+    { wxID_UNDO, STD_UNDO  },
+    { wxID_REDO, STD_REDOW },
+    { wxID_HELP, STD_HELP },
+    { wxID_DELETE, STD_DELETE },
+    { wxID_REPLACE, STD_REPLACE },
+    { wxID_PROPERTIES, STD_PROPERTIES },
+    { wxID_VIEW_DETAILS, VIEW_DETAILS },
+    { wxID_VIEW_SORTDATE, VIEW_SORTDATE },
+    { wxID_VIEW_LARGEICONS, VIEW_LARGEICONS },
+    { wxID_VIEW_SORTNAME, VIEW_SORTNAME },
+    { wxID_VIEW_LIST, VIEW_LIST },
+    { wxID_VIEW_SORTSIZE, VIEW_SORTSIZE },
+    { wxID_VIEW_SMALLICONS, VIEW_SMALLICONS },
+    { wxID_VIEW_SORTTYPE, VIEW_SORTTYPE },
+    { 0, 0},
+};
+
+static int wxFindIdForWinceId(int id)
+{
+    int i = 0;
+    while (TRUE)
+    {
+        if (sm_ToolBarIdMappingArray[i].m_winceId == 0)
+            return -1;
+        else if (sm_ToolBarIdMappingArray[i].m_winceId == id)
+            return sm_ToolBarIdMappingArray[i].m_wxwinId;
+        i ++;
+    }
+    return -1;
+}
+
+static int wxFindIdForwxWinId(int id)
+{
+    int i = 0;
+    while (TRUE)
+    {
+        if (sm_ToolBarIdMappingArray[i].m_wxwinId == 0)
+            return -1;
+        else if (sm_ToolBarIdMappingArray[i].m_wxwinId == id)
+            return sm_ToolBarIdMappingArray[i].m_winceId;
+        i ++;
+    }
+    return -1;
+}
+
+
 bool wxToolBar::Realize()
 {
     const size_t nTools = GetToolsCount();
@@ -573,6 +607,10 @@ bool wxToolBar::Realize()
     // add the buttons and separators
     // ------------------------------
 
+    // Use standard buttons
+    CommandBar_AddBitmap((HWND) GetHWND(), HINST_COMMCTRL,
+        IDB_STD_SMALL_COLOR, 0, 16, 16);
+
     TBBUTTON *buttons = new TBBUTTON[nTools];
 
     // this array will hold the indices of all controls in the toolbar
@@ -585,6 +623,8 @@ bool wxToolBar::Realize()
     {
         wxToolBarToolBase *tool = node->GetData();
 
+        bool processedThis = TRUE;
+
         TBBUTTON& button = buttons[i];
 
         wxZeroMemory(button);
@@ -602,10 +642,8 @@ bool wxToolBar::Realize()
                 break;
 
             case wxTOOL_STYLE_BUTTON:
-                    // TODO
-#if 0
-                if ( !HasFlag(wxTB_NOICONS) )
-                    button.iBitmap = bitmapId;
+//                if ( !HasFlag(wxTB_NOICONS) )
+//                    button.iBitmap = bitmapId;
 
                 if ( HasFlag(wxTB_TEXT) )
                 {
@@ -616,7 +654,15 @@ bool wxToolBar::Realize()
                     }
                 }
 
-                button.idCommand = tool->GetId();
+                int winceId = wxFindIdForwxWinId(tool->GetId());
+                if (winceId > -1)
+                {
+                    button.idCommand = tool->GetId();
+//                if ( !HasFlag(wxTB_NOICONS) )
+                    button.iBitmap = winceId;
+                }
+                else
+                    processedThis = FALSE;
 
                 if ( tool->IsEnabled() )
                     button.fsState |= TBSTATE_ENABLED;
@@ -653,17 +699,17 @@ bool wxToolBar::Realize()
                         button.fsStyle = TBSTYLE_BUTTON;
                 }
 
-                bitmapId++;
-#endif
+//                bitmapId++;
                 break;
         }
 
         lastWasRadio = isRadio;
 
-        i++;
+        if (processedThis)
+            i++;
     }
 
-    // Add buttons in tbSTDButton to Commandbar
+    // Add buttons to Commandbar
     if (!CommandBar_AddButtons(GetHwnd(), i, buttons))
     {
         wxLogLastError(wxT("CommandBar_AddButtons"));