]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: tbargtk.cpp | |
3 | // Purpose: GTK toolbar | |
4 | // Author: Robert Roebling | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
a3622daa | 7 | // RCS-ID: |
c801d85f | 8 | // Copyright: (c) Robert Roebling |
a3622daa | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "tbargtk.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/toolbar.h" | |
17 | ||
314055fa RR |
18 | //----------------------------------------------------------------------------- |
19 | // data | |
20 | //----------------------------------------------------------------------------- | |
21 | ||
22 | extern bool g_blockEventsOnDrag; | |
23 | ||
c801d85f KB |
24 | //----------------------------------------------------------------------------- |
25 | // wxToolBarTool | |
26 | //----------------------------------------------------------------------------- | |
27 | ||
28 | IMPLEMENT_DYNAMIC_CLASS(wxToolBarTool,wxObject) | |
a3622daa VZ |
29 | |
30 | wxToolBarTool::wxToolBarTool( wxToolBar *owner, int theIndex, | |
03f38c58 VZ |
31 | const wxBitmap& bitmap1, const wxBitmap& bitmap2, |
32 | bool toggle, | |
33 | wxObject *clientData, | |
34 | const wxString& shortHelpString, | |
35 | const wxString& longHelpString, | |
36 | GtkWidget *item ) | |
c801d85f KB |
37 | { |
38 | m_owner = owner; | |
39 | m_index = theIndex; | |
40 | m_bitmap1 = bitmap1; | |
41 | m_bitmap2 = bitmap2; | |
42 | m_isToggle = toggle; | |
43 | m_enabled = TRUE; | |
44 | m_toggleState = FALSE; | |
45 | m_shortHelpString = shortHelpString; | |
46 | m_longHelpString = longHelpString; | |
47 | m_isMenuCommand = TRUE; | |
48 | m_clientData = clientData; | |
49 | m_deleteSecondBitmap = FALSE; | |
fc008f25 RR |
50 | m_item = item; |
51 | } | |
c801d85f | 52 | |
a3622daa | 53 | wxToolBarTool::~wxToolBarTool() |
c801d85f | 54 | { |
fc008f25 | 55 | } |
c801d85f KB |
56 | |
57 | //----------------------------------------------------------------------------- | |
2f2aa628 | 58 | // "clicked" (internal from gtk_toolbar) |
c801d85f KB |
59 | //----------------------------------------------------------------------------- |
60 | ||
61 | static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget), wxToolBarTool *tool ) | |
62 | { | |
314055fa | 63 | if (g_blockEventsOnDrag) return; |
c801d85f | 64 | if (!tool->m_enabled) return; |
a3622daa | 65 | |
c801d85f | 66 | if (tool->m_isToggle) tool->m_toggleState = !tool->m_toggleState; |
a3622daa | 67 | |
c801d85f | 68 | tool->m_owner->OnLeftClick( tool->m_index, tool->m_toggleState ); |
fc008f25 | 69 | } |
c801d85f | 70 | |
2f2aa628 RR |
71 | //----------------------------------------------------------------------------- |
72 | // "enter_notify_event" | |
73 | //----------------------------------------------------------------------------- | |
74 | ||
314055fa RR |
75 | static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget), |
76 | GdkEventCrossing *WXUNUSED(gdk_event), wxToolBarTool *tool ) | |
77 | { | |
78 | if (g_blockEventsOnDrag) return TRUE; | |
79 | ||
80 | tool->m_owner->OnMouseEnter( tool->m_index ); | |
81 | ||
83058c58 | 82 | return FALSE; |
314055fa RR |
83 | } |
84 | ||
2f2aa628 RR |
85 | //----------------------------------------------------------------------------- |
86 | // wxToolBar | |
c801d85f KB |
87 | //----------------------------------------------------------------------------- |
88 | ||
716b7364 | 89 | IMPLEMENT_DYNAMIC_CLASS(wxToolBar,wxControl) |
c801d85f | 90 | |
a3622daa | 91 | wxToolBar::wxToolBar() |
c801d85f | 92 | { |
fc008f25 | 93 | } |
c801d85f | 94 | |
a3622daa | 95 | wxToolBar::wxToolBar( wxWindow *parent, wxWindowID id, |
c801d85f | 96 | const wxPoint& pos, const wxSize& size, |
debe6624 | 97 | long style, const wxString& name ) |
c801d85f KB |
98 | { |
99 | Create( parent, id, pos, size, style, name ); | |
fc008f25 | 100 | } |
c801d85f | 101 | |
a3622daa | 102 | wxToolBar::~wxToolBar() |
c801d85f | 103 | { |
fc008f25 | 104 | } |
c801d85f | 105 | |
a3622daa | 106 | bool wxToolBar::Create( wxWindow *parent, wxWindowID id, |
c801d85f | 107 | const wxPoint& pos, const wxSize& size, |
debe6624 | 108 | long style, const wxString& name ) |
c801d85f KB |
109 | { |
110 | m_needParent = TRUE; | |
a3622daa | 111 | |
c801d85f KB |
112 | PreCreation( parent, id, pos, size, style, name ); |
113 | ||
114 | m_tools.DeleteContents( TRUE ); | |
a3622daa | 115 | |
c801d85f | 116 | m_widget = gtk_handle_box_new(); |
a3622daa | 117 | |
68dda785 VZ |
118 | m_toolbar = GTK_TOOLBAR( gtk_toolbar_new( GTK_ORIENTATION_HORIZONTAL, |
119 | GTK_TOOLBAR_ICONS ) ); | |
03f38c58 | 120 | gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE ); |
a3622daa | 121 | |
c801d85f | 122 | gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) ); |
a3622daa | 123 | |
c801d85f | 124 | gtk_widget_show( GTK_WIDGET(m_toolbar) ); |
a3622daa | 125 | |
c801d85f | 126 | PostCreation(); |
a3622daa | 127 | |
c801d85f | 128 | Show( TRUE ); |
a3622daa | 129 | |
c801d85f | 130 | return TRUE; |
fc008f25 | 131 | } |
c801d85f | 132 | |
716b7364 | 133 | bool wxToolBar::OnLeftClick( int toolIndex, bool toggleDown ) |
c801d85f | 134 | { |
cf4219e7 | 135 | wxCommandEvent event( wxEVT_COMMAND_TOOL_CLICKED, toolIndex ); |
c801d85f | 136 | event.SetEventObject(this); |
46dc76ba | 137 | event.SetInt( toolIndex ); |
c801d85f KB |
138 | event.SetExtraLong((long) toggleDown); |
139 | ||
140 | GetEventHandler()->ProcessEvent(event); | |
141 | ||
142 | return TRUE; | |
fc008f25 | 143 | } |
c801d85f | 144 | |
716b7364 | 145 | void wxToolBar::OnRightClick( int toolIndex, float WXUNUSED(x), float WXUNUSED(y) ) |
c801d85f | 146 | { |
cf4219e7 | 147 | wxCommandEvent event( wxEVT_COMMAND_TOOL_RCLICKED, toolIndex ); |
46dc76ba RR |
148 | event.SetEventObject( this ); |
149 | event.SetInt( toolIndex ); | |
c801d85f KB |
150 | |
151 | GetEventHandler()->ProcessEvent(event); | |
fc008f25 | 152 | } |
c801d85f | 153 | |
716b7364 | 154 | void wxToolBar::OnMouseEnter( int toolIndex ) |
c801d85f | 155 | { |
314055fa | 156 | wxCommandEvent event( wxEVT_COMMAND_TOOL_ENTER, GetId() ); |
c801d85f | 157 | event.SetEventObject(this); |
46dc76ba | 158 | event.SetInt( toolIndex ); |
314055fa | 159 | |
c801d85f | 160 | GetEventHandler()->ProcessEvent(event); |
fc008f25 | 161 | } |
c801d85f | 162 | |
a3622daa | 163 | wxToolBarTool *wxToolBar::AddTool( int toolIndex, const wxBitmap& bitmap, |
debe6624 JS |
164 | const wxBitmap& pushedBitmap, bool toggle, |
165 | float WXUNUSED(xPos), float WXUNUSED(yPos), wxObject *clientData, | |
c801d85f KB |
166 | const wxString& helpString1, const wxString& helpString2 ) |
167 | { | |
03f38c58 VZ |
168 | wxCHECK_MSG( bitmap.Ok(), (wxToolBarTool *)NULL, |
169 | "invalid bitmap for wxToolBar icon" ); | |
a3622daa | 170 | |
03f38c58 VZ |
171 | wxToolBarTool *tool = new wxToolBarTool( this, toolIndex, bitmap, pushedBitmap, |
172 | toggle, clientData, | |
173 | helpString1, helpString2 ); | |
a3622daa | 174 | |
03f38c58 VZ |
175 | wxCHECK_MSG( bitmap.GetBitmap() == NULL, (wxToolBarTool *)NULL, |
176 | "wxToolBar doesn't support GdkBitmap" ); | |
177 | ||
178 | wxCHECK_MSG( bitmap.GetPixmap() != NULL, (wxToolBarTool *)NULL, | |
179 | "wxToolBar::Add needs a wxBitmap" ); | |
903f689b | 180 | |
68dda785 | 181 | GtkWidget *tool_pixmap = (GtkWidget *)NULL; |
903f689b | 182 | |
03f38c58 | 183 | if (TRUE) // FIXME huh? |
903f689b RR |
184 | { |
185 | GdkPixmap *pixmap = bitmap.GetPixmap(); | |
a3622daa | 186 | |
68dda785 VZ |
187 | GdkBitmap *mask = (GdkBitmap *)NULL; |
188 | if ( bitmap.GetMask() ) | |
189 | mask = bitmap.GetMask()->GetBitmap(); | |
903f689b RR |
190 | |
191 | tool_pixmap = gtk_pixmap_new( pixmap, mask ); | |
192 | } | |
193 | ||
c801d85f | 194 | gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 ); |
a3622daa | 195 | |
03f38c58 VZ |
196 | GtkToolbarChildType ctype = toggle ? GTK_TOOLBAR_CHILD_TOGGLEBUTTON |
197 | : GTK_TOOLBAR_CHILD_BUTTON; | |
198 | ||
68dda785 VZ |
199 | GtkWidget *item = gtk_toolbar_append_element |
200 | ( | |
201 | GTK_TOOLBAR(m_toolbar), | |
202 | ctype, | |
203 | (GtkWidget *)NULL, | |
204 | (const char *)NULL, | |
205 | helpString1, | |
206 | "", | |
207 | tool_pixmap, | |
208 | (GtkSignalFunc)gtk_toolbar_callback, | |
209 | (gpointer)tool | |
210 | ); | |
211 | ||
212 | // VZ: we don't want GDK_NO_EXPOSE events because for some reason our | |
213 | // toolbar buttons get them (it doesn't happen in a standalone GTK+ program | |
214 | // for unknown reasons) and it prevents tooltips from appearing. | |
215 | gtk_widget_set_events( GTK_WIDGET(item), | |
216 | gtk_widget_get_events( GTK_WIDGET(item) ) & | |
217 | ~GDK_EXPOSURE_MASK); | |
218 | tool->m_item = item; | |
03f38c58 VZ |
219 | |
220 | gtk_signal_connect( GTK_OBJECT(tool->m_item), | |
221 | "enter_notify_event", | |
222 | GTK_SIGNAL_FUNC(gtk_toolbar_enter_callback), | |
223 | (gpointer)tool ); | |
314055fa | 224 | |
a3622daa VZ |
225 | m_tools.Append( tool ); |
226 | ||
c801d85f | 227 | return tool; |
fc008f25 | 228 | } |
c801d85f | 229 | |
03f38c58 | 230 | void wxToolBar::AddSeparator() |
c801d85f KB |
231 | { |
232 | gtk_toolbar_append_space( m_toolbar ); | |
fc008f25 | 233 | } |
c801d85f | 234 | |
03f38c58 | 235 | void wxToolBar::ClearTools() |
c801d85f | 236 | { |
fc008f25 RR |
237 | wxFAIL_MSG( "wxToolBar::ClearTools not implemented" ); |
238 | } | |
c801d85f | 239 | |
03f38c58 | 240 | void wxToolBar::Realize() |
46dc76ba RR |
241 | { |
242 | m_x = 0; | |
243 | m_y = 0; | |
244 | m_width = 100; | |
245 | m_height = 0; | |
246 | ||
247 | wxNode *node = m_tools.First(); | |
248 | while (node) | |
249 | { | |
250 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
251 | if (tool->m_bitmap1.Ok()) | |
252 | { | |
253 | int tool_height = tool->m_bitmap1.GetHeight(); | |
254 | if (tool_height > m_height) m_height = tool_height; | |
fc008f25 | 255 | } |
46dc76ba RR |
256 | |
257 | node = node->Next(); | |
fc008f25 | 258 | } |
46dc76ba RR |
259 | |
260 | m_height += 10; | |
fc008f25 | 261 | } |
46dc76ba | 262 | |
716b7364 | 263 | void wxToolBar::EnableTool(int toolIndex, bool enable) |
c801d85f | 264 | { |
cf4219e7 RR |
265 | wxNode *node = m_tools.First(); |
266 | while (node) | |
267 | { | |
268 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
269 | if (tool->m_index == toolIndex) | |
270 | { | |
271 | tool->m_enabled = enable; | |
272 | return; | |
273 | } | |
274 | node = node->Next(); | |
fc008f25 RR |
275 | } |
276 | ||
277 | wxFAIL_MSG( "wrong toolbar index" ); | |
278 | } | |
c801d85f | 279 | |
fc008f25 | 280 | void wxToolBar::ToggleTool( int toolIndex, bool toggle ) |
c801d85f | 281 | { |
fc008f25 RR |
282 | wxNode *node = m_tools.First(); |
283 | while (node) | |
284 | { | |
285 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
286 | if (tool->m_index == toolIndex) | |
287 | { | |
288 | tool->m_toggleState = toggle; | |
289 | if ((tool->m_item) && (GTK_IS_TOGGLE_BUTTON(tool->m_item))) | |
290 | gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(tool->m_item), toggle ); | |
291 | return; | |
292 | } | |
293 | node = node->Next(); | |
294 | } | |
295 | ||
296 | wxFAIL_MSG( "wrong toolbar index" ); | |
297 | } | |
c801d85f | 298 | |
fc008f25 | 299 | wxObject *wxToolBar::GetToolClientData( int index ) const |
c801d85f | 300 | { |
cf4219e7 RR |
301 | wxNode *node = m_tools.First(); |
302 | while (node) | |
303 | { | |
304 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
305 | if (tool->m_index == index) return tool->m_clientData;; | |
306 | node = node->Next(); | |
fc008f25 RR |
307 | } |
308 | ||
309 | wxFAIL_MSG( "wrong toolbar index" ); | |
310 | ||
cf4219e7 | 311 | return (wxObject*)NULL; |
fc008f25 | 312 | } |
c801d85f | 313 | |
716b7364 | 314 | bool wxToolBar::GetToolState(int toolIndex) const |
c801d85f | 315 | { |
cf4219e7 RR |
316 | wxNode *node = m_tools.First(); |
317 | while (node) | |
318 | { | |
319 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
320 | if (tool->m_index == toolIndex) return tool->m_toggleState; | |
321 | node = node->Next(); | |
fc008f25 RR |
322 | } |
323 | ||
324 | wxFAIL_MSG( "wrong toolbar index" ); | |
325 | ||
cf4219e7 | 326 | return FALSE; |
fc008f25 | 327 | } |
c801d85f | 328 | |
716b7364 | 329 | bool wxToolBar::GetToolEnabled(int toolIndex) const |
c801d85f | 330 | { |
cf4219e7 RR |
331 | wxNode *node = m_tools.First(); |
332 | while (node) | |
333 | { | |
334 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
335 | if (tool->m_index == toolIndex) return tool->m_enabled; | |
336 | node = node->Next(); | |
fc008f25 RR |
337 | } |
338 | ||
339 | wxFAIL_MSG( "wrong toolbar index" ); | |
340 | ||
cf4219e7 | 341 | return FALSE; |
fc008f25 | 342 | } |
c801d85f | 343 | |
cf4219e7 | 344 | void wxToolBar::SetMargins( int WXUNUSED(x), int WXUNUSED(y) ) |
c801d85f | 345 | { |
03f38c58 | 346 | wxFAIL_MSG( "wxToolBar::SetMargins not implemented" ); |
fc008f25 | 347 | } |
c801d85f | 348 | |
cf4219e7 | 349 | void wxToolBar::SetToolPacking( int WXUNUSED(packing) ) |
c801d85f | 350 | { |
03f38c58 | 351 | wxFAIL_MSG( "wxToolBar::SetToolPacking not implemented" ); |
fc008f25 | 352 | } |
c801d85f | 353 | |
cf4219e7 | 354 | void wxToolBar::SetToolSeparation( int separation ) |
c801d85f | 355 | { |
cf4219e7 | 356 | gtk_toolbar_set_space_size( m_toolbar, separation ); |
fc008f25 | 357 | } |
c801d85f | 358 |