xref: /aoo41x/main/svx/source/gallery2/galbrws.cxx (revision 02c50d82)
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 #include "GallerySplitter.hxx"
37 
38 #include <boost/bind.hpp>
39 
40 // -------------------------
41 // - SvxGalleryChildWindow -
42 // -------------------------
43 DBG_NAME(GalleryChildWindow)
44 
45 GalleryChildWindow::GalleryChildWindow( Window* _pParent, sal_uInt16 nId, SfxBindings* pBindings, SfxChildWinInfo* pInfo ) :
46 	SfxChildWindow( _pParent, nId )
47 {
48     DBG_CTOR(GalleryChildWindow,NULL);
49 
50 	pWindow = new GalleryBrowser( pBindings, this, _pParent, GAL_RESID( RID_SVXDLG_GALLERYBROWSER ) );
51 	eChildAlignment = SFX_ALIGN_TOP;
52 	( (GalleryBrowser*) pWindow )->Initialize( pInfo );
53 };
54 
55 // -----------------------------------------------------------------------------
56 
57 GalleryChildWindow::~GalleryChildWindow()
58 {
59 
60     DBG_DTOR(GalleryChildWindow,NULL);
61 }
62 
63 // -----------------------------------------------------------------------------
64 
65 SFX_IMPL_DOCKINGWINDOW( GalleryChildWindow, SID_GALLERY )
66 
67 // ------------------
68 // - GalleryBrowser -
69 // ------------------
70 DBG_NAME(GalleryBrowser)
71 
72 GalleryBrowser::GalleryBrowser(
73     SfxBindings* _pBindings,
74     SfxChildWindow* pCW,
75     Window* pParent,
76     const ResId& rResId)
77 :   SfxDockingWindow(_pBindings, pCW, pParent, rResId),
78     maLastSize(GetOutputSizePixel()),
79     mpSplitter(0),
80     mpBrowser1(0),
81     mpBrowser2(0),
82     mpGallery(0)
83 {
84     DBG_CTOR(GalleryBrowser,NULL);
85 
86 	mpGallery = Gallery::GetGalleryInstance();
87 	mpBrowser1 = new GalleryBrowser1(
88         this,
89         GAL_RESID( GALLERY_BROWSER1 ),
90         mpGallery,
91         ::boost::bind(&GalleryBrowser::KeyInput,this,_1,_2),
92         ::boost::bind(&GalleryBrowser::ThemeSelectionHasChanged, this));
93 	mpSplitter = new GallerySplitter( this, GAL_RESID( GALLERY_SPLITTER ),
94         ::boost::bind(&GalleryBrowser::InitSettings, this));
95 	mpBrowser2 = new GalleryBrowser2( this, GAL_RESID( GALLERY_BROWSER2 ), mpGallery );
96 
97 	FreeResource();
98 	SetMinOutputSizePixel(maLastSize);
99 
100 	mpBrowser1->SelectTheme( 0 );
101 	mpBrowser1->Show( sal_True );
102 	mpBrowser2->Show( sal_True );
103 
104     const bool bLayoutHorizontal(maLastSize.Width() > maLastSize.Height());
105     mpSplitter->SetHorizontal(bLayoutHorizontal);
106 	mpSplitter->SetSplitHdl( LINK( this, GalleryBrowser, SplitHdl ) );
107 	mpSplitter->Show( sal_True );
108 
109     InitSettings();
110 }
111 
112 // -----------------------------------------------------------------------------
113 
114 GalleryBrowser::~GalleryBrowser()
115 {
116 	delete mpBrowser2;
117 	delete mpSplitter;
118 	delete mpBrowser1;
119 
120     DBG_DTOR(GalleryBrowser,NULL);
121 }
122 
123 // -----------------------------------------------------------------------------
124 
125 void GalleryBrowser::InitSettings()
126 {
127 	SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
128 	SetControlBackground( GALLERY_DLG_COLOR );
129 	SetControlForeground( GALLERY_DLG_COLOR );
130 
131 	mpSplitter->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
132 	mpSplitter->SetControlBackground( GALLERY_DLG_COLOR );
133 	mpSplitter->SetControlForeground( GALLERY_DLG_COLOR );
134 
135 	mpBrowser1->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
136 	mpBrowser1->SetControlBackground( GALLERY_DLG_COLOR );
137 	mpBrowser1->SetControlForeground( GALLERY_DLG_COLOR );
138 
139 	mpBrowser2->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
140 	mpBrowser2->SetControlBackground( GALLERY_DLG_COLOR );
141 	mpBrowser2->SetControlForeground( GALLERY_DLG_COLOR );
142 }
143 
144 // -----------------------------------------------------------------------------
145 
146 void GalleryBrowser::Resize()
147 {
148     // call parent
149     SfxDockingWindow::Resize();
150 
151     // update hor/ver
152     const Size aNewSize( GetOutputSizePixel() );
153     const bool bNewLayoutHorizontal(aNewSize.Width() > aNewSize.Height());
154     const bool bOldLayoutHorizontal(mpSplitter->IsHorizontal());
155     const long nSplitPos( bOldLayoutHorizontal ? mpSplitter->GetPosPixel().X() : mpSplitter->GetPosPixel().Y());
156     const long nSplitSize( bOldLayoutHorizontal ? mpSplitter->GetOutputSizePixel().Width() : mpSplitter->GetOutputSizePixel().Height());
157 
158     if(bNewLayoutHorizontal != bOldLayoutHorizontal)
159     {
160         mpSplitter->SetHorizontal(bNewLayoutHorizontal);
161     }
162 
163     const long nFrameLen = LogicToPixel( Size( 3, 0 ), MAP_APPFONT ).Width();
164     const long nFrameLen2 = nFrameLen << 1;
165 
166     if(bNewLayoutHorizontal)
167     {
168         mpBrowser1->SetPosSizePixel(
169             Point( nFrameLen, nFrameLen ),
170             Size(nSplitPos - nFrameLen, aNewSize.Height() - nFrameLen2) );
171 
172         mpSplitter->SetPosSizePixel(
173             Point( nSplitPos, 0),
174             Size( nSplitSize, aNewSize.Height() ) );
175 
176         mpSplitter->SetDragRectPixel(
177             Rectangle(
178                 Point( nFrameLen2, 0 ),
179                 Size( aNewSize.Width() - ( nFrameLen2 << 1 ) - nSplitSize, aNewSize.Height() ) ) );
180 
181         mpBrowser2->SetPosSizePixel(
182             Point( nSplitPos + nSplitSize, nFrameLen ),
183             Size( aNewSize.Width() - nSplitSize - nSplitPos - nFrameLen, aNewSize.Height() - nFrameLen2 ) );
184     }
185     else
186     {
187         mpBrowser1->SetPosSizePixel(
188             Point( nFrameLen, nFrameLen ),
189             Size(aNewSize.Width() - nFrameLen2, nSplitPos - nFrameLen));
190 
191         mpSplitter->SetPosSizePixel(
192             Point( 0, nSplitPos),
193             Size( aNewSize.Width(), nSplitSize ) );
194 
195         mpSplitter->SetDragRectPixel(
196             Rectangle(
197                 Point( 0, nFrameLen2 ),
198                 Size( aNewSize.Width(), aNewSize.Height() - ( nFrameLen2 << 1 ) - nSplitSize ) ));
199 
200         mpBrowser2->SetPosSizePixel(
201             Point( nFrameLen, nSplitPos + nSplitSize ),
202             Size( aNewSize.Width() - nFrameLen2, aNewSize.Height() - nSplitSize - nSplitPos - nFrameLen ));
203     }
204 
205     maLastSize = aNewSize;
206 }
207 
208 // -----------------------------------------------------------------------------
209 
210 sal_Bool GalleryBrowser::KeyInput( const KeyEvent& rKEvt, Window* )
211 {
212     const sal_uInt16    nCode = rKEvt.GetKeyCode().GetCode();
213     sal_Bool            bRet = ( !rKEvt.GetKeyCode().IsMod1() &&
214                            ( ( KEY_TAB == nCode ) || ( KEY_F6 == nCode && rKEvt.GetKeyCode().IsMod2() ) ) );
215 
216     if( bRet )
217     {
218         if( !rKEvt.GetKeyCode().IsShift() )
219         {
220             if( mpBrowser1->mpThemes->HasChildPathFocus( sal_True ) )
221                 mpBrowser2->GetViewWindow()->GrabFocus();
222             else if( mpBrowser2->GetViewWindow()->HasFocus() )
223                 mpBrowser2->maViewBox.GrabFocus();
224             else if( mpBrowser2->maViewBox.HasFocus() )
225                 mpBrowser1->maNewTheme.GrabFocus();
226             else
227                 mpBrowser1->mpThemes->GrabFocus();
228         }
229         else
230         {
231             if( mpBrowser1->mpThemes->HasChildPathFocus( sal_True ) )
232                 mpBrowser1->maNewTheme.GrabFocus();
233             else if( mpBrowser1->maNewTheme.HasFocus() )
234                 mpBrowser2->maViewBox.GrabFocus();
235             else if( mpBrowser2->maViewBox.HasFocus() )
236                 mpBrowser2->GetViewWindow()->GrabFocus();
237             else
238                 mpBrowser1->mpThemes->GrabFocus();
239         }
240     }
241 
242     return bRet;
243 }
244 
245 // -----------------------------------------------------------------------------
246 
247 sal_Bool GalleryBrowser::Close()
248 {
249 	return SfxDockingWindow::Close();
250 }
251 
252 // -----------------------------------------------------------------------------
253 
254 void GalleryBrowser::GetFocus()
255 {
256 	SfxDockingWindow::GetFocus();
257 	mpBrowser1->GrabFocus();
258 }
259 
260 // -----------------------------------------------------------------------------
261 
262 void GalleryBrowser::ThemeSelectionHasChanged()
263 {
264 	mpBrowser2->SelectTheme( mpBrowser1->GetSelectedTheme() );
265 }
266 
267 // -----------------------------------------------------------------------------
268 
269 INetURLObject GalleryBrowser::GetURL() const
270 {
271 	return mpBrowser2->GetURL();
272 }
273 
274 // -----------------------------------------------------------------------------
275 
276 String GalleryBrowser::GetFilterName() const
277 {
278 	return mpBrowser2->GetFilterName();
279 }
280 
281 // -----------------------------------------------------------------------------
282 
283 Graphic GalleryBrowser::GetGraphic() const
284 {
285 	return mpBrowser2->GetGraphic();
286 }
287 
288 // -----------------------------------------------------------------------------
289 
290 sal_Bool GalleryBrowser::GetVCDrawModel( FmFormModel& rModel ) const
291 {
292 	return mpBrowser2->GetVCDrawModel( rModel );
293 }
294 
295 // -----------------------------------------------------------------------------
296 
297 sal_Bool GalleryBrowser::IsLinkage() const
298 {
299 	return mpBrowser2->IsLinkage();
300 }
301 
302 // -----------------------------------------------------------------------------
303 
304 IMPL_LINK( GalleryBrowser, SplitHdl, void*, EMPTYARG )
305 {
306     if(mpSplitter->IsHorizontal())
307     {
308         mpSplitter->SetPosPixel( Point( mpSplitter->GetSplitPosPixel(), mpSplitter->GetPosPixel().Y() ) );
309     }
310     else
311     {
312         mpSplitter->SetPosPixel( Point( mpSplitter->GetPosPixel().X(), mpSplitter->GetSplitPosPixel() ) );
313     }
314 
315     Resize();
316 
317 	return 0L;
318 }
319 
320 // -----------------------------------------------------------------------------
321 // eof
322