]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/menuitem.cpp
   1 /////////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxMenuItem implementation 
   4 // Author:      David Webster 
   8 // Copyright:   (c) David Webster 
   9 // Licence:     wxWindows licence 
  10 /////////////////////////////////////////////////////////////////////////////// 
  12 // ============================================================================ 
  13 // headers & declarations 
  14 // ============================================================================ 
  17     #pragma implementation "menuitem.h" 
  20 // For compilers that support precompilation, includes "wx.h". 
  21 #include "wx/wxprec.h" 
  25     #include "wx/bitmap.h" 
  26     #include "wx/settings.h" 
  28     #include "wx/window.h" 
  31     #include "wx/string.h" 
  34 #include "wx/menuitem.h" 
  41 #include "wx/os2/private.h" 
  43 // --------------------------------------------------------------------------- 
  45 // --------------------------------------------------------------------------- 
  48 #define GetHMenuOf(menu)    ((HMENU)menu->GetHMenu()) 
  50 // conditional compilation 
  52     #define OWNER_DRAWN_ONLY( code ) if ( IsOwnerDrawn() ) code 
  53 #else // !wxUSE_OWNER_DRAWN 
  54     #define OWNER_DRAWN_ONLY( code ) 
  55 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN 
  57 // ---------------------------------------------------------------------------- 
  58 // static function for translating menu labels 
  59 // ---------------------------------------------------------------------------- 
  61 static wxString 
TextToLabel(const wxString
& rTitle
) 
  65     for (pc 
= rTitle
; *pc 
!= wxT('\0'); pc
++ ) 
  69             if (*(pc
+1) == wxT('&')) 
  77 //         else if (*pc == wxT('/')) 
  79 //             Title << wxT('\\'); 
  83             if ( *pc 
== wxT('~') ) 
  85                 // tildes must be doubled to prevent them from being 
  86                 // interpreted as accelerator character prefix by PM ??? 
  95 // ============================================================================ 
  97 // ============================================================================ 
  99 // ---------------------------------------------------------------------------- 
 100 // dynamic classes implementation 
 101 // ---------------------------------------------------------------------------- 
 103     #if wxUSE_OWNER_DRAWN 
 104         IMPLEMENT_DYNAMIC_CLASS2(wxMenuItem
, wxMenuItemBase
, wxOwnerDrawn
) 
 105     #else   //!USE_OWNER_DRAWN 
 106         IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxMenuItemBase
) 
 107     #endif  //USE_OWNER_DRAWN 
 109 // ---------------------------------------------------------------------------- 
 111 // ---------------------------------------------------------------------------- 
 116 wxMenuItem::wxMenuItem( 
 119 , const wxString
&                   rText
 
 120 , const wxString
&                   rStrHelp
 
 124 #if wxUSE_OWNER_DRAWN 
 125 :  wxOwnerDrawn( TextToLabel(rText
) 
 128 #endif // owner drawn 
 130     wxASSERT_MSG(pParentMenu 
!= NULL
, wxT("a menu item should have a parent")); 
 132 #if  wxUSE_OWNER_DRAWN 
 135     // Set default menu colors 
 137     #define SYS_COLOR(c) (wxSystemSettings::GetSystemColour(wxSYS_COLOUR_##c)) 
 139     SetTextColour(SYS_COLOR(MENUTEXT
)); 
 140     SetBackgroundColour(SYS_COLOR(MENU
)); 
 143     // We don't want normal items be owner-drawn 
 148 #endif // wxUSE_OWNER_DRAWN 
 150     m_parentMenu  
= pParentMenu
; 
 151     m_subMenu     
= pSubMenu
; 
 155     m_text        
= TextToLabel(rText
); 
 156     m_isCheckable 
= bCheckable
; 
 158     memset(&m_vMenuData
, '\0', sizeof(m_vMenuData
)); 
 160 } // end of wxMenuItem::wxMenuItem 
 162 wxMenuItem::~wxMenuItem() 
 164 } // end of wxMenuItem::~wxMenuItem 
 171 // Return the id for calling Win32 API functions 
 173 int wxMenuItem::GetRealId() const 
 175     return m_subMenu 
? (int)m_subMenu
->GetHMenu() : GetId(); 
 176 } // end of wxMenuItem::GetRealId 
 181 bool wxMenuItem::IsChecked() const 
 183     USHORT                          uFlag 
