]> git.saurik.com Git - wxWidgets.git/blob - src/x11/popupwin.cpp
a1546f56302c407aff0312a681dee7d92cd943b7
[wxWidgets.git] / src / x11 / popupwin.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: popupwin.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifdef __GNUG__
11 #pragma implementation "popupwin.h"
12 #endif
13
14 #include "wx/defs.h"
15
16 #if wxUSE_POPUPWIN
17
18 #include "wx/popupwin.h"
19 #include "wx/app.h"
20
21 #include "wx/x11/private.h"
22 #include "X11/Xatom.h"
23 #include "X11/Xutil.h"
24
25 //-----------------------------------------------------------------------------
26 // wxPopupWindow
27 //-----------------------------------------------------------------------------
28
29 BEGIN_EVENT_TABLE(wxPopupWindow,wxPopupWindowBase)
30 END_EVENT_TABLE()
31
32 IMPLEMENT_DYNAMIC_CLASS(wxPopupWindow, wxWindow)
33
34 bool wxPopupWindow::Create( wxWindow *parent, int style )
35 {
36 if (!CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, "popup" ))
37 {
38 wxFAIL_MSG( wxT("wxPopupWindow creation failed") );
39 return FALSE;
40 }
41
42 // All dialogs should really have this style
43 m_windowStyle = style;
44 m_windowStyle |= wxTAB_TRAVERSAL;
45
46 wxPoint pos( 20,20 );
47 wxSize size( 20,20 );
48 wxPoint pos2 = pos;
49 wxSize size2 = size;
50
51 m_parent = parent;
52 if (m_parent) m_parent->AddChild( this );
53
54 Display *xdisplay = wxGlobalDisplay();
55 int xscreen = DefaultScreen( xdisplay );
56 Visual *xvisual = DefaultVisual( xdisplay, xscreen );
57 Window xparent = RootWindow( xdisplay, xscreen );
58
59 #if !wxUSE_NANOX
60
61 #if wxUSE_TWO_WINDOWS
62 bool need_two_windows =
63 ((( wxSUNKEN_BORDER | wxRAISED_BORDER | wxSIMPLE_BORDER | wxHSCROLL | wxVSCROLL ) & m_windowStyle) != 0);
64 #else
65 bool need_two_windows = FALSE;
66 #endif
67
68 XSetWindowAttributes xattributes;
69 long xattributes_mask = 0;
70
71 xattributes_mask |= CWBackPixel;
72 xattributes.background_pixel = m_backgroundColour.GetPixel();
73
74 xattributes_mask |= CWBorderPixel;
75 xattributes.border_pixel = BlackPixel( xdisplay, xscreen );
76
77 xattributes_mask |= CWOverrideRedirect | CWSaveUnder;
78 xattributes.override_redirect = True;
79 xattributes.save_under = True;
80
81 xattributes_mask |= CWEventMask;
82
83 if (need_two_windows)
84 {
85 xattributes.event_mask =
86 ExposureMask | StructureNotifyMask | ColormapChangeMask;
87
88 Window xwindow = XCreateWindow( xdisplay, xparent, pos.x, pos.y, size.x, size.y,
89 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
90
91 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
92
93 m_mainWindow = (WXWindow) xwindow;
94 wxAddWindowToTable( xwindow, (wxWindow*) this );
95
96 XMapWindow( xdisplay, xwindow );
97
98 xattributes.event_mask =
99 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
100 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
101 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
102 PropertyChangeMask | VisibilityChangeMask ;
103
104 if (HasFlag( wxSUNKEN_BORDER) || HasFlag( wxRAISED_BORDER))
105 {
106 pos2.x = 2;
107 pos2.y = 2;
108 size2.x -= 4;
109 size2.y -= 4;
110 } else
111 if (HasFlag( wxSIMPLE_BORDER ))
112 {
113 pos2.x = 1;
114 pos2.y = 1;
115 size2.x -= 2;
116 size2.y -= 2;
117 } else
118 {
119 pos2.x = 0;
120 pos2.y = 0;
121 }
122
123 xwindow = XCreateWindow( xdisplay, xwindow, pos2.x, pos2.y, size2.x, size2.y,
124 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
125
126 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
127
128 m_clientWindow = (WXWindow) xwindow;
129 wxAddClientWindowToTable( xwindow, (wxWindow*) this );
130
131 XMapWindow( xdisplay, xwindow );
132 }
133 else
134 {
135 xattributes.event_mask =
136 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
137 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
138 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
139 PropertyChangeMask | VisibilityChangeMask ;
140
141 Window xwindow = XCreateWindow( xdisplay, xparent, pos.x, pos.y, size.x, size.y,
142 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
143
144 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
145
146 m_mainWindow = (WXWindow) xwindow;
147 m_clientWindow = (WXWindow) xwindow;
148 wxAddWindowToTable( xwindow, (wxWindow*) this );
149
150 XMapWindow( xdisplay, xwindow );
151 }
152 #else
153 fixme
154 #endif
155
156 XSetTransientForHint( xdisplay, (Window) m_mainWindow, xparent );
157
158 #if wxUSE_NANOX
159 // Switch off WM
160 wxSetWMDecorations( (Window) m_mainWindow, 0 );
161 #else
162 XWMHints wm_hints;
163 wm_hints.flags = InputHint | StateHint /* | WindowGroupHint */;
164 wm_hints.input = True;
165 wm_hints.initial_state = NormalState;
166 XSetWMHints( xdisplay, (Window) m_mainWindow, &wm_hints);
167 #endif
168
169 return TRUE;
170 }
171
172 void wxPopupWindow::DoMoveWindow(int x, int y, int width, int height )
173 {
174 wxWindowX11::DoMoveWindow( x, y, width, height );
175 }
176
177 void wxPopupWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags )
178 {
179 wxWindowX11::DoSetSize(x, y, width, height, sizeFlags);
180 }
181
182 bool wxPopupWindow::Show( bool show )
183 {
184 bool ret = wxWindowX11::Show( show );
185
186 Raise();
187
188 return ret;
189 }
190
191 #endif // wxUSE_POPUPWIN