virtual void DoSetSize(int x, int y,
int width, int height,
int sizeFlags = wxSIZE_AUTO);
+private:
+ // only implemented for native combo box
+ void AdjustDropDownListSize();
};
#endif
virtual void DoToggleItem(int item, int x) {};
#endif
protected:
+ virtual wxSize DoGetBestSize() const;
+
int m_noItems;
// List mapping positions->client data
extern void wxDoChangeBackgroundColour(WXWidget widget,
wxColour& backgroundColour,
bool changeArmColour = FALSE);
+extern void wxDoChangeFont(WXWidget widget, wxFont& font);
#define wxNO_COLORS 0x00
#define wxBACK_COLORS 0x01
XmString m_string;
};
+wxString wxXmStringToString( const XmString& xmString );
+
// ----------------------------------------------------------------------------
// Routines used in both wxTextCtrl/wxListBox and nativa wxComboBox
// (defined in src/motif/listbox.cpp or src/motif/textctrl.cpp
// ----------------------------------------------------------------------------
int wxDoFindStringInList( Widget listWidget, const wxString& str );
-int wxDoGetSelectionInList(Widget listWidget);
+int wxDoGetSelectionInList( Widget listWidget );
+wxString wxDoGetStringInList( Widget listWidget, int n );
+wxSize wxDoGetListBoxBestSize( Widget listWidget, const wxWindow* window );
+
+wxSize wxDoGetSingleTextCtrlBestSize( Widget textWidget,
+ const wxWindow* window );
// ----------------------------------------------------------------------------
// executes one main loop iteration (implemented in src/motif/evtloop.cpp)
protected:
wxString m_fileName;
-
+
+ virtual wxSize DoGetBestSize() const;
public:
// Motif-specific
void* m_tempCallbackStruct;
DoChangeBackgroundColour((WXWidget) w, m_backgroundColour);
- if (m_font.Ok())
- XtVaSetValues (w,
- XmNfontList, (XmFontList) m_font.GetFontList(1.0, XtDisplay((Widget) m_formWidget)),
- NULL);
+ if( m_font.Ok() )
+ wxDoChangeFont( w, m_font );
m_widgetArray.Add(w);
( style & wxCB_DROPDOWN ) ? XmDROP_DOWN_COMBO_BOX :
// default to wxCB_DROPDOWN
XmDROP_DOWN_COMBO_BOX;
+ if( cb_type == XmDROP_DOWN_COMBO_BOX )
+ SetWindowStyle( style | wxCB_DROPDOWN );
Widget buttonWidget= XtVaCreateManagedWidget(name.c_str(),
xmComboBoxWidgetClass, parentWidget,
(XtCallbackProc) wxComboBoxCallback,
(XtPointer) this);
+ wxSize best = GetBestSize();
+ if( size.x != -1 ) best.x = size.x;
+ if( size.y != -1 ) best.y = size.y;
+
SetCanAddEventHandler(true);
AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
- pos.x, pos.y, size.x, size.y);
-
- XtVaSetValues (GetXmList(this),
- XmNvisibleItemCount, 10,
- NULL);
+ pos.x, pos.y, best.x, best.y);
ChangeBackgroundColour();
return true;
}
+void wxComboBox::AdjustDropDownListSize()
+{
+ int newListCount = -1, itemCount = GetCount();
+ const int MAX = 12;
+
+ if( !itemCount )
+ newListCount = 1;
+ else if( itemCount < MAX )
+ newListCount = itemCount;
+ else
+ newListCount = MAX;
+
+ XtVaSetValues( GetXmList(this),
+ XmNvisibleItemCount, newListCount,
+ NULL );
+}
+
wxComboBox::~wxComboBox()
{
DetachWidget((Widget) m_mainWidget); // Removes event handlers
{
wxXmString str( item.c_str() );
XmComboBoxAddItem((Widget) m_mainWidget, str(), 0, False);
- m_stringList.Add(item);
m_noStrings ++;
+ AdjustDropDownListSize();
return GetCount() - 1;
}
XmComboBoxDeletePos((Widget) m_mainWidget, n+1);
#endif
- wxStringList::Node *node = m_stringList.Item(n);
- if (node)
- {
- delete[] node->GetData();
- delete node;
- }
m_clientDataDict.Delete(n, HasClientObjectData());
m_noStrings--;
+
+ AdjustDropDownListSize();
}
void wxComboBox::Clear()
{
XmComboBoxDeletePos((Widget) m_mainWidget, m_noStrings--);
}
- #endif
-
- m_stringList.Clear();
+#endif
if ( HasClientObjectData() )
m_clientDataDict.DestroyData();
m_noStrings = 0;
+ AdjustDropDownListSize();
}
void wxComboBox::SetSelection (int n)
wxString wxComboBox::GetString(int n) const
{
- wxStringList::Node *node = m_stringList.Item(n);
- if (node)
- return wxString(node->GetData ());
- else
- return wxEmptyString;
+ return wxDoGetStringInList( GetXmList(this), n );
}
int wxComboBox::FindString(const wxString& s) const
void wxComboBox::ChangeFont(bool keepOriginalSize)
{
+ if( m_font.Ok() )
+ {
+ wxDoChangeFont( GetXmText(this), m_font );
+ wxDoChangeFont( GetXmList(this), m_font );
+ }
+
// Don't use the base class wxChoice's ChangeFont
wxWindow::ChangeFont(keepOriginalSize);
}
wxSize wxComboBox::DoGetBestSize() const
{
- return wxWindow::DoGetBestSize();
+ if( (GetWindowStyle() & wxCB_DROPDOWN) == wxCB_DROPDOWN ||
+ (GetWindowStyle() & wxCB_READONLY) == wxCB_READONLY )
+ {
+ Dimension arrowW, arrowS, highlight, xmargin, ymargin, shadow;
+
+ XtVaGetValues( (Widget)m_mainWidget,
+ XmNarrowSize, &arrowW,
+ XmNarrowSpacing, &arrowS,
+ XmNhighlightThickness, &highlight,
+ XmNmarginWidth, &xmargin,
+ XmNmarginHeight, &ymargin,
+ XmNshadowThickness, &shadow,
+ NULL );
+
+ wxSize listSize = wxDoGetListBoxBestSize( GetXmList(this), this );
+ wxSize textSize = wxDoGetSingleTextCtrlBestSize( GetXmText(this),
+ this );
+
+ // FIXME arbitrary constants
+ return wxSize( listSize.x + arrowW + arrowS + 2 * highlight
+ + 2 * shadow + 2 * xmargin ,
+ textSize.y + 2 * highlight + 2 * ymargin + 2 * shadow );
+ }
+ else
+ return wxWindow::DoGetBestSize();
}
#endif // XmVersion >= 2000
Widget parentWidget = (Widget) parent->GetClientWidget();
- Arg args[3];
+ XmFontList fontList = (XmFontList)NULL;
+
+ if( m_font.Ok() )
+ {
+ fontList = (XmFontList)m_font.GetFontList(1.0,
+ XtDisplay(parentWidget));
+ }
+
+ Arg args[4];
int count = 0;
- XtSetArg( args[0], XmNlistSizePolicy, XmCONSTANT ); ++count;
- XtSetArg( args[1], XmNselectionPolicy,
+ XtSetArg( args[count], XmNlistSizePolicy, XmCONSTANT ); ++count;
+ XtSetArg( args[count], XmNselectionPolicy,
( m_windowStyle & wxLB_MULTIPLE ) ? XmMULTIPLE_SELECT :
( m_windowStyle & wxLB_EXTENDED ) ? XmEXTENDED_SELECT :
XmBROWSE_SELECT );
++count;
+ if( fontList )
+ {
+ XtSetArg( args[count], XmNfontList, fontList );
+ ++count;
+ }
if( m_windowStyle & wxLB_ALWAYS_SB )
{
- XtSetArg( args[2], XmNscrollBarDisplayPolicy, XmSTATIC );
+ XtSetArg( args[count], XmNscrollBarDisplayPolicy, XmSTATIC );
++count;
}
XtManageChild (listWidget);
- long width = size.x;
- long height = size.y;
- if (width == -1)
- width = 150;
- if (height == -1)
- height = 80;
+ wxSize best = GetBestSize();
+ if( size.x != -1 ) best.x = size.x;
+ if( size.y != -1 ) best.y = size.y;
XtAddCallback (listWidget,
XmNbrowseSelectionCallback,
(XtCallbackProc) wxListBoxCallback,
(XtPointer) this);
- ChangeFont(FALSE);
-
SetCanAddEventHandler(TRUE);
AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
- pos.x, pos.y, width, height);
+ pos.x, pos.y, best.x, best.y);
ChangeBackgroundColour();
}
// Find string for position
-wxString wxListBox::GetString(int N) const
+wxString wxDoGetStringInList( Widget listBox, int n )
{
- Widget listBox = (Widget) m_mainWidget;
XmString *strlist;
- int n;
- XtVaGetValues (listBox, XmNitemCount, &n, XmNitems, &strlist, NULL);
- if (N <= n && N >= 0)
- {
- char *txt;
- if (XmStringGetLtoR (strlist[N], XmSTRING_DEFAULT_CHARSET, &txt))
- {
- wxString str(txt);
- XtFree (txt);
- return str;
- }
- else
- return wxEmptyString;
- }
+ int count;
+ XtVaGetValues( listBox,
+ XmNitemCount, &count,
+ XmNitems, &strlist,
+ NULL );
+ if( n <= count && n >= 0 )
+ return wxXmStringToString( strlist[n] );
else
return wxEmptyString;
}
+wxString wxListBox::GetString( int n ) const
+{
+ return wxDoGetStringInList( (Widget)m_mainWidget, n );
+}
+
void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
{
wxSizeKeeper sk( this );
{
return m_noItems;
}
+
+#define LIST_SCROLL_SPACING 6
+
+wxSize wxDoGetListBoxBestSize( Widget listWidget, const wxWindow* window )
+{
+ int max;
+ Dimension spacing, highlight, xmargin, ymargin, shadow;
+ int width = 0;
+ int x, y;
+
+ XtVaGetValues( listWidget,
+ XmNitemCount, &max,
+ XmNlistSpacing, &spacing,
+ XmNhighlightThickness, &highlight,
+ XmNlistMarginWidth, &xmargin,
+ XmNlistMarginHeight, &ymargin,
+ XmNshadowThickness, &shadow,
+ NULL );
+
+ for( size_t i = 0; i < (size_t)max; ++i )
+ {
+ window->GetTextExtent( wxDoGetStringInList( listWidget, i ), &x, &y );
+ width = wxMax( width, x );
+ }
+
+ // use some arbitrary value if there are no strings
+ if( width == 0 )
+ width = 100;
+
+ // get my
+ window->GetTextExtent( "v", &x, &y );
+
+ // make it a little larger than widest string, plus the scrollbar
+ width += wxSystemSettings::GetMetric( wxSYS_VSCROLL_X )
+ + 2 * highlight + LIST_SCROLL_SPACING + 2 * xmargin + 2 * shadow;
+
+ // at least 3 items, at most 10
+ int height = wxMax( 3, wxMin( 10, max ) ) *
+ ( y + spacing + 2 * highlight ) + 2 * ymargin + 2 * shadow;
+
+ return wxSize( width, height );
+}
+
+wxSize wxListBox::DoGetBestSize() const
+{
+ return wxDoGetListBoxBestSize( (Widget)m_mainWidget, this );
+}
+
{
switch ( index)
{
+ case wxSYS_HSCROLL_Y:
+ case wxSYS_VSCROLL_X:
+ return 15;
case wxSYS_MOUSE_BUTTONS:
// TODO
case wxSYS_BORDER_X:
// TODO
case wxSYS_SMALLICON_Y:
// TODO
- case wxSYS_HSCROLL_Y:
- // TODO
- case wxSYS_VSCROLL_X:
- // TODO
case wxSYS_VSCROLL_ARROW_X:
// TODO
case wxSYS_VSCROLL_ARROW_Y:
const wxValidator& validator,
const wxString& name)
{
+ if( !CreateControl( parent, id, pos, size, style, validator, name ) )
+ return false;
+
m_tempCallbackStruct = (void*) NULL;
m_modified = FALSE;
m_processedDefault = FALSE;
- // m_backgroundColour = parent->GetBackgroundColour();
- m_backgroundColour = * wxWHITE;
- m_foregroundColour = parent->GetForegroundColour();
-
- SetName(name);
- SetValidator(validator);
- if (parent)
- parent->AddChild(this);
- m_windowStyle = style;
-
- if ( id == -1 )
- m_windowId = (int)NewControlId();
- else
- m_windowId = id;
+ m_backgroundColour = *wxWHITE;
Widget parentWidget = (Widget) parent->GetClientWidget();
NULL);
}
- if ( !!value )
+ if ( !value.empty() )
{
-#if 0
- // don't do this because it is just linking the text to a source
- // string which is unsafe. MB
- //
- XmTextSetString ((Widget) m_mainWidget, (char*)value.c_str());
-#else
// do this instead... MB
//
XtVaSetValues( (Widget) m_mainWidget,
XmNvalue, (char *)value.c_str(),
NULL);
-#endif
}
// install callbacks
XtAddCallback((Widget) m_mainWidget, XmNlosingFocusCallback, (XtCallbackProc)wxTextWindowLoseFocusProc, (XtPointer)this);
// font
- m_font = parent->GetFont();
ChangeFont(FALSE);
+ wxSize best = GetBestSize();
+ if( size.x != -1 ) best.x = size.x;
+ if( size.y != -1 ) best.y = size.y;
+
SetCanAddEventHandler(TRUE);
- AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
+ AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
+ pos.x, pos.y, best.x, best.y);
ChangeBackgroundColour();
{
m_inSetValue = TRUE;
-#if 0
- // don't do this because it is just linking the text to a source
- // string which is unsafe. MB
- //
- XmTextSetString ((Widget) m_mainWidget, (char*)value.c_str());
-#else
// do this instead... MB
//
XtVaSetValues( (Widget) m_mainWidget,
XmNvalue, (char *)value.c_str(),
NULL);
-#endif
m_inSetValue = FALSE;
}
m_tempCallbackStruct = NULL;
}
+wxSize wxDoGetSingleTextCtrlBestSize( Widget textWidget,
+ const wxWindow* window )
+{
+ Dimension xmargin, ymargin, highlight, shadow;
+ char* value;
+
+ XtVaGetValues( textWidget,
+ XmNmarginWidth, &xmargin,
+ XmNmarginHeight, &ymargin,
+ XmNvalue, &value,
+ XmNhighlightThickness, &highlight,
+ XmNshadowThickness, &shadow,
+ NULL );
+ if( !value )
+ value = "|";
+
+ int x, y;
+ window->GetTextExtent( value, &x, &y );
+
+ return wxSize( x + 2 * xmargin + 2 * highlight + 2 * shadow,
+ // MBN: +2 necessary: Lesstif bug or mine?
+ y + 2 * ymargin + 2 * highlight + 2 * shadow + 2 );
+}
+
+wxSize wxTextCtrl::DoGetBestSize() const
+{
+ if( IsSingleLine() )
+ return wxDoGetSingleTextCtrlBestSize( (Widget)m_mainWidget, this );
+ else
+ return wxWindow::DoGetBestSize();
+}
+
// ----------------------------------------------------------------------------
// helpers and Motif callbacks
// ----------------------------------------------------------------------------
NULL);
}
+extern void wxDoChangeFont(WXWidget widget, wxFont& font)
+{
+ // lesstif 0.87 hangs here, but 0.93 does not
+#if !defined(LESSTIF_VERSION) \
+ || (defined(LesstifVersion) && LesstifVersion >= 93)
+
+ Widget w = (Widget)widget;
+ XmFontList fontList = (XmFontList)font.GetFontList(1.0, XtDisplay(w));
+ XtVaSetValues( w,
+ XmNfontList, fontList,
+ NULL );
+#endif
+
+}
+
#endif
// __WXMOTIF__
return (wa.map_state == IsViewable);
}
+
+wxString wxXmStringToString( const XmString& xmString )
+{
+ char *txt;
+ if( XmStringGetLtoR( xmString, XmSTRING_DEFAULT_CHARSET, &txt ) )
+ {
+ wxString str(txt);
+ XtFree (txt);
+ return str;
+ }
+
+ return wxEmptyString;
+}
+
}
// Change a widget's foreground and background colours.
-void wxWindow::DoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour)
+void wxWindow::DoChangeForegroundColour(WXWidget widget,
+ wxColour& foregroundColour)
{
- // When should we specify the foreground, if it's calculated
- // by wxComputeColours?
- // Solution: say we start with the default (computed) foreground colour.
- // If we call SetForegroundColour explicitly for a control or window,
- // then the foreground is changed.
- // Therefore SetBackgroundColour computes the foreground colour, and
- // SetForegroundColour changes the foreground colour. The ordering is
- // important.
-
- Widget w = (Widget)widget;
- XtVaSetValues(
- w,
- XmNforeground, foregroundColour.AllocColour(XtDisplay(w)),
- NULL
- );
+ wxDoChangeForegroundColour( widget, foregroundColour );
}
-void wxWindow::DoChangeBackgroundColour(WXWidget widget, wxColour& backgroundColour, bool changeArmColour)
+void wxWindow::DoChangeBackgroundColour(WXWidget widget,
+ wxColour& backgroundColour,
+ bool changeArmColour)
{
- wxComputeColours (XtDisplay((Widget) widget), & backgroundColour,
- (wxColour*) NULL);
-
- XtVaSetValues ((Widget) widget,
- XmNbackground, g_itemColors[wxBACK_INDEX].pixel,
- XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel,
- XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel,
- XmNforeground, g_itemColors[wxFORE_INDEX].pixel,
- NULL);
-
- if (changeArmColour)
- XtVaSetValues ((Widget) widget,
- XmNarmColor, g_itemColors[wxSELE_INDEX].pixel,
- NULL);
+ wxDoChangeBackgroundColour( widget, backgroundColour, changeArmColour );
}
bool wxWindow::SetBackgroundColour(const wxColour& col)
int width, height, width1, height1;
GetSize(& width, & height);
- // lesstif 0.87 hangs here, but 0.93 does not
-#if !defined(LESSTIF_VERSION) \
- || (defined(LesstifVersion) && LesstifVersion >= 93)
- XtVaSetValues (w,
- XmNfontList, (XmFontList) m_font.GetFontList(1.0, XtDisplay(w)),
- NULL);
-#endif
+ wxDoChangeFont( GetLabelWidget(), m_font );
GetSize(& width1, & height1);
if (keepOriginalSize && (width != width1 || height != height1))