Coverage Report

Created: 2026-07-10 11:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/inc/salinst.hxx
Line
Count
Source
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
#pragma once
21
22
#include <sal/types.h>
23
#include <rtl/ref.hxx>
24
#include <vcl/ColorDialog.hxx>
25
#include <vcl/Platform.hxx>
26
#include <vcl/Toolkit.hxx>
27
#include <vcl/dllapi.h>
28
#include <vcl/salgtype.hxx>
29
#include <vcl/svmain.hxx>
30
#include <vcl/vclenum.hxx>
31
#include <vcl/weld/ColorChooserDialog.hxx>
32
33
#include "ClipboardSelectionType.hxx"
34
35
#include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
36
#include <com/sun/star/datatransfer/dnd/XDragSource.hpp>
37
#include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
38
#include <com/sun/star/uno/XComponentContext.hpp>
39
#include <com/sun/star/ui/dialogs/XFilePicker2.hpp>
40
#include <com/sun/star/ui/dialogs/XFolderPicker2.hpp>
41
#include <memory>
42
43
namespace com::sun::star::awt {
44
    class XWindow;
45
}
46
namespace comphelper { class SolarMutex; }
47
namespace vcl { class Window; }
48
namespace weld {
49
    class Builder;
50
    class MessageDialog;
51
    class Widget;
52
    class Window;
53
}
54
class SystemChildWindow;
55
struct SystemParentData;
56
struct SalPrinterQueueInfo;
57
class ImplJobSetup;
58
class OpenGLContext;
59
class SalData;
60
class SalGraphics;
61
class SalFrame;
62
class SalObject;
63
class SalMenu;
64
class SalMenuItem;
65
class SalVirtualDevice;
66
class SalInfoPrinter;
67
class SalPrinter;
68
class SalTimer;
69
class ImplPrnQueueList;
70
class SalSystem;
71
class SalBitmap;
72
struct SalItemParams;
73
class SalSession;
74
struct SystemEnvData;
75
struct SystemGraphicsData;
76
struct SystemWindowData;
77
class Menu;
78
enum class DesktopType;
79
enum class VclInputFlags;
80
enum class SalFrameStyleFlags;
81
82
typedef struct _cairo_font_options cairo_font_options_t;
83
84
class VCL_DLLPUBLIC SalInstance
85
{
86
private:
87
    const std::unique_ptr<comphelper::SolarMutex> m_pYieldMutex;
88
    css::uno::Reference<css::datatransfer::clipboard::XClipboard> m_clipboard;
89
90
protected:
91
    bool m_bSupportsOpenGL = false;
92
93
#ifdef MACOSX
94
    static void MacStartupWorkarounds();
95
#endif
96
97
public:
98
    SalInstance(std::unique_ptr<comphelper::SolarMutex> pMutex, SalData* pSalData);
99
    virtual ~SalInstance();
100
101
0
    bool supportsOpenGL() const { return m_bSupportsOpenGL; }
102
103
    //called directly after Application::Init
104
0
    virtual void            AfterAppInit() {}
105
106
    // run main application and cleanup; VCL plugin can override
107
    // to implement platform-specific application lifecycle
108
0
    virtual int             SVMainRun() { return ImplSVMainRun(); };
109
110
    // Frame
111
    // DisplayName for Unix ???
112
    virtual SalFrame*       CreateChildFrame( SystemParentData* pParent, SalFrameStyleFlags nStyle ) = 0;
113
    virtual SalFrame*       CreateFrame( SalFrame* pParent, SalFrameStyleFlags nStyle ) = 0;
114
    virtual void            DestroyFrame( SalFrame* pFrame ) = 0;
115
116
    // Object (System Child Window)
117
    virtual SalObject*      CreateObject( SalFrame* pParent, SystemWindowData* pWindowData, bool bShow ) = 0;
118
    virtual void            DestroyObject( SalObject* pObject ) = 0;
119
120
    // VirtualDevice
121
    // nDX and nDY in pixels
122
    // pData allows for using a system dependent graphics or device context,
123
    // if a system context is passed in nDX and nDY are updated to reflect
124
    // its size; otherwise these remain unchanged.
125
    virtual std::unique_ptr<SalVirtualDevice>
126
                            CreateVirtualDevice( SalGraphics& rGraphics,
127
                                                 tools::Long nDX, tools::Long nDY,
128
                                                 DeviceFormat eFormat,
129
                                                 bool bAlphaMaskTransparent = false ) = 0;
130
131
    // VirtualDevice
132
    // nDX and nDY in pixels
133
    // pData allows for using a system dependent graphics or device context,
134
    // nDX and nDY are updated to reflect its size; otherwise these remain unchanged.
135
    virtual std::unique_ptr<SalVirtualDevice>
136
                            CreateVirtualDevice( SalGraphics& rGraphics,
137
                                                 tools::Long &rDX, tools::Long &rDY,
138
                                                 DeviceFormat eFormat, const SystemGraphicsData& rData ) = 0;
139
140
    // Printer
141
    // pSetupData->mpDriverData can be 0
142
    // pSetupData must be updated with the current
143
    // JobSetup
144
    virtual SalInfoPrinter* CreateInfoPrinter(SalPrinterQueueInfo& rQueueInfo,
145
                                              ImplJobSetup& rSetupData) = 0;
146
    virtual void DestroyInfoPrinter(SalInfoPrinter* pPrinter);
147
    virtual std::unique_ptr<SalPrinter> CreatePrinter( SalInfoPrinter* pInfoPrinter ) = 0;
148
149
    virtual void GetPrinterQueueInfo(ImplPrnQueueList& rList) = 0;
150
    virtual void            GetPrinterQueueState(SalPrinterQueueInfo* pInfo);
151
    virtual OUString        GetDefaultPrinter() = 0;
152
153
    // SalTimer
154
    virtual SalTimer*       CreateSalTimer() = 0;
155
    // SalSystem
156
    virtual SalSystem*      CreateSalSystem() = 0;
157
    // SalBitmap
158
    virtual std::shared_ptr<SalBitmap> CreateSalBitmap() = 0;
159
160
    // YieldMutex
161
    comphelper::SolarMutex* GetYieldMutex();
162
    sal_uInt32              ReleaseYieldMutex(bool all);
163
    void                    AcquireYieldMutex(sal_uInt32 nCount = 1);
164
165
    // return true, if the current thread is the main thread
166
    virtual bool            IsMainThread() const = 0;
167
168
    /**
169
     * Wait for the next event (if bWait) and dispatch it,
170
     * includes posted events, and timers.
171
     * If bHandleAllCurrentEvents - dispatch multiple posted
172
     * user events. Returns true if events were processed.
173
     */
174
    virtual bool           DoYield(bool bWait, bool bHandleAllCurrentEvents) = 0;
175
    virtual bool           AnyInput( VclInputFlags nType ) = 0;
176
177
    // menus
178
    virtual std::unique_ptr<SalMenu>     CreateMenu( bool bMenuBar, Menu* pMenu );
179
    virtual std::unique_ptr<SalMenuItem> CreateMenuItem( const SalItemParams& pItemData );
180
181
    // may return NULL to disable session management, only used by X11 backend
182
    virtual std::unique_ptr<SalSession> CreateSalSession();
183
184
    // also needs to set m_bSupportsOpenGL = true in your SalInstance implementation!
185
    virtual OpenGLContext*  CreateOpenGLContext();
186
187
    virtual std::unique_ptr<weld::Builder> CreateBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile);
