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