1
///////////////////////////////////////////////////////////////////////////////
2
// Name: src/msw/popupwin.cpp
3
// Purpose: implements wxPopupWindow for MSW
4
// Author: Vadim Zeitlin
7
// Copyright: (c) 2002 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
8
// Licence: wxWindows licence
9
///////////////////////////////////////////////////////////////////////////////
11
// ============================================================================
13
// ============================================================================
15
// ----------------------------------------------------------------------------
17
// ----------------------------------------------------------------------------
19
// For compilers that support precompilation, includes "wx.h".
20
#include "wx/wxprec.h"
31
#include "wx/popupwin.h"
33
#include "wx/msw/private.h" // for GetDesktopWindow()
35
// ============================================================================
37
// ============================================================================
39
bool wxPopupWindow::Create(wxWindow *parent, int flags)
41
// popup windows are created hidden by default
44
return wxPopupWindowBase::Create(parent) &&
45
wxWindow::Create(parent, wxID_ANY,
46
wxDefaultPosition, wxDefaultSize,
47
flags | wxPOPUP_WINDOW);
50
void wxPopupWindow::DoGetPosition(int *x, int *y) const
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);
57
GetParent()->ClientToScreen(x, y);
60
WXDWORD wxPopupWindow::MSWGetStyle(long flags, WXDWORD *exstyle) const
62
// we only honour the border flags, the others don't make sense for us
63
WXDWORD style = wxWindow::MSWGetStyle(flags & wxBORDER_MASK, exstyle);
67
// a popup window floats on top of everything
68
*exstyle |= WS_EX_TOPMOST | WS_EX_TOOLWINDOW;
74
WXHWND wxPopupWindow::MSWGetParent() const
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)
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
83
// GetDesktopWindow() is not always supported on WinCE, and if
84
// it is, it often returns NULL.
88
return (WXHWND)::GetDesktopWindow();
92
void wxPopupWindow::SetFocus()
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.
101
bool wxPopupWindow::Show(bool show)
103
if ( !wxWindowMSW::Show(show) )
108
// raise to top of z order
109
if (!::SetWindowPos(GetHwnd(), HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE))
111
wxLogLastError(wxT("SetWindowPos"));
114
// and set it as the foreground window so the mouse can be captured
115
::SetForegroundWindow(GetHwnd());
121
#endif // #if wxUSE_POPUPWIN