]> git.saurik.com Git - wxWidgets.git/blame - src/motif/toolbar.cpp
Add missing WXK constants for the control keys
[wxWidgets.git] / src / motif / toolbar.cpp
CommitLineData
4bb6408c 1/////////////////////////////////////////////////////////////////////////////
355b4d3d 2// Name: src/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
65571936 9// Licence: wxWindows licence
4bb6408c
JS
10/////////////////////////////////////////////////////////////////////////////
11
8a0681f9
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
1248b41f
MB
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
670f9935
WS
23#include "wx/toolbar.h"
24
25#ifndef WX_PRECOMP
26 #include "wx/app.h"
76b49cf4 27 #include "wx/frame.h"
c0badb70 28 #include "wx/timer.h"
9eddec69 29 #include "wx/settings.h"
670f9935
WS
30#endif
31
338dd992
JJ
32#ifdef __VMS__
33#pragma message disable nosimpint
34#endif
0d57be45
JS
35#include <Xm/Xm.h>
36#include <Xm/PushBG.h>
37#include <Xm/PushB.h>
1a3ac83f 38#include <Xm/Label.h>
0d57be45
JS
39#include <Xm/ToggleB.h>
40#include <Xm/ToggleBG.h>
41#include <Xm/Form.h>
338dd992
JJ
42#ifdef __VMS__
43#pragma message enable nosimpint
44#endif
0d57be45
JS
45
46#include "wx/motif/private.h"
aae91497 47#include "wx/motif/bmpmotif.h"
4bb6408c 48
8a0681f9
VZ
49// ----------------------------------------------------------------------------
50// wxWin macros
51// ----------------------------------------------------------------------------
52
2eb10e2a 53IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
4bb6408c 54
8a0681f9
VZ
55// ----------------------------------------------------------------------------
56// private functions
57// ----------------------------------------------------------------------------
4bb6408c 58
1a3ac83f 59static void wxToolButtonCallback (Widget w, XtPointer clientData,
bf6c2b35 60 XtPointer ptr);
1a3ac83f
JS
61static void wxToolButtonPopupCallback (Widget w, XtPointer client_data,
62 XEvent *event, Boolean *continue_to_dispatch);
63
8a0681f9
VZ
64// ----------------------------------------------------------------------------
65// private classes
66// ----------------------------------------------------------------------------
67
68class wxToolBarTimer : public wxTimer
1a3ac83f
JS
69{
70public:
8a0681f9 71 virtual void Notify();
1a3ac83f 72
8a0681f9
VZ
73 static Widget help_popup;
74 static Widget buttonWidget;
75 static wxString helpString;
1a3ac83f
JS
76};
77
8a0681f9
VZ
78class wxToolBarTool : public wxToolBarToolBase
79{
80public:
81 wxToolBarTool(wxToolBar *tbar,
82 int id,
fcb35b5f
VZ
83 const wxString& label,
84 const wxBitmap& bmpNormal,
85 const wxBitmap& bmpToggled,
86 wxItemKind kind,
8a0681f9 87 wxObject *clientData,
fcb35b5f
VZ
88 const wxString& shortHelp,
89 const wxString& longHelp)
90 : wxToolBarToolBase(tbar, id, label, bmpNormal, bmpToggled, kind,
91 clientData, shortHelp, longHelp)
8a0681f9
VZ
92 {
93 Init();
94 }
95
07d02e9e
VZ
96 wxToolBarTool(wxToolBar *tbar, wxControl *control, const wxString& label)
97 : wxToolBarToolBase(tbar, control, label)
8a0681f9
VZ
98 {
99 Init();
100 }
101
102 virtual ~wxToolBarTool();
103
104 // accessors
105 void SetWidget(Widget widget) { m_widget = widget; }
106 Widget GetButtonWidget() const { return m_widget; }
107
aae91497
MB
108 Pixmap GetArmPixmap()
109 {
110 m_bitmapCache.SetBitmap( GetNormalBitmap() );
111 return (Pixmap)m_bitmapCache.GetArmPixmap( (WXWidget)m_widget );
112 }
8a0681f9 113
aae91497
MB
114 Pixmap GetInsensPixmap()
115 {
116 m_bitmapCache.SetBitmap( GetNormalBitmap() );
117 return (Pixmap)m_bitmapCache.GetInsensPixmap( (WXWidget)m_widget );
118 }
8a0681f9
VZ
119protected:
120 void Init();
121
122 Widget m_widget;
aae91497 123 wxBitmapCache m_bitmapCache;
8a0681f9
VZ
124};
125
126// ----------------------------------------------------------------------------
127// globals
128// ----------------------------------------------------------------------------
129
d3b9f782 130static wxToolBarTimer* wxTheToolBarTimer = NULL;
1a3ac83f
JS
131
132Widget wxToolBarTimer::help_popup = (Widget) 0;
133Widget wxToolBarTimer::buttonWidget = (Widget) 0;
8a0681f9
VZ
134wxString wxToolBarTimer::helpString;
135
136// ============================================================================
137// implementation
138// ============================================================================
139
140// ----------------------------------------------------------------------------
141// wxToolBarTool
142// ----------------------------------------------------------------------------
143
982b2cfc 144wxToolBarToolBase *wxToolBar::CreateTool(int id,
fcb35b5f
VZ
145 const wxString& label,
146 const wxBitmap& bmpNormal,
147 const wxBitmap& bmpToggled,
148 wxItemKind kind,
982b2cfc 149 wxObject *clientData,
fcb35b5f
VZ
150 const wxString& shortHelp,
151 const wxString& longHelp)
8a0681f9 152{
fcb35b5f
VZ
153 return new wxToolBarTool(this, id, label, bmpNormal, bmpToggled, kind,
154 clientData, shortHelp, longHelp);
8a0681f9 155}
1a3ac83f 156
fcb35b5f 157
07d02e9e
VZ
158wxToolBarToolBase *
159wxToolBar::CreateTool(wxControl *control, const wxString& label)
4bb6408c 160{
07d02e9e 161 return new wxToolBarTool(this, control, label);
4bb6408c
JS
162}
163
8a0681f9
VZ
164void wxToolBarTool::Init()
165{
166 m_widget = (Widget)0;
8a0681f9
VZ
167}
168
169wxToolBarTool::~wxToolBarTool()
170{
982b2cfc
VZ
171 if ( m_widget )
172 XtDestroyWidget(m_widget);
8a0681f9
VZ
173}
174
175// ----------------------------------------------------------------------------
176// wxToolBar construction
177// ----------------------------------------------------------------------------
178
179void wxToolBar::Init()
4bb6408c
JS
180{
181 m_maxWidth = -1;
182 m_maxHeight = -1;
4bb6408c
JS
183 m_defaultWidth = 24;
184 m_defaultHeight = 22;
7b28757f
JS
185 m_toolPacking = 2;
186 m_toolSeparation = 8;
187 m_xMargin = 2;
188 m_yMargin = 2;
189 m_maxRows = 100;
190 m_maxCols = 100;
8a0681f9
VZ
191}
192
193bool wxToolBar::Create(wxWindow *parent,
194 wxWindowID id,
195 const wxPoint& pos,
196 const wxSize& size,
197 long style,
198 const wxString& name)
199{
46675b46
MB
200 if( !wxControl::CreateControl( parent, id, pos, size, style,
201 wxDefaultValidator, name ) )
96be256b 202 return false;
105fbe1f 203 PreCreation();
8a0681f9 204
d408730c
VZ
205 FixupStyle();
206
0d57be45
JS
207 Widget parentWidget = (Widget) parent->GetClientWidget();
208
209 Widget toolbar = XtVaCreateManagedWidget("toolbar",
7fe7d506
JS
210 xmBulletinBoardWidgetClass, (Widget) parentWidget,
211 XmNmarginWidth, 0,
212 XmNmarginHeight, 0,
213 XmNresizePolicy, XmRESIZE_NONE,
214 NULL);
215/*
216 Widget toolbar = XtVaCreateManagedWidget("toolbar",
217 xmFormWidgetClass, (Widget) m_clientWidget,
0d57be45
JS
218 XmNtraversalOn, False,
219 XmNhorizontalSpacing, 0,
220 XmNverticalSpacing, 0,
1a3ac83f
JS
221 XmNleftOffset, 0,
222 XmNrightOffset, 0,
223 XmNmarginWidth, 0,
224 XmNmarginHeight, 0,
0d57be45 225 NULL);
7fe7d506 226*/
0d57be45
JS
227
228 m_mainWidget = (WXWidget) toolbar;
229
46675b46
MB
230 wxPoint rPos = pos;
231 wxSize rSize = size;
232
233 if( rPos.x == -1 ) rPos.x = 0;
234 if( rPos.y == -1 ) rPos.y = 0;
235 if( rSize.x == -1 && GetParent() )
236 rSize.x = GetParent()->GetSize().x;
237
105fbe1f 238 PostCreation();
46675b46
MB
239 AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
240 rPos.x, rPos.y, rSize.x, rSize.y);
0d57be45 241
96be256b 242 return true;
4bb6408c
JS
243}
244
245wxToolBar::~wxToolBar()
246{
5276b0a5 247 wxDELETE(wxTheToolBarTimer);
4bb6408c
JS
248}
249
8a0681f9 250bool wxToolBar::Realize()
7fe7d506 251{
8a0681f9
VZ
252 if ( m_tools.GetCount() == 0 )
253 {
254 // nothing to do
96be256b 255 return true;
8a0681f9 256 }
7fe7d506 257
46675b46
MB
258 bool isVertical = GetWindowStyle() & wxTB_VERTICAL;
259
7fe7d506
JS
260 // Separator spacing
261 const int separatorSize = GetToolSeparation(); // 8;
262 wxSize margins = GetToolMargins();
f3979fcc 263 int packing = GetToolPacking();
7fe7d506
JS
264 int marginX = margins.x;
265 int marginY = margins.y;
266
267 int currentX = marginX;
268 int currentY = marginY;
269
46675b46 270 int buttonHeight = 0, buttonWidth = 0;
7fe7d506 271
8a0681f9
VZ
272 Widget button;
273 Pixmap pixmap, insensPixmap;
aae91497 274 wxBitmap bmp, insensBmp;
8a0681f9 275
ac32ba44 276 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
8a0681f9 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();
46675b46
MB
288 // Allow a control to specify a y[x]-offset by setting
289 // its initial position, but still don't allow it to
290 // position itself above the top[left] margin.
aae91497
MB
291 int controlY = (pos.y > 0) ? pos.y : currentY;
292 int controlX = (pos.x > 0) ? pos.x : currentX;
46675b46
MB
293 control->Move( isVertical ? controlX : currentX,
294 isVertical ? currentY : controlY );
295 if ( isVertical )
296 currentY += sz.y + packing;
297 else
298 currentX += sz.x + packing;
66f55ec6 299
8a0681f9 300 break;
f3979fcc 301 }
8a0681f9 302 case wxTOOL_STYLE_SEPARATOR:
aae91497
MB
303 // skip separators for vertical toolbars
304 if( !isVertical )
305 {
306 currentX += separatorSize;
307 }
8a0681f9 308 break;
7fe7d506 309
8a0681f9
VZ
310 case wxTOOL_STYLE_BUTTON:
311 button = (Widget) 0;
bf6c2b35 312
aae91497 313 if ( tool->CanBeToggled() && !tool->GetButtonWidget() )
7fe7d506 314 {
8a0681f9
VZ
315 button = XtVaCreateWidget("toggleButton",
316 xmToggleButtonWidgetClass, (Widget) m_mainWidget,
317 XmNx, currentX, XmNy, currentY,
e838cc14
VZ
318 XmNindicatorOn, False,
319 XmNshadowThickness, 2,
320 XmNborderWidth, 0,
321 XmNspacing, 0,
322 XmNmarginWidth, 0,
323 XmNmarginHeight, 0,
8a0681f9
VZ
324 XmNmultiClick, XmMULTICLICK_KEEP,
325 XmNlabelType, XmPIXMAP,
326 NULL);
aae91497
MB
327 XtAddCallback ((Widget) button,
328 XmNvalueChangedCallback,
329 (XtCallbackProc) wxToolButtonCallback,
330 (XtPointer) this);
8a0681f9
VZ
331
332 XtVaSetValues ((Widget) button,
aae91497
MB
333 XmNselectColor,
334 m_backgroundColour.AllocColour
335 (XtDisplay((Widget) button)),
336 NULL);
bf6c2b35 337 }
aae91497 338 else if( !tool->GetButtonWidget() )
8a0681f9
VZ
339 {
340 button = XtVaCreateWidget("button",
341 xmPushButtonWidgetClass, (Widget) m_mainWidget,
342 XmNx, currentX, XmNy, currentY,
343 XmNpushButtonEnabled, True,
344 XmNmultiClick, XmMULTICLICK_KEEP,
345 XmNlabelType, XmPIXMAP,
346 NULL);
347 XtAddCallback (button,
aae91497
MB
348 XmNactivateCallback,
349 (XtCallbackProc) wxToolButtonCallback,
350 (XtPointer) this);
8a0681f9 351 }
7fe7d506 352
aae91497
MB
353 if( !tool->GetButtonWidget() )
354 {
a8680e3e 355 wxDoChangeBackgroundColour((WXWidget) button,
96be256b 356 m_backgroundColour, true);
7fe7d506 357
aae91497
MB
358 tool->SetWidget(button);
359 }
360 else
361 {
362 button = (Widget)tool->GetButtonWidget();
363 XtVaSetValues( button,
364 XmNx, currentX, XmNy, currentY,
365 NULL );
366 }
7fe7d506 367
8a0681f9
VZ
368 // For each button, if there is a mask, we must create
369 // a new wxBitmap that has the correct background colour
370 // for the button. Otherwise the background will just be
371 // e.g. black if a transparent XPM has been loaded.
fcb35b5f 372 bmp = tool->GetNormalBitmap();
aae91497
MB
373 insensBmp = tool->GetDisabledBitmap();
374 if ( bmp.GetMask() || insensBmp.GetMask() )
7fe7d506 375 {
3e0071d9 376 WXPixel backgroundPixel;
8a0681f9 377 XtVaGetValues(button, XmNbackground, &backgroundPixel,
aae91497 378 NULL);
8a0681f9
VZ
379
380 wxColour col;
381 col.SetPixel(backgroundPixel);
8a0681f9 382
a1b806b9 383 if( bmp.IsOk() && bmp.GetMask() )
aae91497
MB
384 {
385 bmp = wxCreateMaskedBitmap(bmp, col);
386 tool->SetNormalBitmap(bmp);
387 }
388
a1b806b9 389 if( insensBmp.IsOk() && insensBmp.GetMask() )
aae91497
MB
390 {
391 insensBmp = wxCreateMaskedBitmap(insensBmp, col);
392 tool->SetDisabledBitmap(insensBmp);
393 }
7fe7d506 394 }
8a0681f9
VZ
395
396 // Create a selected/toggled bitmap. If there isn't a 2nd
397 // bitmap, we need to create it (with a darker, selected
398 // background)
3e0071d9 399 WXPixel backgroundPixel;
8a0681f9
VZ
400 if ( tool->CanBeToggled() )
401 XtVaGetValues(button, XmNselectColor, &backgroundPixel,
aae91497 402 NULL);
7fe7d506 403 else
8a0681f9 404 XtVaGetValues(button, XmNarmColor, &backgroundPixel,
aae91497 405 NULL);
8a0681f9
VZ
406 wxColour col;
407 col.SetPixel(backgroundPixel);
408
aae0472b 409 pixmap = (Pixmap) bmp.GetDrawable();
aae91497
MB
410 {
411 wxBitmap tmp = tool->GetDisabledBitmap();
8a0681f9 412
a1b806b9 413 insensPixmap = tmp.IsOk() ?
aae0472b 414 (Pixmap)tmp.GetDrawable() :
aae91497
MB
415 tool->GetInsensPixmap();
416 }
355b4d3d 417
8a0681f9
VZ
418 if (tool->CanBeToggled())
419 {
420 // Toggle button
aae91497
MB
421 Pixmap pixmap2 = tool->GetArmPixmap();
422 Pixmap insensPixmap2 = tool->GetInsensPixmap();
982b2cfc 423
8a0681f9 424 XtVaSetValues (button,
8a0681f9
VZ
425 XmNfillOnSelect, True,
426 XmNlabelPixmap, pixmap,
427 XmNselectPixmap, pixmap2,
428 XmNlabelInsensitivePixmap, insensPixmap,
429 XmNselectInsensitivePixmap, insensPixmap2,
430 XmNlabelType, XmPIXMAP,
431 NULL);
7fe7d506
JS
432 }
433 else
434 {
aae91497 435 Pixmap pixmap2 = tool->GetArmPixmap();
982b2cfc 436
8a0681f9
VZ
437 // Normal button
438 XtVaSetValues(button,
439 XmNlabelPixmap, pixmap,
440 XmNlabelInsensitivePixmap, insensPixmap,
441 XmNarmPixmap, pixmap2,
442 NULL);
443 }
982b2cfc 444
8a0681f9 445 XtManageChild(button);
7fe7d506 446
8a0681f9
VZ
447 {
448 Dimension width, height;
449 XtVaGetValues(button,
450 XmNwidth, &width,
451 XmNheight, & height,
452 NULL);
46675b46
MB
453 if ( isVertical )
454 currentY += height + packing;
455 else
456 currentX += width + packing;
8a0681f9 457 buttonHeight = wxMax(buttonHeight, height);
46675b46 458 buttonWidth = wxMax(buttonWidth, width);
7fe7d506 459 }
8a0681f9
VZ
460
461 XtAddEventHandler (button, EnterWindowMask | LeaveWindowMask,
462 False, wxToolButtonPopupCallback, (XtPointer) this);
463
8a0681f9 464 break;
7fe7d506 465 }
8a0681f9
VZ
466
467 node = node->GetNext();
7fe7d506
JS
468 }
469
46675b46 470 SetSize( -1, -1,
aae91497
MB
471 isVertical ? buttonWidth + 2 * marginX : -1,
472 isVertical ? -1 : buttonHeight + 2*marginY );
7fe7d506 473
96be256b 474 return true;
7fe7d506
JS
475}
476
982b2cfc
VZ
477wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x),
478 wxCoord WXUNUSED(y)) const
4bb6408c 479{
9a83f860 480 wxFAIL_MSG( wxT("TODO") );
4b5f3fe6 481
d3b9f782 482 return NULL;
4bb6408c
JS
483}
484
982b2cfc 485bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool)
4bb6408c 486{
8a0681f9 487 tool->Attach(this);
4bb6408c 488
96be256b 489 return true;
4bb6408c
JS
490}
491
355b4d3d 492bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool)
4bb6408c 493{
8a0681f9 494 tool->Detach();
0d57be45 495
aae91497
MB
496 bool isVertical = GetWindowStyle() & wxTB_VERTICAL;
497 const int separatorSize = GetToolSeparation(); // 8;
498 int packing = GetToolPacking();
499 int offset = 0;
500
ac32ba44 501 for( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
aae91497
MB
502 node; node = node->GetNext() )
503 {
504 wxToolBarTool *t = (wxToolBarTool*)node->GetData();
505
506 if( t == tool )
507 {
508 switch ( t->GetStyle() )
509 {
510 case wxTOOL_STYLE_CONTROL:
511 {
512 wxSize size = t->GetControl()->GetSize();
513 offset = isVertical ? size.y : size.x;
514 offset += packing;
515 break;
355b4d3d 516 }
aae91497
MB
517 case wxTOOL_STYLE_SEPARATOR:
518 offset = isVertical ? 0 : separatorSize;
519 break;
520 case wxTOOL_STYLE_BUTTON:
521 {
522 Widget w = t->GetButtonWidget();
523 Dimension width, height;
524
525 XtVaGetValues( w,
526 XmNwidth, &width,
527 XmNheight, &height,
528 NULL );
529
530 offset = isVertical ? height : width;
531 offset += packing;
532 break;
533 }
534 }
535 }
536 else if( offset )
537 {
538 switch ( t->GetStyle() )
539 {
540 case wxTOOL_STYLE_CONTROL:
541 {
355b4d3d 542 wxPoint location = t->GetControl()->GetPosition();
aae91497
MB
543
544 if( isVertical )
355b4d3d 545 location.y -= offset;
aae91497 546 else
355b4d3d 547 location.x -= offset;
aae91497 548
355b4d3d 549 t->GetControl()->Move( location );
aae91497
MB
550 break;
551 }
552 case wxTOOL_STYLE_SEPARATOR:
553 break;
554 case wxTOOL_STYLE_BUTTON:
555 {
556 Dimension x, y;
557 XtVaGetValues( t->GetButtonWidget(),
558 XmNx, &x,
559 XmNy, &y,
560 NULL );
561
562 if( isVertical )
355b4d3d 563 y = (Dimension)(y - offset);
aae91497 564 else
355b4d3d 565 x = (Dimension)(x - offset);
aae91497
MB
566
567 XtVaSetValues( t->GetButtonWidget(),
568 XmNx, x,
569 XmNy, y,
570 NULL );
571 break;
572 }
573 }
574 }
575 }
576
96be256b 577 return true;
4bb6408c
JS
578}
579
982b2cfc 580void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable)
1a3ac83f 581{
982b2cfc 582 wxToolBarTool *tool = (wxToolBarTool *)toolBase;
6707bb94
MB
583 if (tool->GetButtonWidget()){
584 XtSetSensitive(tool->GetButtonWidget(), (Boolean) enable);
585 } else if (wxTOOL_STYLE_CONTROL == tool->GetStyle()){
586 // Controls (such as wxChoice) do not have button widgets
587 tool->GetControl()->Enable(enable);
588 }
1a3ac83f
JS
589}
590
982b2cfc 591void wxToolBar::DoToggleTool(wxToolBarToolBase *toolBase, bool toggle)
4bb6408c 592{
982b2cfc
VZ
593 wxToolBarTool *tool = (wxToolBarTool *)toolBase;
594
8a0681f9 595 XmToggleButtonSetState(tool->GetButtonWidget(), (Boolean) toggle, False);
4bb6408c
JS
596}
597
982b2cfc
VZ
598void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool),
599 bool WXUNUSED(toggle))
1a3ac83f 600{
982b2cfc 601 // nothing to do
1a3ac83f
JS
602}
603
46675b46
MB
604void wxToolBar::DoSetSize(int x, int y, int width, int height, int sizeFlags)
605{
606 int old_width, old_height;
607 GetSize(&old_width, &old_height);
608
46675b46
MB
609 // Correct width and height if needed.
610 if ( width == -1 || height == -1 )
611 {
aae91497 612 wxSize defaultSize = GetSize();
46675b46
MB
613
614 if ( width == -1 )
aae91497 615 width = defaultSize.x;
46675b46 616 if ( height == -1 )
aae91497 617 height = defaultSize.y;
46675b46 618 }
aae91497
MB
619
620 wxToolBarBase::DoSetSize(x, y, width, height, sizeFlags);
355b4d3d 621
46675b46
MB
622 // We must refresh the frame size when the toolbar changes size
623 // otherwise the toolbar can be shown incorrectly
624 if ( old_width != width || old_height != height )
625 {
355b4d3d 626 // But before we send the size event check it
46675b46
MB
627 // we have a frame that is not being deleted.
628 wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
629 if ( frame && !frame->IsBeingDeleted() )
630 {
631 frame->SendSizeEvent();
632 }
633 }
634}
635
8a0681f9
VZ
636// ----------------------------------------------------------------------------
637// Motif callbacks
638// ----------------------------------------------------------------------------
1a3ac83f 639
982b2cfc 640wxToolBarToolBase *wxToolBar::FindToolByWidget(WXWidget w) const
7fe7d506 641{
ac32ba44 642 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
8a0681f9
VZ
643 while ( node )
644 {
645 wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
646 if ( tool->GetButtonWidget() == w)
647 {
648 return tool;
649 }
7fe7d506 650
8a0681f9
VZ
651 node = node->GetNext();
652 }
7fe7d506 653
d3b9f782 654 return NULL;
7fe7d506
JS
655}
656
8a0681f9
VZ
657static void wxToolButtonCallback(Widget w,
658 XtPointer clientData,
659 XtPointer WXUNUSED(ptr))
1a3ac83f
JS
660{
661 wxToolBar *toolBar = (wxToolBar *) clientData;
982b2cfc 662 wxToolBarToolBase *tool = toolBar->FindToolByWidget((WXWidget) w);
8a0681f9
VZ
663 if ( !tool )
664 return;
1a3ac83f 665
8a0681f9
VZ
666 if ( tool->CanBeToggled() )
667 tool->Toggle();
668
669 if ( !toolBar->OnLeftClick(tool->GetId(), tool->IsToggled()) )
1a3ac83f 670 {
8a0681f9
VZ
671 // revert
672 tool->Toggle();
1a3ac83f 673 }
1a3ac83f
JS
674}
675
1a3ac83f 676
8a0681f9
VZ
677static void wxToolButtonPopupCallback(Widget w,
678 XtPointer client_data,
679 XEvent *event,
680 Boolean *WXUNUSED(continue_to_dispatch))
1a3ac83f
JS
681{
682 // TODO: retrieve delay before popping up tooltip from wxSystemSettings.
8a0681f9 683 static const int delayMilli = 800;
1a3ac83f 684
8a0681f9 685 wxToolBar* toolBar = (wxToolBar*) client_data;
982b2cfc 686 wxToolBarToolBase *tool = toolBar->FindToolByWidget((WXWidget) w);
1a3ac83f 687
8a0681f9
VZ
688 if ( !tool )
689 return;
1a3ac83f 690
8a0681f9
VZ
691 wxString tooltip = tool->GetShortHelp();
692 if ( !tooltip )
693 return;
1a3ac83f 694
8a0681f9
VZ
695 if (!wxTheToolBarTimer)
696 wxTheToolBarTimer = new wxToolBarTimer;
1a3ac83f 697
8a0681f9
VZ
698 wxToolBarTimer::buttonWidget = w;
699 wxToolBarTimer::helpString = tooltip;
1a3ac83f
JS
700
701 /************************************************************/
702 /* Popup help label */
703 /************************************************************/
704 if (event->type == EnterNotify)
705 {
706 if (wxToolBarTimer::help_popup != (Widget) 0)
707 {
708 XtDestroyWidget (wxToolBarTimer::help_popup);
709 XtPopdown (wxToolBarTimer::help_popup);
bf6c2b35 710 }
1a3ac83f
JS
711 wxToolBarTimer::help_popup = (Widget) 0;
712
713 // One shot
96be256b 714 wxTheToolBarTimer->Start(delayMilli, true);
1a3ac83f
JS
715
716 }
717 /************************************************************/
718 /* Popdown help label */
719 /************************************************************/
720 else if (event->type == LeaveNotify)
721 {
722 if (wxTheToolBarTimer)
723 wxTheToolBarTimer->Stop();
724 if (wxToolBarTimer::help_popup != (Widget) 0)
725 {
726 XtDestroyWidget (wxToolBarTimer::help_popup);
727 XtPopdown (wxToolBarTimer::help_popup);
bf6c2b35 728 }
1a3ac83f
JS
729 wxToolBarTimer::help_popup = (Widget) 0;
730 }
1a3ac83f
JS
731}
732
733void wxToolBarTimer::Notify()
734{
735 Position x, y;
736
737 /************************************************************/
738 /* Create shell without window decorations */
739 /************************************************************/
bf6c2b35
VZ
740 help_popup = XtVaCreatePopupShell ("shell",
741 overrideShellWidgetClass, (Widget) wxTheApp->GetTopLevelWidget(),
1a3ac83f
JS
742 NULL);
743
744 /************************************************************/
745 /* Get absolute position on display of toolbar button */
746 /************************************************************/
747 XtTranslateCoords (buttonWidget,
bf6c2b35
VZ
748 (Position) 0,
749 (Position) 0,
1a3ac83f
JS
750 &x, &y);
751
752 // Move the tooltip more or less above the button
753 int yOffset = 20; // TODO: What should be really?
355b4d3d 754 y = (Position)(y - yOffset);
1a3ac83f
JS
755 if (y < yOffset) y = 0;
756
757 /************************************************************/
758 /* Set the position of the help popup */
759 /************************************************************/
bf6c2b35
VZ
760 XtVaSetValues (help_popup,
761 XmNx, (Position) x,
762 XmNy, (Position) y,
1a3ac83f 763 NULL);
bf6c2b35 764
1a3ac83f
JS
765 /************************************************************/
766 /* Create help label */
767 /************************************************************/
768 XmString text = XmStringCreateSimple ((char*) (const char*) helpString);
bf6c2b35
VZ
769 XtVaCreateManagedWidget ("help_label",
770 xmLabelWidgetClass, help_popup,
1a3ac83f 771 XmNlabelString, text,
bf6c2b35
VZ
772 XtVaTypedArg,
773 XmNforeground, XtRString, "black",
774 strlen("black")+1,
775 XtVaTypedArg,
776 XmNbackground, XtRString, "LightGoldenrod",
777 strlen("LightGoldenrod")+1,
1a3ac83f
JS
778 NULL);
779 XmStringFree (text);
780
781 /************************************************************/
782 /* Popup help label */
783 /************************************************************/
784 XtPopup (help_popup, XtGrabNone);
785}