fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / gallery2 / GalleryControl.cxx
blob9c6356beeef02fda23f667eae467f451472522c1
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 #include "sidebar/PanelFactory.hxx"
20 #include "GalleryControl.hxx"
22 #include "gallery.hrc"
23 #include "svx/galmisc.hxx"
24 #include "svx/gallery1.hxx"
25 #include "galbrws1.hxx"
26 #include "galbrws2.hxx"
27 #include "GallerySplitter.hxx"
28 #include <vcl/svapp.hxx>
29 #include <sfx2/sidebar/Theme.hxx>
31 #include <boost/bind.hpp>
33 namespace svx { namespace sidebar {
35 static const sal_Int32 gnInitialVerticalSplitPosition (150);
38 GalleryControl::GalleryControl (
39 SfxBindings* /*pBindings*/,
40 Window* pParentWindow)
41 : Window(pParentWindow, GAL_RES(RID_SVXDLG_GALLERYBROWSER)),
42 mpGallery (Gallery::GetGalleryInstance()),
43 mpSplitter(new GallerySplitter(
44 this,
45 GAL_RES(GALLERY_SPLITTER),
46 ::boost::bind(&GalleryControl::InitSettings, this))),
47 mpBrowser1(new GalleryBrowser1(
48 this,
49 GAL_RES(GALLERY_BROWSER1),
50 mpGallery,
51 ::boost::bind(&GalleryControl::GalleryKeyInput,this,_1,_2),
52 ::boost::bind(&GalleryControl::ThemeSelectionHasChanged, this))),
53 mpBrowser2(new GalleryBrowser2(this, GAL_RES(GALLERY_BROWSER2), mpGallery)),
54 maLastSize(GetOutputSizePixel()),
55 mbIsInitialResize(true)
57 FreeResource();
59 mpBrowser1->SelectTheme(0);
60 mpBrowser1->Show(sal_True);
62 mpBrowser2->Show(sal_True);
64 mpSplitter->SetHorizontal(false);
65 mpSplitter->SetSplitHdl( LINK( this, GalleryControl, SplitHdl ) );
66 mpSplitter->Show( sal_True );
68 InitSettings();
74 GalleryControl::~GalleryControl (void)
81 void GalleryControl::InitSettings (void)
83 SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
84 SetControlBackground( GALLERY_DLG_COLOR );
85 SetControlForeground( GALLERY_DLG_COLOR );
87 mpSplitter->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
88 mpSplitter->SetControlBackground( GALLERY_DLG_COLOR );
89 mpSplitter->SetControlForeground( GALLERY_DLG_COLOR );
91 mpBrowser1->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
92 mpBrowser1->SetControlBackground( GALLERY_DLG_COLOR );
93 mpBrowser1->SetControlForeground( GALLERY_DLG_COLOR );
95 mpBrowser2->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
96 mpBrowser2->SetControlBackground( GALLERY_DLG_COLOR );
97 mpBrowser2->SetControlForeground( GALLERY_DLG_COLOR );
99 const Wallpaper aBackground (sfx2::sidebar::Theme::GetWallpaper(sfx2::sidebar::Theme::Paint_PanelBackground));
100 mpSplitter->SetBackground(aBackground);
101 SetBackground(aBackground);
102 mpBrowser2->SetBackground(aBackground);
108 void GalleryControl::Resize (void)
110 // call parent
111 Window::Resize();
113 // update hor/ver
114 const Size aNewSize( GetOutputSizePixel() );
115 if (aNewSize.Width()<=0 || aNewSize.Height()<=0)
116 return;
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());
123 if(bNewLayoutHorizontal != bOldLayoutHorizontal)
125 mpSplitter->SetHorizontal(bNewLayoutHorizontal);
127 else
129 if (mbIsInitialResize)
131 nSplitPos = gnInitialVerticalSplitPosition;
132 if (nSplitPos > aNewSize.Height()/2)
133 nSplitPos = aNewSize.Height()/2;
136 mbIsInitialResize = false;
138 const long nFrameLen = LogicToPixel( Size( 3, 0 ), MAP_APPFONT ).Width();
139 const long nFrameLen2 = nFrameLen << 1;
141 if(bNewLayoutHorizontal)
143 mpBrowser1->SetPosSizePixel(
144 Point( nFrameLen, nFrameLen ),
145 Size(nSplitPos - nFrameLen, aNewSize.Height() - nFrameLen2) );
147 mpSplitter->SetPosSizePixel(
148 Point( nSplitPos, 0),
149 Size( nSplitSize, aNewSize.Height() ) );
151 mpSplitter->SetDragRectPixel(
152 Rectangle(
153 Point( nFrameLen2, 0 ),
154 Size( aNewSize.Width() - ( nFrameLen2 << 1 ) - nSplitSize, aNewSize.Height() ) ) );
156 mpBrowser2->SetPosSizePixel(
157 Point( nSplitPos + nSplitSize, nFrameLen ),
158 Size( aNewSize.Width() - nSplitSize - nSplitPos - nFrameLen, aNewSize.Height() - nFrameLen2 ) );
160 else
162 mpBrowser1->SetPosSizePixel(
163 Point( nFrameLen, nFrameLen ),
164 Size(aNewSize.Width() - nFrameLen2, nSplitPos - nFrameLen));
166 mpSplitter->SetPosSizePixel(
167 Point( 0, nSplitPos),
168 Size( aNewSize.Width(), nSplitSize ) );
170 mpSplitter->SetDragRectPixel(
171 Rectangle(
172 Point( 0, nFrameLen2 ),
173 Size( aNewSize.Width(), aNewSize.Height() - ( nFrameLen2 << 1 ) - nSplitSize ) ));
175 mpBrowser2->SetPosSizePixel(
176 Point( nFrameLen, nSplitPos + nSplitSize ),
177 Size( aNewSize.Width() - nFrameLen2, aNewSize.Height() - nSplitSize - nSplitPos - nFrameLen ));
180 maLastSize = aNewSize;
186 sal_Bool GalleryControl::GalleryKeyInput( const KeyEvent& rKEvt, Window* )
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() ) ) );
192 if( bRet )
194 if( !rKEvt.GetKeyCode().IsShift() )
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();
205 else
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();
218 return bRet;
224 void GalleryControl::GetFocus (void)
226 Window::GetFocus();
227 mpBrowser1->GrabFocus();
233 void GalleryControl::ThemeSelectionHasChanged (void)
235 mpBrowser2->SelectTheme(mpBrowser1->GetSelectedTheme());
241 INetURLObject GalleryControl::GetURL (void) const
243 return mpBrowser2->GetURL();
249 String GalleryControl::GetFilterName (void) const
251 return mpBrowser2->GetFilterName();
257 Graphic GalleryControl::GetGraphic(void) const
259 return mpBrowser2->GetGraphic();
265 sal_Bool GalleryControl::IsLinkage (void) const
267 return mpBrowser2->IsLinkage();
273 IMPL_LINK( GalleryControl, SplitHdl, void*, EMPTYARG )
275 if(mpSplitter->IsHorizontal())
277 mpSplitter->SetPosPixel( Point( mpSplitter->GetSplitPosPixel(), mpSplitter->GetPosPixel().Y() ) );
279 else
281 mpSplitter->SetPosPixel( Point( mpSplitter->GetPosPixel().X(), mpSplitter->GetSplitPosPixel() ) );
284 Resize();
286 return 0L;
290 } } // end of namespace svx::sidebar