]> git.saurik.com Git - wxWidgets.git/blobdiff - src/motif/radiobox.cpp
fixed memory leaks in case of errors during file load in wxSound::Create() (coverity...
[wxWidgets.git] / src / motif / radiobox.cpp
index 55234658d24d5648627dfc9fbe3e5d7301070584..90e3cdd123bdd8cc59b280de68e96bf56cd5d1e6 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        radiobox.cpp
+// Name:        src/motif/radiobox.cpp
 // Purpose:     wxRadioBox
 // Author:      Julian Smart
 // Modified by:
@@ -9,10 +9,6 @@
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-#pragma implementation "radiobox.h"
-#endif
-
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
@@ -52,7 +48,6 @@ void wxRadioBox::Init()
     m_selectedButton = -1;
     m_noItems = 0;
     m_noRowsOrCols = 0;
-    m_majorDim = 0 ;
 }
 
 bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title,
@@ -67,62 +62,54 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title,
     m_noItems = n;
     m_noRowsOrCols = majorDim;
 
-    if (majorDim==0)
-        m_majorDim = n ;
-    else
-        m_majorDim = majorDim ;
+    SetMajorDim(majorDim == 0 ? n : majorDim, style);
 
     Widget parentWidget = (Widget) parent->GetClientWidget();
+    Display* dpy = XtDisplay(parentWidget);
 
     m_mainWidget = XtVaCreateWidget ("radioboxframe",
-                                        xmFrameWidgetClass, parentWidget,
-                                        XmNresizeHeight, True,
-                                        XmNresizeWidth, True,
-                                        NULL);
+                                     xmFrameWidgetClass, parentWidget,
+                                     XmNresizeHeight, True,
+                                     XmNresizeWidth, True,
+                                     NULL);
 
     wxString label1(wxStripMenuCodes(title));
 
-    WXFontType fontType = m_font.GetFontType(XtDisplay(parentWidget));
-
     if (!label1.empty())
     {
         wxXmString text(label1);
         m_labelWidget = (WXWidget)
             XtVaCreateManagedWidget( label1.c_str(),
 #if wxUSE_GADGETS
-                                       style & wxCOLOURED ? xmLabelWidgetClass
-                                                          : xmLabelGadgetClass,
-                                       (Widget)m_mainWidget,
+                style & wxCOLOURED ? xmLabelWidgetClass
+                                   : xmLabelGadgetClass,
+                (Widget)m_mainWidget,
 #else
-                                       xmLabelWidgetClass,
-                                       (Widget)m_mainWidget,
+                xmLabelWidgetClass, (Widget)m_mainWidget,
 #endif
-                                       wxFont::GetFontTag(), fontType,
-                                       XmNlabelString, text(),
+                wxFont::GetFontTag(), m_font.GetFontTypeC(dpy),
+                XmNlabelString, text(),
 // XmNframeChildType is not in Motif 1.2, nor in Lesstif,
 // if it was compiled with 1.2 compatibility
 // TODO: check this still looks OK for Motif 1.2.
 #if (XmVersion > 1200)
-                                       XmNframeChildType, XmFRAME_TITLE_CHILD,
+                XmNframeChildType, XmFRAME_TITLE_CHILD,
 #else
-                                       XmNchildType, XmFRAME_TITLE_CHILD,
+                XmNchildType, XmFRAME_TITLE_CHILD,
 #endif
-                                       XmNchildVerticalAlignment,
-                                           XmALIGNMENT_CENTER,
-                                       NULL);
+                XmNchildVerticalAlignment, XmALIGNMENT_CENTER,
+                NULL);
     }
 
     Arg args[3];
 
-    m_majorDim = (n + m_majorDim - 1) / m_majorDim;
-
     XtSetArg (args[0], XmNorientation, ((style & wxHORIZONTAL) == wxHORIZONTAL ?
                                           XmHORIZONTAL : XmVERTICAL));
