]>
Commit | Line | Data |
---|---|---|
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 | m_isShown = FALSE; | |
132 | XMapWindow( xdisplay, xwindow ); | |
133 | } | |
134 | else | |
135 | { | |
136 | xattributes.event_mask = | |
137 | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | | |
138 | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | | |
139 | KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask | | |
140 | PropertyChangeMask | VisibilityChangeMask ; | |
141 | ||
142 | Window xwindow = XCreateWindow( xdisplay, xparent, pos.x, pos.y, size.x, size.y, | |
143 | 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes ); | |
144 | ||
145 | XSetWindowBackgroundPixmap( xdisplay, xwindow, None ); | |
146 | ||
147 | m_mainWindow = (WXWindow) xwindow; | |
148 | m_clientWindow = (WXWindow) xwindow; | |
149 | wxAddWindowToTable( xwindow, (wxWindow*) this ); | |
150 | ||
151 | m_isShown = FALSE; | |
152 | // XMapWindow( xdisplay, xwindow ); | |
153 | } | |
154 | #else | |
155 | fixme | |
156 | #endif | |
157 | ||
158 | XSetTransientForHint( xdisplay, (Window) m_mainWindow, xparent ); | |
159 | ||
160 | #if wxUSE_NANOX | |
161 | // Switch off WM | |
162 | wxSetWMDecorations( (Window) m_mainWindow, 0 ); | |
163 | #else | |
164 | XWMHints wm_hints; | |
165 | wm_hints.flags = InputHint | StateHint /* | WindowGroupHint */; | |
166 | wm_hints.input = True; | |
167 | wm_hints.initial_state = NormalState; | |
168 | XSetWMHints( xdisplay, (Window) m_mainWindow, &wm_hints); | |
169 | #endif | |
170 | ||
171 | return TRUE; | |
172 | } | |
173 | ||
174 | void wxPopupWindow::DoMoveWindow(int x, int y, int width, int height ) | |
175 | { | |
176 | wxWindowX11::DoMoveWindow( x, y, width, height ); | |
177 | } | |
178 | ||
179 | void wxPopupWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags ) | |
180 | { | |
181 | wxWindowX11::DoSetSize(x, y, width, height, sizeFlags); | |
182 | } | |
183 | ||
184 | bool wxPopupWindow::Show( bool show ) | |
185 | { | |
186 | bool ret = wxWindowX11::Show( show ); | |
187 | ||
188 | Raise(); | |
189 | ||
190 | return ret; | |
191 | } | |
192 | ||
193 | #endif // wxUSE_POPUPWIN |