X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2d120f8391920145647ec10e84629bc21fa9f1bb..86556aa099d44b170aebbb9b55059b40b1207154:/src/motif/menuitem.cpp diff --git a/src/motif/menuitem.cpp b/src/motif/menuitem.cpp index 800ebb8df2..bb464edeae 100644 --- a/src/motif/menuitem.cpp +++ b/src/motif/menuitem.cpp @@ -10,14 +10,27 @@ /////////////////////////////////////////////////////////////////////////////// // ============================================================================ -// headers & declarations +// declarations // ============================================================================ +#ifdef __GNUG__ + #pragma implementation "menuitem.h" +#endif + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#include "wx/defs.h" + #include "wx/menu.h" #include "wx/menuitem.h" #include "wx/utils.h" #include "wx/frame.h" +#ifdef __VMS__ +#pragma message disable nosimpint +#endif #include #include #include @@ -27,15 +40,19 @@ #include #include #include +#ifdef __VMS__ +#pragma message enable nosimpint +#endif #include "wx/motif/private.h" -void wxMenuItemCallback (Widget w, XtPointer clientData, - XtPointer ptr); -void wxMenuItemArmCallback (Widget w, XtPointer clientData, - XtPointer ptr); -void wxMenuItemDisarmCallback (Widget w, XtPointer clientData, - XtPointer ptr); +// ---------------------------------------------------------------------------- +// functions prototypes +// ---------------------------------------------------------------------------- + +static void wxMenuItemCallback(Widget w, XtPointer clientData, XtPointer ptr); +static void wxMenuItemArmCallback(Widget w, XtPointer clientData, XtPointer ptr); +static void wxMenuItemDisarmCallback(Widget w, XtPointer clientData, XtPointer ptr); // ============================================================================ // implementation @@ -45,9 +62,7 @@ void wxMenuItemDisarmCallback (Widget w, XtPointer clientData, // dynamic classes implementation // ---------------------------------------------------------------------------- -#if !USE_SHARED_LIBRARY -IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject) -#endif //USE_SHARED_LIBRARY + IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject) // ---------------------------------------------------------------------------- // wxMenuItem @@ -59,26 +74,27 @@ IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject) wxMenuItem::wxMenuItem(wxMenu *pParentMenu, int id, const wxString& strName, const wxString& strHelp, bool bCheckable, - wxMenu *pSubMenu) : -m_strHelp(strHelp), -m_bCheckable(bCheckable), -m_strName(strName) + wxMenu *pSubMenu) { - wxASSERT( pParentMenu != NULL ); - - m_pParentMenu = pParentMenu; - m_pSubMenu = pSubMenu; - m_idItem = id; - m_bEnabled = TRUE; - m_bChecked = FALSE; - - //// Motif-specific - m_menuBar = NULL; + wxASSERT_MSG( pParentMenu != NULL, wxT("menuitem should have a menu") ); + + // common init + m_parentMenu = pParentMenu; + m_subMenu = pSubMenu; + m_id = id; + m_isEnabled = TRUE; + m_isChecked = FALSE; + m_help = strHelp; + m_isCheckable = bCheckable; + m_text = strName; + + // Motif-specific + m_menuBar = NULL; m_buttonWidget = (WXWidget) NULL; - m_topMenu = NULL; + m_topMenu = NULL; } -wxMenuItem::~wxMenuItem() +wxMenuItem::~wxMenuItem() { } @@ -88,10 +104,10 @@ wxMenuItem::~wxMenuItem() // delete the sub menu void wxMenuItem::DeleteSubMenu() { - wxASSERT( m_pSubMenu != NULL ); - - delete m_pSubMenu; - m_pSubMenu = NULL; + wxASSERT( m_subMenu != NULL ); + + delete m_subMenu; + m_subMenu = NULL; } // change item state @@ -99,10 +115,11 @@ void wxMenuItem::DeleteSubMenu() void wxMenuItem::Enable(bool bDoEnable) { - if ( m_bEnabled != bDoEnable ) + if ( m_isEnabled != bDoEnable ) { - if ( m_pSubMenu == NULL ) - { // normal menu item + if ( !IsSubMenu() ) + { + // normal menu item if (m_buttonWidget) XtSetSensitive( (Widget) m_buttonWidget, (Boolean) bDoEnable); } @@ -113,73 +130,101 @@ void wxMenuItem::Enable(bool bDoEnable) if (m_buttonWidget) XtSetSensitive( (Widget) m_buttonWidget, (Boolean) bDoEnable); } - - m_bEnabled = bDoEnable; + + wxMenuItemBase::Enable(bDoEnable); } } void wxMenuItem::Check(bool bDoCheck) { wxCHECK_RET( IsCheckable(), "only checkable items may be checked" ); - - if ( m_bChecked != bDoCheck ) + + if ( m_isChecked != bDoCheck ) { - if (m_buttonWidget && XtIsSubclass ((Widget) m_buttonWidget, xmToggleButtonGadgetClass)) + if ( m_buttonWidget ) { - XtVaSetValues ( (Widget) m_buttonWidget, XmNset, (Boolean) bDoCheck, NULL); + wxASSERT_MSG( XtIsSubclass((Widget)m_buttonWidget, + xmToggleButtonGadgetClass), + wxT("checkable menu item must be a toggle button") ); + + XtVaSetValues((Widget)m_buttonWidget, + XmNset, (Boolean)bDoCheck, + NULL); } - m_bChecked = bDoCheck; + + wxMenuItemBase::Check(bDoCheck); } } -//// Motif-specific +/* static */ +wxString wxMenuItemBase::GetLabelFromText(const wxString& text) +{ + return wxStripMenuCodes(text); +} + +// ---------------------------------------------------------------------------- +// wxMenuItemBase +// ---------------------------------------------------------------------------- + +wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu, + int id, + const wxString& name, + const wxString& help, + bool isCheckable, + wxMenu *subMenu) +{ + return new wxMenuItem(parentMenu, id, name, help, isCheckable, subMenu); +} + +// ---------------------------------------------------------------------------- +// Motif-specific +// ---------------------------------------------------------------------------- void wxMenuItem::CreateItem (WXWidget menu, wxMenuBar * menuBar, wxMenu * topMenu) { m_menuBar = menuBar; m_topMenu = topMenu; - + if (GetId() == -2) { // Id=-2 identifies a Title item. - wxStripMenuCodes ((char*) (const char*) m_strName, wxBuffer); - m_buttonWidget = (WXWidget) XtVaCreateManagedWidget (wxBuffer, + m_buttonWidget = (WXWidget) XtVaCreateManagedWidget + (wxStripMenuCodes(m_text), xmLabelGadgetClass, (Widget) menu, NULL); } - else if ((!m_strName.IsNull() && m_strName != "") && (!m_pSubMenu)) + else if ((!m_text.IsNull() && m_text != "") && (!m_subMenu)) { - wxStripMenuCodes ((char*) (const char*) m_strName, wxBuffer); + wxString strName = wxStripMenuCodes(m_text); if (IsCheckable()) { - m_buttonWidget = (WXWidget) XtVaCreateManagedWidget (wxBuffer, + m_buttonWidget = (WXWidget) XtVaCreateManagedWidget (strName, xmToggleButtonGadgetClass, (Widget) menu, NULL); XtVaSetValues ((Widget) m_buttonWidget, XmNset, (Boolean) IsChecked(), NULL); } else - m_buttonWidget = (WXWidget) XtVaCreateManagedWidget (wxBuffer, + m_buttonWidget = (WXWidget) XtVaCreateManagedWidget (strName, xmPushButtonGadgetClass, (Widget) menu, NULL); - char mnem = wxFindMnemonic (m_strName); + char mnem = wxFindMnemonic (m_text); if (mnem != 0) XtVaSetValues ((Widget) m_buttonWidget, XmNmnemonic, mnem, NULL); - + //// TODO: proper accelerator treatment. What does wxFindAccelerator //// look for? - strcpy(wxBuffer, (char*) (const char*) m_strName); - char *accel = wxFindAccelerator (wxBuffer); + strName = m_text; + char *accel = wxFindAccelerator (strName); if (accel) XtVaSetValues ((Widget) m_buttonWidget, XmNaccelerator, accel, NULL); - + // TODO: What does this do? - strcpy(wxBuffer, (char*) (const char*) m_strName); - XmString accel_str = wxFindAcceleratorText (wxBuffer); + XmString accel_str = wxFindAcceleratorText (strName); if (accel_str) { XtVaSetValues ((Widget) m_buttonWidget, XmNacceleratorText, accel_str, NULL); XmStringFree (accel_str); } - + if (IsCheckable()) XtAddCallback ((Widget) m_buttonWidget, XmNvalueChangedCallback, @@ -204,10 +249,10 @@ void wxMenuItem::CreateItem (WXWidget menu, wxMenuBar * menuBar, wxMenu * topMen m_buttonWidget = (WXWidget) XtVaCreateManagedWidget ("separator", xmSeparatorGadgetClass, (Widget) menu, NULL); } - else if (m_pSubMenu) + else if (m_subMenu) { - m_buttonWidget = m_pSubMenu->CreateMenu (menuBar, menu, topMenu, m_strName, TRUE); - m_pSubMenu->SetButtonWidget(m_buttonWidget); + m_buttonWidget = m_subMenu->CreateMenu (menuBar, menu, topMenu, m_text, TRUE); + m_subMenu->SetButtonWidget(m_buttonWidget); XtAddCallback ((Widget) m_buttonWidget, XmNcascadingCallback, (XtCallbackProc) wxMenuItemArmCallback, @@ -221,10 +266,10 @@ void wxMenuItem::DestroyItem(bool full) { if (GetId() == -2) { - ; // Nothing - + ; // Nothing + } - else if ((!m_strName.IsNull() && (m_strName != "")) && !m_pSubMenu) + else if ((!m_text.IsNull() && (m_text != "")) && !m_subMenu) { if (m_buttonWidget) { @@ -242,8 +287,8 @@ void wxMenuItem::DestroyItem(bool full) } else if (GetId() == -1) { - ; // Nothing - + ; // Nothing + } else if (GetSubMenu()) { @@ -252,11 +297,11 @@ void wxMenuItem::DestroyItem(bool full) XtRemoveCallback ((Widget) m_buttonWidget, XmNcascadingCallback, wxMenuItemArmCallback, (XtPointer) this); } - m_pSubMenu->DestroyMenu(full); + m_subMenu->DestroyMenu(full); if (full) m_buttonWidget = NULL; } - + if (m_buttonWidget && full) { XtDestroyWidget ((Widget) m_buttonWidget); @@ -264,29 +309,26 @@ void wxMenuItem::DestroyItem(bool full) } } -void wxMenuItem::SetLabel(const wxString& label) +void wxMenuItem::SetText(const wxString& label) { char mnem = wxFindMnemonic (label); - wxStripMenuCodes ((char*) (const char*) label, wxBuffer); - - m_strName = label; - + wxString label2 = wxStripMenuCodes(label); + + m_text = label; + if (m_buttonWidget) { - XmString label_str = XmStringCreateSimple (wxBuffer); + wxXmString label_str(label2); XtVaSetValues ((Widget) m_buttonWidget, - XmNlabelString, label_str, + XmNlabelString, label_str(), NULL); - XmStringFree (label_str); if (mnem != 0) XtVaSetValues ((Widget) m_buttonWidget, XmNmnemonic, mnem, NULL); - strcpy(wxBuffer, (char*) (const char*) label); - char *accel = wxFindAccelerator (wxBuffer); + char *accel = wxFindAccelerator (label2); if (accel) XtVaSetValues ((Widget) m_buttonWidget, XmNaccelerator, accel, NULL); - - strcpy(wxBuffer, (char*) (const char*) label); - XmString accel_str = wxFindAcceleratorText (wxBuffer); + + XmString accel_str = wxFindAcceleratorText (label2); if (accel_str) { XtVaSetValues ((Widget) m_buttonWidget, XmNacceleratorText, accel_str, NULL); @@ -295,8 +337,12 @@ void wxMenuItem::SetLabel(const wxString& label) } } -void wxMenuItemCallback (Widget w, XtPointer clientData, - XtPointer ptr) +// ---------------------------------------------------------------------------- +// Motif callbacks +// ---------------------------------------------------------------------------- + +void wxMenuItemCallback (Widget WXUNUSED(w), XtPointer clientData, + XtPointer WXUNUSED(ptr)) { wxMenuItem *item = (wxMenuItem *) clientData; if (item) @@ -305,14 +351,16 @@ void wxMenuItemCallback (Widget w, XtPointer clientData, { Boolean isChecked = FALSE; XtVaGetValues ((Widget) item->GetButtonWidget(), XmNset, & isChecked, NULL); - item->SetChecked(isChecked); + + // only set the flag, don't actually check anything + item->wxMenuItemBase::Check(isChecked); } if (item->GetMenuBar() && item->GetMenuBar()->GetMenuBarFrame()) { wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, item->GetId()); commandEvent.SetEventObject(item->GetMenuBar()->GetMenuBarFrame()); commandEvent.SetInt( item->GetId() ); - + item->GetMenuBar()->GetMenuBarFrame()->GetEventHandler()->ProcessEvent(commandEvent); } else if (item->GetTopMenu()) @@ -320,14 +368,14 @@ void wxMenuItemCallback (Widget w, XtPointer clientData, wxCommandEvent event (wxEVT_COMMAND_MENU_SELECTED, item->GetId()); event.SetEventObject(item->GetTopMenu()); event.SetInt( item->GetId() ); - + item->GetTopMenu()->ProcessCommand (event); } } } -void wxMenuItemArmCallback (Widget w, XtPointer clientData, - XtPointer ptr) +void wxMenuItemArmCallback (Widget WXUNUSED(w), XtPointer clientData, + XtPointer WXUNUSED(ptr)) { wxMenuItem *item = (wxMenuItem *) clientData; if (item) @@ -336,15 +384,15 @@ void wxMenuItemArmCallback (Widget w, XtPointer clientData, { wxMenuEvent menuEvent(wxEVT_MENU_HIGHLIGHT, item->GetId()); menuEvent.SetEventObject(item->GetMenuBar()->GetMenuBarFrame()); - + item->GetMenuBar()->GetMenuBarFrame()->GetEventHandler()->ProcessEvent(menuEvent); } } } -void -wxMenuItemDisarmCallback (Widget w, XtPointer clientData, - XtPointer ptr) +void +wxMenuItemDisarmCallback (Widget WXUNUSED(w), XtPointer clientData, + XtPointer WXUNUSED(ptr)) { wxMenuItem *item = (wxMenuItem *) clientData; if (item) @@ -355,7 +403,7 @@ wxMenuItemDisarmCallback (Widget w, XtPointer clientData, // special to event system wxMenuEvent menuEvent(wxEVT_MENU_HIGHLIGHT, -1); menuEvent.SetEventObject(item->GetMenuBar()->GetMenuBarFrame()); - + item->GetMenuBar()->GetMenuBarFrame()->GetEventHandler()->ProcessEvent(menuEvent); } }