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