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 namespace svx
{ namespace sidebar
{
34 static const sal_Int32
gnInitialVerticalSplitPosition (150);
36 GalleryControl::GalleryControl (
37 vcl::Window
* pParentWindow
)
38 : Window(pParentWindow
, WB_SIZEABLE
|WB_MOVEABLE
|WB_CLOSEABLE
|WB_HIDE
),
39 mpGallery (Gallery::GetGalleryInstance()),
40 mpSplitter(VclPtr
<GallerySplitter
>::Create(
43 [this] () { return this->InitSettings(); })),
44 mpBrowser1(VclPtr
<GalleryBrowser1
>::Create(
47 [this] (KeyEvent
const& rEvent
, vcl::Window
*const /*pWindow*/)
48 { return this->GalleryKeyInput(rEvent
); },
50 { return mpBrowser2
->SelectTheme(mpBrowser1
->GetSelectedTheme()); })),
51 mpBrowser2(VclPtr
<GalleryBrowser2
>::Create(this, mpGallery
)),
52 maLastSize(GetOutputSizePixel()),
53 mbIsInitialResize(true)
55 mpBrowser1
->SelectTheme(0);
60 mpSplitter
->SetHorizontal(false);
61 mpSplitter
->SetSplitHdl( LINK( this, GalleryControl
, SplitHdl
) );
67 GalleryControl::~GalleryControl()
72 void GalleryControl::dispose()
74 mpBrowser2
.disposeAndClear();
75 mpBrowser1
.disposeAndClear();
76 mpSplitter
.disposeAndClear();
77 vcl::Window::dispose();
80 void GalleryControl::InitSettings()
82 SetBackground( Wallpaper( GALLERY_DLG_COLOR
) );
83 SetControlBackground( GALLERY_DLG_COLOR
);
84 SetControlForeground( GALLERY_DLG_COLOR
);
86 mpSplitter
->SetBackground( Wallpaper( GALLERY_DLG_COLOR
) );
87 mpSplitter
->SetControlBackground( GALLERY_DLG_COLOR
);
88 mpSplitter
->SetControlForeground( GALLERY_DLG_COLOR
);
90 mpBrowser1
->SetBackground( Wallpaper( GALLERY_DLG_COLOR
) );
91 mpBrowser1
->SetControlBackground( GALLERY_DLG_COLOR
);
92 mpBrowser1
->SetControlForeground( GALLERY_DLG_COLOR
);
94 mpBrowser2
->SetBackground( Wallpaper( GALLERY_DLG_COLOR
) );
95 mpBrowser2
->SetControlBackground( GALLERY_DLG_COLOR
);
96 mpBrowser2
->SetControlForeground( GALLERY_DLG_COLOR
);
98 const Wallpaper
aBackground (sfx2::sidebar::Theme::GetWallpaper(sfx2::sidebar::Theme::Paint_PanelBackground
));
99 mpSplitter
->SetBackground(aBackground
);
100 SetBackground(aBackground
);
101 mpBrowser2
->SetBackground(aBackground
);
104 void GalleryControl::Resize()
110 const Size
aNewSize( GetOutputSizePixel() );
111 if (aNewSize
.Width()<=0 || aNewSize
.Height()<=0)
114 const bool bNewLayoutHorizontal(aNewSize
.Width() > aNewSize
.Height());
115 const bool bOldLayoutHorizontal(mpSplitter
->IsHorizontal());
116 long nSplitPos( bOldLayoutHorizontal
? mpSplitter
->GetPosPixel().X() : mpSplitter
->GetPosPixel().Y());
117 const long nSplitSize( bOldLayoutHorizontal
? mpSplitter
->GetOutputSizePixel().Width() : mpSplitter
->GetOutputSizePixel().Height());
119 if(bNewLayoutHorizontal
!= bOldLayoutHorizontal
)
121 mpSplitter
->SetHorizontal(bNewLayoutHorizontal
);
125 if (mbIsInitialResize
)
127 nSplitPos
= gnInitialVerticalSplitPosition
;
128 if (nSplitPos
> aNewSize
.Height()/2)
129 nSplitPos
= aNewSize
.Height()/2;
132 mbIsInitialResize
= false;
134 const long nFrameLen
= LogicToPixel( Size( 3, 0 ), MapUnit::MapAppFont
).Width();
135 const long nFrameLen2
= nFrameLen
<< 1;
137 if(bNewLayoutHorizontal
)
139 mpBrowser1
->SetPosSizePixel(
140 Point( nFrameLen
, nFrameLen
),
141 Size(nSplitPos
- nFrameLen
, aNewSize
.Height() - nFrameLen2
) );
143 mpSplitter
->SetPosSizePixel(
144 Point( nSplitPos
, 0),
145 Size( nSplitSize
, aNewSize
.Height() ) );
147 mpSplitter
->SetDragRectPixel(
149 Point( nFrameLen2
, 0 ),
150 Size( aNewSize
.Width() - ( nFrameLen2
<< 1 ) - nSplitSize
, aNewSize
.Height() ) ) );
152 mpBrowser2
->SetPosSizePixel(
153 Point( nSplitPos
+ nSplitSize
, nFrameLen
),
154 Size( aNewSize
.Width() - nSplitSize
- nSplitPos
- nFrameLen
, aNewSize
.Height() - nFrameLen2
) );
158 mpBrowser1
->SetPosSizePixel(
159 Point( nFrameLen
, nFrameLen
),
160 Size(aNewSize
.Width() - nFrameLen2
, nSplitPos
- nFrameLen
));
162 mpSplitter
->SetPosSizePixel(
163 Point( 0, nSplitPos
),
164 Size( aNewSize
.Width(), nSplitSize
) );
166 mpSplitter
->SetDragRectPixel(
168 Point( 0, nFrameLen2
),
169 Size( aNewSize
.Width(), aNewSize
.Height() - ( nFrameLen2
<< 1 ) - nSplitSize
) ));
171 mpBrowser2
->SetPosSizePixel(
172 Point( nFrameLen
, nSplitPos
+ nSplitSize
),
173 Size( aNewSize
.Width() - nFrameLen2
, aNewSize
.Height() - nSplitSize
- nSplitPos
- nFrameLen
));
176 maLastSize
= aNewSize
;
179 bool GalleryControl::GalleryKeyInput( const KeyEvent
& rKEvt
)
181 const sal_uInt16 nCode
= rKEvt
.GetKeyCode().GetCode();
182 bool bRet
= ( !rKEvt
.GetKeyCode().IsMod1() &&
183 ( ( KEY_TAB
== nCode
) || ( KEY_F6
== nCode
&& rKEvt
.GetKeyCode().IsMod2() ) ) );
187 if( !rKEvt
.GetKeyCode().IsShift() )
189 if( mpBrowser1
->mpThemes
->HasChildPathFocus( true ) )
190 mpBrowser2
->GetViewWindow()->GrabFocus();
191 else if( mpBrowser2
->GetViewWindow()->HasFocus() )
192 mpBrowser2
->maViewBox
->GrabFocus();
193 else if( mpBrowser2
->maViewBox
->HasFocus() )
194 mpBrowser1
->maNewTheme
->GrabFocus();
196 mpBrowser1
->mpThemes
->GrabFocus();
200 if( mpBrowser1
->mpThemes
->HasChildPathFocus( true ) )
201 mpBrowser1
->maNewTheme
->GrabFocus();
202 else if( mpBrowser1
->maNewTheme
->HasFocus() )
203 mpBrowser2
->maViewBox
->GrabFocus();
204 else if( mpBrowser2
->maViewBox
->HasFocus() )
205 mpBrowser2
->GetViewWindow()->GrabFocus();
207 mpBrowser1
->mpThemes
->GrabFocus();
214 void GalleryControl::GetFocus()
218 mpBrowser1
->GrabFocus();
221 IMPL_LINK_NOARG( GalleryControl
, SplitHdl
, Splitter
*, void )
223 if(mpSplitter
->IsHorizontal())
225 mpSplitter
->SetPosPixel( Point( mpSplitter
->GetSplitPosPixel(), mpSplitter
->GetPosPixel().Y() ) );
229 mpSplitter
->SetPosPixel( Point( mpSplitter
->GetPosPixel().X(), mpSplitter
->GetSplitPosPixel() ) );
236 } } // end of namespace svx::sidebar
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */