Line data Source code
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_SVAPP_HXX
21 : #define INCLUDED_VCL_SVAPP_HXX
22 :
23 : #include <sal/config.h>
24 : #include <sal/types.h>
25 :
26 :
27 : #include <cassert>
28 : #include <stdexcept>
29 : #include <vector>
30 :
31 : #include <comphelper/solarmutex.hxx>
32 : #include <rtl/ustring.hxx>
33 : #include <osl/thread.hxx>
34 : #include <tools/gen.hxx>
35 : #include <tools/link.hxx>
36 : #include <tools/solar.h>
37 : #include <vcl/dllapi.h>
38 : #include <vcl/apptypes.hxx>
39 : #include <vcl/keycod.hxx>
40 : #include <vcl/vclevent.hxx>
41 : #include <vcl/metric.hxx>
42 : #include <unotools/localedatawrapper.hxx>
43 :
44 : class BitmapEx;
45 : class Link;
46 : class AllSettings;
47 : class DataChangedEvent;
48 : class Accelerator;
49 : class Help;
50 : class OutputDevice;
51 : namespace vcl { class Window; }
52 : class WorkWindow;
53 : class MenuBar;
54 : class UnoWrapperBase;
55 : class Reflection;
56 : class NotifyEvent;
57 : class KeyEvent;
58 : class MouseEvent;
59 : class ZoomEvent;
60 : class ScrollEvent;
61 : struct ImplSVEvent;
62 :
63 : #include <com/sun/star/uno/Reference.h>
64 : #include <com/sun/star/connection/XConnection.hpp>
65 :
66 : namespace com {
67 : namespace sun {
68 : namespace star {
69 : namespace uno {
70 : class XComponentContext;
71 : }
72 : namespace ui {
73 : namespace dialogs {
74 : class XFilePicker2;
75 : class XFolderPicker2;
76 : }
77 : }
78 : namespace awt {
79 : class XToolkit;
80 : class XDisplayConnection;
81 : }
82 : } } }
83 :
84 : // helper needed by SalLayout implementations as well as svx/source/dialog/svxbmpnumbalueset.cxx
85 : VCL_DLLPUBLIC sal_UCS4 GetMirroredChar( sal_UCS4 );
86 : VCL_DLLPUBLIC sal_UCS4 GetLocalizedChar( sal_UCS4, LanguageType );
87 :
88 : #define SYSTEMWINDOW_MODE_NOAUTOMODE ((sal_uInt16)0x0001)
89 : #define SYSTEMWINDOW_MODE_DIALOG ((sal_uInt16)0x0002)
90 :
91 : typedef long (*VCLEventHookProc)( NotifyEvent& rEvt, void* pData );
92 :
93 : // ATTENTION: ENUM duplicate in daemon.cxx under Unix!
94 :
95 : #ifdef UNX
96 : enum Service { SERVICE_OLE, SERVICE_APPEVENT, SERVICE_IPC };
97 : #endif
98 :
99 : /** An application can be notified of a number of different events:
100 : - TYPE_ACCEPT - listen for connection to the application (a connection
101 : string is passed via the event)
102 : - TYPE_UNACCEPT - stops listening for a connection to the app (determined by
103 : a connection string passed via the event)
104 : - TYPE_APPEAR - brings the app to the front (i.e. makes it "appear")
105 : - TYPE_VERSION - display the app version
106 : - TYPE_HELP - opens a help topic (help topic passed as string)
107 : - TYPE_OPENHELP_URL - opens a help URL (URL passed as a string)
108 : - TYPE_SHOWDIALOG - shows a dialog (dialog passed as a string)
109 : - TYPE_OPEN - opens a document or group of documents (documents passed
110 : as an array of strings)
111 : - TYPE_PRINT - print a document or group of documents (documents passed
112 : as an array of strings
113 : - TYPE_PRIVATE_DOSHUTDOWN - shutdown the app
114 : */
115 0 : class VCL_DLLPUBLIC ApplicationEvent
116 : {
117 : public:
118 : enum Type {
119 : TYPE_ACCEPT, ///< Listen for connections
120 : TYPE_APPEAR, ///< Make application appear
121 : TYPE_HELP, ///< Bring up help options (command-line help)
122 : TYPE_VERSION, ///< Display product version
123 : TYPE_OPEN, ///< Open a document
124 : TYPE_OPENHELPURL, ///< Open a help URL
125 : TYPE_PRINT, ///< Print document
126 : TYPE_PRIVATE_DOSHUTDOWN, ///< Shutdown application
127 : TYPE_QUICKSTART, ///< Start QuickStart
128 : TYPE_SHOWDIALOG, ///< Show a dialog
129 : TYPE_UNACCEPT ///< Stop listening for connections
130 : };
131 :
132 : /** Explicit constructor for ApplicationEvent.
133 :
134 : @attention TYPE_APPEAR, TYPE_VERSION, TYPE_PRIVATE_DOSHUTDOWN and
135 : TYPE_QUICKSTART are the \em only events that don't need to include
136 : a data string with the event. No other events should use this
137 : constructor!
138 : */
139 0 : explicit ApplicationEvent(Type type): aEvent(type) {
140 : assert(
141 : type == TYPE_APPEAR || type == TYPE_VERSION
142 : || type == TYPE_PRIVATE_DOSHUTDOWN || type == TYPE_QUICKSTART);
143 0 : }
144 :
145 : /** Constructor for ApplicationEvent, accepts a string for the data
146 : associated with the event.
147 :
148 : @attention TYPE_ACCEPT, TYPE_HELP, TYPE_OPENHELPURL, TYPE_SHOWDIALOG
149 : and TYPE_UNACCEPT are the \em only events that accept a single
150 : string as event data. No other events should use this constructor!
151 : */
152 0 : ApplicationEvent(Type type, OUString const & data): aEvent(type) {
153 : assert(
154 : type == TYPE_ACCEPT || type == TYPE_HELP || type == TYPE_OPENHELPURL
155 : || type == TYPE_SHOWDIALOG || type == TYPE_UNACCEPT);
156 0 : aData.push_back(data);
157 0 : }
158 :
159 : /** Constructor for ApplicationEvnet, accepts an array of strings for
160 : the data associated with the event.
161 :
162 : @attention TYPE_OPEN and TYPE_PRINT can apply to multiple documents,
163 : and are the \em only events that accept an array of strings. No other
164 : events should use this constructor.
165 : */
166 : ApplicationEvent(Type type, std::vector<OUString> const & data):
167 : aEvent(type), aData(data)
168 : { assert(type == TYPE_OPEN || type == TYPE_PRINT); }
169 :
170 : /** Get the type of event.
171 :
172 : @returns The type of event.
173 : */
174 0 : Type GetEvent() const { return aEvent; }
175 :
176 : /** Gets the application event's data string.
177 :
178 : @attention The \em only events that need a single string TYPE_ACCEPT,
179 : TYPE_HELP, TYPE_OPENHELPURL, TYPE_SHOWDIALOG and TYPE_UNACCEPT
180 :
181 : @returns The event's data string.
182 : */
183 0 : OUString GetStringData() const {
184 : assert(
185 : aEvent == TYPE_ACCEPT || aEvent == TYPE_HELP
186 : || aEvent == TYPE_OPENHELPURL || aEvent == TYPE_SHOWDIALOG
187 : || aEvent == TYPE_UNACCEPT);
188 : assert(aData.size() == 1);
189 0 : return aData[0];
190 : }
191 :
192 : /** Gets the event's array of strings.
193 :
194 : @attention The \em only events that need an array of strings
195 : are TYPE_OPEN and TYPE_PRINT.
196 : */
197 0 : std::vector<OUString> const & GetStringsData() const {
198 : assert(aEvent == TYPE_OPEN || aEvent == TYPE_PRINT);
199 0 : return aData;
200 : }
201 :
202 : private:
203 : Type aEvent;
204 : std::vector<OUString> aData;
205 : };
206 :
207 : /**
208 : @brief Abstract base class used mainly for the LibreOffice Desktop class.
209 :
210 : The Application class is an abstract class with one pure virtual
211 : function: Main(), however, there are a \em lot of static functions
212 : that are vital for applications. It is really meant to be subclassed
213 : to provide a global singleton, and heavily relies on a single data
214 : structure ImplSVData
215 :
216 : The reason Application exists is because the VCL used to be a
217 : standalone framework, long since abandoned by anything other than
218 : our application.
219 :
220 : @see Desktop, ImplSVData
221 : */
222 : class VCL_DLLPUBLIC Application
223 : {
224 : public:
225 : enum DialogCancelMode {
226 : DIALOG_CANCEL_OFF, ///< do not automatically cancel dialogs
227 : DIALOG_CANCEL_SILENT, ///< silently cancel any dialogs
228 : DIALOG_CANCEL_FATAL ///< cancel any dialogs by std::abort
229 : };
230 :
231 : /** @name Initialization
232 : The following functions perform initialization and deinitialization
233 : of the application.
234 : */
235 : ///@{
236 :
237 : /** Default constructor for Application class.
238 :
239 : Initializes the LibreOffice global instance data structure if needed,
240 : and then sets itself to be the Application class. Also initializes any
241 : platform specific data structures.
242 :
243 : @attention The initialization of the application itself is done in Init()
244 :
245 : @see InitSalData is implemented by platform specific code.
246 : ImplInitSVData initializes the global instance data
247 : */
248 : Application();
249 :
250 : /** Virtual destructor for Application class.
251 :
252 : Deinitializes the LibreOffice global instance data structure, then
253 : deinitializes any platform specific data structures.
254 :
255 : @see ImplDeInitSVData deinitializes the global instance data,
256 : DeInitSalData is implemented by platform specific code
257 : */
258 : virtual ~Application();
259 :
260 : /** Initialize the application itself.
261 :
262 : @attention Note that the global data structures and platform specific
263 : initialization is done in the constructor.
264 :
265 : @see InitFinished, DeInit
266 : */
267 : virtual void Init();
268 :
269 : /** Finish initialization of the application.
270 :
271 : @see Init, DeInit
272 : */
273 : virtual void InitFinished();
274 :
275 : /** Deinitialized the application itself.
276 :
277 : @attention Note that the global data structures and platform specific
278 : deinitialization is done in the destructor.
279 :
280 : @see Init, InitFinished
281 : */
282 : virtual void DeInit();
283 :
284 : ///@}
285 :
286 : /** @brief Pure virtual entrypoint to the application.
287 :
288 : Main() is the pure virtual entrypoint to your application. You
289 : inherit your class from Application and subclass this function to
290 : implement an application.
291 :
292 : The Main() function does not pass in command line parameters,
293 : you must use the functions GetCommandLineParamCount() and
294 : GetCommandLineParam() to get these values as these are platform
295 : independent ways of getting the command line (use GetAppFileName()
296 : to get the invoked executable filename).
297 :
298 : Once in this function, you create windows, etc. then call on
299 : Execute() to start the application's main event loop.
300 :
301 : An example code snippet follows (it won't compile, this just gives the
302 : general flavour of the framework and is adapted from an old HelloWorld
303 : example program that Star Division used to provide as part of their
304 : library).
305 :
306 : \code{.cpp}
307 : class TheApplication : public Application
308 : {
309 : public:
310 : virtual void Main();
311 : };
312 :
313 : class TheWindow : public WorkWindow
314 : {
315 : public:
316 : TheWindow(vcl::Window *parent, WinBits windowStyle) :
317 : WorkWindow(parent, windowStyle) {}
318 :
319 : virtual void Paint(const Rectangle &);
320 : };
321 :
322 : void TheWindow::Paint(const Rectangle&)
323 : {
324 : DrawText(Point(100,100), String("Hello World!"));
325 : }
326 :
327 : void TheApplication::Main()
328 : {
329 : TheWindow aWindow(NULL, WB_APP | WB_STDWORK);
330 : aWindow.Show();
331 : Execute();
332 : }
333 :
334 : TheApplication anApplication;
335 : \endcode
336 :
337 : Some examples in the source tree can be found here:
338 :
339 : vcl/workben/svdem.cxx
340 :
341 : This is an example of how to use the Application and WorkWindow. Unfortunately, it
342 : no longer compiles.
343 :
344 : vcl/fpicker/test/svdem.cxx
345 : */
346 : virtual int Main() = 0;
347 :
348 : /** Exit from the application
349 :
350 : @returns true if exited successfully, false if not able to fully exit
351 : */
352 : virtual bool QueryExit();
353 :
354 : /** @name Change Notification Functions
355 :
356 : Functions that notify when changes occur in the application.
357 : */
358 : ///@{
359 :
360 : /** Notify that the application is no longer the "focused" (or current)
361 : application - needed for Windowing systems where an end user can switch
362 : from one application to another.
363 :
364 : @see DataChanged
365 : */
366 : virtual void FocusChanged();
367 :
368 : /** Notify the application that data has changed via an event.
369 :
370 : @param rDCEvt Const reference to a DataChangedEvent object
371 :
372 : @see FocusChanged, NotifyAllWindows
373 : */
374 : virtual void DataChanged( const DataChangedEvent& rDCEvt );
375 :
376 : /** Notify all windows that the application has changed data.
377 :
378 : @param rDCEvt Reference to a DataChangedEvent object
379 :
380 : @see DataChanged
381 : */
382 : static void NotifyAllWindows( DataChangedEvent& rDCEvt );
383 :
384 : ///@}
385 :
386 : /** @name Command Line Processing
387 :
388 : Command line processing is done via the following functions. They
389 : give the number of parameters, the parameters themselves and a way
390 : to get the name of the invoking application.
391 : */
392 :
393 : ///@{
394 :
395 : /** Gets the number of command line parameters passed to the application
396 :
397 : @return sal_uInt16 - the number of parameters
398 :
399 : @see GetCommandLineParam, GetAppFileName
400 : */
401 : static sal_uInt16 GetCommandLineParamCount();
402 :
403 : /** Gets a particular command line parameter
404 :
405 : @param nParam The index of the parameter to return.
406 :
407 : @return The command line parameter as an OUString
408 :
409 : @see GetCommandLineParamCount, GetAppFileName
410 : */
411 : static OUString GetCommandLineParam( sal_uInt16 nParam );
412 :
413 : /** Get the name of the file used to start the application
414 :
415 : @return The filename as an OUString
416 :
417 : @see GetCommandLineParamCount, GetCommandLineParam
418 : */
419 : static OUString GetAppFileName();
420 :
421 : ///@}
422 :
423 : /** @name Error Handling
424 :
425 : \em Very rudimentary error handling is done by these
426 : functions.
427 :
428 : @{
429 : */
430 :
431 : /** Handles an error code.
432 :
433 : @remark This is not actually an exception. It merely takes an
434 : error code, then in most cases aborts. The list of exception
435 : identifiers can be found at include/vcl/apptypes.hxx - each
436 : one starts with EXC_*
437 :
438 : @param nError The error code identifier
439 :
440 : @returns sal_uInt16 value - if it is 0, then the error wasn't handled.
441 :
442 : @see Abort
443 : */
444 : virtual sal_uInt16 Exception( sal_uInt16 nError );
445 :
446 : /** Ends the program prematurely with an error message.
447 :
448 : If the \code --norestore \endcode command line argument is given (assuming
449 : this process is run by developers who are interested in cores,
450 : vs. end users who are not) then it does a coredump.
451 :
452 : @param rErrorText The error message to report.
453 :
454 : @see Exception
455 : */
456 : static void Abort( const OUString& rErrorText );
457 :
458 : ///@}
459 :
460 : /** @name Event Loop Functions
461 :
462 : Functions that handle the LibreOffice main event loop are here,
463 : including a global lock called the Solar Mutex.
464 : */
465 : ///@{
466 :
467 : /** Run the main event processing loop until it is quit by Quit().
468 :
469 : @see Quit, Reschedule, Yield, EndYield, GetSolarMutex,
470 : GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
471 : EnableNoYieldMode, DisableNoYieldMode, AddPostYieldListener,
472 : RemovePostYieldListener
473 : */
474 : static void Execute();
475 :
476 : /** Quit the program
477 :
478 : @see Execute, Reschedule, Yield, EndYield, GetSolarMutex,
479 : GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
480 : EnableNoYieldMode, DisableNoYieldMode, AddPostYieldListener,
481 : RemovePostYieldListener
482 : */
483 : static void Quit();
484 :
485 : /** Attempt to reschedule in processing of current event(s)
486 :
487 : @param bAllEvents If set to true, then try to process all the
488 : events. If set to false, then only process the current
489 : event. Defaults to false.
490 :
491 : @see Execute, Quit, Yield, EndYield, GetSolarMutex,
492 : GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
493 : EnableNoYieldMode, DisableNoYieldMode, AddPostYieldListener,
494 : RemovePostYieldListener
495 : */
496 : static void Reschedule( bool bAllEvents = false );
497 :
498 : /** Allow processing of the next event.
499 :
500 : @see Execute, Quit, Reschedule, EndYield, GetSolarMutex,
501 : GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
502 : EnableNoYieldMode, DisableNoYieldMode, AddPostYieldListener,
503 : RemovePostYieldListener
504 : */
505 : static void Yield();
506 :
507 : /**
508 :
509 : @see Execute, Quit, Reschedule, Yield, GetSolarMutex,
510 : GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
511 : EnableNoYieldMode, DisableNoYieldMode, AddPostYieldListener,
512 : RemovePostYieldListener
513 : */
514 : static void EndYield();
515 :
516 : /** @brief Get the Solar Mutex for this thread.
517 :
518 : Get the Solar Mutex that prevents other threads from accessing VCL
519 : concurrently.
520 :
521 : @returns SolarMutex reference
522 :
523 : @see Execute, Quit, Reschedule, Yield, EndYield,
524 : GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
525 : EnableNoYieldMode, DisableNoYieldMode, AddPostYieldListener,
526 : RemovePostYieldListener
527 : */
528 : static comphelper::SolarMutex& GetSolarMutex();
529 :
530 : /** Get the main thread ID.
531 :
532 : @returns oslThreadIdentifier that contains the thread ID
533 :
534 : @see Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
535 : ReleaseSolarMutex, AcquireSolarMutex,
536 : EnableNoYieldMode, DisableNoYieldMode, AddPostYieldListener,
537 : RemovePostYieldListener
538 : */
539 : static oslThreadIdentifier GetMainThreadIdentifier();
540 :
541 : /** @brief Release Solar Mutex(es) for this thread
542 :
543 : Release the Solar Mutex(es) that prevents other threads from accessing
544 : VCL concurrently.
545 :
546 : @returns The number of mutexes that were acquired by this thread.
547 :
548 : @see Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
549 : GetMainThreadIdentifier, AcquireSolarMutex,
550 : EnableNoYieldMode, DisableNoYieldMode, AddPostYieldListener,
551 : RemovePostYieldListener
552 : */
553 : static sal_uLong ReleaseSolarMutex();
554 :
555 : /** @brief Acquire Solar Mutex(es) for this thread.
556 :
557 : Acquire the Solar Mutex(es) that prevents other threads from accessing
558 : VCL concurrently.
559 :
560 : @see Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
561 : GetMainThreadIdentifier, ReleaseSolarMutex,
562 : EnableNoYieldMode, DisableNoYieldMode, AddPostYieldListener,
563 : RemovePostYieldListener
564 : */
565 : static void AcquireSolarMutex( sal_uLong nCount );
566 :
567 : /** @brief Enables "no yield" mode
568 :
569 : "No yield" mode prevents Yield() from waiting for events.
570 :
571 : @remarks This was originally implemented in OOo bug 98792 to improve
572 : Impress slideshows.
573 :
574 : @see DisableNoYieldMode, Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
575 : GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
576 : DisableNoYield, AddPostYieldListener, RemovePostYieldListener
577 : */
578 : static void EnableNoYieldMode();
579 :
580 : /** @brief Disables "no yield" mode
581 :
582 : "No yield" mode prevents Yield() from waiting for events.
583 :
584 : @remarks This was originally implemented in OOo bug 98792 to improve
585 : Impress slideshows.
586 :
587 : @see EnableNoYieldMode, Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
588 : GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
589 : EnableNoYield, AddPostYieldListener, RemovePostYieldListener
590 : */
591 :
592 : static void DisableNoYieldMode();
593 :
594 : /** Add a listener for yield events
595 :
596 : @param i_rListener Listener to add
597 :
598 : @see Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
599 : GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
600 : EnableNoYieldMode, DisableNoYieldMode, RemovePostYieldListener
601 : */
602 : static void AddPostYieldListener( const Link& i_rListener );
603 :
604 : /** Remove listener for yield events
605 :
606 : @param i_rListener Listener to remove
607 :
608 : @see Execute, Quit, Reschedule, Yield, EndYield, GetSolarMutex,
609 : GetMainThreadIdentifier, ReleaseSolarMutex, AcquireSolarMutex,
610 : AddPostYieldListener, EnableNoYieldMode, DisableNoYieldMode
611 : */
612 : static void RemovePostYieldListener( const Link& i_rListener );
613 :
614 :
615 : /** Queries whether the application is in "main", i.e. not yet in
616 : the event loop
617 :
618 : @returns true if in main, false if not in main
619 :
620 : @see IsInExecute, IsInModalMode
621 : */
622 : static bool IsInMain();
623 :
624 : /** Queries whether the application is in the event loop
625 :
626 : @returns true if in the event loop, false if not
627 :
628 : @see IsInMain, IsInModalMode
629 : */
630 : static bool IsInExecute();
631 :
632 : /** Queries whether application has a modal dialog active.
633 :
634 : @returns true if a modal dialog is active, false if not
635 :
636 : @see IsInMain, IsInExecute
637 : */
638 : static bool IsInModalMode();
639 :
640 : /** Return how many events are being dispatched.
641 :
642 : @returns the number of events currently being dispatched
643 : */
644 : static sal_uInt16 GetDispatchLevel();
645 :
646 : /** Determine if there are any pending input events.
647 :
648 : @param nType input identifier, defined in include/vcl/apptypes.hxx
649 : The default is VCL_INPUT_ANY.
650 :
651 : @returns true if there are pending events, false if not.
652 :
653 : @see GetLastInputInterval
654 : */
655 : static bool AnyInput( sal_uInt16 nType = VCL_INPUT_ANY );
656 :
657 : /** The interval from the last time that input was received.
658 :
659 : @returns system ticks - last input time
660 :
661 : @see AnyInput
662 : */
663 : static sal_uLong GetLastInputInterval();
664 :
665 : ///@}
666 :
667 : /* Determines if the UI is captured.
668 :
669 : The UI is considered captured if a system dialog is open (e.g. printer setup),
670 : a floating window, menu or toolbox dropdown is open, or a window has been
671 : captured by the mouse.
672 :
673 : @returns true if UI is captured, false if not
674 : */
675 : static bool IsUICaptured();
676 :
677 : /** @name Settings
678 :
679 : The following functions set system settings (e.g. tab color, etc.). There are functions
680 : that set settings objects, and functions that set and get the actual system settings for
681 : the application.
682 : */
683 : ///@{
684 :
685 : /** Sets user settings in settings object to override system settings
686 :
687 : The system settings that can be overridden are:
688 : - window dragging options (on or off, including live scrolling!)
689 : - style settings (e.g. checkbox color, border color, 3D colors,
690 : button rollover colors, etc.)
691 : - mouse settings
692 : - menu options, including the mouse follows the menu and whether menu
693 : icons are used
694 :
695 : @param rSettings Reference to the settings object to change.
696 :
697 : @see MergeSystemSettings, SetSettings, GetSettings
698 : */
699 : virtual void OverrideSystemSettings( AllSettings& rSettings );
700 :
701 : /** Set the settings object to the platform/desktop environment system
702 : settings.
703 :
704 : @param rSettings Reference to the settings object to change.
705 :
706 : @see OverrideSystemSettings, SetSettings, GetSettings
707 : */
708 : static void MergeSystemSettings( AllSettings& rSettings );
709 :
710 : /** Sets the application's settings and notifies all windows of the
711 : change.
712 :
713 : @param rSettings const reference to settings object used to
714 : change the application's settings.
715 :
716 : @see OverrideSystemSettings, MergeSystemSettings, GetSettings
717 : */
718 : static void SetSettings( const AllSettings& rSettings );
719 :
720 : /** Gets the application's settings. If the application hasn't initialized
721 : it's settings, then it does so (lazy initialization).
722 :
723 : @returns AllSettings instance that contains the current settings of the
724 : application.
725 :
726 : @see OverrideSystemSettings, MergeSystemSettings, SetSettings
727 : */
728 : static const AllSettings& GetSettings();
729 :
730 : /** Validate that the currently selected system UI font is suitable
731 : to display the application's UI.
732 :
733 : A localized test string will be checked if it can be displayed in the currently
734 : selected system UI font. If no glyphs are missing it can be assumed that the font
735 : is proper for display of the application's UI.
736 :
737 : @returns true if the system font is suitable for our UI and false if the test
738 : string could not be displayed with the system font.
739 : */
740 : static bool ValidateSystemFont();
741 :
742 : /** Get the application's locale data wrapper.
743 :
744 : @returns reference to a LocaleDataWrapper object
745 : */
746 : static const LocaleDataWrapper& GetAppLocaleDataWrapper();
747 :
748 : ///@}
749 :
750 : /** @name Event Listeners/Handlers
751 :
752 : A set of event listeners and callers. Note that in this code there is
753 : platform specific functions - namely for zoom and scroll events.
754 : */
755 : ///@{
756 :
757 :
758 : /** Call on all event hooks
759 :
760 : @param rEvt Reference to the notification event to send
761 : to the event hook.
762 :
763 : @return If any of the event hooks called upon fail with a non-zero
764 : status, then it stops processing any more event hooks and returns
765 : the error code as a long.
766 :
767 : */
768 : static long CallEventHooks( NotifyEvent& rEvt );
769 :
770 : /** Add a VCL event listener to the application. If no event listener exists,
771 : then initialize the application's event listener with a new one, then add
772 : the event listener.
773 :
774 : @param rEventListener Const reference to the event listener to add.
775 :
776 : @see RemoveEventListener, AddKeyListener, RemoveKeyListener
777 : */
778 : static void AddEventListener( const Link& rEventListener );
779 :
780 : /** Remove a VCL event listener from the application.
781 :
782 : @param rEventListener Const refernece to the event listener to be removed
783 :
784 : @see AddEventListener, AddKeyListener, RemoveKeyListener
785 : */
786 : static void RemoveEventListener( const Link& rEventListener );
787 :
788 : /** Add a keypress listener to the application. If keypress listener exists,
789 : then initialize the application's keypress event listener with a new one, then
790 : add the keypress listener.
791 :
792 : @param rKeyListener Const reference to the keypress event listener to add
793 :
794 : @see AddEventListener, RemoveEventListener, RemoveKeyListener
795 : */
796 : static void AddKeyListener( const Link& rKeyListener );
797 :
798 : /** Remove a keypress listener from the application.
799 :
800 : @param rKeyListener Const reference to the keypress event listener to be removed
801 :
802 : @see AddEventListener, RemoveEventListener, AddKeyListener
803 : */
804 : static void RemoveKeyListener( const Link& rKeyListener );
805 :
806 : /** Send event to all VCL application event listeners
807 :
808 : @param nEvent Event ID
809 : @param pWin Pointer to window to send event
810 : @param pData Pointer to data to send with event
811 :
812 : @see ImplCallEventListeners(VclSimpleEvent* pEvent)
813 : */
814 : static void ImplCallEventListeners( sal_uLong nEvent, vcl::Window* pWin, void* pData );
815 :
816 : /** Send event to all VCL application event listeners
817 :
818 : @param pEvent Pointer to VclSimpleEvent
819 :
820 : @see ImplCallEventListeners(sal_uLong nEvent, Windows* pWin, void* pData);
821 : */
822 : static void ImplCallEventListeners( VclSimpleEvent* pEvent );
823 :
824 : /** Handle keypress event
825 :
826 : @param nEvent Event ID for keypress
827 : @param pWin Pointer to window that receives the event
828 : @param pKeyEvent Received key event
829 :
830 : @see PostKeyEvent
831 : */
832 : static bool HandleKey( sal_uLong nEvent, vcl::Window *pWin, KeyEvent* pKeyEvent );
833 :
834 : /** Send keypress event
835 :
836 : @param nEvent Event ID for keypress
837 : @param pWin Pointer to window to which the event is sent
838 : @param pKeyEvent Key event to send
839 :
840 : @see HandleKey
841 : */
842 : static ImplSVEvent * PostKeyEvent( sal_uLong nEvent, vcl::Window *pWin, KeyEvent* pKeyEvent );
843 :
844 : /** Send mouse event
845 :
846 : @param nEvent Event ID for mouse event
847 : @param pWin Pointer to window to which the event is sent
848 : @param pKeyEvent Mouse event to send
849 : */
850 : static ImplSVEvent * PostMouseEvent( sal_uLong nEvent, vcl::Window *pWin, MouseEvent* pMouseEvent );
851 :
852 : /** Send zoom event
853 :
854 : Experimental work in progress. Available only for iOS and Android, and unclear whether actually
855 : is needed now with tiled rendering.
856 :
857 : @param nEvent Event ID for zoom event
858 : @param pWin Pointer to window to which the event is sent
859 : @param pZoomEvent Zoom event to send
860 : */
861 : static ImplSVEvent * PostZoomEvent( sal_uLong nEvent, vcl::Window *pWin, ZoomEvent* pZoomEvent );
862 :
863 : /* Send scroll event
864 :
865 : Experimental work in progress. Available only for iOS and Android, and unclear whether actually
866 : is needed now with tiled rendering.
867 :
868 : @param nEvent Event ID for scroll event
869 : @param pWin Pointer to window to which the event is sent
870 : @param pScrollEvent Scroll event to send
871 : */
872 : static ImplSVEvent * PostScrollEvent( sal_uLong nEvent, vcl::Window *pWin, ScrollEvent* pScrollEvent );
873 :
874 : /** Remove mouse and keypress events from a window... any also zoom and scroll events
875 : if the platform supports it.
876 :
877 : @param pWin Window to remove events from
878 :
879 : @see HandleKey, PostKeyEvent, PostMouseEvent, PostZoomEvent, PostScrollEvent
880 : */
881 : static void RemoveMouseAndKeyEvents( vcl::Window *pWin );
882 :
883 : /** Post a user event to the default window.
884 :
885 : User events allow for the deferral of work to later in the main-loop - at idle.
886 :
887 : @param rLink Link to event callback function
888 : @param pCaller Pointer to data sent to the event by the caller. Optional.
889 :
890 : @return the event ID used to post the event.
891 : */
892 : static ImplSVEvent * PostUserEvent( const Link& rLink, void* pCaller = NULL );
893 :
894 : /** Remove user event based on event ID
895 :
896 : @param nUserEvent User event to remove
897 : */
898 : static void RemoveUserEvent( ImplSVEvent * nUserEvent );
899 :
900 : /** Insert an idle handler into the application.
901 :
902 : If the idle event manager doesn't exist, then initialize it.
903 :
904 : @param rLink const reference to the idle handler
905 : @param nPrio The priority of the idle handler - idle handlers of a higher
906 : priority will be processed before this handler.
907 :
908 : @return true if the handler was inserted successfully, false if it couldn't be inserted.
909 : */
910 : static bool InsertIdleHdl( const Link& rLink, sal_uInt16 nPriority );
911 :
912 : /** Remove an idle handler from the application.
913 :
914 : @param rLink const reference to the idle handler to remove
915 : */
916 : static void RemoveIdleHdl( const Link& rLink );
917 :
918 : /*** Get the DisplayConnection.
919 :
920 : It is a reference to XDisplayConnection, which allows toolkits to send display
921 : events to the application.
922 :
923 : @returns UNO reference to an object that implements the css:awt:XDisplayConnection
924 : interface.
925 : */
926 : static css::uno::Reference< css::awt::XDisplayConnection > GetDisplayConnection();
927 :
928 : /** @deprecated AppEvent is used only in the Desktop class now. However, it is
929 : intended to notify the application that an event has occurred. It was in oldsv.cxx,
930 : but is still needed by a number of functions.
931 :
932 : @param rAppEvent const reference to ApplicationEvent event
933 : */
934 : virtual void AppEvent( const ApplicationEvent& rAppEvent );
935 :
936 : ///@}
937 :
938 : /** @name Application Window Functions
939 :
940 : Functions that deal with the application's windows
941 : */
942 : ///@{
943 :
944 : /** Get the main application window.
945 :
946 : @remark the main application window (or App window) has a style of WB_APP,
947 : there can only be on WorkWindow with this style, if a dialog or floating
948 : window cannot find a parent, then the parent becomes the app window.
949 :
950 : It also becomes the "default window", is used for help, is a fallback if
951 : the application has no name, and a number of other things.
952 :
953 : returns Pointer to main application window.
954 :
955 : @see GetFocusWindow, GetDefaultDevice
956 : */
957 : static WorkWindow* GetAppWindow();
958 :
959 : /** Get the currently focussed window.
960 :
961 : @returns Pointer to focused window.
962 :
963 : @see GetAppWindow, GetDefaultDevice
964 : */
965 : static vcl::Window* GetFocusWindow();
966 :
967 : /** Get the default "device" (in this case the default window).
968 :
969 : @returns Pointer to an OutputDevice. However, it is a Window object -
970 : Window class subclasses OutputDevice.
971 :
972 : @see GetAppWindow, GetFocusWindow
973 : */
974 : static OutputDevice* GetDefaultDevice();
975 :
976 : /** Get the first top-level window of the application.
977 :
978 : @returns Pointer to top-level window (a Window object)
979 :
980 : @see GetNextTopLevelWindow, GetTopWindowCount, GetTopWindow,
981 : GetActiveTopWindow
982 : */
983 : static vcl::Window* GetFirstTopLevelWindow();
984 :
985 : /** Get the next top level window.
986 :
987 : @param pWindow Pointer to Window object you wish to get the next
988 : window from.
989 :
990 : @returns Pointer to next top window.
991 : */
992 : static vcl::Window* GetNextTopLevelWindow( vcl::Window* pWindow );
993 :
994 : /** Return the number of top-level windows being used by the application
995 :
996 : @returns the number of top-level windows
997 :
998 : @see GetFirstTopLevelWindow, GetNextTopLevelWindow, GetTopWindow,
999 : GetActiveTopWindow
1000 :
1001 : */
1002 : static long GetTopWindowCount();
1003 :
1004 : /** Get the nth top window.
1005 :
1006 : @remark Top windows are actually implemented in a one-way linked list.
1007 : This iterates through top level windows n times.
1008 :
1009 : @param nIndex The index of the top-level window
1010 :
1011 : @returns The nth top-level window of the application
1012 :
1013 : @see GetFirstTopLevelWindow, GetNextTopLevelWindow, GetTopWindowCount,
1014 : GetActiveTopWindow
1015 : */
1016 : static vcl::Window* GetTopWindow( long nIndex );
1017 :
1018 : /** Get the "active" top window.
1019 :
1020 : An "active" top window is one that has a child window that has the
1021 : application's focus.
1022 :
1023 : @returns the active top window
1024 :
1025 : @see GetFirstTopLevelWindow, GetNextTopLevelWindow, GetTopWindowCount,
1026 : GetTopWindow
1027 : */
1028 : static vcl::Window* GetActiveTopWindow();
1029 :
1030 : ///@}
1031 :
1032 : /** Set the application's name.
1033 :
1034 : @param rUniqueName What to set the application name to
1035 :
1036 : @see GetAppName
1037 : */
1038 : static void SetAppName( const OUString& rUniqueName );
1039 :
1040 :
1041 : /** @name Application Name, Branding
1042 : */
1043 : ///@{
1044 :
1045 : /** Get the application's name.
1046 :
1047 : @returns The application name.
1048 : */
1049 : static OUString GetAppName();
1050 :
1051 : /** Load a localized branding PNG file as a bitmap.
1052 :
1053 : @param pName Name of the bitmap to load.
1054 : @param rBitmap Reference to BitmapEx object to load PNG into
1055 :
1056 : @returns true if the PNG could be loaded, otherwise returns false.
1057 : */
1058 : static bool LoadBrandBitmap (const char* pName, BitmapEx &rBitmap);
1059 :
1060 : ///@}
1061 :
1062 : /** @name Display and Screen
1063 : */
1064 : ///@{
1065 :
1066 : /** Set the default name of the application for message dialogs and printing.
1067 :
1068 : @param rDisplayName const reference to string to set the Display name to.
1069 :
1070 : @see GetDisplayName
1071 : */
1072 : static void SetDisplayName( const OUString& rDisplayName );
1073 :
1074 : /** Get the default name of the application for messag dialogs and printing.
1075 :
1076 : @returns The display name of the application.
1077 : */
1078 : static OUString GetDisplayName();
1079 :
1080 : /** Get the number of screens available for the display.
1081 :
1082 : @returns The number of screens available.
1083 :
1084 : @see GetScreenPosSizePixel
1085 : */
1086 : static unsigned int GetScreenCount();
1087 :
1088 : /** Get a screen's rectangular area.
1089 :
1090 : @param nScreen The number of the screen requested.
1091 :
1092 : @returns The area of the screen in a Rectangle object.
1093 :
1094 : @see GetScreenCount
1095 : */
1096 : static Rectangle GetScreenPosSizePixel( unsigned int nScreen );
1097 :
1098 : /** Determines if the screens that make up a display are separate or
1099 : form one large display area.
1100 :
1101 : @returns true when screens form up one large display area windows can be
1102 : moved between single screens (e.g. Xserver with Xinerama, Windows)
1103 : and false when different screens are separate and windows cannot be moved
1104 : between them (e.g. Xserver with multiple screens)
1105 :
1106 : @see GetBestScreen, GetDisplayBuiltInScreen
1107 : */
1108 : static bool IsUnifiedDisplay();
1109 :
1110 : /** Get the "best" screen.
1111 :
1112 : @returns If IsUnifiedDisplay() == true the return value will be
1113 : nearest screen of the target rectangle.
1114 :
1115 : In case of IsUnifiedDisplay() == false the return value
1116 : will always be GetDisplayDefaultScreen().
1117 :
1118 : @see IsUnifiedDisplay, GetDisplayBuiltInScreen
1119 : */
1120 : SAL_DLLPRIVATE static unsigned int GetBestScreen( const Rectangle& );
1121 :
1122 : /** Get the built-in screen.
1123 :
1124 : @return
1125 : This returns the LCD screen number for a laptop, or the primary
1126 : external VGA display for a desktop machine - it is where a presenter
1127 : console should be rendered if there are other (non-built-in) screens
1128 : present.
1129 :
1130 : @see IsUnifiedDisplay, GetBestScreen
1131 : */
1132 : static unsigned int GetDisplayBuiltInScreen();
1133 :
1134 : /** Get the display's external screen.
1135 :
1136 : Practically, this means - Get the screen we should run a presentation on.
1137 :
1138 : @returns 0 or 1 currently, will fallback to the first available screen if
1139 : there are more than one external screens. May be changed in the future.
1140 : */
1141 : static unsigned int GetDisplayExternalScreen();
1142 :
1143 : ///@}
1144 :
1145 : /** @name Accelerators and Mnemonics
1146 :
1147 : Accelerators allow a user to hold down Ctrl+key (or CMD+key on OS X)
1148 : combination to gain quick access to functionality.
1149 :
1150 : Mnemonics are underline letters in things like menus and dialog boxes
1151 : that allow a user to type in the letter to activate the menu or option.
1152 : */
1153 : ///@{
1154 :
1155 : /** Insert accelerator
1156 :
1157 : @param pAccel Pointer to an Accelerator object to insert
1158 :
1159 : @returns true if successful, false if otherwise
1160 :
1161 : @see RemoveAccel
1162 : */
1163 : static bool InsertAccel( Accelerator* pAccel );
1164 :
1165 : /** Remove accelerator
1166 :
1167 : @param pAccel Pointer to Accelerator object to remove
1168 :
1169 : @see InsertAccel
1170 : */
1171 : static void RemoveAccel( Accelerator* pAccel );
1172 :
1173 : /** Enable auto-mnemonics
1174 :
1175 : @param bEnabled True enables auto-mnemonics, and false disables it
1176 :
1177 : @see IsAutoMnemonicEnabled
1178 : */
1179 : static void EnableAutoMnemonic( bool bEnabled = true );
1180 :
1181 : /** Determines if auto-mnemonics are enabled.
1182 :
1183 : @returns True if auto-mnemonics is enabled, false if not.
1184 :
1185 : @see EnableAutoMnemonic
1186 : */
1187 : static bool IsAutoMnemonicEnabled();
1188 :
1189 : /** Get the number of reserved key codes used by the application.
1190 :
1191 : @returns number of reserved key codes
1192 :
1193 : @see GetReservedKeyCode
1194 : */
1195 : static sal_uLong GetReservedKeyCodeCount();
1196 :
1197 : /** Get the reserved key code.
1198 :
1199 : @param i The keycode number to retrieve
1200 :
1201 : @returns Const pointer to a KeyCode object
1202 :
1203 : @see GetReservedKeyCodeCount
1204 : */
1205 : static const vcl::KeyCode* GetReservedKeyCode( sal_uLong i );
1206 :
1207 : ///@}
1208 :
1209 : /** @name Application Help
1210 :
1211 : Deals with the help system, and "auto-help", where a user hovers a mouse above
1212 : a UI element and a tooltip with an explanation pops up.
1213 : */
1214 : ///@{
1215 :
1216 : /** Sets up help
1217 :
1218 : @param pHelp Pointer to a Help object (optional, can by NULL)
1219 :
1220 : @see GetHelp
1221 : */
1222 : static void SetHelp( Help* pHelp = NULL );
1223 :
1224 : /** Gets the application's help
1225 :
1226 : @returns Pointer to application's help object. Note that the application may
1227 : not have a help object, so it might return NULL.
1228 :
1229 : @see SetHelp
1230 : */
1231 : static Help* GetHelp();
1232 :
1233 : /** Turns on "auto-help" (hover mouse above UI element and a tooltip with an
1234 : explanation pops up.
1235 :
1236 : @param bEnabled Enables/disables auto-help.
1237 :
1238 : @see EnableAutoHelpId
1239 : */
1240 : static void EnableAutoHelpId( bool bEnabled = true );
1241 :
1242 : /** Determines if auto-help is enabled or disabled.
1243 :
1244 : @return true if auto-help is enabled, false if it is disabled.
1245 :
1246 : @see EnableAutoHelpId
1247 : */
1248 : static bool IsAutoHelpIdEnabled();
1249 :
1250 : ///@}
1251 :
1252 : /** @name Dialogs
1253 :
1254 : @remark "Dialog cancel mode" tells a headless install whether to
1255 : cancel dialogs when they appear. See the DialogCancelMode
1256 : enumerator.
1257 : */
1258 : ///@{
1259 :
1260 : /** Set the default parent window for dialog boxes.
1261 :
1262 : @param pWindow Pointer to window that should be the default parent.
1263 :
1264 : @remark You can set pWindow to NULL, which means there \em is no default parent.
1265 :
1266 : @see GetDefDialogParent
1267 : */
1268 : static void SetDefDialogParent( vcl::Window* pWindow );
1269 :
1270 : /** Get the default parent window for dialog boxes.
1271 :
1272 : @remark GetDefDialogParent does all sorts of things find a useful parent
1273 : window for dialogs. If it can't find one (it wasn't set!) then it
1274 : first uses the topmost parent of the active window to avoid using
1275 : floating windows or other dialog boxes. If there are no active
1276 : windows, then it will take a random stab and choose the first visible
1277 : top window. Otherwise, it defaults to the desktop.
1278 :
1279 : @returns Pointer to the default window.
1280 : */
1281 : static vcl::Window* GetDefDialogParent();
1282 :
1283 :
1284 : /** Gets the dialog cancel mode for headless environments.
1285 :
1286 : @return DialogCancelMode value
1287 :
1288 : @see SetDialogCancelMode, IsDialogCancelEnabled
1289 : */
1290 : static DialogCancelMode GetDialogCancelMode();
1291 :
1292 : /** Sets the dialog cancel mode for headless environments.
1293 :
1294 : @param mode DialogCancel mode value
1295 :
1296 : @see GetDialogCancelMode, IsDialogCancelEnabled
1297 : */
1298 : static void SetDialogCancelMode( DialogCancelMode mode );
1299 :
1300 : /** Determines if dialog cancel mode is enabled.
1301 :
1302 : @returns True if dialog cancel mode is enabled, false if disabled.
1303 :
1304 : @see GetDialogCancelMode, SetDialogCancelMode
1305 : */
1306 : static bool IsDialogCancelEnabled();
1307 :
1308 :
1309 : /** Make a dialog box a system window or not.
1310 :
1311 : @param nMode Can be either: SYSTEMWINDOW_MODE_NOAUTOMODE (0x0001) or
1312 : SYSTEMWINDOW_MODE_DIALOG (0x0002)
1313 :
1314 : @see GetSystemWindowMode
1315 : */
1316 : static void SetSystemWindowMode( sal_uInt16 nMode );
1317 :
1318 : /** Get the system window mode of dialogs.
1319 :
1320 : @returns SYSTEMWINDOW_MODE_NOAUTOMODE (0x0001) or SYSTEMWINDOW_MODE_DIALOG (0x0002)
1321 :
1322 : @see SetSystemWindowMode
1323 : */
1324 : static sal_uInt16 GetSystemWindowMode();
1325 :
1326 :
1327 : /** Set a dialog scaling factor. Used for localization.
1328 :
1329 : @param nScale Scaling factor
1330 : */
1331 : static void SetDialogScaleX( short nScale );
1332 :
1333 : ///@}
1334 :
1335 : /** @name VCL Toolkit and UNO Wrapper
1336 :
1337 : The VCL Toolkit implements the UNO XToolkit interface, which specifies a
1338 : factory interface for the window toolkit. It is similar to the abstract window
1339 : toolkit (AWT) in Java.
1340 :
1341 : */
1342 : ///@{
1343 :
1344 : /** Gets the VCL toolkit.
1345 :
1346 : @attention The global service manager has to be created before getting the toolkit!
1347 :
1348 : @returns UNO reference to VCL toolkit
1349 : */
1350 : static css::uno::Reference< css::awt::XToolkit > GetVCLToolkit();
1351 :
1352 : /** Get the application's UNO wrapper object.
1353 :
1354 : Note that this static function will only ever try to create UNO wrapper object once, and
1355 : if it fails then it will not ever try again, even if the function is called multiple times.
1356 :
1357 : @param bCreateIfNotExists Create the UNO wrapper object if it doesn't exist when true.
1358 :
1359 : @return UNO wrapper object.
1360 : */
1361 : static UnoWrapperBase* GetUnoWrapper( bool bCreateIfNotExists = true );
1362 :
1363 : /** Sets the application's UNO Wrapper object.
1364 :
1365 : @param pWrapper Pointer to UNO wrapper object.
1366 : */
1367 : static void SetUnoWrapper( UnoWrapperBase* pWrapper );
1368 :
1369 : ///@}
1370 :
1371 :
1372 : /*** @name Graphic Filters
1373 : */
1374 : ///@{
1375 :
1376 : /** Setup a new graphics filter
1377 :
1378 : @param rLink Const reference to a Link object, which the filter calls upon.
1379 :
1380 : @see GetFilterHdl
1381 : */
1382 : static void SetFilterHdl( const Link& rLink );
1383 :
1384 : /*** Get a new graphics filter
1385 :
1386 : @return Const reference to the Link object (the filter)
1387 : */
1388 : static const Link& GetFilterHdl();
1389 :
1390 : ///@}
1391 :
1392 : /** @name Headless Mode
1393 : */
1394 :
1395 : /** Enables headless mode.
1396 :
1397 : @param dialogsAreFatal Set to true if a dialog ends the session, false if not.
1398 :
1399 : @see IsHeadlessModeEnabled, IsHeadlessModeRequested
1400 : */
1401 : static void EnableHeadlessMode( bool dialogsAreFatal );
1402 :
1403 : /** Determines if headless mode is enabled
1404 :
1405 : @return True if headless mode is enabled, false if not.
1406 :
1407 : @see EnableHeadlessMode, IsHeadlessModeRequested
1408 : */
1409 : static bool IsHeadlessModeEnabled();
1410 :
1411 : /** Check command line arguments for \code --headless \endcode
1412 :
1413 : @return True if headless mode was requested, false if not
1414 :
1415 : @see EnableHeadlessMode, IsHeadlessModeEnabled
1416 : */
1417 : static bool IsHeadlessModeRequested();
1418 :
1419 : /** Enable Console Only mode
1420 :
1421 : Used to disable Mac specific app init that requires an app bundle.
1422 : */
1423 : static void EnableConsoleOnly();
1424 :
1425 : /** Determines if console only mode is enabled.
1426 :
1427 : Used to see if Mac specific app init has been disabled.
1428 :
1429 : @returns True if console only mode is on, false if not.
1430 :
1431 : @see EnableConsoleOnly
1432 : */
1433 : static bool IsConsoleOnly();
1434 :
1435 : ///@}
1436 :
1437 : /** @name IME Status Window Control
1438 : */
1439 : ///@{
1440 :
1441 : /** Determine application can toggle the IME status window on and off.
1442 :
1443 : @attention Must only be called with the Solar mutex locked.
1444 :
1445 : @return true if any IME status window can be toggled on and off
1446 : externally.
1447 :
1448 : @see ShowImeStatusWindow, GetShowImeStatusWindowDefault,
1449 : GetShowImeStatusWindowDefault
1450 : */
1451 : static bool CanToggleImeStatusWindow();
1452 :
1453 : /** Toggle any IME status window on and off.
1454 :
1455 : This only works if CanToggleImeStatusWindow returns true (otherwise,
1456 : any calls of this method are ignored).
1457 :
1458 : @remark Can be called without the Solar mutex locked.
1459 :
1460 : @param bShow If true, then show the IME status window
1461 :
1462 : @see GetShowImeStatusWindowDefault, CanToggleImeStatusWindow,
1463 : GetShowImeStatusWindow
1464 : */
1465 : static void ShowImeStatusWindow(bool bShow);
1466 :
1467 : /** Determines if the IME status window should be turned of by default.
1468 :
1469 : @return true if any IME status window should be turned on by default
1470 : (this decision can be locale dependent, for example).
1471 :
1472 : @see ShowImeStatusWindow, GetShowImeStatusWindowDefault,
1473 : CanToggleImeStatusWindow
1474 : */
1475 : static bool GetShowImeStatusWindowDefault();
1476 :
1477 : ///@}
1478 :
1479 : /** Get the desktop environment the process is currently running in
1480 :
1481 : @returns String representing the desktop environment
1482 : */
1483 : static const OUString& GetDesktopEnvironment();
1484 :
1485 : /*** @name Platform Functionality
1486 : */
1487 : ///@{
1488 :
1489 : /** Add a file to the system shells recent document list if there is any.
1490 : This function may have no effect under Unix because there is no standard
1491 : API among the different desktop managers.
1492 :
1493 : @param rFileUrl The file url of the document.
1494 :
1495 : @param rMimeType The mime content type of the document specified by aFileUrl.
1496 : If an empty string will be provided "application/octet-stream"
1497 : will be used.
1498 : */
1499 : static void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService);
1500 :
1501 : /*** Show a native error messagebox
1502 :
1503 : @param sTitle Title of error messagebox
1504 :
1505 : @param sMessage Message displayed in messagebox
1506 : */
1507 : static void ShowNativeErrorBox(const OUString& sTitle ,
1508 : const OUString& sMessage);
1509 :
1510 : /** Do we have a native / system file selector available?
1511 :
1512 : @returns True if native file selector is available, false otherwise.
1513 : */
1514 : static bool hasNativeFileSelection();
1515 :
1516 : /** Create a platform specific file picker, if one is available, otherwise return an
1517 : empty reference.
1518 :
1519 : @param rServiceManager Const reference to a UNO component context (service manager).
1520 :
1521 : @returns File picker if available, otherwise an empty reference.
1522 : */
1523 : static css::uno::Reference< css::ui::dialogs::XFilePicker2 >
1524 : createFilePicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1525 :
1526 : /** Create a platform specific folder picker, if one is available, otherwise return an
1527 : empty reference
1528 :
1529 : @param rServiceManager Const reference to a UNO component context (service manager).
1530 :
1531 : @returns Folder picker if available, otherwise an empty reference.
1532 : */
1533 : static css::uno::Reference< css::ui::dialogs::XFolderPicker2 >
1534 : createFolderPicker( const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
1535 :
1536 : /** Is the access interface enabled?
1537 :
1538 : @returns true
1539 : */
1540 : static bool IsEnableAccessInterface() { return true; }
1541 :
1542 : ///@}
1543 :
1544 : // For vclbootstrapprotector:
1545 : static void setDeInitHook(Link const & hook);
1546 :
1547 : private:
1548 :
1549 : static void InitSettings(ImplSVData* pSVData);
1550 :
1551 : DECL_STATIC_LINK( Application, PostEventHandler, void* );
1552 : };
1553 :
1554 :
1555 : class VCL_DLLPUBLIC SolarMutexGuard
1556 : {
1557 : private:
1558 : SolarMutexGuard( const SolarMutexGuard& );
1559 : const SolarMutexGuard& operator = ( const SolarMutexGuard& );
1560 : comphelper::SolarMutex& m_solarMutex;
1561 :
1562 : public:
1563 :
1564 : /** Acquires the object specified as parameter.
1565 : */
1566 26756530 : SolarMutexGuard() :
1567 26756530 : m_solarMutex(Application::GetSolarMutex())
1568 : {
1569 26756531 : m_solarMutex.acquire();
1570 26756532 : }
1571 :
1572 : /** Releases the mutex or interface. */
1573 26756532 : ~SolarMutexGuard()
1574 : {
1575 26756532 : m_solarMutex.release();
1576 26756532 : }
1577 : };
1578 :
1579 : class VCL_DLLPUBLIC SolarMutexClearableGuard
1580 : {
1581 : SolarMutexClearableGuard( const SolarMutexClearableGuard& );
1582 : const SolarMutexClearableGuard& operator = ( const SolarMutexClearableGuard& );
1583 : bool m_bCleared;
1584 : public:
1585 : /** Acquires mutex
1586 : */
1587 3080666 : SolarMutexClearableGuard()
1588 : : m_bCleared(false)
1589 3080666 : , m_solarMutex( Application::GetSolarMutex() )
1590 : {
1591 3080666 : m_solarMutex.acquire();
1592 3080666 : }
1593 :
1594 : /** Releases mutex. */
1595 3080666 : virtual ~SolarMutexClearableGuard()
1596 3080666 : {
1597 3080666 : if( !m_bCleared )
1598 : {
1599 206560 : m_solarMutex.release();
1600 : }
1601 3080666 : }
1602 :
1603 : /** Releases mutex. */
1604 2897673 : void SAL_CALL clear()
1605 : {
1606 2897673 : if( !m_bCleared )
1607 : {
1608 2874106 : m_solarMutex.release();
1609 2874106 : m_bCleared = true;
1610 : }
1611 2897673 : }
1612 : protected:
1613 : comphelper::SolarMutex& m_solarMutex;
1614 : };
1615 :
1616 : class VCL_DLLPUBLIC SolarMutexResettableGuard
1617 : {
1618 : SolarMutexResettableGuard( const SolarMutexResettableGuard& );
1619 : const SolarMutexResettableGuard& operator = ( const SolarMutexResettableGuard& );
1620 : bool m_bCleared;
1621 : public:
1622 : /** Acquires mutex
1623 : */
1624 2276517 : SolarMutexResettableGuard()
1625 : : m_bCleared(false)
1626 2276517 : , m_solarMutex( Application::GetSolarMutex() )
1627 : {
1628 2276517 : m_solarMutex.acquire();
1629 2276517 : }
1630 :
1631 : /** Releases mutex. */
1632 2276517 : virtual ~SolarMutexResettableGuard()
1633 2276517 : {
1634 2276517 : if( !m_bCleared )
1635 : {
1636 1815297 : m_solarMutex.release();
1637 : }
1638 2276517 : }
1639 :
1640 : /** Releases mutex. */
1641 939970 : void SAL_CALL clear()
1642 : {
1643 939970 : if( !m_bCleared)
1644 : {
1645 939970 : m_solarMutex.release();
1646 939970 : m_bCleared = true;
1647 : }
1648 939970 : }
1649 : /** Releases mutex. */
1650 478750 : void SAL_CALL reset()
1651 : {
1652 478750 : if( m_bCleared)
1653 : {
1654 478750 : m_solarMutex.acquire();
1655 478750 : m_bCleared = false;
1656 : }
1657 478750 : }
1658 : protected:
1659 : comphelper::SolarMutex& m_solarMutex;
1660 : };
1661 :
1662 : namespace vcl
1663 : {
1664 :
1665 : /** guard class that uses tryToAcquire() and has isAcquired() to check
1666 : */
1667 : class SolarMutexTryAndBuyGuard
1668 : : private boost::noncopyable
1669 : {
1670 : private:
1671 : bool m_isAcquired;
1672 : #ifdef DBG_UTIL
1673 : bool m_isChecked;
1674 : #endif
1675 : comphelper::SolarMutex& m_rSolarMutex;
1676 :
1677 : public:
1678 :
1679 2 : SolarMutexTryAndBuyGuard()
1680 : : m_isAcquired(false)
1681 : #ifdef DBG_UTIL
1682 : , m_isChecked(false)
1683 : #endif
1684 2 : , m_rSolarMutex(Application::GetSolarMutex())
1685 :
1686 : {
1687 2 : m_isAcquired = m_rSolarMutex.tryToAcquire();
1688 2 : }
1689 :
1690 2 : ~SolarMutexTryAndBuyGuard()
1691 : {
1692 : #ifdef DBG_UTIL
1693 : assert(m_isChecked);
1694 : #endif
1695 2 : if (m_isAcquired)
1696 2 : m_rSolarMutex.release();
1697 2 : }
1698 :
1699 2 : bool isAcquired()
1700 : {
1701 : #ifdef DBG_UTIL
1702 : m_isChecked = true;
1703 : #endif
1704 2 : return m_isAcquired;
1705 : }
1706 : };
1707 :
1708 : } // namespace vcl
1709 :
1710 : /**
1711 : A helper class that calls Application::ReleaseSolarMutex() in its constructor
1712 : and restores the mutex in its destructor.
1713 : */
1714 : class SolarMutexReleaser
1715 : {
1716 : sal_uLong mnReleased;
1717 :
1718 : public:
1719 512 : SolarMutexReleaser(): mnReleased(Application::ReleaseSolarMutex()) {}
1720 :
1721 512 : ~SolarMutexReleaser()
1722 : {
1723 512 : Application::AcquireSolarMutex( mnReleased );
1724 512 : }
1725 : };
1726 :
1727 : VCL_DLLPUBLIC Application* GetpApp();
1728 :
1729 : VCL_DLLPUBLIC bool InitVCL();
1730 : VCL_DLLPUBLIC void DeInitVCL();
1731 :
1732 : VCL_DLLPUBLIC bool InitAccessBridge();
1733 :
1734 : // only allowed to call, if no thread is running. You must call JoinMainLoopThread to free all memory.
1735 : VCL_DLLPUBLIC void CreateMainLoopThread( oslWorkerFunction pWorker, void * pThreadData );
1736 : VCL_DLLPUBLIC void JoinMainLoopThread();
1737 :
1738 136 : inline void Application::EndYield()
1739 : {
1740 136 : PostUserEvent( Link() );
1741 136 : }
1742 :
1743 : #endif // _APP_HXX
1744 :
1745 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|