1 /////////////////////////////////////////////////////////////////////////////
2 // Name: srx/x11/popupwin.cpp
4 // Author: Robert Roebling
5 // Copyright: (c) 1998 Robert Roebling
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // for compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
14 #include "wx/popupwin.h"
19 #include "wx/settings.h"
22 #include "wx/x11/private.h"
23 #include "X11/Xatom.h"
24 #include "X11/Xutil.h"
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
30 BEGIN_EVENT_TABLE(wxPopupWindow
,wxPopupWindowBase
)
33 wxPopupWindow::~wxPopupWindow()
37 bool wxPopupWindow::Create( wxWindow
*parent
, int style
)
39 if (!CreateBase( parent
, -1, wxDefaultPosition
, wxDefaultSize
, style
, wxDefaultValidator
, wxT("popup") ))
41 wxFAIL_MSG( wxT("wxPopupWindow creation failed") );
45 // All dialogs should really have this style
46 m_windowStyle
= style
;
47 m_windowStyle
|= wxTAB_TRAVERSAL
;
55 if (m_parent
) m_parent
->AddChild( this );
57 Display
*xdisplay
= wxGlobalDisplay();
58 int xscreen
= DefaultScreen( xdisplay
);
59 Visual
*xvisual
= DefaultVisual( xdisplay
, xscreen
);
60 Window xparent
= RootWindow( xdisplay
, xscreen
);
61 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
64 bool need_two_windows
=
65 ((( wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxSIMPLE_BORDER
| wxHSCROLL
| wxVSCROLL
) & m_windowStyle
) != 0);
67 bool need_two_windows
= false;
71 long xattributes_mask
= 0;
74 XSetWindowAttributes xattributes
;
75 long xattributes_mask
= 0;
77 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
78 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
80 m_foregroundColour
= *wxBLACK
;
81 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
83 xattributes_mask
|= CWBackPixel
;
84 xattributes
.background_pixel
= m_backgroundColour
.GetPixel();
86 xattributes_mask
|= CWBorderPixel
;
87 xattributes
.border_pixel
= BlackPixel( xdisplay
, xscreen
);
89 xattributes_mask
|= CWOverrideRedirect
| CWSaveUnder
;
90 xattributes
.override_redirect
= True
;
91 xattributes
.save_under
= True
;
93 xattributes_mask
|= CWEventMask
;
99 xattributes
.event_mask
=
100 ExposureMask
| StructureNotifyMask
| ColormapChangeMask
;
103 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos
.x
, pos
.y
, size
.x
, size
.y
,
104 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
107 XSelectInput( xdisplay
, xwindow
,
108 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
109 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
110 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
111 PropertyChangeMask
);
114 // Set background to None which will prevent X11 from clearing the
115 // background comletely.
116 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
118 m_mainWindow
= (WXWindow
) xwindow
;
119 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
121 // XMapWindow( xdisplay, xwindow );
123 xattributes
.event_mask
=
124 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
125 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
126 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
127 PropertyChangeMask
| VisibilityChangeMask
;
130 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
137 if (HasFlag( wxSIMPLE_BORDER
))
149 xwindow
= XCreateWindow( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
150 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
152 // Set background to None which will prevent X11 from clearing the
153 // background comletely.
154 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
157 XSelectInput( xdisplay
, xwindow
,
158 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
159 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
160 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
161 PropertyChangeMask
);
164 m_clientWindow
= (WXWindow
) xwindow
;
165 wxAddClientWindowToTable( xwindow
, (wxWindow
*) this );
168 XMapWindow( xdisplay
, xwindow
);
174 xattributes
.event_mask
=
175 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
176 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
177 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
178 PropertyChangeMask
| VisibilityChangeMask
;
181 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos
.x
, pos
.y
, size
.x
, size
.y
,
182 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
185 XSelectInput( xdisplay
, xwindow
,
186 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
187 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
188 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
189 PropertyChangeMask
);
192 // Set background to None which will prevent X11 from clearing the
193 // background comletely.
194 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
196 m_mainWindow
= (WXWindow
) xwindow
;
197 m_clientWindow
= (WXWindow
) xwindow
;
198 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
201 // XMapWindow( xdisplay, xwindow );
204 XSetTransientForHint( xdisplay
, (Window
) m_mainWindow
, xparent
);
208 wxSetWMDecorations( (Window
) m_mainWindow
, 0 );
211 wm_hints
.flags
= InputHint
| StateHint
/* | WindowGroupHint */;
212 wm_hints
.input
= True
;
213 wm_hints
.initial_state
= NormalState
;
214 XSetWMHints( xdisplay
, (Window
) m_mainWindow
, &wm_hints
);
220 void wxPopupWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
222 wxWindowX11::DoMoveWindow( x
, y
, width
, height
);
225 void wxPopupWindow::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
227 wxWindowX11::DoSetSize(x
, y
, width
, height
, sizeFlags
);
230 bool wxPopupWindow::Show( bool show
)
232 bool ret
= wxWindowX11::Show( show
);
239 #endif // wxUSE_POPUPWIN