xref: /trunk/main/fpicker/source/win32/filepicker/dibpreview.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _DIBPREVIEW_HXX_
25 #define _DIBPREVIEW_HXX_
26 
27 //------------------------------------------------------------------------
28 // includes
29 //------------------------------------------------------------------------
30 
31 #include "previewbase.hxx"
32 #include <osl/mutex.hxx>
33 
34 #if defined _MSC_VER
35 #pragma warning(push, 1)
36 #endif
37 #include <windows.h>
38 #if defined _MSC_VER
39 #pragma warning(pop)
40 #endif
41 
42 //---------------------------------------------
43 // A very simple wrapper for a window that does
44 // display DIBs.
45 // Maybe it would be better and more extensible
46 // to create another class that is responsible
47 // for rendering a specific image format into
48 // the area of the window, but for our purpose
49 // it's enough to go the simple way - KISS.
50 //---------------------------------------------
51 
52 class CDIBPreview : public PreviewBase
53 {
54 public:
55 
56     // ctor
57     CDIBPreview(HINSTANCE instance,HWND parent,sal_Bool bShowWindow = sal_False);
58 
59     // dtor
60     virtual ~CDIBPreview( );
61 
62     // preview interface implementation
63 
64     virtual sal_Int32 SAL_CALL getTargetColorDepth();
65 
66     virtual sal_Int32 SAL_CALL getAvailableWidth();
67 
68     virtual sal_Int32 SAL_CALL getAvailableHeight();
69 
70     virtual void SAL_CALL setImage(sal_Int16 aImageFormat, const ::com::sun::star::uno::Any& aImage);
71 
72     virtual sal_Bool SAL_CALL setShowState(sal_Bool bShowState);
73 
74     virtual sal_Bool SAL_CALL getShowState();
75 
76     virtual HWND SAL_CALL getWindowHandle() const;
77 
78 private:
79     virtual void SAL_CALL onPaint( HWND hWnd, HDC hDC );
80 
81     ATOM SAL_CALL RegisterDibPreviewWindowClass( );
82     void SAL_CALL UnregisterDibPreviewWindowClass( );
83 
84     static LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
85 
86 private:
87     HINSTANCE  m_Instance;
88     HWND       m_Hwnd;
89     com::sun::star::uno::Sequence<sal_Int8> m_Image;
90     osl::Mutex  m_PaintLock;
91 
92     // the preview window class has to be registered only
93     // once per process, so multiple instance of this class
94     // share the registered window class
95     static ATOM       s_ClassAtom;
96     static osl::Mutex s_Mutex;
97     static sal_Int32  s_RegisterDibPreviewWndCount;
98 
99 // prevent copy and assignment
100 private:
101     CDIBPreview(const CDIBPreview&);
102     CDIBPreview& operator=(const CDIBPreview&);
103 };
104 
105 
106 #endif
107