1*b557fc96SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*b557fc96SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b557fc96SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b557fc96SAndrew Rist * distributed with this work for additional information
6*b557fc96SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b557fc96SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b557fc96SAndrew Rist * "License"); you may not use this file except in compliance
9*b557fc96SAndrew Rist * with the License. You may obtain a copy of the License at
10*b557fc96SAndrew Rist *
11*b557fc96SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*b557fc96SAndrew Rist *
13*b557fc96SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b557fc96SAndrew Rist * software distributed under the License is distributed on an
15*b557fc96SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b557fc96SAndrew Rist * KIND, either express or implied. See the License for the
17*b557fc96SAndrew Rist * specific language governing permissions and limitations
18*b557fc96SAndrew Rist * under the License.
19*b557fc96SAndrew Rist *
20*b557fc96SAndrew Rist *************************************************************/
21*b557fc96SAndrew Rist
22*b557fc96SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_fpicker.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir //------------------------------------------------------------------------
28cdf0e10cSrcweir // includes
29cdf0e10cSrcweir //------------------------------------------------------------------------
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include <tchar.h>
32cdf0e10cSrcweir #include "dibpreview.hxx"
33cdf0e10cSrcweir #include <osl/diagnose.h>
34cdf0e10cSrcweir
35cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UI_DIALOG_FILEPREVIEWIMAGEFORMATS_HPP_
36cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp>
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir
39cdf0e10cSrcweir #ifndef _USTRING_HXX_
40cdf0e10cSrcweir #include <rtl/ustring.hxx>
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir
43cdf0e10cSrcweir #include <stdexcept>
44cdf0e10cSrcweir #include <string>
45cdf0e10cSrcweir
46cdf0e10cSrcweir //------------------------------------------------------------------------
47cdf0e10cSrcweir //
48cdf0e10cSrcweir //------------------------------------------------------------------------
49cdf0e10cSrcweir
50cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
51cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException;
52cdf0e10cSrcweir using ::com::sun::star::uno::Any;
53cdf0e10cSrcweir using ::com::sun::star::lang::IllegalArgumentException;
54cdf0e10cSrcweir using rtl::OUString;
55cdf0e10cSrcweir
56cdf0e10cSrcweir //------------------------------------------------------------------------
57cdf0e10cSrcweir //
58cdf0e10cSrcweir //------------------------------------------------------------------------
59cdf0e10cSrcweir
60cdf0e10cSrcweir namespace /* private */
61cdf0e10cSrcweir {
62cdf0e10cSrcweir const LPTSTR CURRENT_INSTANCE = TEXT("CurrInst");
63cdf0e10cSrcweir };
64cdf0e10cSrcweir
65cdf0e10cSrcweir //------------------------------------------------------------------------
66cdf0e10cSrcweir // defines
67cdf0e10cSrcweir //------------------------------------------------------------------------
68cdf0e10cSrcweir
69cdf0e10cSrcweir #define PREVIEWWND_CLASS_NAME TEXT("DIBPreviewWnd###")
70cdf0e10cSrcweir
71cdf0e10cSrcweir // means 3 pixel left and 3 pixel right
72cdf0e10cSrcweir #define HORZ_BODER_SPACE 6
73cdf0e10cSrcweir
74cdf0e10cSrcweir // means 3 pixel top and 3 pixel bottom
75cdf0e10cSrcweir #define VERT_BORDER_SPACE 6
76cdf0e10cSrcweir
77cdf0e10cSrcweir //---------------------------------------------------
78cdf0e10cSrcweir // static member initialization
79cdf0e10cSrcweir //---------------------------------------------------
80cdf0e10cSrcweir
81cdf0e10cSrcweir osl::Mutex CDIBPreview::s_Mutex;
82cdf0e10cSrcweir ATOM CDIBPreview::s_ClassAtom = 0;
83cdf0e10cSrcweir sal_Int32 CDIBPreview::s_RegisterDibPreviewWndCount = 0;
84cdf0e10cSrcweir
85cdf0e10cSrcweir //---------------------------------------------------
86cdf0e10cSrcweir //
87cdf0e10cSrcweir //---------------------------------------------------
88cdf0e10cSrcweir
CDIBPreview(HINSTANCE instance,HWND parent,sal_Bool bShowWindow)89cdf0e10cSrcweir CDIBPreview::CDIBPreview(HINSTANCE instance,HWND parent,sal_Bool bShowWindow) :
90cdf0e10cSrcweir m_Instance(instance)
91cdf0e10cSrcweir {
92cdf0e10cSrcweir RegisterDibPreviewWindowClass();
93cdf0e10cSrcweir
94cdf0e10cSrcweir DWORD dwStyle = WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
95cdf0e10cSrcweir
96cdf0e10cSrcweir if (bShowWindow)
97cdf0e10cSrcweir dwStyle |= WS_VISIBLE;
98cdf0e10cSrcweir
99cdf0e10cSrcweir m_Hwnd = CreateWindowEx(
100cdf0e10cSrcweir WS_EX_CLIENTEDGE,
101cdf0e10cSrcweir PREVIEWWND_CLASS_NAME,
102cdf0e10cSrcweir TEXT(""),
103cdf0e10cSrcweir dwStyle,
104cdf0e10cSrcweir 0, 0, 0, 0,
105cdf0e10cSrcweir parent,
106cdf0e10cSrcweir (HMENU)0x0, // for child windows this will
107cdf0e10cSrcweir // be used as child window identifier
108cdf0e10cSrcweir m_Instance,
109cdf0e10cSrcweir (LPVOID)this // pass a pointer to the current
110cdf0e10cSrcweir // instance of this class
111cdf0e10cSrcweir );
112cdf0e10cSrcweir
113cdf0e10cSrcweir bool bSuccess = IsWindow(m_Hwnd);
114cdf0e10cSrcweir
115cdf0e10cSrcweir OSL_POSTCOND(bSuccess,"Coud not create preview window");
116cdf0e10cSrcweir
117cdf0e10cSrcweir if (!bSuccess)
118cdf0e10cSrcweir {
119cdf0e10cSrcweir UnregisterDibPreviewWindowClass();
120cdf0e10cSrcweir throw std::runtime_error("Could not create preview window");
121cdf0e10cSrcweir }
122cdf0e10cSrcweir }
123cdf0e10cSrcweir
124cdf0e10cSrcweir //---------------------------------------------------
125cdf0e10cSrcweir //
126cdf0e10cSrcweir //---------------------------------------------------
127cdf0e10cSrcweir
~CDIBPreview()128cdf0e10cSrcweir CDIBPreview::~CDIBPreview( )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir // remember: we don't have to destroy the
131cdf0e10cSrcweir // preview window because it will be destroyed
132cdf0e10cSrcweir // by it's parent window (the FileOpen dialog)
133cdf0e10cSrcweir // but we have to unregister the window class
134cdf0e10cSrcweir //if ( m_bWndClassRegistered )
135cdf0e10cSrcweir UnregisterDibPreviewWindowClass();
136cdf0e10cSrcweir }
137cdf0e10cSrcweir
138cdf0e10cSrcweir //-------------------------------
139cdf0e10cSrcweir //
140cdf0e10cSrcweir //-------------------------------
141cdf0e10cSrcweir
getTargetColorDepth()142cdf0e10cSrcweir sal_Int32 SAL_CALL CDIBPreview::getTargetColorDepth() throw (RuntimeException)
143cdf0e10cSrcweir {
144cdf0e10cSrcweir HDC hdc = GetDC(m_Hwnd);
145cdf0e10cSrcweir int clrRes = 0;
146cdf0e10cSrcweir
147cdf0e10cSrcweir if (hdc)
148cdf0e10cSrcweir clrRes = GetDeviceCaps(hdc, COLORRES);
149cdf0e10cSrcweir
150cdf0e10cSrcweir return clrRes;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir
153cdf0e10cSrcweir //-------------------------------
154cdf0e10cSrcweir //
155cdf0e10cSrcweir //-------------------------------
156cdf0e10cSrcweir
getAvailableWidth()157cdf0e10cSrcweir sal_Int32 SAL_CALL CDIBPreview::getAvailableWidth() throw (RuntimeException)
158cdf0e10cSrcweir {
159cdf0e10cSrcweir RECT rect;
160cdf0e10cSrcweir bool bRet = GetClientRect(m_Hwnd,&rect);
161cdf0e10cSrcweir
162cdf0e10cSrcweir sal_Int32 cx = 0;
163cdf0e10cSrcweir
164cdf0e10cSrcweir if ( bRet )
165cdf0e10cSrcweir cx = rect.right;
166cdf0e10cSrcweir
167cdf0e10cSrcweir return cx;
168cdf0e10cSrcweir }
169cdf0e10cSrcweir
170cdf0e10cSrcweir //-------------------------------
171cdf0e10cSrcweir //
172cdf0e10cSrcweir //-------------------------------
173cdf0e10cSrcweir
getAvailableHeight()174cdf0e10cSrcweir sal_Int32 SAL_CALL CDIBPreview::getAvailableHeight() throw (RuntimeException)
175cdf0e10cSrcweir {
176cdf0e10cSrcweir RECT rect;
177cdf0e10cSrcweir bool bRet = GetClientRect(m_Hwnd,&rect);
178cdf0e10cSrcweir
179cdf0e10cSrcweir sal_Int32 cy = 0;
180cdf0e10cSrcweir
181cdf0e10cSrcweir if ( bRet )
182cdf0e10cSrcweir cy = rect.bottom;
183cdf0e10cSrcweir
184cdf0e10cSrcweir return cy;
185cdf0e10cSrcweir }
186cdf0e10cSrcweir
187cdf0e10cSrcweir //-------------------------------
188cdf0e10cSrcweir //
189cdf0e10cSrcweir //-------------------------------
190cdf0e10cSrcweir
setImage(sal_Int16 aImageFormat,const Any & aImage)191cdf0e10cSrcweir void SAL_CALL CDIBPreview::setImage(sal_Int16 aImageFormat, const Any& aImage)
192cdf0e10cSrcweir throw (IllegalArgumentException, RuntimeException)
193cdf0e10cSrcweir {
194cdf0e10cSrcweir PreviewBase::setImage(aImageFormat,aImage);
195cdf0e10cSrcweir
196cdf0e10cSrcweir // if the any has no value we have an
197cdf0e10cSrcweir // empty Sequence which clears the
198cdf0e10cSrcweir // preview window
199cdf0e10cSrcweir osl::ClearableMutexGuard aGuard(m_PaintLock);
200cdf0e10cSrcweir
201cdf0e10cSrcweir m_Image.realloc(0);
202cdf0e10cSrcweir m_ImageData >>= m_Image;
203cdf0e10cSrcweir
204cdf0e10cSrcweir aGuard.clear();
205cdf0e10cSrcweir
206cdf0e10cSrcweir InvalidateRect(m_Hwnd,NULL,sal_False);
207cdf0e10cSrcweir UpdateWindow(m_Hwnd);
208cdf0e10cSrcweir }
209cdf0e10cSrcweir
210cdf0e10cSrcweir //-------------------------------
211cdf0e10cSrcweir //
212cdf0e10cSrcweir //-------------------------------
213cdf0e10cSrcweir
setShowState(sal_Bool bShowState)214cdf0e10cSrcweir sal_Bool SAL_CALL CDIBPreview::setShowState(sal_Bool bShowState) throw (RuntimeException)
215cdf0e10cSrcweir {
216cdf0e10cSrcweir PreviewBase::setShowState(bShowState);
217cdf0e10cSrcweir ShowWindow(m_Hwnd, m_bShowState ? SW_SHOW : SW_HIDE);
218cdf0e10cSrcweir return sal_True;
219cdf0e10cSrcweir }
220cdf0e10cSrcweir
221cdf0e10cSrcweir //-------------------------------
222cdf0e10cSrcweir //
223cdf0e10cSrcweir //-------------------------------
224cdf0e10cSrcweir
getShowState()225cdf0e10cSrcweir sal_Bool SAL_CALL CDIBPreview::getShowState() throw (RuntimeException)
226cdf0e10cSrcweir {
227cdf0e10cSrcweir return (sal_Bool)IsWindowVisible(m_Hwnd);
228cdf0e10cSrcweir }
229cdf0e10cSrcweir
230cdf0e10cSrcweir //-------------------------------
231cdf0e10cSrcweir //
232cdf0e10cSrcweir //-------------------------------
233cdf0e10cSrcweir
getWindowHandle() const234cdf0e10cSrcweir HWND SAL_CALL CDIBPreview::getWindowHandle() const
235cdf0e10cSrcweir {
236cdf0e10cSrcweir return m_Hwnd;
237cdf0e10cSrcweir }
238cdf0e10cSrcweir
239cdf0e10cSrcweir //---------------------------------------------------
240cdf0e10cSrcweir //
241cdf0e10cSrcweir //---------------------------------------------------
242cdf0e10cSrcweir
onPaint(HWND hWnd,HDC hDC)243cdf0e10cSrcweir void SAL_CALL CDIBPreview::onPaint(HWND hWnd, HDC hDC)
244cdf0e10cSrcweir {
245cdf0e10cSrcweir BITMAPFILEHEADER* pbmfh;
246cdf0e10cSrcweir BITMAPINFO * pbmi;
247cdf0e10cSrcweir sal_uInt8 * pBits;
248cdf0e10cSrcweir int cxDib;
249cdf0e10cSrcweir int cyDib;
250cdf0e10cSrcweir
251cdf0e10cSrcweir osl::MutexGuard aGuard(m_PaintLock);
252cdf0e10cSrcweir
253cdf0e10cSrcweir try
254cdf0e10cSrcweir {
255cdf0e10cSrcweir pbmfh = reinterpret_cast<BITMAPFILEHEADER*>(m_Image.getArray());
256cdf0e10cSrcweir
257cdf0e10cSrcweir if ( !IsBadReadPtr( pbmfh, sizeof(BITMAPFILEHEADER)) &&
258cdf0e10cSrcweir (pbmfh->bfType == ('B' | ('M' << 8))) )
259cdf0e10cSrcweir {
260cdf0e10cSrcweir pbmi = reinterpret_cast<BITMAPINFO*>((pbmfh + 1));
261cdf0e10cSrcweir pBits = reinterpret_cast<sal_uInt8*>(((DWORD)pbmfh) + pbmfh->bfOffBits);
262cdf0e10cSrcweir
263cdf0e10cSrcweir cxDib = pbmi->bmiHeader.biWidth;
264cdf0e10cSrcweir cyDib = abs (pbmi->bmiHeader.biHeight);
265cdf0e10cSrcweir
266cdf0e10cSrcweir SetStretchBltMode(hDC, COLORONCOLOR);
267cdf0e10cSrcweir
268cdf0e10cSrcweir int nWidth = getAvailableWidth();
269cdf0e10cSrcweir int nHeight = getAvailableHeight();
270cdf0e10cSrcweir
271cdf0e10cSrcweir int nX = abs(nWidth - cxDib) / 2;
272cdf0e10cSrcweir int nY = abs(nHeight - cyDib) / 2;
273cdf0e10cSrcweir
274cdf0e10cSrcweir int GDIError = GDI_ERROR;
275cdf0e10cSrcweir GDIError = StretchDIBits(
276cdf0e10cSrcweir hDC, nX, nY, cxDib, cyDib,
277cdf0e10cSrcweir 0, 0, cxDib, cyDib, pBits, pbmi,
278cdf0e10cSrcweir DIB_RGB_COLORS, SRCCOPY);
279cdf0e10cSrcweir
280cdf0e10cSrcweir OSL_ASSERT(GDI_ERROR != GDIError);
281cdf0e10cSrcweir
282cdf0e10cSrcweir // paint the border
283cdf0e10cSrcweir RECT rc;
284cdf0e10cSrcweir
285cdf0e10cSrcweir if (nY > 0)
286cdf0e10cSrcweir {
287cdf0e10cSrcweir // top
288cdf0e10cSrcweir rc.left = 0;
289cdf0e10cSrcweir rc.top = 0;
290cdf0e10cSrcweir rc.right = nWidth;
291cdf0e10cSrcweir rc.bottom = nY;
292cdf0e10cSrcweir FillRect(hDC,&rc,(HBRUSH)(COLOR_INACTIVEBORDER + 1));
293cdf0e10cSrcweir
294cdf0e10cSrcweir // bottom
295cdf0e10cSrcweir rc.left = 0;
296cdf0e10cSrcweir rc.top = nHeight - nY - 1;
297cdf0e10cSrcweir rc.right = nWidth;
298cdf0e10cSrcweir rc.bottom = nHeight;
299cdf0e10cSrcweir FillRect(hDC,&rc,(HBRUSH)(COLOR_INACTIVEBORDER + 1));
300cdf0e10cSrcweir }
301cdf0e10cSrcweir
302cdf0e10cSrcweir if (nX > 0)
303cdf0e10cSrcweir {
304cdf0e10cSrcweir // left
305cdf0e10cSrcweir rc.left = 0;
306cdf0e10cSrcweir rc.top = nY;
307cdf0e10cSrcweir rc.right = nX;
308cdf0e10cSrcweir rc.bottom = nHeight - nY;
309cdf0e10cSrcweir FillRect(hDC,&rc,(HBRUSH)(COLOR_INACTIVEBORDER + 1));
310cdf0e10cSrcweir
311cdf0e10cSrcweir // right
312cdf0e10cSrcweir rc.left = nWidth - nX - 1;
313cdf0e10cSrcweir rc.top = nY;
314cdf0e10cSrcweir rc.right = nWidth;
315cdf0e10cSrcweir rc.bottom = nHeight - nY;
316cdf0e10cSrcweir FillRect(hDC,&rc,(HBRUSH)(COLOR_INACTIVEBORDER + 1));
317cdf0e10cSrcweir }
318cdf0e10cSrcweir }
319cdf0e10cSrcweir else // clear background
320cdf0e10cSrcweir {
321cdf0e10cSrcweir RECT rc;
322cdf0e10cSrcweir GetClientRect(hWnd,&rc);
323cdf0e10cSrcweir FillRect(hDC,&rc,(HBRUSH)(COLOR_INACTIVEBORDER + 1));
324cdf0e10cSrcweir }
325cdf0e10cSrcweir }
326cdf0e10cSrcweir catch(...)
327cdf0e10cSrcweir {
328cdf0e10cSrcweir OSL_ASSERT(sal_False);
329cdf0e10cSrcweir }
330cdf0e10cSrcweir }
331cdf0e10cSrcweir
332cdf0e10cSrcweir //---------------------------------------------------
333cdf0e10cSrcweir //
334cdf0e10cSrcweir //---------------------------------------------------
335cdf0e10cSrcweir
WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)336cdf0e10cSrcweir LRESULT CALLBACK CDIBPreview::WndProc(
337cdf0e10cSrcweir HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
338cdf0e10cSrcweir {
339cdf0e10cSrcweir LRESULT lResult = 0;
340cdf0e10cSrcweir
341cdf0e10cSrcweir switch(uMsg)
342cdf0e10cSrcweir {
343cdf0e10cSrcweir
344cdf0e10cSrcweir // we connect a pointer to the current instance
345cdf0e10cSrcweir // with a window instance via SetProp
346cdf0e10cSrcweir case WM_CREATE:
347cdf0e10cSrcweir {
348cdf0e10cSrcweir LPCREATESTRUCT lpcs =
349cdf0e10cSrcweir reinterpret_cast< LPCREATESTRUCT >(lParam);
350cdf0e10cSrcweir
351cdf0e10cSrcweir OSL_ASSERT(lpcs->lpCreateParams);
352cdf0e10cSrcweir
353cdf0e10cSrcweir // connect the instance handle to the window
354cdf0e10cSrcweir SetProp(hWnd, CURRENT_INSTANCE, lpcs->lpCreateParams);
355cdf0e10cSrcweir }
356cdf0e10cSrcweir break;
357cdf0e10cSrcweir
358cdf0e10cSrcweir // we remove the window property which connects
359cdf0e10cSrcweir // a class instance with a window class
360cdf0e10cSrcweir case WM_NCDESTROY:
361cdf0e10cSrcweir {
362cdf0e10cSrcweir // RemoveProp returns the saved value on success
363cdf0e10cSrcweir if (reinterpret_cast<CDIBPreview*>(
364cdf0e10cSrcweir RemoveProp(hWnd, CURRENT_INSTANCE)) == NULL)
365cdf0e10cSrcweir {
366cdf0e10cSrcweir OSL_ASSERT(false);
367cdf0e10cSrcweir }
368cdf0e10cSrcweir }
369cdf0e10cSrcweir break;
370cdf0e10cSrcweir
371cdf0e10cSrcweir case WM_PAINT:
372cdf0e10cSrcweir {
373cdf0e10cSrcweir CDIBPreview* pImpl = reinterpret_cast<CDIBPreview*>(
374cdf0e10cSrcweir GetProp(hWnd, CURRENT_INSTANCE));
375cdf0e10cSrcweir
376cdf0e10cSrcweir OSL_ASSERT(pImpl);
377cdf0e10cSrcweir
378cdf0e10cSrcweir HDC hDC;
379cdf0e10cSrcweir PAINTSTRUCT ps;
380cdf0e10cSrcweir
381cdf0e10cSrcweir hDC = BeginPaint(hWnd,&ps);
382cdf0e10cSrcweir pImpl->onPaint(hWnd,hDC);
383cdf0e10cSrcweir EndPaint(hWnd,&ps);
384cdf0e10cSrcweir }
385cdf0e10cSrcweir break;
386cdf0e10cSrcweir
387cdf0e10cSrcweir // ignore this message in order to
388cdf0e10cSrcweir // avoid flickering during paint
389cdf0e10cSrcweir case WM_ERASEBKGND:
390cdf0e10cSrcweir lResult = 1;
391cdf0e10cSrcweir break;
392cdf0e10cSrcweir
393cdf0e10cSrcweir default:
394cdf0e10cSrcweir return DefWindowProc(hWnd, uMsg, wParam, lParam);
395cdf0e10cSrcweir }
396cdf0e10cSrcweir
397cdf0e10cSrcweir return lResult;
398cdf0e10cSrcweir }
399cdf0e10cSrcweir
400cdf0e10cSrcweir //---------------------------------------------------
401cdf0e10cSrcweir //
402cdf0e10cSrcweir //---------------------------------------------------
403cdf0e10cSrcweir
RegisterDibPreviewWindowClass()404cdf0e10cSrcweir ATOM SAL_CALL CDIBPreview::RegisterDibPreviewWindowClass()
405cdf0e10cSrcweir {
406cdf0e10cSrcweir osl::MutexGuard aGuard( s_Mutex );
407cdf0e10cSrcweir
408cdf0e10cSrcweir if (0 == s_ClassAtom)
409cdf0e10cSrcweir {
410cdf0e10cSrcweir // register the preview window class
411cdf0e10cSrcweir WNDCLASSEX wndClsEx;
412cdf0e10cSrcweir ZeroMemory(&wndClsEx, sizeof(wndClsEx));
413cdf0e10cSrcweir
414cdf0e10cSrcweir wndClsEx.cbSize = sizeof(wndClsEx);
415cdf0e10cSrcweir wndClsEx.style = CS_HREDRAW | CS_VREDRAW;
416cdf0e10cSrcweir wndClsEx.lpfnWndProc = CDIBPreview::WndProc;
417cdf0e10cSrcweir wndClsEx.hInstance = m_Instance;
418cdf0e10cSrcweir wndClsEx.hbrBackground = (HBRUSH)(COLOR_INACTIVEBORDER + 1);
419cdf0e10cSrcweir wndClsEx.lpszClassName = PREVIEWWND_CLASS_NAME;
420cdf0e10cSrcweir
421cdf0e10cSrcweir // register the preview window class
422cdf0e10cSrcweir // !!! Win95 - the window class will be unregistered automaticly
423cdf0e10cSrcweir // if the dll is unloaded
424cdf0e10cSrcweir // Win2000 - the window class must be unregistered manually
425cdf0e10cSrcweir // if the dll is unloaded
426cdf0e10cSrcweir s_ClassAtom = RegisterClassEx(&wndClsEx);
427cdf0e10cSrcweir
428cdf0e10cSrcweir OSL_POSTCOND(s_ClassAtom,"Could not register preview window class");
429cdf0e10cSrcweir
430cdf0e10cSrcweir if (0 == s_ClassAtom)
431cdf0e10cSrcweir throw std::runtime_error("Preview window class could not be registered");
432cdf0e10cSrcweir }
433cdf0e10cSrcweir
434cdf0e10cSrcweir // increment the register class counter
435cdf0e10cSrcweir // so that we keep track of the number
436cdf0e10cSrcweir // of class registrations
437cdf0e10cSrcweir //if ( 0 != s_ClassAtom )
438cdf0e10cSrcweir s_RegisterDibPreviewWndCount++;
439cdf0e10cSrcweir
440cdf0e10cSrcweir return s_ClassAtom;
441cdf0e10cSrcweir }
442cdf0e10cSrcweir
443cdf0e10cSrcweir //---------------------------------------------------
444cdf0e10cSrcweir //
445cdf0e10cSrcweir //---------------------------------------------------
446cdf0e10cSrcweir
UnregisterDibPreviewWindowClass()447cdf0e10cSrcweir void SAL_CALL CDIBPreview::UnregisterDibPreviewWindowClass()
448cdf0e10cSrcweir {
449cdf0e10cSrcweir osl::MutexGuard aGuard( s_Mutex );
450cdf0e10cSrcweir
451cdf0e10cSrcweir OSL_ASSERT( ( (0 != s_ClassAtom) && (s_RegisterDibPreviewWndCount > 0)) ||
452cdf0e10cSrcweir ( (0 == s_ClassAtom) && (0 == s_RegisterDibPreviewWndCount) ) );
453cdf0e10cSrcweir
454cdf0e10cSrcweir // update the register class counter
455cdf0e10cSrcweir // and unregister the window class if
456cdf0e10cSrcweir // counter drops to zero
457cdf0e10cSrcweir if (0 != s_ClassAtom)
458cdf0e10cSrcweir {
459cdf0e10cSrcweir s_RegisterDibPreviewWndCount--;
460cdf0e10cSrcweir OSL_ASSERT(s_RegisterDibPreviewWndCount >= 0);
461cdf0e10cSrcweir }
462cdf0e10cSrcweir
463cdf0e10cSrcweir if (0 == s_RegisterDibPreviewWndCount)
464cdf0e10cSrcweir {
465cdf0e10cSrcweir UnregisterClass((LPCTSTR)MAKELONG(s_ClassAtom,0),m_Instance);
466cdf0e10cSrcweir s_ClassAtom = 0;
467cdf0e10cSrcweir }
468cdf0e10cSrcweir }
469