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