-    XtSetArg (args[1], XmNnumColumns, m_majorDim);
+    XtSetArg (args[1], XmNnumColumns, GetMajorDim());
     XtSetArg (args[2], XmNadjustLast, False);
 
     Widget radioBoxWidget =
-        XmCreateRadioBox ((Widget)m_mainWidget, "radioBoxWidget", args, 3);
+        XmCreateRadioBox ((Widget)m_mainWidget, wxMOTIF_STR("radioBoxWidget"), args, 3);
 
     m_radioButtons.reserve(n);
     m_radioButtonLabels.reserve(n);
@@ -132,14 +119,15 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title,
     {
         wxString str(wxStripMenuCodes(choices[i]));
         m_radioButtonLabels.push_back(str);
-        Widget radioItem =  XtVaCreateManagedWidget (wxConstCast(str.c_str(), char),
+        Widget radioItem =  XtVaCreateManagedWidget (
+                                wxConstCast(str.c_str(), char),
 #if wxUSE_GADGETS
-                            xmToggleButtonGadgetClass, radioBoxWidget,
+                                xmToggleButtonGadgetClass, radioBoxWidget,
 #else
-                            xmToggleButtonWidgetClass, radioBoxWidget,
+                                xmToggleButtonWidgetClass, radioBoxWidget,
 #endif
-                            wxFont::GetFontTag(), fontType,
-                                                 NULL);
+                                wxFont::GetFontTag(), m_font.GetFontTypeC(dpy),
+                                NULL);
         m_radioButtons.push_back((WXWidget)radioItem);
         XtAddCallback (radioItem, XmNvalueChangedCallback,
                        (XtCallbackProc) wxRadioBoxCallback,
@@ -198,15 +186,6 @@ void wxRadioBox::SetString(int item, const wxString& label)
     }
 }
 
-int wxRadioBox::FindString(const wxString& s) const
-{
-    int i;
-    for (i = 0; i < m_noItems; i++)
-        if (s == m_radioButtonLabels[i])
-            return i;
-    return wxNOT_FOUND;
-}
-
 void wxRadioBox::SetSelection(int n)
 {
     if (!IsValid(n))
@@ -356,16 +335,13 @@ void wxRadioBox::ChangeFont(bool keepOriginalSize)
 {
     wxWindow::ChangeFont(keepOriginalSize);
 
-    WXFontType fontType =
-        m_font.GetFontType(XtDisplay((Widget) GetTopWidget()));
-
     int i;
     for (i = 0; i < m_noItems; i++)
     {
         WXWidget radioButton = m_radioButtons[i];
 
         XtVaSetValues ((Widget) radioButton,
-                       wxFont::GetFontTag(), fontType,
+                       wxFont::GetFontTag(), m_font.GetFontTypeC(XtDisplay((Widget) GetTopWidget())),
                        NULL);
     }
 }
@@ -402,23 +378,6 @@ void wxRadioBox::ChangeForegroundColour()
     }
 }
 
-static int CalcOtherDim( int items, int dim )
-{
-    return items / dim + ( items % dim ? 1 : 0 );
-}
-
-int wxRadioBox::GetRowCount() const
-{
-    return m_windowStyle & wxRA_SPECIFY_ROWS ? m_noRowsOrCols
-        : CalcOtherDim( GetCount(), m_noRowsOrCols );
-}
-
-int wxRadioBox::GetColumnCount() const
-{
-    return m_windowStyle & wxRA_SPECIFY_COLS ? m_noRowsOrCols
-        : CalcOtherDim( GetCount(), m_noRowsOrCols );
-}
-
 void wxRadioBoxCallback (Widget w, XtPointer clientData,
                     XmToggleButtonCallbackStruct * cbs)
 {
@@ -443,4 +402,3 @@ void wxRadioBoxCallback (Widget w, XtPointer clientData,
   event.SetEventObject(item);
   item->ProcessCommand (event);
 }
-