xref: /aoo42x/main/svx/source/gallery2/galbrws.cxx (revision 45fc0049)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_svx.hxx"
24 
25 #include <vcl/split.hxx>
26 #include <vcl/ctrl.hxx>
27 #include <unotools/pathoptions.hxx>
28 #include <sfx2/app.hxx>
29 #include <sfx2/sfxsids.hrc>
30 #include "gallery.hrc"
31 #include "svx/galmisc.hxx"
32 #include "svx/gallery1.hxx"
33 #include "galbrws1.hxx"
34 #include "galbrws2.hxx"
35 #include "svx/galbrws.hxx"
36 
37 // -------------------
38 // - GallerySplitter -
39 // -------------------
40 
41 class GallerySplitter : public Splitter
42 {
43 protected:
44 
45     virtual void    DataChanged( const DataChangedEvent& rDCEvt );
46 
47 public:
48 
49                     GallerySplitter( Window* pParent, const ResId& rResId );
50     virtual         ~GallerySplitter();
51 };
52 
53 // -----------------------------------------------------------------------------
54 DBG_NAME(GallerySplitter)
55 
56 GallerySplitter::GallerySplitter( Window* pParent, const ResId& rResId )
57 :   Splitter( pParent, rResId )
58 {
59     DBG_CTOR(GallerySplitter,NULL);
60 }
61 
62 // -----------------------------------------------------------------------------
63 
64 GallerySplitter::~GallerySplitter()
65 {
66     DBG_DTOR(GallerySplitter,NULL);
67 }
68 
69 // -----------------------------------------------------------------------------
70 
71 void GallerySplitter::DataChanged( const DataChangedEvent& rDCEvt )
72 {
73     Splitter::DataChanged( rDCEvt );
74     static_cast< GalleryBrowser* >( GetParent() )->InitSettings();
75 }
76 
77 // -------------------------
78 // - SvxGalleryChildWindow -
79 // -------------------------
80 DBG_NAME(GalleryChildWindow)
81 
82 GalleryChildWindow::GalleryChildWindow( Window* _pParent, sal_uInt16 nId, SfxBindings* pBindings, SfxChildWinInfo* pInfo ) :
83 	SfxChildWindow( _pParent, nId )
84 {
85     DBG_CTOR(GalleryChildWindow,NULL);
86 
87 	pWindow = new GalleryBrowser( pBindings, this, _pParent, GAL_RESID( RID_SVXDLG_GALLERYBROWSER ) );
88 	eChildAlignment = SFX_ALIGN_TOP;
89 	( (GalleryBrowser*) pWindow )->Initialize( pInfo );
90 };
91 
92 // -----------------------------------------------------------------------------
93 
94 GalleryChildWindow::~GalleryChildWindow()
95 {
96 
97     DBG_DTOR(GalleryChildWindow,NULL);
98 }
99 
100 // -----------------------------------------------------------------------------
101 
102 SFX_IMPL_DOCKINGWINDOW( GalleryChildWindow, SID_GALLERY )
103 
104 // ------------------
105 // - GalleryBrowser -
106 // ------------------
107 DBG_NAME(GalleryBrowser)
108 
109 GalleryBrowser::GalleryBrowser(
110     SfxBindings* _pBindings,
111     SfxChildWindow* pCW,
112     Window* pParent,
113     const ResId& rResId)
114 :   SfxDockingWindow(_pBindings, pCW, pParent, rResId),
115     maLastSize(GetOutputSizePixel()),
116     mpSplitter(0),
117     mpBrowser1(0),
118     mpBrowser2(0),
119     mpGallery(0)
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);
130 
131 	mpBrowser1->SelectTheme( 0 );
132 	mpBrowser1->Show( sal_True );
133 	mpBrowser2->Show( sal_True );
134 
135     const bool bLayoutHorizontal(maLastSize.Width() > maLastSize.Height());
136     mpSplitter->SetHorizontal(bLayoutHorizontal);
137 	mpSplitter->SetSplitHdl( LINK( this, GalleryBrowser, SplitHdl ) );
138 	mpSplitter->Show( sal_True );
139 
140     InitSettings();
141 }
142 
143 // -----------------------------------------------------------------------------
144 
145 GalleryBrowser::~GalleryBrowser()
146 {
147 	delete mpBrowser2;
148 	delete mpSplitter;
149 	delete mpBrowser1;
150 
151     DBG_DTOR(GalleryBrowser,NULL);
152 }
153 
154 // -----------------------------------------------------------------------------
155 
156 void GalleryBrowser::InitSettings()
157 {
158 	SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
159 	SetControlBackground( GALLERY_DLG_COLOR );
160 	SetControlForeground( GALLERY_DLG_COLOR );
161 
162 	mpSplitter->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
163 	mpSplitter->SetControlBackground( GALLERY_DLG_COLOR );
164 	mpSplitter->SetControlForeground( GALLERY_DLG_COLOR );
165 
166 	mpBrowser1->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
167 	mpBrowser1->SetControlBackground( GALLERY_DLG_COLOR );
168 	mpBrowser1->SetControlForeground( GALLERY_DLG_COLOR );
169 
170 	mpBrowser2->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
171 	mpBrowser2->SetControlBackground( GALLERY_DLG_COLOR );
172 	mpBrowser2->SetControlForeground( GALLERY_DLG_COLOR );
173 }
174 
175 // -----------------------------------------------------------------------------
176 
177 void GalleryBrowser::Resize()
178 {
179     // call parent
180     SfxDockingWindow::Resize();
181 
182     // update hor/ver
183     const Size aNewSize( GetOutputSizePixel() );
184     const bool bNewLayoutHorizontal(aNewSize.Width() > aNewSize.Height());
185     const bool bOldLayoutHorizontal(mpSplitter->IsHorizontal());
186     const long nSplitPos( bOldLayoutHorizontal ? mpSplitter->GetPosPixel().X() : mpSplitter->GetPosPixel().Y());
187     const long nSplitSize( bOldLayoutHorizontal ? mpSplitter->GetOutputSizePixel().Width() : mpSplitter->GetOutputSizePixel().Height());
188 
189     if(bNewLayoutHorizontal != bOldLayoutHorizontal)
190     {
191         mpSplitter->SetHorizontal(bNewLayoutHorizontal);
192     }
193 
194     const long nFrameLen = LogicToPixel( Size( 3, 0 ), MAP_APPFONT ).Width();
195     const long nFrameLen2 = nFrameLen << 1;
196 
197     if(bNewLayoutHorizontal)
198     {
199         mpBrowser1->SetPosSizePixel(
200             Point( nFrameLen, nFrameLen ),
201             Size(nSplitPos - nFrameLen, aNewSize.Height() - nFrameLen2) );
202 
203         mpSplitter->SetPosSizePixel(
204             Point( nSplitPos, 0),
205             Size( nSplitSize, aNewSize.Height() ) );
206 
207         mpSplitter->SetDragRectPixel(
208             Rectangle(
209                 Point( nFrameLen2, 0 ),
210                 Size( aNewSize.Width() - ( nFrameLen2 << 1 ) - nSplitSize, aNewSize.Height() ) ) );
211 
212         mpBrowser2->SetPosSizePixel(
213             Point( nSplitPos + nSplitSize, nFrameLen ),
214             Size( aNewSize.Width() - nSplitSize - nSplitPos - nFrameLen, aNewSize.Height() - nFrameLen2 ) );
215     }
216     else
217     {
218         mpBrowser1->SetPosSizePixel(
219             Point( nFrameLen, nFrameLen ),
220             Size(aNewSize.Width() - nFrameLen2, nSplitPos - nFrameLen));
221 
222         mpSplitter->SetPosSizePixel(
223             Point( 0, nSplitPos),
224             Size( aNewSize.Width(), nSplitSize ) );
225 
226         mpSplitter->SetDragRectPixel(
227             Rectangle(
228                 Point( 0, nFrameLen2 ),
229                 Size( aNewSize.Width(), aNewSize.Height() - ( nFrameLen2 << 1 ) - nSplitSize ) ));
230 
231         mpBrowser2->SetPosSizePixel(
232             Point( nFrameLen, nSplitPos + nSplitSize ),
233             Size( aNewSize.Width() - nFrameLen2, aNewSize.Height() - nSplitSize - nSplitPos - nFrameLen ));
234     }
235 
236     maLastSize = aNewSize;
237 }
238 
239 // -----------------------------------------------------------------------------
240 
241 sal_Bool GalleryBrowser::KeyInput( const KeyEvent& rKEvt, Window* )
242 {
243     const sal_uInt16    nCode = rKEvt.GetKeyCode().GetCode();
244     sal_Bool            bRet = ( !rKEvt.GetKeyCode().IsMod1() &&
245                            ( ( KEY_TAB == nCode ) || ( KEY_F6 == nCode && rKEvt.GetKeyCode().IsMod2() ) ) );
246 
247     if( bRet )
248     {
249         if( !rKEvt.GetKeyCode().IsShift() )
250         {
251             if( mpBrowser1->mpThemes->HasChildPathFocus( sal_True ) )
252                 mpBrowser2->GetViewWindow()->GrabFocus();
253             else if( mpBrowser2->GetViewWindow()->HasFocus() )
254                 mpBrowser2->maViewBox.GrabFocus();
255             else if( mpBrowser2->maViewBox.HasFocus() )
256                 mpBrowser1->maNewTheme.GrabFocus();
257             else
258                 mpBrowser1->mpThemes->GrabFocus();
259         }
260         else
261         {
262             if( mpBrowser1->mpThemes->HasChildPathFocus( sal_True ) )
263                 mpBrowser1->maNewTheme.GrabFocus();
264             else if( mpBrowser1->maNewTheme.HasFocus() )
265                 mpBrowser2->maViewBox.GrabFocus();
266             else if( mpBrowser2->maViewBox.HasFocus() )
267                 mpBrowser2->GetViewWindow()->GrabFocus();
268             else
269                 mpBrowser1->mpThemes->GrabFocus();
270         }
271     }
272 
273     return bRet;
274 }
275 
276 // -----------------------------------------------------------------------------
277 
278 sal_Bool GalleryBrowser::Close()
279 {
280 	return SfxDockingWindow::Close();
281 }
282 
283 // -----------------------------------------------------------------------------
284 
285 void GalleryBrowser::GetFocus()
286 {
287 	SfxDockingWindow::GetFocus();
288 	mpBrowser1->GrabFocus();
289 }
290 
291 // -----------------------------------------------------------------------------
292 
293 void GalleryBrowser::ThemeSelectionHasChanged()
294 {
295 	mpBrowser2->SelectTheme( mpBrowser1->GetSelectedTheme() );
296 }
297 
298 // -----------------------------------------------------------------------------
299 
300 INetURLObject GalleryBrowser::GetURL() const
301 {
302 	return mpBrowser2->GetURL();
303 }
304 
305 // -----------------------------------------------------------------------------
306 
307 String GalleryBrowser::GetFilterName() const
308 {
309 	return mpBrowser2->GetFilterName();
310 }
311 
312 // -----------------------------------------------------------------------------
313 
314 Graphic GalleryBrowser::GetGraphic() const
315 {
316 	return mpBrowser2->GetGraphic();
317 }
318 
319 // -----------------------------------------------------------------------------
320 
321 sal_Bool GalleryBrowser::GetVCDrawModel( FmFormModel& rModel ) const
322 {
323 	return mpBrowser2->GetVCDrawModel( rModel );
324 }
325 
326 // -----------------------------------------------------------------------------
327 
328 sal_Bool GalleryBrowser::IsLinkage() const
329 {
330 	return mpBrowser2->IsLinkage();
331 }
332 
333 // -----------------------------------------------------------------------------
334 
335 IMPL_LINK( GalleryBrowser, SplitHdl, void*, EMPTYARG )
336 {
337     if(mpSplitter->IsHorizontal())
338     {
339         mpSplitter->SetPosPixel( Point( mpSplitter->GetSplitPosPixel(), mpSplitter->GetPosPixel().Y() ) );
340     }
341     else
342     {
343         mpSplitter->SetPosPixel( Point( mpSplitter->GetPosPixel().X(), mpSplitter->GetSplitPosPixel() ) );
344     }
345 
346     Resize();
347 
348 	return 0L;
349 }
350 
351 // -----------------------------------------------------------------------------
352 // eof
353