1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PreviewCtrl.hxx,v $
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 //------------------------------------------------------------------------
36 //------------------------------------------------------------------------
38 #include <sal/types.h>
39 #include <rtl/ustring.hxx>
45 //---------------------------------------------
47 //---------------------------------------------
58 CDimension( sal_Int32 cx
, sal_Int32 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 //--------------------------------------------------
82 // used to communicate ole
83 // initialzation failures
84 class COleInitException
{ };
88 HRESULT hr
= OleInitialize( NULL
);
90 throw COleInitException( );
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
111 //---------------------------------------------
116 // to ensure only one instance (singleton)
117 static CFilePreview
* createInstance(
120 const CDimension
& aSize
,
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
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
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
);
161 // clients can create instances only through the static create method
165 const CDimension
& aSize
,
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
;
178 virtual void SAL_CALL
onPaint( HWND hWnd
, HDC hDC
);
180 sal_Bool
loadFile( const rtl::OUString
& aFileName
);
183 CAutoOleInit m_autoOleInit
;
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
;
198 friend FILEPREVIEW_SINGLETON_DESTROYER_T
;