]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/menuitem.cpp
more fixes to radio menu items: fixed Check() for them; allow separators inside the...
[wxWidgets.git] / src / os2 / menuitem.cpp
index af97aab35a6613c776d1a4536afaa0c79e7e2052..3c065c11fd96d1796236b6f4fa8c555092ff0e57 100644 (file)
@@ -62,7 +62,7 @@ static wxString TextToLabel(const wxString& rTitle)
 {
     wxString Title;
     const wxChar *pc;
-    for (pc = rTitle; *pc != wxT('\0'); pc++ )
+    for (pc = rTitle.c_str(); *pc != wxT('\0'); pc++ )
     {
         if (*pc == wxT('&') )
         {
@@ -71,13 +71,9 @@ static wxString TextToLabel(const wxString& rTitle)
                 pc++;
                 Title << wxT('&');
             }
-            else 
+            else
                 Title << wxT('~');
         }
-//         else if (*pc == wxT('/'))
-//         {
-//             Title << wxT('\\');
-//         }
         else
         {
             if ( *pc == wxT('~') )
@@ -100,11 +96,7 @@ static wxString TextToLabel(const wxString& rTitle)
 // dynamic classes implementation
 // ----------------------------------------------------------------------------
 
-    #if wxUSE_OWNER_DRAWN
-        IMPLEMENT_DYNAMIC_CLASS2(wxMenuItem, wxMenuItemBase, wxOwnerDrawn)
-    #else   //!USE_OWNER_DRAWN
-        IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxMenuItemBase)
-    #endif  //USE_OWNER_DRAWN
+IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
 
 // ----------------------------------------------------------------------------
 // wxMenuItem
@@ -118,44 +110,62 @@ wxMenuItem::wxMenuItem(
 , int                               nId
 , const wxString&                   rText
 , const wxString&                   rStrHelp
-, bool                              bCheckable
+, wxItemKind                        kind
 , wxMenu*                           pSubMenu
 )
+: wxMenuItemBase(pParentMenu, nId, rText, rStrHelp, kind, pSubMenu)
 #if wxUSE_OWNER_DRAWN
-:  wxOwnerDrawn( TextToLabel(rText)
+,  wxOwnerDrawn( TextToLabel(rText)
                 ,bCheckable
                )
 #endif // owner drawn
 {
     wxASSERT_MSG(pParentMenu != NULL, wxT("a menu item should have a parent"));
 
-#if  wxUSE_OWNER_DRAWN
+    Init();
+} // end of wxMenuItem::wxMenuItem
 
-    //
-    // Set default menu colors
-    //
-    #define SYS_COLOR(c) (wxSystemSettings::GetSystemColour(wxSYS_COLOUR_##c))
+wxMenuItem::wxMenuItem(
+  wxMenu*                           pParentMenu
+, int                               nId
+, const wxString&                   rText
+, const wxString&                   rStrHelp
+, bool                              bIsCheckable
+, wxMenu*                           pSubMenu
+)
+: wxMenuItemBase(pParentMenu, nId, rText, rStrHelp, bIsCheckable ? kITEM_CHECK : kITEM_NORMAL, pSubMenu)
+#if wxUSE_OWNER_DRAWN
+,  wxOwnerDrawn( TextToLabel(rText)
+                ,bCheckable
+               )
+#endif // owner drawn
+{
+    wxASSERT_MSG(pParentMenu != NULL, wxT("a menu item should have a parent"));
+
+    Init();
+} // end of wxMenuItem::wxMenuItem
+
+void wxMenuItem::Init()
+{
+    m_radioGroup.start = -1;
+    m_isRadioGroupStart = FALSE;
+
+#if  wxUSE_OWNER_DRAWN
+    // set default menu colors
+    #define SYS_COLOR(c) (wxSystemSettings::GetColour(wxSYS_COLOUR_##c))
 
     SetTextColour(SYS_COLOR(MENUTEXT));
     SetBackgroundColour(SYS_COLOR(MENU));
 
-    //
-    // We don't want normal items be owner-drawn
-    //
+    #undef  SYS_COLOR
+
+    // we don't want normal items be owner-drawn
     ResetOwnerDrawn();
 
-    #undef  SYS_COLOR
+    // tell the owner drawing code to to show the accel string as well
+    SetAccelString(m_text.AfterFirst(_T('\t')));
 #endif // wxUSE_OWNER_DRAWN
-
-    m_parentMenu  = pParentMenu;
-    m_subMenu     = pSubMenu;
-    m_isEnabled   = TRUE;
-    m_isChecked   = FALSE;
-    m_id          = nId;
-    m_text        = TextToLabel(rText);
-    m_isCheckable = bCheckable;
-    m_help        = rStrHelp;
-} // end of wxMenuItem::wxMenuItem
+}
 
 wxMenuItem::~wxMenuItem()
 {
@@ -206,17 +216,33 @@ wxString wxMenuItemBase::GetLabelFromText(
     return label;
 }
 
-// accelerators
-// ------------
+// radio group stuff
+// -----------------
 
-#if wxUSE_ACCEL
+void wxMenuItem::SetAsRadioGroupStart()
+{
+    m_bIsRadioGroupStart = TRUE;
+} // end of wxMenuItem::SetAsRadioGroupStart
 
-wxAcceleratorEntry *wxMenuItem::GetAccel() const
+void wxMenuItem::SetRadioGroupStart(
+  int                               nStart
+)
 {
-    return wxGetAccelFromString(GetText());
-}
+    wxASSERT_MSG( !m_bIsRadioGroupStart,
+                  _T("should only be called for the next radio items") );
 
-#endif // wxUSE_ACCEL
+    m_vRadioGroup.m_nStart = nStart;
+} // end of wxMenuItem::SetRadioGroupStart
+
+void wxMenuItem::SetRadioGroupEnd(
+  int                               nEnd
+)
+{
+    wxASSERT_MSG( m_bIsRadioGroupStart,
+                  _T("should only be called for the first radio item") );
+
+    m_vRadioGroup.m_nEnd = nEnd;
+} // end of wxMenuItem::SetRadioGroupEnd
 
 // change item state
 // -----------------
@@ -233,13 +259,13 @@ void wxMenuItem::Enable(
         bOk = (bool)::WinSendMsg( GetHMenuOf(m_parentMenu)
                                  ,MM_SETITEMATTR
                                  ,MPFROM2SHORT(GetRealId(), TRUE)
-                                 ,MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED)
+                                 ,MPFROM2SHORT(MIA_DISABLED, FALSE)
                                 );
     else
         bOk = (bool)::WinSendMsg( GetHMenuOf(m_parentMenu)
                                  ,MM_SETITEMATTR
                                  ,MPFROM2SHORT(GetRealId(), TRUE)
-                                 ,MPFROM2SHORT(MIA_DISABLED, FALSE)
+                                 ,MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED)
                                 );
     if (!bOk)
     {
@@ -254,9 +280,10 @@ void wxMenuItem::Check(
 {
     bool                            bOk;
 
-    wxCHECK_RET( m_isCheckable, wxT("only checkable items may be checked") );
+    wxCHECK_RET( IsCheckable(), wxT("only checkable items may be checked") );
     if (m_isChecked == bCheck)
         return;
+
     if (bCheck)
         bOk = (bool)::WinSendMsg( GetHMenuOf(m_parentMenu)
                                  ,MM_SETITEMATTR
@@ -271,7 +298,7 @@ void wxMenuItem::Check(
                                 );
     if (!bOk)
     {
-        wxLogLastError("EnableMenuItem");
+        wxLogLastError("CheckMenuItem");
     }
     wxMenuItemBase::Check(bCheck);
 } // end of wxMenuItem::Check
@@ -377,7 +404,7 @@ wxMenuItem* wxMenuItemBase::New(
 , int                               nId
 , const wxString&                   rName
 , const wxString&                   rHelp
-, bool                              bIsCheckable
+, wxItemKind                        kind
 , wxMenu*                           pSubMenu
 )
 {
@@ -385,7 +412,7 @@ wxMenuItem* wxMenuItemBase::New(
                           ,nId
                           ,rName
                           ,rHelp
-                          ,bIsCheckable
+                          ,kind
                           ,pSubMenu
                          );
 } // end of wxMenuItemBase::New