xref: /aoo41x/main/svx/source/gallery2/galbrws.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 
31 #include <vcl/split.hxx>
32 #include <vcl/ctrl.hxx>
33 #include <unotools/pathoptions.hxx>
34 #include <sfx2/app.hxx>
35 #include <sfx2/sfxsids.hrc>
36 #include "gallery.hrc"
37 #include "svx/galmisc.hxx"
38 #include "svx/gallery1.hxx"
39 #include "galbrws1.hxx"
40 #include "galbrws2.hxx"
41 #include "svx/galbrws.hxx"
42 
43 // -------------------
44 // - GallerySplitter -
45 // -------------------
46 
47 class GallerySplitter : public Splitter
48 {
49 protected:
50 
51     virtual void    DataChanged( const DataChangedEvent& rDCEvt );
52 
53 public:
54 
55                     GallerySplitter( Window* pParent, const ResId& rResId );
56     virtual         ~GallerySplitter();
57 };
58 
59 // -----------------------------------------------------------------------------
60 DBG_NAME(GallerySplitter)
61 
62 GallerySplitter::GallerySplitter( Window* pParent, const ResId& rResId ) :
63     Splitter( pParent, rResId )
64 {
65     DBG_CTOR(GallerySplitter,NULL);
66 
67 }
68 
69 // -----------------------------------------------------------------------------
70 
71 GallerySplitter::~GallerySplitter()
72 {
73 
74     DBG_DTOR(GallerySplitter,NULL);
75 }
76 
77 // -----------------------------------------------------------------------------
78 
79 void GallerySplitter::DataChanged( const DataChangedEvent& rDCEvt )
80 {
81     Splitter::DataChanged( rDCEvt );
82     static_cast< GalleryBrowser* >( GetParent() )->InitSettings();
83 }
84 
85 // -------------------------
86 // - SvxGalleryChildWindow -
87 // -------------------------
88 DBG_NAME(GalleryChildWindow)
89 
90 GalleryChildWindow::GalleryChildWindow( Window* _pParent, sal_uInt16 nId, SfxBindings* pBindings, SfxChildWinInfo* pInfo ) :
91 	SfxChildWindow( _pParent, nId )
92 {
93     DBG_CTOR(GalleryChildWindow,NULL);
94 
95 	pWindow = new GalleryBrowser( pBindings, this, _pParent, GAL_RESID( RID_SVXDLG_GALLERYBROWSER ) );
96 	eChildAlignment = SFX_ALIGN_TOP;
97 	( (GalleryBrowser*) pWindow )->Initialize( pInfo );
98 };
99 
100 // -----------------------------------------------------------------------------
101 
102 GalleryChildWindow::~GalleryChildWindow()
103 {
104 
105     DBG_DTOR(GalleryChildWindow,NULL);
106 }
107 
108 // -----------------------------------------------------------------------------
109 
110 SFX_IMPL_DOCKINGWINDOW( GalleryChildWindow, SID_GALLERY )
111 
112 // ------------------
113 // - GalleryBrowser -
114 // ------------------
115 DBG_NAME(GalleryBrowser)
116 
117 GalleryBrowser::GalleryBrowser( SfxBindings* _pBindings, SfxChildWindow* pCW,
118 								Window* pParent, const ResId& rResId ) :
119 	SfxDockingWindow( _pBindings, pCW, pParent, rResId )
120 {
121     DBG_CTOR(GalleryBrowser,NULL);
122 
123 	mpGallery = Gallery::GetGalleryInstance();
124 	mpBrowser1 = new GalleryBrowser1( this, GAL_RESID( GALLERY_BROWSER1 ), mpGallery );
125 	mpSplitter = new GallerySplitter( this, GAL_RESID( GALLERY_SPLITTER ) );
126 	mpBrowser2 = new GalleryBrowser2( this, GAL_RESID( GALLERY_BROWSER2 ), mpGallery );
127 
128 	FreeResource();
129 	SetMinOutputSizePixel( maLastSize = GetOutputSizePixel() );
130 
131 	mpBrowser1->SelectTheme( 0 );
132 	mpBrowser1->Show( sal_True );
133 	mpBrowser2->Show( sal_True );
134 
135 	mpSplitter->SetSplitHdl( LINK( this, GalleryBrowser, SplitHdl ) );
136 	mpSplitter->Show( sal_True );
137 
138     InitSettings();
139 }
140 
141 // -----------------------------------------------------------------------------
142 
143 GalleryBrowser::~GalleryBrowser()
144 {
145 	delete mpBrowser2;
146 	delete mpSplitter;
147 	delete mpBrowser1;
148 
149     DBG_DTOR(GalleryBrowser,NULL);
150 }
151 
152 // -----------------------------------------------------------------------------
153 
154 void GalleryBrowser::InitSettings()
155 {
156 	SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
157 	SetControlBackground( GALLERY_DLG_COLOR );
158 	SetControlForeground( GALLERY_DLG_COLOR );
159 
160 	mpSplitter->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
161 	mpSplitter->SetControlBackground( GALLERY_DLG_COLOR );
162 	mpSplitter->SetControlForeground( GALLERY_DLG_COLOR );
163 
164 	mpBrowser1->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
165 	mpBrowser1->SetControlBackground( GALLERY_DLG_COLOR );
166 	mpBrowser1->SetControlForeground( GALLERY_DLG_COLOR );
167 
168 	mpBrowser2->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
169 	mpBrowser2->SetControlBackground( GALLERY_DLG_COLOR );
170 	mpBrowser2->SetControlForeground( GALLERY_DLG_COLOR );
171 }
172 
173 // -----------------------------------------------------------------------------
174 
175 void GalleryBrowser::Resize()
176 {
177 	SfxDockingWindow::Resize();
178 
179 	const long	nFrameWidth = LogicToPixel( Size( 3, 0 ), MAP_APPFONT ).Width();
180 	const long	nFrameWidth2 = nFrameWidth << 1;
181 	Size		aMinSize( GetMinOutputSizePixel() );
182 	Size		aNewSize( GetOutputSizePixel() );
183 	Point		aSplitPos( mpSplitter->GetPosPixel() );
184 	const Size	aSplitSize( mpSplitter->GetOutputSizePixel() );
185 
186 	mpBrowser1->SetPosSizePixel( Point( nFrameWidth, nFrameWidth ),
187 								 Size( aSplitPos.X() - nFrameWidth, aNewSize.Height() - nFrameWidth2 ) );
188 
189 	mpSplitter->SetPosSizePixel( aSplitPos, Size( aSplitSize.Width(), aNewSize.Height() ) );
190 	mpSplitter->SetDragRectPixel( Rectangle( Point( nFrameWidth2, 0 ), Size( aNewSize.Width() - ( nFrameWidth2 << 1 ) - aSplitSize.Width(), aNewSize.Height() ) ) );
191 
192 	mpBrowser2->SetPosSizePixel( Point( aSplitPos.X() + aSplitSize.Width(), nFrameWidth ),
193 								 Size( aNewSize.Width() - aSplitSize.Width() - aSplitPos.X() - nFrameWidth, aNewSize.Height() - nFrameWidth2 ) );
194 
195 	maLastSize = aNewSize;
196 }
197 
198 // -----------------------------------------------------------------------------
199 
200 sal_Bool GalleryBrowser::KeyInput( const KeyEvent& rKEvt, Window* )
201 {
202     const sal_uInt16    nCode = rKEvt.GetKeyCode().GetCode();
203     sal_Bool            bRet = ( !rKEvt.GetKeyCode().IsMod1() &&
204                            ( ( KEY_TAB == nCode ) || ( KEY_F6 == nCode && rKEvt.GetKeyCode().IsMod2() ) ) );
205 
206     if( bRet )
207     {
208         if( !rKEvt.GetKeyCode().IsShift() )
209         {
210             if( mpBrowser1->mpThemes->HasChildPathFocus( sal_True ) )
211                 mpBrowser2->GetViewWindow()->GrabFocus();
212             else if( mpBrowser2->GetViewWindow()->HasFocus() )
213                 mpBrowser2->maViewBox.GrabFocus();
214             else if( mpBrowser2->maViewBox.HasFocus() )
215                 mpBrowser1->maNewTheme.GrabFocus();
216             else
217                 mpBrowser1->mpThemes->GrabFocus();
218         }
219         else
220         {
221             if( mpBrowser1->mpThemes->HasChildPathFocus( sal_True ) )
222                 mpBrowser1->maNewTheme.GrabFocus();
223             else if( mpBrowser1->maNewTheme.HasFocus() )
224                 mpBrowser2->maViewBox.GrabFocus();
225             else if( mpBrowser2->maViewBox.HasFocus() )
226                 mpBrowser2->GetViewWindow()->GrabFocus();
227             else
228                 mpBrowser1->mpThemes->GrabFocus();
229         }
230     }
231 
232     return bRet;
233 }
234 
235 // -----------------------------------------------------------------------------
236 
237 sal_Bool GalleryBrowser::Close()
238 {
239 	return SfxDockingWindow::Close();
240 }
241 
242 // -----------------------------------------------------------------------------
243 
244 void GalleryBrowser::GetFocus()
245 {
246 	SfxDockingWindow::GetFocus();
247 	mpBrowser1->GrabFocus();
248 }
249 
250 // -----------------------------------------------------------------------------
251 
252 void GalleryBrowser::ThemeSelectionHasChanged()
253 {
254 	mpBrowser2->SelectTheme( mpBrowser1->GetSelectedTheme() );
255 }
256 
257 // -----------------------------------------------------------------------------
258 
259 INetURLObject GalleryBrowser::GetURL() const
260 {
261 	return mpBrowser2->GetURL();
262 }
263 
264 // -----------------------------------------------------------------------------
265 
266 String GalleryBrowser::GetFilterName() const
267 {
268 	return mpBrowser2->GetFilterName();
269 }
270 
271 // -----------------------------------------------------------------------------
272 
273 Graphic GalleryBrowser::GetGraphic() const
274 {
275 	return mpBrowser2->GetGraphic();
276 }
277 
278 // -----------------------------------------------------------------------------
279 
280 sal_Bool GalleryBrowser::GetVCDrawModel( FmFormModel& rModel ) const
281 {
282 	return mpBrowser2->GetVCDrawModel( rModel );
283 }
284 
285 // -----------------------------------------------------------------------------
286 
287 sal_Bool GalleryBrowser::IsLinkage() const
288 {
289 	return mpBrowser2->IsLinkage();
290 }
291 
292 // -----------------------------------------------------------------------------
293 
294 IMPL_LINK( GalleryBrowser, SplitHdl, void*, EMPTYARG )
295 {
296 	mpSplitter->SetPosPixel( Point( mpSplitter->GetSplitPosPixel(), mpSplitter->GetPosPixel().Y() ) );
297 	Resize();
298 
299 	return 0L;
300 }
301