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