1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <sal/config.h>
24 #include <o3tl/lru_map.hxx>
25 #include <o3tl/hash_combine.hxx>
26 #include <tools/fldunit.hxx>
27 #include <unotools/options.hxx>
28 #include <vcl/bitmapex.hxx>
29 #include <vcl/cvtgrf.hxx>
30 #include <vcl/image.hxx>
31 #include <vcl/settings.hxx>
32 #include <vcl/svapp.hxx>
33 #include <vcl/print.hxx>
34 #include <vcl/uitest/logger.hxx>
35 #include <vcl/virdev.hxx>
36 #include <vcl/wrkwin.hxx>
37 #include <vcl/window.hxx>
38 #include <vcl/task.hxx>
39 #include <LibreOfficeKit/LibreOfficeKitTypes.h>
40 #include <unotools/resmgr.hxx>
42 #include <com/sun/star/lang/XComponent.hpp>
43 #include <com/sun/star/i18n/XCharacterClassification.hpp>
44 #include "vcleventlisteners.hxx"
46 #include "salwtype.hxx"
47 #include "windowdev.hxx"
48 #include "displayconnectiondispatch.hxx"
54 #include <unordered_map>
55 #include "schedulerimpl.hxx"
56 #include <basegfx/DrawCommands.hxx>
58 struct ImplPostEventData
;
61 struct ImplConfigData
;
68 class DirectFontSubstitution
;
69 class PhysicalFontCollection
;
74 class ImplAccelManager
;
98 class ImplPrnQueueList
;
100 class GraphicConverter
;
101 class ImplWheelWindow
;
103 class DockingManager
;
104 class VclEventListeners2
;
109 #define SV_ICON_ID_OFFICE 1
110 #define SV_ICON_ID_TEXT 2
111 #define SV_ICON_ID_TEXT_TEMPLATE 3
112 #define SV_ICON_ID_SPREADSHEET 4
113 #define SV_ICON_ID_SPREADSHEET_TEMPLATE 5
114 #define SV_ICON_ID_DRAWING 6
115 #define SV_ICON_ID_PRESENTATION 8
116 #define SV_ICON_ID_MASTER_DOCUMENT 10
117 #define SV_ICON_ID_TEMPLATE 11
118 #define SV_ICON_ID_DATABASE 12
119 #define SV_ICON_ID_FORMULA 13
121 const FloatWinPopupFlags LISTBOX_FLOATWINPOPUPFLAGS
= FloatWinPopupFlags::Down
|
122 FloatWinPopupFlags::NoHorzPlacement
| FloatWinPopupFlags::AllMouseButtonClose
;
124 namespace com::sun::star::datatransfer::clipboard
{ class XClipboard
; }
128 class DisplayConnectionDispatch
;
129 class SettingsConfigItem
;
130 class DeleteOnDeinitBase
;
136 class SystemDependentDataManager
;
139 class LocaleConfigurationListener final
: public utl::ConfigurationListener
142 virtual void ConfigurationChanged( utl::ConfigurationBroadcaster
*, ConfigurationHints
) override
;
145 typedef std::pair
<VclPtr
<vcl::Window
>, ImplPostEventData
*> ImplPostEventPair
;
152 std::optional
<AllSettings
> mxSettings
; // Application settings
153 LocaleConfigurationListener
* mpCfgListener
= nullptr;
154 VclEventListeners maEventListeners
; // listeners for vcl events (eg, extended toolkit)
155 std::vector
<Link
<VclWindowEvent
&,bool> >
156 maKeyListeners
; // listeners for key events only (eg, extended toolkit)
157 std::vector
<ImplPostEventPair
> maPostedEventList
;
158 ImplAccelManager
* mpAccelMgr
= nullptr; // Accelerator Manager
159 std::optional
<OUString
> mxAppName
; // Application name
160 std::optional
<OUString
> mxAppFileName
; // Abs. Application FileName
161 std::optional
<OUString
> mxDisplayName
; // Application Display Name
162 std::optional
<OUString
> mxToolkitName
; // Toolkit Name
163 Help
* mpHelp
= nullptr; // Application help
164 VclPtr
<PopupMenu
> mpActivePopupMenu
; // Actives Popup-Menu (in Execute)
165 VclPtr
<ImplWheelWindow
> mpWheelWindow
; // WheelWindow
166 sal_uInt64 mnLastInputTime
= 0; // GetLastInputTime()
167 sal_uInt16 mnDispatchLevel
= 0; // DispatchLevel
168 sal_uInt16 mnModalMode
= 0; // ModalMode Count
169 SystemWindowFlags mnSysWinMode
= SystemWindowFlags(0); // Mode, when SystemWindows should be created
170 bool mbInAppMain
= false; // is Application::Main() on stack
171 bool mbInAppExecute
= false; // is Application::Execute() on stack
172 std::atomic
<bool> mbAppQuit
= false; // is Application::Quit() called, volatile because we read/write from different threads
173 bool mbSettingsInit
= false; // true: Settings are initialized
174 DialogCancelMode meDialogCancel
= DialogCancelMode::Off
; // true: All Dialog::Execute() calls will be terminated immediately with return false
175 bool mbRenderToBitmaps
= false; // set via svp / headless plugin
176 bool m_bUseSystemLoop
= false;
178 DECL_STATIC_LINK(ImplSVAppData
, ImplQuitMsg
, void*, void);
181 /// Cache multiple scalings for the same bitmap
182 struct ScaleCacheKey
{
185 ScaleCacheKey(SalBitmap
*pBitmap
, const Size
&aDestSize
)
188 maDestSize
= aDestSize
;
190 ScaleCacheKey(const ScaleCacheKey
&key
)
192 mpBitmap
= key
.mpBitmap
;
193 maDestSize
= key
.maDestSize
;
195 bool operator==(ScaleCacheKey
const& rOther
) const
197 return mpBitmap
== rOther
.mpBitmap
&& maDestSize
== rOther
.maDestSize
;
203 template <> struct hash
<ScaleCacheKey
>
205 std::size_t operator()(ScaleCacheKey
const& k
) const noexcept
207 std::size_t seed
= 0;
208 o3tl::hash_combine(seed
, k
.mpBitmap
);
209 o3tl::hash_combine(seed
, k
.maDestSize
.getWidth());
210 o3tl::hash_combine(seed
, k
.maDestSize
.getHeight());
215 } // end std namespace
217 typedef o3tl::lru_map
<ScaleCacheKey
, BitmapEx
> lru_scale_cache
;
223 VclPtr
<vcl::WindowOutputDevice
> mpFirstWinGraphics
; // First OutputDevice with a Frame Graphics
224 VclPtr
<vcl::WindowOutputDevice
> mpLastWinGraphics
; // Last OutputDevice with a Frame Graphics
225 VclPtr
<OutputDevice
> mpFirstVirGraphics
; // First OutputDevice with a VirtualDevice Graphics
226 VclPtr
<OutputDevice
> mpLastVirGraphics
; // Last OutputDevice with a VirtualDevice Graphics
227 VclPtr
<Printer
> mpFirstPrnGraphics
; // First OutputDevice with an InfoPrinter Graphics
228 VclPtr
<Printer
> mpLastPrnGraphics
; // Last OutputDevice with an InfoPrinter Graphics
229 VclPtr
<VirtualDevice
> mpFirstVirDev
; // First VirtualDevice
230 OpenGLContext
* mpLastContext
= nullptr; // Last OpenGLContext
231 VclPtr
<Printer
> mpFirstPrinter
; // First Printer
232 std::unique_ptr
<ImplPrnQueueList
> mpPrinterQueueList
; // List of all printer queue
233 std::shared_ptr
<vcl::font::PhysicalFontCollection
> mxScreenFontList
; // Screen-Font-List
234 std::shared_ptr
<ImplFontCache
> mxScreenFontCache
; // Screen-Font-Cache
235 lru_scale_cache maScaleCache
= lru_scale_cache(10); // Cache for scaled images
236 vcl::font::DirectFontSubstitution
* mpDirectFontSubst
= nullptr; // Font-Substitutions defined in Tools->Options->Fonts
237 std::unique_ptr
<GraphicConverter
> mxGrfConverter
; // Converter for graphics
238 tools::Long mnAppFontX
= 0; // AppFont X-Numenator for 40/tel Width
239 tools::Long mnAppFontY
= 0; // AppFont Y-Numenator for 80/tel Height
240 bool mbFontSubChanged
= false; // true: FontSubstitution was changed between Begin/End
242 o3tl::lru_map
<OUString
, BitmapEx
> maThemeImageCache
= o3tl::lru_map
<OUString
, BitmapEx
>(10);
243 o3tl::lru_map
<OUString
, gfx::DrawRoot
> maThemeDrawCommandsCache
= o3tl::lru_map
<OUString
, gfx::DrawRoot
>(50);
246 struct ImplSVFrameData
249 VclPtr
<vcl::Window
> mpFirstFrame
; // First FrameWindow
250 VclPtr
<vcl::Window
> mpActiveApplicationFrame
; // the last active application frame, can be used as DefModalDialogParent if no focuswin set
251 VclPtr
<WorkWindow
> mpAppWin
; // Application-Window
253 std::unique_ptr
<UITestLogger
> m_pUITestLogger
;
259 VclPtr
<vcl::Window
> mpFocusWin
; // window, that has the focus
260 VclPtr
<vcl::Window
> mpCaptureWin
; // window, that has the mouse capture
261 VclPtr
<vcl::Window
> mpLastDeacWin
; // Window, that need a deactivate (FloatingWindow-Handling)
262 VclPtr
<FloatingWindow
> mpFirstFloat
; // First FloatingWindow in PopupMode
263 std::vector
<VclPtr
<Dialog
>> mpExecuteDialogs
; ///< Stack of dialogs that are Execute()'d - the last one is the top most one.
264 VclPtr
<vcl::Window
> mpExtTextInputWin
; // Window, which is in ExtTextInput
265 VclPtr
<vcl::Window
> mpTrackWin
; // window, that is in tracking mode
266 std::unique_ptr
<AutoTimer
> mpTrackTimer
; // tracking timer
267 std::vector
<Image
> maMsgBoxImgList
; // ImageList for MessageBox
268 VclPtr
<vcl::Window
> mpAutoScrollWin
; // window, that is in AutoScrollMode mode
269 VclPtr
<vcl::Window
> mpLastWheelWindow
; // window, that last received a mouse wheel event
270 SalWheelMouseEvent maLastWheelEvent
; // the last received mouse wheel event
272 StartTrackingFlags mnTrackFlags
= StartTrackingFlags::NONE
; // tracking flags
273 StartAutoScrollFlags mnAutoScrollFlags
= StartAutoScrollFlags::NONE
; // auto scroll flags
274 bool mbNoDeactivate
= false; // true: do not execute Deactivate
275 bool mbNoSaveFocus
= false; // true: menus must not save/restore focus
276 bool mbIsLiveResize
= false; // true: skip waiting for events and low priority timers
279 typedef std::vector
< std::pair
< OUString
, FieldUnit
> > FieldUnitStringList
;
281 struct ImplSVCtrlData
283 std::vector
<Image
> maCheckImgList
; // ImageList for CheckBoxes
284 std::vector
<Image
> maRadioImgList
; // ImageList for RadioButtons
285 std::optional
<Image
> moDisclosurePlus
;
286 std::optional
<Image
> moDisclosureMinus
;
287 ImplTBDragMgr
* mpTBDragMgr
= nullptr; // DragMgr for ToolBox
288 sal_uInt16 mnCheckStyle
= 0; // CheckBox-Style for ImageList-Update
289 sal_uInt16 mnRadioStyle
= 0; // Radio-Style for ImageList-Update
290 Color mnLastCheckFColor
; // Last FaceColor for CheckImage
291 Color mnLastCheckWColor
; // Last WindowColor for CheckImage
292 Color mnLastCheckLColor
; // Last LightColor for CheckImage
293 Color mnLastRadioFColor
; // Last FaceColor for RadioImage
294 Color mnLastRadioWColor
; // Last WindowColor for RadioImage
295 Color mnLastRadioLColor
; // Last LightColor for RadioImage
296 FieldUnitStringList maFieldUnitStrings
; // list with field units
297 FieldUnitStringList maCleanUnitStrings
; // same list but with some "fluff" like spaces removed
300 struct ImplSVHelpData
303 bool mbContextHelp
= false; // is ContextHelp enabled
304 bool mbExtHelp
= false; // is ExtendedHelp enabled
305 bool mbExtHelpMode
= false; // is in ExtendedHelp Mode
306 bool mbOldBalloonMode
= false; // BalloonMode, before ExtHelpMode started
307 bool mbBalloonHelp
= false; // is BalloonHelp enabled
308 bool mbQuickHelp
= false; // is QuickHelp enabled
309 bool mbSetKeyboardHelp
= false; // tiphelp was activated by keyboard
310 bool mbKeyboardHelp
= false; // tiphelp was activated by keyboard
311 bool mbRequestingHelp
= false; // In Window::RequestHelp
312 VclPtr
<HelpTextWindow
> mpHelpWin
; // HelpWindow
313 sal_uInt64 mnLastHelpHideTime
= 0; // ticks of last show
316 // "NWF" means "Native Widget Framework" and was the term used for the
317 // idea that StarView/OOo "widgets" should *look* (and feel) like the
318 // "native widgets" on each platform, even if not at all implemented
319 // using them. See http://people.redhat.com/dcbw/ooo-nwf.html .
323 int mnStatusBarLowerRightOffset
= 0; // amount in pixel to avoid in the lower righthand corner
324 int mnMenuFormatBorderX
= 0; // horizontal inner popup menu border
325 int mnMenuFormatBorderY
= 0; // vertical inner popup menu border
326 ::Color maMenuBarHighlightTextColor
= COL_TRANSPARENT
; // override highlight text color
327 // in menubar if not transparent
328 bool mbMenuBarDockingAreaCommonBG
= false; // e.g. WinXP default theme
329 bool mbDockingAreaSeparateTB
= false; // individual toolbar backgrounds
330 // instead of one for docking area
331 bool mbDockingAreaAvoidTBFrames
= false; ///< don't draw frames around the individual toolbars if mbDockingAreaSeparateTB is false
332 bool mbFlatMenu
= false; // no popup 3D border
333 bool mbNoFocusRects
= false; // on Aqua/Gtk3 use native focus rendering, except for flat buttons
334 bool mbNoFocusRectsForFlatButtons
= false; // on Gtk3 native focusing is also preferred for flat buttons
335 bool mbNoFrameJunctionForPopups
= false; // on Gtk4 popups are done via popovers and a toolbar menu won't align to its toolitem, so
336 // omit the effort the creation a visual junction
337 bool mbCenteredTabs
= false; // on Aqua, tabs are centered
338 bool mbNoActiveTabTextRaise
= false; // on Aqua the text for the selected tab
339 // should not "jump up" a pixel
340 bool mbProgressNeedsErase
= false; // set true for platforms that should draw the
341 // window background before drawing the native
343 bool mbCanDrawWidgetAnySize
= false; // set to true currently on gtk
345 /// entire drop down listbox resembles a button, no textarea/button parts (as currently on Windows)
346 bool mbDDListBoxNoTextArea
= false;
347 bool mbAutoAccel
= false; // whether accelerators are only shown when Alt is held down
348 bool mbRolloverMenubar
= false; // theming engine supports rollover in menubar
349 // gnome#768128 I cannot see a route under wayland at present to support
350 // floating toolbars that can be redocked because there's no way to track
351 // that the toolbar is over a dockable area.
352 bool mbCanDetermineWindowPosition
= true;
354 int mnListBoxEntryMargin
= 0;
357 struct BlendFrameCache
360 sal_uInt8 m_nLastAlpha
;
361 Color m_aLastColorTopLeft
;
362 Color m_aLastColorTopRight
;
363 Color m_aLastColorBottomRight
;
364 Color m_aLastColorBottomLeft
;
365 BitmapEx m_aLastResult
;
370 , m_aLastColorTopLeft(COL_BLACK
)
371 , m_aLastColorTopRight(COL_BLACK
)
372 , m_aLastColorBottomRight(COL_BLACK
)
373 , m_aLastColorBottomLeft(COL_BLACK
)
378 struct ImplSchedulerContext
380 ImplSchedulerData
* mpFirstSchedulerData
[PRIO_COUNT
] = { nullptr, }; ///< list of all active tasks per priority
381 ImplSchedulerData
* mpLastSchedulerData
[PRIO_COUNT
] = { nullptr, }; ///< last item of each mpFirstSchedulerData list
382 ImplSchedulerData
* mpSchedulerStack
= nullptr; ///< stack of invoked tasks
383 ImplSchedulerData
* mpSchedulerStackTop
= nullptr; ///< top most stack entry to detect needed rescheduling during pop
384 SalTimer
* mpSalTimer
= nullptr; ///< interface to sal event loop / system timer
385 sal_uInt64 mnTimerStart
= 0; ///< start time of the timer
386 sal_uInt64 mnTimerPeriod
= SAL_MAX_UINT64
; ///< current timer period
387 std::mutex maMutex
; ///< the "scheduler mutex" (see
388 ///< vcl/README.scheduler)
389 bool mbActive
= true; ///< is the scheduler active?
396 SalData
* mpSalData
= nullptr;
397 SalInstance
* mpDefInst
= nullptr; // Default SalInstance
398 Application
* mpApp
= nullptr; // pApp
399 VclPtr
<WorkWindow
> mpDefaultWin
; // Default-Window
400 bool mbDeInit
= false; // Is VCL deinitializing
401 std::unique_ptr
<SalSystem
> mpSalSystem
; // SalSystem interface
402 bool mbResLocaleSet
= false; // SV-Resource-Manager
403 std::locale maResLocale
; // Resource locale
404 ImplSchedulerContext maSchedCtx
; // Data for class Scheduler
405 ImplSVAppData maAppData
; // Data for class Application
406 ImplSVGDIData maGDIData
; // Data for Output classes
407 ImplSVFrameData maFrameData
; // Data for Frame classes
408 ImplSVWinData
* mpWinData
= nullptr; // Data for per-view Windows classes
409 ImplSVCtrlData maCtrlData
; // Data for Control classes
410 ImplSVHelpData
* mpHelpData
; // Data for Help classes
411 ImplSVNWFData maNWFData
;
412 UnoWrapperBase
* mpUnoWrapper
= nullptr;
413 VclPtr
<vcl::Window
> mpIntroWindow
; // the splash screen
414 std::unique_ptr
<DockingManager
> mpDockingManager
;
415 std::unique_ptr
<BlendFrameCache
> mpBlendFrameCache
;
417 oslThreadIdentifier mnMainThreadId
= 0;
418 rtl::Reference
< vcl::DisplayConnectionDispatch
> mxDisplayConnection
;
420 css::uno::Reference
< css::lang::XComponent
> mxAccessBridge
;
421 std::unique_ptr
<vcl::SettingsConfigItem
> mpSettingsConfigItem
;
422 std::vector
< vcl::DeleteOnDeinitBase
* > maDeinitDeleteList
;
423 std::unordered_map
< int, OUString
> maPaperNames
;
425 css::uno::Reference
<css::i18n::XCharacterClassification
> m_xCharClass
;
428 css::uno::Reference
<css::datatransfer::clipboard::XClipboard
> m_xSystemClipboard
;
431 Link
<LinkParamNone
*,void> maDeInitHook
;
433 // LOK & headless backend specific hooks
434 LibreOfficeKitPollCallback mpPollCallback
= nullptr;
435 LibreOfficeKitWakeCallback mpWakeCallback
= nullptr;
436 void *mpPollClosure
= nullptr;
439 void dumpState(rtl::OStringBuffer
&rState
);
442 css::uno::Reference
<css::i18n::XCharacterClassification
> const& ImplGetCharClass();
444 void ImplDeInitSVData();
445 VCL_PLUGIN_PUBLIC
basegfx::SystemDependentDataManager
& ImplGetSystemDependentDataManager();
446 VCL_PLUGIN_PUBLIC
vcl::Window
* ImplGetDefaultWindow();
447 vcl::Window
* ImplGetDefaultContextWindow();
448 const std::locale
& ImplGetResLocale();
449 VCL_PLUGIN_PUBLIC OUString
VclResId(TranslateId sContextAndId
);
450 DockingManager
* ImplGetDockingManager();
451 BlendFrameCache
* ImplGetBlendFrameCache();
452 void GenerateAutoMnemonicsOnHierarchy(const vcl::Window
* pWindow
);
454 VCL_PLUGIN_PUBLIC ImplSVHelpData
& ImplGetSVHelpData();
456 VCL_DLLPUBLIC
bool ImplCallPreNotify( NotifyEvent
& rEvt
);
458 VCL_PLUGIN_PUBLIC ImplSVData
* ImplGetSVData();
459 VCL_PLUGIN_PUBLIC
void ImplHideSplash();
462 bool ImplInitAccessBridge();
465 const FieldUnitStringList
& ImplGetFieldUnits();
466 const FieldUnitStringList
& ImplGetCleanedFieldUnits();
471 Link
<void*,void> maLink
;
472 VclPtr
<vcl::Window
> mpInstanceRef
;
473 VclPtr
<vcl::Window
> mpWindow
;
477 extern int nImplSysDialog
;
479 inline SalData
* GetSalData() { return ImplGetSVData()->mpSalData
; }
480 inline void SetSalData(SalData
* pData
) { ImplGetSVData()->mpSalData
= pData
; }
481 inline SalInstance
* GetSalInstance() { return ImplGetSVData()->mpDefInst
; }
483 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */