Added wxControl::PostCreation for wxGTK. Moved calls to
[wxWidgets.git] / src / gtk1 / control.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: control.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Vadim Zeitlin
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "control.h"
12 #endif
13
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
16
17 #include "wx/defs.h"
18
19 #if wxUSE_CONTROLS
20
21 #include "wx/control.h"
22
23 #include <gtk/gtk.h>
24
25 //-----------------------------------------------------------------------------
26 // wxControl
27 //-----------------------------------------------------------------------------
28
29 IMPLEMENT_DYNAMIC_CLASS(wxControl, wxWindow)
30
31 wxControl::wxControl()
32 {
33 m_needParent = TRUE;
34 }
35
36 bool wxControl::Create( wxWindow *parent,
37 wxWindowID id,
38 const wxPoint &pos,
39 const wxSize &size,
40 long style,
41 const wxValidator& validator,
42 const wxString &name )
43 {
44 bool ret = wxWindow::Create(parent, id, pos, size, style, name);
45
46 #if wxUSE_VALIDATORS
47 SetValidator(validator);
48 #endif
49
50 return ret;
51 }
52
53 void wxControl::SetLabel( const wxString &label )
54 {
55 m_label.Empty();
56 for ( const wxChar *pc = label; *pc != wxT('\0'); pc++ )
57 {
58 if ( *pc == wxT('&') )
59 {
60 pc++; // skip it
61 #if 0 // it would be unused anyhow for now - kbd interface not done yet
62 if ( *pc != wxT('&') ) m_chAccel = *pc;
63 #endif
64 }
65 m_label << *pc;
66 }
67 }
68
69 wxString wxControl::GetLabel() const
70 {
71 return m_label;
72 }
73
74
75 wxSize wxControl::DoGetBestSize() const
76 {
77 // Do not return any arbitrary default value...
78 wxASSERT_MSG( m_widget, wxT("DoGetBestSize called before creation") );
79
80 GtkRequisition req;
81 req.width = 2;
82 req.height = 2;
83 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request )
84 (m_widget, &req );
85
86 return wxSize(req.width, req.height);
87 }
88
89
90 void wxControl::PostCreation(const wxSize& size)
91 {
92 wxWindow::PostCreation();
93 InheritAttributes();
94 ApplyWidgetStyle();
95 SetInitialBestSize(size);
96 }
97
98
99 #ifdef __WXGTK20__
100 wxString wxControl::PrepareLabelMnemonics( const wxString &label ) const
101 {
102 //Format mnemonics properly for GTK2. This can be called from GTK1.x, but
103 //it's not very useful because mnemonics don't exist prior to GTK2.
104 wxString label2;
105 for (size_t i = 0; i < label.Len(); i++)
106 {
107 if (label.GetChar(i) == wxT('&'))
108 {
109 //Mnemonic escape sequence "&&" is a literal "&" in the output.
110 if (label.GetChar(i + 1) == wxT('&'))
111 {
112 label2 << wxT('&');
113 i++;
114 }
115 //Handle special case of "&_" (i.e. "_" is the mnemonic).
116 //FIXME - Is it possible to use "_" as a GTK mnemonic? Just use a
117 //dash for now.
118 else if (label.GetChar(i + 1) == wxT('_'))
119 {
120 label2 << wxT("_-");
121 i++;
122 }
123 //Replace WX mnemonic indicator "&" with GTK indicator "_".
124 else
125 {
126 label2 << wxT('_');
127 }
128 }
129 else if (label.GetChar(i) == wxT('_'))
130 {
131 //Escape any underlines in the string so GTK doesn't use them.
132 label2 << wxT("__");
133 }
134 else
135 {
136 label2 << label.GetChar(i);
137 }
138 }
139 return label2;
140 }
141 #endif
142
143 #endif // wxUSE_CONTROLS
144