+ m_menuBar = menuBar;
+ m_topMenu = topMenu;
+
+ if (GetId() == -2)
+ {
+ // Id=-2 identifies a Title item.
+ m_buttonWidget = (WXWidget) XtVaCreateManagedWidget
+ (wxStripMenuCodes(m_text),
+ xmLabelGadgetClass, (Widget) menu, NULL);
+ }
+ else if ((!m_text.IsNull() && m_text != "") && (!m_subMenu))
+ {
+ wxString strName = wxStripMenuCodes(m_text);
+ if (IsCheckable())
+ {
+ m_buttonWidget = (WXWidget) XtVaCreateManagedWidget (strName,
+ xmToggleButtonGadgetClass, (Widget) menu,
+ NULL);
+ XtVaSetValues ((Widget) m_buttonWidget, XmNset, (Boolean) IsChecked(), NULL);
+ }
+ else
+ m_buttonWidget = (WXWidget) XtVaCreateManagedWidget (strName,
+ xmPushButtonGadgetClass, (Widget) menu,
+ NULL);
+ char mnem = wxFindMnemonic (m_text);
+ if (mnem != 0)
+ XtVaSetValues ((Widget) m_buttonWidget, XmNmnemonic, mnem, NULL);
+
+ //// TODO: proper accelerator treatment. What does wxFindAccelerator
+ //// look for?
+ strName = m_text;
+ char *accel = wxFindAccelerator (strName);
+ if (accel)
+ XtVaSetValues ((Widget) m_buttonWidget, XmNaccelerator, accel, NULL);
+
+ // TODO: What does this do?
+ 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,
+ (XtCallbackProc) wxMenuItemCallback,
+ (XtPointer) this);
+ else
+ XtAddCallback ((Widget) m_buttonWidget,
+ XmNactivateCallback,
+ (XtCallbackProc) wxMenuItemCallback,
+ (XtPointer) this);
+ XtAddCallback ((Widget) m_buttonWidget,
+ XmNarmCallback,
+ (XtCallbackProc) wxMenuItemArmCallback,
+ (XtPointer) this);
+ XtAddCallback ((Widget) m_buttonWidget,
+ XmNdisarmCallback,
+ (XtCallbackProc) wxMenuItemDisarmCallback,
+ (XtPointer) this);
+ }
+ else if (GetId() == -1)
+ {
+ m_buttonWidget = (WXWidget) XtVaCreateManagedWidget ("separator",
+ xmSeparatorGadgetClass, (Widget) menu, NULL);
+ }
+ else if (m_subMenu)
+ {
+ m_buttonWidget = m_subMenu->CreateMenu (menuBar, menu, topMenu, m_text, TRUE);
+ m_subMenu->SetButtonWidget(m_buttonWidget);
+ XtAddCallback ((Widget) m_buttonWidget,
+ XmNcascadingCallback,
+ (XtCallbackProc) wxMenuItemArmCallback,
+ (XtPointer) this);
+ }
+ if (m_buttonWidget)
+ XtSetSensitive ((Widget) m_buttonWidget, (Boolean) IsEnabled());
+}
+
+void wxMenuItem::DestroyItem(bool full)
+{
+ if (GetId() == -2)
+ {
+ ; // Nothing
+
+ }
+ else if ((!m_text.IsNull() && (m_text != "")) && !m_subMenu)
+ {
+ if (m_buttonWidget)
+ {
+ if (IsCheckable())
+ XtRemoveCallback ((Widget) m_buttonWidget, XmNvalueChangedCallback,
+ wxMenuItemCallback, (XtPointer) this);
+ else
+ XtRemoveCallback ((Widget) m_buttonWidget, XmNactivateCallback,
+ wxMenuItemCallback, (XtPointer) this);
+ XtRemoveCallback ((Widget) m_buttonWidget, XmNarmCallback,
+ wxMenuItemArmCallback, (XtPointer) this);
+ XtRemoveCallback ((Widget) m_buttonWidget, XmNdisarmCallback,
+ wxMenuItemDisarmCallback, (XtPointer) this);
+ }
+ }
+ else if (GetId() == -1)
+ {
+ ; // Nothing
+
+ }
+ else if (GetSubMenu())
+ {
+ if (m_buttonWidget)
+ {
+ XtRemoveCallback ((Widget) m_buttonWidget, XmNcascadingCallback,
+ wxMenuItemArmCallback, (XtPointer) this);
+ }
+ m_subMenu->DestroyMenu(full);
+ if (full)
+ m_buttonWidget = NULL;
+ }
+
+ if (m_buttonWidget && full)
+ {
+ XtDestroyWidget ((Widget) m_buttonWidget);
+ m_buttonWidget = (WXWidget) 0;
+ }
+}
+
+void wxMenuItem::SetText(const wxString& label)
+{
+ char mnem = wxFindMnemonic (label);
+ wxString label2 = wxStripMenuCodes(label);
+
+ m_text = label;
+
+ if (m_buttonWidget)
+ {
+ wxXmString label_str(label2);
+ XtVaSetValues ((Widget) m_buttonWidget,
+ XmNlabelString, label_str(),
+ NULL);
+ if (mnem != 0)
+ XtVaSetValues ((Widget) m_buttonWidget, XmNmnemonic, mnem, NULL);
+ char *accel = wxFindAccelerator (label2);
+ if (accel)
+ XtVaSetValues ((Widget) m_buttonWidget, XmNaccelerator, accel, NULL);
+
+ XmString accel_str = wxFindAcceleratorText (label2);
+ if (accel_str)
+ {
+ XtVaSetValues ((Widget) m_buttonWidget, XmNacceleratorText, accel_str, NULL);
+ XmStringFree (accel_str);
+ }
+ }
+}
+
+// ----------------------------------------------------------------------------
+// Motif callbacks
+// ----------------------------------------------------------------------------
+
+void wxMenuItemCallback (Widget WXUNUSED(w), XtPointer clientData,
+ XtPointer WXUNUSED(ptr))
+{
+ wxMenuItem *item = (wxMenuItem *) clientData;
+ if (item)
+ {
+ if (item->IsCheckable())
+ {
+ Boolean isChecked = FALSE;
+ XtVaGetValues ((Widget) item->GetButtonWidget(), XmNset, & isChecked, NULL);
+
+ // 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())
+ {
+ wxCommandEvent event (wxEVT_COMMAND_MENU_SELECTED, item->GetId());
+ event.SetEventObject(item->GetTopMenu());
+ event.SetInt( item->GetId() );
+
+ item->GetTopMenu()->ProcessCommand (event);
+ }
+ }
+}
+
+void wxMenuItemArmCallback (Widget WXUNUSED(w), XtPointer clientData,
+ XtPointer WXUNUSED(ptr))
+{
+ wxMenuItem *item = (wxMenuItem *) clientData;
+ if (item)
+ {
+ if (item->GetMenuBar() && item->GetMenuBar()->GetMenuBarFrame())
+ {
+ wxMenuEvent menuEvent(wxEVT_MENU_HIGHLIGHT, item->GetId());
+ menuEvent.SetEventObject(item->GetMenuBar()->GetMenuBarFrame());
+
+ item->GetMenuBar()->GetMenuBarFrame()->GetEventHandler()->ProcessEvent(menuEvent);
+ }
+ }
+}
+
+void
+wxMenuItemDisarmCallback (Widget WXUNUSED(w), XtPointer clientData,
+ XtPointer WXUNUSED(ptr))
+{
+ wxMenuItem *item = (wxMenuItem *) clientData;
+ if (item)
+ {
+ if (item->GetMenuBar() && item->GetMenuBar()->GetMenuBarFrame())
+ {
+ // TODO: not sure this is correct, since -1 means something
+ // special to event system
+ wxMenuEvent menuEvent(wxEVT_MENU_HIGHLIGHT, -1);
+ menuEvent.SetEventObject(item->GetMenuBar()->GetMenuBarFrame());
+
+ item->GetMenuBar()->GetMenuBarFrame()->GetEventHandler()->ProcessEvent(menuEvent);
+ }
+ }
+}