]>
Commit | Line | Data |
---|---|---|
4bb6408c | 1 | ///////////////////////////////////////////////////////////////////////////// |
8a0681f9 | 2 | // Name: motif/toolbar.cpp |
4bb6408c JS |
3 | // Purpose: wxToolBar |
4 | // Author: Julian Smart | |
8a0681f9 | 5 | // Modified by: 13.12.99 by VZ during toolbar classes reorganization |
4bb6408c JS |
6 | // Created: 04/01/98 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
8a0681f9 | 9 | // Licence: wxWindows licence |
4bb6408c JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
8a0681f9 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
4bb6408c | 20 | #ifdef __GNUG__ |
8a0681f9 | 21 | #pragma implementation "toolbar.h" |
4bb6408c JS |
22 | #endif |
23 | ||
24 | #include "wx/wx.h" | |
1a3ac83f JS |
25 | #include "wx/app.h" |
26 | #include "wx/timer.h" | |
1ccbb61a | 27 | #include "wx/toolbar.h" |
0d57be45 | 28 | |
338dd992 JJ |
29 | #ifdef __VMS__ |
30 | #pragma message disable nosimpint | |
31 | #endif | |
0d57be45 JS |
32 | #include <Xm/Xm.h> |
33 | #include <Xm/PushBG.h> | |
34 | #include <Xm/PushB.h> | |
1a3ac83f | 35 | #include <Xm/Label.h> |
0d57be45 JS |
36 | #include <Xm/ToggleB.h> |
37 | #include <Xm/ToggleBG.h> | |
38 | #include <Xm/Form.h> | |
338dd992 JJ |
39 | #ifdef __VMS__ |
40 | #pragma message enable nosimpint | |
41 | #endif | |
0d57be45 JS |
42 | |
43 | #include "wx/motif/private.h" | |
4bb6408c | 44 | |
8a0681f9 VZ |
45 | // ---------------------------------------------------------------------------- |
46 | // wxWin macros | |
47 | // ---------------------------------------------------------------------------- | |
48 | ||
49 | #if !USE_SHARED_LIBRARY | |
50 | IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl) | |
51 | #endif | |
4bb6408c | 52 | |
8a0681f9 VZ |
53 | // ---------------------------------------------------------------------------- |
54 | // private functions | |
55 | // ---------------------------------------------------------------------------- | |
4bb6408c | 56 | |
1a3ac83f | 57 | static void wxToolButtonCallback (Widget w, XtPointer clientData, |
bf6c2b35 | 58 | XtPointer ptr); |
1a3ac83f JS |
59 | static void wxToolButtonPopupCallback (Widget w, XtPointer client_data, |
60 | XEvent *event, Boolean *continue_to_dispatch); | |
61 | ||
8a0681f9 VZ |
62 | // ---------------------------------------------------------------------------- |
63 | // private classes | |
64 | // ---------------------------------------------------------------------------- | |
65 | ||
66 | class wxToolBarTimer : public wxTimer | |
1a3ac83f JS |
67 | { |
68 | public: | |
8a0681f9 | 69 | virtual void Notify(); |
1a3ac83f | 70 | |
8a0681f9 VZ |
71 | static Widget help_popup; |
72 | static Widget buttonWidget; | |
73 | static wxString helpString; | |
1a3ac83f JS |
74 | }; |
75 | ||
8a0681f9 VZ |
76 | class wxToolBarTool : public wxToolBarToolBase |
77 | { | |
78 | public: | |
79 | wxToolBarTool(wxToolBar *tbar, | |
80 | int id, | |
81 | const wxBitmap& bitmap1, | |
82 | const wxBitmap& bitmap2, | |
83 | bool toggle, | |
84 | wxObject *clientData, | |
85 | const wxString& shortHelpString, | |
86 | const wxString& longHelpString) | |
87 | : wxToolBarToolBase(tbar, id, bitmap1, bitmap2, toggle, | |
88 | clientData, shortHelpString, longHelpString) | |
89 | { | |
90 | Init(); | |
91 | } | |
92 | ||
93 | wxToolBarTool(wxToolBar *tbar, wxControl *control) | |
94 | : wxToolBarToolBase(tbar, control) | |
95 | { | |
96 | Init(); | |
97 | } | |
98 | ||
99 | virtual ~wxToolBarTool(); | |
100 | ||
101 | // accessors | |
102 | void SetWidget(Widget widget) { m_widget = widget; } | |
103 | Widget GetButtonWidget() const { return m_widget; } | |
104 | ||
105 | void SetPixmap(Pixmap pixmap) { m_pixmap = pixmap; } | |
106 | Pixmap GetPixmap() const { return m_pixmap; } | |
107 | ||
108 | protected: | |
109 | void Init(); | |
110 | ||
111 | Widget m_widget; | |
112 | Pixmap m_pixmap; | |
113 | }; | |
114 | ||
115 | // ---------------------------------------------------------------------------- | |
116 | // globals | |
117 | // ---------------------------------------------------------------------------- | |
118 | ||
1a3ac83f JS |
119 | static wxToolBarTimer* wxTheToolBarTimer = (wxToolBarTimer*) NULL; |
120 | ||
121 | Widget wxToolBarTimer::help_popup = (Widget) 0; | |
122 | Widget wxToolBarTimer::buttonWidget = (Widget) 0; | |
8a0681f9 VZ |
123 | wxString wxToolBarTimer::helpString; |
124 | ||
125 | // ============================================================================ | |
126 | // implementation | |
127 | // ============================================================================ | |
128 | ||
129 | // ---------------------------------------------------------------------------- | |
130 | // wxToolBarTool | |
131 | // ---------------------------------------------------------------------------- | |
132 | ||
982b2cfc VZ |
133 | wxToolBarToolBase *wxToolBar::CreateTool(int id, |
134 | const wxBitmap& bitmap1, | |
135 | const wxBitmap& bitmap2, | |
136 | bool toggle, | |
137 | wxObject *clientData, | |
138 | const wxString& shortHelpString, | |
139 | const wxString& longHelpString) | |
8a0681f9 | 140 | { |
982b2cfc | 141 | return new wxToolBarTool(this, id, bitmap1, bitmap2, toggle, |
8a0681f9 VZ |
142 | clientData, shortHelpString, longHelpString); |
143 | } | |
1a3ac83f | 144 | |
982b2cfc | 145 | wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control) |
4bb6408c | 146 | { |
982b2cfc | 147 | return new wxToolBarTool(this, control); |
4bb6408c JS |
148 | } |
149 | ||
8a0681f9 VZ |
150 | void wxToolBarTool::Init() |
151 | { | |
152 | m_widget = (Widget)0; | |
153 | m_pixmap = (Pixmap)0; | |
154 | } | |
155 | ||
156 | wxToolBarTool::~wxToolBarTool() | |
157 | { | |
982b2cfc VZ |
158 | if ( m_widget ) |
159 | XtDestroyWidget(m_widget); | |
160 | if ( m_pixmap ) | |
161 | XmDestroyPixmap(DefaultScreenOfDisplay((Display*)wxGetDisplay()), | |
162 | m_pixmap); | |
8a0681f9 VZ |
163 | } |
164 | ||
165 | // ---------------------------------------------------------------------------- | |
166 | // wxToolBar construction | |
167 | // ---------------------------------------------------------------------------- | |
168 | ||
169 | void wxToolBar::Init() | |
4bb6408c JS |
170 | { |
171 | m_maxWidth = -1; | |
172 | m_maxHeight = -1; | |
4bb6408c JS |
173 | m_defaultWidth = 24; |
174 | m_defaultHeight = 22; | |
7b28757f JS |
175 | m_toolPacking = 2; |
176 | m_toolSeparation = 8; | |
177 | m_xMargin = 2; | |
178 | m_yMargin = 2; | |
179 | m_maxRows = 100; | |
180 | m_maxCols = 100; | |
8a0681f9 VZ |
181 | } |
182 | ||
183 | bool wxToolBar::Create(wxWindow *parent, | |
184 | wxWindowID id, | |
185 | const wxPoint& pos, | |
186 | const wxSize& size, | |
187 | long style, | |
188 | const wxString& name) | |
189 | { | |
190 | Init(); | |
191 | ||
192 | m_windowId = id; | |
193 | ||
4bb6408c | 194 | SetName(name); |
0d57be45 JS |
195 | m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE); |
196 | m_foregroundColour = parent->GetForegroundColour(); | |
4bb6408c JS |
197 | m_windowStyle = style; |
198 | ||
199 | SetParent(parent); | |
200 | ||
201 | if (parent) parent->AddChild(this); | |
202 | ||
0d57be45 JS |
203 | Widget parentWidget = (Widget) parent->GetClientWidget(); |
204 | ||
205 | Widget toolbar = XtVaCreateManagedWidget("toolbar", | |
7fe7d506 JS |
206 | xmBulletinBoardWidgetClass, (Widget) parentWidget, |
207 | XmNmarginWidth, 0, | |
208 | XmNmarginHeight, 0, | |
209 | XmNresizePolicy, XmRESIZE_NONE, | |
210 | NULL); | |
211 | /* | |
212 | Widget toolbar = XtVaCreateManagedWidget("toolbar", | |
213 | xmFormWidgetClass, (Widget) m_clientWidget, | |
0d57be45 JS |
214 | XmNtraversalOn, False, |
215 | XmNhorizontalSpacing, 0, | |
216 | XmNverticalSpacing, 0, | |
1a3ac83f JS |
217 | XmNleftOffset, 0, |
218 | XmNrightOffset, 0, | |
219 | XmNmarginWidth, 0, | |
220 | XmNmarginHeight, 0, | |
0d57be45 | 221 | NULL); |
7fe7d506 | 222 | */ |
0d57be45 JS |
223 | |
224 | m_mainWidget = (WXWidget) toolbar; | |
225 | ||
da175b2c | 226 | m_font = parent->GetFont(); |
4b5f3fe6 JS |
227 | ChangeFont(FALSE); |
228 | ||
0d57be45 JS |
229 | SetCanAddEventHandler(TRUE); |
230 | AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); | |
231 | ||
0d57be45 | 232 | ChangeBackgroundColour(); |
bf6c2b35 | 233 | |
0d57be45 | 234 | return TRUE; |
4bb6408c JS |
235 | } |
236 | ||
237 | wxToolBar::~wxToolBar() | |
238 | { | |
1a3ac83f JS |
239 | delete wxTheToolBarTimer; |
240 | wxTheToolBarTimer = NULL; | |
4bb6408c JS |
241 | } |
242 | ||
8a0681f9 | 243 | bool wxToolBar::Realize() |
7fe7d506 | 244 | { |
8a0681f9 VZ |
245 | if ( m_tools.GetCount() == 0 ) |
246 | { | |
247 | // nothing to do | |
248 | return TRUE; | |
249 | } | |
7fe7d506 JS |
250 | |
251 | // Separator spacing | |
252 | const int separatorSize = GetToolSeparation(); // 8; | |
253 | wxSize margins = GetToolMargins(); | |
254 | int marginX = margins.x; | |
255 | int marginY = margins.y; | |
256 | ||
257 | int currentX = marginX; | |
258 | int currentY = marginY; | |
259 | ||
260 | int buttonHeight = 0; | |
261 | ||
262 | int currentSpacing = 0; | |
263 | ||
8a0681f9 VZ |
264 | Widget button; |
265 | Pixmap pixmap, insensPixmap; | |
266 | wxBitmap bmp; | |
267 | ||
268 | wxToolBarToolsList::Node *node = m_tools.GetFirst(); | |
269 | while ( node ) | |
7fe7d506 | 270 | { |
8a0681f9 | 271 | wxToolBarTool *tool = (wxToolBarTool *)node->GetData(); |
7fe7d506 | 272 | |
8a0681f9 | 273 | switch ( tool->GetStyle() ) |
7fe7d506 | 274 | { |
8a0681f9 VZ |
275 | case wxTOOL_STYLE_CONTROL: |
276 | wxFAIL_MSG( _T("not implemented") ); | |
277 | break; | |
7fe7d506 | 278 | |
8a0681f9 VZ |
279 | case wxTOOL_STYLE_SEPARATOR: |
280 | currentX += separatorSize; | |
281 | break; | |
7fe7d506 | 282 | |
8a0681f9 VZ |
283 | case wxTOOL_STYLE_BUTTON: |
284 | button = (Widget) 0; | |
bf6c2b35 | 285 | |
8a0681f9 | 286 | if ( tool->CanBeToggled() ) |
7fe7d506 | 287 | { |
8a0681f9 VZ |
288 | button = XtVaCreateWidget("toggleButton", |
289 | xmToggleButtonWidgetClass, (Widget) m_mainWidget, | |
290 | XmNx, currentX, XmNy, currentY, | |
e838cc14 VZ |
291 | XmNindicatorOn, False, |
292 | XmNshadowThickness, 2, | |
293 | XmNborderWidth, 0, | |
294 | XmNspacing, 0, | |
295 | XmNmarginWidth, 0, | |
296 | XmNmarginHeight, 0, | |
8a0681f9 VZ |
297 | XmNmultiClick, XmMULTICLICK_KEEP, |
298 | XmNlabelType, XmPIXMAP, | |
299 | NULL); | |
300 | XtAddCallback ((Widget) button, XmNvalueChangedCallback, (XtCallbackProc) wxToolButtonCallback, | |
301 | (XtPointer) this); | |
302 | ||
303 | XtVaSetValues ((Widget) button, | |
304 | XmNselectColor, m_backgroundColour.AllocColour(XtDisplay((Widget) button)), | |
305 | NULL); | |
bf6c2b35 | 306 | } |
7fe7d506 | 307 | else |
8a0681f9 VZ |
308 | { |
309 | button = XtVaCreateWidget("button", | |
310 | xmPushButtonWidgetClass, (Widget) m_mainWidget, | |
311 | XmNx, currentX, XmNy, currentY, | |
312 | XmNpushButtonEnabled, True, | |
313 | XmNmultiClick, XmMULTICLICK_KEEP, | |
314 | XmNlabelType, XmPIXMAP, | |
315 | NULL); | |
316 | XtAddCallback (button, | |
317 | XmNactivateCallback, (XtCallbackProc) wxToolButtonCallback, | |
318 | (XtPointer) this); | |
319 | } | |
7fe7d506 | 320 | |
8a0681f9 | 321 | DoChangeBackgroundColour((WXWidget) button, m_backgroundColour, TRUE); |
7fe7d506 | 322 | |
8a0681f9 | 323 | tool->SetWidget(button); |
7fe7d506 | 324 | |
8a0681f9 VZ |
325 | // For each button, if there is a mask, we must create |
326 | // a new wxBitmap that has the correct background colour | |
327 | // for the button. Otherwise the background will just be | |
328 | // e.g. black if a transparent XPM has been loaded. | |
329 | bmp = tool->GetBitmap1(); | |
330 | if ( bmp.GetMask() ) | |
7fe7d506 | 331 | { |
8a0681f9 VZ |
332 | int backgroundPixel; |
333 | XtVaGetValues(button, XmNbackground, &backgroundPixel, | |
334 | NULL); | |
335 | ||
336 | wxColour col; | |
337 | col.SetPixel(backgroundPixel); | |
338 | ||
e838cc14 | 339 | bmp = wxCreateMaskedBitmap(bmp, col); |
8a0681f9 | 340 | |
e838cc14 | 341 | tool->SetBitmap1(bmp); |
7fe7d506 | 342 | } |
8a0681f9 VZ |
343 | |
344 | // Create a selected/toggled bitmap. If there isn't a 2nd | |
345 | // bitmap, we need to create it (with a darker, selected | |
346 | // background) | |
347 | int backgroundPixel; | |
348 | if ( tool->CanBeToggled() ) | |
349 | XtVaGetValues(button, XmNselectColor, &backgroundPixel, | |
350 | NULL); | |
7fe7d506 | 351 | else |
8a0681f9 VZ |
352 | XtVaGetValues(button, XmNarmColor, &backgroundPixel, |
353 | NULL); | |
354 | ||
355 | wxColour col; | |
356 | col.SetPixel(backgroundPixel); | |
357 | ||
358 | if (tool->GetBitmap2().Ok() && tool->GetBitmap2().GetMask()) | |
7fe7d506 | 359 | { |
8a0681f9 VZ |
360 | // Use what's there |
361 | wxBitmap newBitmap = wxCreateMaskedBitmap(tool->GetBitmap2(), col); | |
362 | tool->SetBitmap2(newBitmap); | |
7fe7d506 | 363 | } |
8a0681f9 | 364 | else |
7fe7d506 | 365 | { |
8a0681f9 VZ |
366 | // Use unselected bitmap |
367 | if ( bmp.GetMask() ) | |
368 | { | |
369 | wxBitmap newBitmap = wxCreateMaskedBitmap(bmp, col); | |
370 | tool->SetBitmap2(newBitmap); | |
371 | } | |
372 | else | |
373 | tool->SetBitmap2(bmp); | |
374 | } | |
375 | ||
376 | pixmap = (Pixmap) bmp.GetPixmap(); | |
377 | insensPixmap = (Pixmap) bmp.GetInsensPixmap(); | |
378 | ||
379 | if (tool->CanBeToggled()) | |
380 | { | |
381 | // Toggle button | |
382 | Pixmap pixmap2 = (Pixmap) 0; | |
383 | Pixmap insensPixmap2 = (Pixmap) 0; | |
384 | ||
385 | // If there's a bitmap for the toggled state, use it, | |
386 | // otherwise generate one. | |
387 | if (tool->GetBitmap2().Ok()) | |
388 | { | |
389 | wxBitmap bmp2 = tool->GetBitmap2(); | |
390 | pixmap2 = (Pixmap) bmp2.GetPixmap(); | |
391 | insensPixmap2 = (Pixmap) bmp2.GetInsensPixmap(); | |
392 | } | |
393 | else | |
394 | { | |
395 | pixmap2 = (Pixmap) bmp.GetArmPixmap(button); | |
396 | insensPixmap2 = XCreateInsensitivePixmap((Display*) wxGetDisplay(), pixmap2); | |
397 | } | |
398 | ||
982b2cfc VZ |
399 | tool->SetPixmap(pixmap2); |
400 | ||
8a0681f9 | 401 | XtVaSetValues (button, |
8a0681f9 VZ |
402 | XmNfillOnSelect, True, |
403 | XmNlabelPixmap, pixmap, | |
404 | XmNselectPixmap, pixmap2, | |
405 | XmNlabelInsensitivePixmap, insensPixmap, | |
406 | XmNselectInsensitivePixmap, insensPixmap2, | |
407 | XmNlabelType, XmPIXMAP, | |
408 | NULL); | |
7fe7d506 JS |
409 | } |
410 | else | |
411 | { | |
8a0681f9 VZ |
412 | Pixmap pixmap2 = (Pixmap) 0; |
413 | ||
414 | // If there's a bitmap for the armed state, use it, | |
415 | // otherwise generate one. | |
416 | if (tool->GetBitmap2().Ok()) | |
417 | { | |
418 | pixmap2 = (Pixmap) tool->GetBitmap2().GetPixmap(); | |
419 | } | |
420 | else | |
421 | { | |
422 | pixmap2 = (Pixmap) bmp.GetArmPixmap(button); | |
423 | ||
424 | } | |
982b2cfc VZ |
425 | |
426 | tool->SetPixmap(pixmap2); | |
427 | ||
8a0681f9 VZ |
428 | // Normal button |
429 | XtVaSetValues(button, | |
430 | XmNlabelPixmap, pixmap, | |
431 | XmNlabelInsensitivePixmap, insensPixmap, | |
432 | XmNarmPixmap, pixmap2, | |
433 | NULL); | |
434 | } | |
982b2cfc | 435 | |
8a0681f9 | 436 | XtManageChild(button); |
7fe7d506 | 437 | |
8a0681f9 VZ |
438 | { |
439 | Dimension width, height; | |
440 | XtVaGetValues(button, | |
441 | XmNwidth, &width, | |
442 | XmNheight, & height, | |
443 | NULL); | |
444 | currentX += width + marginX; | |
445 | buttonHeight = wxMax(buttonHeight, height); | |
7fe7d506 | 446 | } |
8a0681f9 VZ |
447 | |
448 | XtAddEventHandler (button, EnterWindowMask | LeaveWindowMask, | |
449 | False, wxToolButtonPopupCallback, (XtPointer) this); | |
450 | ||
451 | currentSpacing = 0; | |
452 | break; | |
7fe7d506 | 453 | } |
8a0681f9 VZ |
454 | |
455 | node = node->GetNext(); | |
7fe7d506 JS |
456 | } |
457 | ||
458 | SetSize(-1, -1, currentX, buttonHeight + 2*marginY); | |
459 | ||
460 | return TRUE; | |
461 | } | |
462 | ||
982b2cfc VZ |
463 | wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x), |
464 | wxCoord WXUNUSED(y)) const | |
4bb6408c | 465 | { |
8a0681f9 | 466 | wxFAIL_MSG( _T("TODO") ); |
4b5f3fe6 | 467 | |
982b2cfc | 468 | return (wxToolBarToolBase *)NULL; |
4bb6408c JS |
469 | } |
470 | ||
982b2cfc | 471 | bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool) |
4bb6408c | 472 | { |
8a0681f9 | 473 | tool->Attach(this); |
4bb6408c | 474 | |
8a0681f9 | 475 | return TRUE; |
4bb6408c JS |
476 | } |
477 | ||
982b2cfc | 478 | bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool) |
4bb6408c | 479 | { |
8a0681f9 | 480 | tool->Detach(); |
0d57be45 | 481 | |
8a0681f9 | 482 | return TRUE; |
4bb6408c JS |
483 | } |
484 | ||
982b2cfc | 485 | void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable) |
1a3ac83f | 486 | { |
982b2cfc VZ |
487 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
488 | ||
8a0681f9 | 489 | XtSetSensitive(tool->GetButtonWidget(), (Boolean) enable); |
1a3ac83f JS |
490 | } |
491 | ||
982b2cfc | 492 | void wxToolBar::DoToggleTool(wxToolBarToolBase *toolBase, bool toggle) |
4bb6408c | 493 | { |
982b2cfc VZ |
494 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
495 | ||
8a0681f9 | 496 | XmToggleButtonSetState(tool->GetButtonWidget(), (Boolean) toggle, False); |
4bb6408c JS |
497 | } |
498 | ||
982b2cfc VZ |
499 | void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool), |
500 | bool WXUNUSED(toggle)) | |
1a3ac83f | 501 | { |
982b2cfc | 502 | // nothing to do |
1a3ac83f JS |
503 | } |
504 | ||
8a0681f9 VZ |
505 | // ---------------------------------------------------------------------------- |
506 | // Motif callbacks | |
507 | // ---------------------------------------------------------------------------- | |
1a3ac83f | 508 | |
982b2cfc | 509 | wxToolBarToolBase *wxToolBar::FindToolByWidget(WXWidget w) const |
7fe7d506 | 510 | { |
8a0681f9 VZ |
511 | wxToolBarToolsList::Node* node = m_tools.GetFirst(); |
512 | while ( node ) | |
513 | { | |
514 | wxToolBarTool *tool = (wxToolBarTool *)node->GetData(); | |
515 | if ( tool->GetButtonWidget() == w) | |
516 | { | |
517 | return tool; | |
518 | } | |
7fe7d506 | 519 | |
8a0681f9 VZ |
520 | node = node->GetNext(); |
521 | } | |
7fe7d506 | 522 | |
982b2cfc | 523 | return (wxToolBarToolBase *)NULL; |
7fe7d506 JS |
524 | } |
525 | ||
8a0681f9 VZ |
526 | static void wxToolButtonCallback(Widget w, |
527 | XtPointer clientData, | |
528 | XtPointer WXUNUSED(ptr)) | |
1a3ac83f JS |
529 | { |
530 | wxToolBar *toolBar = (wxToolBar *) clientData; | |
982b2cfc | 531 | wxToolBarToolBase *tool = toolBar->FindToolByWidget((WXWidget) w); |
8a0681f9 VZ |
532 | if ( !tool ) |
533 | return; | |
1a3ac83f | 534 | |
8a0681f9 VZ |
535 | if ( tool->CanBeToggled() ) |
536 | tool->Toggle(); | |
537 | ||
538 | if ( !toolBar->OnLeftClick(tool->GetId(), tool->IsToggled()) ) | |
1a3ac83f | 539 | { |
8a0681f9 VZ |
540 | // revert |
541 | tool->Toggle(); | |
1a3ac83f | 542 | } |
1a3ac83f JS |
543 | } |
544 | ||
1a3ac83f | 545 | |
8a0681f9 VZ |
546 | static void wxToolButtonPopupCallback(Widget w, |
547 | XtPointer client_data, | |
548 | XEvent *event, | |
549 | Boolean *WXUNUSED(continue_to_dispatch)) | |
1a3ac83f JS |
550 | { |
551 | // TODO: retrieve delay before popping up tooltip from wxSystemSettings. | |
8a0681f9 | 552 | static const int delayMilli = 800; |
1a3ac83f | 553 | |
8a0681f9 | 554 | wxToolBar* toolBar = (wxToolBar*) client_data; |
982b2cfc | 555 | wxToolBarToolBase *tool = toolBar->FindToolByWidget((WXWidget) w); |
1a3ac83f | 556 | |
8a0681f9 VZ |
557 | if ( !tool ) |
558 | return; | |
1a3ac83f | 559 | |
8a0681f9 VZ |
560 | wxString tooltip = tool->GetShortHelp(); |
561 | if ( !tooltip ) | |
562 | return; | |
1a3ac83f | 563 | |
8a0681f9 VZ |
564 | if (!wxTheToolBarTimer) |
565 | wxTheToolBarTimer = new wxToolBarTimer; | |
1a3ac83f | 566 | |
8a0681f9 VZ |
567 | wxToolBarTimer::buttonWidget = w; |
568 | wxToolBarTimer::helpString = tooltip; | |
1a3ac83f JS |
569 | |
570 | /************************************************************/ | |
571 | /* Popup help label */ | |
572 | /************************************************************/ | |
573 | if (event->type == EnterNotify) | |
574 | { | |
575 | if (wxToolBarTimer::help_popup != (Widget) 0) | |
576 | { | |
577 | XtDestroyWidget (wxToolBarTimer::help_popup); | |
578 | XtPopdown (wxToolBarTimer::help_popup); | |
bf6c2b35 | 579 | } |
1a3ac83f JS |
580 | wxToolBarTimer::help_popup = (Widget) 0; |
581 | ||
582 | // One shot | |
583 | wxTheToolBarTimer->Start(delayMilli, TRUE); | |
584 | ||
585 | } | |
586 | /************************************************************/ | |
587 | /* Popdown help label */ | |
588 | /************************************************************/ | |
589 | else if (event->type == LeaveNotify) | |
590 | { | |
591 | if (wxTheToolBarTimer) | |
592 | wxTheToolBarTimer->Stop(); | |
593 | if (wxToolBarTimer::help_popup != (Widget) 0) | |
594 | { | |
595 | XtDestroyWidget (wxToolBarTimer::help_popup); | |
596 | XtPopdown (wxToolBarTimer::help_popup); | |
bf6c2b35 | 597 | } |
1a3ac83f JS |
598 | wxToolBarTimer::help_popup = (Widget) 0; |
599 | } | |
1a3ac83f JS |
600 | } |
601 | ||
602 | void wxToolBarTimer::Notify() | |
603 | { | |
604 | Position x, y; | |
605 | ||
606 | /************************************************************/ | |
607 | /* Create shell without window decorations */ | |
608 | /************************************************************/ | |
bf6c2b35 VZ |
609 | help_popup = XtVaCreatePopupShell ("shell", |
610 | overrideShellWidgetClass, (Widget) wxTheApp->GetTopLevelWidget(), | |
1a3ac83f JS |
611 | NULL); |
612 | ||
613 | /************************************************************/ | |
614 | /* Get absolute position on display of toolbar button */ | |
615 | /************************************************************/ | |
616 | XtTranslateCoords (buttonWidget, | |
bf6c2b35 VZ |
617 | (Position) 0, |
618 | (Position) 0, | |
1a3ac83f JS |
619 | &x, &y); |
620 | ||
621 | // Move the tooltip more or less above the button | |
622 | int yOffset = 20; // TODO: What should be really? | |
623 | y -= yOffset; | |
624 | if (y < yOffset) y = 0; | |
625 | ||
626 | /************************************************************/ | |
627 | /* Set the position of the help popup */ | |
628 | /************************************************************/ | |
bf6c2b35 VZ |
629 | XtVaSetValues (help_popup, |
630 | XmNx, (Position) x, | |
631 | XmNy, (Position) y, | |
1a3ac83f | 632 | NULL); |
bf6c2b35 | 633 | |
1a3ac83f JS |
634 | /************************************************************/ |
635 | /* Create help label */ | |
636 | /************************************************************/ | |
637 | XmString text = XmStringCreateSimple ((char*) (const char*) helpString); | |
bf6c2b35 VZ |
638 | XtVaCreateManagedWidget ("help_label", |
639 | xmLabelWidgetClass, help_popup, | |
1a3ac83f | 640 | XmNlabelString, text, |
bf6c2b35 VZ |
641 | XtVaTypedArg, |
642 | XmNforeground, XtRString, "black", | |
643 | strlen("black")+1, | |
644 | XtVaTypedArg, | |
645 | XmNbackground, XtRString, "LightGoldenrod", | |
646 | strlen("LightGoldenrod")+1, | |
1a3ac83f JS |
647 | NULL); |
648 | XmStringFree (text); | |
649 | ||
650 | /************************************************************/ | |
651 | /* Popup help label */ | |
652 | /************************************************************/ | |
653 | XtPopup (help_popup, XtGrabNone); | |
654 | } | |
655 |