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