]> git.saurik.com Git - wxWidgets.git/blame - src/motif/toolbar.cpp
compilation fixes for wxUniv (moved wxDlgProc back to toplevel.cpp)
[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();
66f55ec6 288 control->Move(currentX, pos.y);
f3979fcc 289 currentX += sz.x + packing;
66f55ec6 290
8a0681f9 291 break;
f3979fcc 292 }
8a0681f9
VZ
293 case wxTOOL_STYLE_SEPARATOR:
294 currentX += separatorSize;
295 break;
7fe7d506 296
8a0681f9
VZ
297 case wxTOOL_STYLE_BUTTON:
298 button = (Widget) 0;
bf6c2b35 299
8a0681f9 300 if ( tool->CanBeToggled() )
7fe7d506 301 {
8a0681f9
VZ
302 button = XtVaCreateWidget("toggleButton",
303 xmToggleButtonWidgetClass, (Widget) m_mainWidget,
304 XmNx, currentX, XmNy, currentY,
e838cc14
VZ
305 XmNindicatorOn, False,
306 XmNshadowThickness, 2,
307 XmNborderWidth, 0,
308 XmNspacing, 0,
309 XmNmarginWidth, 0,
310 XmNmarginHeight, 0,
8a0681f9
VZ
311 XmNmultiClick, XmMULTICLICK_KEEP,
312 XmNlabelType, XmPIXMAP,
313 NULL);
314 XtAddCallback ((Widget) button, XmNvalueChangedCallback, (XtCallbackProc) wxToolButtonCallback,
315 (XtPointer) this);
316
317 XtVaSetValues ((Widget) button,
318 XmNselectColor, m_backgroundColour.AllocColour(XtDisplay((Widget) button)),
319 NULL);
bf6c2b35 320 }
7fe7d506 321 else
8a0681f9
VZ
322 {
323 button = XtVaCreateWidget("button",
324 xmPushButtonWidgetClass, (Widget) m_mainWidget,
325 XmNx, currentX, XmNy, currentY,
326 XmNpushButtonEnabled, True,
327 XmNmultiClick, XmMULTICLICK_KEEP,
328 XmNlabelType, XmPIXMAP,
329 NULL);
330 XtAddCallback (button,
331 XmNactivateCallback, (XtCallbackProc) wxToolButtonCallback,
332 (XtPointer) this);
333 }
7fe7d506 334
8a0681f9 335 DoChangeBackgroundColour((WXWidget) button, m_backgroundColour, TRUE);
7fe7d506 336
8a0681f9 337 tool->SetWidget(button);
7fe7d506 338
8a0681f9
VZ
339 // For each button, if there is a mask, we must create
340 // a new wxBitmap that has the correct background colour
341 // for the button. Otherwise the background will just be
342 // e.g. black if a transparent XPM has been loaded.
fcb35b5f 343 bmp = tool->GetNormalBitmap();
8a0681f9 344 if ( bmp.GetMask() )
7fe7d506 345 {
8a0681f9
VZ
346 int backgroundPixel;
347 XtVaGetValues(button, XmNbackground, &backgroundPixel,
348 NULL);
349
350 wxColour col;
351 col.SetPixel(backgroundPixel);
352
e838cc14 353 bmp = wxCreateMaskedBitmap(bmp, col);
8a0681f9 354
fcb35b5f 355 tool->SetNormalBitmap(bmp);
7fe7d506 356 }
8a0681f9
VZ
357
358 // Create a selected/toggled bitmap. If there isn't a 2nd
359 // bitmap, we need to create it (with a darker, selected
360 // background)
361 int backgroundPixel;
362 if ( tool->CanBeToggled() )
363 XtVaGetValues(button, XmNselectColor, &backgroundPixel,
364 NULL);
7fe7d506 365 else
8a0681f9
VZ
366 XtVaGetValues(button, XmNarmColor, &backgroundPixel,
367 NULL);
368
369 wxColour col;
370 col.SetPixel(backgroundPixel);
371
fcb35b5f
VZ
372 // FIXME: we use disabled bitmap as the bitmap for the toggled
373 // state, we probably need a GetToggledBitmap() instead
374 wxBitmap bmpToggled = tool->GetDisabledBitmap();
375 if ( bmpToggled.Ok() && bmpToggled.GetMask())
7fe7d506 376 {
8a0681f9 377 // Use what's there
fcb35b5f
VZ
378 wxBitmap newBitmap = wxCreateMaskedBitmap(bmpToggled, col);
379 tool->SetDisabledBitmap(newBitmap);
7fe7d506 380 }
8a0681f9 381 else
7fe7d506 382 {
8a0681f9
VZ
383 // Use unselected bitmap
384 if ( bmp.GetMask() )
385 {
386 wxBitmap newBitmap = wxCreateMaskedBitmap(bmp, col);
fcb35b5f 387 tool->SetDisabledBitmap(newBitmap);
8a0681f9
VZ
388 }
389 else
fcb35b5f 390 tool->SetDisabledBitmap(bmp);
8a0681f9
VZ
391 }
392
fcb35b5f 393 // FIXME: and here we should use GetDisabledBitmap()...
8a0681f9
VZ
394 pixmap = (Pixmap) bmp.GetPixmap();
395 insensPixmap = (Pixmap) bmp.GetInsensPixmap();
396
397 if (tool->CanBeToggled())
398 {
399 // Toggle button
400 Pixmap pixmap2 = (Pixmap) 0;
401 Pixmap insensPixmap2 = (Pixmap) 0;
402
403 // If there's a bitmap for the toggled state, use it,
404 // otherwise generate one.
fcb35b5f
VZ
405 //
406 // FIXME: see above
407 if ( bmpToggled.Ok() )
8a0681f9 408 {
fcb35b5f
VZ
409 pixmap2 = (Pixmap) bmpToggled.GetPixmap();
410 insensPixmap2 = (Pixmap) bmpToggled.GetInsensPixmap();
8a0681f9
VZ
411 }
412 else
413 {
414 pixmap2 = (Pixmap) bmp.GetArmPixmap(button);
415 insensPixmap2 = XCreateInsensitivePixmap((Display*) wxGetDisplay(), pixmap2);
416 }
417
982b2cfc
VZ
418 tool->SetPixmap(pixmap2);
419
8a0681f9 420 XtVaSetValues (button,
8a0681f9
VZ
421 XmNfillOnSelect, True,
422 XmNlabelPixmap, pixmap,
423 XmNselectPixmap, pixmap2,
424 XmNlabelInsensitivePixmap, insensPixmap,
425 XmNselectInsensitivePixmap, insensPixmap2,
426 XmNlabelType, XmPIXMAP,
427 NULL);
7fe7d506
JS
428 }
429 else
430 {
8a0681f9
VZ
431 Pixmap pixmap2 = (Pixmap) 0;
432
433 // If there's a bitmap for the armed state, use it,
434 // otherwise generate one.
fcb35b5f 435 if ( bmpToggled.Ok() )
8a0681f9 436 {
fcb35b5f 437 pixmap2 = (Pixmap) bmpToggled.GetPixmap();
8a0681f9
VZ
438 }
439 else
440 {
441 pixmap2 = (Pixmap) bmp.GetArmPixmap(button);
442
443 }
982b2cfc
VZ
444
445 tool->SetPixmap(pixmap2);
446
8a0681f9
VZ
447 // Normal button
448 XtVaSetValues(button,
449 XmNlabelPixmap, pixmap,
450 XmNlabelInsensitivePixmap, insensPixmap,
451 XmNarmPixmap, pixmap2,
452 NULL);
453 }
982b2cfc 454
8a0681f9 455 XtManageChild(button);
7fe7d506 456
8a0681f9
VZ
457 {
458 Dimension width, height;
459 XtVaGetValues(button,
460 XmNwidth, &width,
461 XmNheight, & height,
462 NULL);
f3979fcc 463 currentX += width + packing;
8a0681f9 464 buttonHeight = wxMax(buttonHeight, height);
7fe7d506 465 }
8a0681f9
VZ
466
467 XtAddEventHandler (button, EnterWindowMask | LeaveWindowMask,
468 False, wxToolButtonPopupCallback, (XtPointer) this);
469
470 currentSpacing = 0;
471 break;
7fe7d506 472 }
8a0681f9
VZ
473
474 node = node->GetNext();
7fe7d506
JS
475 }
476
477 SetSize(-1, -1, currentX, buttonHeight + 2*marginY);
478
479 return TRUE;
480}
481
982b2cfc
VZ
482wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x),
483 wxCoord WXUNUSED(y)) const
4bb6408c 484{
8a0681f9 485 wxFAIL_MSG( _T("TODO") );
4b5f3fe6 486
982b2cfc 487 return (wxToolBarToolBase *)NULL;
4bb6408c
JS
488}
489
982b2cfc 490bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool)
4bb6408c 491{
8a0681f9 492 tool->Attach(this);
4bb6408c 493
8a0681f9 494 return TRUE;
4bb6408c
JS
495}
496
982b2cfc 497bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool)
4bb6408c 498{
8a0681f9 499 tool->Detach();
0d57be45 500
8a0681f9 501 return TRUE;
4bb6408c
JS
502}
503
982b2cfc 504void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable)
1a3ac83f 505{
982b2cfc
VZ
506 wxToolBarTool *tool = (wxToolBarTool *)toolBase;
507
8a0681f9 508 XtSetSensitive(tool->GetButtonWidget(), (Boolean) enable);
1a3ac83f
JS
509}
510
982b2cfc 511void wxToolBar::DoToggleTool(wxToolBarToolBase *toolBase, bool toggle)
4bb6408c 512{
982b2cfc
VZ
513 wxToolBarTool *tool = (wxToolBarTool *)toolBase;
514
8a0681f9 515 XmToggleButtonSetState(tool->GetButtonWidget(), (Boolean) toggle, False);
4bb6408c
JS
516}
517
982b2cfc
VZ
518void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool),
519 bool WXUNUSED(toggle))
1a3ac83f 520{
982b2cfc 521 // nothing to do
1a3ac83f
JS
522}
523
8a0681f9
VZ
524// ----------------------------------------------------------------------------
525// Motif callbacks
526// ----------------------------------------------------------------------------
1a3ac83f 527
982b2cfc 528wxToolBarToolBase *wxToolBar::FindToolByWidget(WXWidget w) const
7fe7d506 529{
8a0681f9
VZ
530 wxToolBarToolsList::Node* node = m_tools.GetFirst();
531 while ( node )
532 {
533 wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
534 if ( tool->GetButtonWidget() == w)
535 {
536 return tool;
537 }
7fe7d506 538
8a0681f9
VZ
539 node = node->GetNext();
540 }
7fe7d506 541
982b2cfc 542 return (wxToolBarToolBase *)NULL;
7fe7d506
JS
543}
544
8a0681f9
VZ
545static void wxToolButtonCallback(Widget w,
546 XtPointer clientData,
547 XtPointer WXUNUSED(ptr))
1a3ac83f
JS
548{
549 wxToolBar *toolBar = (wxToolBar *) clientData;
982b2cfc 550 wxToolBarToolBase *tool = toolBar->FindToolByWidget((WXWidget) w);
8a0681f9
VZ
551 if ( !tool )
552 return;
1a3ac83f 553
8a0681f9
VZ
554 if ( tool->CanBeToggled() )
555 tool->Toggle();
556
557 if ( !toolBar->OnLeftClick(tool->GetId(), tool->IsToggled()) )
1a3ac83f 558 {
8a0681f9
VZ
559 // revert
560 tool->Toggle();
1a3ac83f 561 }
1a3ac83f
JS
562}
563
1a3ac83f 564
8a0681f9
VZ
565static void wxToolButtonPopupCallback(Widget w,
566 XtPointer client_data,
567 XEvent *event,
568 Boolean *WXUNUSED(continue_to_dispatch))
1a3ac83f
JS
569{
570 // TODO: retrieve delay before popping up tooltip from wxSystemSettings.
8a0681f9 571 static const int delayMilli = 800;
1a3ac83f 572
8a0681f9 573 wxToolBar* toolBar = (wxToolBar*) client_data;
982b2cfc 574 wxToolBarToolBase *tool = toolBar->FindToolByWidget((WXWidget) w);
1a3ac83f 575
8a0681f9
VZ
576 if ( !tool )
577 return;
1a3ac83f 578
8a0681f9
VZ
579 wxString tooltip = tool->GetShortHelp();
580 if ( !tooltip )
581 return;
1a3ac83f 582
8a0681f9
VZ
583 if (!wxTheToolBarTimer)
584 wxTheToolBarTimer = new wxToolBarTimer;
1a3ac83f 585
8a0681f9
VZ
586 wxToolBarTimer::buttonWidget = w;
587 wxToolBarTimer::helpString = tooltip;
1a3ac83f
JS
588
589 /************************************************************/
590 /* Popup help label */
591 /************************************************************/
592 if (event->type == EnterNotify)
593 {
594 if (wxToolBarTimer::help_popup != (Widget) 0)
595 {
596 XtDestroyWidget (wxToolBarTimer::help_popup);
597 XtPopdown (wxToolBarTimer::help_popup);
bf6c2b35 598 }
1a3ac83f
JS
599 wxToolBarTimer::help_popup = (Widget) 0;
600
601 // One shot
602 wxTheToolBarTimer->Start(delayMilli, TRUE);
603
604 }
605 /************************************************************/
606 /* Popdown help label */
607 /************************************************************/
608 else if (event->type == LeaveNotify)
609 {
610 if (wxTheToolBarTimer)
611 wxTheToolBarTimer->Stop();
612 if (wxToolBarTimer::help_popup != (Widget) 0)
613 {
614 XtDestroyWidget (wxToolBarTimer::help_popup);
615 XtPopdown (wxToolBarTimer::help_popup);
bf6c2b35 616 }
1a3ac83f
JS
617 wxToolBarTimer::help_popup = (Widget) 0;
618 }
1a3ac83f
JS
619}
620
621void wxToolBarTimer::Notify()
622{
623 Position x, y;
624
625 /************************************************************/
626 /* Create shell without window decorations */
627 /************************************************************/
bf6c2b35
VZ
628 help_popup = XtVaCreatePopupShell ("shell",
629 overrideShellWidgetClass, (Widget) wxTheApp->GetTopLevelWidget(),
1a3ac83f
JS
630 NULL);
631
632 /************************************************************/
633 /* Get absolute position on display of toolbar button */
634 /************************************************************/
635 XtTranslateCoords (buttonWidget,
bf6c2b35
VZ
636 (Position) 0,
637 (Position) 0,
1a3ac83f
JS
638 &x, &y);
639
640 // Move the tooltip more or less above the button
641 int yOffset = 20; // TODO: What should be really?
642 y -= yOffset;
643 if (y < yOffset) y = 0;
644
645 /************************************************************/
646 /* Set the position of the help popup */
647 /************************************************************/
bf6c2b35
VZ
648 XtVaSetValues (help_popup,
649 XmNx, (Position) x,
650 XmNy, (Position) y,
1a3ac83f 651 NULL);
bf6c2b35 652
1a3ac83f
JS
653 /************************************************************/
654 /* Create help label */
655 /************************************************************/
656 XmString text = XmStringCreateSimple ((char*) (const char*) helpString);
bf6c2b35
VZ
657 XtVaCreateManagedWidget ("help_label",
658 xmLabelWidgetClass, help_popup,
1a3ac83f 659 XmNlabelString, text,
bf6c2b35
VZ
660 XtVaTypedArg,
661 XmNforeground, XtRString, "black",
662 strlen("black")+1,
663 XtVaTypedArg,
664 XmNbackground, XtRString, "LightGoldenrod",
665 strlen("LightGoldenrod")+1,
1a3ac83f
JS
666 NULL);
667 XmStringFree (text);
668
669 /************************************************************/
670 /* Popup help label */
671 /************************************************************/
672 XtPopup (help_popup, XtGrabNone);
673}
674