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