merge the formfield patch from ooo-build
[ooovba.git] / vcl / unx / inc / plugins / gtk / gtkframe.hxx
blobafd258b156d8a08c7a848b9dae99788850ac434e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gtkframe.hxx,v $
10 * $Revision: 1.35 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _VCL_GTKFRAME_HXX
32 #define _VCL_GTKFRAME_HXX
34 #include <tools/prex.h>
35 #include <gtk/gtk.h>
36 #include <gdk/gdk.h>
37 #include <gdk/gdkx.h>
38 #include <gdk/gdkkeysyms.h>
39 #include <tools/postx.h>
41 #include <vcl/salframe.hxx>
42 #include <vcl/sysdata.hxx>
44 #include <list>
45 #include <vector>
47 class GtkSalGraphics;
48 class GtkSalDisplay;
50 class GtkSalFrame : public SalFrame
52 static const int nMaxGraphics = 2;
54 struct GraphicsHolder
56 GtkSalGraphics* pGraphics;
57 bool bInUse;
58 GraphicsHolder()
59 : pGraphics( NULL ),
60 bInUse( false )
62 ~GraphicsHolder();
65 struct IMHandler
67 //--------------------------------------------------------
68 // Not all GTK Input Methods swallow key release
69 // events. Since they swallow the key press events and we
70 // are left with the key release events, we need to
71 // manually swallow those. To do this, we keep a list of
72 // the previous 10 key press events in each GtkSalFrame
73 // and when we get a key release that matches one of the
74 // key press events in our list, we swallow it.
75 struct PreviousKeyPress
77 GdkWindow *window;
78 gint8 send_event;
79 guint32 time;
80 guint state;
81 guint keyval;
82 guint16 hardware_keycode;
83 guint8 group;
85 PreviousKeyPress (GdkEventKey *event)
86 : window (NULL),
87 send_event (0),
88 time (0),
89 state (0),
90 keyval (0),
91 hardware_keycode (0),
92 group (0)
94 if (event)
96 window = event->window;
97 send_event = event->send_event;
98 time = event->time;
99 state = event->state;
100 keyval = event->keyval;
101 hardware_keycode = event->hardware_keycode;
102 group = event->group;
106 PreviousKeyPress( const PreviousKeyPress& rPrev )
107 : window( rPrev.window ),
108 send_event( rPrev.send_event ),
109 time( rPrev.time ),
110 state( rPrev.state ),
111 keyval( rPrev.keyval ),
112 hardware_keycode( rPrev.hardware_keycode ),
113 group( rPrev.group )
116 bool operator== (GdkEventKey *event) const
118 return (event != NULL)
119 && (event->window == window)
120 && (event->send_event == send_event)
121 && (event->state == state)
122 && (event->keyval == keyval)
123 && (event->hardware_keycode == hardware_keycode)
124 && (event->group == group)
125 && (event->time - time < 3)
131 GtkSalFrame* m_pFrame;
132 std::list< PreviousKeyPress > m_aPrevKeyPresses;
133 int m_nPrevKeyPresses; // avoid using size()
134 GtkIMContext* m_pIMContext;
135 bool m_bFocused;
136 SalExtTextInputEvent m_aInputEvent;
137 std::vector< USHORT > m_aInputFlags;
139 IMHandler( GtkSalFrame* );
140 ~IMHandler();
142 void createIMContext();
143 void deleteIMContext();
144 void updateIMSpotLocation();
145 void setInputContext( SalInputContext* pContext );
146 void endExtTextInput( USHORT nFlags );
147 bool handleKeyEvent( GdkEventKey* pEvent );
148 void focusChanged( bool bFocusIn );
150 void doCallEndExtTextInput();
151 void sendEmptyCommit();
154 static void signalIMCommit( GtkIMContext*, gchar*, gpointer );
155 static gboolean signalIMDeleteSurrounding( GtkIMContext*, gint, gint, gpointer );
156 static void signalIMPreeditChanged( GtkIMContext*, gpointer );
157 static void signalIMPreeditEnd( GtkIMContext*, gpointer );
158 static void signalIMPreeditStart( GtkIMContext*, gpointer );
159 static gboolean signalIMRetrieveSurrounding( GtkIMContext*, gpointer );
161 friend struct IMHandler;
163 int m_nScreen;
164 GtkWidget* m_pWindow;
165 GdkWindow* m_pForeignParent;
166 GdkNativeWindow m_aForeignParentWindow;
167 GdkWindow* m_pForeignTopLevel;
168 GdkNativeWindow m_aForeignTopLevelWindow;
169 Pixmap m_hBackgroundPixmap;
170 ULONG m_nStyle;
171 SalExtStyle m_nExtStyle;
172 GtkFixed* m_pFixedContainer;
173 GtkSalFrame* m_pParent;
174 std::list< GtkSalFrame* > m_aChildren;
175 GdkWindowState m_nState;
176 SystemEnvData m_aSystemData;
177 GraphicsHolder m_aGraphics[ nMaxGraphics ];
178 USHORT m_nKeyModifiers;
179 GdkCursor *m_pCurrentCursor;
180 GdkVisibilityState m_nVisibility;
181 PointerStyle m_ePointerStyle;
182 int m_nSavedScreenSaverTimeout;
183 guint m_nGSSCookie;
184 int m_nWorkArea;
185 bool m_bFullscreen;
186 bool m_bSingleAltPress;
187 bool m_bDefaultPos;
188 bool m_bDefaultSize;
189 bool m_bSendModChangeOnRelease;
190 bool m_bWindowIsGtkPlug;
191 String m_aTitle;
193 IMHandler* m_pIMHandler;
195 Size m_aMaxSize;
196 Size m_aMinSize;
197 Rectangle m_aRestorePosSize;
199 GdkRegion* m_pRegion;
201 void Init( SalFrame* pParent, ULONG nStyle );
202 void Init( SystemParentData* pSysData );
203 void InitCommon();
205 // signals
206 static gboolean signalButton( GtkWidget*, GdkEventButton*, gpointer );
207 static void signalStyleSet( GtkWidget*, GtkStyle* pPrevious, gpointer );
208 static gboolean signalExpose( GtkWidget*, GdkEventExpose*, gpointer );
209 static gboolean signalFocus( GtkWidget*, GdkEventFocus*, gpointer );
210 static gboolean signalMap( GtkWidget*, GdkEvent*, gpointer );
211 static gboolean signalUnmap( GtkWidget*, GdkEvent*, gpointer );
212 static gboolean signalConfigure( GtkWidget*, GdkEventConfigure*, gpointer );
213 static gboolean signalMotion( GtkWidget*, GdkEventMotion*, gpointer );
214 static gboolean signalKey( GtkWidget*, GdkEventKey*, gpointer );
215 static gboolean signalDelete( GtkWidget*, GdkEvent*, gpointer );
216 static gboolean signalState( GtkWidget*, GdkEvent*, gpointer );
217 static gboolean signalScroll( GtkWidget*, GdkEvent*, gpointer );
218 static gboolean signalCrossing( GtkWidget*, GdkEventCrossing*, gpointer );
219 static gboolean signalVisibility( GtkWidget*, GdkEventVisibility*, gpointer );
220 static void signalDestroy( GtkObject*, gpointer );
222 void Center();
223 void SetDefaultSize();
224 void setAutoLock( bool bLock );
225 void setScreenSaverTimeout( int nTimeout );
227 void doKeyCallback( guint state,
228 guint keyval,
229 guint16 hardware_keycode,
230 guint8 group,
231 guint32 time,
232 sal_Unicode aOrigCode,
233 bool bDown,
234 bool bSendRelease
238 GdkNativeWindow findTopLevelSystemWindow( GdkNativeWindow aWindow );
240 static int m_nFloats;
242 bool isFloatGrabWindow() const
244 return
245 (m_nStyle & SAL_FRAME_STYLE_FLOAT) && // only a float can be floatgrab
246 !(m_nStyle & SAL_FRAME_STYLE_TOOLTIP) && // tool tips are not
247 !(m_nStyle & SAL_FRAME_STYLE_OWNERDRAWDECORATION); // toolbars are also not
250 bool isChild( bool bPlug = true, bool bSysChild = true )
252 ULONG nMask = 0;
253 if( bPlug )
254 nMask |= SAL_FRAME_STYLE_PLUG;
255 if( bSysChild )
256 nMask |= SAL_FRAME_STYLE_SYSTEMCHILD;
257 return (m_nStyle & nMask) != 0;
260 void resizeWindow( long nWidth, long nHeight );
261 void moveWindow( long nX, long nY );
263 Size calcDefaultSize();
265 void setMinMaxSize();
266 void createNewWindow( XLIB_Window aParent, bool bXEmbed, int nScreen );
267 void askForXEmbedFocus( sal_Int32 nTimecode );
268 public:
269 GtkSalFrame( SalFrame* pParent, ULONG nStyle );
270 GtkSalFrame( SystemParentData* pSysData );
272 // dispatches an event, returns true if dispatched
273 // and false else; if true was returned the event should
274 // be swallowed
275 bool Dispatch( const XEvent* pEvent );
276 void grabPointer( BOOL bGrab, BOOL bOwnerEvents = FALSE );
278 GtkSalDisplay* getDisplay();
279 GdkDisplay* getGdkDisplay();
280 GtkWidget* getWindow() const { return m_pWindow; }
281 GtkFixed* getFixedContainer() const { return m_pFixedContainer; }
282 GdkWindow* getForeignParent() const { return m_pForeignParent; }
283 GdkNativeWindow getForeignParentWindow() const { return m_aForeignParentWindow; }
284 GdkWindow* getForeignTopLevel() const { return m_pForeignTopLevel; }
285 GdkNativeWindow getForeignTopLevelWindow() const { return m_aForeignTopLevelWindow; }
286 GdkVisibilityState getVisibilityState() const
287 { return m_nVisibility; }
288 Pixmap getBackgroundPixmap() const { return m_hBackgroundPixmap; }
289 int getScreenNumber() const { return m_nScreen; }
290 void updateScreenNumber();
292 void moveToScreen( int nScreen );
294 virtual ~GtkSalFrame();
296 // SalGraphics or NULL, but two Graphics for all SalFrames
297 // must be returned
298 virtual SalGraphics* GetGraphics();
299 virtual void ReleaseGraphics( SalGraphics* pGraphics );
301 // Event must be destroyed, when Frame is destroyed
302 // When Event is called, SalInstance::Yield() must be returned
303 virtual BOOL PostEvent( void* pData );
305 virtual void SetTitle( const XubString& rTitle );
306 virtual void SetIcon( USHORT nIcon );
307 virtual void SetMenu( SalMenu *pSalMenu );
308 virtual void DrawMenuBar();
310 virtual void SetExtendedFrameStyle( SalExtStyle nExtStyle );
311 // Before the window is visible, a resize event
312 // must be sent with the correct size
313 virtual void Show( BOOL bVisible, BOOL bNoActivate = FALSE );
314 virtual void Enable( BOOL bEnable );
315 // Set ClientSize and Center the Window to the desktop
316 // and send/post a resize message
317 virtual void SetMinClientSize( long nWidth, long nHeight );
318 virtual void SetMaxClientSize( long nWidth, long nHeight );
319 virtual void SetPosSize( long nX, long nY, long nWidth, long nHeight, USHORT nFlags );
320 virtual void GetClientSize( long& rWidth, long& rHeight );
321 virtual void GetWorkArea( Rectangle& rRect );
322 virtual SalFrame* GetParent() const;
323 virtual void SetWindowState( const SalFrameState* pState );
324 virtual BOOL GetWindowState( SalFrameState* pState );
325 virtual void ShowFullScreen( BOOL bFullScreen, sal_Int32 nDisplay );
326 // Enable/Disable ScreenSaver, SystemAgents, ...
327 virtual void StartPresentation( BOOL bStart );
328 // Show Window over all other Windows
329 virtual void SetAlwaysOnTop( BOOL bOnTop );
331 // Window to top and grab focus
332 virtual void ToTop( USHORT nFlags );
334 // this function can call with the same
335 // pointer style
336 virtual void SetPointer( PointerStyle ePointerStyle );
337 virtual void CaptureMouse( BOOL bMouse );
338 virtual void SetPointerPos( long nX, long nY );
340 // flush output buffer
341 using SalFrame::Flush;
342 virtual void Flush();
343 // flush output buffer, wait till outstanding operations are done
344 virtual void Sync();
346 virtual void SetInputContext( SalInputContext* pContext );
347 virtual void EndExtTextInput( USHORT nFlags );
349 virtual String GetKeyName( USHORT nKeyCode );
350 virtual String GetSymbolKeyName( const XubString& rFontName, USHORT nKeyCode );
351 virtual BOOL MapUnicodeToKeyCode( sal_Unicode aUnicode, LanguageType aLangType, KeyCode& rKeyCode );
353 // returns the input language used for the last key stroke
354 // may be LANGUAGE_DONTKNOW if not supported by the OS
355 virtual LanguageType GetInputLanguage();
357 virtual SalBitmap* SnapShot();
359 virtual void UpdateSettings( AllSettings& rSettings );
361 virtual void Beep( SoundType eSoundType );
363 // returns system data (most prominent: window handle)
364 virtual const SystemEnvData* GetSystemData() const;
367 // get current modifier and button mask
368 virtual SalPointerState GetPointerState();
370 virtual SalIndicatorState GetIndicatorState();
372 virtual void SimulateKeyPress( USHORT nKeyCode );
374 // set new parent window
375 virtual void SetParent( SalFrame* pNewParent );
376 // reparent window to act as a plugin; implementation
377 // may choose to use a new system window internally
378 // return false to indicate failure
379 virtual bool SetPluginParent( SystemParentData* pNewParent );
381 virtual void SetBackgroundBitmap( SalBitmap* );
383 virtual void SetScreenNumber( unsigned int );
385 // shaped system windows
386 // set clip region to none (-> rectangular windows, normal state)
387 virtual void ResetClipRegion();
388 // start setting the clipregion consisting of nRects rectangles
389 virtual void BeginSetClipRegion( ULONG nRects );
390 // add a rectangle to the clip region
391 virtual void UnionClipRegion( long nX, long nY, long nWidth, long nHeight );
392 // done setting up the clipregion
393 virtual void EndSetClipRegion();
395 static GtkSalFrame *getFromWindow( GtkWindow *pWindow );
399 #define OOO_TYPE_FIXED ooo_fixed_get_type()
401 extern "C" {
403 GType ooo_fixed_get_type( void );
405 } // extern "C"
407 #endif //_VCL_GTKFRAME_HXX