102c50d82SAndre Fischer /**************************************************************
202c50d82SAndre Fischer  *
302c50d82SAndre Fischer  * Licensed to the Apache Software Foundation (ASF) under one
402c50d82SAndre Fischer  * or more contributor license agreements.  See the NOTICE file
502c50d82SAndre Fischer  * distributed with this work for additional information
602c50d82SAndre Fischer  * regarding copyright ownership.  The ASF licenses this file
702c50d82SAndre Fischer  * to you under the Apache License, Version 2.0 (the
802c50d82SAndre Fischer  * "License"); you may not use this file except in compliance
902c50d82SAndre Fischer  * with the License.  You may obtain a copy of the License at
1002c50d82SAndre Fischer  *
1102c50d82SAndre Fischer  *   http://www.apache.org/licenses/LICENSE-2.0
1202c50d82SAndre Fischer  *
1302c50d82SAndre Fischer  * Unless required by applicable law or agreed to in writing,
1402c50d82SAndre Fischer  * software distributed under the License is distributed on an
1502c50d82SAndre Fischer  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1602c50d82SAndre Fischer  * KIND, either express or implied.  See the License for the
1702c50d82SAndre Fischer  * specific language governing permissions and limitations
1802c50d82SAndre Fischer  * under the License.
1902c50d82SAndre Fischer  *
2002c50d82SAndre Fischer  *************************************************************/
2102c50d82SAndre Fischer 
2202c50d82SAndre Fischer #include "sidebar/PanelFactory.hxx"
2302c50d82SAndre Fischer 
2402c50d82SAndre Fischer #include "GalleryControl.hxx"
2502c50d82SAndre Fischer 
2602c50d82SAndre Fischer #include "gallery.hrc"
2702c50d82SAndre Fischer #include "svx/galmisc.hxx"
2802c50d82SAndre Fischer #include "svx/gallery1.hxx"
2902c50d82SAndre Fischer #include "galbrws1.hxx"
3002c50d82SAndre Fischer #include "galbrws2.hxx"
3102c50d82SAndre Fischer #include "GallerySplitter.hxx"
3202c50d82SAndre Fischer #include <vcl/svapp.hxx>
3337fee4fdSAndre Fischer #include <sfx2/sidebar/Theme.hxx>
3402c50d82SAndre Fischer 
3502c50d82SAndre Fischer #include <boost/bind.hpp>
3602c50d82SAndre Fischer 
3702c50d82SAndre Fischer namespace svx { namespace sidebar {
3802c50d82SAndre Fischer 
39a8eaca58SAndre Fischer static const sal_Int32 gnInitialVerticalSplitPosition (150);
40a8eaca58SAndre Fischer 
41a8eaca58SAndre Fischer 
GalleryControl(SfxBindings *,Window * pParentWindow)4202c50d82SAndre Fischer GalleryControl::GalleryControl (
43*600f296aSPavel Janík     SfxBindings* /* pBindings */,
4402c50d82SAndre Fischer     Window* pParentWindow)
4502c50d82SAndre Fischer     : Window(pParentWindow, GAL_RESID(RID_SVXDLG_GALLERYBROWSER)),
4602c50d82SAndre Fischer       mpGallery (Gallery::GetGalleryInstance()),
47*600f296aSPavel Janík       mpSplitter(new GallerySplitter(
48*600f296aSPavel Janík               this,
49*600f296aSPavel Janík               GAL_RESID(GALLERY_SPLITTER),
50*600f296aSPavel Janík               ::boost::bind(&GalleryControl::InitSettings, this))),
5102c50d82SAndre Fischer       mpBrowser1(new GalleryBrowser1(
5202c50d82SAndre Fischer               this,
5302c50d82SAndre Fischer               GAL_RESID(GALLERY_BROWSER1),
5402c50d82SAndre Fischer               mpGallery,
5502c50d82SAndre Fischer               ::boost::bind(&GalleryControl::KeyInput,this,_1,_2),
5602c50d82SAndre Fischer               ::boost::bind(&GalleryControl::ThemeSelectionHasChanged, this))),
5702c50d82SAndre Fischer       mpBrowser2(new GalleryBrowser2(this, GAL_RESID(GALLERY_BROWSER2), mpGallery)),
58a8eaca58SAndre Fischer       maLastSize(GetOutputSizePixel()),
59a8eaca58SAndre Fischer       mbIsInitialResize(true)
6002c50d82SAndre Fischer {
6102c50d82SAndre Fischer     FreeResource();
62a8eaca58SAndre Fischer 
6302c50d82SAndre Fischer     mpBrowser1->SelectTheme(0);
6402c50d82SAndre Fischer     mpBrowser1->Show(sal_True);
65a8eaca58SAndre Fischer 
6602c50d82SAndre Fischer     mpBrowser2->Show(sal_True);
6702c50d82SAndre Fischer 
68a8eaca58SAndre Fischer     mpSplitter->SetHorizontal(false);
6902c50d82SAndre Fischer 	mpSplitter->SetSplitHdl( LINK( this, GalleryControl, SplitHdl ) );
7002c50d82SAndre Fischer 	mpSplitter->Show( sal_True );
7102c50d82SAndre Fischer 
7202c50d82SAndre Fischer     InitSettings();
7302c50d82SAndre Fischer }
7402c50d82SAndre Fischer 
7502c50d82SAndre Fischer 
7602c50d82SAndre Fischer 
7702c50d82SAndre Fischer 
~GalleryControl(void)7802c50d82SAndre Fischer GalleryControl::~GalleryControl (void)
7902c50d82SAndre Fischer {
8002c50d82SAndre Fischer }
8102c50d82SAndre Fischer 
8202c50d82SAndre Fischer 
8302c50d82SAndre Fischer 
8402c50d82SAndre Fischer 
InitSettings(void)8502c50d82SAndre Fischer void GalleryControl::InitSettings (void)
8602c50d82SAndre Fischer {
8702c50d82SAndre Fischer 	SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
8802c50d82SAndre Fischer 	SetControlBackground( GALLERY_DLG_COLOR );
8902c50d82SAndre Fischer 	SetControlForeground( GALLERY_DLG_COLOR );
9002c50d82SAndre Fischer 
9102c50d82SAndre Fischer 	mpSplitter->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
9202c50d82SAndre Fischer 	mpSplitter->SetControlBackground( GALLERY_DLG_COLOR );
9302c50d82SAndre Fischer 	mpSplitter->SetControlForeground( GALLERY_DLG_COLOR );
9402c50d82SAndre Fischer 
9502c50d82SAndre Fischer 	mpBrowser1->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
9602c50d82SAndre Fischer 	mpBrowser1->SetControlBackground( GALLERY_DLG_COLOR );
9702c50d82SAndre Fischer 	mpBrowser1->SetControlForeground( GALLERY_DLG_COLOR );
9802c50d82SAndre Fischer 
9902c50d82SAndre Fischer 	mpBrowser2->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
10002c50d82SAndre Fischer 	mpBrowser2->SetControlBackground( GALLERY_DLG_COLOR );
10102c50d82SAndre Fischer 	mpBrowser2->SetControlForeground( GALLERY_DLG_COLOR );
10237fee4fdSAndre Fischer 
10337fee4fdSAndre Fischer     const Wallpaper aBackground (sfx2::sidebar::Theme::GetWallpaper(sfx2::sidebar::Theme::Paint_PanelBackground));
10437fee4fdSAndre Fischer 	mpSplitter->SetBackground(aBackground);
10537fee4fdSAndre Fischer 	SetBackground(aBackground);
10637fee4fdSAndre Fischer 	mpBrowser2->SetBackground(aBackground);
10702c50d82SAndre Fischer }
10802c50d82SAndre Fischer 
10902c50d82SAndre Fischer 
11002c50d82SAndre Fischer 
11102c50d82SAndre Fischer 
Resize(void)11202c50d82SAndre Fischer void GalleryControl::Resize (void)
11302c50d82SAndre Fischer {
11402c50d82SAndre Fischer     // call parent
11502c50d82SAndre Fischer     Window::Resize();
11602c50d82SAndre Fischer 
11702c50d82SAndre Fischer     // update hor/ver
11802c50d82SAndre Fischer     const Size aNewSize( GetOutputSizePixel() );
119a8eaca58SAndre Fischer     if (aNewSize.Width()<=0 || aNewSize.Height()<=0)
120a8eaca58SAndre Fischer         return;
121a8eaca58SAndre Fischer 
12202c50d82SAndre Fischer     const bool bNewLayoutHorizontal(aNewSize.Width() > aNewSize.Height());
12302c50d82SAndre Fischer     const bool bOldLayoutHorizontal(mpSplitter->IsHorizontal());
124a8eaca58SAndre Fischer     long nSplitPos( bOldLayoutHorizontal ? mpSplitter->GetPosPixel().X() : mpSplitter->GetPosPixel().Y());
12502c50d82SAndre Fischer     const long nSplitSize( bOldLayoutHorizontal ? mpSplitter->GetOutputSizePixel().Width() : mpSplitter->GetOutputSizePixel().Height());
12602c50d82SAndre Fischer 
12702c50d82SAndre Fischer     if(bNewLayoutHorizontal != bOldLayoutHorizontal)
12802c50d82SAndre Fischer     {
12902c50d82SAndre Fischer         mpSplitter->SetHorizontal(bNewLayoutHorizontal);
13002c50d82SAndre Fischer     }
131a8eaca58SAndre Fischer     else
132a8eaca58SAndre Fischer     {
133a8eaca58SAndre Fischer         if (mbIsInitialResize)
134a8eaca58SAndre Fischer         {
135a8eaca58SAndre Fischer             nSplitPos = gnInitialVerticalSplitPosition;
136a8eaca58SAndre Fischer             if (nSplitPos > aNewSize.Height()/2)
137a8eaca58SAndre Fischer                 nSplitPos = aNewSize.Height()/2;
138a8eaca58SAndre Fischer         }
139a8eaca58SAndre Fischer     }
140a8eaca58SAndre Fischer     mbIsInitialResize = false;
14102c50d82SAndre Fischer 
14202c50d82SAndre Fischer     const long nFrameLen = LogicToPixel( Size( 3, 0 ), MAP_APPFONT ).Width();
14302c50d82SAndre Fischer     const long nFrameLen2 = nFrameLen << 1;
14402c50d82SAndre Fischer 
14502c50d82SAndre Fischer     if(bNewLayoutHorizontal)
14602c50d82SAndre Fischer     {
14702c50d82SAndre Fischer         mpBrowser1->SetPosSizePixel(
14802c50d82SAndre Fischer             Point( nFrameLen, nFrameLen ),
14902c50d82SAndre Fischer             Size(nSplitPos - nFrameLen, aNewSize.Height() - nFrameLen2) );
15002c50d82SAndre Fischer 
15102c50d82SAndre Fischer         mpSplitter->SetPosSizePixel(
15202c50d82SAndre Fischer             Point( nSplitPos, 0),
15302c50d82SAndre Fischer             Size( nSplitSize, aNewSize.Height() ) );
15402c50d82SAndre Fischer 
15502c50d82SAndre Fischer         mpSplitter->SetDragRectPixel(
15602c50d82SAndre Fischer             Rectangle(
15702c50d82SAndre Fischer                 Point( nFrameLen2, 0 ),
15802c50d82SAndre Fischer                 Size( aNewSize.Width() - ( nFrameLen2 << 1 ) - nSplitSize, aNewSize.Height() ) ) );
15902c50d82SAndre Fischer 
16002c50d82SAndre Fischer         mpBrowser2->SetPosSizePixel(
16102c50d82SAndre Fischer             Point( nSplitPos + nSplitSize, nFrameLen ),
16202c50d82SAndre Fischer             Size( aNewSize.Width() - nSplitSize - nSplitPos - nFrameLen, aNewSize.Height() - nFrameLen2 ) );
16302c50d82SAndre Fischer     }
16402c50d82SAndre Fischer     else
16502c50d82SAndre Fischer     {
16602c50d82SAndre Fischer         mpBrowser1->SetPosSizePixel(
16702c50d82SAndre Fischer             Point( nFrameLen, nFrameLen ),
16802c50d82SAndre Fischer             Size(aNewSize.Width() - nFrameLen2, nSplitPos - nFrameLen));
16902c50d82SAndre Fischer 
17002c50d82SAndre Fischer         mpSplitter->SetPosSizePixel(
17102c50d82SAndre Fischer             Point( 0, nSplitPos),
17202c50d82SAndre Fischer             Size( aNewSize.Width(), nSplitSize ) );
17302c50d82SAndre Fischer 
17402c50d82SAndre Fischer         mpSplitter->SetDragRectPixel(
17502c50d82SAndre Fischer             Rectangle(
17602c50d82SAndre Fischer                 Point( 0, nFrameLen2 ),
17702c50d82SAndre Fischer                 Size( aNewSize.Width(), aNewSize.Height() - ( nFrameLen2 << 1 ) - nSplitSize ) ));
17802c50d82SAndre Fischer 
17902c50d82SAndre Fischer         mpBrowser2->SetPosSizePixel(
18002c50d82SAndre Fischer             Point( nFrameLen, nSplitPos + nSplitSize ),
18102c50d82SAndre Fischer             Size( aNewSize.Width() - nFrameLen2, aNewSize.Height() - nSplitSize - nSplitPos - nFrameLen ));
18202c50d82SAndre Fischer     }
18302c50d82SAndre Fischer 
18402c50d82SAndre Fischer     maLastSize = aNewSize;
18502c50d82SAndre Fischer }
18602c50d82SAndre Fischer 
18702c50d82SAndre Fischer 
18802c50d82SAndre Fischer 
18902c50d82SAndre Fischer 
KeyInput(const KeyEvent & rKEvt,Window *)19002c50d82SAndre Fischer sal_Bool GalleryControl::KeyInput( const KeyEvent& rKEvt, Window* )
19102c50d82SAndre Fischer {
19202c50d82SAndre Fischer     const sal_uInt16    nCode = rKEvt.GetKeyCode().GetCode();
19302c50d82SAndre Fischer     sal_Bool            bRet = ( !rKEvt.GetKeyCode().IsMod1() &&
19402c50d82SAndre Fischer                            ( ( KEY_TAB == nCode ) || ( KEY_F6 == nCode && rKEvt.GetKeyCode().IsMod2() ) ) );
19502c50d82SAndre Fischer 
19602c50d82SAndre Fischer     if( bRet )
19702c50d82SAndre Fischer     {
19802c50d82SAndre Fischer         if( !rKEvt.GetKeyCode().IsShift() )
19902c50d82SAndre Fischer         {
20002c50d82SAndre Fischer             if( mpBrowser1->mpThemes->HasChildPathFocus( sal_True ) )
20102c50d82SAndre Fischer                 mpBrowser2->GetViewWindow()->GrabFocus();
20202c50d82SAndre Fischer             else if( mpBrowser2->GetViewWindow()->HasFocus() )
20302c50d82SAndre Fischer                 mpBrowser2->maViewBox.GrabFocus();
20402c50d82SAndre Fischer             else if( mpBrowser2->maViewBox.HasFocus() )
20502c50d82SAndre Fischer                 mpBrowser1->maNewTheme.GrabFocus();
20602c50d82SAndre Fischer             else
20702c50d82SAndre Fischer                 mpBrowser1->mpThemes->GrabFocus();
20802c50d82SAndre Fischer         }
20902c50d82SAndre Fischer         else
21002c50d82SAndre Fischer         {
21102c50d82SAndre Fischer             if( mpBrowser1->mpThemes->HasChildPathFocus( sal_True ) )
21202c50d82SAndre Fischer                 mpBrowser1->maNewTheme.GrabFocus();
21302c50d82SAndre Fischer             else if( mpBrowser1->maNewTheme.HasFocus() )
21402c50d82SAndre Fischer                 mpBrowser2->maViewBox.GrabFocus();
21502c50d82SAndre Fischer             else if( mpBrowser2->maViewBox.HasFocus() )
21602c50d82SAndre Fischer                 mpBrowser2->GetViewWindow()->GrabFocus();
21702c50d82SAndre Fischer             else
21802c50d82SAndre Fischer                 mpBrowser1->mpThemes->GrabFocus();
21902c50d82SAndre Fischer         }
22002c50d82SAndre Fischer     }
22102c50d82SAndre Fischer 
22202c50d82SAndre Fischer     return bRet;
22302c50d82SAndre Fischer }
22402c50d82SAndre Fischer 
22502c50d82SAndre Fischer 
22602c50d82SAndre Fischer 
22702c50d82SAndre Fischer 
GetFocus(void)22802c50d82SAndre Fischer void GalleryControl::GetFocus (void)
22902c50d82SAndre Fischer {
23002c50d82SAndre Fischer 	Window::GetFocus();
23102c50d82SAndre Fischer 	mpBrowser1->GrabFocus();
23202c50d82SAndre Fischer }
23302c50d82SAndre Fischer 
23402c50d82SAndre Fischer 
23502c50d82SAndre Fischer 
23602c50d82SAndre Fischer 
ThemeSelectionHasChanged(void)23702c50d82SAndre Fischer void GalleryControl::ThemeSelectionHasChanged (void)
23802c50d82SAndre Fischer {
23902c50d82SAndre Fischer 	mpBrowser2->SelectTheme(mpBrowser1->GetSelectedTheme());
24002c50d82SAndre Fischer }
24102c50d82SAndre Fischer 
24202c50d82SAndre Fischer 
IMPL_LINK(GalleryControl,SplitHdl,void *,EMPTYARG)24302c50d82SAndre Fischer IMPL_LINK( GalleryControl, SplitHdl, void*, EMPTYARG )
24402c50d82SAndre Fischer {
24502c50d82SAndre Fischer     if(mpSplitter->IsHorizontal())
24602c50d82SAndre Fischer     {
24702c50d82SAndre Fischer         mpSplitter->SetPosPixel( Point( mpSplitter->GetSplitPosPixel(), mpSplitter->GetPosPixel().Y() ) );
24802c50d82SAndre Fischer     }
24902c50d82SAndre Fischer     else
25002c50d82SAndre Fischer     {
25102c50d82SAndre Fischer         mpSplitter->SetPosPixel( Point( mpSplitter->GetPosPixel().X(), mpSplitter->GetSplitPosPixel() ) );
25202c50d82SAndre Fischer     }
25302c50d82SAndre Fischer 
25402c50d82SAndre Fischer     Resize();
25502c50d82SAndre Fischer 
25602c50d82SAndre Fischer 	return 0L;
25702c50d82SAndre Fischer }
25802c50d82SAndre Fischer 
25902c50d82SAndre Fischer 
26002c50d82SAndre Fischer } } // end of namespace svx::sidebar
261