xref: /aoo41x/main/vcl/unx/headless/svpinst.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _SVP_SALINST_HXX
29 #define _SVP_SALINST_HXX
30 
31 #include <vos/mutex.hxx>
32 #include <vos/thread.hxx>
33 
34 #include <salinst.hxx>
35 #include <salwtype.hxx>
36 #include <saltimer.hxx>
37 
38 #include <list>
39 
40 #include <time.h>  // timeval
41 
42 #define VIRTUAL_DESKTOP_WIDTH 1024
43 #define VIRTUAL_DESKTOP_HEIGHT 768
44 #define VIRTUAL_DESKTOP_DEPTH 24
45 
46 // -------------------------------------------------------------------------
47 // SalYieldMutex
48 // -------------------------------------------------------------------------
49 
50 class SvpSalYieldMutex : public vos::OMutex
51 {
52 protected:
53 	sal_uLong										mnCount;
54 	vos::OThread::TThreadIdentifier	mnThreadId;
55 
56 public:
57 												SvpSalYieldMutex();
58 
59 	virtual void								acquire();
60 	virtual void								release();
61 	virtual sal_Bool 							tryToAcquire();
62 
63 	sal_uLong										GetAcquireCount() const { return mnCount; }
64 	vos::OThread::TThreadIdentifier	GetThreadId() const { return mnThreadId; }
65 };
66 
67 // ---------------
68 // - SalTimer -
69 // ---------------
70 class SvpSalInstance;
71 class SvpSalTimer : public SalTimer
72 {
73     SvpSalInstance* m_pInstance;
74 public:
75     SvpSalTimer( SvpSalInstance* pInstance ) : m_pInstance( pInstance ) {}
76     virtual ~SvpSalTimer();
77 
78     // overload all pure virtual methods
79 	virtual void Start( sal_uLong nMS );
80 	virtual void Stop();
81 };
82 
83 // ---------------
84 // - SalInstance -
85 // ---------------
86 class SvpSalFrame;
87 class SvpSalInstance : public SalInstance
88 {
89     timeval			    m_aTimeout;
90     sal_uLong               m_nTimeoutMS;
91 	int                 m_pTimeoutFDS[2];
92     SvpSalYieldMutex    m_aYieldMutex;
93 
94     // internal event queue
95     struct SalUserEvent
96     {
97         const SalFrame*		m_pFrame;
98         void*			    m_pData;
99         sal_uInt16		   m_nEvent;
100 
101         SalUserEvent( const SalFrame* pFrame, void* pData, sal_uInt16 nEvent = SALEVENT_USEREVENT )
102                 : m_pFrame( pFrame ),
103                   m_pData( pData ),
104                   m_nEvent( nEvent )
105         {}
106     };
107 
108     oslMutex        m_aEventGuard;
109     std::list< SalUserEvent > m_aUserEvents;
110 
111     std::list< SalFrame* > m_aFrames;
112 
113     bool isFrameAlive( const SalFrame* pFrame ) const;
114 
115 public:
116     static SvpSalInstance* s_pDefaultInstance;
117 
118     SvpSalInstance();
119     virtual ~SvpSalInstance();
120 
121     void PostEvent( const SalFrame* pFrame, void* pData, sal_uInt16 nEvent );
122     void CancelEvent( const SalFrame* pFrame, void* pData, sal_uInt16 nEvent );
123 
124     void StartTimer( sal_uLong nMS );
125     void StopTimer();
126     void Wakeup();
127 
128     void registerFrame( SalFrame* pFrame ) { m_aFrames.push_back( pFrame ); }
129     void deregisterFrame( SalFrame* pFrame );
130     const std::list< SalFrame* >& getFrames() const { return m_aFrames; }
131 
132     bool            CheckTimeout( bool bExecuteTimers = true );
133 
134     // Frame
135     virtual SalFrame*      	CreateChildFrame( SystemParentData* pParent, sal_uLong nStyle );
136     virtual SalFrame*      	CreateFrame( SalFrame* pParent, sal_uLong nStyle );
137     virtual void			DestroyFrame( SalFrame* pFrame );
138 
139     // Object (System Child Window)
140     virtual SalObject*		CreateObject( SalFrame* pParent, SystemWindowData* pWindowData, sal_Bool bShow = sal_True );
141     virtual void			DestroyObject( SalObject* pObject );
142 
143     // VirtualDevice
144     // nDX and nDY in Pixel
145     // nBitCount: 0 == Default(=as window) / 1 == Mono
146     // pData allows for using a system dependent graphics or device context
147     virtual SalVirtualDevice*	CreateVirtualDevice( SalGraphics* pGraphics,
148                                                      long nDX, long nDY,
149                                                      sal_uInt16 nBitCount, const SystemGraphicsData *pData = NULL );
150     virtual void				DestroyVirtualDevice( SalVirtualDevice* pDevice );
151 
152     // Printer
153     // pSetupData->mpDriverData can be 0
154     // pSetupData must be updatet with the current
155     // JobSetup
156     virtual SalInfoPrinter*	CreateInfoPrinter( SalPrinterQueueInfo* pQueueInfo,
157                                                ImplJobSetup* pSetupData );
158     virtual void			DestroyInfoPrinter( SalInfoPrinter* pPrinter );
159     virtual SalPrinter*		CreatePrinter( SalInfoPrinter* pInfoPrinter );
160     virtual void			DestroyPrinter( SalPrinter* pPrinter );
161 
162     virtual void			GetPrinterQueueInfo( ImplPrnQueueList* pList );
163     virtual void			GetPrinterQueueState( SalPrinterQueueInfo* pInfo );
164     virtual void			DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo );
165     virtual String          GetDefaultPrinter();
166 
167     // SalTimer
168     virtual SalTimer*		CreateSalTimer();
169     // SalI18NImeStatus
170     virtual SalI18NImeStatus*   CreateI18NImeStatus();
171     // SalSystem
172     virtual SalSystem*		CreateSalSystem();
173     // SalBitmap
174     virtual SalBitmap*		CreateSalBitmap();
175 
176     // YieldMutex
177     virtual vos::IMutex*	GetYieldMutex();
178     virtual sal_uLong			ReleaseYieldMutex();
179     virtual void			AcquireYieldMutex( sal_uLong nCount );
180     virtual bool            CheckYieldMutex();
181 
182 	// wait next event and dispatch
183     // must returned by UserEvent (SalFrame::PostEvent)
184     // and timer
185     virtual void			Yield( bool bWait, bool bHandleAllCurrentEvents );
186     virtual bool			AnyInput( sal_uInt16 nType );
187 
188     // may return NULL to disable session management
189     virtual SalSession*		CreateSalSession();
190 
191     virtual void*			GetConnectionIdentifier( ConnectionIdentifierType& rReturnedType, int& rReturnedBytes );
192 
193     virtual void            AddToRecentDocumentList(const rtl::OUString& rFileUrl, const rtl::OUString& rMimeType);
194 };
195 
196 #endif // _SV_SALINST_HXX
197