xref: /aoo41x/main/svx/source/gallery2/galbrws.cxx (revision 02c50d82)
1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10f6e50924SAndrew Rist  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12f6e50924SAndrew Rist  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19f6e50924SAndrew Rist  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_svx.hxx"
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include <vcl/split.hxx>
26cdf0e10cSrcweir #include <vcl/ctrl.hxx>
27cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
28cdf0e10cSrcweir #include <sfx2/app.hxx>
29cdf0e10cSrcweir #include <sfx2/sfxsids.hrc>
30cdf0e10cSrcweir #include "gallery.hrc"
31cdf0e10cSrcweir #include "svx/galmisc.hxx"
32cdf0e10cSrcweir #include "svx/gallery1.hxx"
33cdf0e10cSrcweir #include "galbrws1.hxx"
34cdf0e10cSrcweir #include "galbrws2.hxx"
35cdf0e10cSrcweir #include "svx/galbrws.hxx"
36*02c50d82SAndre Fischer #include "GallerySplitter.hxx"
37cdf0e10cSrcweir 
38*02c50d82SAndre Fischer #include <boost/bind.hpp>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir // -------------------------
41cdf0e10cSrcweir // - SvxGalleryChildWindow -
42cdf0e10cSrcweir // -------------------------
43cdf0e10cSrcweir DBG_NAME(GalleryChildWindow)
44cdf0e10cSrcweir 
45cdf0e10cSrcweir GalleryChildWindow::GalleryChildWindow( Window* _pParent, sal_uInt16 nId, SfxBindings* pBindings, SfxChildWinInfo* pInfo ) :
46cdf0e10cSrcweir 	SfxChildWindow( _pParent, nId )
47cdf0e10cSrcweir {
48cdf0e10cSrcweir     DBG_CTOR(GalleryChildWindow,NULL);
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 	pWindow = new GalleryBrowser( pBindings, this, _pParent, GAL_RESID( RID_SVXDLG_GALLERYBROWSER ) );
51cdf0e10cSrcweir 	eChildAlignment = SFX_ALIGN_TOP;
52cdf0e10cSrcweir 	( (GalleryBrowser*) pWindow )->Initialize( pInfo );
53cdf0e10cSrcweir };
54cdf0e10cSrcweir 
55cdf0e10cSrcweir // -----------------------------------------------------------------------------
56cdf0e10cSrcweir 
57cdf0e10cSrcweir GalleryChildWindow::~GalleryChildWindow()
58cdf0e10cSrcweir {
59cdf0e10cSrcweir 
60cdf0e10cSrcweir     DBG_DTOR(GalleryChildWindow,NULL);
61cdf0e10cSrcweir }
62cdf0e10cSrcweir 
63cdf0e10cSrcweir // -----------------------------------------------------------------------------
64cdf0e10cSrcweir 
65cdf0e10cSrcweir SFX_IMPL_DOCKINGWINDOW( GalleryChildWindow, SID_GALLERY )
66cdf0e10cSrcweir 
67cdf0e10cSrcweir // ------------------
68cdf0e10cSrcweir // - GalleryBrowser -
69cdf0e10cSrcweir // ------------------
70cdf0e10cSrcweir DBG_NAME(GalleryBrowser)
71cdf0e10cSrcweir 
7245fc0049SArmin Le Grand GalleryBrowser::GalleryBrowser(
7345fc0049SArmin Le Grand     SfxBindings* _pBindings,
7445fc0049SArmin Le Grand     SfxChildWindow* pCW,
7545fc0049SArmin Le Grand     Window* pParent,
7645fc0049SArmin Le Grand     const ResId& rResId)
7745fc0049SArmin Le Grand :   SfxDockingWindow(_pBindings, pCW, pParent, rResId),
7845fc0049SArmin Le Grand     maLastSize(GetOutputSizePixel()),
7945fc0049SArmin Le Grand     mpSplitter(0),
8045fc0049SArmin Le Grand     mpBrowser1(0),
8145fc0049SArmin Le Grand     mpBrowser2(0),
8245fc0049SArmin Le Grand     mpGallery(0)
83cdf0e10cSrcweir {
84cdf0e10cSrcweir     DBG_CTOR(GalleryBrowser,NULL);
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	mpGallery = Gallery::GetGalleryInstance();
87*02c50d82SAndre Fischer 	mpBrowser1 = new GalleryBrowser1(
88*02c50d82SAndre Fischer         this,
89*02c50d82SAndre Fischer         GAL_RESID( GALLERY_BROWSER1 ),
90*02c50d82SAndre Fischer         mpGallery,
91*02c50d82SAndre Fischer         ::boost::bind(&GalleryBrowser::KeyInput,this,_1,_2),
92*02c50d82SAndre Fischer         ::boost::bind(&GalleryBrowser::ThemeSelectionHasChanged, this));
93*02c50d82SAndre Fischer 	mpSplitter = new GallerySplitter( this, GAL_RESID( GALLERY_SPLITTER ),
94*02c50d82SAndre Fischer         ::boost::bind(&GalleryBrowser::InitSettings, this));
95cdf0e10cSrcweir 	mpBrowser2 = new GalleryBrowser2( this, GAL_RESID( GALLERY_BROWSER2 ), mpGallery );
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 	FreeResource();
9845fc0049SArmin Le Grand 	SetMinOutputSizePixel(maLastSize);
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 	mpBrowser1->SelectTheme( 0 );
101cdf0e10cSrcweir 	mpBrowser1->Show( sal_True );
102cdf0e10cSrcweir 	mpBrowser2->Show( sal_True );
103cdf0e10cSrcweir 
10445fc0049SArmin Le Grand     const bool bLayoutHorizontal(maLastSize.Width() > maLastSize.Height());
10545fc0049SArmin Le Grand     mpSplitter->SetHorizontal(bLayoutHorizontal);
106cdf0e10cSrcweir 	mpSplitter->SetSplitHdl( LINK( this, GalleryBrowser, SplitHdl ) );
107cdf0e10cSrcweir 	mpSplitter->Show( sal_True );
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     InitSettings();
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir // -----------------------------------------------------------------------------
113cdf0e10cSrcweir 
114cdf0e10cSrcweir GalleryBrowser::~GalleryBrowser()
115cdf0e10cSrcweir {
116cdf0e10cSrcweir 	delete mpBrowser2;
117cdf0e10cSrcweir 	delete mpSplitter;
118cdf0e10cSrcweir 	delete mpBrowser1;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir     DBG_DTOR(GalleryBrowser,NULL);
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir // -----------------------------------------------------------------------------
124cdf0e10cSrcweir 
125cdf0e10cSrcweir void GalleryBrowser::InitSettings()
126cdf0e10cSrcweir {
127cdf0e10cSrcweir 	SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
128cdf0e10cSrcweir 	SetControlBackground( GALLERY_DLG_COLOR );
129cdf0e10cSrcweir 	SetControlForeground( GALLERY_DLG_COLOR );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 	mpSplitter->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
132cdf0e10cSrcweir 	mpSplitter->SetControlBackground( GALLERY_DLG_COLOR );
133cdf0e10cSrcweir 	mpSplitter->SetControlForeground( GALLERY_DLG_COLOR );
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 	mpBrowser1->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
136cdf0e10cSrcweir 	mpBrowser1->SetControlBackground( GALLERY_DLG_COLOR );
137cdf0e10cSrcweir 	mpBrowser1->SetControlForeground( GALLERY_DLG_COLOR );
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 	mpBrowser2->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
140cdf0e10cSrcweir 	mpBrowser2->SetControlBackground( GALLERY_DLG_COLOR );
141cdf0e10cSrcweir 	mpBrowser2->SetControlForeground( GALLERY_DLG_COLOR );
142cdf0e10cSrcweir }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir // -----------------------------------------------------------------------------
145cdf0e10cSrcweir 
146cdf0e10cSrcweir void GalleryBrowser::Resize()
147cdf0e10cSrcweir {
14845fc0049SArmin Le Grand     // call parent
14945fc0049SArmin Le Grand     SfxDockingWindow::Resize();
150cdf0e10cSrcweir 
15145fc0049SArmin Le Grand     // update hor/ver
15245fc0049SArmin Le Grand     const Size aNewSize( GetOutputSizePixel() );
15345fc0049SArmin Le Grand     const bool bNewLayoutHorizontal(aNewSize.Width() > aNewSize.Height());
15445fc0049SArmin Le Grand     const bool bOldLayoutHorizontal(mpSplitter->IsHorizontal());
15545fc0049SArmin Le Grand     const long nSplitPos( bOldLayoutHorizontal ? mpSplitter->GetPosPixel().X() : mpSplitter->GetPosPixel().Y());
15645fc0049SArmin Le Grand     const long nSplitSize( bOldLayoutHorizontal ? mpSplitter->GetOutputSizePixel().Width() : mpSplitter->GetOutputSizePixel().Height());
157cdf0e10cSrcweir 
15845fc0049SArmin Le Grand     if(bNewLayoutHorizontal != bOldLayoutHorizontal)
15945fc0049SArmin Le Grand     {
16045fc0049SArmin Le Grand         mpSplitter->SetHorizontal(bNewLayoutHorizontal);
16145fc0049SArmin Le Grand     }
162cdf0e10cSrcweir 
16345fc0049SArmin Le Grand     const long nFrameLen = LogicToPixel( Size( 3, 0 ), MAP_APPFONT ).Width();
16445fc0049SArmin Le Grand     const long nFrameLen2 = nFrameLen << 1;
165cdf0e10cSrcweir 
16645fc0049SArmin Le Grand     if(bNewLayoutHorizontal)
16745fc0049SArmin Le Grand     {
16845fc0049SArmin Le Grand         mpBrowser1->SetPosSizePixel(
16945fc0049SArmin Le Grand             Point( nFrameLen, nFrameLen ),
17045fc0049SArmin Le Grand             Size(nSplitPos - nFrameLen, aNewSize.Height() - nFrameLen2) );
17145fc0049SArmin Le Grand 
17245fc0049SArmin Le Grand         mpSplitter->SetPosSizePixel(
17345fc0049SArmin Le Grand             Point( nSplitPos, 0),
17445fc0049SArmin Le Grand             Size( nSplitSize, aNewSize.Height() ) );
17545fc0049SArmin Le Grand 
17645fc0049SArmin Le Grand         mpSplitter->SetDragRectPixel(
17745fc0049SArmin Le Grand             Rectangle(
17845fc0049SArmin Le Grand                 Point( nFrameLen2, 0 ),
17945fc0049SArmin Le Grand                 Size( aNewSize.Width() - ( nFrameLen2 << 1 ) - nSplitSize, aNewSize.Height() ) ) );
18045fc0049SArmin Le Grand 
18145fc0049SArmin Le Grand         mpBrowser2->SetPosSizePixel(
18245fc0049SArmin Le Grand             Point( nSplitPos + nSplitSize, nFrameLen ),
18345fc0049SArmin Le Grand             Size( aNewSize.Width() - nSplitSize - nSplitPos - nFrameLen, aNewSize.Height() - nFrameLen2 ) );
18445fc0049SArmin Le Grand     }
18545fc0049SArmin Le Grand     else
18645fc0049SArmin Le Grand     {
18745fc0049SArmin Le Grand         mpBrowser1->SetPosSizePixel(
18845fc0049SArmin Le Grand             Point( nFrameLen, nFrameLen ),
18945fc0049SArmin Le Grand             Size(aNewSize.Width() - nFrameLen2, nSplitPos - nFrameLen));
19045fc0049SArmin Le Grand 
19145fc0049SArmin Le Grand         mpSplitter->SetPosSizePixel(
19245fc0049SArmin Le Grand             Point( 0, nSplitPos),
19345fc0049SArmin Le Grand             Size( aNewSize.Width(), nSplitSize ) );
19445fc0049SArmin Le Grand 
19545fc0049SArmin Le Grand         mpSplitter->SetDragRectPixel(
19645fc0049SArmin Le Grand             Rectangle(
19745fc0049SArmin Le Grand                 Point( 0, nFrameLen2 ),
19845fc0049SArmin Le Grand                 Size( aNewSize.Width(), aNewSize.Height() - ( nFrameLen2 << 1 ) - nSplitSize ) ));
19945fc0049SArmin Le Grand 
20045fc0049SArmin Le Grand         mpBrowser2->SetPosSizePixel(
20145fc0049SArmin Le Grand             Point( nFrameLen, nSplitPos + nSplitSize ),
20245fc0049SArmin Le Grand             Size( aNewSize.Width() - nFrameLen2, aNewSize.Height() - nSplitSize - nSplitPos - nFrameLen ));
20345fc0049SArmin Le Grand     }
204cdf0e10cSrcweir 
20545fc0049SArmin Le Grand     maLastSize = aNewSize;
206cdf0e10cSrcweir }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir // -----------------------------------------------------------------------------
209cdf0e10cSrcweir 
210cdf0e10cSrcweir sal_Bool GalleryBrowser::KeyInput( const KeyEvent& rKEvt, Window* )
211cdf0e10cSrcweir {
212cdf0e10cSrcweir     const sal_uInt16    nCode = rKEvt.GetKeyCode().GetCode();
213cdf0e10cSrcweir     sal_Bool            bRet = ( !rKEvt.GetKeyCode().IsMod1() &&
214cdf0e10cSrcweir                            ( ( KEY_TAB == nCode ) || ( KEY_F6 == nCode && rKEvt.GetKeyCode().IsMod2() ) ) );
215cdf0e10cSrcweir 
216cdf0e10cSrcweir     if( bRet )
217cdf0e10cSrcweir     {
218cdf0e10cSrcweir         if( !rKEvt.GetKeyCode().IsShift() )
219cdf0e10cSrcweir         {
220cdf0e10cSrcweir             if( mpBrowser1->mpThemes->HasChildPathFocus( sal_True ) )
221cdf0e10cSrcweir                 mpBrowser2->GetViewWindow()->GrabFocus();
222cdf0e10cSrcweir             else if( mpBrowser2->GetViewWindow()->HasFocus() )
223cdf0e10cSrcweir                 mpBrowser2->maViewBox.GrabFocus();
224cdf0e10cSrcweir             else if( mpBrowser2->maViewBox.HasFocus() )
225cdf0e10cSrcweir                 mpBrowser1->maNewTheme.GrabFocus();
226cdf0e10cSrcweir             else
227cdf0e10cSrcweir                 mpBrowser1->mpThemes->GrabFocus();
228cdf0e10cSrcweir         }
229cdf0e10cSrcweir         else
230cdf0e10cSrcweir         {
231cdf0e10cSrcweir             if( mpBrowser1->mpThemes->HasChildPathFocus( sal_True ) )
232cdf0e10cSrcweir                 mpBrowser1->maNewTheme.GrabFocus();
233cdf0e10cSrcweir             else if( mpBrowser1->maNewTheme.HasFocus() )
234cdf0e10cSrcweir                 mpBrowser2->maViewBox.GrabFocus();
235cdf0e10cSrcweir             else if( mpBrowser2->maViewBox.HasFocus() )
236cdf0e10cSrcweir                 mpBrowser2->GetViewWindow()->GrabFocus();
237cdf0e10cSrcweir             else
238cdf0e10cSrcweir                 mpBrowser1->mpThemes->GrabFocus();
239cdf0e10cSrcweir         }
240cdf0e10cSrcweir     }
241cdf0e10cSrcweir 
242cdf0e10cSrcweir     return bRet;
243cdf0e10cSrcweir }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir // -----------------------------------------------------------------------------
246cdf0e10cSrcweir 
247cdf0e10cSrcweir sal_Bool GalleryBrowser::Close()
248cdf0e10cSrcweir {
249cdf0e10cSrcweir 	return SfxDockingWindow::Close();
250cdf0e10cSrcweir }
251cdf0e10cSrcweir 
252cdf0e10cSrcweir // -----------------------------------------------------------------------------
253cdf0e10cSrcweir 
254cdf0e10cSrcweir void GalleryBrowser::GetFocus()
255cdf0e10cSrcweir {
256cdf0e10cSrcweir 	SfxDockingWindow::GetFocus();
257cdf0e10cSrcweir 	mpBrowser1->GrabFocus();
258cdf0e10cSrcweir }
259cdf0e10cSrcweir 
260cdf0e10cSrcweir // -----------------------------------------------------------------------------
261cdf0e10cSrcweir 
262cdf0e10cSrcweir void GalleryBrowser::ThemeSelectionHasChanged()
263cdf0e10cSrcweir {
264cdf0e10cSrcweir 	mpBrowser2->SelectTheme( mpBrowser1->GetSelectedTheme() );
265cdf0e10cSrcweir }
266cdf0e10cSrcweir 
267cdf0e10cSrcweir // -----------------------------------------------------------------------------
268cdf0e10cSrcweir 
269cdf0e10cSrcweir INetURLObject GalleryBrowser::GetURL() const
270cdf0e10cSrcweir {
271cdf0e10cSrcweir 	return mpBrowser2->GetURL();
272cdf0e10cSrcweir }
273cdf0e10cSrcweir 
274cdf0e10cSrcweir // -----------------------------------------------------------------------------
275cdf0e10cSrcweir 
276cdf0e10cSrcweir String GalleryBrowser::GetFilterName() const
277cdf0e10cSrcweir {
278cdf0e10cSrcweir 	return mpBrowser2->GetFilterName();
279cdf0e10cSrcweir }
280cdf0e10cSrcweir 
281cdf0e10cSrcweir // -----------------------------------------------------------------------------
282cdf0e10cSrcweir 
283cdf0e10cSrcweir Graphic GalleryBrowser::GetGraphic() const
284cdf0e10cSrcweir {
285cdf0e10cSrcweir 	return mpBrowser2->GetGraphic();
286cdf0e10cSrcweir }
287cdf0e10cSrcweir 
288cdf0e10cSrcweir // -----------------------------------------------------------------------------
289cdf0e10cSrcweir 
290cdf0e10cSrcweir sal_Bool GalleryBrowser::GetVCDrawModel( FmFormModel& rModel ) const
291cdf0e10cSrcweir {
292cdf0e10cSrcweir 	return mpBrowser2->GetVCDrawModel( rModel );
293cdf0e10cSrcweir }
294cdf0e10cSrcweir 
295cdf0e10cSrcweir // -----------------------------------------------------------------------------
296cdf0e10cSrcweir 
297cdf0e10cSrcweir sal_Bool GalleryBrowser::IsLinkage() const
298cdf0e10cSrcweir {
299cdf0e10cSrcweir 	return mpBrowser2->IsLinkage();
300cdf0e10cSrcweir }
301cdf0e10cSrcweir 
302cdf0e10cSrcweir // -----------------------------------------------------------------------------
303cdf0e10cSrcweir 
304cdf0e10cSrcweir IMPL_LINK( GalleryBrowser, SplitHdl, void*, EMPTYARG )
305cdf0e10cSrcweir {
30645fc0049SArmin Le Grand     if(mpSplitter->IsHorizontal())
30745fc0049SArmin Le Grand     {
30845fc0049SArmin Le Grand         mpSplitter->SetPosPixel( Point( mpSplitter->GetSplitPosPixel(), mpSplitter->GetPosPixel().Y() ) );
30945fc0049SArmin Le Grand     }
31045fc0049SArmin Le Grand     else
31145fc0049SArmin Le Grand     {
31245fc0049SArmin Le Grand         mpSplitter->SetPosPixel( Point( mpSplitter->GetPosPixel().X(), mpSplitter->GetSplitPosPixel() ) );
31345fc0049SArmin Le Grand     }
31445fc0049SArmin Le Grand 
31545fc0049SArmin Le Grand     Resize();
316cdf0e10cSrcweir 
317cdf0e10cSrcweir 	return 0L;
318cdf0e10cSrcweir }
31945fc0049SArmin Le Grand 
32045fc0049SArmin Le Grand // -----------------------------------------------------------------------------
32145fc0049SArmin Le Grand // eof
322