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 :
21 : #include <com/sun/star/text/WritingMode.hpp>
22 :
23 : #include <vcl/toolbox.hxx>
24 :
25 : #include <svl/itempool.hxx>
26 :
27 : #include <svtools/toolbarmenu.hxx>
28 : #include <svtools/popupwindowcontroller.hxx>
29 : #include <svtools/popupmenucontrollerbase.hxx>
30 :
31 : #include <sfx2/app.hxx>
32 : #include <sfx2/dispatch.hxx>
33 :
34 : #include <editeng/eeitem.hxx>
35 : #include <editeng/frmdiritem.hxx>
36 :
37 : #include <svx/fmmodel.hxx>
38 : #include <svx/svxids.hrc>
39 : #include <svx/dialmgr.hxx>
40 : #include <svx/dialogs.hrc>
41 : #include <svx/svdpage.hxx>
42 : #include <svx/svdobj.hxx>
43 : #include <svx/svdview.hxx>
44 : #include <svx/svdoutl.hxx>
45 :
46 : #include "svx/gallery.hxx"
47 : #include <svx/dlgutil.hxx>
48 :
49 : #include <svx/fontworkgallery.hxx>
50 : #include "fontworkgallery.hrc"
51 :
52 : #include <algorithm>
53 :
54 : #include "helpid.hrc"
55 :
56 : using ::svtools::ToolbarMenu;
57 :
58 : using namespace ::com::sun::star;
59 : using namespace ::com::sun::star::uno;
60 : using namespace ::com::sun::star::lang;
61 : using namespace ::com::sun::star::beans;
62 : using namespace ::com::sun::star::frame;
63 :
64 : namespace svx
65 : {
66 :
67 : const int nColCount = 4;
68 : const int nLineCount = 4;
69 :
70 : /*************************************************************************
71 : |* Svx3DWin - FloatingWindow
72 : \************************************************************************/
73 0 : FontWorkGalleryDialog::FontWorkGalleryDialog( SdrView* pSdrView, Window* pParent, sal_uInt16 /*nSID*/ ) :
74 0 : ModalDialog( pParent, SVX_RES( RID_SVX_MDLG_FONTWORK_GALLERY ) ),
75 0 : maFLFavorites ( this, SVX_RES( FL_FAVORITES ) ),
76 0 : maCtlFavorites ( this, SVX_RES( CTL_FAVORITES ) ),
77 0 : maOKButton ( this, SVX_RES( BTN_OK ) ),
78 0 : maCancelButton ( this, SVX_RES( BTN_CANCEL ) ),
79 0 : maHelpButton ( this, SVX_RES( BTN_HELP ) ),
80 : mnThemeId ( 0xffff ),
81 : mpSdrView ( pSdrView ),
82 0 : mpModel ( (FmFormModel*)pSdrView->GetModel() ),
83 0 : maStrClickToAddText ( SVX_RES( STR_CLICK_TO_ADD_TEXT ) ),
84 : mppSdrObject ( NULL ),
85 0 : mpDestModel ( NULL )
86 : {
87 0 : FreeResource();
88 :
89 0 : maCtlFavorites.SetDoubleClickHdl( LINK( this, FontWorkGalleryDialog, DoubleClickFavoriteHdl ) );
90 0 : maOKButton.SetClickHdl( LINK( this, FontWorkGalleryDialog, ClickOKHdl ) );
91 :
92 0 : maCtlFavorites.SetColCount( nColCount );
93 0 : maCtlFavorites.SetLineCount( nLineCount );
94 0 : maCtlFavorites.SetExtraSpacing( 3 );
95 :
96 0 : initFavorites( GALLERY_THEME_FONTWORK );
97 0 : fillFavorites( GALLERY_THEME_FONTWORK );
98 0 : }
99 :
100 : // -----------------------------------------------------------------------
101 0 : FontWorkGalleryDialog::~FontWorkGalleryDialog()
102 : {
103 0 : }
104 :
105 : // -----------------------------------------------------------------------
106 :
107 0 : void FontWorkGalleryDialog::initFavorites(sal_uInt16 nThemeId)
108 : {
109 : // Ueber die Gallery werden die Favoriten eingelesen
110 0 : sal_uIntPtr nFavCount = GalleryExplorer::GetSdrObjCount( nThemeId );
111 :
112 : // Gallery thema locken
113 0 : GalleryExplorer::BeginLocking(nThemeId);
114 :
115 : sal_uInt32 nModelPos;
116 0 : FmFormModel *pModel = NULL;
117 0 : const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
118 :
119 0 : for( nModelPos = 0; nModelPos < nFavCount; nModelPos++ )
120 : {
121 0 : BitmapEx aThumb;
122 :
123 0 : GalleryExplorer::GetSdrObj(nThemeId, nModelPos, pModel, &aThumb);
124 :
125 0 : if(!!aThumb)
126 : {
127 0 : VirtualDevice aVDev;
128 0 : const Point aNull(0, 0);
129 0 : const Size aSize(aThumb.GetSizePixel());
130 :
131 0 : aVDev.SetOutputSizePixel(aSize);
132 :
133 0 : if(rStyleSettings.GetPreviewUsesCheckeredBackground())
134 : {
135 : static const sal_uInt32 nLen(8);
136 0 : static const Color aW(COL_WHITE);
137 0 : static const Color aG(0xef, 0xef, 0xef);
138 :
139 0 : aVDev.DrawCheckered(aNull, aSize, nLen, aW, aG);
140 : }
141 : else
142 : {
143 0 : aVDev.SetBackground(rStyleSettings.GetFieldColor());
144 0 : aVDev.Erase();
145 : }
146 :
147 0 : aVDev.DrawBitmapEx(aNull, aThumb);
148 0 : maFavoritesHorizontal.push_back(aVDev.GetBitmap(aNull, aSize));
149 : }
150 0 : }
151 :
152 : // Gallery thema freigeben
153 0 : GalleryExplorer::EndLocking(nThemeId);
154 0 : }
155 :
156 0 : void FontWorkGalleryDialog::fillFavorites(sal_uInt16 nThemeId)
157 : {
158 0 : mnThemeId = nThemeId;
159 :
160 0 : Size aThumbSize( maCtlFavorites.GetSizePixel() );
161 0 : aThumbSize.Width() /= nColCount;
162 0 : aThumbSize.Height() /= nLineCount;
163 0 : aThumbSize.Width() -= 12;
164 0 : aThumbSize.Height() -= 12;
165 :
166 0 : std::vector< Bitmap * >::size_type nFavCount = maFavoritesHorizontal.size();
167 :
168 : // ValueSet Favoriten
169 0 : if( nFavCount > (nColCount * nLineCount) )
170 : {
171 0 : WinBits nWinBits = maCtlFavorites.GetStyle();
172 0 : nWinBits |= WB_VSCROLL;
173 0 : maCtlFavorites.SetStyle( nWinBits );
174 : }
175 :
176 0 : maCtlFavorites.Clear();
177 :
178 : sal_uInt32 nFavorite;
179 0 : for( nFavorite = 1; nFavorite <= nFavCount; nFavorite++ )
180 : {
181 0 : String aStr(SVX_RES(RID_SVXFLOAT3D_FAVORITE));
182 0 : aStr += sal_Unicode(' ');
183 0 : aStr += OUString::number((sal_Int32)nFavorite);
184 0 : Image aThumbImage( maFavoritesHorizontal[nFavorite-1] );
185 0 : maCtlFavorites.InsertItem( (sal_uInt16)nFavorite, aThumbImage, aStr );
186 0 : }
187 0 : }
188 :
189 0 : void FontWorkGalleryDialog::SetSdrObjectRef( SdrObject** ppSdrObject, SdrModel* pModel )
190 : {
191 0 : mppSdrObject = ppSdrObject;
192 0 : mpDestModel = pModel;
193 0 : }
194 :
195 0 : void FontWorkGalleryDialog::insertSelectedFontwork()
196 : {
197 0 : sal_uInt16 nItemId = maCtlFavorites.GetSelectItemId();
198 :
199 0 : if( nItemId > 0 )
200 : {
201 0 : FmFormModel* pModel = new FmFormModel();
202 0 : pModel->GetItemPool().FreezeIdRanges();
203 :
204 0 : if( GalleryExplorer::GetSdrObj( mnThemeId, nItemId-1, pModel ) )
205 : {
206 0 : SdrPage* pPage = pModel->GetPage(0);
207 0 : if( pPage && pPage->GetObjCount() )
208 : {
209 0 : SdrObject* pNewObject = pPage->GetObj(0)->Clone();
210 :
211 : // center shape on current view
212 0 : OutputDevice* pOutDev = mpSdrView->GetFirstOutputDevice();
213 0 : if( pOutDev )
214 : {
215 0 : Rectangle aObjRect( pNewObject->GetLogicRect() );
216 0 : Rectangle aVisArea = pOutDev->PixelToLogic(Rectangle(Point(0,0), pOutDev->GetOutputSizePixel()));
217 0 : Point aPagePos = aVisArea.Center();
218 0 : aPagePos.X() -= aObjRect.GetWidth() / 2;
219 0 : aPagePos.Y() -= aObjRect.GetHeight() / 2;
220 0 : Rectangle aNewObjectRectangle(aPagePos, aObjRect.GetSize());
221 0 : SdrPageView* pPV = mpSdrView->GetSdrPageView();
222 :
223 0 : pNewObject->SetLogicRect(aNewObjectRectangle);
224 0 : if ( mppSdrObject )
225 : {
226 0 : *mppSdrObject = pNewObject;
227 0 : (*mppSdrObject)->SetModel( mpDestModel );
228 : }
229 0 : else if( pPV )
230 : {
231 0 : mpSdrView->InsertObjectAtView( pNewObject, *pPV );
232 : }
233 : }
234 : }
235 : }
236 :
237 0 : delete pModel;
238 : }
239 0 : }
240 :
241 : // -----------------------------------------------------------------------
242 :
243 0 : IMPL_LINK_NOARG(FontWorkGalleryDialog, ClickOKHdl)
244 : {
245 0 : insertSelectedFontwork();
246 0 : EndDialog( true );
247 0 : return 0;
248 : }
249 :
250 : // -----------------------------------------------------------------------
251 :
252 0 : IMPL_LINK_NOARG(FontWorkGalleryDialog, DoubleClickFavoriteHdl)
253 : {
254 0 : insertSelectedFontwork();
255 0 : EndDialog( true );
256 0 : return( 0L );
257 : }
258 :
259 : //------------------------------------------------------------------------
260 :
261 75 : SFX_IMPL_TOOLBOX_CONTROL( FontWorkShapeTypeControl, SfxStringItem );
262 0 : FontWorkShapeTypeControl::FontWorkShapeTypeControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx )
263 0 : : SfxToolBoxControl( nSlotId, nId, rTbx )
264 : {
265 0 : rTbx.SetItemBits( nId, TIB_DROPDOWNONLY | rTbx.GetItemBits( nId ) );
266 0 : rTbx.Invalidate();
267 0 : }
268 :
269 : // -----------------------------------------------------------------------
270 :
271 0 : FontWorkShapeTypeControl::~FontWorkShapeTypeControl()
272 : {
273 0 : }
274 :
275 : // -----------------------------------------------------------------------
276 :
277 0 : SfxPopupWindowType FontWorkShapeTypeControl::GetPopupWindowType() const
278 : {
279 0 : return SFX_POPUPWINDOW_ONCLICK; //( aLastAction.getLength() == 0 ? SFX_POPUPWINDOW_ONCLICK : SFX_POPUPWINDOW_ONTIMEOUT );
280 : }
281 :
282 : // -----------------------------------------------------------------------
283 :
284 0 : SfxPopupWindow* FontWorkShapeTypeControl::CreatePopupWindow()
285 : {
286 0 : OUString aSubTbxResName( "private:resource/toolbar/fontworkshapetype" );
287 0 : createAndPositionSubToolBar( aSubTbxResName );
288 0 : return NULL;
289 : }
290 :
291 : // -----------------------------------------------------------------------
292 :
293 0 : void FontWorkShapeTypeControl::Select( sal_Bool )
294 : {
295 :
296 0 : }
297 :
298 : // ========================================================================
299 : // FontworkAlignmentWindow
300 : // ========================================================================
301 :
302 0 : class FontworkAlignmentWindow : public ToolbarMenu
303 : {
304 : public:
305 : FontworkAlignmentWindow( svt::ToolboxController& rController, const Reference< XFrame >& rFrame, Window* pParentWindow );
306 :
307 : virtual void SAL_CALL statusChanged( const frame::FeatureStateEvent& Event ) throw ( RuntimeException );
308 : virtual void DataChanged( const DataChangedEvent& rDCEvt );
309 :
310 : private:
311 : svt::ToolboxController& mrController;
312 :
313 : Image maImgAlgin1;
314 : Image maImgAlgin2;
315 : Image maImgAlgin3;
316 : Image maImgAlgin4;
317 : Image maImgAlgin5;
318 :
319 : const OUString msFontworkAlignment;
320 :
321 : DECL_LINK( SelectHdl, void * );
322 :
323 : void implSetAlignment( int nAlignmentMode, bool bEnabled );
324 : };
325 :
326 0 : FontworkAlignmentWindow::FontworkAlignmentWindow( svt::ToolboxController& rController, const Reference< XFrame >& rFrame, Window* pParentWindow )
327 0 : : ToolbarMenu( rFrame, pParentWindow, SVX_RES( RID_SVXFLOAT_FONTWORK_ALIGNMENT ))
328 : , mrController( rController )
329 0 : , maImgAlgin1( SVX_RES( IMG_FONTWORK_ALIGN_LEFT_16 ) )
330 0 : , maImgAlgin2( SVX_RES( IMG_FONTWORK_ALIGN_CENTER_16 ) )
331 0 : , maImgAlgin3( SVX_RES( IMG_FONTWORK_ALIGN_RIGHT_16 ) )
332 0 : , maImgAlgin4( SVX_RES( IMG_FONTWORK_ALIGN_WORD_16 ) )
333 0 : , maImgAlgin5( SVX_RES( IMG_FONTWORK_ALIGN_STRETCH_16 ) )
334 0 : , msFontworkAlignment( ".uno:FontworkAlignment" )
335 : {
336 0 : SetHelpId( HID_POPUP_FONTWORK_ALIGN );
337 0 : SetSelectHdl( LINK( this, FontworkAlignmentWindow, SelectHdl ) );
338 :
339 0 : appendEntry( 0, String( SVX_RES( STR_ALIGN_LEFT ) ), maImgAlgin1 );
340 0 : appendEntry( 1, String( SVX_RES( STR_ALIGN_CENTER ) ), maImgAlgin2 );
341 0 : appendEntry( 2, String( SVX_RES( STR_ALIGN_RIGHT ) ), maImgAlgin3 );
342 0 : appendEntry( 3, String( SVX_RES( STR_ALIGN_WORD ) ), maImgAlgin4 );
343 0 : appendEntry( 4, String( SVX_RES( STR_ALIGN_STRETCH ) ), maImgAlgin5 );
344 :
345 0 : SetOutputSizePixel( getMenuSize() );
346 :
347 0 : FreeResource();
348 :
349 0 : AddStatusListener( msFontworkAlignment );
350 0 : }
351 :
352 : // -----------------------------------------------------------------------
353 :
354 0 : void FontworkAlignmentWindow::implSetAlignment( int nSurface, bool bEnabled )
355 : {
356 : int i;
357 0 : for( i = 0; i < 5; i++ )
358 : {
359 0 : checkEntry( i, (i == nSurface) && bEnabled );
360 0 : enableEntry( i, bEnabled );
361 : }
362 0 : }
363 :
364 : // -----------------------------------------------------------------------
365 :
366 0 : void SAL_CALL FontworkAlignmentWindow::statusChanged( const frame::FeatureStateEvent& Event ) throw ( RuntimeException )
367 : {
368 0 : if( Event.FeatureURL.Main.equals( msFontworkAlignment ) )
369 : {
370 0 : if( !Event.IsEnabled )
371 : {
372 0 : implSetAlignment( 0, false );
373 : }
374 : else
375 : {
376 0 : sal_Int32 nValue = 0;
377 0 : if( Event.State >>= nValue )
378 0 : implSetAlignment( nValue, true );
379 : }
380 : }
381 0 : }
382 :
383 : // -----------------------------------------------------------------------
384 :
385 0 : void FontworkAlignmentWindow::DataChanged( const DataChangedEvent& rDCEvt )
386 : {
387 0 : ToolbarMenu::DataChanged( rDCEvt );
388 :
389 0 : if( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
390 : {
391 0 : appendEntry( 0, String( SVX_RES( STR_ALIGN_LEFT ) ), maImgAlgin1 );
392 0 : appendEntry( 1, String( SVX_RES( STR_ALIGN_CENTER ) ), maImgAlgin2 );
393 0 : appendEntry( 2, String( SVX_RES( STR_ALIGN_RIGHT ) ), maImgAlgin3 );
394 0 : appendEntry( 3, String( SVX_RES( STR_ALIGN_WORD ) ), maImgAlgin4 );
395 0 : appendEntry( 4, String( SVX_RES( STR_ALIGN_STRETCH ) ), maImgAlgin5 );
396 : }
397 0 : }
398 :
399 : // -----------------------------------------------------------------------
400 :
401 0 : IMPL_LINK_NOARG(FontworkAlignmentWindow, SelectHdl)
402 : {
403 0 : if ( IsInPopupMode() )
404 0 : EndPopupMode();
405 :
406 0 : sal_Int32 nAlignment = getSelectedEntryId();
407 0 : if( nAlignment >= 0 )
408 : {
409 0 : Sequence< PropertyValue > aArgs( 1 );
410 0 : aArgs[0].Name = msFontworkAlignment.copy(5);
411 0 : aArgs[0].Value <<= (sal_Int32)nAlignment;
412 :
413 0 : mrController.dispatchCommand( msFontworkAlignment, aArgs );
414 :
415 0 : implSetAlignment( nAlignment, true );
416 : }
417 :
418 0 : return 0;
419 : }
420 :
421 : // ========================================================================
422 : // FontworkAlignmentControl
423 : // ========================================================================
424 :
425 0 : class FontworkAlignmentControl : public svt::PopupWindowController
426 : {
427 : public:
428 : FontworkAlignmentControl( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rxContext );
429 :
430 : virtual ::Window* createPopupWindow( ::Window* pParent );
431 :
432 : // XServiceInfo
433 : virtual OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException );
434 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException );
435 :
436 : using svt::PopupWindowController::createPopupWindow;
437 : };
438 :
439 :
440 : // -----------------------------------------------------------------------
441 :
442 0 : FontworkAlignmentControl::FontworkAlignmentControl( const Reference< XComponentContext >& rxContext )
443 0 : : svt::PopupWindowController( rxContext, Reference< frame::XFrame >(), OUString( ".uno:FontworkAlignment" ) )
444 : {
445 0 : }
446 :
447 : // -----------------------------------------------------------------------
448 :
449 0 : ::Window* FontworkAlignmentControl::createPopupWindow( ::Window* pParent )
450 : {
451 0 : return new FontworkAlignmentWindow( *this, m_xFrame, pParent );
452 : }
453 :
454 : // -----------------------------------------------------------------------
455 : // XServiceInfo
456 : // -----------------------------------------------------------------------
457 :
458 0 : OUString SAL_CALL FontworkAlignmentControl_getImplementationName()
459 : {
460 0 : return OUString( "com.sun.star.comp.svx.FontworkAlignmentController" );
461 : }
462 :
463 : // --------------------------------------------------------------------
464 :
465 0 : Sequence< OUString > SAL_CALL FontworkAlignmentControl_getSupportedServiceNames() throw( RuntimeException )
466 : {
467 0 : Sequence< OUString > aSNS( 1 );
468 0 : aSNS.getArray()[0] = OUString( "com.sun.star.frame.ToolbarController" );
469 0 : return aSNS;
470 : }
471 :
472 : // --------------------------------------------------------------------
473 :
474 0 : Reference< XInterface > SAL_CALL SAL_CALL FontworkAlignmentControl_createInstance( const Reference< XMultiServiceFactory >& rSMgr ) throw( RuntimeException )
475 : {
476 0 : return *new FontworkAlignmentControl( comphelper::getComponentContext(rSMgr) );
477 : }
478 :
479 : // --------------------------------------------------------------------
480 :
481 0 : OUString SAL_CALL FontworkAlignmentControl::getImplementationName( ) throw (RuntimeException)
482 : {
483 0 : return FontworkAlignmentControl_getImplementationName();
484 : }
485 :
486 : // --------------------------------------------------------------------
487 :
488 0 : Sequence< OUString > SAL_CALL FontworkAlignmentControl::getSupportedServiceNames( ) throw (RuntimeException)
489 : {
490 0 : return FontworkAlignmentControl_getSupportedServiceNames();
491 : }
492 :
493 :
494 : // ####################################################################
495 :
496 0 : class FontworkCharacterSpacingWindow : public ToolbarMenu
497 : {
498 : public:
499 : FontworkCharacterSpacingWindow( svt::ToolboxController& rController, const Reference< XFrame >& rFrame, Window* pParentWindow );
500 :
501 : virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException );
502 : private:
503 : svt::ToolboxController& mrController;
504 :
505 : const OUString msFontworkCharacterSpacing;
506 : const OUString msFontworkKernCharacterPairs;
507 :
508 : DECL_LINK( SelectHdl, void * );
509 :
510 : void implSetCharacterSpacing( sal_Int32 nCharacterSpacing, bool bEnabled );
511 : void implSetKernCharacterPairs( sal_Bool bKernOnOff, bool bEnabled );
512 :
513 : };
514 :
515 : // -----------------------------------------------------------------------
516 :
517 0 : FontworkCharacterSpacingWindow::FontworkCharacterSpacingWindow( svt::ToolboxController& rController, const Reference< XFrame >& rFrame, Window* pParentWindow )
518 0 : : ToolbarMenu( rFrame, pParentWindow, SVX_RES( RID_SVXFLOAT_FONTWORK_CHARSPACING ))
519 : , mrController( rController )
520 : , msFontworkCharacterSpacing( ".uno:FontworkCharacterSpacing" )
521 0 : , msFontworkKernCharacterPairs( ".uno:FontworkKernCharacterPairs" )
522 : {
523 0 : SetHelpId( HID_POPUP_FONTWORK_CHARSPACE );
524 0 : SetSelectHdl( LINK( this, FontworkCharacterSpacingWindow, SelectHdl ) );
525 :
526 0 : appendEntry( 0, String( SVX_RES( STR_CHARS_SPACING_VERY_TIGHT ) ), MIB_RADIOCHECK );
527 0 : appendEntry( 1, String( SVX_RES( STR_CHARS_SPACING_TIGHT ) ), MIB_RADIOCHECK );
528 0 : appendEntry( 2, String( SVX_RES( STR_CHARS_SPACING_NORMAL ) ), MIB_RADIOCHECK );
529 0 : appendEntry( 3, String( SVX_RES( STR_CHARS_SPACING_LOOSE ) ), MIB_RADIOCHECK );
530 0 : appendEntry( 4, String( SVX_RES( STR_CHARS_SPACING_VERY_LOOSE ) ), MIB_RADIOCHECK );
531 0 : appendEntry( 5, String( SVX_RES( STR_CHARS_SPACING_CUSTOM ) ), MIB_RADIOCHECK );
532 0 : appendSeparator();
533 0 : appendEntry( 6, String( SVX_RES( STR_CHARS_SPACING_KERN_PAIRS ) ), MIB_CHECKABLE );
534 :
535 0 : SetOutputSizePixel( getMenuSize() );
536 :
537 0 : FreeResource();
538 :
539 0 : AddStatusListener( msFontworkCharacterSpacing );
540 0 : AddStatusListener( msFontworkKernCharacterPairs );
541 0 : }
542 :
543 : // -----------------------------------------------------------------------
544 :
545 0 : void FontworkCharacterSpacingWindow::implSetCharacterSpacing( sal_Int32 nCharacterSpacing, bool bEnabled )
546 : {
547 : sal_Int32 i;
548 0 : for ( i = 0; i < 6; i++ )
549 : {
550 0 : checkEntry( i, sal_False );
551 0 : enableEntry( i, bEnabled );
552 : }
553 0 : if ( nCharacterSpacing != -1 )
554 : {
555 : sal_Int32 nEntry;
556 0 : switch( nCharacterSpacing )
557 : {
558 0 : case 80 : nEntry = 0; break;
559 0 : case 90 : nEntry = 1; break;
560 0 : case 100 : nEntry = 2; break;
561 0 : case 120 : nEntry = 3; break;
562 0 : case 150 : nEntry = 4; break;
563 0 : default : nEntry = 5; break;
564 : }
565 0 : checkEntry( nEntry, bEnabled );
566 : }
567 0 : }
568 :
569 : // -----------------------------------------------------------------------
570 :
571 0 : void FontworkCharacterSpacingWindow::implSetKernCharacterPairs( sal_Bool, bool bEnabled )
572 : {
573 0 : enableEntry( 6, bEnabled );
574 0 : checkEntry( 6, bEnabled );
575 0 : }
576 :
577 : // -----------------------------------------------------------------------
578 :
579 0 : void SAL_CALL FontworkCharacterSpacingWindow::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException )
580 : {
581 0 : if( Event.FeatureURL.Main.equals( msFontworkCharacterSpacing ) )
582 : {
583 0 : if( !Event.IsEnabled )
584 : {
585 0 : implSetCharacterSpacing( 0, false );
586 : }
587 : else
588 : {
589 0 : sal_Int32 nValue = 0;
590 0 : if( Event.State >>= nValue )
591 0 : implSetCharacterSpacing( nValue, true );
592 : }
593 : }
594 0 : else if( Event.FeatureURL.Main.equals( msFontworkKernCharacterPairs ) )
595 : {
596 0 : if( !Event.IsEnabled )
597 : {
598 0 : implSetKernCharacterPairs( 0, false );
599 : }
600 : else
601 : {
602 0 : sal_Bool bValue = sal_False;
603 0 : if( Event.State >>= bValue )
604 0 : implSetKernCharacterPairs( bValue, true );
605 : }
606 : }
607 0 : }
608 :
609 : // -----------------------------------------------------------------------
610 :
611 0 : IMPL_LINK_NOARG(FontworkCharacterSpacingWindow, SelectHdl)
612 : {
613 0 : if ( IsInPopupMode() )
614 0 : EndPopupMode();
615 :
616 0 : sal_Int32 nSelection = getSelectedEntryId();
617 : sal_Int32 nCharacterSpacing;
618 0 : switch( nSelection )
619 : {
620 0 : case 0 : nCharacterSpacing = 80; break;
621 0 : case 1 : nCharacterSpacing = 90; break;
622 0 : case 2 : nCharacterSpacing = 100; break;
623 0 : case 3 : nCharacterSpacing = 120; break;
624 0 : case 4 : nCharacterSpacing = 150; break;
625 0 : default : nCharacterSpacing = 100; break;
626 : }
627 0 : if ( nSelection == 5 ) // custom spacing
628 : {
629 0 : Sequence< PropertyValue > aArgs( 1 );
630 0 : aArgs[0].Name = msFontworkCharacterSpacing.copy(5);
631 0 : aArgs[0].Value <<= (sal_Int32)nCharacterSpacing;
632 :
633 0 : mrController.dispatchCommand( OUString( ".uno:FontworkCharacterSpacingDialog" ), aArgs );
634 : }
635 0 : else if ( nSelection == 6 ) // KernCharacterPairs
636 : {
637 0 : Sequence< PropertyValue > aArgs( 1 );
638 0 : aArgs[0].Name = msFontworkKernCharacterPairs.copy(5);
639 0 : aArgs[0].Value <<= (sal_Bool) sal_True;
640 :
641 0 : mrController.dispatchCommand( msFontworkKernCharacterPairs, aArgs );
642 :
643 0 : implSetKernCharacterPairs( sal_True, true );
644 : }
645 0 : else if( nSelection >= 0 )
646 : {
647 0 : Sequence< PropertyValue > aArgs( 1 );
648 0 : aArgs[0].Name = msFontworkCharacterSpacing.copy(5);
649 0 : aArgs[0].Value <<=( sal_Int32)nCharacterSpacing;
650 :
651 0 : mrController.dispatchCommand( msFontworkCharacterSpacing, aArgs );
652 :
653 0 : implSetCharacterSpacing( nCharacterSpacing, true );
654 : }
655 :
656 0 : return 0;
657 : }
658 :
659 : // ========================================================================
660 : // FontworkCharacterSpacingControl
661 : // ========================================================================
662 :
663 0 : class FontworkCharacterSpacingControl : public svt::PopupWindowController
664 : {
665 : public:
666 : FontworkCharacterSpacingControl( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rxContext );
667 :
668 : virtual ::Window* createPopupWindow( ::Window* pParent );
669 :
670 : // XServiceInfo
671 : virtual OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException );
672 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException );
673 :
674 : using svt::PopupWindowController::createPopupWindow;
675 : };
676 :
677 :
678 0 : FontworkCharacterSpacingControl::FontworkCharacterSpacingControl( const Reference< XComponentContext >& rxContext )
679 0 : : svt::PopupWindowController( rxContext, Reference< frame::XFrame >(), OUString( ".uno:FontworkCharacterSpacingFloater" ) )
680 : {
681 0 : }
682 :
683 : // -----------------------------------------------------------------------
684 :
685 0 : ::Window* FontworkCharacterSpacingControl::createPopupWindow( ::Window* pParent )
686 : {
687 0 : return new FontworkCharacterSpacingWindow( *this, m_xFrame, pParent );
688 : }
689 :
690 : // -----------------------------------------------------------------------
691 : // XServiceInfo
692 : // -----------------------------------------------------------------------
693 :
694 0 : OUString SAL_CALL FontworkCharacterSpacingControl_getImplementationName()
695 : {
696 0 : return OUString( "com.sun.star.comp.svx.FontworkCharacterSpacingController" );
697 : }
698 :
699 : // --------------------------------------------------------------------
700 :
701 0 : Sequence< OUString > SAL_CALL FontworkCharacterSpacingControl_getSupportedServiceNames() throw( RuntimeException )
702 : {
703 0 : Sequence< OUString > aSNS( 1 );
704 0 : aSNS.getArray()[0] = OUString( "com.sun.star.frame.ToolbarController" );
705 0 : return aSNS;
706 : }
707 :
708 : // --------------------------------------------------------------------
709 :
710 0 : Reference< XInterface > SAL_CALL SAL_CALL FontworkCharacterSpacingControl_createInstance( const Reference< XMultiServiceFactory >& rSMgr ) throw( RuntimeException )
711 : {
712 0 : return *new FontworkCharacterSpacingControl( comphelper::getComponentContext(rSMgr) );
713 : }
714 :
715 : // --------------------------------------------------------------------
716 :
717 0 : OUString SAL_CALL FontworkCharacterSpacingControl::getImplementationName( ) throw (RuntimeException)
718 : {
719 0 : return FontworkCharacterSpacingControl_getImplementationName();
720 : }
721 :
722 : // --------------------------------------------------------------------
723 :
724 0 : Sequence< OUString > SAL_CALL FontworkCharacterSpacingControl::getSupportedServiceNames( ) throw (RuntimeException)
725 : {
726 0 : return FontworkCharacterSpacingControl_getSupportedServiceNames();
727 : }
728 :
729 : // ========================================================================
730 : // FontworkCharacterSpacingDialog
731 : // ========================================================================
732 :
733 0 : FontworkCharacterSpacingDialog::FontworkCharacterSpacingDialog( Window* pParent, sal_Int32 nScale )
734 0 : : ModalDialog( pParent, SVX_RES( RID_SVX_MDLG_FONTWORK_CHARSPACING ) ),
735 0 : maFLScale( this, SVX_RES( FT_VALUE ) ),
736 0 : maMtrScale( this, SVX_RES( MF_VALUE ) ),
737 0 : maOKButton( this, SVX_RES( BTN_OK ) ),
738 0 : maCancelButton( this, SVX_RES( BTN_CANCEL ) ),
739 0 : maHelpButton( this, SVX_RES( BTN_HELP ) )
740 : {
741 0 : maMtrScale.SetValue( nScale );
742 0 : FreeResource();
743 0 : }
744 :
745 0 : FontworkCharacterSpacingDialog::~FontworkCharacterSpacingDialog()
746 : {
747 0 : }
748 :
749 0 : sal_Int32 FontworkCharacterSpacingDialog::getScale() const
750 : {
751 0 : return (sal_Int32)maMtrScale.GetValue();
752 : }
753 :
754 258 : }
755 :
756 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|