1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gtkframe.hxx,v $
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>
38 #include <gdk/gdkkeysyms.h>
39 #include <tools/postx.h>
41 #include <vcl/salframe.hxx>
42 #include <vcl/sysdata.hxx>
50 class GtkSalFrame
: public SalFrame
52 static const int nMaxGraphics
= 2;
56 GtkSalGraphics
* pGraphics
;
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
82 guint16 hardware_keycode
;
85 PreviousKeyPress (GdkEventKey
*event
)
96 window
= event
->window
;
97 send_event
= event
->send_event
;
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
),
110 state( rPrev
.state
),
111 keyval( rPrev
.keyval
),
112 hardware_keycode( rPrev
.hardware_keycode
),
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
;
136 SalExtTextInputEvent m_aInputEvent
;
137 std::vector
< USHORT
> m_aInputFlags
;
139 IMHandler( GtkSalFrame
* );
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
;
164 GtkWidget
* m_pWindow
;
165 GdkWindow
* m_pForeignParent
;
166 GdkNativeWindow m_aForeignParentWindow
;
167 GdkWindow
* m_pForeignTopLevel
;
168 GdkNativeWindow m_aForeignTopLevelWindow
;
169 Pixmap m_hBackgroundPixmap
;
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
;
186 bool m_bSingleAltPress
;
189 bool m_bSendModChangeOnRelease
;
190 bool m_bWindowIsGtkPlug
;
193 IMHandler
* m_pIMHandler
;
197 Rectangle m_aRestorePosSize
;
199 GdkRegion
* m_pRegion
;
201 void Init( SalFrame
* pParent
, ULONG nStyle
);
202 void Init( SystemParentData
* pSysData
);
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
);
223 void SetDefaultSize();
224 void setAutoLock( bool bLock
);
225 void setScreenSaverTimeout( int nTimeout
);
227 void doKeyCallback( guint state
,
229 guint16 hardware_keycode
,
232 sal_Unicode aOrigCode
,
238 GdkNativeWindow
findTopLevelSystemWindow( GdkNativeWindow aWindow
);
240 static int m_nFloats
;
242 bool isFloatGrabWindow() const
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 )
254 nMask
|= SAL_FRAME_STYLE_PLUG
;
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
);
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
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
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
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
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()
403 GType
ooo_fixed_get_type( void );
407 #endif //_VCL_GTKFRAME_HXX