= SHORT1FROMMR(::WinSendMsg( GetHMenuOf(m_parentMenu
) 
 185                                                                       ,MPFROM2SHORT(GetId(), TRUE
) 
 186                                                                       ,MPFROMSHORT(MIA_CHECKED
) 
 189     return (uFlag 
& MIA_CHECKED
); 
 190 } // end of wxMenuItem::IsChecked 
 192 wxString 
wxMenuItemBase::GetLabelFromText( 
 193   const wxString
&                   rText
 
 197     for ( const wxChar 
*pc 
= rText
.c_str(); *pc
; pc
++ ) 
 199         if ( *pc 
== wxT('~') || *pc 
== wxT('&') ) 
 201             // '~' is the escape character for GTK+ and '&' is the one for 
 202             // wxWindows - skip both of them 
 214 void wxMenuItem::Enable( 
 220     if (m_isEnabled 
== bEnable
) 
 223         bOk 
= (bool)::WinSendMsg( GetHMenuOf(m_parentMenu
) 
 225                                  ,MPFROM2SHORT(GetRealId(), TRUE
) 
 226                                  ,MPFROM2SHORT(MIA_DISABLED
, FALSE
) 
 229         bOk 
= (bool)::WinSendMsg( GetHMenuOf(m_parentMenu
) 
 231                                  ,MPFROM2SHORT(GetRealId(), TRUE
) 
 232                                  ,MPFROM2SHORT(MIA_DISABLED
, MIA_DISABLED
) 
 236         wxLogLastError("EnableMenuItem"); 
 238     wxMenuItemBase::Enable(bEnable
); 
 239 } // end of wxMenuItem::Enable 
 241 void wxMenuItem::Check( 
 247     wxCHECK_RET( m_isCheckable
, wxT("only checkable items may be checked") ); 
 248     if (m_isChecked 
== bCheck
) 
 251         bOk 
= (bool)::WinSendMsg( GetHMenuOf(m_parentMenu
) 
 253                                  ,MPFROM2SHORT(GetRealId(), TRUE
) 
 254                                  ,MPFROM2SHORT(MIA_CHECKED
, MIA_CHECKED
) 
 257         bOk 
= (bool)::WinSendMsg( GetHMenuOf(m_parentMenu
) 
 259                                  ,MPFROM2SHORT(GetRealId(), TRUE
) 
 260                                  ,MPFROM2SHORT(MIA_CHECKED
, FALSE
) 
 264         wxLogLastError("CheckMenuItem"); 
 266     wxMenuItemBase::Check(bCheck
); 
 267 } // end of wxMenuItem::Check 
 269 void wxMenuItem::SetText( 
 270   const wxString
&                   rText
 
 274     // Don't do anything if label didn't change 
 277     wxString Text 
= TextToLabel(rText
); 
 281     wxMenuItemBase::SetText(Text
); 
 282     OWNER_DRAWN_ONLY(wxOwnerDrawn::SetName(Text
)); 
 284     HWND                            hMenu 
= GetHMenuOf(m_parentMenu
); 
 286     wxCHECK_RET(hMenu
, wxT("menuitem without menu")); 
 289     m_parentMenu
->UpdateAccel(this); 
 290 #endif // wxUSE_ACCEL 
 292     USHORT                          uId 
= GetRealId(); 
 296     if (!::WinSendMsg( hMenu
 
 298                       ,MPFROM2SHORT(uId
, TRUE
) 
 302         wxLogLastError("GetMenuState"); 
 306         uFlagsOld 
= vItem
.afStyle
; 
 309             uFlagsOld 
|= MIS_SUBMENU
; 
 314 #if wxUSE_OWNER_DRAWN 
 317             uFlagsOld 
|= MIS_OWNERDRAW
; 
 323             uFlagsOld 
|= MIS_TEXT
; 
 324             pData 
= (BYTE
*)Text
.c_str(); 
 330         if (!::WinSendMsg( hMenu
 
 332                           ,MPFROM2SHORT(uId
, TRUE
) 
 336             wxLogLastError(wxT("ModifyMenu")); 
 342         if (::WinSendMsg( hMenu
 
 348             wxLogLastError(wxT("ModifyMenu")); 
 351 } // end of wxMenuItem::SetText 
 353 void wxMenuItem::SetCheckable( 
 357     wxMenuItemBase::SetCheckable(bCheckable
); 
 358     OWNER_DRAWN_ONLY(wxOwnerDrawn::SetCheckable(bCheckable
)); 
 359 } // end of wxMenuItem::SetCheckable 
 361 // ---------------------------------------------------------------------------- 
 363 // ---------------------------------------------------------------------------- 
 365 wxMenuItem
* wxMenuItemBase::New( 
 368 , const wxString
&                   rName
 
 369 , const wxString
&                   rHelp
 
 374     return new wxMenuItem( pParentMenu
 
 381 } // end of wxMenuItemBase::New