1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #ifndef INCLUDED_VCL_INC_OSX_SALFRAME_H
21 #define INCLUDED_VCL_INC_OSX_SALFRAME_H
22
23 #include <premac.h>
24 #include <IOKit/pwr_mgt/IOPMLib.h>
25 #include <postmac.h>
26
27 #include <vcl/sysdata.hxx>
28
29 #include <osx/salinst.h>
30 #include <osx/salmenu.h>
31 #include <osx/saldata.hxx>
32 #include <osx/osxvcltypes.h>
33
34 #include <salframe.hxx>
35
36 #include <vector>
37 #include <utility>
38 #include <stdexcept>
39
40 class AquaSalGraphics;
41 class AquaSalFrame;
42 class AquaSalTimer;
43 class AquaSalInstance;
44 class AquaSalMenu;
45
46 class AquaSalFrame : public SalFrame
47 {
48 public:
49 NSWindow* mpNSWindow; // Cocoa window
50 NSView* mpNSView; // Cocoa view (actually a custom view)
51 NSMenuItem* mpDockMenuEntry; // entry in the dynamic dock menu
52 NSRect maScreenRect; // for mirroring purposes
53 AquaSalGraphics* mpGraphics; // current frame graphics
54 AquaSalFrame* mpParent; // pointer to parent frame
55 SystemEnvData maSysData; // system data
56 int mnMinWidth; // min. client width in pixels
57 int mnMinHeight; // min. client height in pixels
58 int mnMaxWidth; // max. client width in pixels
59 int mnMaxHeight; // max. client height in pixels
60 NSRect maFullScreenRect; // old window size when in FullScreen
61 bool mbGraphics; // is Graphics used?
62 bool mbFullScreen; // is Window in FullScreen?
63 bool mbShown;
64 bool mbInitShow;
65 bool mbPositioned;
66 bool mbSized;
67 bool mbPresentation;
68
69 SalFrameStyleFlags mnStyle;
70 unsigned int mnStyleMask; // our style mask from NSWindow creation
71
72 sal_uInt64 mnLastEventTime;
73 unsigned int mnLastModifierFlags;
74 AquaSalMenu* mpMenu;
75
76 SalExtStyle mnExtStyle; // currently document frames are marked this way
77
78 PointerStyle mePointerStyle; // currently active pointer style
79
80 NSTrackingRectTag mnTrackingRectTag; // used to get enter/leave messages
81 NSRect maTrackingRect;
82
83 CGMutablePathRef mrClippingPath; // used for "shaping"
84 std::vector< CGRect > maClippingRects;
85
86 tools::Rectangle maInvalidRect;
87
88 InputContextFlags mnICOptions;
89
90 // To prevent display sleep during presentation
91 IOPMAssertionID mnAssertionID;
92
93 NSRect maFrameRect;
94 NSRect maContentRect;
95
96 bool mbGeometryDidChange;
97
98 int mnBlinkCursorDelay;
99
100 public:
101 /** Constructor
102
103 Creates a system window and connects this frame with it.
104
105 @throws std::runtime_error in case window creation fails
106 */
107 AquaSalFrame( SalFrame* pParent, SalFrameStyleFlags salFrameStyle );
108
109 virtual ~AquaSalFrame() override;
110
111 virtual SalGraphics* AcquireGraphics() override;
112 virtual void ReleaseGraphics( SalGraphics* pGraphics ) override;
113 virtual bool PostEvent(std::unique_ptr<ImplSVEvent> pData) override;
114 virtual void SetTitle( const OUString& rTitle ) override;
115 virtual void SetIcon( sal_uInt16 nIcon ) override;
116 virtual void SetRepresentedURL( const OUString& ) override;
117 virtual void SetMenu( SalMenu* pSalMenu ) override;
118 virtual void DrawMenuBar() override;
119 virtual void Show( bool bVisible, bool bNoActivate = false ) override;
120 virtual void SetMinClientSize( long nWidth, long nHeight ) override;
121 virtual void SetMaxClientSize( long nWidth, long nHeight ) override;
122 virtual void SetPosSize( long nX, long nY, long nWidth, long nHeight, sal_uInt16 nFlags ) override;
123 virtual void GetClientSize( long& rWidth, long& rHeight ) override;
124 virtual void GetWorkArea( tools::Rectangle& rRect ) override;
125 virtual SalFrame* GetParent() const override;
126 virtual void SetWindowState( const SalFrameState* pState ) override;
127 virtual bool GetWindowState( SalFrameState* pState ) override;
128 virtual void ShowFullScreen( bool bFullScreen, sal_Int32 nDisplay ) override;
129 virtual void StartPresentation( bool bStart ) override;
130 virtual void SetAlwaysOnTop( bool bOnTop ) override;
131 virtual void ToTop( SalFrameToTop nFlags ) override;
132 virtual void SetPointer( PointerStyle ePointerStyle ) override;
133 virtual void CaptureMouse( bool bMouse ) override;
134 virtual void SetPointerPos( long nX, long nY ) override;
135 virtual void Flush( void ) override;
136 virtual void Flush( const tools::Rectangle& ) override;
137 virtual void SetInputContext( SalInputContext* pContext ) override;
138 virtual void EndExtTextInput( EndExtTextInputFlags nFlags ) override;
139 virtual OUString GetKeyName( sal_uInt16 nKeyCode ) override;
140 virtual bool MapUnicodeToKeyCode( sal_Unicode aUnicode, LanguageType aLangType, vcl::KeyCode& rKeyCode ) override;
141 virtual LanguageType GetInputLanguage() override;
142 virtual void UpdateSettings( AllSettings& rSettings ) override;
143 virtual void Beep() override;
144 virtual const SystemEnvData* GetSystemData() const override;
145 virtual SalPointerState GetPointerState() override;
146 virtual KeyIndicatorState GetIndicatorState() override;
147 virtual void SimulateKeyPress( sal_uInt16 nKeyCode ) override;
148 virtual void SetParent( SalFrame* pNewParent ) override;
149 virtual bool SetPluginParent( SystemParentData* pNewParent ) override;
150 virtual void SetExtendedFrameStyle( SalExtStyle ) override;
151 virtual void SetScreenNumber(unsigned int) override;
152 virtual void SetApplicationID( const OUString &rApplicationID ) override;
153
154 // shaped system windows
155 // set clip region to none (-> rectangular windows, normal state)
156 virtual void ResetClipRegion() override;
157 // start setting the clipregion consisting of nRects rectangles
158 virtual void BeginSetClipRegion( sal_uInt32 nRects ) override;
159 // add a rectangle to the clip region
160 virtual void UnionClipRegion( long nX, long nY, long nWidth, long nHeight ) override;
161 // done setting up the clipregion
162 virtual void EndSetClipRegion() override;
163
164 void UpdateFrameGeometry();
165
166 // trigger painting of the window
167 void SendPaintEvent( const tools::Rectangle* pRect = nullptr );
168
169 static inline bool isAlive( const AquaSalFrame* pFrame );
170
GetCaptureFrame()171 static AquaSalFrame* GetCaptureFrame() { return s_pCaptureFrame; }
172
getNSWindow()173 NSWindow* getNSWindow() const { return mpNSWindow; }
getNSView()174 NSView* getNSView() const { return mpNSView; }
getStyleMask()175 unsigned int getStyleMask() const { return mnStyleMask; }
176
177 void getResolution( sal_Int32& o_rDPIX, sal_Int32& o_rDPIY );
178
179 // actually the following methods do the same thing: flipping y coordinates
180 // but having two of them makes clearer what the coordinate system
181 // is supposed to be before and after
182 void VCLToCocoa( NSRect& io_rRect, bool bRelativeToScreen = true );
183 void CocoaToVCL( NSRect& io_rRect, bool bRelativeToScreen = true );
184
185 void VCLToCocoa( NSPoint& io_rPoint, bool bRelativeToScreen = true );
186 void CocoaToVCL( NSPoint& io_Point, bool bRelativeToScreen = true );
187
188 NSCursor* getCurrentCursor();
189
getClipPath()190 CGMutablePathRef getClipPath() const { return mrClippingPath; }
191
192 // called by VCL_NSApplication to indicate screen settings have changed
193 void screenParametersChanged();
194
195 protected:
196 SalEvent PreparePosSize(long nX, long nY, long nWidth, long nHeight, sal_uInt16 nFlags);
197
198 private: // methods
199 /** do things on initial show (like centering on parent or on screen)
200 */
201 void initShow();
202
203 void initWindowAndView();
204
205 void doShowFullScreen( bool bFullScreen, sal_Int32 nDisplay );
206
207 void doResetClipRegion();
208
209 private: // data
210 static AquaSalFrame* s_pCaptureFrame;
211
212 AquaSalFrame( const AquaSalFrame& ) = delete;
213 AquaSalFrame& operator=(const AquaSalFrame&) = delete;
214 };
215
isAlive(const AquaSalFrame * pFrame)216 inline bool AquaSalFrame::isAlive( const AquaSalFrame* pFrame )
217 {
218 AquaSalInstance *pInst = GetSalData()->mpInstance;
219 return pInst && pInst->isFrameAlive( pFrame );
220 }
221
222 #endif // INCLUDED_VCL_INC_OSX_SALFRAME_H
223
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
225