1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "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>
32 #include <boost/bind.hpp>
34 namespace svx
{ namespace sidebar
{
36 static const sal_Int32
gnInitialVerticalSplitPosition (150);
38 GalleryControl::GalleryControl (
39 SfxBindings
* /*pBindings*/,
40 vcl::Window
* pParentWindow
)
41 : Window(pParentWindow
, WB_SIZEABLE
|WB_MOVEABLE
|WB_CLOSEABLE
|WB_HIDE
),
42 mpGallery (Gallery::GetGalleryInstance()),
43 mpSplitter(VclPtr
<GallerySplitter
>::Create(
47 ::boost::bind(&GalleryControl::InitSettings
, this))),
48 mpBrowser1(VclPtr
<GalleryBrowser1
>::Create(
52 ::boost::bind(&GalleryControl::GalleryKeyInput
,this,_1
,_2
),
53 ::boost::bind(&GalleryControl::ThemeSelectionHasChanged
, this))),
54 mpBrowser2(VclPtr
<GalleryBrowser2
>::Create(this, mpGallery
)),
55 maLastSize(GetOutputSizePixel()),
56 mbIsInitialResize(true)
58 mpBrowser1
->SelectTheme(0);
59 mpBrowser1
->Show(true);
61 mpBrowser2
->Show(true);
63 mpSplitter
->SetHorizontal(false);
64 mpSplitter
->SetSplitHdl( LINK( this, GalleryControl
, SplitHdl
) );
65 mpSplitter
->Show( true );
70 GalleryControl::~GalleryControl()
75 void GalleryControl::dispose()
77 mpBrowser2
.disposeAndClear();
78 mpBrowser1
.disposeAndClear();
79 mpSplitter
.disposeAndClear();
80 vcl::Window::dispose();
83 void GalleryControl::InitSettings()
85 SetBackground( Wallpaper( GALLERY_DLG_COLOR
) );
86 SetControlBackground( GALLERY_DLG_COLOR
);
87 SetControlForeground( GALLERY_DLG_COLOR
);
89 mpSplitter
->SetBackground( Wallpaper( GALLERY_DLG_COLOR
) );
90 mpSplitter
->SetControlBackground( GALLERY_DLG_COLOR
);
91 mpSplitter
->SetControlForeground( GALLERY_DLG_COLOR
);
93 mpBrowser1
->SetBackground( Wallpaper( GALLERY_DLG_COLOR
) );
94 mpBrowser1
->SetControlBackground( GALLERY_DLG_COLOR
);
95 mpBrowser1
->SetControlForeground( GALLERY_DLG_COLOR
);
97 mpBrowser2
->SetBackground( Wallpaper( GALLERY_DLG_COLOR
) );
98 mpBrowser2
->SetControlBackground( GALLERY_DLG_COLOR
);
99 mpBrowser2
->SetControlForeground( GALLERY_DLG_COLOR
);
101 const Wallpaper
aBackground (sfx2::sidebar::Theme::GetWallpaper(sfx2::sidebar::Theme::Paint_PanelBackground
));
102 mpSplitter
->SetBackground(aBackground
);
103 SetBackground(aBackground
);
104 mpBrowser2
->SetBackground(aBackground
);
107 void GalleryControl::Resize()
113 const Size
aNewSize( GetOutputSizePixel() );
114 if (aNewSize
.Width()<=0 || aNewSize
.Height()<=0)
117 const bool bNewLayoutHorizontal(aNewSize
.Width() > aNewSize
.Height());
118 const bool bOldLayoutHorizontal(mpSplitter
->IsHorizontal());
119 long nSplitPos( bOldLayoutHorizontal
? mpSplitter
->GetPosPixel().X() : mpSplitter
->GetPosPixel().Y());
120 const long nSplitSize( bOldLayoutHorizontal
? mpSplitter
->GetOutputSizePixel().Width() : mpSplitter
->GetOutputSizePixel().Height());
122 if(bNewLayoutHorizontal
!= bOldLayoutHorizontal
)
124 mpSplitter
->SetHorizontal(bNewLayoutHorizontal
);
128 if (mbIsInitialResize
)
130 nSplitPos
= gnInitialVerticalSplitPosition
;
131 if (nSplitPos
> aNewSize
.Height()/2)
132 nSplitPos
= aNewSize
.Height()/2;
135 mbIsInitialResize
= false;
137 const long nFrameLen
= LogicToPixel( Size( 3, 0 ), MAP_APPFONT
).Width();
138 const long nFrameLen2
= nFrameLen
<< 1;
140 if(bNewLayoutHorizontal
)
142 mpBrowser1
->SetPosSizePixel(
143 Point( nFrameLen
, nFrameLen
),
144 Size(nSplitPos
- nFrameLen
, aNewSize
.Height() - nFrameLen2
) );
146 mpSplitter
->SetPosSizePixel(
147 Point( nSplitPos
, 0),
148 Size( nSplitSize
, aNewSize
.Height() ) );
150 mpSplitter
->SetDragRectPixel(
152 Point( nFrameLen2
, 0 ),
153 Size( aNewSize
.Width() - ( nFrameLen2
<< 1 ) - nSplitSize
, aNewSize
.Height() ) ) );
155 mpBrowser2
->SetPosSizePixel(
156 Point( nSplitPos
+ nSplitSize
, nFrameLen
),
157 Size( aNewSize
.Width() - nSplitSize
- nSplitPos
- nFrameLen
, aNewSize
.Height() - nFrameLen2
) );
161 mpBrowser1
->SetPosSizePixel(
162 Point( nFrameLen
, nFrameLen
),
163 Size(aNewSize
.Width() - nFrameLen2
, nSplitPos
- nFrameLen
));
165 mpSplitter
->SetPosSizePixel(
166 Point( 0, nSplitPos
),
167 Size( aNewSize
.Width(), nSplitSize
) );
169 mpSplitter
->SetDragRectPixel(
171 Point( 0, nFrameLen2
),
172 Size( aNewSize
.Width(), aNewSize
.Height() - ( nFrameLen2
<< 1 ) - nSplitSize
) ));
174 mpBrowser2
->SetPosSizePixel(
175 Point( nFrameLen
, nSplitPos
+ nSplitSize
),
176 Size( aNewSize
.Width() - nFrameLen2
, aNewSize
.Height() - nSplitSize
- nSplitPos
- nFrameLen
));
179 maLastSize
= aNewSize
;
182 bool GalleryControl::GalleryKeyInput( const KeyEvent
& rKEvt
, vcl::Window
* )
184 const sal_uInt16 nCode
= rKEvt
.GetKeyCode().GetCode();
185 bool bRet
= ( !rKEvt
.GetKeyCode().IsMod1() &&
186 ( ( KEY_TAB
== nCode
) || ( KEY_F6
== nCode
&& rKEvt
.GetKeyCode().IsMod2() ) ) );
190 if( !rKEvt
.GetKeyCode().IsShift() )
192 if( mpBrowser1
->mpThemes
->HasChildPathFocus( true ) )
193 mpBrowser2
->GetViewWindow()->GrabFocus();
194 else if( mpBrowser2
->GetViewWindow()->HasFocus() )
195 mpBrowser2
->maViewBox
->GrabFocus();
196 else if( mpBrowser2
->maViewBox
->HasFocus() )
197 mpBrowser1
->maNewTheme
->GrabFocus();
199 mpBrowser1
->mpThemes
->GrabFocus();
203 if( mpBrowser1
->mpThemes
->HasChildPathFocus( true ) )
204 mpBrowser1
->maNewTheme
->GrabFocus();
205 else if( mpBrowser1
->maNewTheme
->HasFocus() )
206 mpBrowser2
->maViewBox
->GrabFocus();
207 else if( mpBrowser2
->maViewBox
->HasFocus() )
208 mpBrowser2
->GetViewWindow()->GrabFocus();
210 mpBrowser1
->mpThemes
->GrabFocus();
217 void GalleryControl::GetFocus()
221 mpBrowser1
->GrabFocus();
224 void GalleryControl::ThemeSelectionHasChanged()
226 mpBrowser2
->SelectTheme(mpBrowser1
->GetSelectedTheme());
229 IMPL_LINK_NOARG( GalleryControl
, SplitHdl
)
231 if(mpSplitter
->IsHorizontal())
233 mpSplitter
->SetPosPixel( Point( mpSplitter
->GetSplitPosPixel(), mpSplitter
->GetPosPixel().Y() ) );
237 mpSplitter
->SetPosPixel( Point( mpSplitter
->GetPosPixel().X(), mpSplitter
->GetSplitPosPixel() ) );
246 } } // end of namespace svx::sidebar
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */