]>
Commit | Line | Data |
---|---|---|
e49d97e6 | 1 | /////////////////////////////////////////////////////////////////////////////// |
7520f3da | 2 | // Name: src/msw/popupwin.cpp |
e49d97e6 VZ |
3 | // Purpose: implements wxPopupWindow for MSW |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 08.05.02 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2002 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
65571936 | 9 | // License: wxWindows licence |
e49d97e6 VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
e49d97e6 VZ |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
7520f3da WS |
27 | #if wxUSE_POPUPWIN |
28 | ||
e49d97e6 VZ |
29 | #ifndef WX_PRECOMP |
30 | #endif //WX_PRECOMP | |
31 | ||
32 | #include "wx/popupwin.h" | |
33 | ||
24b3cc2c | 34 | #include "wx/msw/private.h" // for GetDesktopWindow() |
220c6d43 | 35 | |
e49d97e6 VZ |
36 | // ============================================================================ |
37 | // implementation | |
38 | // ============================================================================ | |
39 | ||
40 | bool wxPopupWindow::Create(wxWindow *parent, int flags) | |
41 | { | |
eefe6d4b VZ |
42 | // popup windows are created hidden by default |
43 | Hide(); | |
44 | ||
e49d97e6 | 45 | return wxPopupWindowBase::Create(parent) && |
078cf5cb | 46 | wxWindow::Create(parent, wxID_ANY, |
e49d97e6 VZ |
47 | wxDefaultPosition, wxDefaultSize, |
48 | flags | wxPOPUP_WINDOW); | |
49 | } | |
50 | ||
51 | void wxPopupWindow::DoGetPosition(int *x, int *y) const | |
52 | { | |
53 | // the position of a "top level" window such as this should be in | |
54 | // screen coordinates, not in the client ones which MSW gives us | |
55 | // (because we are a child window) | |
56 | wxPopupWindowBase::DoGetPosition(x, y); | |
57 | ||
58 | GetParent()->ClientToScreen(x, y); | |
59 | } | |
60 | ||
61 | WXDWORD wxPopupWindow::MSWGetStyle(long flags, WXDWORD *exstyle) const | |
62 | { | |
24b3cc2c | 63 | // we only honour the border flags, the others don't make sense for us |
e49d97e6 VZ |
64 | WXDWORD style = wxWindow::MSWGetStyle(flags & wxBORDER_MASK, exstyle); |
65 | ||
e49d97e6 VZ |
66 | if ( exstyle ) |
67 | { | |
68 | // a popup window floats on top of everything | |
69 | *exstyle |= WS_EX_TOPMOST | WS_EX_TOOLWINDOW; | |
70 | } | |
71 | ||
72 | return style; | |
73 | } | |
74 | ||
24b3cc2c | 75 | WXHWND wxPopupWindow::MSWGetParent() const |
7e25f59e | 76 | { |
24b3cc2c VZ |
77 | // we must be a child of the desktop to be able to extend beyond the parent |
78 | // window client area (like the comboboxes drop downs do) | |
79 | // | |
80 | // NB: alternative implementation would be to use WS_POPUP instead of | |
81 | // WS_CHILD but then showing a popup would deactivate the parent which | |
82 | // is ugly and working around this, although possible, is even more | |
83 | // ugly | |
4676948b JS |
84 | // GetDesktopWindow() is not always supported on WinCE, and if |
85 | // it is, it often returns NULL. | |
86 | #ifdef __WXWINCE__ | |
87 | return 0; | |
88 | #else | |
24b3cc2c | 89 | return (WXHWND)::GetDesktopWindow(); |
4676948b | 90 | #endif |
7e25f59e VZ |
91 | } |
92 | ||
25b1b442 JS |
93 | bool wxPopupWindow::Show(bool show) |
94 | { | |
c649a6ab | 95 | if ( !wxWindowMSW::Show(show) ) |
078cf5cb | 96 | return false; |
25b1b442 | 97 | |
25b1b442 JS |
98 | if ( show ) |
99 | { | |
100 | // raise to top of z order | |
c649a6ab | 101 | if (!::SetWindowPos(GetHwnd(), HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE)) |
25b1b442 JS |
102 | { |
103 | wxLogLastError(_T("SetWindowPos")); | |
104 | } | |
82ceade7 RD |
105 | |
106 | // and set it as the foreground window so the mouse can be captured | |
107 | ::SetForegroundWindow(GetHwnd()); | |
25b1b442 JS |
108 | } |
109 | ||
078cf5cb | 110 | return true; |
25b1b442 JS |
111 | } |
112 | ||
3080bf59 | 113 | #endif // #if wxUSE_POPUPWIN |