]>
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 | |
12ed316d | 56 | IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarBase) |
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 | ||
0d57be45 | 242 | SetCanAddEventHandler(TRUE); |
46675b46 MB |
243 | AttachWidget (parent, m_mainWidget, (WXWidget) NULL, |
244 | rPos.x, rPos.y, rSize.x, rSize.y); | |
0d57be45 | 245 | |
0d57be45 | 246 | ChangeBackgroundColour(); |
bf6c2b35 | 247 | |
0d57be45 | 248 | return TRUE; |
4bb6408c JS |
249 | } |
250 | ||
251 | wxToolBar::~wxToolBar() | |
252 | { | |
1a3ac83f JS |
253 | delete wxTheToolBarTimer; |
254 | wxTheToolBarTimer = NULL; | |
4bb6408c JS |
255 | } |
256 | ||
8a0681f9 | 257 | bool wxToolBar::Realize() |
7fe7d506 | 258 | { |
8a0681f9 VZ |
259 | if ( m_tools.GetCount() == 0 ) |
260 | { | |
261 | // nothing to do | |
262 | return TRUE; | |
263 | } | |
7fe7d506 | 264 | |
46675b46 MB |
265 | bool isVertical = GetWindowStyle() & wxTB_VERTICAL; |
266 | ||
7fe7d506 JS |
267 | // Separator spacing |
268 | const int separatorSize = GetToolSeparation(); // 8; | |
269 | wxSize margins = GetToolMargins(); | |
f3979fcc | 270 | int packing = GetToolPacking(); |
7fe7d506 JS |
271 | int marginX = margins.x; |
272 | int marginY = margins.y; | |
273 | ||
274 | int currentX = marginX; | |
275 | int currentY = marginY; | |
276 | ||
46675b46 | 277 | int buttonHeight = 0, buttonWidth = 0; |
7fe7d506 JS |
278 | |
279 | int currentSpacing = 0; | |
280 | ||
8a0681f9 VZ |
281 | Widget button; |
282 | Pixmap pixmap, insensPixmap; | |
aae91497 | 283 | wxBitmap bmp, insensBmp; |
8a0681f9 VZ |
284 | |
285 | wxToolBarToolsList::Node *node = m_tools.GetFirst(); | |
286 | while ( node ) | |
7fe7d506 | 287 | { |
8a0681f9 | 288 | wxToolBarTool *tool = (wxToolBarTool *)node->GetData(); |
7fe7d506 | 289 | |
8a0681f9 | 290 | switch ( tool->GetStyle() ) |
7fe7d506 | 291 | { |
8a0681f9 | 292 | case wxTOOL_STYLE_CONTROL: |
f3979fcc | 293 | { |
66f55ec6 JS |
294 | wxControl* control = tool->GetControl(); |
295 | wxSize sz = control->GetSize(); | |
f3979fcc | 296 | wxPoint pos = control->GetPosition(); |
46675b46 MB |
297 | // Allow a control to specify a y[x]-offset by setting |
298 | // its initial position, but still don't allow it to | |
299 | // position itself above the top[left] margin. | |
aae91497 MB |
300 | int controlY = (pos.y > 0) ? pos.y : currentY; |
301 | int controlX = (pos.x > 0) ? pos.x : currentX; | |
46675b46 MB |
302 | control->Move( isVertical ? controlX : currentX, |
303 | isVertical ? currentY : controlY ); | |
304 | if ( isVertical ) | |
305 | currentY += sz.y + packing; | |
306 | else | |
307 | currentX += sz.x + packing; | |
66f55ec6 | 308 | |
8a0681f9 | 309 | break; |
f3979fcc | 310 | } |
8a0681f9 | 311 | case wxTOOL_STYLE_SEPARATOR: |
aae91497 MB |
312 | // skip separators for vertical toolbars |
313 | if( !isVertical ) | |
314 | { | |
315 | currentX += separatorSize; | |
316 | } | |
8a0681f9 | 317 | break; |
7fe7d506 | 318 | |
8a0681f9 VZ |
319 | case wxTOOL_STYLE_BUTTON: |
320 | button = (Widget) 0; | |
bf6c2b35 | 321 | |
aae91497 | 322 | if ( tool->CanBeToggled() && !tool->GetButtonWidget() ) |
7fe7d506 | 323 | { |
8a0681f9 VZ |
324 | button = XtVaCreateWidget("toggleButton", |
325 | xmToggleButtonWidgetClass, (Widget) m_mainWidget, | |
326 | XmNx, currentX, XmNy, currentY, | |
e838cc14 VZ |
327 | XmNindicatorOn, False, |
328 | XmNshadowThickness, 2, | |
329 | XmNborderWidth, 0, | |
330 | XmNspacing, 0, | |
331 | XmNmarginWidth, 0, | |
332 | XmNmarginHeight, 0, | |
8a0681f9 VZ |
333 | XmNmultiClick, XmMULTICLICK_KEEP, |
334 | XmNlabelType, XmPIXMAP, | |
335 | NULL); | |
aae91497 MB |
336 | XtAddCallback ((Widget) button, |
337 | XmNvalueChangedCallback, | |
338 | (XtCallbackProc) wxToolButtonCallback, | |
339 | (XtPointer) this); | |
8a0681f9 VZ |
340 | |
341 | XtVaSetValues ((Widget) button, | |
aae91497 MB |
342 | XmNselectColor, |
343 | m_backgroundColour.AllocColour | |
344 | (XtDisplay((Widget) button)), | |
345 | NULL); | |
bf6c2b35 | 346 | } |
aae91497 | 347 | else if( !tool->GetButtonWidget() ) |
8a0681f9 VZ |
348 | { |
349 | button = XtVaCreateWidget("button", | |
350 | xmPushButtonWidgetClass, (Widget) m_mainWidget, | |
351 | XmNx, currentX, XmNy, currentY, | |
352 | XmNpushButtonEnabled, True, | |
353 | XmNmultiClick, XmMULTICLICK_KEEP, | |
354 | XmNlabelType, XmPIXMAP, | |
355 | NULL); | |
356 | XtAddCallback (button, | |
aae91497 MB |
357 | XmNactivateCallback, |
358 | (XtCallbackProc) wxToolButtonCallback, | |
359 | (XtPointer) this); | |
8a0681f9 | 360 | } |
7fe7d506 | 361 | |
aae91497 MB |
362 | if( !tool->GetButtonWidget() ) |
363 | { | |
364 | DoChangeBackgroundColour((WXWidget) button, | |
365 | m_backgroundColour, TRUE); | |
7fe7d506 | 366 | |
aae91497 MB |
367 | tool->SetWidget(button); |
368 | } | |
369 | else | |
370 | { | |
371 | button = (Widget)tool->GetButtonWidget(); | |
372 | XtVaSetValues( button, | |
373 | XmNx, currentX, XmNy, currentY, | |
374 | NULL ); | |
375 | } | |
7fe7d506 | 376 | |
8a0681f9 VZ |
377 | // For each button, if there is a mask, we must create |
378 | // a new wxBitmap that has the correct background colour | |
379 | // for the button. Otherwise the background will just be | |
380 | // e.g. black if a transparent XPM has been loaded. | |
fcb35b5f | 381 | bmp = tool->GetNormalBitmap(); |
aae91497 MB |
382 | insensBmp = tool->GetDisabledBitmap(); |
383 | if ( bmp.GetMask() || insensBmp.GetMask() ) | |
7fe7d506 | 384 | { |
8a0681f9 VZ |
385 | int backgroundPixel; |
386 | XtVaGetValues(button, XmNbackground, &backgroundPixel, | |
aae91497 | 387 | NULL); |
8a0681f9 VZ |
388 | |
389 | wxColour col; | |
390 | col.SetPixel(backgroundPixel); | |
8a0681f9 | 391 | |
aae91497 MB |
392 | if( bmp.GetMask() ) |
393 | { | |
394 | bmp = wxCreateMaskedBitmap(bmp, col); | |
395 | tool->SetNormalBitmap(bmp); | |
396 | } | |
397 | ||
398 | if( insensBmp.GetMask() ) | |
399 | { | |
400 | insensBmp = wxCreateMaskedBitmap(insensBmp, col); | |
401 | tool->SetDisabledBitmap(insensBmp); | |
402 | } | |
7fe7d506 | 403 | } |
8a0681f9 VZ |
404 | |
405 | // Create a selected/toggled bitmap. If there isn't a 2nd | |
406 | // bitmap, we need to create it (with a darker, selected | |
407 | // background) | |
408 | int backgroundPixel; | |
409 | if ( tool->CanBeToggled() ) | |
410 | XtVaGetValues(button, XmNselectColor, &backgroundPixel, | |
aae91497 | 411 | NULL); |
7fe7d506 | 412 | else |
8a0681f9 | 413 | XtVaGetValues(button, XmNarmColor, &backgroundPixel, |
aae91497 | 414 | NULL); |
8a0681f9 VZ |
415 | wxColour col; |
416 | col.SetPixel(backgroundPixel); | |
417 | ||
8a0681f9 | 418 | pixmap = (Pixmap) bmp.GetPixmap(); |
aae91497 MB |
419 | { |
420 | wxBitmap tmp = tool->GetDisabledBitmap(); | |
8a0681f9 | 421 | |
aae91497 MB |
422 | insensPixmap = tmp.Ok() ? |
423 | (Pixmap)tmp.GetPixmap() : | |
424 | tool->GetInsensPixmap(); | |
425 | } | |
426 | ||
8a0681f9 VZ |
427 | if (tool->CanBeToggled()) |
428 | { | |
429 | // Toggle button | |
aae91497 MB |
430 | Pixmap pixmap2 = tool->GetArmPixmap(); |
431 | Pixmap insensPixmap2 = tool->GetInsensPixmap(); | |
982b2cfc | 432 | |
8a0681f9 | 433 | XtVaSetValues (button, |
8a0681f9 VZ |
434 | XmNfillOnSelect, True, |
435 | XmNlabelPixmap, pixmap, | |
436 | XmNselectPixmap, pixmap2, | |
437 | XmNlabelInsensitivePixmap, insensPixmap, | |
438 | XmNselectInsensitivePixmap, insensPixmap2, | |
439 | XmNlabelType, XmPIXMAP, | |
440 | NULL); | |
7fe7d506 JS |
441 | } |
442 | else | |
443 | { | |
aae91497 | 444 | Pixmap pixmap2 = tool->GetArmPixmap(); |
982b2cfc | 445 | |
8a0681f9 VZ |
446 | // Normal button |
447 | XtVaSetValues(button, | |
448 | XmNlabelPixmap, pixmap, | |
449 | XmNlabelInsensitivePixmap, insensPixmap, | |
450 | XmNarmPixmap, pixmap2, | |
451 | NULL); | |
452 | } | |
982b2cfc | 453 | |
8a0681f9 | 454 | XtManageChild(button); |
7fe7d506 | 455 | |
8a0681f9 VZ |
456 | { |
457 | Dimension width, height; | |
458 | XtVaGetValues(button, | |
459 | XmNwidth, &width, | |
460 | XmNheight, & height, | |
461 | NULL); | |
46675b46 MB |
462 | if ( isVertical ) |
463 | currentY += height + packing; | |
464 | else | |
465 | currentX += width + packing; | |
8a0681f9 | 466 | buttonHeight = wxMax(buttonHeight, height); |
46675b46 | 467 | buttonWidth = wxMax(buttonWidth, width); |
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 | ||
46675b46 | 480 | SetSize( -1, -1, |
aae91497 MB |
481 | isVertical ? buttonWidth + 2 * marginX : -1, |
482 | isVertical ? -1 : buttonHeight + 2*marginY ); | |
7fe7d506 JS |
483 | |
484 | return TRUE; | |
485 | } | |
486 | ||
982b2cfc VZ |
487 | wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x), |
488 | wxCoord WXUNUSED(y)) const | |
4bb6408c | 489 | { |
8a0681f9 | 490 | wxFAIL_MSG( _T("TODO") ); |
4b5f3fe6 | 491 | |
982b2cfc | 492 | return (wxToolBarToolBase *)NULL; |
4bb6408c JS |
493 | } |
494 | ||
982b2cfc | 495 | bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool) |
4bb6408c | 496 | { |
8a0681f9 | 497 | tool->Attach(this); |
4bb6408c | 498 | |
8a0681f9 | 499 | return TRUE; |
4bb6408c JS |
500 | } |
501 | ||
aae91497 | 502 | bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) |
4bb6408c | 503 | { |
8a0681f9 | 504 | tool->Detach(); |
0d57be45 | 505 | |
aae91497 MB |
506 | bool isVertical = GetWindowStyle() & wxTB_VERTICAL; |
507 | const int separatorSize = GetToolSeparation(); // 8; | |
508 | int packing = GetToolPacking(); | |
509 | int offset = 0; | |
510 | ||
511 | for( wxToolBarToolsList::Node *node = m_tools.GetFirst(); | |
512 | node; node = node->GetNext() ) | |
513 | { | |
514 | wxToolBarTool *t = (wxToolBarTool*)node->GetData(); | |
515 | ||
516 | if( t == tool ) | |
517 | { | |
518 | switch ( t->GetStyle() ) | |
519 | { | |
520 | case wxTOOL_STYLE_CONTROL: | |
521 | { | |
522 | wxSize size = t->GetControl()->GetSize(); | |
523 | offset = isVertical ? size.y : size.x; | |
524 | offset += packing; | |
525 | break; | |
526 | } | |
527 | case wxTOOL_STYLE_SEPARATOR: | |
528 | offset = isVertical ? 0 : separatorSize; | |
529 | break; | |
530 | case wxTOOL_STYLE_BUTTON: | |
531 | { | |
532 | Widget w = t->GetButtonWidget(); | |
533 | Dimension width, height; | |
534 | ||
535 | XtVaGetValues( w, | |
536 | XmNwidth, &width, | |
537 | XmNheight, &height, | |
538 | NULL ); | |
539 | ||
540 | offset = isVertical ? height : width; | |
541 | offset += packing; | |
542 | break; | |
543 | } | |
544 | } | |
545 | } | |
546 | else if( offset ) | |
547 | { | |
548 | switch ( t->GetStyle() ) | |
549 | { | |
550 | case wxTOOL_STYLE_CONTROL: | |
551 | { | |
552 | wxPoint pos = t->GetControl()->GetPosition(); | |
553 | ||
554 | if( isVertical ) | |
555 | pos.y -= offset; | |
556 | else | |
557 | pos.x -= offset; | |
558 | ||
559 | t->GetControl()->Move( pos ); | |
560 | break; | |
561 | } | |
562 | case wxTOOL_STYLE_SEPARATOR: | |
563 | break; | |
564 | case wxTOOL_STYLE_BUTTON: | |
565 | { | |
566 | Dimension x, y; | |
567 | XtVaGetValues( t->GetButtonWidget(), | |
568 | XmNx, &x, | |
569 | XmNy, &y, | |
570 | NULL ); | |
571 | ||
572 | if( isVertical ) | |
573 | y -= offset; | |
574 | else | |
575 | x -= offset; | |
576 | ||
577 | XtVaSetValues( t->GetButtonWidget(), | |
578 | XmNx, x, | |
579 | XmNy, y, | |
580 | NULL ); | |
581 | break; | |
582 | } | |
583 | } | |
584 | } | |
585 | } | |
586 | ||
8a0681f9 | 587 | return TRUE; |
4bb6408c JS |
588 | } |
589 | ||
982b2cfc | 590 | void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable) |
1a3ac83f | 591 | { |
982b2cfc VZ |
592 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
593 | ||
8a0681f9 | 594 | XtSetSensitive(tool->GetButtonWidget(), (Boolean) enable); |
1a3ac83f JS |
595 | } |
596 | ||
982b2cfc | 597 | void wxToolBar::DoToggleTool(wxToolBarToolBase *toolBase, bool toggle) |
4bb6408c | 598 | { |
982b2cfc VZ |
599 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
600 | ||
8a0681f9 | 601 | XmToggleButtonSetState(tool->GetButtonWidget(), (Boolean) toggle, False); |
4bb6408c JS |
602 | } |
603 | ||
982b2cfc VZ |
604 | void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool), |
605 | bool WXUNUSED(toggle)) | |
1a3ac83f | 606 | { |
982b2cfc | 607 | // nothing to do |
1a3ac83f JS |
608 | } |
609 | ||
46675b46 MB |
610 | void wxToolBar::DoSetSize(int x, int y, int width, int height, int sizeFlags) |
611 | { | |
612 | int old_width, old_height; | |
613 | GetSize(&old_width, &old_height); | |
614 | ||
46675b46 MB |
615 | // Correct width and height if needed. |
616 | if ( width == -1 || height == -1 ) | |
617 | { | |
aae91497 | 618 | wxSize defaultSize = GetSize(); |
46675b46 MB |
619 | |
620 | if ( width == -1 ) | |
aae91497 | 621 | width = defaultSize.x; |
46675b46 | 622 | if ( height == -1 ) |
aae91497 | 623 | height = defaultSize.y; |
46675b46 | 624 | } |
aae91497 MB |
625 | |
626 | wxToolBarBase::DoSetSize(x, y, width, height, sizeFlags); | |
46675b46 MB |
627 | |
628 | // We must refresh the frame size when the toolbar changes size | |
629 | // otherwise the toolbar can be shown incorrectly | |
630 | if ( old_width != width || old_height != height ) | |
631 | { | |
632 | // But before we send the size event check it | |
633 | // we have a frame that is not being deleted. | |
634 | wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); | |
635 | if ( frame && !frame->IsBeingDeleted() ) | |
636 | { | |
637 | frame->SendSizeEvent(); | |
638 | } | |
639 | } | |
640 | } | |
641 | ||
8a0681f9 VZ |
642 | // ---------------------------------------------------------------------------- |
643 | // Motif callbacks | |
644 | // ---------------------------------------------------------------------------- | |
1a3ac83f | 645 | |
982b2cfc | 646 | wxToolBarToolBase *wxToolBar::FindToolByWidget(WXWidget w) const |
7fe7d506 | 647 | { |
8a0681f9 VZ |
648 | wxToolBarToolsList::Node* node = m_tools.GetFirst(); |
649 | while ( node ) | |
650 | { | |
651 | wxToolBarTool *tool = (wxToolBarTool *)node->GetData(); | |
652 | if ( tool->GetButtonWidget() == w) | |
653 | { | |
654 | return tool; | |
655 | } | |
7fe7d506 | 656 | |
8a0681f9 VZ |
657 | node = node->GetNext(); |
658 | } | |
7fe7d506 | 659 | |
982b2cfc | 660 | return (wxToolBarToolBase *)NULL; |
7fe7d506 JS |
661 | } |
662 | ||
8a0681f9 VZ |
663 | static void wxToolButtonCallback(Widget w, |
664 | XtPointer clientData, | |
665 | XtPointer WXUNUSED(ptr)) | |
1a3ac83f JS |
666 | { |
667 | wxToolBar *toolBar = (wxToolBar *) clientData; | |
982b2cfc | 668 | wxToolBarToolBase *tool = toolBar->FindToolByWidget((WXWidget) w); |
8a0681f9 VZ |
669 | if ( !tool ) |
670 | return; | |
1a3ac83f | 671 | |
8a0681f9 VZ |
672 | if ( tool->CanBeToggled() ) |
673 | tool->Toggle(); | |
674 | ||
675 | if ( !toolBar->OnLeftClick(tool->GetId(), tool->IsToggled()) ) | |
1a3ac83f | 676 | { |
8a0681f9 VZ |
677 | // revert |
678 | tool->Toggle(); | |
1a3ac83f | 679 | } |
1a3ac83f JS |
680 | } |
681 | ||
1a3ac83f | 682 | |
8a0681f9 VZ |
683 | static void wxToolButtonPopupCallback(Widget w, |
684 | XtPointer client_data, | |
685 | XEvent *event, | |
686 | Boolean *WXUNUSED(continue_to_dispatch)) | |
1a3ac83f JS |
687 | { |
688 | // TODO: retrieve delay before popping up tooltip from wxSystemSettings. | |
8a0681f9 | 689 | static const int delayMilli = 800; |
1a3ac83f | 690 | |
8a0681f9 | 691 | wxToolBar* toolBar = (wxToolBar*) client_data; |
982b2cfc | 692 | wxToolBarToolBase *tool = toolBar->FindToolByWidget((WXWidget) w); |
1a3ac83f | 693 | |
8a0681f9 VZ |
694 | if ( !tool ) |
695 | return; | |
1a3ac83f | 696 | |
8a0681f9 VZ |
697 | wxString tooltip = tool->GetShortHelp(); |
698 | if ( !tooltip ) | |
699 | return; | |
1a3ac83f | 700 | |
8a0681f9 VZ |
701 | if (!wxTheToolBarTimer) |
702 | wxTheToolBarTimer = new wxToolBarTimer; | |
1a3ac83f | 703 | |
8a0681f9 VZ |
704 | wxToolBarTimer::buttonWidget = w; |
705 | wxToolBarTimer::helpString = tooltip; | |
1a3ac83f JS |
706 | |
707 | /************************************************************/ | |
708 | /* Popup help label */ | |
709 | /************************************************************/ | |
710 | if (event->type == EnterNotify) | |
711 | { | |
712 | if (wxToolBarTimer::help_popup != (Widget) 0) | |
713 | { | |
714 | XtDestroyWidget (wxToolBarTimer::help_popup); | |
715 | XtPopdown (wxToolBarTimer::help_popup); | |
bf6c2b35 | 716 | } |
1a3ac83f JS |
717 | wxToolBarTimer::help_popup = (Widget) 0; |
718 | ||
719 | // One shot | |
720 | wxTheToolBarTimer->Start(delayMilli, TRUE); | |
721 | ||
722 | } | |
723 | /************************************************************/ | |
724 | /* Popdown help label */ | |
725 | /************************************************************/ | |
726 | else if (event->type == LeaveNotify) | |
727 | { | |
728 | if (wxTheToolBarTimer) | |
729 | wxTheToolBarTimer->Stop(); | |
730 | if (wxToolBarTimer::help_popup != (Widget) 0) | |
731 | { | |
732 | XtDestroyWidget (wxToolBarTimer::help_popup); | |
733 | XtPopdown (wxToolBarTimer::help_popup); | |
bf6c2b35 | 734 | } |
1a3ac83f JS |
735 | wxToolBarTimer::help_popup = (Widget) 0; |
736 | } | |
1a3ac83f JS |
737 | } |
738 | ||
739 | void wxToolBarTimer::Notify() | |
740 | { | |
741 | Position x, y; | |
742 | ||
743 | /************************************************************/ | |
744 | /* Create shell without window decorations */ | |
745 | /************************************************************/ | |
bf6c2b35 VZ |
746 | help_popup = XtVaCreatePopupShell ("shell", |
747 | overrideShellWidgetClass, (Widget) wxTheApp->GetTopLevelWidget(), | |
1a3ac83f JS |
748 | NULL); |
749 | ||
750 | /************************************************************/ | |
751 | /* Get absolute position on display of toolbar button */ | |
752 | /************************************************************/ | |
753 | XtTranslateCoords (buttonWidget, | |
bf6c2b35 VZ |
754 | (Position) 0, |
755 | (Position) 0, | |
1a3ac83f JS |
756 | &x, &y); |
757 | ||
758 | // Move the tooltip more or less above the button | |
759 | int yOffset = 20; // TODO: What should be really? | |
760 | y -= yOffset; | |
761 | if (y < yOffset) y = 0; | |
762 | ||
763 | /************************************************************/ | |
764 | /* Set the position of the help popup */ | |
765 | /************************************************************/ | |
bf6c2b35 VZ |
766 | XtVaSetValues (help_popup, |
767 | XmNx, (Position) x, | |
768 | XmNy, (Position) y, | |
1a3ac83f | 769 | NULL); |
bf6c2b35 | 770 | |
1a3ac83f JS |
771 | /************************************************************/ |
772 | /* Create help label */ | |
773 | /************************************************************/ | |
774 | XmString text = XmStringCreateSimple ((char*) (const char*) helpString); | |
bf6c2b35 VZ |
775 | XtVaCreateManagedWidget ("help_label", |
776 | xmLabelWidgetClass, help_popup, | |
1a3ac83f | 777 | XmNlabelString, text, |
bf6c2b35 VZ |
778 | XtVaTypedArg, |
779 | XmNforeground, XtRString, "black", | |
780 | strlen("black")+1, | |
781 | XtVaTypedArg, | |
782 | XmNbackground, XtRString, "LightGoldenrod", | |
783 | strlen("LightGoldenrod")+1, | |
1a3ac83f JS |
784 | NULL); |
785 | XmStringFree (text); | |
786 | ||
787 | /************************************************************/ | |
788 | /* Popup help label */ | |
789 | /************************************************************/ | |
790 | XtPopup (help_popup, XtGrabNone); | |
791 | } | |
792 |