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 _DIBPREVIEW_HXX_
29 #define _DIBPREVIEW_HXX_
30 
31 //------------------------------------------------------------------------
32 // includes
33 //------------------------------------------------------------------------
34 
35 #include "previewbase.hxx"
36 #include <osl/mutex.hxx>
37 
38 #if defined _MSC_VER
39 #pragma warning(push, 1)
40 #endif
41 #include <windows.h>
42 #if defined _MSC_VER
43 #pragma warning(pop)
44 #endif
45 
46 //---------------------------------------------
47 // A very simple wrapper for a window that does
48 // display DIBs.
49 // Maybe it would be better and more extensible
50 // to create another class that is responsible
51 // for rendering a specific image format into
52 // the area of the window, but for our purpose
53 // it's enough to go the simple way - KISS.
54 //---------------------------------------------
55 
56 class CDIBPreview : public PreviewBase
57 {
58 public:
59 
60 	// ctor
61 	CDIBPreview(HINSTANCE instance,HWND parent,sal_Bool bShowWindow = sal_False);
62 
63     // dtor
64 	virtual ~CDIBPreview( );
65 
66 	// preview interface implementation
67 
68     virtual sal_Int32 SAL_CALL getTargetColorDepth()
69 		throw (::com::sun::star::uno::RuntimeException);
70 
71     virtual sal_Int32 SAL_CALL getAvailableWidth()
72 		throw (::com::sun::star::uno::RuntimeException);
73 
74     virtual sal_Int32 SAL_CALL getAvailableHeight()
75 		throw (::com::sun::star::uno::RuntimeException);
76 
77     virtual void SAL_CALL setImage(sal_Int16 aImageFormat, const ::com::sun::star::uno::Any& aImage)
78 		throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
79 
80     virtual sal_Bool SAL_CALL setShowState(sal_Bool bShowState)
81 		throw (::com::sun::star::uno::RuntimeException);
82 
83     virtual sal_Bool SAL_CALL getShowState()
84 		throw (::com::sun::star::uno::RuntimeException);
85 
86 	virtual HWND SAL_CALL getWindowHandle() const;
87 
88 private:
89 	virtual void SAL_CALL onPaint( HWND hWnd, HDC hDC );
90 
91     ATOM SAL_CALL RegisterDibPreviewWindowClass( );
92     void SAL_CALL UnregisterDibPreviewWindowClass( );
93 
94     static LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
95 
96 private:
97 	HINSTANCE  m_Instance;
98 	HWND	   m_Hwnd;
99 	com::sun::star::uno::Sequence<sal_Int8> m_Image;
100 	osl::Mutex	m_PaintLock;
101 
102     // the preview window class has to be registered only
103     // once per process, so multiple instance of this class
104     // share the registered window class
105     static ATOM       s_ClassAtom;
106     static osl::Mutex s_Mutex;
107     static sal_Int32  s_RegisterDibPreviewWndCount;
108 
109 // prevent copy and assignment
110 private:
111     CDIBPreview(const CDIBPreview&);
112     CDIBPreview& operator=(const CDIBPreview&);
113 };
114 
115 
116 #endif
117