1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _VCL_GTKFRAME_HXX 25 #define _VCL_GTKFRAME_HXX 26 27 #include <tools/prex.h> 28 #include <gtk/gtk.h> 29 #include <gdk/gdk.h> 30 #include <gdk/gdkx.h> 31 #include <gdk/gdkkeysyms.h> 32 #include <tools/postx.h> 33 34 #include <salframe.hxx> 35 #include <vcl/sysdata.hxx> 36 37 #include "tools/link.hxx" 38 39 #include <list> 40 #include <vector> 41 42 class GtkSalGraphics; 43 class GtkSalDisplay; 44 45 class GtkSalFrame : public SalFrame 46 { 47 static const int nMaxGraphics = 2; 48 49 struct GraphicsHolder 50 { 51 GtkSalGraphics* pGraphics; 52 bool bInUse; 53 GraphicsHolder() 54 : pGraphics( NULL ), 55 bInUse( false ) 56 {} 57 ~GraphicsHolder(); 58 }; 59 60 struct IMHandler 61 { 62 //-------------------------------------------------------- 63 // Not all GTK Input Methods swallow key release 64 // events. Since they swallow the key press events and we 65 // are left with the key release events, we need to 66 // manually swallow those. To do this, we keep a list of 67 // the previous 10 key press events in each GtkSalFrame 68 // and when we get a key release that matches one of the 69 // key press events in our list, we swallow it. 70 struct PreviousKeyPress 71 { 72 GdkWindow *window; 73 gint8 send_event; 74 guint32 time; 75 guint state; 76 guint keyval; 77 guint16 hardware_keycode; 78 guint8 group; 79 80 PreviousKeyPress (GdkEventKey *event) 81 : window (NULL), 82 send_event (0), 83 time (0), 84 state (0), 85 keyval (0), 86 hardware_keycode (0), 87 group (0) 88 { 89 if (event) 90 { 91 window = event->window; 92 send_event = event->send_event; 93 time = event->time; 94 state = event->state; 95 keyval = event->keyval; 96 hardware_keycode = event->hardware_keycode; 97 group = event->group; 98 } 99 } 100 101 PreviousKeyPress( const PreviousKeyPress& rPrev ) 102 : window( rPrev.window ), 103 send_event( rPrev.send_event ), 104 time( rPrev.time ), 105 state( rPrev.state ), 106 keyval( rPrev.keyval ), 107 hardware_keycode( rPrev.hardware_keycode ), 108 group( rPrev.group ) 109 {} 110 111 bool operator== (GdkEventKey *event) const 112 { 113 return (event != NULL) 114 && (event->window == window) 115 && (event->send_event == send_event) 116 && (event->state == state) 117 && (event->keyval == keyval) 118 && (event->hardware_keycode == hardware_keycode) 119 && (event->group == group) 120 && (event->time - time < 3) 121 ; 122 } 123 }; 124 125 126 GtkSalFrame* m_pFrame; 127 std::list< PreviousKeyPress > m_aPrevKeyPresses; 128 int m_nPrevKeyPresses; // avoid using size() 129 GtkIMContext* m_pIMContext; 130 bool m_bFocused; 131 bool m_bPreeditJustChanged; 132 SalExtTextInputEvent m_aInputEvent; 133 std::vector< sal_uInt16 > m_aInputFlags; 134 135 IMHandler( GtkSalFrame* ); 136 ~IMHandler(); 137 138 void createIMContext(); 139 void deleteIMContext(); 140 void updateIMSpotLocation(); 141 void setInputContext( SalInputContext* pContext ); 142 void endExtTextInput( sal_uInt16 nFlags ); 143 bool handleKeyEvent( GdkEventKey* pEvent ); 144 void focusChanged( bool bFocusIn ); 145 146 void doCallEndExtTextInput(); 147 void sendEmptyCommit(); 148 149 150 static void signalIMCommit( GtkIMContext*, gchar*, gpointer ); 151 static gboolean signalIMDeleteSurrounding( GtkIMContext*, gint, gint, gpointer ); 152 static void signalIMPreeditChanged( GtkIMContext*, gpointer ); 153 static void signalIMPreeditEnd( GtkIMContext*, gpointer ); 154 static void signalIMPreeditStart( GtkIMContext*, gpointer ); 155 static gboolean signalIMRetrieveSurrounding( GtkIMContext*, gpointer ); 156 }; 157 friend struct IMHandler; 158 159 int m_nScreen; 160 GtkWidget* m_pWindow; 161 GdkWindow* m_pForeignParent; 162 GdkNativeWindow m_aForeignParentWindow; 163 GdkWindow* m_pForeignTopLevel; 164 GdkNativeWindow m_aForeignTopLevelWindow; 165 Pixmap m_hBackgroundPixmap; 166 sal_uLong m_nStyle; 167 SalExtStyle m_nExtStyle; 168 GtkFixed* m_pFixedContainer; 169 GtkSalFrame* m_pParent; 170 std::list< GtkSalFrame* > m_aChildren; 171 GdkWindowState m_nState; 172 SystemEnvData m_aSystemData; 173 GraphicsHolder m_aGraphics[ nMaxGraphics ]; 174 sal_uInt16 m_nKeyModifiers; 175 GdkCursor *m_pCurrentCursor; 176 GdkVisibilityState m_nVisibility; 177 PointerStyle m_ePointerStyle; 178 int m_nSavedScreenSaverTimeout; 179 guint m_nGSMCookie; 180 int m_nWorkArea; 181 bool m_bFullscreen; 182 bool m_bSingleAltPress; 183 bool m_bDefaultPos; 184 bool m_bDefaultSize; 185 bool m_bSendModChangeOnRelease; 186 bool m_bWindowIsGtkPlug; 187 bool m_bSetFocusOnMap; 188 String m_aTitle; 189 190 IMHandler* m_pIMHandler; 191 192 Size m_aMaxSize; 193 Size m_aMinSize; 194 Rectangle m_aRestorePosSize; 195 196 GdkRegion* m_pRegion; 197 198 void Init( SalFrame* pParent, sal_uLong nStyle ); 199 void Init( SystemParentData* pSysData ); 200 void InitCommon(); 201 202 // signals 203 static gboolean signalButton( GtkWidget*, GdkEventButton*, gpointer ); 204 static void signalStyleSet( GtkWidget*, GtkStyle* pPrevious, gpointer ); 205 static gboolean signalExpose( GtkWidget*, GdkEventExpose*, gpointer ); 206 static gboolean signalFocus( GtkWidget*, GdkEventFocus*, gpointer ); 207 static gboolean signalMap( GtkWidget*, GdkEvent*, gpointer ); 208 static gboolean signalUnmap( GtkWidget*, GdkEvent*, gpointer ); 209 static gboolean signalConfigure( GtkWidget*, GdkEventConfigure*, gpointer ); 210 static gboolean signalMotion( GtkWidget*, GdkEventMotion*, gpointer ); 211 static gboolean signalKey( GtkWidget*, GdkEventKey*, gpointer ); 212 static gboolean signalDelete( GtkWidget*, GdkEvent*, gpointer ); 213 static gboolean signalState( GtkWidget*, GdkEvent*, gpointer ); 214 static gboolean signalScroll( GtkWidget*, GdkEvent*, gpointer ); 215 static gboolean signalCrossing( GtkWidget*, GdkEventCrossing*, gpointer ); 216 static gboolean signalVisibility( GtkWidget*, GdkEventVisibility*, gpointer ); 217 static void signalDestroy( GtkObject*, gpointer ); 218 219 void Center(); 220 void SetDefaultSize(); 221 void setAutoLock( bool bLock ); 222 void setScreenSaverTimeout( int nTimeout ); 223 224 void doKeyCallback( guint state, 225 guint keyval, 226 guint16 hardware_keycode, 227 guint8 group, 228 guint32 time, 229 sal_Unicode aOrigCode, 230 bool bDown, 231 bool bSendRelease 232 ); 233 234 235 GdkNativeWindow findTopLevelSystemWindow( GdkNativeWindow aWindow ); 236 237 static int m_nFloats; 238 239 bool isFloatGrabWindow() const 240 { 241 return 242 (m_nStyle & SAL_FRAME_STYLE_FLOAT) && // only a float can be floatgrab 243 !(m_nStyle & SAL_FRAME_STYLE_TOOLTIP) && // tool tips are not 244 !(m_nStyle & SAL_FRAME_STYLE_OWNERDRAWDECORATION) && // toolbars are also not 245 !(m_nStyle & SAL_FRAME_STYLE_FLOAT_FOCUSABLE); // focusable floats are not 246 } 247 248 bool isChild( bool bPlug = true, bool bSysChild = true ) 249 { 250 sal_uLong nMask = 0; 251 if( bPlug ) 252 nMask |= SAL_FRAME_STYLE_PLUG; 253 if( bSysChild ) 254 nMask |= SAL_FRAME_STYLE_SYSTEMCHILD; 255 return (m_nStyle & nMask) != 0; 256 } 257 258 void resizeWindow( long nWidth, long nHeight ); 259 void moveWindow( long nX, long nY ); 260 261 Size calcDefaultSize(); 262 263 void setMinMaxSize(); 264 void createNewWindow( XLIB_Window aParent, bool bXEmbed, int nScreen ); 265 void askForXEmbedFocus( sal_Int32 nTimecode ); 266 267 DECL_LINK( ImplDelayedFullScreenHdl, void* ); 268 public: 269 GtkSalFrame( SalFrame* pParent, sal_uLong nStyle ); 270 GtkSalFrame( SystemParentData* pSysData ); 271 272 // Dispatches an XEvent; true means handled and swallowed. 273 bool dispatchXEvent( const XEvent* pEvent ); 274 275 // Legacy wrapper: true means continue, false means swallowed. 276 bool Dispatch( const XEvent* pEvent ); 277 void grabPointer( sal_Bool bGrab, sal_Bool bOwnerEvents = sal_False ); 278 279 GtkSalDisplay* getDisplay(); 280 GdkDisplay* getGdkDisplay(); 281 GtkWidget* getWindow() const { return m_pWindow; } 282 GtkFixed* getFixedContainer() const { return m_pFixedContainer; } 283 GdkWindow* getForeignParent() const { return m_pForeignParent; } 284 GdkNativeWindow getForeignParentWindow() const { return m_aForeignParentWindow; } 285 GdkWindow* getForeignTopLevel() const { return m_pForeignTopLevel; } 286 GdkNativeWindow getForeignTopLevelWindow() const { return m_aForeignTopLevelWindow; } 287 GdkVisibilityState getVisibilityState() const 288 { return m_nVisibility; } 289 Pixmap getBackgroundPixmap() const { return m_hBackgroundPixmap; } 290 int getScreenNumber() const { return m_nScreen; } 291 void updateScreenNumber(); 292 293 void moveToScreen( int nScreen ); 294 295 virtual ~GtkSalFrame(); 296 297 // SalGraphics or NULL, but two Graphics for all SalFrames 298 // must be returned 299 virtual SalGraphics* GetGraphics(); 300 virtual void ReleaseGraphics( SalGraphics* pGraphics ); 301 302 // Event must be destroyed, when Frame is destroyed 303 // When Event is called, SalInstance::Yield() must be returned 304 virtual sal_Bool PostEvent( void* pData ); 305 306 virtual void SetTitle( const XubString& rTitle ); 307 virtual void SetIcon( sal_uInt16 nIcon ); 308 virtual void SetMenu( SalMenu *pSalMenu ); 309 virtual void DrawMenuBar(); 310 311 virtual void SetExtendedFrameStyle( SalExtStyle nExtStyle ); 312 // Before the window is visible, a resize event 313 // must be sent with the correct size 314 virtual void Show( sal_Bool bVisible, sal_Bool bNoActivate = sal_False ); 315 virtual void Enable( sal_Bool bEnable ); 316 // Set ClientSize and Center the Window to the desktop 317 // and send/post a resize message 318 virtual void SetMinClientSize( long nWidth, long nHeight ); 319 virtual void SetMaxClientSize( long nWidth, long nHeight ); 320 virtual void SetPosSize( long nX, long nY, long nWidth, long nHeight, sal_uInt16 nFlags ); 321 virtual void GetClientSize( long& rWidth, long& rHeight ); 322 virtual void GetWorkArea( Rectangle& rRect ); 323 virtual SalFrame* GetParent() const; 324 virtual void SetWindowState( const SalFrameState* pState ); 325 virtual sal_Bool GetWindowState( SalFrameState* pState ); 326 virtual void ShowFullScreen( sal_Bool bFullScreen, sal_Int32 nDisplay ); 327 // Enable/Disable ScreenSaver, SystemAgents, ... 328 virtual void StartPresentation( sal_Bool bStart ); 329 // Show Window over all other Windows 330 virtual void SetAlwaysOnTop( sal_Bool bOnTop ); 331 332 // Window to top and grab focus 333 virtual void ToTop( sal_uInt16 nFlags ); 334 335 // this function can call with the same 336 // pointer style 337 virtual void SetPointer( PointerStyle ePointerStyle ); 338 virtual void CaptureMouse( sal_Bool bMouse ); 339 virtual void SetPointerPos( long nX, long nY ); 340 341 // flush output buffer 342 using SalFrame::Flush; 343 virtual void Flush(); 344 // flush output buffer, wait till outstanding operations are done 345 virtual void Sync(); 346 347 virtual void SetInputContext( SalInputContext* pContext ); 348 virtual void EndExtTextInput( sal_uInt16 nFlags ); 349 350 virtual String GetKeyName( sal_uInt16 nKeyCode ); 351 virtual String GetSymbolKeyName( const XubString& rFontName, sal_uInt16 nKeyCode ); 352 virtual sal_Bool MapUnicodeToKeyCode( sal_Unicode aUnicode, LanguageType aLangType, KeyCode& rKeyCode ); 353 354 // returns the input language used for the last key stroke 355 // may be LANGUAGE_DONTKNOW if not supported by the OS 356 virtual LanguageType GetInputLanguage(); 357 358 virtual SalBitmap* SnapShot(); 359 360 virtual void UpdateSettings( AllSettings& rSettings ); 361 362 virtual void Beep( SoundType eSoundType ); 363 364 // returns system data (most prominent: window handle) 365 virtual const SystemEnvData* GetSystemData() const; 366 367 368 // get current modifier and button mask 369 virtual SalPointerState GetPointerState(); 370 371 // set new parent window 372 virtual void SetParent( SalFrame* pNewParent ); 373 // reparent window to act as a plugin; implementation 374 // may choose to use a new system window internally 375 // return false to indicate failure 376 virtual bool SetPluginParent( SystemParentData* pNewParent ); 377 378 virtual void SetBackgroundBitmap( SalBitmap* ); 379 380 virtual void SetScreenNumber( unsigned int ); 381 382 // shaped system windows 383 // set clip region to none (-> rectangular windows, normal state) 384 virtual void ResetClipRegion(); 385 // start setting the clipregion consisting of nRects rectangles 386 virtual void BeginSetClipRegion( sal_uLong nRects ); 387 // add a rectangle to the clip region 388 virtual void UnionClipRegion( long nX, long nY, long nWidth, long nHeight ); 389 // done setting up the clipregion 390 virtual void EndSetClipRegion(); 391 392 static GtkSalFrame *getFromWindow( GtkWindow *pWindow ); 393 }; 394 395 396 #define OOO_TYPE_FIXED ooo_fixed_get_type() 397 398 extern "C" { 399 400 GType ooo_fixed_get_type( void ); 401 402 } // extern "C" 403 404 #endif //_VCL_GTKFRAME_HXX 405