1*b557fc96SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b557fc96SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b557fc96SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b557fc96SAndrew Rist  * distributed with this work for additional information
6*b557fc96SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b557fc96SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b557fc96SAndrew Rist  * "License"); you may not use this file except in compliance
9*b557fc96SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b557fc96SAndrew Rist  *
11*b557fc96SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b557fc96SAndrew Rist  *
13*b557fc96SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b557fc96SAndrew Rist  * software distributed under the License is distributed on an
15*b557fc96SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b557fc96SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b557fc96SAndrew Rist  * specific language governing permissions and limitations
18*b557fc96SAndrew Rist  * under the License.
19*b557fc96SAndrew Rist  *
20*b557fc96SAndrew Rist  *************************************************************/
21*b557fc96SAndrew Rist 
22*b557fc96SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_fpicker.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <tchar.h>
28cdf0e10cSrcweir #include "previewadapter.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UI_DIALOG_FILEPREVIEWIMAGEFORMATS_HPP_
31cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp>
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #include "dibpreview.hxx"
34cdf0e10cSrcweir #include "../misc/WinImplHelper.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <memory>
37cdf0e10cSrcweir #include <stdexcept>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir //---------------------------------------------
40cdf0e10cSrcweir //
41cdf0e10cSrcweir //---------------------------------------------
42cdf0e10cSrcweir 
43cdf0e10cSrcweir using namespace ::com::sun::star::uno;
44cdf0e10cSrcweir using namespace ::com::sun::star::lang;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir //---------------------------------------------
47cdf0e10cSrcweir // An impl class to hide implementation details
48cdf0e10cSrcweir // from clients
49cdf0e10cSrcweir //---------------------------------------------
50cdf0e10cSrcweir 
51cdf0e10cSrcweir class CPreviewAdapterImpl
52cdf0e10cSrcweir {
53cdf0e10cSrcweir public:
54cdf0e10cSrcweir 	CPreviewAdapterImpl(HINSTANCE instance);
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 	virtual ~CPreviewAdapterImpl();
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 	virtual sal_Int32 SAL_CALL getTargetColorDepth();
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 	virtual sal_Int32 SAL_CALL getAvailableWidth();
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 	virtual sal_Int32 SAL_CALL getAvailableHeight();
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 	virtual void SAL_CALL setImage( sal_Int16 aImageFormat, const Any& aImage )
65cdf0e10cSrcweir 		throw (IllegalArgumentException,RuntimeException);
66cdf0e10cSrcweir 
67cdf0e10cSrcweir     virtual sal_Bool SAL_CALL setShowState(sal_Bool bShowState);
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 	virtual sal_Bool SAL_CALL getShowState();
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	virtual void SAL_CALL setParent(HWND parent);
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 	virtual HWND SAL_CALL getParent();
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	//-------------------------------------
76cdf0e10cSrcweir 	// parent notification handler
77cdf0e10cSrcweir 	//-------------------------------------
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 	virtual void SAL_CALL notifyParentShow(sal_Bool bShow);
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 	virtual void SAL_CALL notifyParentSizeChanged();
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 	virtual void SAL_CALL notifyParentWindowPosChanged();
84cdf0e10cSrcweir 
85cdf0e10cSrcweir protected:
86cdf0e10cSrcweir 	virtual void SAL_CALL calcRightMargin();
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 	virtual void SAL_CALL rearrangeLayout();
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 	void SAL_CALL initializeActivePreview() throw(std::runtime_error);
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 	HWND SAL_CALL findFileListbox() const;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir // member
95cdf0e10cSrcweir protected:
96cdf0e10cSrcweir 	HINSTANCE					m_Instance;
97cdf0e10cSrcweir 	std::auto_ptr<PreviewBase>  m_Preview;
98cdf0e10cSrcweir 	HWND						m_FileDialog;
99cdf0e10cSrcweir 	int							m_RightMargin;
100cdf0e10cSrcweir 
101cdf0e10cSrcweir //prevent copy/assignment
102cdf0e10cSrcweir private:
103cdf0e10cSrcweir 	CPreviewAdapterImpl(const CPreviewAdapterImpl&);
104cdf0e10cSrcweir 	CPreviewAdapterImpl& operator=(const CPreviewAdapterImpl&);
105cdf0e10cSrcweir };
106cdf0e10cSrcweir 
107cdf0e10cSrcweir //-----------------------------------------
108cdf0e10cSrcweir //
109cdf0e10cSrcweir //-----------------------------------------
110cdf0e10cSrcweir 
CPreviewAdapterImpl(HINSTANCE instance)111cdf0e10cSrcweir CPreviewAdapterImpl::CPreviewAdapterImpl(HINSTANCE instance) :
112cdf0e10cSrcweir 	m_Instance(instance),
113cdf0e10cSrcweir 	m_Preview(new PreviewBase()), // create dummy preview (NULL-Object pattern)
114cdf0e10cSrcweir 	m_FileDialog(0),
115cdf0e10cSrcweir 	m_RightMargin(0)
116cdf0e10cSrcweir {
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir //-----------------------------------------
120cdf0e10cSrcweir //
121cdf0e10cSrcweir //-----------------------------------------
122cdf0e10cSrcweir 
~CPreviewAdapterImpl()123cdf0e10cSrcweir CPreviewAdapterImpl::~CPreviewAdapterImpl()
124cdf0e10cSrcweir {
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir //-----------------------------------------
128cdf0e10cSrcweir //
129cdf0e10cSrcweir //-----------------------------------------
130cdf0e10cSrcweir 
getTargetColorDepth()131cdf0e10cSrcweir sal_Int32 SAL_CALL CPreviewAdapterImpl::getTargetColorDepth()
132cdf0e10cSrcweir {
133cdf0e10cSrcweir 	return m_Preview->getTargetColorDepth();
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir //-----------------------------------------
137cdf0e10cSrcweir //
138cdf0e10cSrcweir //-----------------------------------------
139cdf0e10cSrcweir 
getAvailableWidth()140cdf0e10cSrcweir sal_Int32 SAL_CALL CPreviewAdapterImpl::getAvailableWidth()
141cdf0e10cSrcweir {
142cdf0e10cSrcweir 	return m_Preview->getAvailableWidth();
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir //-----------------------------------------
146cdf0e10cSrcweir //
147cdf0e10cSrcweir //-----------------------------------------
148cdf0e10cSrcweir 
getAvailableHeight()149cdf0e10cSrcweir sal_Int32 SAL_CALL CPreviewAdapterImpl::getAvailableHeight()
150cdf0e10cSrcweir {
151cdf0e10cSrcweir 	return m_Preview->getAvailableHeight();
152cdf0e10cSrcweir }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir //-----------------------------------------
155cdf0e10cSrcweir //
156cdf0e10cSrcweir //-----------------------------------------
157cdf0e10cSrcweir 
setImage(sal_Int16 aImageFormat,const Any & aImage)158cdf0e10cSrcweir void SAL_CALL CPreviewAdapterImpl::setImage( sal_Int16 aImageFormat, const Any& aImage )
159cdf0e10cSrcweir 	throw (IllegalArgumentException,RuntimeException)
160cdf0e10cSrcweir {
161cdf0e10cSrcweir 	m_Preview->setImage(aImageFormat,aImage);
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir //-----------------------------------------
165cdf0e10cSrcweir //
166cdf0e10cSrcweir //-----------------------------------------
167cdf0e10cSrcweir 
setShowState(sal_Bool bShowState)168cdf0e10cSrcweir sal_Bool SAL_CALL CPreviewAdapterImpl::setShowState( sal_Bool bShowState )
169cdf0e10cSrcweir {
170cdf0e10cSrcweir 	sal_Bool bRet = m_Preview->setShowState(bShowState);
171cdf0e10cSrcweir 	rearrangeLayout();
172cdf0e10cSrcweir 	return bRet;
173cdf0e10cSrcweir }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir //-----------------------------------------
176cdf0e10cSrcweir //
177cdf0e10cSrcweir //-----------------------------------------
178cdf0e10cSrcweir 
getShowState()179cdf0e10cSrcweir sal_Bool SAL_CALL CPreviewAdapterImpl::getShowState()
180cdf0e10cSrcweir {
181cdf0e10cSrcweir 	return m_Preview->getShowState();
182cdf0e10cSrcweir }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir //-----------------------------------------
185cdf0e10cSrcweir //
186cdf0e10cSrcweir //-----------------------------------------
187cdf0e10cSrcweir 
setParent(HWND parent)188cdf0e10cSrcweir void SAL_CALL CPreviewAdapterImpl::setParent(HWND parent)
189cdf0e10cSrcweir {
190cdf0e10cSrcweir 	OSL_PRECOND(IsWindow(parent),"Invalid FileDialog handle");
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 	m_FileDialog = parent;
193cdf0e10cSrcweir 	calcRightMargin();
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
196cdf0e10cSrcweir //-----------------------------------------
197cdf0e10cSrcweir //
198cdf0e10cSrcweir //-----------------------------------------
199cdf0e10cSrcweir 
getParent()200cdf0e10cSrcweir HWND SAL_CALL CPreviewAdapterImpl::getParent()
201cdf0e10cSrcweir {
202cdf0e10cSrcweir 	return m_FileDialog;
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir //-----------------------------------------
206cdf0e10cSrcweir //
207cdf0e10cSrcweir //-----------------------------------------
208cdf0e10cSrcweir 
calcRightMargin()209cdf0e10cSrcweir void SAL_CALL CPreviewAdapterImpl::calcRightMargin()
210cdf0e10cSrcweir {
211cdf0e10cSrcweir 	// Calculate the right reference margin
212cdf0e10cSrcweir 	//
213cdf0e10cSrcweir 	// Assumtions:
214cdf0e10cSrcweir 	// 1. This method will be called before the dialog becomes
215cdf0e10cSrcweir 	//    visible
216cdf0e10cSrcweir 	// 2. There exist a FileListbox with the id lst1 even
217cdf0e10cSrcweir 	//    if it is not visible like under Win2000/XP
218cdf0e10cSrcweir 	// 3. Initially this FileListbox has the appropriate size
219cdf0e10cSrcweir 	//    to fit within the FileListbox
220cdf0e10cSrcweir 	// 4. The margin between the right edge of the FileListbox
221cdf0e10cSrcweir 	//    and the right edge of the FileDialog will be constant
222cdf0e10cSrcweir 	//    even if the size of the dialog changes
223cdf0e10cSrcweir 
224cdf0e10cSrcweir 	HWND flb = GetDlgItem(m_FileDialog,lst1);
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 	OSL_ENSURE(IsWindow(flb),"Filelistbox not found");
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 	RECT rcFlb;
229cdf0e10cSrcweir 	GetWindowRect(flb,&rcFlb);
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 	RECT rcFileDlg;
232cdf0e10cSrcweir 	GetWindowRect(m_FileDialog,&rcFileDlg);
233cdf0e10cSrcweir 
234cdf0e10cSrcweir 	m_RightMargin = rcFileDlg.right - rcFlb.right;
235cdf0e10cSrcweir }
236cdf0e10cSrcweir 
237cdf0e10cSrcweir //-----------------------------------------
238cdf0e10cSrcweir //
239cdf0e10cSrcweir //-----------------------------------------
240cdf0e10cSrcweir 
notifyParentShow(sal_Bool)241cdf0e10cSrcweir void SAL_CALL CPreviewAdapterImpl::notifyParentShow(sal_Bool)
242cdf0e10cSrcweir {
243cdf0e10cSrcweir }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir //-----------------------------------------
246cdf0e10cSrcweir //
247cdf0e10cSrcweir //-----------------------------------------
248cdf0e10cSrcweir 
notifyParentSizeChanged()249cdf0e10cSrcweir void SAL_CALL CPreviewAdapterImpl::notifyParentSizeChanged()
250cdf0e10cSrcweir {
251cdf0e10cSrcweir 	rearrangeLayout();
252cdf0e10cSrcweir }
253cdf0e10cSrcweir 
254cdf0e10cSrcweir //-----------------------------------------
255cdf0e10cSrcweir //
256cdf0e10cSrcweir //-----------------------------------------
257cdf0e10cSrcweir 
notifyParentWindowPosChanged()258cdf0e10cSrcweir void SAL_CALL CPreviewAdapterImpl::notifyParentWindowPosChanged()
259cdf0e10cSrcweir {
260cdf0e10cSrcweir }
261cdf0e10cSrcweir 
262cdf0e10cSrcweir //-----------------------------------------
263cdf0e10cSrcweir //
264cdf0e10cSrcweir //-----------------------------------------
265cdf0e10cSrcweir 
rearrangeLayout()266cdf0e10cSrcweir void SAL_CALL CPreviewAdapterImpl::rearrangeLayout()
267cdf0e10cSrcweir {
268cdf0e10cSrcweir 	// try to get a handle to the filelistbox
269cdf0e10cSrcweir 	// if there is no new-style filelistbox like
270cdf0e10cSrcweir 	// in Win2000/XP there should be at least the
271cdf0e10cSrcweir 	// old listbox, so we take this one
272cdf0e10cSrcweir 	// lst1 - identifies the old-style filelistbox
273cdf0e10cSrcweir 	// lst2 - identifies the new-style filelistbox
274cdf0e10cSrcweir 	// see dlgs.h
275cdf0e10cSrcweir 	HWND flb_new = findFileListbox();
276cdf0e10cSrcweir 
277cdf0e10cSrcweir 	// under Windows NT 4.0 the size of the old
278cdf0e10cSrcweir 	// filelistbox will be used as reference for
279cdf0e10cSrcweir 	// sizing the new filelistbox, so we have
280cdf0e10cSrcweir 	// to change the size of it too
281cdf0e10cSrcweir 	HWND flb_old = GetDlgItem(m_FileDialog,lst1);
282cdf0e10cSrcweir 
283cdf0e10cSrcweir 	RECT rcFlbNew;
284cdf0e10cSrcweir 	GetWindowRect(flb_new,&rcFlbNew);
285cdf0e10cSrcweir 
286cdf0e10cSrcweir 	RECT rcFileDlg;
287cdf0e10cSrcweir 	GetWindowRect(m_FileDialog,&rcFileDlg);
288cdf0e10cSrcweir 	rcFileDlg.right -= m_RightMargin;
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 	// the available area for the filelistbox should be
291cdf0e10cSrcweir 	// the left edge of the filelistbox and the right
292cdf0e10cSrcweir 	// edge of the OK button, we take this as reference
293cdf0e10cSrcweir 	int height = rcFlbNew.bottom - rcFlbNew.top;
294cdf0e10cSrcweir 	int width  = rcFileDlg.right - rcFlbNew.left;
295cdf0e10cSrcweir 
296cdf0e10cSrcweir 	HWND prvwnd = m_Preview->getWindowHandle();
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 	// we use GetWindowLong to ask for the visibility
299cdf0e10cSrcweir 	// of the preview window because IsWindowVisible
300cdf0e10cSrcweir 	// only returns true the specified window including
301cdf0e10cSrcweir 	// its parent windows are visible
302cdf0e10cSrcweir 	// this is not the case when we are called in response
303cdf0e10cSrcweir 	// to the WM_SHOWWINDOW message, somehow the WS_VISIBLE
304cdf0e10cSrcweir 	// style bit of the FileOpen dialog must be set after that
305cdf0e10cSrcweir 	// message
306cdf0e10cSrcweir 	LONG lStyle = GetWindowLong(prvwnd,GWL_STYLE);
307cdf0e10cSrcweir 	bool bIsVisible = ((lStyle & WS_VISIBLE) != 0);
308cdf0e10cSrcweir 
309cdf0e10cSrcweir 	int cx = 0;
310cdf0e10cSrcweir 
311cdf0e10cSrcweir 	if (IsWindow(prvwnd) && bIsVisible)
312cdf0e10cSrcweir 	{
313cdf0e10cSrcweir 		cx = width/2;
314cdf0e10cSrcweir 
315cdf0e10cSrcweir 		// resize the filelistbox to the half of the
316cdf0e10cSrcweir 		// available space
317cdf0e10cSrcweir 		bool bRet = SetWindowPos(flb_new,
318cdf0e10cSrcweir 			NULL, 0, 0, cx, height,
319cdf0e10cSrcweir 			SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
320cdf0e10cSrcweir 
321cdf0e10cSrcweir 		bRet = SetWindowPos(flb_old,
322cdf0e10cSrcweir 			NULL, 0, 0, cx, height,
323cdf0e10cSrcweir 			SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
324cdf0e10cSrcweir 
325cdf0e10cSrcweir 		// get the new dimensions of the filelistbox after
326cdf0e10cSrcweir 		// resizing and take the right,top corner as starting
327cdf0e10cSrcweir 		// point for the preview window
328cdf0e10cSrcweir 		GetWindowRect(flb_new,&rcFlbNew);
329cdf0e10cSrcweir 		POINT pt = { rcFlbNew.right, rcFlbNew.top };
330cdf0e10cSrcweir 		ScreenToClient(m_FileDialog,&pt);
331cdf0e10cSrcweir 
332cdf0e10cSrcweir 		// resize the preview window to fit within
333cdf0e10cSrcweir 		// the available space and set the window
334cdf0e10cSrcweir 		// to the top of the z-order else it will
335cdf0e10cSrcweir 		// be invisible
336cdf0e10cSrcweir 		SetWindowPos(prvwnd,
337cdf0e10cSrcweir 			HWND_TOP, pt.x, pt.y, cx, height, SWP_NOACTIVATE);
338cdf0e10cSrcweir 	}
339cdf0e10cSrcweir 	else
340cdf0e10cSrcweir 	{
341cdf0e10cSrcweir 		// resize the filelistbox to the maximum available
342cdf0e10cSrcweir 		// space
343cdf0e10cSrcweir 		cx = rcFileDlg.right - rcFlbNew.left;
344cdf0e10cSrcweir 
345cdf0e10cSrcweir 		// resize the old filelistbox
346cdf0e10cSrcweir 		SetWindowPos(flb_old,
347cdf0e10cSrcweir 			NULL, 0, 0, cx, height,
348cdf0e10cSrcweir 			SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
349cdf0e10cSrcweir 
350cdf0e10cSrcweir 		// resize the new filelistbox
351cdf0e10cSrcweir 		SetWindowPos(flb_new,
352cdf0e10cSrcweir 			NULL, 0, 0, cx, height,
353cdf0e10cSrcweir 			SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
354cdf0e10cSrcweir 	}
355cdf0e10cSrcweir }
356cdf0e10cSrcweir 
357cdf0e10cSrcweir //-----------------------------------------
358cdf0e10cSrcweir //
359cdf0e10cSrcweir //-----------------------------------------
360cdf0e10cSrcweir 
initializeActivePreview()361cdf0e10cSrcweir void SAL_CALL CPreviewAdapterImpl::initializeActivePreview() throw(std::runtime_error)
362cdf0e10cSrcweir {
363cdf0e10cSrcweir 	sal_Bool bShowState = m_Preview->getImaginaryShowState();
364cdf0e10cSrcweir 
365cdf0e10cSrcweir 	sal_Int16 aImgFrmt;
366cdf0e10cSrcweir 	Any aImg;
367cdf0e10cSrcweir 	m_Preview->getImage(aImgFrmt,aImg);
368cdf0e10cSrcweir 
369cdf0e10cSrcweir 	HWND flb = findFileListbox();
370cdf0e10cSrcweir 
371cdf0e10cSrcweir 	PreviewBase* prv = new CDIBPreview(
372cdf0e10cSrcweir 		m_Instance, GetParent(flb), bShowState);
373cdf0e10cSrcweir 
374cdf0e10cSrcweir 	m_Preview.reset(prv);
375cdf0e10cSrcweir 
376cdf0e10cSrcweir 	m_Preview->setImage(aImgFrmt,aImg);
377cdf0e10cSrcweir }
378cdf0e10cSrcweir 
379cdf0e10cSrcweir //-----------------------------------------
380cdf0e10cSrcweir //
381cdf0e10cSrcweir //-----------------------------------------
382cdf0e10cSrcweir 
findFileListbox() const383cdf0e10cSrcweir HWND SAL_CALL CPreviewAdapterImpl::findFileListbox() const
384cdf0e10cSrcweir {
385cdf0e10cSrcweir 	// try to get a handle to the filelistbox
386cdf0e10cSrcweir 	// if there is no new-style filelistbox like
387cdf0e10cSrcweir 	// in Win2000/XP there should be at least the
388cdf0e10cSrcweir 	// old listbox, so we take this one
389cdf0e10cSrcweir 	// lst1 - identifies the old-style filelistbox
390cdf0e10cSrcweir 	// lst2 - identifies the new-style filelistbox
391cdf0e10cSrcweir 	// see dlgs.h
392cdf0e10cSrcweir 	HWND flb = GetDlgItem(m_FileDialog,lst2);
393cdf0e10cSrcweir 	if (!IsWindow(flb))
394cdf0e10cSrcweir 		flb = GetDlgItem(m_FileDialog,lst1);
395cdf0e10cSrcweir 
396cdf0e10cSrcweir 	return flb;
397cdf0e10cSrcweir }
398cdf0e10cSrcweir 
399cdf0e10cSrcweir 
400cdf0e10cSrcweir //##############################################################
401cdf0e10cSrcweir 
402cdf0e10cSrcweir 
403cdf0e10cSrcweir //-----------------------------------------
404cdf0e10cSrcweir // Special implementation for Win98
405cdf0e10cSrcweir // because:
406cdf0e10cSrcweir //
407cdf0e10cSrcweir //-----------------------------------------
408cdf0e10cSrcweir 
409cdf0e10cSrcweir class CWin98PreviewAdapterImpl : public CPreviewAdapterImpl
410cdf0e10cSrcweir {
411cdf0e10cSrcweir public:
412cdf0e10cSrcweir 	CWin98PreviewAdapterImpl(HINSTANCE instance);
413cdf0e10cSrcweir 
414cdf0e10cSrcweir 	virtual void SAL_CALL notifyParentWindowPosChanged();
415cdf0e10cSrcweir 
416cdf0e10cSrcweir protected:
417cdf0e10cSrcweir 	virtual void SAL_CALL rearrangeLayout();
418cdf0e10cSrcweir 
419cdf0e10cSrcweir 	bool isValidToolbarDimension() const;
420cdf0e10cSrcweir 
421cdf0e10cSrcweir private:
422cdf0e10cSrcweir 	sal_Bool	m_PreviewActive;
423cdf0e10cSrcweir 	int			m_ToolbarPosX;
424cdf0e10cSrcweir 	int			m_ToolbarPosY;
425cdf0e10cSrcweir 	int			m_ToolbarWidth;
426cdf0e10cSrcweir 	int			m_ToolbarHeight;
427cdf0e10cSrcweir };
428cdf0e10cSrcweir 
429cdf0e10cSrcweir //--------------------------------------------
430cdf0e10cSrcweir //
431cdf0e10cSrcweir //--------------------------------------------
432cdf0e10cSrcweir 
CWin98PreviewAdapterImpl(HINSTANCE instance)433cdf0e10cSrcweir CWin98PreviewAdapterImpl::CWin98PreviewAdapterImpl(HINSTANCE instance) :
434cdf0e10cSrcweir 	CPreviewAdapterImpl(instance),
435cdf0e10cSrcweir 	m_PreviewActive(sal_False),
436cdf0e10cSrcweir 	m_ToolbarPosX(0),
437cdf0e10cSrcweir 	m_ToolbarPosY(0),
438cdf0e10cSrcweir 	m_ToolbarWidth(0),
439cdf0e10cSrcweir 	m_ToolbarHeight(0)
440cdf0e10cSrcweir {
441cdf0e10cSrcweir }
442cdf0e10cSrcweir 
443cdf0e10cSrcweir //--------------------------------------------
444cdf0e10cSrcweir //
445cdf0e10cSrcweir //--------------------------------------------
446cdf0e10cSrcweir 
notifyParentWindowPosChanged()447cdf0e10cSrcweir void SAL_CALL CWin98PreviewAdapterImpl::notifyParentWindowPosChanged()
448cdf0e10cSrcweir {
449cdf0e10cSrcweir 	try
450cdf0e10cSrcweir 	{
451cdf0e10cSrcweir 		// the reason for this condition is
452cdf0e10cSrcweir 		// Windows 98
453cdf0e10cSrcweir 		// Under Windows 98 the message WM_SHOWWINDOW
454cdf0e10cSrcweir 		// will be sent only the first time the
455cdf0e10cSrcweir 		// GetOpenFileName function is called within
456cdf0e10cSrcweir 		// the same process
457cdf0e10cSrcweir 		// so we must use another message to initialize
458cdf0e10cSrcweir 		// the preview window
459cdf0e10cSrcweir 		if (IsWindow(m_FileDialog) && !m_PreviewActive)
460cdf0e10cSrcweir 		{
461cdf0e10cSrcweir 			initializeActivePreview();
462cdf0e10cSrcweir 			m_PreviewActive = sal_True;
463cdf0e10cSrcweir 			rearrangeLayout();
464cdf0e10cSrcweir 		}
465cdf0e10cSrcweir 
466cdf0e10cSrcweir 		if (IsWindow(m_FileDialog) && !isValidToolbarDimension())
467cdf0e10cSrcweir 		{
468cdf0e10cSrcweir 			RECT rcStc1;
469cdf0e10cSrcweir 			GetWindowRect(GetDlgItem(m_FileDialog,stc1),&rcStc1);
470cdf0e10cSrcweir 
471cdf0e10cSrcweir 			RECT rcCmb2;
472cdf0e10cSrcweir 			GetWindowRect(GetDlgItem(m_FileDialog,cmb2),&rcCmb2);
473cdf0e10cSrcweir 
474cdf0e10cSrcweir 			// Assumption:
475cdf0e10cSrcweir 			// the toolbar position is only valid
476cdf0e10cSrcweir 			// if the left edge is greater or equal
477cdf0e10cSrcweir 			// than the right edge of the drives listbox
478cdf0e10cSrcweir 			// the stc1 static text is invisible at runtime
479cdf0e10cSrcweir 			// but will be used as reference for the position
480cdf0e10cSrcweir 			// and dimension of the toolbar
481cdf0e10cSrcweir 			if (rcStc1.left >= rcCmb2.right)
482cdf0e10cSrcweir 			{
483cdf0e10cSrcweir 				// important: save the upper left corner in
484cdf0e10cSrcweir 				// client coordinates
485cdf0e10cSrcweir 				POINT pt = {rcStc1.left,rcStc1.top};
486cdf0e10cSrcweir 				ScreenToClient(m_FileDialog,&pt);
487cdf0e10cSrcweir 
488cdf0e10cSrcweir 				m_ToolbarPosX   = pt.x;
489cdf0e10cSrcweir 				m_ToolbarPosY   = pt.y;
490cdf0e10cSrcweir 				m_ToolbarWidth  = rcStc1.right - rcStc1.left;
491cdf0e10cSrcweir 				m_ToolbarHeight = rcStc1.bottom - rcStc1.top;
492cdf0e10cSrcweir 			}
493cdf0e10cSrcweir 		}
494cdf0e10cSrcweir 	}
495cdf0e10cSrcweir 	catch(std::runtime_error&)
496cdf0e10cSrcweir 	{
497cdf0e10cSrcweir 	}
498cdf0e10cSrcweir }
499cdf0e10cSrcweir 
500cdf0e10cSrcweir //--------------------------------------------
501cdf0e10cSrcweir //
502cdf0e10cSrcweir //--------------------------------------------
503cdf0e10cSrcweir 
rearrangeLayout()504cdf0e10cSrcweir void SAL_CALL CWin98PreviewAdapterImpl::rearrangeLayout()
505cdf0e10cSrcweir {
506cdf0e10cSrcweir 	CPreviewAdapterImpl::rearrangeLayout();
507cdf0e10cSrcweir 
508cdf0e10cSrcweir 	// fix the position of the upper toolbar
509cdf0e10cSrcweir 	// because the FileDialog moves all windows
510cdf0e10cSrcweir 	// that are to the right of the FileListbox
511cdf0e10cSrcweir 	// so if we have changed the size of the
512cdf0e10cSrcweir 	// FileListbox we would run into trouble else
513cdf0e10cSrcweir 	if (isValidToolbarDimension())
514cdf0e10cSrcweir 	{
515cdf0e10cSrcweir 		HWND hwndTlb = FindWindowEx(
516cdf0e10cSrcweir 			m_FileDialog,NULL,TEXT("ToolbarWindow32"),NULL);
517cdf0e10cSrcweir 
518cdf0e10cSrcweir 		SetWindowPos(hwndTlb,
519cdf0e10cSrcweir 			HWND_TOP,
520cdf0e10cSrcweir 			m_ToolbarPosX,
521cdf0e10cSrcweir 			m_ToolbarPosY,
522cdf0e10cSrcweir 			m_ToolbarWidth,
523cdf0e10cSrcweir 			m_ToolbarHeight,
524cdf0e10cSrcweir 			SWP_NOACTIVATE);
525cdf0e10cSrcweir 	}
526cdf0e10cSrcweir }
527cdf0e10cSrcweir 
528cdf0e10cSrcweir //--------------------------------------------
529cdf0e10cSrcweir //
530cdf0e10cSrcweir //--------------------------------------------
531cdf0e10cSrcweir 
isValidToolbarDimension() const532cdf0e10cSrcweir bool CWin98PreviewAdapterImpl::isValidToolbarDimension() const
533cdf0e10cSrcweir {
534cdf0e10cSrcweir 	return (m_ToolbarPosX   > 0 &&
535cdf0e10cSrcweir 			m_ToolbarPosY   > 0 &&
536cdf0e10cSrcweir 			m_ToolbarWidth  > 0 &&
537cdf0e10cSrcweir 			m_ToolbarHeight > 0);
538cdf0e10cSrcweir }
539cdf0e10cSrcweir 
540cdf0e10cSrcweir //##############################################################
541cdf0e10cSrcweir 
542cdf0e10cSrcweir 
543cdf0e10cSrcweir //--------------------------------------------
544cdf0e10cSrcweir // Implementation for Windows 95/NT/ME/2000/XP
545cdf0e10cSrcweir // because:
546cdf0e10cSrcweir //
547cdf0e10cSrcweir //--------------------------------------------
548cdf0e10cSrcweir 
549cdf0e10cSrcweir class CWin95NTPreviewAdapterImpl : public CPreviewAdapterImpl
550cdf0e10cSrcweir {
551cdf0e10cSrcweir public:
552cdf0e10cSrcweir 	CWin95NTPreviewAdapterImpl(HINSTANCE instance);
553cdf0e10cSrcweir 
554cdf0e10cSrcweir 	virtual void SAL_CALL notifyParentShow(sal_Bool bShow);
555cdf0e10cSrcweir };
556cdf0e10cSrcweir 
557cdf0e10cSrcweir //--------------------------------------------
558cdf0e10cSrcweir //
559cdf0e10cSrcweir //--------------------------------------------
560cdf0e10cSrcweir 
CWin95NTPreviewAdapterImpl(HINSTANCE instance)561cdf0e10cSrcweir CWin95NTPreviewAdapterImpl::CWin95NTPreviewAdapterImpl(HINSTANCE instance) :
562cdf0e10cSrcweir 	CPreviewAdapterImpl(instance)
563cdf0e10cSrcweir {
564cdf0e10cSrcweir }
565cdf0e10cSrcweir 
566cdf0e10cSrcweir //--------------------------------------------
567cdf0e10cSrcweir //
568cdf0e10cSrcweir //--------------------------------------------
569cdf0e10cSrcweir 
notifyParentShow(sal_Bool bShow)570cdf0e10cSrcweir void SAL_CALL CWin95NTPreviewAdapterImpl::notifyParentShow(sal_Bool bShow)
571cdf0e10cSrcweir {
572cdf0e10cSrcweir 	try
573cdf0e10cSrcweir 	{
574cdf0e10cSrcweir 		if (bShow)
575cdf0e10cSrcweir 		{
576cdf0e10cSrcweir 			initializeActivePreview();
577cdf0e10cSrcweir 			rearrangeLayout();
578cdf0e10cSrcweir 		}
579cdf0e10cSrcweir 	}
580cdf0e10cSrcweir 	catch(std::runtime_error&)
581cdf0e10cSrcweir 	{
582cdf0e10cSrcweir 	}
583cdf0e10cSrcweir }
584cdf0e10cSrcweir 
585cdf0e10cSrcweir 
586cdf0e10cSrcweir //##############################################################
587cdf0e10cSrcweir 
588cdf0e10cSrcweir 
589cdf0e10cSrcweir //-------------------------------
590cdf0e10cSrcweir // ctor
591cdf0e10cSrcweir //-------------------------------
592cdf0e10cSrcweir 
CPreviewAdapter(HINSTANCE instance)593cdf0e10cSrcweir CPreviewAdapter::CPreviewAdapter(HINSTANCE instance)
594cdf0e10cSrcweir {
595cdf0e10cSrcweir 	if (!IsWindows98())
596cdf0e10cSrcweir 		m_pImpl.reset(new CWin95NTPreviewAdapterImpl(instance));
597cdf0e10cSrcweir 	else
598cdf0e10cSrcweir 		m_pImpl.reset(new CWin98PreviewAdapterImpl(instance));
599cdf0e10cSrcweir }
600cdf0e10cSrcweir 
601cdf0e10cSrcweir //-------------------------------
602cdf0e10cSrcweir //
603cdf0e10cSrcweir //-------------------------------
604cdf0e10cSrcweir 
~CPreviewAdapter()605cdf0e10cSrcweir CPreviewAdapter::~CPreviewAdapter()
606cdf0e10cSrcweir {
607cdf0e10cSrcweir }
608cdf0e10cSrcweir 
609cdf0e10cSrcweir //-------------------------------
610cdf0e10cSrcweir //
611cdf0e10cSrcweir //-------------------------------
612cdf0e10cSrcweir 
getSupportedImageFormats()613cdf0e10cSrcweir Sequence<sal_Int16> SAL_CALL CPreviewAdapter::getSupportedImageFormats()
614cdf0e10cSrcweir {
615cdf0e10cSrcweir 	com::sun::star::uno::Sequence<sal_Int16> imgFormats(1);
616cdf0e10cSrcweir     imgFormats[0] = ::com::sun::star::ui::dialogs::FilePreviewImageFormats::BITMAP;
617cdf0e10cSrcweir     return imgFormats;
618cdf0e10cSrcweir }
619cdf0e10cSrcweir 
620cdf0e10cSrcweir //-------------------------------
621cdf0e10cSrcweir //
622cdf0e10cSrcweir //-------------------------------
623cdf0e10cSrcweir 
getTargetColorDepth()624cdf0e10cSrcweir sal_Int32 SAL_CALL CPreviewAdapter::getTargetColorDepth()
625cdf0e10cSrcweir {
626cdf0e10cSrcweir 	return m_pImpl->getTargetColorDepth();
627cdf0e10cSrcweir }
628cdf0e10cSrcweir 
629cdf0e10cSrcweir //-------------------------------
630cdf0e10cSrcweir //
631cdf0e10cSrcweir //-------------------------------
632cdf0e10cSrcweir 
getAvailableWidth()633cdf0e10cSrcweir sal_Int32 SAL_CALL CPreviewAdapter::getAvailableWidth()
634cdf0e10cSrcweir {
635cdf0e10cSrcweir 	return m_pImpl->getAvailableWidth();
636cdf0e10cSrcweir }
637cdf0e10cSrcweir 
638cdf0e10cSrcweir //-------------------------------
639cdf0e10cSrcweir //
640cdf0e10cSrcweir //-------------------------------
641cdf0e10cSrcweir 
getAvailableHeight()642cdf0e10cSrcweir sal_Int32 SAL_CALL CPreviewAdapter::getAvailableHeight()
643cdf0e10cSrcweir {
644cdf0e10cSrcweir 	return m_pImpl->getAvailableHeight();
645cdf0e10cSrcweir }
646cdf0e10cSrcweir 
647cdf0e10cSrcweir //-------------------------------
648cdf0e10cSrcweir //
649cdf0e10cSrcweir //-------------------------------
650cdf0e10cSrcweir 
setImage(sal_Int16 aImageFormat,const Any & aImage)651cdf0e10cSrcweir void SAL_CALL CPreviewAdapter::setImage( sal_Int16 aImageFormat, const Any& aImage )
652cdf0e10cSrcweir 	throw (IllegalArgumentException, RuntimeException)
653cdf0e10cSrcweir {
654cdf0e10cSrcweir 	m_pImpl->setImage(aImageFormat,aImage);
655cdf0e10cSrcweir }
656cdf0e10cSrcweir 
657cdf0e10cSrcweir //-------------------------------
658cdf0e10cSrcweir //
659cdf0e10cSrcweir //-------------------------------
660cdf0e10cSrcweir 
setShowState(sal_Bool bShowState)661cdf0e10cSrcweir sal_Bool SAL_CALL CPreviewAdapter::setShowState( sal_Bool bShowState )
662cdf0e10cSrcweir {
663cdf0e10cSrcweir 	return m_pImpl->setShowState(bShowState);
664cdf0e10cSrcweir }
665cdf0e10cSrcweir 
666cdf0e10cSrcweir //-------------------------------
667cdf0e10cSrcweir //
668cdf0e10cSrcweir //-------------------------------
669cdf0e10cSrcweir 
getShowState()670cdf0e10cSrcweir sal_Bool SAL_CALL CPreviewAdapter::getShowState()
671cdf0e10cSrcweir {
672cdf0e10cSrcweir 	return m_pImpl->getShowState();
673cdf0e10cSrcweir }
674cdf0e10cSrcweir 
675cdf0e10cSrcweir //-------------------------------
676cdf0e10cSrcweir //
677cdf0e10cSrcweir //-------------------------------
678cdf0e10cSrcweir 
setParent(HWND parent)679cdf0e10cSrcweir void SAL_CALL CPreviewAdapter::setParent(HWND parent)
680cdf0e10cSrcweir {
681cdf0e10cSrcweir 	m_pImpl->setParent(parent);
682cdf0e10cSrcweir }
683cdf0e10cSrcweir 
684cdf0e10cSrcweir //-------------------------------
685cdf0e10cSrcweir //
686cdf0e10cSrcweir //-------------------------------
687cdf0e10cSrcweir 
notifyParentShow(bool bShow)688cdf0e10cSrcweir void SAL_CALL CPreviewAdapter::notifyParentShow(bool bShow)
689cdf0e10cSrcweir {
690cdf0e10cSrcweir 	m_pImpl->notifyParentShow(bShow);
691cdf0e10cSrcweir }
692cdf0e10cSrcweir 
693cdf0e10cSrcweir //-------------------------------
694cdf0e10cSrcweir //
695cdf0e10cSrcweir //-------------------------------
696cdf0e10cSrcweir 
notifyParentSizeChanged()697cdf0e10cSrcweir void SAL_CALL CPreviewAdapter::notifyParentSizeChanged()
698cdf0e10cSrcweir {
699cdf0e10cSrcweir 	m_pImpl->notifyParentSizeChanged();
700cdf0e10cSrcweir }
701cdf0e10cSrcweir 
702cdf0e10cSrcweir //-------------------------------
703cdf0e10cSrcweir //
704cdf0e10cSrcweir //-------------------------------
705cdf0e10cSrcweir 
notifyParentWindowPosChanged()706cdf0e10cSrcweir void SAL_CALL CPreviewAdapter::notifyParentWindowPosChanged()
707cdf0e10cSrcweir {
708cdf0e10cSrcweir 	m_pImpl->notifyParentWindowPosChanged();
709cdf0e10cSrcweir }
710