Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <vcl/split.hxx>
21 : #include <vcl/ctrl.hxx>
22 : #include <unotools/pathoptions.hxx>
23 : #include <sfx2/app.hxx>
24 : #include <sfx2/sfxsids.hrc>
25 : #include "gallery.hrc"
26 : #include "svx/galmisc.hxx"
27 : #include "svx/gallery1.hxx"
28 : #include "galbrws1.hxx"
29 : #include "galbrws2.hxx"
30 : #include "svx/galbrws.hxx"
31 : #include "GallerySplitter.hxx"
32 :
33 : #include <boost/bind.hpp>
34 :
35 : // -------------------------
36 : // - SvxGalleryChildWindow -
37 : // -------------------------
38 : DBG_NAME(GalleryChildWindow)
39 :
40 0 : GalleryChildWindow::GalleryChildWindow( Window* _pParent, sal_uInt16 nId, SfxBindings* pBindings, SfxChildWinInfo* pInfo ) :
41 0 : SfxChildWindow( _pParent, nId )
42 : {
43 : DBG_CTOR(GalleryChildWindow,NULL);
44 :
45 0 : pWindow = new GalleryBrowser( pBindings, this, _pParent, GAL_RES( RID_SVXDLG_GALLERYBROWSER ) );
46 0 : eChildAlignment = SFX_ALIGN_TOP;
47 0 : ( (GalleryBrowser*) pWindow )->Initialize( pInfo );
48 0 : };
49 :
50 : // -----------------------------------------------------------------------------
51 :
52 0 : GalleryChildWindow::~GalleryChildWindow()
53 : {
54 : DBG_DTOR(GalleryChildWindow,NULL);
55 0 : }
56 :
57 : // -----------------------------------------------------------------------------
58 :
59 461 : SFX_IMPL_DOCKINGWINDOW_WITHID( GalleryChildWindow, SID_GALLERY )
60 :
61 : // ------------------
62 : // - GalleryBrowser -
63 : // ------------------
64 : DBG_NAME(GalleryBrowser)
65 :
66 0 : GalleryBrowser::GalleryBrowser(
67 : SfxBindings* _pBindings,
68 : SfxChildWindow* pCW,
69 : Window* pParent,
70 : const ResId& rResId)
71 : : SfxDockingWindow(_pBindings, pCW, pParent, rResId),
72 0 : maLastSize(GetOutputSizePixel()),
73 : mpSplitter(0),
74 : mpBrowser1(0),
75 : mpBrowser2(0),
76 0 : mpGallery(0)
77 : {
78 : DBG_CTOR(GalleryBrowser,NULL);
79 :
80 0 : mpGallery = Gallery::GetGalleryInstance();
81 : mpBrowser1 = new GalleryBrowser1(
82 : this,
83 0 : GAL_RES( GALLERY_BROWSER1 ),
84 : mpGallery,
85 : ::boost::bind(&GalleryBrowser::KeyInput,this,_1,_2),
86 0 : ::boost::bind(&GalleryBrowser::ThemeSelectionHasChanged, this));
87 0 : mpSplitter = new GallerySplitter( this, GAL_RES( GALLERY_SPLITTER ),
88 0 : ::boost::bind(&GalleryBrowser::InitSettings, this));
89 0 : mpBrowser2 = new GalleryBrowser2( this, GAL_RES( GALLERY_BROWSER2 ), mpGallery );
90 :
91 0 : FreeResource();
92 0 : SetMinOutputSizePixel(maLastSize);
93 :
94 0 : mpBrowser1->SelectTheme( 0 );
95 0 : mpBrowser1->Show( sal_True );
96 0 : mpBrowser2->Show( sal_True );
97 :
98 0 : const bool bLayoutHorizontal(maLastSize.Width() > maLastSize.Height());
99 0 : mpSplitter->SetHorizontal(bLayoutHorizontal);
100 0 : mpSplitter->SetSplitHdl( LINK( this, GalleryBrowser, SplitHdl ) );
101 0 : mpSplitter->Show( sal_True );
102 :
103 0 : InitSettings();
104 0 : }
105 :
106 : // -----------------------------------------------------------------------------
107 :
108 0 : GalleryBrowser::~GalleryBrowser()
109 : {
110 0 : delete mpBrowser2;
111 0 : delete mpSplitter;
112 0 : delete mpBrowser1;
113 :
114 : DBG_DTOR(GalleryBrowser,NULL);
115 0 : }
116 :
117 : // -----------------------------------------------------------------------------
118 :
119 0 : void GalleryBrowser::InitSettings()
120 : {
121 0 : SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
122 0 : SetControlBackground( GALLERY_DLG_COLOR );
123 0 : SetControlForeground( GALLERY_DLG_COLOR );
124 :
125 0 : mpSplitter->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
126 0 : mpSplitter->SetControlBackground( GALLERY_DLG_COLOR );
127 0 : mpSplitter->SetControlForeground( GALLERY_DLG_COLOR );
128 :
129 0 : mpBrowser1->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
130 0 : mpBrowser1->SetControlBackground( GALLERY_DLG_COLOR );
131 0 : mpBrowser1->SetControlForeground( GALLERY_DLG_COLOR );
132 :
133 0 : mpBrowser2->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
134 0 : mpBrowser2->SetControlBackground( GALLERY_DLG_COLOR );
135 0 : mpBrowser2->SetControlForeground( GALLERY_DLG_COLOR );
136 0 : }
137 :
138 : // -----------------------------------------------------------------------------
139 :
140 0 : void GalleryBrowser::Resize()
141 : {
142 : // call parent
143 0 : SfxDockingWindow::Resize();
144 :
145 : // update hor/ver
146 0 : const Size aNewSize( GetOutputSizePixel() );
147 0 : const bool bNewLayoutHorizontal(aNewSize.Width() > aNewSize.Height());
148 0 : const bool bOldLayoutHorizontal(mpSplitter->IsHorizontal());
149 0 : const long nSplitPos( bOldLayoutHorizontal ? mpSplitter->GetPosPixel().X() : mpSplitter->GetPosPixel().Y());
150 0 : const long nSplitSize( bOldLayoutHorizontal ? mpSplitter->GetOutputSizePixel().Width() : mpSplitter->GetOutputSizePixel().Height());
151 :
152 0 : if(bNewLayoutHorizontal != bOldLayoutHorizontal)
153 : {
154 0 : mpSplitter->SetHorizontal(bNewLayoutHorizontal);
155 : }
156 :
157 0 : const long nFrameLen = LogicToPixel( Size( 3, 0 ), MAP_APPFONT ).Width();
158 0 : const long nFrameLen2 = nFrameLen << 1;
159 :
160 0 : if(bNewLayoutHorizontal)
161 : {
162 : mpBrowser1->SetPosSizePixel(
163 : Point( nFrameLen, nFrameLen ),
164 0 : Size(nSplitPos - nFrameLen, aNewSize.Height() - nFrameLen2) );
165 :
166 : mpSplitter->SetPosSizePixel(
167 : Point( nSplitPos, 0),
168 0 : Size( nSplitSize, aNewSize.Height() ) );
169 :
170 : mpSplitter->SetDragRectPixel(
171 : Rectangle(
172 : Point( nFrameLen2, 0 ),
173 0 : Size( aNewSize.Width() - ( nFrameLen2 << 1 ) - nSplitSize, aNewSize.Height() ) ) );
174 :
175 : mpBrowser2->SetPosSizePixel(
176 : Point( nSplitPos + nSplitSize, nFrameLen ),
177 0 : Size( aNewSize.Width() - nSplitSize - nSplitPos - nFrameLen, aNewSize.Height() - nFrameLen2 ) );
178 : }
179 : else
180 : {
181 : mpBrowser1->SetPosSizePixel(
182 : Point( nFrameLen, nFrameLen ),
183 0 : Size(aNewSize.Width() - nFrameLen2, nSplitPos - nFrameLen));
184 :
185 : mpSplitter->SetPosSizePixel(
186 : Point( 0, nSplitPos),
187 0 : Size( aNewSize.Width(), nSplitSize ) );
188 :
189 : mpSplitter->SetDragRectPixel(
190 : Rectangle(
191 : Point( 0, nFrameLen2 ),
192 0 : Size( aNewSize.Width(), aNewSize.Height() - ( nFrameLen2 << 1 ) - nSplitSize ) ));
193 :
194 : mpBrowser2->SetPosSizePixel(
195 : Point( nFrameLen, nSplitPos + nSplitSize ),
196 0 : Size( aNewSize.Width() - nFrameLen2, aNewSize.Height() - nSplitSize - nSplitPos - nFrameLen ));
197 : }
198 :
199 0 : maLastSize = aNewSize;
200 0 : }
201 :
202 : // -----------------------------------------------------------------------------
203 :
204 0 : sal_Bool GalleryBrowser::KeyInput( const KeyEvent& rKEvt, Window* )
205 : {
206 0 : const sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
207 0 : sal_Bool bRet = ( !rKEvt.GetKeyCode().IsMod1() &&
208 0 : ( ( KEY_TAB == nCode ) || ( KEY_F6 == nCode && rKEvt.GetKeyCode().IsMod2() ) ) );
209 :
210 0 : if( bRet )
211 : {
212 0 : if( !rKEvt.GetKeyCode().IsShift() )
213 : {
214 0 : if( mpBrowser1->mpThemes->HasChildPathFocus( sal_True ) )
215 0 : mpBrowser2->GetViewWindow()->GrabFocus();
216 0 : else if( mpBrowser2->GetViewWindow()->HasFocus() )
217 0 : mpBrowser2->maViewBox.GrabFocus();
218 0 : else if( mpBrowser2->maViewBox.HasFocus() )
219 0 : mpBrowser1->maNewTheme.GrabFocus();
220 : else
221 0 : mpBrowser1->mpThemes->GrabFocus();
222 : }
223 : else
224 : {
225 0 : if( mpBrowser1->mpThemes->HasChildPathFocus( sal_True ) )
226 0 : mpBrowser1->maNewTheme.GrabFocus();
227 0 : else if( mpBrowser1->maNewTheme.HasFocus() )
228 0 : mpBrowser2->maViewBox.GrabFocus();
229 0 : else if( mpBrowser2->maViewBox.HasFocus() )
230 0 : mpBrowser2->GetViewWindow()->GrabFocus();
231 : else
232 0 : mpBrowser1->mpThemes->GrabFocus();
233 : }
234 : }
235 :
236 0 : return bRet;
237 : }
238 :
239 : // -----------------------------------------------------------------------------
240 :
241 0 : sal_Bool GalleryBrowser::Close()
242 : {
243 0 : return SfxDockingWindow::Close();
244 : }
245 :
246 : // -----------------------------------------------------------------------------
247 :
248 0 : void GalleryBrowser::GetFocus()
249 : {
250 0 : SfxDockingWindow::GetFocus();
251 0 : mpBrowser1->GrabFocus();
252 0 : }
253 :
254 : // -----------------------------------------------------------------------------
255 :
256 0 : void GalleryBrowser::ThemeSelectionHasChanged()
257 : {
258 0 : mpBrowser2->SelectTheme( mpBrowser1->GetSelectedTheme() );
259 0 : }
260 :
261 : // -----------------------------------------------------------------------------
262 :
263 0 : IMPL_LINK_NOARG(GalleryBrowser, SplitHdl)
264 : {
265 0 : if(mpSplitter->IsHorizontal())
266 : {
267 0 : mpSplitter->SetPosPixel( Point( mpSplitter->GetSplitPosPixel(), mpSplitter->GetPosPixel().Y() ) );
268 : }
269 : else
270 : {
271 0 : mpSplitter->SetPosPixel( Point( mpSplitter->GetPosPixel().X(), mpSplitter->GetSplitPosPixel() ) );
272 : }
273 :
274 0 : Resize();
275 :
276 0 : return 0L;
277 258 : }
278 :
279 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|