]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/control.cpp
Commit mentioned fix/hack to enable controls
[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 #ifdef __WXGTK20__
90 wxString wxControl::PrepareLabelMnemonics( const wxString &label ) const
91 {
92 //Format mnemonics properly for GTK2. This can be called from GTK1.x, but
93 //it's not very useful because mnemonics don't exist prior to GTK2.
94 wxString label2;
95 for (size_t i = 0; i < label.Len(); i++)
96 {
97 if (label.GetChar(i) == wxT('&'))
98 {
99 //Mnemonic escape sequence "&&" is a literal "&" in the output.
100 if (label.GetChar(i + 1) == wxT('&'))
101 {
102 label2 << wxT('&');
103 i++;
104 }
105 //Handle special case of "&_" (i.e. "_" is the mnemonic).
106 //FIXME - Is it possible to use "_" as a GTK mnemonic? Just use a
107 //dash for now.
108 else if (label.GetChar(i + 1) == wxT('_'))
109 {
110 label2 << wxT("_-");
111 i++;
112 }
113 //Replace WX mnemonic indicator "&" with GTK indicator "_".
114 else
115 {
116 label2 << wxT('_');
117 }
118 }
119 else if (label.GetChar(i) == wxT('_'))
120 {
121 //Escape any underlines in the string so GTK doesn't use them.
122 label2 << wxT("__");
123 }
124 else
125 {
126 label2 << label.GetChar(i);
127 }
128 }
129 return label2;
130 }
131 #endif
132
133 #endif // wxUSE_CONTROLS
134