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 .
23 #include "comphelper/solarmutex.hxx"
24 #include "osl/thread.hxx"
25 #include "osl/conditn.h"
26 #include <vcl/solarmutex.hxx>
28 #include "aqua/aquavcltypes.h"
30 #include "salinst.hxx"
35 class ApplicationEvent
;
38 class SalYieldMutex
: public vcl::SolarMutexObject
41 oslThreadIdentifier mnThreadId
;
45 virtual void acquire();
46 virtual void release();
47 virtual bool tryToAcquire();
48 sal_uLong
GetAcquireCount() const { return mnCount
; }
49 oslThreadIdentifier
GetThreadId() const { return mnThreadId
; }
52 #define YIELD_GUARD osl::Guard< comphelper::SolarMutex > aGuard( GetSalData()->mpFirstInstance->GetYieldMutex() )
55 class AquaSalInstance
: public SalInstance
59 AquaSalFrame
* mpFrame
;
63 SalUserEvent( AquaSalFrame
* pFrame
, void* pData
, sal_uInt16 nType
) :
64 mpFrame( pFrame
), mpData( pData
), mnType( nType
)
69 SalYieldMutex
* mpSalYieldMutex
; // Sal-Yield-Mutex
70 OUString maDefaultPrinter
;
71 oslThreadIdentifier maMainThread
;
73 int mnActivePrintJobs
;
74 std::list
< SalUserEvent
> maUserEvents
;
75 oslMutex maUserEventListMutex
;
76 oslCondition maWaitingYieldCond
;
78 typedef std::list
<const ApplicationEvent
*> AppEventList
;
79 static AppEventList aAppEventList
;
83 virtual ~AquaSalInstance();
85 virtual SalSystem
* CreateSystem();
86 virtual void DestroySystem(SalSystem
*);
87 virtual SalFrame
* CreateChildFrame( SystemParentData
* pParent
, sal_uLong nStyle
);
88 virtual SalFrame
* CreateFrame( SalFrame
* pParent
, sal_uLong nStyle
);
89 virtual void DestroyFrame( SalFrame
* pFrame
);
90 virtual SalObject
* CreateObject( SalFrame
* pParent
, SystemWindowData
* pWindowData
, sal_Bool bShow
= sal_True
);
91 virtual void DestroyObject( SalObject
* pObject
);
92 virtual SalVirtualDevice
* CreateVirtualDevice( SalGraphics
* pGraphics
,
94 sal_uInt16 nBitCount
, const SystemGraphicsData
*pData
);
95 virtual void DestroyVirtualDevice( SalVirtualDevice
* pDevice
);
97 virtual SalInfoPrinter
* CreateInfoPrinter( SalPrinterQueueInfo
* pQueueInfo
,
98 ImplJobSetup
* pSetupData
);
99 virtual void DestroyInfoPrinter( SalInfoPrinter
* pPrinter
);
100 virtual SalPrinter
* CreatePrinter( SalInfoPrinter
* pInfoPrinter
);
101 virtual void DestroyPrinter( SalPrinter
* pPrinter
);
102 virtual void GetPrinterQueueInfo( ImplPrnQueueList
* pList
);
103 virtual void GetPrinterQueueState( SalPrinterQueueInfo
* pInfo
);
104 virtual void DeletePrinterQueueInfo( SalPrinterQueueInfo
* pInfo
);
105 virtual OUString
GetDefaultPrinter();
106 virtual SalTimer
* CreateSalTimer();
107 virtual SalI18NImeStatus
* CreateI18NImeStatus();
108 virtual SalSystem
* CreateSalSystem();
109 virtual SalBitmap
* CreateSalBitmap();
110 virtual comphelper::SolarMutex
* GetYieldMutex();
111 virtual sal_uLong
ReleaseYieldMutex();
112 virtual void AcquireYieldMutex( sal_uLong nCount
);
113 virtual bool CheckYieldMutex();
114 virtual void Yield( bool bWait
, bool bHandleAllCurrentEvents
);
115 virtual bool AnyInput( sal_uInt16 nType
);
116 virtual SalMenu
* CreateMenu( sal_Bool bMenuBar
, Menu
* pVCLMenu
);
117 virtual void DestroyMenu( SalMenu
* );
118 virtual SalMenuItem
* CreateMenuItem( const SalItemParams
* pItemData
);
119 virtual void DestroyMenuItem( SalMenuItem
* );
120 virtual SalSession
* CreateSalSession();
121 virtual void* GetConnectionIdentifier( ConnectionIdentifierType
& rReturnedType
, int& rReturnedBytes
);
122 virtual void AddToRecentDocumentList(const OUString
& rFileUrl
, const OUString
& rMimeType
, const OUString
& rDocumentService
);
123 virtual void SetEventCallback( void* pInstance
, bool(*pCallback
)(void*,void*,int) );
124 virtual void SetErrorEventCallback( void* pInstance
, bool(*pCallback
)(void*,void*,int) );
126 // dtrans implementation
127 virtual com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
>
128 CreateClipboard( const com::sun::star::uno::Sequence
< com::sun::star::uno::Any
>& i_rArguments
);
129 virtual com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
> CreateDragSource();
130 virtual com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
> CreateDropTarget();
132 static void handleAppDefinedEvent( NSEvent
* pEvent
);
134 // check whether a particular string is passed on the command line
135 // this is needed to avoid duplicate open events through a) command line and b) NSApp's openFile
136 static bool isOnCommandLine( const OUString
& );
141 friend class AquaSalFrame
;
143 void PostUserEvent( AquaSalFrame
* pFrame
, sal_uInt16 nType
, void* pData
);
144 void delayedSettingsChanged( bool bInvalidate
);
146 bool isNSAppThread() const;
148 void startedPrintJob() { mnActivePrintJobs
++; }
149 void endedPrintJob() { mnActivePrintJobs
--; }
151 // event subtypes for NSApplicationDefined events
152 static const short AppExecuteSVMain
= 0x7fff;
153 static const short AppEndLoopEvent
= 1;
154 static const short AppStartTimerEvent
= 10;
155 static const short AppleRemoteEvent
= 15;
156 static const short YieldWakeupEvent
= 20;
158 static NSMenu
* GetDynamicDockMenu();
161 // helper class: inverted solar guard
162 class YieldMutexReleaser
166 YieldMutexReleaser();
167 ~YieldMutexReleaser();
170 CGImageRef
CreateCGImage( const Image
& );
171 NSImage
* CreateNSImage( const Image
& );
173 #endif // _SV_SALINST_H
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */