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