Bump version to 6.4-15
[LibreOffice.git] / svx / source / gallery2 / GalleryControl.cxx
blob83979938b00dd388931e1bf5fb473f968f89d2d6
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 <GalleryControl.hxx>
22 #include <svx/galmisc.hxx>
23 #include <svx/gallery1.hxx>
24 #include "galbrws1.hxx"
25 #include <galbrws2.hxx>
26 #include "GallerySplitter.hxx"
27 #include <vcl/svapp.hxx>
28 #include <vcl/settings.hxx>
29 #include <sfx2/sidebar/Theme.hxx>
31 namespace svx { namespace sidebar {
33 static const sal_Int32 gnInitialVerticalSplitPosition (150);
35 GalleryControl::GalleryControl (
36 vcl::Window* pParentWindow)
37 : Window(pParentWindow, WB_SIZEABLE|WB_MOVEABLE|WB_CLOSEABLE|WB_HIDE),
38 mpGallery (Gallery::GetGalleryInstance()),
39 mpSplitter(VclPtr<GallerySplitter>::Create(
40 this,
41 WB_HSCROLL,
42 [this] () { return this->InitSettings(); })),
43 mpBrowser1(VclPtr<GalleryBrowser1>::Create(
44 this,
45 mpGallery,
46 [this] (KeyEvent const& rEvent, vcl::Window *const /*pWindow*/)
47 { return this->GalleryKeyInput(rEvent); },
48 [this] ()
49 { return mpBrowser2->SelectTheme(mpBrowser1->GetSelectedTheme()); })),
50 mpBrowser2(VclPtr<GalleryBrowser2>::Create(this, mpGallery)),
51 mbIsInitialResize(true)
53 mpBrowser1->SelectTheme(0);
54 mpBrowser1->Show();
56 mpBrowser2->Show();
58 mpSplitter->SetHorizontal(false);
59 mpSplitter->SetSplitHdl( LINK( this, GalleryControl, SplitHdl ) );
60 mpSplitter->Show();
62 InitSettings();
65 GalleryControl::~GalleryControl()
67 disposeOnce();
70 void GalleryControl::dispose()
72 mpBrowser2.disposeAndClear();
73 mpBrowser1.disposeAndClear();
74 mpSplitter.disposeAndClear();
75 vcl::Window::dispose();
78 void GalleryControl::InitSettings()
80 SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
81 SetControlBackground( GALLERY_DLG_COLOR );
82 SetControlForeground( GALLERY_DLG_COLOR );
84 mpSplitter->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
85 mpSplitter->SetControlBackground( GALLERY_DLG_COLOR );
86 mpSplitter->SetControlForeground( GALLERY_DLG_COLOR );
88 mpBrowser1->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
89 mpBrowser1->SetControlBackground( GALLERY_DLG_COLOR );
90 mpBrowser1->SetControlForeground( GALLERY_DLG_COLOR );
92 mpBrowser2->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
93 mpBrowser2->SetControlBackground( GALLERY_DLG_COLOR );
94 mpBrowser2->SetControlForeground( GALLERY_DLG_COLOR );
96 const Wallpaper aBackground (sfx2::sidebar::Theme::GetWallpaper(sfx2::sidebar::Theme::Paint_PanelBackground));
97 mpSplitter->SetBackground(aBackground);
98 SetBackground(aBackground);
99 mpBrowser2->SetBackground(aBackground);
102 void GalleryControl::Resize()
104 // call parent
105 Window::Resize();
107 // update hor/ver
108 const Size aNewSize( GetOutputSizePixel() );
109 if (aNewSize.Width()<=0 || aNewSize.Height()<=0)
110 return;
112 const bool bNewLayoutHorizontal(aNewSize.Width() > aNewSize.Height());
113 const bool bOldLayoutHorizontal(mpSplitter->IsHorizontal());
114 long nSplitPos( bOldLayoutHorizontal ? mpSplitter->GetPosPixel().X() : mpSplitter->GetPosPixel().Y());
115 const long nSplitSize( bOldLayoutHorizontal ? mpSplitter->GetOutputSizePixel().Width() : mpSplitter->GetOutputSizePixel().Height());
117 if(bNewLayoutHorizontal != bOldLayoutHorizontal)
119 mpSplitter->SetHorizontal(bNewLayoutHorizontal);
121 else
123 if (mbIsInitialResize)
125 nSplitPos = gnInitialVerticalSplitPosition;
126 if (nSplitPos > aNewSize.Height()/2)
127 nSplitPos = aNewSize.Height()/2;
130 mbIsInitialResize = false;
132 const long nFrameLen = LogicToPixel(Size(3, 0), MapMode(MapUnit::MapAppFont)).Width();
133 const long nFrameLen2 = nFrameLen << 1;
135 if(bNewLayoutHorizontal)
137 mpBrowser1->SetPosSizePixel(
138 Point( nFrameLen, nFrameLen ),
139 Size(nSplitPos - nFrameLen, aNewSize.Height() - nFrameLen2) );
141 mpSplitter->SetPosSizePixel(
142 Point( nSplitPos, 0),
143 Size( nSplitSize, aNewSize.Height() ) );
145 mpSplitter->SetDragRectPixel(
146 tools::Rectangle(
147 Point( nFrameLen2, 0 ),
148 Size( aNewSize.Width() - ( nFrameLen2 << 1 ) - nSplitSize, aNewSize.Height() ) ) );
150 mpBrowser2->SetPosSizePixel(
151 Point( nSplitPos + nSplitSize, nFrameLen ),
152 Size( aNewSize.Width() - nSplitSize - nSplitPos - nFrameLen, aNewSize.Height() - nFrameLen2 ) );
154 else
156 mpBrowser1->SetPosSizePixel(
157 Point( nFrameLen, nFrameLen ),
158 Size(aNewSize.Width() - nFrameLen2, nSplitPos - nFrameLen));
160 mpSplitter->SetPosSizePixel(
161 Point( 0, nSplitPos),
162 Size( aNewSize.Width(), nSplitSize ) );
164 mpSplitter->SetDragRectPixel(
165 tools::Rectangle(
166 Point( 0, nFrameLen2 ),
167 Size( aNewSize.Width(), aNewSize.Height() - ( nFrameLen2 << 1 ) - nSplitSize ) ));
169 mpBrowser2->SetPosSizePixel(
170 Point( nFrameLen, nSplitPos + nSplitSize ),
171 Size( aNewSize.Width() - nFrameLen2, aNewSize.Height() - nSplitSize - nSplitPos - nFrameLen ));
175 bool GalleryControl::GalleryKeyInput( const KeyEvent& rKEvt )
177 const sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
178 bool bRet = ( !rKEvt.GetKeyCode().IsMod1() &&
179 ( ( KEY_TAB == nCode ) || ( KEY_F6 == nCode && rKEvt.GetKeyCode().IsMod2() ) ) );
181 if( bRet )
183 if( !rKEvt.GetKeyCode().IsShift() )
185 if( mpBrowser1->maNewTheme->HasFocus() )
186 mpBrowser1->mpThemes->GrabFocus();
187 else if( mpBrowser1->mpThemes->HasChildPathFocus( true ) )
188 mpBrowser2->maViewBox->GrabFocus();
189 else if( mpBrowser2->maViewBox->HasFocus() )
190 mpBrowser2->GetViewWindow()->GrabFocus();
191 else
193 if( mpBrowser1->maNewTheme->IsEnabled() )
194 mpBrowser1->maNewTheme->GrabFocus();
195 else
196 mpBrowser1->mpThemes->GrabFocus();
199 else
201 if( mpBrowser2->GetViewWindow()->HasFocus() )
202 mpBrowser2->maViewBox->GrabFocus();
203 else if( mpBrowser2->maViewBox->HasFocus() )
204 mpBrowser1->mpThemes->GrabFocus();
205 else if( mpBrowser1->mpThemes->HasChildPathFocus( true ) )
207 if( mpBrowser1->maNewTheme->IsEnabled() )
208 mpBrowser1->maNewTheme->GrabFocus();
209 else
210 mpBrowser2->GetViewWindow()->GrabFocus();
212 else
213 mpBrowser2->GetViewWindow()->GrabFocus();
217 return bRet;
220 void GalleryControl::GetFocus()
222 Window::GetFocus();
223 if (mpBrowser1)
224 mpBrowser1->GrabFocus();
227 IMPL_LINK_NOARG( GalleryControl, SplitHdl, Splitter*, void )
229 if(mpSplitter->IsHorizontal())
231 mpSplitter->SetPosPixel( Point( mpSplitter->GetSplitPosPixel(), mpSplitter->GetPosPixel().Y() ) );
233 else
235 mpSplitter->SetPosPixel( Point( mpSplitter->GetPosPixel().X(), mpSplitter->GetSplitPosPixel() ) );
238 Resize();
242 } } // end of namespace svx::sidebar
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */