]>
Commit | Line | Data |
---|---|---|
10b959e3 | 1 | ///////////////////////////////////////////////////////////////////////////// |
8a0681f9 VZ |
2 | // Name: common/tbarbase.cpp |
3 | // Purpose: wxToolBarBase implementation | |
10b959e3 | 4 | // Author: Julian Smart |
8a0681f9 | 5 | // Modified by: VZ at 11.12.99 (wxScrollableToolBar splitted off) |
10b959e3 JS |
6 | // Created: 04/01/98 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
1c383dba | 9 | // Licence: wxWindows license |
10b959e3 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
8a0681f9 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
10b959e3 | 20 | #ifdef __GNUG__ |
8a0681f9 | 21 | #pragma implementation "tbarbase.h" |
10b959e3 JS |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
8a0681f9 | 28 | #pragma hdrstop |
10b959e3 JS |
29 | #endif |
30 | ||
1e6feb95 VZ |
31 | #if wxUSE_TOOLBAR |
32 | ||
10b959e3 | 33 | #ifndef WX_PRECOMP |
f538710f | 34 | #include "wx/control.h" |
10b959e3 JS |
35 | #endif |
36 | ||
e702ff0f | 37 | #include "wx/frame.h" |
c229e50d JS |
38 | #include "wx/image.h" |
39 | #include "wx/settings.h" | |
e702ff0f | 40 | |
10b959e3 JS |
41 | #include "wx/tbarbase.h" |
42 | ||
8a0681f9 VZ |
43 | // ---------------------------------------------------------------------------- |
44 | // wxWindows macros | |
45 | // ---------------------------------------------------------------------------- | |
46 | ||
12ed316d JS |
47 | IMPLEMENT_CLASS(wxToolBarBase, wxControl) |
48 | ||
1e6feb95 VZ |
49 | BEGIN_EVENT_TABLE(wxToolBarBase, wxControl) |
50 | EVT_IDLE(wxToolBarBase::OnIdle) | |
51 | END_EVENT_TABLE() | |
52 | ||
8a0681f9 | 53 | #include "wx/listimpl.cpp" |
1c383dba | 54 | |
8a0681f9 | 55 | WX_DEFINE_LIST(wxToolBarToolsList); |
10b959e3 | 56 | |
8a0681f9 VZ |
57 | // ============================================================================ |
58 | // implementation | |
59 | // ============================================================================ | |
10b959e3 | 60 | |
8a0681f9 VZ |
61 | // ---------------------------------------------------------------------------- |
62 | // wxToolBarToolBase | |
63 | // ---------------------------------------------------------------------------- | |
10b959e3 | 64 | |
8a0681f9 | 65 | bool wxToolBarToolBase::Enable(bool enable) |
10b959e3 | 66 | { |
8a0681f9 VZ |
67 | if ( m_enabled == enable ) |
68 | return FALSE; | |
10b959e3 | 69 | |
8a0681f9 | 70 | m_enabled = enable; |
10b959e3 | 71 | |
8a0681f9 | 72 | return TRUE; |
10b959e3 JS |
73 | } |
74 | ||
8a0681f9 | 75 | bool wxToolBarToolBase::Toggle(bool toggle) |
10b959e3 | 76 | { |
e76c0b5f | 77 | wxASSERT_MSG( CanBeToggled(), _T("can't toggle this tool") ); |
8a0681f9 VZ |
78 | |
79 | if ( m_toggled == toggle ) | |
80 | return FALSE; | |
10b959e3 | 81 | |
8a0681f9 VZ |
82 | m_toggled = toggle; |
83 | ||
84 | return TRUE; | |
10b959e3 JS |
85 | } |
86 | ||
8a0681f9 | 87 | bool wxToolBarToolBase::SetToggle(bool toggle) |
10b959e3 | 88 | { |
e76c0b5f VZ |
89 | wxItemKind kind = toggle ? wxITEM_CHECK : wxITEM_NORMAL; |
90 | if ( m_kind == kind ) | |
8a0681f9 | 91 | return FALSE; |
10b959e3 | 92 | |
e76c0b5f | 93 | m_kind = kind; |
10b959e3 JS |
94 | |
95 | return TRUE; | |
96 | } | |
97 | ||
8a0681f9 | 98 | bool wxToolBarToolBase::SetShortHelp(const wxString& help) |
10b959e3 | 99 | { |
8a0681f9 VZ |
100 | if ( m_shortHelpString == help ) |
101 | return FALSE; | |
10b959e3 | 102 | |
8a0681f9 VZ |
103 | m_shortHelpString = help; |
104 | ||
105 | return TRUE; | |
10b959e3 JS |
106 | } |
107 | ||
8a0681f9 | 108 | bool wxToolBarToolBase::SetLongHelp(const wxString& help) |
10b959e3 | 109 | { |
8a0681f9 VZ |
110 | if ( m_longHelpString == help ) |
111 | return FALSE; | |
10b959e3 | 112 | |
8a0681f9 VZ |
113 | m_longHelpString = help; |
114 | ||
115 | return TRUE; | |
10b959e3 JS |
116 | } |
117 | ||
8a0681f9 | 118 | wxToolBarToolBase::~wxToolBarToolBase() |
10b959e3 | 119 | { |
8a0681f9 | 120 | } |
10b959e3 | 121 | |
8a0681f9 VZ |
122 | // ---------------------------------------------------------------------------- |
123 | // wxToolBarBase adding/deleting items | |
124 | // ---------------------------------------------------------------------------- | |
ac91b9d2 | 125 | |
8a0681f9 VZ |
126 | wxToolBarBase::wxToolBarBase() |
127 | { | |
128 | // the list owns the pointers | |
129 | m_tools.DeleteContents(TRUE); | |
10b959e3 | 130 | |
8a0681f9 | 131 | m_xMargin = m_yMargin = 0; |
10b959e3 | 132 | |
8a0681f9 | 133 | m_maxRows = m_maxCols = 0; |
10b959e3 JS |
134 | } |
135 | ||
e76c0b5f VZ |
136 | wxToolBarToolBase *wxToolBarBase::DoAddTool(int id, |
137 | const wxString& label, | |
138 | const wxBitmap& bitmap, | |
139 | const wxBitmap& bmpDisabled, | |
140 | wxItemKind kind, | |
141 | const wxString& shortHelp, | |
142 | const wxString& longHelp, | |
143 | wxObject *clientData, | |
144 | wxCoord WXUNUSED(xPos), | |
145 | wxCoord WXUNUSED(yPos)) | |
10b959e3 | 146 | { |
e76c0b5f VZ |
147 | return InsertTool(GetToolsCount(), id, label, bitmap, bmpDisabled, |
148 | kind, shortHelp, longHelp, clientData); | |
10b959e3 JS |
149 | } |
150 | ||
8a0681f9 VZ |
151 | wxToolBarToolBase *wxToolBarBase::InsertTool(size_t pos, |
152 | int id, | |
e76c0b5f | 153 | const wxString& label, |
8a0681f9 | 154 | const wxBitmap& bitmap, |
e76c0b5f VZ |
155 | const wxBitmap& bmpDisabled, |
156 | wxItemKind kind, | |
157 | const wxString& shortHelp, | |
158 | const wxString& longHelp, | |
159 | wxObject *clientData) | |
10b959e3 | 160 | { |
8a0681f9 VZ |
161 | wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL, |
162 | _T("invalid position in wxToolBar::InsertTool()") ); | |
163 | ||
e76c0b5f VZ |
164 | wxToolBarToolBase *tool = CreateTool(id, label, bitmap, bmpDisabled, kind, |
165 | clientData, shortHelp, longHelp); | |
8a0681f9 | 166 | |
dd91da4e | 167 | if ( !InsertTool(pos, tool) ) |
8a0681f9 VZ |
168 | { |
169 | delete tool; | |
170 | ||
171 | return NULL; | |
172 | } | |
173 | ||
dd91da4e VZ |
174 | return tool; |
175 | } | |
176 | ||
177 | wxToolBarToolBase *wxToolBarBase::AddTool(wxToolBarToolBase *tool) | |
178 | { | |
179 | return InsertTool(GetToolsCount(), tool); | |
180 | } | |
181 | ||
182 | wxToolBarToolBase * | |
183 | wxToolBarBase::InsertTool(size_t pos, wxToolBarToolBase *tool) | |
184 | { | |
185 | wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL, | |
186 | _T("invalid position in wxToolBar::InsertTool()") ); | |
187 | ||
188 | if ( !tool || !DoInsertTool(pos, tool) ) | |
189 | { | |
190 | return NULL; | |
191 | } | |
192 | ||
8a0681f9 VZ |
193 | m_tools.Insert(pos, tool); |
194 | ||
195 | return tool; | |
10b959e3 JS |
196 | } |
197 | ||
8a0681f9 | 198 | wxToolBarToolBase *wxToolBarBase::AddControl(wxControl *control) |
10b959e3 | 199 | { |
8a0681f9 | 200 | return InsertControl(GetToolsCount(), control); |
10b959e3 JS |
201 | } |
202 | ||
8a0681f9 | 203 | wxToolBarToolBase *wxToolBarBase::InsertControl(size_t pos, wxControl *control) |
10b959e3 | 204 | { |
8a0681f9 VZ |
205 | wxCHECK_MSG( control, (wxToolBarToolBase *)NULL, |
206 | _T("toolbar: can't insert NULL control") ); | |
207 | ||
208 | wxCHECK_MSG( control->GetParent() == this, (wxToolBarToolBase *)NULL, | |
209 | _T("control must have toolbar as parent") ); | |
210 | ||
211 | wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL, | |
212 | _T("invalid position in wxToolBar::InsertControl()") ); | |
213 | ||
214 | wxToolBarToolBase *tool = CreateTool(control); | |
215 | ||
dd91da4e | 216 | if ( !InsertTool(pos, tool) ) |
8a0681f9 VZ |
217 | { |
218 | delete tool; | |
219 | ||
220 | return NULL; | |
221 | } | |
222 | ||
8a0681f9 | 223 | return tool; |
10b959e3 JS |
224 | } |
225 | ||
fba2d5e6 RR |
226 | wxControl *wxToolBarBase::FindControl( int id ) |
227 | { | |
228 | for ( wxToolBarToolsList::Node* node = m_tools.GetFirst(); | |
229 | node; | |
230 | node = node->GetNext() ) | |
231 | { | |
232 | wxControl *control = node->GetData()->GetControl(); | |
dd91da4e | 233 | |
fba2d5e6 RR |
234 | if (control) |
235 | { | |
236 | if (control->GetId() == id) | |
237 | return control; | |
238 | } | |
239 | } | |
240 | ||
241 | return NULL; | |
242 | } | |
243 | ||
8a0681f9 | 244 | wxToolBarToolBase *wxToolBarBase::AddSeparator() |
10b959e3 | 245 | { |
8a0681f9 | 246 | return InsertSeparator(GetToolsCount()); |
10b959e3 JS |
247 | } |
248 | ||
8a0681f9 | 249 | wxToolBarToolBase *wxToolBarBase::InsertSeparator(size_t pos) |
10b959e3 | 250 | { |
8a0681f9 VZ |
251 | wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL, |
252 | _T("invalid position in wxToolBar::InsertSeparator()") ); | |
253 | ||
254 | wxToolBarToolBase *tool = CreateTool(wxID_SEPARATOR, | |
e76c0b5f | 255 | wxEmptyString, |
8a0681f9 | 256 | wxNullBitmap, wxNullBitmap, |
e76c0b5f | 257 | wxITEM_SEPARATOR, (wxObject *)NULL, |
8a0681f9 VZ |
258 | wxEmptyString, wxEmptyString); |
259 | ||
260 | if ( !tool || !DoInsertTool(pos, tool) ) | |
10b959e3 | 261 | { |
8a0681f9 VZ |
262 | delete tool; |
263 | ||
264 | return NULL; | |
10b959e3 | 265 | } |
8a0681f9 VZ |
266 | |
267 | m_tools.Insert(pos, tool); | |
268 | ||
269 | return tool; | |
10b959e3 JS |
270 | } |
271 | ||
8a0681f9 | 272 | wxToolBarToolBase *wxToolBarBase::RemoveTool(int id) |
10b959e3 | 273 | { |
8a0681f9 VZ |
274 | size_t pos = 0; |
275 | wxToolBarToolsList::Node *node; | |
276 | for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) | |
10b959e3 | 277 | { |
8a0681f9 VZ |
278 | if ( node->GetData()->GetId() == id ) |
279 | break; | |
280 | ||
281 | pos++; | |
10b959e3 | 282 | } |
10b959e3 | 283 | |
8a0681f9 | 284 | if ( !node ) |
10b959e3 | 285 | { |
8a0681f9 VZ |
286 | // don't give any error messages - sometimes we might call RemoveTool() |
287 | // without knowing whether the tool is or not in the toolbar | |
288 | return (wxToolBarToolBase *)NULL; | |
10b959e3 | 289 | } |
10b959e3 | 290 | |
8a0681f9 VZ |
291 | wxToolBarToolBase *tool = node->GetData(); |
292 | if ( !DoDeleteTool(pos, tool) ) | |
293 | { | |
294 | return (wxToolBarToolBase *)NULL; | |
295 | } | |
10b959e3 | 296 | |
8a0681f9 VZ |
297 | // the node would delete the data, so set it to NULL to avoid this |
298 | node->SetData(NULL); | |
10b959e3 | 299 | |
8a0681f9 | 300 | m_tools.DeleteNode(node); |
10b959e3 | 301 | |
8a0681f9 | 302 | return tool; |
10b959e3 JS |
303 | } |
304 | ||
8a0681f9 | 305 | bool wxToolBarBase::DeleteToolByPos(size_t pos) |
10b959e3 | 306 | { |
8a0681f9 VZ |
307 | wxCHECK_MSG( pos < GetToolsCount(), FALSE, |
308 | _T("invalid position in wxToolBar::DeleteToolByPos()") ); | |
10b959e3 | 309 | |
8a0681f9 | 310 | wxToolBarToolsList::Node *node = m_tools.Item(pos); |
10b959e3 | 311 | |
8a0681f9 VZ |
312 | if ( !DoDeleteTool(pos, node->GetData()) ) |
313 | { | |
314 | return FALSE; | |
315 | } | |
316 | ||
317 | m_tools.DeleteNode(node); | |
318 | ||
319 | return TRUE; | |
10b959e3 JS |
320 | } |
321 | ||
8a0681f9 | 322 | bool wxToolBarBase::DeleteTool(int id) |
10b959e3 | 323 | { |
8a0681f9 VZ |
324 | size_t pos = 0; |
325 | wxToolBarToolsList::Node *node; | |
326 | for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) | |
327 | { | |
328 | if ( node->GetData()->GetId() == id ) | |
329 | break; | |
330 | ||
331 | pos++; | |
332 | } | |
333 | ||
334 | if ( !node || !DoDeleteTool(pos, node->GetData()) ) | |
335 | { | |
336 | return FALSE; | |
337 | } | |
338 | ||
339 | m_tools.DeleteNode(node); | |
340 | ||
341 | return TRUE; | |
10b959e3 JS |
342 | } |
343 | ||
8a0681f9 | 344 | wxToolBarToolBase *wxToolBarBase::FindById(int id) const |
10b959e3 | 345 | { |
8a0681f9 VZ |
346 | wxToolBarToolBase *tool = (wxToolBarToolBase *)NULL; |
347 | ||
348 | for ( wxToolBarToolsList::Node *node = m_tools.GetFirst(); | |
349 | node; | |
350 | node = node->GetNext() ) | |
351 | { | |
352 | tool = node->GetData(); | |
353 | if ( tool->GetId() == id ) | |
354 | { | |
355 | // found | |
356 | break; | |
357 | } | |
d9739886 VZ |
358 | |
359 | tool = NULL; | |
8a0681f9 VZ |
360 | } |
361 | ||
362 | return tool; | |
10b959e3 JS |
363 | } |
364 | ||
8a0681f9 | 365 | void wxToolBarBase::ClearTools() |
10b959e3 | 366 | { |
8a0681f9 | 367 | m_tools.Clear(); |
10b959e3 JS |
368 | } |
369 | ||
8a0681f9 | 370 | bool wxToolBarBase::Realize() |
10b959e3 | 371 | { |
8a0681f9 | 372 | return TRUE; |
10b959e3 JS |
373 | } |
374 | ||
8a0681f9 | 375 | wxToolBarBase::~wxToolBarBase() |
10b959e3 | 376 | { |
10b959e3 JS |
377 | } |
378 | ||
8a0681f9 VZ |
379 | // ---------------------------------------------------------------------------- |
380 | // wxToolBarBase tools state | |
381 | // ---------------------------------------------------------------------------- | |
10b959e3 | 382 | |
8a0681f9 | 383 | void wxToolBarBase::EnableTool(int id, bool enable) |
10b959e3 | 384 | { |
8a0681f9 VZ |
385 | wxToolBarToolBase *tool = FindById(id); |
386 | if ( tool ) | |
10b959e3 | 387 | { |
8a0681f9 VZ |
388 | if ( tool->Enable(enable) ) |
389 | { | |
390 | DoEnableTool(tool, enable); | |
391 | } | |
10b959e3 | 392 | } |
8a0681f9 | 393 | } |
10b959e3 | 394 | |
8a0681f9 VZ |
395 | void wxToolBarBase::ToggleTool(int id, bool toggle) |
396 | { | |
397 | wxToolBarToolBase *tool = FindById(id); | |
398 | if ( tool && tool->CanBeToggled() ) | |
10b959e3 | 399 | { |
8a0681f9 VZ |
400 | if ( tool->Toggle(toggle) ) |
401 | { | |
402 | DoToggleTool(tool, toggle); | |
403 | } | |
10b959e3 | 404 | } |
10b959e3 JS |
405 | } |
406 | ||
8a0681f9 VZ |
407 | void wxToolBarBase::SetToggle(int id, bool toggle) |
408 | { | |
409 | wxToolBarToolBase *tool = FindById(id); | |
410 | if ( tool ) | |
10b959e3 | 411 | { |
8a0681f9 VZ |
412 | if ( tool->SetToggle(toggle) ) |
413 | { | |
414 | DoSetToggle(tool, toggle); | |
415 | } | |
10b959e3 | 416 | } |
8a0681f9 VZ |
417 | } |
418 | ||
419 | void wxToolBarBase::SetToolShortHelp(int id, const wxString& help) | |
420 | { | |
421 | wxToolBarToolBase *tool = FindById(id); | |
422 | if ( tool ) | |
10b959e3 | 423 | { |
8a0681f9 | 424 | (void)tool->SetShortHelp(help); |
10b959e3 | 425 | } |
8a0681f9 VZ |
426 | } |
427 | ||
428 | void wxToolBarBase::SetToolLongHelp(int id, const wxString& help) | |
429 | { | |
430 | wxToolBarToolBase *tool = FindById(id); | |
431 | if ( tool ) | |
10b959e3 | 432 | { |
8a0681f9 | 433 | (void)tool->SetLongHelp(help); |
10b959e3 | 434 | } |
10b959e3 JS |
435 | } |
436 | ||
8a0681f9 | 437 | wxObject *wxToolBarBase::GetToolClientData(int id) const |
10b959e3 | 438 | { |
8a0681f9 VZ |
439 | wxToolBarToolBase *tool = FindById(id); |
440 | ||
441 | return tool ? tool->GetClientData() : (wxObject *)NULL; | |
10b959e3 JS |
442 | } |
443 | ||
6fd5fa4f VZ |
444 | void wxToolBarBase::SetToolClientData(int id, wxObject *clientData) |
445 | { | |
446 | wxToolBarToolBase *tool = FindById(id); | |
447 | ||
448 | wxCHECK_RET( tool, _T("no such tool in wxToolBar::SetToolClientData") ); | |
449 | ||
450 | tool->SetClientData(clientData); | |
451 | } | |
452 | ||
8a0681f9 | 453 | bool wxToolBarBase::GetToolState(int id) const |
10b959e3 | 454 | { |
8a0681f9 VZ |
455 | wxToolBarToolBase *tool = FindById(id); |
456 | wxCHECK_MSG( tool, FALSE, _T("no such tool") ); | |
457 | ||
458 | return tool->IsToggled(); | |
10b959e3 JS |
459 | } |
460 | ||
8a0681f9 | 461 | bool wxToolBarBase::GetToolEnabled(int id) const |
10b959e3 | 462 | { |
8a0681f9 VZ |
463 | wxToolBarToolBase *tool = FindById(id); |
464 | wxCHECK_MSG( tool, FALSE, _T("no such tool") ); | |
465 | ||
466 | return tool->IsEnabled(); | |
10b959e3 JS |
467 | } |
468 | ||
8a0681f9 | 469 | wxString wxToolBarBase::GetToolShortHelp(int id) const |
10b959e3 | 470 | { |
8a0681f9 VZ |
471 | wxToolBarToolBase *tool = FindById(id); |
472 | wxCHECK_MSG( tool, _T(""), _T("no such tool") ); | |
473 | ||
474 | return tool->GetShortHelp(); | |
10b959e3 JS |
475 | } |
476 | ||
8a0681f9 | 477 | wxString wxToolBarBase::GetToolLongHelp(int id) const |
10b959e3 | 478 | { |
8a0681f9 VZ |
479 | wxToolBarToolBase *tool = FindById(id); |
480 | wxCHECK_MSG( tool, _T(""), _T("no such tool") ); | |
10b959e3 | 481 | |
8a0681f9 | 482 | return tool->GetLongHelp(); |
10b959e3 JS |
483 | } |
484 | ||
8a0681f9 VZ |
485 | // ---------------------------------------------------------------------------- |
486 | // wxToolBarBase geometry | |
487 | // ---------------------------------------------------------------------------- | |
488 | ||
489 | void wxToolBarBase::SetMargins(int x, int y) | |
10b959e3 | 490 | { |
8a0681f9 VZ |
491 | m_xMargin = x; |
492 | m_yMargin = y; | |
10b959e3 JS |
493 | } |
494 | ||
8a0681f9 | 495 | void wxToolBarBase::SetRows(int WXUNUSED(nRows)) |
10b959e3 | 496 | { |
8a0681f9 | 497 | // nothing |
10b959e3 JS |
498 | } |
499 | ||
8a0681f9 VZ |
500 | // ---------------------------------------------------------------------------- |
501 | // event processing | |
502 | // ---------------------------------------------------------------------------- | |
503 | ||
504 | // Only allow toggle if returns TRUE | |
505 | bool wxToolBarBase::OnLeftClick(int id, bool toggleDown) | |
10b959e3 | 506 | { |
8a0681f9 VZ |
507 | wxCommandEvent event(wxEVT_COMMAND_TOOL_CLICKED, id); |
508 | event.SetEventObject(this); | |
6bec54e1 VZ |
509 | |
510 | // we use SetInt() to make wxCommandEvent::IsChecked() return toggleDown | |
511 | event.SetInt((int)toggleDown); | |
512 | ||
513 | // and SetExtraLong() for backwards compatibility | |
514 | event.SetExtraLong((long)toggleDown); | |
8a0681f9 VZ |
515 | |
516 | // Send events to this toolbar instead (and thence up the window hierarchy) | |
517 | GetEventHandler()->ProcessEvent(event); | |
518 | ||
519 | return TRUE; | |
10b959e3 JS |
520 | } |
521 | ||
8a0681f9 VZ |
522 | // Call when right button down. |
523 | void wxToolBarBase::OnRightClick(int id, | |
524 | long WXUNUSED(x), | |
525 | long WXUNUSED(y)) | |
10b959e3 | 526 | { |
8a0681f9 VZ |
527 | wxCommandEvent event(wxEVT_COMMAND_TOOL_RCLICKED, id); |
528 | event.SetEventObject(this); | |
529 | event.SetInt(id); | |
530 | ||
531 | GetEventHandler()->ProcessEvent(event); | |
532 | } | |
43d811ea | 533 | |
8a0681f9 VZ |
534 | // Called when the mouse cursor enters a tool bitmap (no button pressed). |
535 | // Argument is -1 if mouse is exiting the toolbar. | |
536 | // Note that for this event, the id of the window is used, | |
537 | // and the integer parameter of wxCommandEvent is used to retrieve | |
538 | // the tool id. | |
539 | void wxToolBarBase::OnMouseEnter(int id) | |
540 | { | |
541 | wxCommandEvent event(wxEVT_COMMAND_TOOL_ENTER, GetId()); | |
542 | event.SetEventObject(this); | |
543 | event.SetInt(id); | |
544 | ||
8a0681f9 | 545 | wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); |
1f361cdd | 546 | if( frame ) |
66ce9e06 | 547 | { |
1f361cdd MB |
548 | wxToolBarToolBase* tool = id == -1 ? (wxToolBarToolBase*)0 : FindById(id); |
549 | wxString help = tool ? tool->GetLongHelp() : wxString(); | |
550 | frame->DoGiveHelp( help, id != -1 ); | |
66ce9e06 VZ |
551 | } |
552 | ||
1f361cdd | 553 | (void)GetEventHandler()->ProcessEvent(event); |
8a0681f9 VZ |
554 | } |
555 | ||
556 | // ---------------------------------------------------------------------------- | |
557 | // UI updates | |
558 | // ---------------------------------------------------------------------------- | |
559 | ||
560 | void wxToolBarBase::OnIdle(wxIdleEvent& event) | |
561 | { | |
ac91b9d2 | 562 | DoToolbarUpdates(); |
8a0681f9 VZ |
563 | |
564 | event.Skip(); | |
10b959e3 JS |
565 | } |
566 | ||
567 | // Do the toolbar button updates (check for EVT_UPDATE_UI handlers) | |
ac91b9d2 VZ |
568 | void wxToolBarBase::DoToolbarUpdates() |
569 | { | |
e63fdcd6 JS |
570 | wxWindow* parent = this; |
571 | while (parent->GetParent()) | |
572 | parent = parent->GetParent(); | |
573 | ||
d3734d65 RR |
574 | // This kind of #ifdef is a good way to annoy people. It breaks |
575 | // apps, but only on one platform and due to a hack in officially | |
576 | // platform independent code. It took me hours to fix this. RR. | |
577 | // | |
578 | // #ifdef __WXMSW__ | |
579 | // wxWindow* focusWin = wxFindFocusDescendant(parent); | |
580 | // #else | |
f0e9f0d3 | 581 | wxWindow* focusWin = (wxWindow*) NULL; |
d3734d65 | 582 | // #endif |
e63fdcd6 JS |
583 | |
584 | wxEvtHandler* evtHandler = focusWin ? focusWin->GetEventHandler() : GetEventHandler() ; | |
e702ff0f | 585 | |
8a0681f9 VZ |
586 | for ( wxToolBarToolsList::Node* node = m_tools.GetFirst(); |
587 | node; | |
588 | node = node->GetNext() ) | |
ac91b9d2 | 589 | { |
8a0681f9 | 590 | int id = node->GetData()->GetId(); |
ac91b9d2 | 591 | |
8a0681f9 | 592 | wxUpdateUIEvent event(id); |
ac91b9d2 VZ |
593 | event.SetEventObject(this); |
594 | ||
8a0681f9 | 595 | if ( evtHandler->ProcessEvent(event) ) |
ac91b9d2 | 596 | { |
8a0681f9 VZ |
597 | if ( event.GetSetEnabled() ) |
598 | EnableTool(id, event.GetEnabled()); | |
599 | if ( event.GetSetChecked() ) | |
600 | ToggleTool(id, event.GetChecked()); | |
601 | #if 0 | |
602 | if ( event.GetSetText() ) | |
ac91b9d2 | 603 | // Set tooltip? |
8a0681f9 | 604 | #endif // 0 |
ac91b9d2 | 605 | } |
ac91b9d2 | 606 | } |
10b959e3 JS |
607 | } |
608 | ||
c229e50d JS |
609 | // Helper function, used by wxCreateGreyedImage |
610 | ||
cee14ca0 VZ |
611 | static void wxGreyOutImage( const wxImage& src, |
612 | wxImage& dest, | |
613 | const wxColour& darkCol, | |
614 | const wxColour& lightCol, | |
615 | const wxColour& bgCol ) | |
c229e50d | 616 | { |
25a14595 JS |
617 | // Second attempt, just making things monochrome |
618 | int width = src.GetWidth(); | |
619 | int height = src.GetHeight(); | |
620 | ||
cee14ca0 VZ |
621 | int redCur, greenCur, blueCur; |
622 | for ( int x = 0; x < width; x++ ) | |
25a14595 | 623 | { |
cee14ca0 VZ |
624 | for ( int y = 1; y < height; y++ ) |
625 | { | |
25a14595 JS |
626 | redCur = src.GetRed(x, y); |
627 | greenCur = src.GetGreen(x, y); | |
cee14ca0 | 628 | blueCur = src.GetBlue(x, y); |
25a14595 | 629 | |
cee14ca0 | 630 | // Change light things to the background colour |
25a14595 JS |
631 | if ( redCur >= (lightCol.Red() - 50) && greenCur >= (lightCol.Green() - 50) && blueCur >= (lightCol.Blue() - 50) ) |
632 | { | |
633 | dest.SetRGB(x,y, bgCol.Red(), bgCol.Green(), bgCol.Blue()); | |
634 | } | |
635 | else if ( redCur == bgCol.Red() && greenCur == bgCol.Green() && blueCur == bgCol.Blue() ) | |
636 | { | |
cee14ca0 | 637 | // Leave the background colour as-is |
25a14595 JS |
638 | // dest.SetRGB(x,y, bgCol.Red(), bgCol.Green(), bgCol.Blue()); |
639 | } | |
640 | else // if ( redCur <= darkCol.Red() && greenCur <= darkCol.Green() && blueCur <= darkCol.Blue() ) | |
641 | { | |
cee14ca0 | 642 | // Change dark things to really dark |
c229e50d JS |
643 | dest.SetRGB(x,y, darkCol.Red(), darkCol.Green(), darkCol.Blue()); |
644 | } | |
c229e50d | 645 | } |
cee14ca0 | 646 | } |
c229e50d JS |
647 | } |
648 | ||
649 | /* | |
650 | * Make a greyed-out image suitable for disabled buttons. | |
651 | * This code is adapted from wxNewBitmapButton in FL. | |
652 | */ | |
653 | ||
654 | bool wxCreateGreyedImage(const wxImage& in, wxImage& out) | |
655 | { | |
656 | out = in.Copy(); | |
657 | ||
658 | // assuming the pixels along the edges are of the background color | |
659 | wxColour bgCol(in.GetRed(0, 0), in.GetGreen(0, 0), in.GetBlue(0, 0)); | |
660 | ||
661 | wxColour darkCol = wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW) ; | |
662 | wxColour lightCol = wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT) ; | |
663 | ||
664 | wxGreyOutImage(in, out, darkCol, lightCol, bgCol); | |
665 | ||
666 | return TRUE; | |
667 | } | |
668 | ||
8a0681f9 | 669 | #endif // wxUSE_TOOLBAR |