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 #include "sidebar/PanelFactory.hxx"
23 
24 #include "GalleryControl.hxx"
25 
26 #include "gallery.hrc"
27 #include "svx/galmisc.hxx"
28 #include "svx/gallery1.hxx"
29 #include "galbrws1.hxx"
30 #include "galbrws2.hxx"
31 #include "GallerySplitter.hxx"
32 #include <vcl/svapp.hxx>
33 
34 #include <boost/bind.hpp>
35 
36 namespace svx { namespace sidebar {
37 
38 GalleryControl::GalleryControl (
39     SfxBindings* pBindings,
40     Window* pParentWindow)
41     : Window(pParentWindow, GAL_RESID(RID_SVXDLG_GALLERYBROWSER)),
42       mpGallery (Gallery::GetGalleryInstance()),
43       mpBrowser1(new GalleryBrowser1(
44               this,
45               GAL_RESID(GALLERY_BROWSER1),
46               mpGallery,
47               ::boost::bind(&GalleryControl::KeyInput,this,_1,_2),
48               ::boost::bind(&GalleryControl::ThemeSelectionHasChanged, this))),
49       mpSplitter(new GallerySplitter(
50               this,
51               GAL_RESID(GALLERY_SPLITTER),
52               ::boost::bind(&GalleryControl::InitSettings, this))),
53       mpBrowser2(new GalleryBrowser2(this, GAL_RESID(GALLERY_BROWSER2), mpGallery)),
54       maLastSize(0,0)
55 {
56     FreeResource();
57     //    SetMinOutputSizePixel(maLastSize);
58     SetSizePixel(Size(300,300));
59 
60     mpBrowser1->SelectTheme(0);
61     mpBrowser1->Show(sal_True);
62     mpBrowser2->Show(sal_True);
63 
64     mpSplitter->SetHorizontal(true);
65 	mpSplitter->SetSplitHdl( LINK( this, GalleryControl, SplitHdl ) );
66 	mpSplitter->Show( sal_True );
67 
68     InitSettings();
69 }
70 
71 
72 
73 
74 GalleryControl::~GalleryControl (void)
75 {
76 }
77 
78 
79 
80 
81 void GalleryControl::InitSettings (void)
82 {
83 	SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
84 	SetControlBackground( GALLERY_DLG_COLOR );
85 	SetControlForeground( GALLERY_DLG_COLOR );
86 
87 	mpSplitter->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
88 	mpSplitter->SetControlBackground( GALLERY_DLG_COLOR );
89 	mpSplitter->SetControlForeground( GALLERY_DLG_COLOR );
90 
91 	mpBrowser1->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
92 	mpBrowser1->SetControlBackground( GALLERY_DLG_COLOR );
93 	mpBrowser1->SetControlForeground( GALLERY_DLG_COLOR );
94 
95 	mpBrowser2->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
96 	mpBrowser2->SetControlBackground( GALLERY_DLG_COLOR );
97 	mpBrowser2->SetControlForeground( GALLERY_DLG_COLOR );
98 }
99 
100 
101 
102 
103 void GalleryControl::Resize (void)
104 {
105     // call parent
106     Window::Resize();
107 
108     // update hor/ver
109     const Size aNewSize( GetOutputSizePixel() );
110     const bool bNewLayoutHorizontal(aNewSize.Width() > aNewSize.Height());
111     const bool bOldLayoutHorizontal(mpSplitter->IsHorizontal());
112     const long nSplitPos( bOldLayoutHorizontal ? mpSplitter->GetPosPixel().X() : mpSplitter->GetPosPixel().Y());
113     const long nSplitSize( bOldLayoutHorizontal ? mpSplitter->GetOutputSizePixel().Width() : mpSplitter->GetOutputSizePixel().Height());
114 
115     if(bNewLayoutHorizontal != bOldLayoutHorizontal)
116     {
117         mpSplitter->SetHorizontal(bNewLayoutHorizontal);
118     }
119 
120     const long nFrameLen = LogicToPixel( Size( 3, 0 ), MAP_APPFONT ).Width();
121     const long nFrameLen2 = nFrameLen << 1;
122 
123     if(bNewLayoutHorizontal)
124     {
125         mpBrowser1->SetPosSizePixel(
126             Point( nFrameLen, nFrameLen ),
127             Size(nSplitPos - nFrameLen, aNewSize.Height() - nFrameLen2) );
128 
129         mpSplitter->SetPosSizePixel(
130             Point( nSplitPos, 0),
131             Size( nSplitSize, aNewSize.Height() ) );
132 
133         mpSplitter->SetDragRectPixel(
134             Rectangle(
135                 Point( nFrameLen2, 0 ),
136                 Size( aNewSize.Width() - ( nFrameLen2 << 1 ) - nSplitSize, aNewSize.Height() ) ) );
137 
138         mpBrowser2->SetPosSizePixel(
139             Point( nSplitPos + nSplitSize, nFrameLen ),
140             Size( aNewSize.Width() - nSplitSize - nSplitPos - nFrameLen, aNewSize.Height() - nFrameLen2 ) );
141     }
142     else
143     {
144         mpBrowser1->SetPosSizePixel(
145             Point( nFrameLen, nFrameLen ),
146             Size(aNewSize.Width() - nFrameLen2, nSplitPos - nFrameLen));
147 
148         mpSplitter->SetPosSizePixel(
149             Point( 0, nSplitPos),
150             Size( aNewSize.Width(), nSplitSize ) );
151 
152         mpSplitter->SetDragRectPixel(
153             Rectangle(
154                 Point( 0, nFrameLen2 ),
155                 Size( aNewSize.Width(), aNewSize.Height() - ( nFrameLen2 << 1 ) - nSplitSize ) ));
156 
157         mpBrowser2->SetPosSizePixel(
158             Point( nFrameLen, nSplitPos + nSplitSize ),
159             Size( aNewSize.Width() - nFrameLen2, aNewSize.Height() - nSplitSize - nSplitPos - nFrameLen ));
160     }
161 
162     maLastSize = aNewSize;
163 }
164 
165 
166 
167 
168 sal_Bool GalleryControl::KeyInput( const KeyEvent& rKEvt, Window* )
169 {
170     const sal_uInt16    nCode = rKEvt.GetKeyCode().GetCode();
171     sal_Bool            bRet = ( !rKEvt.GetKeyCode().IsMod1() &&
172                            ( ( KEY_TAB == nCode ) || ( KEY_F6 == nCode && rKEvt.GetKeyCode().IsMod2() ) ) );
173 
174     if( bRet )
175     {
176         if( !rKEvt.GetKeyCode().IsShift() )
177         {
178             if( mpBrowser1->mpThemes->HasChildPathFocus( sal_True ) )
179                 mpBrowser2->GetViewWindow()->GrabFocus();
180             else if( mpBrowser2->GetViewWindow()->HasFocus() )
181                 mpBrowser2->maViewBox.GrabFocus();
182             else if( mpBrowser2->maViewBox.HasFocus() )
183                 mpBrowser1->maNewTheme.GrabFocus();
184             else
185                 mpBrowser1->mpThemes->GrabFocus();
186         }
187         else
188         {
189             if( mpBrowser1->mpThemes->HasChildPathFocus( sal_True ) )
190                 mpBrowser1->maNewTheme.GrabFocus();
191             else if( mpBrowser1->maNewTheme.HasFocus() )
192                 mpBrowser2->maViewBox.GrabFocus();
193             else if( mpBrowser2->maViewBox.HasFocus() )
194                 mpBrowser2->GetViewWindow()->GrabFocus();
195             else
196                 mpBrowser1->mpThemes->GrabFocus();
197         }
198     }
199 
200     return bRet;
201 }
202 
203 
204 
205 
206 void GalleryControl::GetFocus (void)
207 {
208 	Window::GetFocus();
209 	mpBrowser1->GrabFocus();
210 }
211 
212 
213 
214 
215 void GalleryControl::ThemeSelectionHasChanged (void)
216 {
217 	mpBrowser2->SelectTheme(mpBrowser1->GetSelectedTheme());
218 }
219 
220 
221 
222 
223 INetURLObject GalleryControl::GetURL (void) const
224 {
225 	return mpBrowser2->GetURL();
226 }
227 
228 
229 
230 
231 String GalleryControl::GetFilterName (void) const
232 {
233 	return mpBrowser2->GetFilterName();
234 }
235 
236 
237 
238 
239 Graphic GalleryControl::GetGraphic(void) const
240 {
241 	return mpBrowser2->GetGraphic();
242 }
243 
244 
245 
246 
247 sal_Bool GalleryControl::GetVCDrawModel( FmFormModel& rModel ) const
248 {
249 	return mpBrowser2->GetVCDrawModel( rModel );
250 }
251 
252 
253 
254 
255 sal_Bool GalleryControl::IsLinkage (void) const
256 {
257 	return mpBrowser2->IsLinkage();
258 }
259 
260 
261 
262 
263 IMPL_LINK( GalleryControl, SplitHdl, void*, EMPTYARG )
264 {
265     if(mpSplitter->IsHorizontal())
266     {
267         mpSplitter->SetPosPixel( Point( mpSplitter->GetSplitPosPixel(), mpSplitter->GetPosPixel().Y() ) );
268     }
269     else
270     {
271         mpSplitter->SetPosPixel( Point( mpSplitter->GetPosPixel().X(), mpSplitter->GetSplitPosPixel() ) );
272     }
273 
274     Resize();
275 
276 	return 0L;
277 }
278 
279 
280 } } // end of namespace svx::sidebar
281