]> git.saurik.com Git - wxWidgets.git/blame - src/x11/popupwin.cpp
Applied #15375 to stop event-sending in generic wxSpinCtrl ctor (eco)
[wxWidgets.git] / src / x11 / popupwin.cpp
CommitLineData
1246e28f 1/////////////////////////////////////////////////////////////////////////////
7520f3da 2// Name: srx/x11/popupwin.cpp
1246e28f
JS
3// Purpose:
4// Author: Robert Roebling
1246e28f 5// Copyright: (c) 1998 Robert Roebling
65571936 6// Licence: wxWindows licence
1246e28f
JS
7/////////////////////////////////////////////////////////////////////////////
8
7520f3da
WS
9// for compilers that support precompilation, includes "wx.h".
10#include "wx/wxprec.h"
1246e28f
JS
11
12#if wxUSE_POPUPWIN
13
14#include "wx/popupwin.h"
e4db172a
WS
15
16#ifndef WX_PRECOMP
17 #include "wx/log.h"
670f9935 18 #include "wx/app.h"
9eddec69 19 #include "wx/settings.h"
e4db172a
WS
20#endif
21
1246e28f 22#include "wx/x11/private.h"
6a44bffd
JS
23#include "X11/Xatom.h"
24#include "X11/Xutil.h"
1246e28f
JS
25
26//-----------------------------------------------------------------------------
27// wxPopupWindow
28//-----------------------------------------------------------------------------
29
30BEGIN_EVENT_TABLE(wxPopupWindow,wxPopupWindowBase)
31END_EVENT_TABLE()
32
6033bbc1
JS
33wxPopupWindow::~wxPopupWindow()
34{
35}
36
1246e28f
JS
37bool wxPopupWindow::Create( wxWindow *parent, int style )
38{
2b5f62a0 39 if (!CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, wxT("popup") ))
1246e28f
JS
40 {
41 wxFAIL_MSG( wxT("wxPopupWindow creation failed") );
7520f3da 42 return false;
1246e28f
JS
43 }
44
45 // All dialogs should really have this style
b28d3abf 46 m_windowStyle = style;
1246e28f 47 m_windowStyle |= wxTAB_TRAVERSAL;
7520f3da 48
1b0b798d
RR
49 wxPoint pos( 20,20 );
50 wxSize size( 20,20 );
97bb82cc
RR
51 wxPoint pos2 = pos;
52 wxSize size2 = size;
1246e28f 53
b28d3abf 54 m_parent = parent;
1246e28f
JS
55 if (m_parent) m_parent->AddChild( this );
56
b28d3abf
JS
57 Display *xdisplay = wxGlobalDisplay();
58 int xscreen = DefaultScreen( xdisplay );
59 Visual *xvisual = DefaultVisual( xdisplay, xscreen );
60 Window xparent = RootWindow( xdisplay, xscreen );
6033bbc1 61 Colormap cm = DefaultColormap( xdisplay, xscreen);
7520f3da 62
97bb82cc 63#if wxUSE_TWO_WINDOWS
7520f3da 64 bool need_two_windows =
97bb82cc 65 ((( wxSUNKEN_BORDER | wxRAISED_BORDER | wxSIMPLE_BORDER | wxHSCROLL | wxVSCROLL ) & m_windowStyle) != 0);
788519c6 66#else
7520f3da 67 bool need_two_windows = false;
97bb82cc
RR
68#endif
69
8601b2e1
JS
70#if wxUSE_NANOX
71 long xattributes_mask = 0;
72#else
7520f3da 73
b28d3abf 74 XSetWindowAttributes xattributes;
97bb82cc 75 long xattributes_mask = 0;
6033bbc1
JS
76
77 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
78 m_backgroundColour.CalcPixel( (WXColormap) cm);
7520f3da 79
6033bbc1
JS
80 m_foregroundColour = *wxBLACK;
81 m_foregroundColour.CalcPixel( (WXColormap) cm);
7520f3da 82
97bb82cc
RR
83 xattributes_mask |= CWBackPixel;
84 xattributes.background_pixel = m_backgroundColour.GetPixel();
7520f3da 85
97bb82cc 86 xattributes_mask |= CWBorderPixel;
b28d3abf 87 xattributes.border_pixel = BlackPixel( xdisplay, xscreen );
7520f3da 88
97bb82cc 89 xattributes_mask |= CWOverrideRedirect | CWSaveUnder;
0d1dff01
RR
90 xattributes.override_redirect = True;
91 xattributes.save_under = True;
7520f3da 92
97bb82cc 93 xattributes_mask |= CWEventMask;
8601b2e1 94#endif
7520f3da 95
97bb82cc
RR
96 if (need_two_windows)
97 {
8601b2e1 98#if !wxUSE_NANOX
7520f3da 99 xattributes.event_mask =
97bb82cc 100 ExposureMask | StructureNotifyMask | ColormapChangeMask;
8601b2e1 101#endif
7520f3da
WS
102
103 Window xwindow = XCreateWindow( xdisplay, xparent, pos.x, pos.y, size.x, size.y,
97bb82cc 104 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
8601b2e1 105
7520f3da 106#if wxUSE_NANOX
8601b2e1
JS
107 XSelectInput( xdisplay, xwindow,
108 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
109 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
110 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
111 PropertyChangeMask );
112#endif
7520f3da 113
8601b2e1
JS
114 // Set background to None which will prevent X11 from clearing the
115 // background comletely.
97bb82cc 116 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
7520f3da 117
97bb82cc
RR
118 m_mainWindow = (WXWindow) xwindow;
119 wxAddWindowToTable( xwindow, (wxWindow*) this );
7520f3da 120
e97d2576 121 // XMapWindow( xdisplay, xwindow );
7520f3da
WS
122#if !wxUSE_NANOX
123 xattributes.event_mask =
97bb82cc
RR
124 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
125 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
126 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
127 PropertyChangeMask | VisibilityChangeMask ;
8601b2e1 128#endif
7520f3da 129
97bb82cc
RR
130 if (HasFlag( wxSUNKEN_BORDER) || HasFlag( wxRAISED_BORDER))
131 {
132 pos2.x = 2;
133 pos2.y = 2;
134 size2.x -= 4;
135 size2.y -= 4;
136 } else
137 if (HasFlag( wxSIMPLE_BORDER ))
138 {
139 pos2.x = 1;
140 pos2.y = 1;
141 size2.x -= 2;
142 size2.y -= 2;
143 } else
144 {
145 pos2.x = 0;
146 pos2.y = 0;
147 }
7520f3da
WS
148
149 xwindow = XCreateWindow( xdisplay, xwindow, pos2.x, pos2.y, size2.x, size2.y,
97bb82cc 150 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
7520f3da 151
8601b2e1
JS
152 // Set background to None which will prevent X11 from clearing the
153 // background comletely.
97bb82cc 154 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
7520f3da
WS
155
156#if wxUSE_NANOX
8601b2e1
JS
157 XSelectInput( xdisplay, xwindow,
158 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
159 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
160 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
161 PropertyChangeMask );
162#endif
7520f3da 163
97bb82cc
RR
164 m_clientWindow = (WXWindow) xwindow;
165 wxAddClientWindowToTable( xwindow, (wxWindow*) this );
7520f3da
WS
166
167 m_isShown = false;
97bb82cc
RR
168 XMapWindow( xdisplay, xwindow );
169 }
170 else
171 {
8601b2e1
JS
172 // One window
173#if !wxUSE_NANOX
7520f3da 174 xattributes.event_mask =
97bb82cc
RR
175 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
176 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
177 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
178 PropertyChangeMask | VisibilityChangeMask ;
8601b2e1 179#endif
7520f3da
WS
180
181 Window xwindow = XCreateWindow( xdisplay, xparent, pos.x, pos.y, size.x, size.y,
97bb82cc 182 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
8601b2e1
JS
183
184#if wxUSE_NANOX
185 XSelectInput( xdisplay, xwindow,
186 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
187 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
188 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
189 PropertyChangeMask );
190#endif
7520f3da 191
8601b2e1
JS
192 // Set background to None which will prevent X11 from clearing the
193 // background comletely.
97bb82cc 194 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
7520f3da 195
97bb82cc
RR
196 m_mainWindow = (WXWindow) xwindow;
197 m_clientWindow = (WXWindow) xwindow;
198 wxAddWindowToTable( xwindow, (wxWindow*) this );
7520f3da
WS
199
200 m_isShown = false;
e97d2576 201 // XMapWindow( xdisplay, xwindow );
97bb82cc 202 }
ba696cfa 203
97bb82cc 204 XSetTransientForHint( xdisplay, (Window) m_mainWindow, xparent );
5e29f97a 205
70b8ab77
JS
206#if wxUSE_NANOX
207 // Switch off WM
97bb82cc 208 wxSetWMDecorations( (Window) m_mainWindow, 0 );
70b8ab77 209#else
86fd8bda 210 XWMHints wm_hints;
b28d3abf
JS
211 wm_hints.flags = InputHint | StateHint /* | WindowGroupHint */;
212 wm_hints.input = True;
213 wm_hints.initial_state = NormalState;
97bb82cc 214 XSetWMHints( xdisplay, (Window) m_mainWindow, &wm_hints);
788519c6 215#endif
7520f3da
WS
216
217 return true;
1246e28f
JS
218}
219
27398643 220void wxPopupWindow::DoMoveWindow(int x, int y, int width, int height )
1246e28f 221{
27398643 222 wxWindowX11::DoMoveWindow( x, y, width, height );
1246e28f
JS
223}
224
225void wxPopupWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags )
226{
b28d3abf 227 wxWindowX11::DoSetSize(x, y, width, height, sizeFlags);
1246e28f 228}
b28d3abf 229
1246e28f
JS
230bool wxPopupWindow::Show( bool show )
231{
86fd8bda
RR
232 bool ret = wxWindowX11::Show( show );
233
90f501b1 234 Raise();
7520f3da 235
86fd8bda 236 return ret;
1246e28f
JS
237}
238
239#endif // wxUSE_POPUPWIN