]> git.saurik.com Git - wxWidgets.git/blame - src/msw/popupwin.cpp
Correct making the newly inserted menu item owner drawn in some cases.
[wxWidgets.git] / src / msw / popupwin.cpp
CommitLineData
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
e49d97e6 7// Copyright: (c) 2002 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
526954c5 8// Licence: wxWindows licence
e49d97e6
VZ
9///////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
e49d97e6
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
7520f3da
WS
26#if wxUSE_POPUPWIN
27
e49d97e6
VZ
28#ifndef WX_PRECOMP
29#endif //WX_PRECOMP
30
31#include "wx/popupwin.h"
32
24b3cc2c 33#include "wx/msw/private.h" // for GetDesktopWindow()
220c6d43 34
e49d97e6
VZ
35// ============================================================================
36// implementation
37// ============================================================================
38
39bool wxPopupWindow::Create(wxWindow *parent, int flags)
40{
eefe6d4b
VZ
41 // popup windows are created hidden by default
42 Hide();
43
e49d97e6 44 return wxPopupWindowBase::Create(parent) &&
078cf5cb 45 wxWindow::Create(parent, wxID_ANY,
e49d97e6
VZ
46 wxDefaultPosition, wxDefaultSize,
47 flags | wxPOPUP_WINDOW);
48}
49
50void 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
60WXDWORD wxPopupWindow::MSWGetStyle(long flags, WXDWORD *exstyle) const
61{
24b3cc2c 62 // we only honour the border flags, the others don't make sense for us
e49d97e6
VZ
63 WXDWORD style = wxWindow::MSWGetStyle(flags & wxBORDER_MASK, exstyle);
64
e49d97e6
VZ
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
24b3cc2c 74WXHWND wxPopupWindow::MSWGetParent() const
7e25f59e 75{
24b3cc2c
VZ
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
4676948b
JS
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
24b3cc2c 88 return (WXHWND)::GetDesktopWindow();
4676948b 89#endif
7e25f59e
VZ
90}
91
af2372b9
VZ
92void 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
25b1b442
JS
101bool wxPopupWindow::Show(bool show)
102{
c649a6ab 103 if ( !wxWindowMSW::Show(show) )
078cf5cb 104 return false;
25b1b442 105
25b1b442
JS
106 if ( show )
107 {
108 // raise to top of z order
c649a6ab 109 if (!::SetWindowPos(GetHwnd(), HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE))
25b1b442 110 {
9a83f860 111 wxLogLastError(wxT("SetWindowPos"));
25b1b442 112 }
82ceade7
RD
113
114 // and set it as the foreground window so the mouse can be captured
115 ::SetForegroundWindow(GetHwnd());
25b1b442
JS
116 }
117
078cf5cb 118 return true;
25b1b442
JS
119}
120
3080bf59 121#endif // #if wxUSE_POPUPWIN