fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / gallery2 / galbrws.cxx
blob7435788b614bda023984ef6b48698b98cb09eb87
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/split.hxx>
21 #include <vcl/ctrl.hxx>
22 #include <unotools/pathoptions.hxx>
23 #include <sfx2/app.hxx>
24 #include <sfx2/sfxsids.hrc>
25 #include "gallery.hrc"
26 #include "svx/galmisc.hxx"
27 #include "svx/gallery1.hxx"
28 #include "galbrws1.hxx"
29 #include "galbrws2.hxx"
30 #include "svx/galbrws.hxx"
31 #include "GallerySplitter.hxx"
33 #include <boost/bind.hpp>
35 // -------------------------
36 // - SvxGalleryChildWindow -
37 // -------------------------
38 DBG_NAME(GalleryChildWindow)
40 GalleryChildWindow::GalleryChildWindow( Window* _pParent, sal_uInt16 nId, SfxBindings* pBindings, SfxChildWinInfo* pInfo ) :
41 SfxChildWindow( _pParent, nId )
43 DBG_CTOR(GalleryChildWindow,NULL);
45 pWindow = new GalleryBrowser( pBindings, this, _pParent, GAL_RES( RID_SVXDLG_GALLERYBROWSER ) );
46 eChildAlignment = SFX_ALIGN_TOP;
47 ( (GalleryBrowser*) pWindow )->Initialize( pInfo );
50 // -----------------------------------------------------------------------------
52 GalleryChildWindow::~GalleryChildWindow()
54 DBG_DTOR(GalleryChildWindow,NULL);
57 // -----------------------------------------------------------------------------
59 SFX_IMPL_DOCKINGWINDOW_WITHID( GalleryChildWindow, SID_GALLERY )
61 // ------------------
62 // - GalleryBrowser -
63 // ------------------
64 DBG_NAME(GalleryBrowser)
66 GalleryBrowser::GalleryBrowser(
67 SfxBindings* _pBindings,
68 SfxChildWindow* pCW,
69 Window* pParent,
70 const ResId& rResId)
71 : SfxDockingWindow(_pBindings, pCW, pParent, rResId),
72 maLastSize(GetOutputSizePixel()),
73 mpSplitter(0),
74 mpBrowser1(0),
75 mpBrowser2(0),
76 mpGallery(0)
78 DBG_CTOR(GalleryBrowser,NULL);
80 mpGallery = Gallery::GetGalleryInstance();
81 mpBrowser1 = new GalleryBrowser1(
82 this,
83 GAL_RES( GALLERY_BROWSER1 ),
84 mpGallery,
85 ::boost::bind(&GalleryBrowser::KeyInput,this,_1,_2),
86 ::boost::bind(&GalleryBrowser::ThemeSelectionHasChanged, this));
87 mpSplitter = new GallerySplitter( this, GAL_RES( GALLERY_SPLITTER ),
88 ::boost::bind(&GalleryBrowser::InitSettings, this));
89 mpBrowser2 = new GalleryBrowser2( this, GAL_RES( GALLERY_BROWSER2 ), mpGallery );
91 FreeResource();
92 SetMinOutputSizePixel(maLastSize);
94 mpBrowser1->SelectTheme( 0 );
95 mpBrowser1->Show( sal_True );
96 mpBrowser2->Show( sal_True );
98 const bool bLayoutHorizontal(maLastSize.Width() > maLastSize.Height());
99 mpSplitter->SetHorizontal(bLayoutHorizontal);
100 mpSplitter->SetSplitHdl( LINK( this, GalleryBrowser, SplitHdl ) );
101 mpSplitter->Show( sal_True );
103 InitSettings();
106 // -----------------------------------------------------------------------------
108 GalleryBrowser::~GalleryBrowser()
110 delete mpBrowser2;
111 delete mpSplitter;
112 delete mpBrowser1;
114 DBG_DTOR(GalleryBrowser,NULL);
117 // -----------------------------------------------------------------------------
119 void GalleryBrowser::InitSettings()
121 SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
122 SetControlBackground( GALLERY_DLG_COLOR );
123 SetControlForeground( GALLERY_DLG_COLOR );
125 mpSplitter->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
126 mpSplitter->SetControlBackground( GALLERY_DLG_COLOR );
127 mpSplitter->SetControlForeground( GALLERY_DLG_COLOR );
129 mpBrowser1->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
130 mpBrowser1->SetControlBackground( GALLERY_DLG_COLOR );
131 mpBrowser1->SetControlForeground( GALLERY_DLG_COLOR );
133 mpBrowser2->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
134 mpBrowser2->SetControlBackground( GALLERY_DLG_COLOR );
135 mpBrowser2->SetControlForeground( GALLERY_DLG_COLOR );
138 // -----------------------------------------------------------------------------
140 void GalleryBrowser::Resize()
142 // call parent
143 SfxDockingWindow::Resize();
145 // update hor/ver
146 const Size aNewSize( GetOutputSizePixel() );
147 const bool bNewLayoutHorizontal(aNewSize.Width() > aNewSize.Height());
148 const bool bOldLayoutHorizontal(mpSplitter->IsHorizontal());
149 const long nSplitPos( bOldLayoutHorizontal ? mpSplitter->GetPosPixel().X() : mpSplitter->GetPosPixel().Y());
150 const long nSplitSize( bOldLayoutHorizontal ? mpSplitter->GetOutputSizePixel().Width() : mpSplitter->GetOutputSizePixel().Height());
152 if(bNewLayoutHorizontal != bOldLayoutHorizontal)
154 mpSplitter->SetHorizontal(bNewLayoutHorizontal);
157 const long nFrameLen = LogicToPixel( Size( 3, 0 ), MAP_APPFONT ).Width();
158 const long nFrameLen2 = nFrameLen << 1;
160 if(bNewLayoutHorizontal)
162 mpBrowser1->SetPosSizePixel(
163 Point( nFrameLen, nFrameLen ),
164 Size(nSplitPos - nFrameLen, aNewSize.Height() - nFrameLen2) );
166 mpSplitter->SetPosSizePixel(
167 Point( nSplitPos, 0),
168 Size( nSplitSize, aNewSize.Height() ) );
170 mpSplitter->SetDragRectPixel(
171 Rectangle(
172 Point( nFrameLen2, 0 ),
173 Size( aNewSize.Width() - ( nFrameLen2 << 1 ) - nSplitSize, aNewSize.Height() ) ) );
175 mpBrowser2->SetPosSizePixel(
176 Point( nSplitPos + nSplitSize, nFrameLen ),
177 Size( aNewSize.Width() - nSplitSize - nSplitPos - nFrameLen, aNewSize.Height() - nFrameLen2 ) );
179 else
181 mpBrowser1->SetPosSizePixel(
182 Point( nFrameLen, nFrameLen ),
183 Size(aNewSize.Width() - nFrameLen2, nSplitPos - nFrameLen));
185 mpSplitter->SetPosSizePixel(
186 Point( 0, nSplitPos),
187 Size( aNewSize.Width(), nSplitSize ) );
189 mpSplitter->SetDragRectPixel(
190 Rectangle(
191 Point( 0, nFrameLen2 ),
192 Size( aNewSize.Width(), aNewSize.Height() - ( nFrameLen2 << 1 ) - nSplitSize ) ));
194 mpBrowser2->SetPosSizePixel(
195 Point( nFrameLen, nSplitPos + nSplitSize ),
196 Size( aNewSize.Width() - nFrameLen2, aNewSize.Height() - nSplitSize - nSplitPos - nFrameLen ));
199 maLastSize = aNewSize;
202 // -----------------------------------------------------------------------------
204 sal_Bool GalleryBrowser::KeyInput( const KeyEvent& rKEvt, Window* )
206 const sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
207 sal_Bool bRet = ( !rKEvt.GetKeyCode().IsMod1() &&
208 ( ( KEY_TAB == nCode ) || ( KEY_F6 == nCode && rKEvt.GetKeyCode().IsMod2() ) ) );
210 if( bRet )
212 if( !rKEvt.GetKeyCode().IsShift() )
214 if( mpBrowser1->mpThemes->HasChildPathFocus( sal_True ) )
215 mpBrowser2->GetViewWindow()->GrabFocus();
216 else if( mpBrowser2->GetViewWindow()->HasFocus() )
217 mpBrowser2->maViewBox.GrabFocus();
218 else if( mpBrowser2->maViewBox.HasFocus() )
219 mpBrowser1->maNewTheme.GrabFocus();
220 else
221 mpBrowser1->mpThemes->GrabFocus();
223 else
225 if( mpBrowser1->mpThemes->HasChildPathFocus( sal_True ) )
226 mpBrowser1->maNewTheme.GrabFocus();
227 else if( mpBrowser1->maNewTheme.HasFocus() )
228 mpBrowser2->maViewBox.GrabFocus();
229 else if( mpBrowser2->maViewBox.HasFocus() )
230 mpBrowser2->GetViewWindow()->GrabFocus();
231 else
232 mpBrowser1->mpThemes->GrabFocus();
236 return bRet;
239 // -----------------------------------------------------------------------------
241 sal_Bool GalleryBrowser::Close()
243 return SfxDockingWindow::Close();
246 // -----------------------------------------------------------------------------
248 void GalleryBrowser::GetFocus()
250 SfxDockingWindow::GetFocus();
251 mpBrowser1->GrabFocus();
254 // -----------------------------------------------------------------------------
256 void GalleryBrowser::ThemeSelectionHasChanged()
258 mpBrowser2->SelectTheme( mpBrowser1->GetSelectedTheme() );
261 // -----------------------------------------------------------------------------
263 INetURLObject GalleryBrowser::GetURL() const
265 return mpBrowser2->GetURL();
268 // -----------------------------------------------------------------------------
270 String GalleryBrowser::GetFilterName() const
272 return mpBrowser2->GetFilterName();
275 // -----------------------------------------------------------------------------
277 Graphic GalleryBrowser::GetGraphic() const
279 return mpBrowser2->GetGraphic();
282 // -----------------------------------------------------------------------------
284 sal_Bool GalleryBrowser::IsLinkage() const
286 return mpBrowser2->IsLinkage();
289 // -----------------------------------------------------------------------------
291 IMPL_LINK_NOARG(GalleryBrowser, SplitHdl)
293 if(mpSplitter->IsHorizontal())
295 mpSplitter->SetPosPixel( Point( mpSplitter->GetSplitPosPixel(), mpSplitter->GetPosPixel().Y() ) );
297 else
299 mpSplitter->SetPosPixel( Point( mpSplitter->GetPosPixel().X(), mpSplitter->GetSplitPosPixel() ) );
302 Resize();
304 return 0L;
307 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */