Avoid potential negative array index access to cached text.
[LibreOffice.git] / vcl / inc / unx / salframe.h
bloba6603f6777f32b8bee697803b487ba6fc7efcc2e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #pragma once
22 #include <X11/Xlib.h>
24 #include <unx/saltype.h>
25 #include <unx/saldisp.hxx>
26 #include <unx/sessioninhibitor.hxx>
27 #include <salframe.hxx>
28 #include <salwtype.hxx>
30 #include <vcl/ptrstyle.hxx>
31 #include <vcl/sysdata.hxx>
32 #include <vcl/timer.hxx>
34 #include <list>
36 class X11SalGraphics;
37 class SalI18N_InputContext;
39 namespace vcl_sal { class WMAdaptor; class NetWMAdaptor; class GnomeWMAdaptor; }
41 // X11SalFrame
42 enum class X11ShowState
44 Unknown = -1,
45 Minimized = 0,
46 Normal = 1,
47 Hidden = 2
50 enum class WMWindowType
52 Normal,
53 ModelessDialogue,
54 Utility,
55 Splash,
56 Toolbar,
57 Dock
60 class X11SalFrame final : public SalFrame
62 friend class vcl_sal::WMAdaptor;
63 friend class vcl_sal::NetWMAdaptor;
64 friend class vcl_sal::GnomeWMAdaptor;
66 X11SalFrame* mpParent; // pointer to parent frame
67 // which should never obscure this frame
68 bool mbTransientForRoot;
69 std::list< X11SalFrame* > maChildren; // List of child frames
71 SalDisplay *pDisplay_;
72 SalX11Screen m_nXScreen;
73 ::Window mhWindow;
74 cairo_surface_t* mpSurface;
75 ::Window mhShellWindow;
76 ::Window mhForeignParent;
77 // window to fall back to when no longer in fullscreen mode
78 ::Window mhStackingWindow;
79 // window to listen for CirculateNotify events
81 Cursor hCursor_;
82 int nCaptured_; // is captured
84 std::unique_ptr<X11SalGraphics> pGraphics_; // current frame graphics
85 std::unique_ptr<X11SalGraphics> pFreeGraphics_; // first free frame graphics
87 bool mbSendExtKeyModChange;
88 ModKeyFlags mnExtKeyMod;
90 X11ShowState nShowState_; // show state
91 int nWidth_; // client width
92 int nHeight_; // client height
93 AbsoluteScreenPixelRectangle maRestorePosSize;
94 SalFrameStyleFlags nStyle_;
95 SalExtStyle mnExtStyle;
96 bool bAlwaysOnTop_;
97 bool bViewable_;
98 bool bMapped_;
99 bool bDefaultPosition_; // client is centered initially
100 bool m_bXEmbed;
101 int nVisibility_;
102 int m_nWorkArea;
103 bool m_bSetFocusOnMap;
105 SessionManagerInhibitor maSessionManagerInhibitor;
106 tools::Rectangle maPaintRegion;
108 Timer maAlwaysOnTopRaiseTimer;
110 // data for WMAdaptor
111 WMWindowType meWindowType;
112 bool mbMaximizedVert;
113 bool mbMaximizedHorz;
114 bool mbFullScreen;
115 bool m_bIsPartialFullScreen;
117 // icon id
118 int mnIconID;
120 OUString m_aTitle;
122 OUString m_sWMClass;
124 SystemEnvData maSystemChildData;
126 std::unique_ptr<SalI18N_InputContext> mpInputContext;
127 Bool mbInputFocus;
129 std::vector<XRectangle> m_vClipRectangles;
131 bool mPendingSizeEvent;
133 void GetPosSize( AbsoluteScreenPixelRectangle &rPosSize );
134 void SetSize ( const Size &rSize );
135 void Center();
136 void SetPosSize( const AbsoluteScreenPixelRectangle &rPosSize );
137 void Minimize();
138 void Maximize();
139 void Restore();
141 void RestackChildren( ::Window* pTopLevelWindows, int nTopLevelWindows );
142 void RestackChildren();
144 bool HandleKeyEvent ( XKeyEvent *pEvent );
145 bool HandleMouseEvent ( XEvent *pEvent );
146 bool HandleFocusEvent ( XFocusChangeEvent const *pEvent );
147 bool HandleExposeEvent ( XEvent const *pEvent );
148 bool HandleSizeEvent ( XConfigureEvent *pEvent );
149 bool HandleStateEvent ( XPropertyEvent const *pEvent );
150 bool HandleReparentEvent ( XReparentEvent *pEvent );
151 bool HandleClientMessage ( XClientMessageEvent*pEvent );
153 DECL_LINK( HandleAlwaysOnTopRaise, Timer*, void );
155 void createNewWindow( ::Window aParent, SalX11Screen nXScreen = SalX11Screen( -1 ) );
156 void updateScreenNumber();
158 void setXEmbedInfo();
159 void askForXEmbedFocus( sal_Int32 i_nTimeCode );
161 void updateWMClass();
162 public:
163 X11SalFrame( SalFrame* pParent, SalFrameStyleFlags nSalFrameStyle, SystemParentData const * pSystemParent = nullptr );
164 virtual ~X11SalFrame() override;
166 bool Dispatch( XEvent *pEvent );
167 void Init( SalFrameStyleFlags nSalFrameStyle, SalX11Screen nScreen,
168 SystemParentData const * pParentData, bool bUseGeometry = false );
170 SalDisplay* GetDisplay() const
172 return pDisplay_;
174 Display *GetXDisplay() const
176 return pDisplay_->GetDisplay();
178 const SalX11Screen& GetScreenNumber() const { return m_nXScreen; }
179 ::Window GetWindow() const { return mhWindow; }
180 cairo_surface_t* GetSurface() const { return mpSurface; }
181 ::Window GetShellWindow() const { return mhShellWindow; }
182 ::Window GetForeignParent() const { return mhForeignParent; }
183 ::Window GetStackingWindow() const { return mhStackingWindow; }
184 void Close() const { CallCallback( SalEvent::Close, nullptr ); }
185 SalFrameStyleFlags GetStyle() const { return nStyle_; }
187 Cursor GetCursor() const { return hCursor_; }
188 bool IsCaptured() const { return nCaptured_ == 1; }
189 #if !defined(__synchronous_extinput__)
190 void HandleExtTextEvent (XClientMessageEvent const *pEvent);
191 #endif
192 bool IsOverrideRedirect() const;
193 bool IsChildWindow() const { return bool(nStyle_ & (SalFrameStyleFlags::PLUG|SalFrameStyleFlags::SYSTEMCHILD)); }
194 bool IsSysChildWindow() const { return bool(nStyle_ & SalFrameStyleFlags::SYSTEMCHILD); }
195 bool IsFloatGrabWindow() const;
196 SalI18N_InputContext* getInputContext() const { return mpInputContext.get(); }
197 bool hasFocus() const { return mbInputFocus; }
199 void beginUnicodeSequence();
200 bool appendUnicodeSequence( sal_Unicode );
201 bool endUnicodeSequence();
203 virtual SalGraphics* AcquireGraphics() override;
204 virtual void ReleaseGraphics( SalGraphics* pGraphics ) override;
206 // call with true to clear graphics (setting None as drawable)
207 // call with false to setup graphics with window (GetWindow())
208 virtual void updateGraphics( bool bClear );
210 virtual bool PostEvent(std::unique_ptr<ImplSVEvent> pData) override;
212 virtual void SetTitle( const OUString& rTitle ) override;
213 virtual void SetIcon( sal_uInt16 nIcon ) override;
214 virtual void SetMenu( SalMenu* pMenu ) override;
216 virtual void SetExtendedFrameStyle( SalExtStyle nExtStyle ) override;
217 virtual void Show( bool bVisible, bool bNoActivate = false ) override;
218 virtual void SetMinClientSize( tools::Long nWidth, tools::Long nHeight ) override;
219 virtual void SetMaxClientSize( tools::Long nWidth, tools::Long nHeight ) override;
220 virtual void SetPosSize( tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, sal_uInt16 nFlags ) override;
221 virtual void GetClientSize( tools::Long& rWidth, tools::Long& rHeight ) override;
222 virtual void GetWorkArea( AbsoluteScreenPixelRectangle& rRect ) override;
223 virtual SalFrame* GetParent() const override;
224 virtual void SetWindowState(const vcl::WindowData*) override;
225 virtual bool GetWindowState(vcl::WindowData*) override;
226 virtual void ShowFullScreen( bool bFullScreen, sal_Int32 nMonitor ) override;
227 virtual void StartPresentation( bool bStart ) override;
228 virtual void SetAlwaysOnTop( bool bOnTop ) override;
229 virtual void ToTop( SalFrameToTop nFlags ) override;
230 virtual void SetPointer( PointerStyle ePointerStyle ) override;
231 virtual void CaptureMouse( bool bMouse ) override;
232 virtual void SetPointerPos( tools::Long nX, tools::Long nY ) override;
233 using SalFrame::Flush;
234 virtual void Flush() override;
235 virtual void SetInputContext( SalInputContext* pContext ) override;
236 virtual void EndExtTextInput( EndExtTextInputFlags nFlags ) override;
237 virtual OUString GetKeyName( sal_uInt16 nKeyCode ) override;
238 virtual bool MapUnicodeToKeyCode( sal_Unicode aUnicode, LanguageType aLangType, vcl::KeyCode& rKeyCode ) override;
239 virtual LanguageType GetInputLanguage() override;
240 virtual void UpdateSettings( AllSettings& rSettings ) override;
241 virtual void Beep() override;
242 virtual const SystemEnvData* GetSystemData() const override;
243 virtual SalPointerState GetPointerState() override;
244 virtual KeyIndicatorState GetIndicatorState() override;
245 virtual void SimulateKeyPress( sal_uInt16 nKeyCode ) override;
246 virtual void SetParent( SalFrame* pNewParent ) override;
247 virtual void SetPluginParent( SystemParentData* pNewParent ) override;
249 virtual void SetScreenNumber( unsigned int ) override;
250 virtual void SetApplicationID( const OUString &rWMClass ) override;
252 // shaped system windows
253 // set clip region to none (-> rectangular windows, normal state)
254 virtual void ResetClipRegion() override;
255 // start setting the clipregion consisting of nRects rectangles
256 virtual void BeginSetClipRegion( sal_uInt32 nRects ) override;
257 // add a rectangle to the clip region
258 virtual void UnionClipRegion( tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight ) override;
259 // done setting up the clipregion
260 virtual void EndSetClipRegion() override;
262 /// @internal
263 void setPendingSizeEvent();
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */