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