merge the formfield patch from ooo-build
[ooovba.git] / fpicker / source / win32 / filepicker / PreviewCtrl.hxx
blobebf2160c162724ff8c924371ac5497ad3fefc5f9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PreviewCtrl.hxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _PREVIEWCTRL_HXX_
32 #define _PREVIEWCTRL_HXX_
34 //------------------------------------------------------------------------
35 // includes
36 //------------------------------------------------------------------------
38 #include <sal/types.h>
39 #include <rtl/ustring.hxx>
41 #include <comdef.h>
43 #include <memory>
45 //---------------------------------------------
46 // declaration
47 //---------------------------------------------
49 class CDimension
51 public:
52 CDimension( ) :
53 m_cx( 0 ),
54 m_cy( 0 )
58 CDimension( sal_Int32 cx, sal_Int32 cy ) :
59 m_cx( cx ),
60 m_cy( cy )
64 sal_Int32 m_cx;
65 sal_Int32 m_cy;
68 //--------------------------------------------------
69 // we use OleInitialize here because we are calling
70 // some Ole functions to realize the picture preview
71 // and we expect to be called from the main thread
72 // so that there will be no problem calling
73 // OleInitialize (the main thread should be an STA)
74 // When OleInitialize should fail at worst the
75 // preview doesn't work
76 //--------------------------------------------------
78 class CAutoOleInit
80 public:
82 // used to communicate ole
83 // initialzation failures
84 class COleInitException { };
86 CAutoOleInit( )
88 HRESULT hr = OleInitialize( NULL );
89 if ( FAILED( hr ) )
90 throw COleInitException( );
93 ~CAutoOleInit( )
95 OleUninitialize( );
99 //---------------------------------------------
100 // A simple file preview class to preview some
101 // common picture formats like *.gif, *jpg, etc.
102 // This class is not thread-safe and is
103 // implmented as singleton, because the class
104 // has only one static member to reconnect
105 // from callback functions
106 // we use a singleton-destroyer to get rid off
107 // the singleton instance, but this happens
108 // only on shutdown (unloading of the dll) -
109 // it's a question of taste (other solutions
110 // are possible)
111 //---------------------------------------------
113 class CFilePreview
115 public:
116 // to ensure only one instance (singleton)
117 static CFilePreview* createInstance(
118 HWND aParent,
119 POINT ulCorner,
120 const CDimension& aSize,
121 HINSTANCE hInstance,
122 sal_Bool bShow = sal_True,
123 sal_Bool bEnabled = sal_True );
125 // sets the size of the preview window
126 sal_Bool SAL_CALL setSize( const CDimension& aSize );
128 // returns the CDimension of the preview
129 sal_Bool SAL_CALL getSize( CDimension& theSize ) const;
131 // sets the position of the upper left corner
132 // of the preview window relative to the
133 // upper left corner of the parent window
134 sal_Bool SAL_CALL setPos( POINT ulCorner );
136 // returns the current position of the preview
137 // relative to the upper left corner of the
138 // parent window
139 sal_Bool SAL_CALL getPos( POINT& ulCorner ) const;
141 // enables or disables the preview window
142 // bEnable - true the window is enabled and updates its
143 // view when update is called
144 // bEnable - false the window shows itself in disabled
145 // mode and does not update its view when update is
146 // called
147 void SAL_CALL enable( sal_Bool bEnable );
149 // shows the preview window
150 // possible values see SHOW_STATE
151 sal_Bool SAL_CALL show( sal_Bool bShow );
154 // if the preview is shown and enabled
155 // preview of the given file will be shown
156 // returns true on success or false if an error
157 // occured (the file in not there or not accessible etc.)
158 virtual sal_Bool SAL_CALL update( const rtl::OUString& aFileName );
160 protected:
161 // clients can create instances only through the static create method
162 CFilePreview(
163 HWND aParent,
164 POINT ulCorner,
165 const CDimension& aSize,
166 HINSTANCE hInstance,
167 sal_Bool bShow = sal_True,
168 sal_Bool bEnabled = sal_True );
170 // only the singleton destroyer class is allowed to delete the
171 // singleton instance of this class
172 virtual ~CFilePreview( );
174 // we use the stl auto_ptr class as singleton destroyer
175 typedef std::auto_ptr< CFilePreview > FILEPREVIEW_SINGLETON_DESTROYER_T;
177 protected:
178 virtual void SAL_CALL onPaint( HWND hWnd, HDC hDC );
180 sal_Bool loadFile( const rtl::OUString& aFileName );
182 private:
183 CAutoOleInit m_autoOleInit;
184 POINT m_pt;
185 CDimension m_dim;
186 HWND m_hwnd;
187 sal_Bool m_bEnabled;
188 IPicturePtr m_IPicture;
189 ATOM m_atomPrevWndClass;
190 HINSTANCE m_hInstance;
192 static LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
194 static CFilePreview* s_FilePreviewInst;
195 static FILEPREVIEW_SINGLETON_DESTROYER_T s_SingletonDestroyer;
197 private:
198 friend FILEPREVIEW_SINGLETON_DESTROYER_T;
202 #endif