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 <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(
42 [this] () { return this->InitSettings(); })),
43 mpBrowser1(VclPtr
<GalleryBrowser1
>::Create(
46 [this] (KeyEvent
const& rEvent
, vcl::Window
*const /*pWindow*/)
47 { return this->GalleryKeyInput(rEvent
); },
49 { return mpBrowser2
->SelectTheme(mpBrowser1
->GetSelectedTheme()); })),
50 mpBrowser2(VclPtr
<GalleryBrowser2
>::Create(this, mpGallery
)),
51 mbIsInitialResize(true)
53 mpBrowser1
->SelectTheme(0);
58 mpSplitter
->SetHorizontal(false);
59 mpSplitter
->SetSplitHdl( LINK( this, GalleryControl
, SplitHdl
) );
65 GalleryControl::~GalleryControl()
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()
108 const Size
aNewSize( GetOutputSizePixel() );
109 if (aNewSize
.Width()<=0 || aNewSize
.Height()<=0)
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
);
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(
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
) );
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(
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() ) ) );
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();
193 if( mpBrowser1
->maNewTheme
->IsEnabled() )
194 mpBrowser1
->maNewTheme
->GrabFocus();
196 mpBrowser1
->mpThemes
->GrabFocus();
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();
210 mpBrowser2
->GetViewWindow()->GrabFocus();
213 mpBrowser2
->GetViewWindow()->GrabFocus();
220 void GalleryControl::GetFocus()
224 mpBrowser1
->GrabFocus();
227 IMPL_LINK_NOARG( GalleryControl
, SplitHdl
, Splitter
*, void )
229 if(mpSplitter
->IsHorizontal())
231 mpSplitter
->SetPosPixel( Point( mpSplitter
->GetSplitPosPixel(), mpSplitter
->GetPosPixel().Y() ) );
235 mpSplitter
->SetPosPixel( Point( mpSplitter
->GetPosPixel().X(), mpSplitter
->GetSplitPosPixel() ) );
242 } } // end of namespace svx::sidebar
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */