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