merged tag ooo/DEV300_m102
[LibreOffice.git] / fpicker / source / win32 / filepicker / PreviewCtrl.hxx
blob3e91acab4c56af8181c0dac10c690d53f74d8d97
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 #ifndef _PREVIEWCTRL_HXX_
29 #define _PREVIEWCTRL_HXX_
31 //------------------------------------------------------------------------
32 // includes
33 //------------------------------------------------------------------------
35 #include <sal/types.h>
36 #include <rtl/ustring.hxx>
38 #include <comdef.h>
40 #include <memory>
42 //---------------------------------------------
43 // declaration
44 //---------------------------------------------
46 class CDimension
48 public:
49 CDimension( ) :
50 m_cx( 0 ),
51 m_cy( 0 )
55 CDimension( sal_Int32 cx, sal_Int32 cy ) :
56 m_cx( cx ),
57 m_cy( cy )
61 sal_Int32 m_cx;
62 sal_Int32 m_cy;
65 //--------------------------------------------------
66 // we use OleInitialize here because we are calling
67 // some Ole functions to realize the picture preview
68 // and we expect to be called from the main thread
69 // so that there will be no problem calling
70 // OleInitialize (the main thread should be an STA)
71 // When OleInitialize should fail at worst the
72 // preview doesn't work
73 //--------------------------------------------------
75 class CAutoOleInit
77 public:
79 // used to communicate ole
80 // initialzation failures
81 class COleInitException { };
83 CAutoOleInit( )
85 HRESULT hr = OleInitialize( NULL );
86 if ( FAILED( hr ) )
87 throw COleInitException( );
90 ~CAutoOleInit( )
92 OleUninitialize( );
96 //---------------------------------------------
97 // A simple file preview class to preview some
98 // common picture formats like *.gif, *jpg, etc.
99 // This class is not thread-safe and is
100 // implmented as singleton, because the class
101 // has only one static member to reconnect
102 // from callback functions
103 // we use a singleton-destroyer to get rid off
104 // the singleton instance, but this happens
105 // only on shutdown (unloading of the dll) -
106 // it's a question of taste (other solutions
107 // are possible)
108 //---------------------------------------------
110 class CFilePreview
112 public:
113 // to ensure only one instance (singleton)
114 static CFilePreview* createInstance(
115 HWND aParent,
116 POINT ulCorner,
117 const CDimension& aSize,
118 HINSTANCE hInstance,
119 sal_Bool bShow = sal_True,
120 sal_Bool bEnabled = sal_True );
122 // sets the size of the preview window
123 sal_Bool SAL_CALL setSize( const CDimension& aSize );
125 // returns the CDimension of the preview
126 sal_Bool SAL_CALL getSize( CDimension& theSize ) const;
128 // sets the position of the upper left corner
129 // of the preview window relative to the
130 // upper left corner of the parent window
131 sal_Bool SAL_CALL setPos( POINT ulCorner );
133 // returns the current position of the preview
134 // relative to the upper left corner of the
135 // parent window
136 sal_Bool SAL_CALL getPos( POINT& ulCorner ) const;
138 // enables or disables the preview window
139 // bEnable - true the window is enabled and updates its
140 // view when update is called
141 // bEnable - false the window shows itself in disabled
142 // mode and does not update its view when update is
143 // called
144 void SAL_CALL enable( sal_Bool bEnable );
146 // shows the preview window
147 // possible values see SHOW_STATE
148 sal_Bool SAL_CALL show( sal_Bool bShow );
151 // if the preview is shown and enabled
152 // preview of the given file will be shown
153 // returns true on success or false if an error
154 // occured (the file in not there or not accessible etc.)
155 virtual sal_Bool SAL_CALL update( const rtl::OUString& aFileName );
157 protected:
158 // clients can create instances only through the static create method
159 CFilePreview(
160 HWND aParent,
161 POINT ulCorner,
162 const CDimension& aSize,
163 HINSTANCE hInstance,
164 sal_Bool bShow = sal_True,
165 sal_Bool bEnabled = sal_True );
167 // only the singleton destroyer class is allowed to delete the
168 // singleton instance of this class
169 virtual ~CFilePreview( );
171 // we use the stl auto_ptr class as singleton destroyer
172 typedef std::auto_ptr< CFilePreview > FILEPREVIEW_SINGLETON_DESTROYER_T;
174 protected:
175 virtual void SAL_CALL onPaint( HWND hWnd, HDC hDC );
177 sal_Bool loadFile( const rtl::OUString& aFileName );
179 private:
180 CAutoOleInit m_autoOleInit;
181 POINT m_pt;
182 CDimension m_dim;
183 HWND m_hwnd;
184 sal_Bool m_bEnabled;
185 IPicturePtr m_IPicture;
186 ATOM m_atomPrevWndClass;
187 HINSTANCE m_hInstance;
189 static LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
191 static CFilePreview* s_FilePreviewInst;
192 static FILEPREVIEW_SINGLETON_DESTROYER_T s_SingletonDestroyer;
194 private:
195 friend FILEPREVIEW_SINGLETON_DESTROYER_T;
199 #endif