Added shared private declarations header privx.h, utils.cpp now shared
[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
49 m_parent = parent;
50 if (m_parent) m_parent->AddChild( this );
51
52 wxTopLevelWindows.Append(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 XSetWindowAttributes xattributes;
60 XSizeHints size_hints;
61 XWMHints wm_hints;
62
63 long xattributes_mask =
64 CWOverrideRedirect |
65 CWBorderPixel | CWBackPixel;
66 xattributes.background_pixel = BlackPixel( xdisplay, xscreen );
67 xattributes.border_pixel = BlackPixel( xdisplay, xscreen );
68
69 // Trying True in order to stop WM decorating it
70 //xattributes.override_redirect = False;
71 xattributes.override_redirect = TRUE;
72
73 Window xwindow = XCreateWindow( xdisplay, xparent, pos.x, pos.y, size.x, size.y,
74 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
75
76 XSelectInput( xdisplay, xwindow,
77 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
78 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
79 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
80 PropertyChangeMask );
81
82 m_mainWidget = (WXWindow) xwindow;
83 wxAddWindowToTable( xwindow, (wxWindow*) this );
84
85 // Probably shouldn't be here for an unmanaged window
86 //XSetTransientForHint( xdisplay, xwindow, xparent );
87
88 // TODO: Will these calls cause decoration??
89
90 size_hints.flags = PSize;
91 size_hints.width = size.x;
92 size_hints.height = size.y;
93 XSetWMNormalHints( xdisplay, xwindow, &size_hints);
94
95 wm_hints.flags = InputHint | StateHint /* | WindowGroupHint */;
96 wm_hints.input = True;
97 wm_hints.initial_state = NormalState;
98 XSetWMHints( xdisplay, xwindow, &wm_hints);
99
100 // No decorations for this window
101 #if 0
102 Atom wm_delete_window = XInternAtom( xdisplay, "WM_DELETE_WINDOW", False);
103 XSetWMProtocols( xdisplay, xwindow, &wm_delete_window, 1);
104
105 wxSetWMDecorations((Window) GetMainWindow(), style);
106 #endif
107
108 return TRUE;
109 }
110
111 void wxPopupWindow::DoMoveWindow(int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(width), int WXUNUSED(height) )
112 {
113 wxFAIL_MSG( wxT("DoMoveWindow called for wxPopupWindow") );
114 }
115
116 void wxPopupWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags )
117 {
118 wxWindowX11::DoSetSize(x, y, width, height, sizeFlags);
119 }
120
121 bool wxPopupWindow::Show( bool show )
122 {
123 return wxWindowX11::Show( show );
124 }
125
126 #endif // wxUSE_POPUPWIN