]> git.saurik.com Git - wxWidgets.git/blame - src/x11/popupwin.cpp
updates for OpenVMS compile support
[wxWidgets.git] / src / x11 / popupwin.cpp
CommitLineData
1246e28f 1/////////////////////////////////////////////////////////////////////////////
7520f3da 2// Name: srx/x11/popupwin.cpp
1246e28f
JS
3// Purpose:
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
65571936 7// Licence: wxWindows licence
1246e28f
JS
8/////////////////////////////////////////////////////////////////////////////
9
7520f3da
WS
10// for compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
1246e28f
JS
12
13#if wxUSE_POPUPWIN
14
15#include "wx/popupwin.h"
e4db172a
WS
16
17#ifndef WX_PRECOMP
18 #include "wx/log.h"
670f9935 19 #include "wx/app.h"
9eddec69 20 #include "wx/settings.h"
e4db172a
WS
21#endif
22
1246e28f 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") );
7520f3da 43 return false;
1246e28f
JS
44 }
45
46 // All dialogs should really have this style
b28d3abf 47 m_windowStyle = style;
1246e28f 48 m_windowStyle |= wxTAB_TRAVERSAL;
7520f3da 49
1b0b798d
RR
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);
7520f3da 63
97bb82cc 64#if wxUSE_TWO_WINDOWS
7520f3da 65 bool need_two_windows =
97bb82cc 66 ((( wxSUNKEN_BORDER | wxRAISED_BORDER | wxSIMPLE_BORDER | wxHSCROLL | wxVSCROLL ) & m_windowStyle) != 0);
788519c6 67#else
7520f3da 68 bool need_two_windows = false;
97bb82cc
RR
69#endif
70
8601b2e1
JS
71#if wxUSE_NANOX
72 long xattributes_mask = 0;
73#else
7520f3da 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);
7520f3da 80
6033bbc1
JS
81 m_foregroundColour = *wxBLACK;
82 m_foregroundColour.CalcPixel( (WXColormap) cm);
7520f3da 83
97bb82cc
RR
84 xattributes_mask |= CWBackPixel;
85 xattributes.background_pixel = m_backgroundColour.GetPixel();
7520f3da 86
97bb82cc 87 xattributes_mask |= CWBorderPixel;
b28d3abf 88 xattributes.border_pixel = BlackPixel( xdisplay, xscreen );
7520f3da 89
97bb82cc 90 xattributes_mask |= CWOverrideRedirect | CWSaveUnder;
0d1dff01
RR
91 xattributes.override_redirect = True;
92 xattributes.save_under = True;
7520f3da 93
97bb82cc 94 xattributes_mask |= CWEventMask;
8601b2e1 95#endif
7520f3da 96
97bb82cc
RR
97 if (need_two_windows)
98 {
8601b2e1 99#if !wxUSE_NANOX
7520f3da 100 xattributes.event_mask =
97bb82cc 101 ExposureMask | StructureNotifyMask | ColormapChangeMask;
8601b2e1 102#endif
7520f3da
WS
103
104 Window xwindow = XCreateWindow( xdisplay, xparent, pos.x, pos.y, size.x, size.y,
97bb82cc 105 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
8601b2e1 106
7520f3da 107#if wxUSE_NANOX
8601b2e1
JS
108 XSelectInput( xdisplay, xwindow,
109 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
110 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
111 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
112 PropertyChangeMask );
113#endif
7520f3da 114
8601b2e1
JS
115 // Set background to None which will prevent X11 from clearing the
116 // background comletely.
97bb82cc 117 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
7520f3da 118
97bb82cc
RR
119 m_mainWindow = (WXWindow) xwindow;
120 wxAddWindowToTable( xwindow, (wxWindow*) this );
7520f3da 121
e97d2576 122 // XMapWindow( xdisplay, xwindow );
7520f3da
WS
123#if !wxUSE_NANOX
124 xattributes.event_mask =
97bb82cc
RR
125 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
126 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
127 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
128 PropertyChangeMask | VisibilityChangeMask ;
8601b2e1 129#endif
7520f3da 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 }
7520f3da
WS
149
150 xwindow = XCreateWindow( xdisplay, xwindow, pos2.x, pos2.y, size2.x, size2.y,
97bb82cc 151 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
7520f3da 152
8601b2e1
JS
153 // Set background to None which will prevent X11 from clearing the
154 // background comletely.
97bb82cc 155 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
7520f3da
WS
156
157#if wxUSE_NANOX
8601b2e1
JS
158 XSelectInput( xdisplay, xwindow,
159 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
160 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
161 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
162 PropertyChangeMask );
163#endif
7520f3da 164
97bb82cc
RR
165 m_clientWindow = (WXWindow) xwindow;
166 wxAddClientWindowToTable( xwindow, (wxWindow*) this );
7520f3da
WS
167
168 m_isShown = false;
97bb82cc
RR
169 XMapWindow( xdisplay, xwindow );
170 }
171 else
172 {
8601b2e1
JS
173 // One window
174#if !wxUSE_NANOX
7520f3da 175 xattributes.event_mask =
97bb82cc
RR
176 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
177 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
178 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
179 PropertyChangeMask | VisibilityChangeMask ;
8601b2e1 180#endif
7520f3da
WS
181
182 Window xwindow = XCreateWindow( xdisplay, xparent, pos.x, pos.y, size.x, size.y,
97bb82cc 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
7520f3da 192
8601b2e1
JS
193 // Set background to None which will prevent X11 from clearing the
194 // background comletely.
97bb82cc 195 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
7520f3da 196
97bb82cc
RR
197 m_mainWindow = (WXWindow) xwindow;
198 m_clientWindow = (WXWindow) xwindow;
199 wxAddWindowToTable( xwindow, (wxWindow*) this );
7520f3da
WS
200
201 m_isShown = false;
e97d2576 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 216#endif
7520f3da
WS
217
218 return true;
1246e28f
JS
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();
7520f3da 236
86fd8bda 237 return ret;
1246e28f
JS
238}
239
240#endif // wxUSE_POPUPWIN