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