merge the formfield patch from ooo-build
[ooovba.git] / svx / source / gallery2 / galbrws.cxx
blob4260aec4b89e63054c944109008958ba81bedc3b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: galbrws.cxx,v $
10 * $Revision: 1.17 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <vcl/split.hxx>
35 #include <vcl/ctrl.hxx>
36 #include <svtools/pathoptions.hxx>
37 #include <sfx2/app.hxx>
38 #include <sfx2/sfxsids.hrc>
39 #include "gallery.hrc"
40 #include "galmisc.hxx"
41 #include "gallery1.hxx"
42 #include "galbrws1.hxx"
43 #include "galbrws2.hxx"
44 #include "galbrws.hxx"
46 // -------------------
47 // - GallerySplitter -
48 // -------------------
50 class GallerySplitter : public Splitter
52 protected:
54 virtual void DataChanged( const DataChangedEvent& rDCEvt );
56 public:
58 GallerySplitter( Window* pParent, const ResId& rResId );
59 virtual ~GallerySplitter();
62 // -----------------------------------------------------------------------------
64 GallerySplitter::GallerySplitter( Window* pParent, const ResId& rResId ) :
65 Splitter( pParent, rResId )
69 // -----------------------------------------------------------------------------
71 GallerySplitter::~GallerySplitter()
75 // -----------------------------------------------------------------------------
77 void GallerySplitter::DataChanged( const DataChangedEvent& rDCEvt )
79 Splitter::DataChanged( rDCEvt );
80 static_cast< GalleryBrowser* >( GetParent() )->InitSettings();
83 // -------------------------
84 // - SvxGalleryChildWindow -
85 // -------------------------
87 GalleryChildWindow::GalleryChildWindow( Window* _pParent, USHORT nId, SfxBindings* pBindings, SfxChildWinInfo* pInfo ) :
88 SfxChildWindow( _pParent, nId )
90 pWindow = new GalleryBrowser( pBindings, this, _pParent, GAL_RESID( RID_SVXDLG_GALLERYBROWSER ) );
91 eChildAlignment = SFX_ALIGN_TOP;
92 ( (GalleryBrowser*) pWindow )->Initialize( pInfo );
95 // -----------------------------------------------------------------------------
97 GalleryChildWindow::~GalleryChildWindow()
101 // -----------------------------------------------------------------------------
103 SFX_IMPL_DOCKINGWINDOW( GalleryChildWindow, SID_GALLERY )
105 // ------------------
106 // - GalleryBrowser -
107 // ------------------
109 GalleryBrowser::GalleryBrowser( SfxBindings* _pBindings, SfxChildWindow* pCW,
110 Window* pParent, const ResId& rResId ) :
111 SfxDockingWindow( _pBindings, pCW, pParent, rResId )
113 mpGallery = Gallery::GetGalleryInstance();
114 mpBrowser1 = new GalleryBrowser1( this, GAL_RESID( GALLERY_BROWSER1 ), mpGallery );
115 mpSplitter = new GallerySplitter( this, GAL_RESID( GALLERY_SPLITTER ) );
116 mpBrowser2 = new GalleryBrowser2( this, GAL_RESID( GALLERY_BROWSER2 ), mpGallery );
118 FreeResource();
119 SetMinOutputSizePixel( maLastSize = GetOutputSizePixel() );
121 mpBrowser1->SelectTheme( 0 );
122 mpBrowser1->Show( TRUE );
123 mpBrowser2->Show( TRUE );
125 mpSplitter->SetSplitHdl( LINK( this, GalleryBrowser, SplitHdl ) );
126 mpSplitter->Show( TRUE );
128 InitSettings();
131 // -----------------------------------------------------------------------------
133 GalleryBrowser::~GalleryBrowser()
135 delete mpBrowser2;
136 delete mpSplitter;
137 delete mpBrowser1;
140 // -----------------------------------------------------------------------------
142 void GalleryBrowser::InitSettings()
144 SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
145 SetControlBackground( GALLERY_DLG_COLOR );
146 SetControlForeground( GALLERY_DLG_COLOR );
148 mpSplitter->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
149 mpSplitter->SetControlBackground( GALLERY_DLG_COLOR );
150 mpSplitter->SetControlForeground( GALLERY_DLG_COLOR );
152 mpBrowser1->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
153 mpBrowser1->SetControlBackground( GALLERY_DLG_COLOR );
154 mpBrowser1->SetControlForeground( GALLERY_DLG_COLOR );
156 mpBrowser2->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
157 mpBrowser2->SetControlBackground( GALLERY_DLG_COLOR );
158 mpBrowser2->SetControlForeground( GALLERY_DLG_COLOR );
161 // -----------------------------------------------------------------------------
163 void GalleryBrowser::Resize()
165 SfxDockingWindow::Resize();
167 const long nFrameWidth = LogicToPixel( Size( 3, 0 ), MAP_APPFONT ).Width();
168 const long nFrameWidth2 = nFrameWidth << 1;
169 Size aMinSize( GetMinOutputSizePixel() );
170 Size aNewSize( GetOutputSizePixel() );
171 Point aSplitPos( mpSplitter->GetPosPixel() );
172 const Size aSplitSize( mpSplitter->GetOutputSizePixel() );
174 mpBrowser1->SetPosSizePixel( Point( nFrameWidth, nFrameWidth ),
175 Size( aSplitPos.X() - nFrameWidth, aNewSize.Height() - nFrameWidth2 ) );
177 mpSplitter->SetPosSizePixel( aSplitPos, Size( aSplitSize.Width(), aNewSize.Height() ) );
178 mpSplitter->SetDragRectPixel( Rectangle( Point( nFrameWidth2, 0 ), Size( aNewSize.Width() - ( nFrameWidth2 << 1 ) - aSplitSize.Width(), aNewSize.Height() ) ) );
180 mpBrowser2->SetPosSizePixel( Point( aSplitPos.X() + aSplitSize.Width(), nFrameWidth ),
181 Size( aNewSize.Width() - aSplitSize.Width() - aSplitPos.X() - nFrameWidth, aNewSize.Height() - nFrameWidth2 ) );
183 maLastSize = aNewSize;
186 // -----------------------------------------------------------------------------
188 BOOL GalleryBrowser::KeyInput( const KeyEvent& rKEvt, Window* )
190 const USHORT nCode = rKEvt.GetKeyCode().GetCode();
191 BOOL bRet = ( !rKEvt.GetKeyCode().IsMod1() &&
192 ( ( KEY_TAB == nCode ) || ( KEY_F6 == nCode && rKEvt.GetKeyCode().IsMod2() ) ) );
194 if( bRet )
196 if( !rKEvt.GetKeyCode().IsShift() )
198 if( mpBrowser1->mpThemes->HasChildPathFocus( TRUE ) )
199 mpBrowser2->GetViewWindow()->GrabFocus();
200 else if( mpBrowser2->GetViewWindow()->HasFocus() )
201 mpBrowser2->maViewBox.GrabFocus();
202 else if( mpBrowser2->maViewBox.HasFocus() )
203 mpBrowser1->maNewTheme.GrabFocus();
204 else
205 mpBrowser1->mpThemes->GrabFocus();
207 else
209 if( mpBrowser1->mpThemes->HasChildPathFocus( TRUE ) )
210 mpBrowser1->maNewTheme.GrabFocus();
211 else if( mpBrowser1->maNewTheme.HasFocus() )
212 mpBrowser2->maViewBox.GrabFocus();
213 else if( mpBrowser2->maViewBox.HasFocus() )
214 mpBrowser2->GetViewWindow()->GrabFocus();
215 else
216 mpBrowser1->mpThemes->GrabFocus();
220 return bRet;
223 // -----------------------------------------------------------------------------
225 BOOL GalleryBrowser::Close()
227 return SfxDockingWindow::Close();
230 // -----------------------------------------------------------------------------
232 void GalleryBrowser::GetFocus()
234 SfxDockingWindow::GetFocus();
235 mpBrowser1->GrabFocus();
238 // -----------------------------------------------------------------------------
240 void GalleryBrowser::ThemeSelectionHasChanged()
242 mpBrowser2->SelectTheme( mpBrowser1->GetSelectedTheme() );
245 // -----------------------------------------------------------------------------
247 INetURLObject GalleryBrowser::GetURL() const
249 return mpBrowser2->GetURL();
252 // -----------------------------------------------------------------------------
254 String GalleryBrowser::GetFilterName() const
256 return mpBrowser2->GetFilterName();
259 // -----------------------------------------------------------------------------
261 Graphic GalleryBrowser::GetGraphic() const
263 return mpBrowser2->GetGraphic();
266 // -----------------------------------------------------------------------------
268 BOOL GalleryBrowser::GetVCDrawModel( FmFormModel& rModel ) const
270 return mpBrowser2->GetVCDrawModel( rModel );
273 // -----------------------------------------------------------------------------
275 BOOL GalleryBrowser::IsLinkage() const
277 return mpBrowser2->IsLinkage();
280 // -----------------------------------------------------------------------------
282 IMPL_LINK( GalleryBrowser, SplitHdl, void*, EMPTYARG )
284 mpSplitter->SetPosPixel( Point( mpSplitter->GetSplitPosPixel(), mpSplitter->GetPosPixel().Y() ) );
285 Resize();
287 return 0L;