]> git.saurik.com Git - wxWidgets.git/blame - src/common/popupcmn.cpp
Allow absent checkbox when transferring dimension data
[wxWidgets.git] / src / common / popupcmn.cpp
CommitLineData
c02ee97f 1///////////////////////////////////////////////////////////////////////////////
670f9935 2// Name: src/common/popupcmn.cpp
c02ee97f
VZ
3// Purpose: implementation of wxPopupTransientWindow
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 06.01.01
c02ee97f 7// Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
526954c5 8// Licence: wxWindows licence
c02ee97f
VZ
9///////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
c02ee97f
VZ
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
833a51f6 26#if wxUSE_POPUPWIN
c02ee97f
VZ
27
28#include "wx/popupwin.h"
29
30#ifndef WX_PRECOMP
a57d600f 31 #include "wx/combobox.h" // wxComboCtrl
6a0fab3a 32 #include "wx/app.h" // wxPostEvent
ee351013 33 #include "wx/log.h"
c02ee97f
VZ
34#endif //WX_PRECOMP
35
2ac51e16 36#include "wx/display.h"
1295f134
VZ
37#include "wx/recguard.h"
38
c02ee97f
VZ
39#ifdef __WXUNIVERSAL__
40 #include "wx/univ/renderer.h"
76fa9e02 41 #include "wx/scrolbar.h"
c02ee97f
VZ
42#endif // __WXUNIVERSAL__
43
537a0880
RR
44#ifdef __WXGTK__
45 #include <gtk/gtk.h>
04e40451
PC
46 #if GTK_CHECK_VERSION(2,0,0)
47 #include "wx/gtk/private/gtk2-compat.h"
48 #else
49 #define gtk_widget_get_window(x) x->window
50 #endif
ac52d2b0
VZ
51#elif defined(__WXMSW__)
52 #include "wx/msw/private.h"
53#elif defined(__WXX11__)
54 #include "wx/x11/private.h"
c51c4752 55#endif
eb729cd3 56
537a0880 57IMPLEMENT_DYNAMIC_CLASS(wxPopupWindow, wxWindow)
6c3422e9 58IMPLEMENT_DYNAMIC_CLASS(wxPopupTransientWindow, wxPopupWindow)
761df41e
VZ
59
60#if wxUSE_COMBOBOX && defined(__WXUNIVERSAL__)
61 IMPLEMENT_DYNAMIC_CLASS(wxPopupComboWindow, wxPopupTransientWindow)
62#endif
6c3422e9 63
c02ee97f
VZ
64// ----------------------------------------------------------------------------
65// private classes
66// ----------------------------------------------------------------------------
67
68// event handlers which we use to intercept events which cause the popup to
69// disappear
70class wxPopupWindowHandler : public wxEvtHandler
71{
72public:
276612f7 73 wxPopupWindowHandler(wxPopupTransientWindow *popup) : m_popup(popup) {}
c02ee97f
VZ
74
75protected:
76 // event handlers
77 void OnLeftDown(wxMouseEvent& event);
0419fee9 78 void OnCaptureLost(wxMouseCaptureLostEvent& event);
c02ee97f
VZ
79
80private:
81 wxPopupTransientWindow *m_popup;
82
83 DECLARE_EVENT_TABLE()
c0c133e1 84 wxDECLARE_NO_COPY_CLASS(wxPopupWindowHandler);
c02ee97f
VZ
85};
86
87class wxPopupFocusHandler : public wxEvtHandler
88{
89public:
276612f7 90 wxPopupFocusHandler(wxPopupTransientWindow *popup) : m_popup(popup) {}
c02ee97f
VZ
91
92protected:
c02ee97f 93 void OnKillFocus(wxFocusEvent& event);
ffe42ca6 94 void OnChar(wxKeyEvent& event);
c02ee97f
VZ
95
96private:
97 wxPopupTransientWindow *m_popup;
98
99 DECLARE_EVENT_TABLE()
c0c133e1 100 wxDECLARE_NO_COPY_CLASS(wxPopupFocusHandler);
c02ee97f
VZ
101};
102
103// ----------------------------------------------------------------------------
104// event tables
105// ----------------------------------------------------------------------------
106
107BEGIN_EVENT_TABLE(wxPopupWindowHandler, wxEvtHandler)
108 EVT_LEFT_DOWN(wxPopupWindowHandler::OnLeftDown)
0419fee9 109 EVT_MOUSE_CAPTURE_LOST(wxPopupWindowHandler::OnCaptureLost)
c02ee97f
VZ
110END_EVENT_TABLE()
111
112BEGIN_EVENT_TABLE(wxPopupFocusHandler, wxEvtHandler)
113 EVT_KILL_FOCUS(wxPopupFocusHandler::OnKillFocus)
ffe42ca6 114 EVT_CHAR(wxPopupFocusHandler::OnChar)
c02ee97f
VZ
115END_EVENT_TABLE()
116
414f2513 117BEGIN_EVENT_TABLE(wxPopupTransientWindow, wxPopupWindow)
b7005dfd 118#if defined(__WXMSW__) || (defined(__WXMAC__) && wxOSX_USE_COCOA_OR_CARBON)
414f2513
RD
119 EVT_IDLE(wxPopupTransientWindow::OnIdle)
120#endif
121END_EVENT_TABLE()
122
c02ee97f
VZ
123// ============================================================================
124// implementation
125// ============================================================================
126
127// ----------------------------------------------------------------------------
128// wxPopupWindowBase
129// ----------------------------------------------------------------------------
130
799ea011
GD
131wxPopupWindowBase::~wxPopupWindowBase()
132{
133 // this destructor is required for Darwin
134}
135
c02ee97f
VZ
136bool wxPopupWindowBase::Create(wxWindow* WXUNUSED(parent), int WXUNUSED(flags))
137{
7e548f6b 138 return true;
c02ee97f
VZ
139}
140
141void wxPopupWindowBase::Position(const wxPoint& ptOrigin,
142 const wxSize& size)
143{
2ac51e16
VZ
144 // determine the position and size of the screen we clamp the popup to
145 wxPoint posScreen;
146 wxSize sizeScreen;
147
148 const int displayNum = wxDisplay::GetFromPoint(ptOrigin);
149 if ( displayNum != wxNOT_FOUND )
150 {
151 const wxRect rectScreen = wxDisplay(displayNum).GetGeometry();
152 posScreen = rectScreen.GetPosition();
153 sizeScreen = rectScreen.GetSize();
154 }
155 else // outside of any display?
156 {
157 // just use the primary one then
158 posScreen = wxPoint(0, 0);
159 sizeScreen = wxGetDisplaySize();
160 }
161
162
163 const wxSize sizeSelf = GetSize();
c02ee97f
VZ
164
165 // is there enough space to put the popup below the window (where we put it
166 // by default)?
167 wxCoord y = ptOrigin.y + size.y;
247f310d 168 if ( y + sizeSelf.y > posScreen.y + sizeScreen.y )
c02ee97f
VZ
169 {
170 // check if there is enough space above
171 if ( ptOrigin.y > sizeSelf.y )
172 {
173 // do position the control above the window
174 y -= size.y + sizeSelf.y;
175 }
176 //else: not enough space below nor above, leave below
177 }
178
179 // now check left/right too
d2aa263f 180 wxCoord x = ptOrigin.x;
2ac51e16 181
d2aa263f
VZ
182 if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft )
183 {
184 // shift the window to the left instead of the right.
185 x -= size.x;
186 x -= sizeSelf.x; // also shift it by window width.
187 }
188 else
189 x += size.x;
190
2ac51e16 191
247f310d 192 if ( x + sizeSelf.x > posScreen.x + sizeScreen.x )
c02ee97f
VZ
193 {
194 // check if there is enough space to the left
195 if ( ptOrigin.x > sizeSelf.x )
196 {
197 // do position the control to the left
198 x -= size.x + sizeSelf.x;
199 }
200 //else: not enough space there neither, leave in default position
201 }
202
203 Move(x, y, wxSIZE_NO_ADJUSTMENTS);
204}
205
206// ----------------------------------------------------------------------------
207// wxPopupTransientWindow
208// ----------------------------------------------------------------------------
209
210void wxPopupTransientWindow::Init()
211{
212 m_child =
d3b9f782 213 m_focus = NULL;
d7cff34d
VZ
214
215 m_handlerFocus = NULL;
216 m_handlerPopup = NULL;
c02ee97f
VZ
217}
218
758bce95 219wxPopupTransientWindow::wxPopupTransientWindow(wxWindow *parent, int style)
c02ee97f
VZ
220{
221 Init();
222
758bce95 223 (void)Create(parent, style);
c02ee97f
VZ
224}
225
226wxPopupTransientWindow::~wxPopupTransientWindow()
227{
0bf16170
MW
228 if (m_handlerPopup && m_handlerPopup->GetNextHandler())
229 PopHandlers();
17a1ebd1 230
0bf16170
MW
231 wxASSERT(!m_handlerFocus || !m_handlerFocus->GetNextHandler());
232 wxASSERT(!m_handlerPopup || !m_handlerPopup->GetNextHandler());
233
234 delete m_handlerFocus;
235 delete m_handlerPopup;
c02ee97f
VZ
236}
237
238void wxPopupTransientWindow::PopHandlers()
239{
240 if ( m_child )
241 {
0bf16170 242 if ( !m_child->RemoveEventHandler(m_handlerPopup) )
d7cff34d
VZ
243 {
244 // something is very wrong and someone else probably deleted our
245 // handler - so don't risk deleting it second time
246 m_handlerPopup = NULL;
247 }
414f2513 248 if (m_child->HasCapture())
17a1ebd1 249 {
414f2513
RD
250 m_child->ReleaseMouse();
251 }
c02ee97f
VZ
252 m_child = NULL;
253 }
254
255 if ( m_focus )
256 {
0bf16170 257 if ( !m_focus->RemoveEventHandler(m_handlerFocus) )
d7cff34d
VZ
258 {
259 // see above
260 m_handlerFocus = NULL;
261 }
c02ee97f 262 }
537a0880 263 m_focus = NULL;
c02ee97f
VZ
264}
265
266void wxPopupTransientWindow::Popup(wxWindow *winFocus)
267{
60435227
VZ
268 // If we have a single child, we suppose that it must cover the entire
269 // popup window and hence we give the mouse capture to it instead of
270 // keeping it for ourselves.
271 //
272 // Notice that this works best for combobox-like popups which have a single
273 // control inside them and not so well for popups containing a single
274 // wxPanel with multiple children inside it but OTOH it does no harm in
275 // this case neither and we can't reliably distinguish between them.
c02ee97f 276 const wxWindowList& children = GetChildren();
60435227 277 if ( children.GetCount() == 1 )
c02ee97f
VZ
278 {
279 m_child = children.GetFirst()->GetData();
280 }
281 else
282 {
283 m_child = this;
284 }
285
e4606ed9 286 Show();
e4606ed9 287
c9737636 288 // There is a problem if these are still in use
0bf16170
MW
289 wxASSERT(!m_handlerFocus || !m_handlerFocus->GetNextHandler());
290 wxASSERT(!m_handlerPopup || !m_handlerPopup->GetNextHandler());
276612f7 291
0bf16170
MW
292 if (!m_handlerPopup)
293 m_handlerPopup = new wxPopupWindowHandler(this);
d7cff34d 294
d7cff34d 295 m_child->PushEventHandler(m_handlerPopup);
c02ee97f 296
582699e1
JS
297#if defined(__WXMSW__)
298 // Focusing on child of popup window does not work on MSW unless WS_POPUP
299 // style is set. We do not even want to try to set the focus, as it may
300 // provoke errors on some Windows versions (Vista and later).
301 if ( ::GetWindowLong(GetHwnd(), GWL_STYLE) & WS_POPUP )
302#endif
303 {
304 m_focus = winFocus ? winFocus : this;
305 m_focus->SetFocus();
306 }
60178eb4 307
b7005dfd 308#if defined( __WXMSW__ ) || (defined( __WXMAC__) && wxOSX_USE_COCOA_OR_CARBON)
d7cff34d
VZ
309 // MSW doesn't allow to set focus to the popup window, but we need to
310 // subclass the window which has the focus, and not winFocus passed in or
311 // otherwise everything else breaks down
516cdd54 312 m_focus = FindFocus();
8c624a14 313#elif defined(__WXGTK__)
0bf16170
MW
314 // GTK+ catches the activate events from the popup
315 // window, not the focus events from the child window
316 m_focus = this;
317#endif
318
60178eb4
VZ
319 if ( m_focus )
320 {
0bf16170
MW
321 if (!m_handlerFocus)
322 m_handlerFocus = new wxPopupFocusHandler(this);
d7cff34d
VZ
323
324 m_focus->PushEventHandler(m_handlerFocus);
60178eb4 325 }
537a0880
RR
326}
327
328bool wxPopupTransientWindow::Show( bool show )
329{
330#ifdef __WXGTK__
331 if (!show)
f4bb632c 332 {
1897abe1
PC
333#ifdef __WXGTK3__
334 GdkDisplay* display = gtk_widget_get_display(m_widget);
335 GdkDeviceManager* manager = gdk_display_get_device_manager(display);
336 GdkDevice* device = gdk_device_manager_get_client_pointer(manager);
337 gdk_device_ungrab(device, unsigned(GDK_CURRENT_TIME));
338#else
f4bb632c 339 gdk_pointer_ungrab( (guint32)GDK_CURRENT_TIME );
1897abe1 340#endif
2997ca30 341
537a0880 342 gtk_grab_remove( m_widget );
f4bb632c 343 }
537a0880
RR
344#endif
345
c51c4752
RR
346#ifdef __WXX11__
347 if (!show)
348 {
349 XUngrabPointer( wxGlobalDisplay(), CurrentTime );
350 }
351#endif
352
9a890937 353#if defined( __WXMSW__ ) || defined( __WXMAC__)
414f2513 354 if (!show && m_child && m_child->HasCapture())
17a1ebd1 355 {
414f2513
RD
356 m_child->ReleaseMouse();
357 }
358#endif
17a1ebd1 359
537a0880 360 bool ret = wxPopupWindow::Show( show );
2997ca30 361
537a0880
RR
362#ifdef __WXGTK__
363 if (show)
f4bb632c 364 {
537a0880 365 gtk_grab_add( m_widget );
2997ca30 366
1897abe1
PC
367 const GdkEventMask mask = GdkEventMask(
368 GDK_BUTTON_PRESS_MASK |
369 GDK_BUTTON_RELEASE_MASK |
370 GDK_POINTER_MOTION_HINT_MASK |
371 GDK_POINTER_MOTION_MASK);
372 GdkWindow* window = gtk_widget_get_window(m_widget);
373#ifdef __WXGTK3__
374 GdkDisplay* display = gdk_window_get_display(window);
375 GdkDeviceManager* manager = gdk_display_get_device_manager(display);
376 GdkDevice* device = gdk_device_manager_get_client_pointer(manager);
377 gdk_device_grab(device, window,
378 GDK_OWNERSHIP_NONE, false, mask, NULL, unsigned(GDK_CURRENT_TIME));
379#else
380 gdk_pointer_grab( window, true,
381 mask,
d3b9f782
VZ
382 NULL,
383 NULL,
f4bb632c 384 (guint32)GDK_CURRENT_TIME );
1897abe1 385#endif
f4bb632c 386 }
537a0880
RR
387#endif
388
c51c4752
RR
389#ifdef __WXX11__
390 if (show)
391 {
392 Window xwindow = (Window) m_clientWindow;
2997ca30 393
c51c4752
RR
394 /* int res =*/ XGrabPointer(wxGlobalDisplay(), xwindow,
395 True,
396 ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
397 GrabModeAsync,
398 GrabModeAsync,
399 None,
400 None,
401 CurrentTime );
402 }
403#endif
414f2513 404
9a890937 405#if defined( __WXMSW__ ) || defined( __WXMAC__)
414f2513
RD
406 if (show && m_child)
407 {
408 // Assume that the mouse is outside the popup to begin with
409 m_child->CaptureMouse();
410 }
411#endif
412
537a0880 413 return ret;
c02ee97f
VZ
414}
415
f9e19204
VZ
416bool wxPopupTransientWindow::Destroy()
417{
418 // The popup window can be deleted at any moment, even while some events
419 // are still being processed for it, so delay its real destruction until
420 // the next idle time when we're sure that it's safe to really destroy it.
421
422 wxCHECK_MSG( !wxPendingDelete.Member(this), false,
423 wxS("Shouldn't destroy the popup twice.") );
424
425 wxPendingDelete.Append(this);
426
427 return true;
428}
429
c02ee97f
VZ
430void wxPopupTransientWindow::Dismiss()
431{
c02ee97f 432 Hide();
414f2513 433 PopHandlers();
c02ee97f
VZ
434}
435
436void wxPopupTransientWindow::DismissAndNotify()
437{
438 Dismiss();
c02ee97f
VZ
439 OnDismiss();
440}
441
442void wxPopupTransientWindow::OnDismiss()
443{
444 // nothing to do here - but it may be interesting for derived class
445}
446
447bool wxPopupTransientWindow::ProcessLeftDown(wxMouseEvent& WXUNUSED(event))
448{
449 // no special processing here
7e548f6b 450 return false;
c02ee97f
VZ
451}
452
b7005dfd 453#if defined(__WXMSW__) ||(defined(__WXMAC__) && wxOSX_USE_COCOA_OR_CARBON)
414f2513
RD
454void wxPopupTransientWindow::OnIdle(wxIdleEvent& event)
455{
456 event.Skip();
457
458 if (IsShown() && m_child)
459 {
5f9e369a
VZ
460 // Store the last mouse position to minimize the number of calls to
461 // wxFindWindowAtPoint() which are quite expensive.
462 static wxPoint s_posLast;
463 const wxPoint pos = wxGetMousePosition();
464 if ( pos != s_posLast )
414f2513 465 {
5f9e369a
VZ
466 s_posLast = pos;
467
468 wxWindow* const winUnderMouse = wxFindWindowAtPoint(pos);
469
470 // We release the mouse capture while the mouse is inside the popup
471 // itself to allow using it normally with the controls inside it.
472 if ( wxGetTopLevelParent(winUnderMouse) == this )
414f2513 473 {
5f9e369a
VZ
474 if ( m_child->HasCapture() )
475 {
476 m_child->ReleaseMouse();
477 }
414f2513 478 }
5f9e369a 479 else // And we reacquire it as soon as the mouse goes outside.
414f2513 480 {
5f9e369a
VZ
481 if ( !m_child->HasCapture() )
482 {
483 m_child->CaptureMouse();
484 }
414f2513 485 }
17a1ebd1 486 }
414f2513
RD
487 }
488}
0419fee9 489#endif // wxOSX/Carbon
414f2513
RD
490
491
a8132cd4 492#if wxUSE_COMBOBOX && defined(__WXUNIVERSAL__)
c02ee97f
VZ
493
494// ----------------------------------------------------------------------------
495// wxPopupComboWindow
496// ----------------------------------------------------------------------------
497
e0c83227
VZ
498BEGIN_EVENT_TABLE(wxPopupComboWindow, wxPopupTransientWindow)
499 EVT_KEY_DOWN(wxPopupComboWindow::OnKeyDown)
500END_EVENT_TABLE()
501
a57d600f 502wxPopupComboWindow::wxPopupComboWindow(wxComboCtrl *parent)
c02ee97f
VZ
503 : wxPopupTransientWindow(parent)
504{
505 m_combo = parent;
506}
507
a57d600f 508bool wxPopupComboWindow::Create(wxComboCtrl *parent)
c02ee97f
VZ
509{
510 m_combo = parent;
511
512 return wxPopupWindow::Create(parent);
513}
514
515void wxPopupComboWindow::PositionNearCombo()
516{
517 // the origin point must be in screen coords
c47addef 518 wxPoint ptOrigin = m_combo->ClientToScreen(wxPoint(0,0));
c02ee97f 519
89e7a223 520#if 0 //def __WXUNIVERSAL__
c02ee97f
VZ
521 // account for the fact that (0, 0) is not the top left corner of the
522 // window: there is also the border
523 wxRect rectBorders = m_combo->GetRenderer()->
524 GetBorderDimensions(m_combo->GetBorder());
525 ptOrigin.x -= rectBorders.x;
526 ptOrigin.y -= rectBorders.y;
527#endif // __WXUNIVERSAL__
528
529 // position below or above the combobox: the width is 0 to put it exactly
530 // below us, not to the left or to the right
531 Position(ptOrigin, wxSize(0, m_combo->GetSize().y));
532}
533
534void wxPopupComboWindow::OnDismiss()
535{
5d8a7943 536 m_combo->OnPopupDismiss(true);
c02ee97f
VZ
537}
538
e0c83227
VZ
539void wxPopupComboWindow::OnKeyDown(wxKeyEvent& event)
540{
3b7fa206 541 m_combo->ProcessWindowEvent(event);
e0c83227
VZ
542}
543
a8132cd4 544#endif // wxUSE_COMBOBOX && defined(__WXUNIVERSAL__)
c02ee97f
VZ
545
546// ----------------------------------------------------------------------------
547// wxPopupWindowHandler
548// ----------------------------------------------------------------------------
549
550void wxPopupWindowHandler::OnLeftDown(wxMouseEvent& event)
551{
552 // let the window have it first (we're the first event handler in the chain
553 // of handlers for this window)
554 if ( m_popup->ProcessLeftDown(event) )
555 {
556 return;
557 }
326c7ea8 558
c02ee97f
VZ
559 wxPoint pos = event.GetPosition();
560
af5c81b3 561 // in non-Univ ports the system manages scrollbars for us
9a6384ca 562#if defined(__WXUNIVERSAL__) && wxUSE_SCROLLBAR
3103e8a9 563 // scrollbar on which the click occurred
c02ee97f 564 wxWindow *sbar = NULL;
9a6384ca 565#endif // __WXUNIVERSAL__ && wxUSE_SCROLLBAR
c02ee97f
VZ
566
567 wxWindow *win = (wxWindow *)event.GetEventObject();
326c7ea8 568
c02ee97f
VZ
569 switch ( win->HitTest(pos.x, pos.y) )
570 {
571 case wxHT_WINDOW_OUTSIDE:
326c7ea8
VZ
572 {
573 // do the coords translation now as after DismissAndNotify()
574 // m_popup may be destroyed
575 wxMouseEvent event2(event);
576
577 m_popup->ClientToScreen(&event2.m_x, &event2.m_y);
578
579 // clicking outside a popup dismisses it
580 m_popup->DismissAndNotify();
581
582 // dismissing a tooltip shouldn't waste a click, i.e. you
583 // should be able to dismiss it and press the button with the
584 // same click, so repost this event to the window beneath us
17a1ebd1
VZ
585 wxWindow *winUnder = wxFindWindowAtPoint(event2.GetPosition());
586 if ( winUnder )
326c7ea8
VZ
587 {
588 // translate the event coords to the ones of the window
589 // which is going to get the event
17a1ebd1 590 winUnder->ScreenToClient(&event2.m_x, &event2.m_y);
326c7ea8 591
17a1ebd1 592 event2.SetEventObject(winUnder);
6aab9279 593 wxPostEvent(winUnder->GetEventHandler(), event2);
326c7ea8
VZ
594 }
595 }
c02ee97f
VZ
596 break;
597
9a6384ca 598#if defined(__WXUNIVERSAL__) && wxUSE_SCROLLBAR
c02ee97f
VZ
599 case wxHT_WINDOW_HORZ_SCROLLBAR:
600 sbar = win->GetScrollbar(wxHORIZONTAL);
601 break;
602
603 case wxHT_WINDOW_VERT_SCROLLBAR:
604 sbar = win->GetScrollbar(wxVERTICAL);
605 break;
9a6384ca 606#endif // __WXUNIVERSAL__ && wxUSE_SCROLLBAR
c02ee97f
VZ
607
608 default:
609 // forgot to update the switch after adding a new hit test code?
9a83f860 610 wxFAIL_MSG( wxT("unexpected HitTest() return value") );
c02ee97f
VZ
611 // fall through
612
613 case wxHT_WINDOW_CORNER:
614 // don't actually know if this one is good for anything, but let it
615 // pass just in case
616
617 case wxHT_WINDOW_INSIDE:
618 // let the normal processing take place
619 event.Skip();
620 break;
621 }
622
9a6384ca 623#if defined(__WXUNIVERSAL__) && wxUSE_SCROLLBAR
c02ee97f
VZ
624 if ( sbar )
625 {
626 // translate the event coordinates to the scrollbar ones
627 pos = sbar->ScreenToClient(win->ClientToScreen(pos));
628
629 // and give the event to it
630 wxMouseEvent event2 = event;
631 event2.m_x = pos.x;
632 event2.m_y = pos.y;
633
634 (void)sbar->GetEventHandler()->ProcessEvent(event2);
635 }
9a6384ca 636#endif // __WXUNIVERSAL__ && wxUSE_SCROLLBAR
c02ee97f
VZ
637}
638
0419fee9
VZ
639void
640wxPopupWindowHandler::OnCaptureLost(wxMouseCaptureLostEvent& WXUNUSED(event))
641{
642 m_popup->DismissAndNotify();
643
644 // There is no need to skip the event here, normally we've already dealt
645 // with the focus loss.
646}
647
c02ee97f
VZ
648// ----------------------------------------------------------------------------
649// wxPopupFocusHandler
650// ----------------------------------------------------------------------------
651
652void wxPopupFocusHandler::OnKillFocus(wxFocusEvent& event)
653{
60178eb4
VZ
654 // when we lose focus we always disappear - unless it goes to the popup (in
655 // which case we don't really lose it)
36a56c65
VS
656 wxWindow *win = event.GetWindow();
657 while ( win )
658 {
659 if ( win == m_popup )
660 return;
661 win = win->GetParent();
662 }
326c7ea8 663
36a56c65 664 m_popup->DismissAndNotify();
60178eb4 665}
54800df8 666
ffe42ca6 667void wxPopupFocusHandler::OnChar(wxKeyEvent& event)
60178eb4 668{
1295f134
VZ
669 // we can be associated with the popup itself in which case we should avoid
670 // infinite recursion
671 static int s_inside;
672 wxRecursionGuard guard(s_inside);
673 if ( guard.IsInside() )
674 {
675 event.Skip();
676 return;
677 }
678
60178eb4 679 // let the window have it first, it might process the keys
06077aaf 680 if ( !m_popup->GetEventHandler()->ProcessEvent(event) )
60178eb4
VZ
681 {
682 // by default, dismiss the popup
54800df8 683 m_popup->DismissAndNotify();
60178eb4 684 }
c02ee97f
VZ
685}
686
687#endif // wxUSE_POPUPWIN