188
    virtual std::unique_ptr<weld::Builder> CreateInterimBuilder(vcl::Window* pParent,
189
                                                                const OUString& rUIRoot,
190
                                                                const OUString& rUIFile,
191
                                                                bool bAllowCycleFocusOut);
192
    virtual weld::MessageDialog* CreateMessageDialog(weld::Widget* pParent, VclMessageType eMessageType,
193
                                                     VclButtonsType eButtonType, const OUString& rPrimaryMessage);
194
    virtual std::unique_ptr<weld::ColorChooserDialog>
195
    CreateColorChooserDialog(weld::Window* pParent, vcl::ColorPickerMode eMode);
196
    virtual weld::Window* GetFrameWeld(const css::uno::Reference<css::awt::XWindow>& rWindow);
197
198
    // dtrans implementation
199
    virtual css::uno::Reference<css::datatransfer::clipboard::XClipboard>
200
    CreateClipboard(ClipboardSelectionType eSelection);
201
    virtual css::uno::Reference<css::datatransfer::dnd::XDragSource>
202
    ImplCreateDragSource(const SystemEnvData& rSysEnv);
203
    virtual css::uno::Reference<css::datatransfer::dnd::XDropTarget>
204
    ImplCreateDropTarget(const SystemEnvData& rSysEnv);
205
    css::uno::Reference<css::datatransfer::dnd::XDragSource>
206
    CreateDragSource(const SystemEnvData& rSysEnv);
207
    css::uno::Reference<css::datatransfer::dnd::XDropTarget>
208
    CreateDropTarget(const SystemEnvData& rSysEnv);
209
    virtual void            AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService) = 0;
210
211
0
    virtual bool hasNativeColorChooserDialog() const { return false; }
212
0
    virtual bool            hasNativeFileSelection() const { return false; }
213
    // if you override this, make sure to override hasNativeFileSelection too.
214
    virtual css::uno::Reference< css::ui::dialogs::XFilePicker2 > createFilePicker( const css::uno::Reference< css::uno::XComponentContext >& )
215
0
        { return css::uno::Reference< css::ui::dialogs::XFilePicker2 >(); }
216
    virtual css::uno::Reference< css::ui::dialogs::XFolderPicker2 > createFolderPicker( const css::uno::Reference< css::uno::XComponentContext >& )
217
0
        { return css::uno::Reference< css::ui::dialogs::XFolderPicker2 >(); }
218
219
    /// Set the app's (somewhat) magic/main-thread to this one.
220
0
    virtual void            updateMainThread() {}
221
    /// Disconnect that - good for detaching from the JavaVM on Android.
222
0
    virtual void            releaseMainThread() {}
223
224
    /// get information about underlying versions
225
0
    virtual OUString        getOSVersion() { return u"-"_ustr; }
226
0
    virtual Platform GetPlatform() const { return Platform::Other; }
227
0
    virtual Toolkit GetToolkit() const { return Toolkit::Invalid; }
228
0
    virtual OUString GetToolkitName() const { return u""_ustr; };
229
230
0
    virtual const cairo_font_options_t* GetCairoFontOptions() { return nullptr; }
231
232
0
    virtual void* CreateGStreamerSink(const SystemChildWindow*) { return nullptr; }
233
234
0
    virtual void BeforeAbort(const OUString& /* rErrorText */, bool /* bDumpCore */) {}
235
236
    // both must be implemented, if the VCL plugin needs to run via system event loop
237
    virtual bool DoExecute(int &nExitCode);
238
    virtual void DoQuit();
239
};
240
241
// called from SVMain
242
SalInstance* CreateSalInstance();
243
void DestroySalInstance( SalInstance* pInst );
244
245
void SalAbort( const OUString& rErrorText, bool bDumpCore );
246
247
DesktopType SalGetDesktopEnvironment();
248
249
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */