X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f97c985452b20a8c2f0bbfb1d0275298bf09fb45..184b5d99a5382cd7a19888c85aff11f8a21af2f6:/src/motif/choice.cpp diff --git a/src/motif/choice.cpp b/src/motif/choice.cpp index 7012c75c0f..566dc1ea49 100644 --- a/src/motif/choice.cpp +++ b/src/motif/choice.cpp @@ -38,7 +38,6 @@ wxChoice::wxChoice() m_menuWidget = (WXWidget) 0; m_widgetList = (WXWidget*) 0; m_formWidget = (WXWidget) 0; - m_inSetValue = FALSE; } bool wxChoice::Create(wxWindow *parent, wxWindowID id, @@ -51,13 +50,12 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id, { SetName(name); SetValidator(validator); - m_noStrings = n; + m_noStrings = 0; // Starts off with none, incremented in Append m_windowStyle = style; m_buttonWidget = (WXWidget) 0; m_menuWidget = (WXWidget) 0; m_widgetList = (WXWidget*) 0; m_formWidget = (WXWidget) 0; - m_inSetValue = FALSE; if (parent) parent->AddChild(this); @@ -66,6 +64,10 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id, else m_windowId = id; + m_backgroundColour = parent->GetBackgroundColour(); + m_foregroundColour = parent->GetForegroundColour(); + m_windowFont = parent->GetFont(); + Widget parentWidget = (Widget) parent->GetClientWidget(); m_formWidget = (WXWidget) XtVaCreateManagedWidget ((char*) (const char*) name, @@ -83,7 +85,7 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id, */ m_menuWidget = (WXWidget) XmCreatePulldownMenu ((Widget) m_formWidget, "choiceMenu", NULL, 0); - int i; +// int i; if (n > 0) { int i; @@ -124,10 +126,11 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id, XtVaSetValues((Widget) m_formWidget, XmNresizePolicy, XmRESIZE_NONE, NULL); + ChangeFont(FALSE); + AttachWidget (parent, m_buttonWidget, m_formWidget, pos.x, pos.y, size.x, size.y); - SetFont(* parent->GetFont()); - ChangeColour(m_mainWidget); + ChangeBackgroundColour(); return TRUE; } @@ -142,14 +145,17 @@ wxChoice::~wxChoice() if (m_widgetList) delete[] m_widgetList; - DetachWidget(GetMainWidget()); // Removes event handlers + if (GetMainWidget()) + { + DetachWidget(GetMainWidget()); // Removes event handlers - XtDestroyWidget((Widget) m_formWidget); - m_formWidget = (WXWidget) 0; + XtDestroyWidget((Widget) m_formWidget); + m_formWidget = (WXWidget) 0; - // Presumably the other widgets have been deleted now, via the form - m_mainWidget = (WXWidget) 0; - m_buttonWidget = (WXWidget) 0; + // Presumably the other widgets have been deleted now, via the form + m_mainWidget = (WXWidget) 0; + m_buttonWidget = (WXWidget) 0; + } } void wxChoice::Append(const wxString& item) @@ -163,6 +169,8 @@ void wxChoice::Append(const wxString& item) #endif NULL); + DoChangeBackgroundColour((WXWidget) w, m_backgroundColour); + if (m_windowFont.Ok()) XtVaSetValues (w, XmNfontList, (XmFontList) m_windowFont.GetFontList(1.0, XtDisplay((Widget) m_formWidget)), @@ -170,9 +178,12 @@ void wxChoice::Append(const wxString& item) WXWidget *new_widgetList = new WXWidget[m_noStrings + 1]; int i; - for (i = 0; i < m_noStrings; i++) - new_widgetList[i] = m_widgetList[i]; + if (m_widgetList) + for (i = 0; i < m_noStrings; i++) + new_widgetList[i] = m_widgetList[i]; + new_widgetList[m_noStrings] = (WXWidget) w; + if (m_widgetList) delete[] m_widgetList; m_widgetList = new_widgetList; @@ -199,7 +210,7 @@ void wxChoice::Append(const wxString& item) m_noStrings ++; } -void wxChoice::Delete(int n) +void wxChoice::Delete(int WXUNUSED(n)) { wxFAIL_MSG( "Sorry, wxChoice::Delete isn't implemented yet. Maybe you'd like to volunteer? :-)" ); @@ -396,20 +407,20 @@ void wxChoice::Command(wxCommandEvent & event) ProcessCommand (event); } -void wxChoiceCallback (Widget w, XtPointer clientData, - XtPointer ptr) +void wxChoiceCallback (Widget w, XtPointer clientData, XtPointer WXUNUSED(ptr)) { wxChoice *item = (wxChoice *) clientData; if (item) { - if (item->m_inSetValue) + if (item->InSetValue()) return; char *s = NULL; XtVaGetValues (w, XmNuserData, &s, NULL); if (s) { - wxCommandEvent event (wxEVT_COMMAND_CHOICE_SELECTED); + wxCommandEvent event (wxEVT_COMMAND_CHOICE_SELECTED, item->GetId()); + event.SetEventObject(item); event.m_commandInt = item->FindString (s); // event.m_commandString = s; item->ProcessCommand (event); @@ -417,3 +428,49 @@ void wxChoiceCallback (Widget w, XtPointer clientData, } } +void wxChoice::ChangeFont(bool keepOriginalSize) +{ + // Note that this causes the widget to be resized back + // to its original size! We therefore have to set the size + // back again. TODO: a better way in Motif? + if (m_windowFont.Ok()) + { + int width, height, width1, height1; + GetSize(& width, & height); + + XmFontList fontList = (XmFontList) m_windowFont.GetFontList(1.0, XtDisplay((Widget) m_mainWidget)); + XtVaSetValues ((Widget) m_mainWidget, XmNfontList, fontList, NULL); + XtVaSetValues ((Widget) m_buttonWidget, XmNfontList, fontList, NULL); + + /* TODO: why does this cause a crash in XtWidgetToApplicationContext? + int i; + for (i = 0; i < m_noStrings; i++) + XtVaSetValues ((Widget) m_widgetList[i], XmNfontList, fontList, NULL); + */ + GetSize(& width1, & height1); + if (keepOriginalSize && (width != width1 || height != height1)) + { + SetSize(-1, -1, width, height); + } + } +} + +void wxChoice::ChangeBackgroundColour() +{ + DoChangeBackgroundColour(m_formWidget, m_backgroundColour); + DoChangeBackgroundColour(m_buttonWidget, m_backgroundColour); + DoChangeBackgroundColour(m_menuWidget, m_backgroundColour); + int i; + for (i = 0; i < m_noStrings; i++) + DoChangeBackgroundColour(m_widgetList[i], m_backgroundColour); +} + +void wxChoice::ChangeForegroundColour() +{ + DoChangeForegroundColour(m_formWidget, m_foregroundColour); + DoChangeForegroundColour(m_buttonWidget, m_foregroundColour); + DoChangeForegroundColour(m_menuWidget, m_foregroundColour); + int i; + for (i = 0; i < m_noStrings; i++) + DoChangeForegroundColour(m_widgetList[i], m_foregroundColour); +}