]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: control.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
dbf858b5 | 5 | // Id: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling, Julian Smart and Vadim Zeitlin |
32c77a71 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "control.h" | |
12 | #endif | |
13 | ||
1e6feb95 VZ |
14 | #include "wx/defs.h" |
15 | ||
16 | #if wxUSE_CONTROLS | |
17 | ||
c801d85f KB |
18 | #include "wx/control.h" |
19 | ||
071a2d78 | 20 | #include <gtk/gtk.h> |
034be888 | 21 | |
c801d85f KB |
22 | //----------------------------------------------------------------------------- |
23 | // wxControl | |
24 | //----------------------------------------------------------------------------- | |
25 | ||
9abe166a | 26 | IMPLEMENT_DYNAMIC_CLASS(wxControl, wxWindow) |
c801d85f | 27 | |
31528cd3 | 28 | wxControl::wxControl() |
c801d85f | 29 | { |
b292e2f5 | 30 | m_needParent = TRUE; |
6de97a3b | 31 | } |
c801d85f | 32 | |
04165bec | 33 | bool wxControl::Create( wxWindow *parent, |
31528cd3 VZ |
34 | wxWindowID id, |
35 | const wxPoint &pos, | |
36 | const wxSize &size, | |
37 | long style, | |
8d772832 | 38 | const wxValidator& validator, |
04165bec | 39 | const wxString &name ) |
8d772832 | 40 | { |
04165bec RR |
41 | bool ret = wxWindow::Create(parent, id, pos, size, style, name); |
42 | ||
43 | #if wxUSE_VALIDATORS | |
8d772832 | 44 | SetValidator(validator); |
8d772832 RD |
45 | #endif |
46 | ||
04165bec RR |
47 | return ret; |
48 | } | |
49 | ||
c801d85f KB |
50 | void wxControl::SetLabel( const wxString &label ) |
51 | { | |
d9ea011f | 52 | m_label.Empty(); |
223d09f6 | 53 | for ( const wxChar *pc = label; *pc != wxT('\0'); pc++ ) |
b292e2f5 | 54 | { |
223d09f6 | 55 | if ( *pc == wxT('&') ) |
31528cd3 | 56 | { |
b292e2f5 | 57 | pc++; // skip it |
32c77a71 | 58 | #if 0 // it would be unused anyhow for now - kbd interface not done yet |
223d09f6 | 59 | if ( *pc != wxT('&') ) m_chAccel = *pc; |
32c77a71 | 60 | #endif |
b292e2f5 RR |
61 | } |
62 | m_label << *pc; | |
32c77a71 | 63 | } |
6de97a3b | 64 | } |
c801d85f | 65 | |
9abe166a | 66 | wxString wxControl::GetLabel() const |
c801d85f | 67 | { |
b292e2f5 | 68 | return m_label; |
6de97a3b | 69 | } |
c801d85f KB |
70 | |
71 | ||
f68586e5 VZ |
72 | wxSize wxControl::DoGetBestSize() const |
73 | { | |
0279e844 RR |
74 | // Do not return any arbitrary default value... |
75 | wxASSERT_MSG( m_widget, wxT("DoGetBestSize called before creation") ); | |
76 | ||
f68586e5 | 77 | GtkRequisition req; |
33720b2d RR |
78 | req.width = 2; |
79 | req.height = 2; | |
2afa14f2 | 80 | (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request ) |
f68586e5 VZ |
81 | (m_widget, &req ); |
82 | ||
83 | return wxSize(req.width, req.height); | |
84 | } | |
85 | ||
393cbb8f | 86 | #ifdef __WXGTK20__ |
eaafd2f8 VS |
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 | } | |
393cbb8f | 128 | #endif |
eaafd2f8 | 129 | |
1e6feb95 VZ |
130 | #endif // wxUSE_CONTROLS |
131 |