bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / tbxctrls / tbcontrl.cxx
blob62f2ee2b999dafb892085437f8fa5e1a684b3df4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <string>
21 #include <tools/shl.hxx>
22 #include <tools/color.hxx>
23 #include <svl/poolitem.hxx>
24 #include <svl/eitem.hxx>
25 #include <svl/itemset.hxx>
26 #include <vcl/toolbox.hxx>
27 #include <vcl/bmpacc.hxx>
28 #include <svtools/valueset.hxx>
29 #include <svtools/ctrlbox.hxx>
30 #include <svl/style.hxx>
31 #include <svtools/ctrltool.hxx>
32 #include <svtools/borderhelper.hxx>
33 #include <svl/stritem.hxx>
34 #include <unotools/pathoptions.hxx>
35 #include <sfx2/tplpitem.hxx>
36 #include <sfx2/dispatch.hxx>
37 #include <sfx2/viewsh.hxx>
38 #include <sfx2/objsh.hxx>
39 #include <sfx2/docfac.hxx>
40 #include <sfx2/templdlg.hxx>
41 #include <svl/isethint.hxx>
42 #include <sfx2/querystatus.hxx>
43 #include <sfx2/sfxstatuslistener.hxx>
44 #include <tools/urlobj.hxx>
45 #include <sfx2/childwin.hxx>
46 #include <sfx2/viewfrm.hxx>
47 #include <unotools/fontoptions.hxx>
48 #include <vcl/mnemonic.hxx>
49 #include <vcl/svapp.hxx>
50 #include <svl/smplhint.hxx>
51 #include <svtools/colorcfg.hxx>
52 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
53 #include <com/sun/star/lang/XServiceInfo.hpp>
54 #include <com/sun/star/beans/XPropertySet.hpp>
55 #include <com/sun/star/frame/status/ItemStatus.hpp>
56 #include <svx/dialogs.hrc>
57 #include <svx/svxitems.hrc>
58 #include "helpid.hrc"
59 #include <sfx2/htmlmode.hxx>
60 #include <svx/xtable.hxx>
61 #include <editeng/fontitem.hxx>
62 #include <editeng/fhgtitem.hxx>
63 #include <editeng/brushitem.hxx>
64 #include <editeng/boxitem.hxx>
65 #include <editeng/charreliefitem.hxx>
66 #include <editeng/contouritem.hxx>
67 #include <editeng/colritem.hxx>
68 #include <editeng/crossedoutitem.hxx>
69 #include <editeng/emphasismarkitem.hxx>
70 #include <editeng/flstitem.hxx>
71 #include <editeng/lineitem.hxx>
72 #include <editeng/postitem.hxx>
73 #include <editeng/shdditem.hxx>
74 #include <editeng/udlnitem.hxx>
75 #include <editeng/wghtitem.hxx>
76 #include "svx/drawitem.hxx"
77 #include <svx/tbcontrl.hxx>
78 #include "svx/dlgutil.hxx"
79 #include <svx/dialmgr.hxx>
80 #include "colorwindow.hxx"
81 #include <memory>
83 #include <svx/framelink.hxx>
84 #include <svx/tbxcolorupdate.hxx>
85 #include <editeng/eerdll.hxx>
86 #include <editeng/editrids.hrc>
88 // ------------------------------------------------------------------------
90 #define MAX_MRU_FONTNAME_ENTRIES 5
91 #define LOGICAL_EDIT_HEIGHT 12
93 // STATIC DATA -----------------------------------------------------------
95 #ifndef DELETEZ
96 #define DELETEZ(p) (delete (p), (p)=NULL)
97 #endif
98 // don't make more than 15 entries visible at once
99 #define MAX_STYLES_ENTRIES static_cast< sal_uInt16 >( 15 )
101 static void lcl_ResizeValueSet( Window &rWin, ValueSet &rValueSet );
102 static void lcl_CalcSizeValueSet( Window &rWin, ValueSet &rValueSet, const Size &aItemSize );
104 // namespaces
105 using namespace ::editeng;
106 using namespace ::com::sun::star;
107 using namespace ::com::sun::star::uno;
108 using namespace ::com::sun::star::frame;
109 using namespace ::com::sun::star::beans;
110 using namespace ::com::sun::star::lang;
112 SFX_IMPL_TOOLBOX_CONTROL( SvxStyleToolBoxControl, SfxTemplateItem );
113 SFX_IMPL_TOOLBOX_CONTROL( SvxFontNameToolBoxControl, SvxFontItem );
114 SFX_IMPL_TOOLBOX_CONTROL( SvxFontColorToolBoxControl, SvxColorItem );
115 SFX_IMPL_TOOLBOX_CONTROL( SvxColorExtToolBoxControl, SvxColorItem );
116 SFX_IMPL_TOOLBOX_CONTROL( SvxFrameToolBoxControl, SvxBoxItem );
117 SFX_IMPL_TOOLBOX_CONTROL( SvxFrameLineStyleToolBoxControl, SvxLineItem );
118 SFX_IMPL_TOOLBOX_CONTROL( SvxFrameLineColorToolBoxControl, SvxColorItem );
119 SFX_IMPL_TOOLBOX_CONTROL( SvxSimpleUndoRedoController, SfxStringItem );
121 //========================================================================
122 // class SvxStyleBox_Impl -----------------------------------------------------
123 //========================================================================
126 class SvxStyleBox_Impl : public ComboBox
128 using Window::IsVisible;
129 public:
130 SvxStyleBox_Impl( Window* pParent, const OUString& rCommand, SfxStyleFamily eFamily, const Reference< XDispatchProvider >& rDispatchProvider,
131 const Reference< XFrame >& _xFrame,const String& rClearFormatKey, const String& rMoreKey, bool bInSpecialMode );
132 ~SvxStyleBox_Impl();
134 void SetFamily( SfxStyleFamily eNewFamily );
135 inline bool IsVisible() { return bVisible; }
137 virtual long PreNotify( NotifyEvent& rNEvt );
138 virtual long Notify( NotifyEvent& rNEvt );
139 virtual void DataChanged( const DataChangedEvent& rDCEvt );
140 virtual void StateChanged( StateChangedType nStateChange );
142 virtual void UserDraw( const UserDrawEvent& rUDEvt );
144 inline void SetVisibilityListener( const Link& aVisListener ) { aVisibilityListener = aVisListener; }
145 inline void RemoveVisibilityListener() { aVisibilityListener = Link(); }
147 void SetDefaultStyle( const OUString& rDefault ) { sDefaultStyle = rDefault; }
148 DECL_STATIC_LINK( SvxStyleBox_Impl, FocusHdl_Impl, Control* );
150 protected:
151 virtual void Select();
153 private:
154 SfxStyleFamily eStyleFamily;
155 sal_uInt16 nCurSel;
156 bool bRelease;
157 Size aLogicalSize;
158 Link aVisibilityListener;
159 bool bVisible;
160 Reference< XDispatchProvider > m_xDispatchProvider;
161 Reference< XFrame > m_xFrame;
162 OUString m_aCommand;
163 String aClearFormatKey;
164 String aMoreKey;
165 String sDefaultStyle;
166 bool bInSpecialMode;
168 void ReleaseFocus();
171 //========================================================================
172 // class SvxFontNameBox --------------------------------------------------
173 //========================================================================
175 class SvxFontNameBox_Impl : public FontNameBox
177 using Window::Update;
178 private:
179 const FontList* pFontList;
180 SAL_WNODEPRECATED_DECLARATIONS_PUSH
181 ::std::auto_ptr<FontList> m_aOwnFontList;
182 SAL_WNODEPRECATED_DECLARATIONS_POP
183 Font aCurFont;
184 Size aLogicalSize;
185 String aCurText;
186 sal_uInt16 nFtCount;
187 bool bRelease;
188 Reference< XDispatchProvider > m_xDispatchProvider;
189 Reference< XFrame > m_xFrame;
190 bool mbEndPreview;
192 void ReleaseFocus_Impl();
193 void EnableControls_Impl();
195 void EndPreview()
197 Sequence< PropertyValue > aArgs;
198 SfxToolBoxControl::Dispatch( m_xDispatchProvider,
199 OUString( ".uno:CharEndPreviewFontName" ),
200 aArgs );
202 DECL_DLLPRIVATE_LINK( CheckAndMarkUnknownFont, VclWindowEvent* );
204 protected:
205 virtual void Select();
206 virtual void DataChanged( const DataChangedEvent& rDCEvt );
208 public:
209 SvxFontNameBox_Impl( Window* pParent, const Reference< XDispatchProvider >& rDispatchProvider,const Reference< XFrame >& _xFrame
210 , WinBits nStyle = WB_SORT
212 virtual ~SvxFontNameBox_Impl();
214 void FillList();
215 void Update( const SvxFontItem* pFontItem );
216 sal_uInt16 GetListCount() { return nFtCount; }
217 void Clear() { FontNameBox::Clear(); nFtCount = 0; }
218 void Fill( const FontList* pList )
219 { FontNameBox::Fill( pList );
220 nFtCount = pList->GetFontNameCount(); }
221 virtual void UserDraw( const UserDrawEvent& rUDEvt );
222 virtual long PreNotify( NotifyEvent& rNEvt );
223 virtual long Notify( NotifyEvent& rNEvt );
224 virtual Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible();
225 SAL_WNODEPRECATED_DECLARATIONS_PUSH
226 void SetOwnFontList(::std::auto_ptr<FontList> _aOwnFontList) { m_aOwnFontList = _aOwnFontList; }
227 SAL_WNODEPRECATED_DECLARATIONS_POP
230 //========================================================================
231 // class SvxFrameWindow_Impl --------------------------------------------------
232 //========================================================================
234 // SelectHdl needs the Modifiers, get them in MouseButtonUp
236 class SvxFrmValueSet_Impl : public ValueSet
238 sal_uInt16 nModifier;
239 virtual void MouseButtonUp( const MouseEvent& rMEvt );
240 public:
241 SvxFrmValueSet_Impl(Window* pParent, WinBits nWinStyle)
242 : ValueSet(pParent, nWinStyle), nModifier(0) {}
243 sal_uInt16 GetModifier() const {return nModifier;}
247 void SvxFrmValueSet_Impl::MouseButtonUp( const MouseEvent& rMEvt )
249 nModifier = rMEvt.GetModifier();
250 ValueSet::MouseButtonUp(rMEvt);
253 class SvxFrameWindow_Impl : public SfxPopupWindow
255 using FloatingWindow::StateChanged;
257 private:
258 SvxFrmValueSet_Impl aFrameSet;
259 ImageList aImgList;
260 sal_Bool bParagraphMode;
262 DECL_LINK( SelectHdl, void * );
264 protected:
265 virtual void Resize();
266 virtual sal_Bool Close();
267 virtual Window* GetPreferredKeyInputWindow();
268 virtual void GetFocus();
270 public:
271 SvxFrameWindow_Impl( sal_uInt16 nId, const Reference< XFrame >& rFrame, Window* pParentWindow );
272 ~SvxFrameWindow_Impl();
273 void StartSelection();
275 virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState,
276 const SfxPoolItem* pState );
277 virtual SfxPopupWindow* Clone() const;
278 virtual void DataChanged( const DataChangedEvent& rDCEvt );
281 //========================================================================
282 // class SvxLineWindow_Impl ---------------------------------------------------
283 //========================================================================
284 class SvxLineWindow_Impl : public SfxPopupWindow
286 private:
287 LineListBox m_aLineStyleLb;
288 bool m_bIsWriter;
290 DECL_LINK( SelectHdl, void * );
292 protected:
293 virtual void Resize();
294 virtual sal_Bool Close();
295 virtual Window* GetPreferredKeyInputWindow();
296 virtual void GetFocus();
297 virtual void DataChanged( const DataChangedEvent& rDCEvt );
298 public:
299 SvxLineWindow_Impl( sal_uInt16 nId, const Reference< XFrame >& rFrame, Window* pParentWindow );
301 virtual SfxPopupWindow* Clone() const;
304 //########################################################################
305 // Helper classes:
306 //========================================================================
307 // class SfxStyleControllerItem ------------------------------------------
308 //========================================================================
309 class SvxStyleToolBoxControl;
311 class SfxStyleControllerItem_Impl : public SfxStatusListener
313 public:
314 SfxStyleControllerItem_Impl( const Reference< XDispatchProvider >& rDispatchProvider,
315 sal_uInt16 nSlotId,
316 const OUString& rCommand,
317 SvxStyleToolBoxControl& rTbxCtl );
319 protected:
320 virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState );
322 private:
323 SvxStyleToolBoxControl& rControl;
326 //========================================================================
327 // class SvxStyleBox_Impl -----------------------------------------------------
328 //========================================================================
330 SvxStyleBox_Impl::SvxStyleBox_Impl(
331 Window* pParent,
332 const OUString& rCommand,
333 SfxStyleFamily eFamily,
334 const Reference< XDispatchProvider >& rDispatchProvider,
335 const Reference< XFrame >& _xFrame,
336 const String& rClearFormatKey,
337 const String& rMoreKey,
338 bool bInSpec) :
340 ComboBox( pParent, SVX_RES( RID_SVXTBX_STYLE ) ),
342 eStyleFamily( eFamily ),
343 bRelease ( true ),
344 bVisible(false),
345 m_xDispatchProvider( rDispatchProvider ),
346 m_xFrame(_xFrame),
347 m_aCommand ( rCommand ),
348 aClearFormatKey ( rClearFormatKey ),
349 aMoreKey ( rMoreKey ),
350 bInSpecialMode ( bInSpec )
352 aLogicalSize = PixelToLogic( GetSizePixel(), MAP_APPFONT );
353 EnableAutocomplete( sal_True );
354 EnableUserDraw( true );
355 SetUserItemSize( Size( 0, 30 ) );
358 SvxStyleBox_Impl::~SvxStyleBox_Impl()
362 // -----------------------------------------------------------------------
364 void SvxStyleBox_Impl::ReleaseFocus()
366 if ( !bRelease )
368 bRelease = true;
369 return;
371 if ( m_xFrame.is() && m_xFrame->getContainerWindow().is() )
372 m_xFrame->getContainerWindow()->setFocus();
375 // -----------------------------------------------------------------------
377 void SvxStyleBox_Impl::Select()
379 // Tell base class about selection so that AT get informed about it.
380 ComboBox::Select();
382 if ( !IsTravelSelect() )
384 OUString aSearchEntry( GetText() );
385 bool bDoIt = true, bClear = false;
386 if( bInSpecialMode )
388 if( aSearchEntry == aClearFormatKey && GetSelectEntryPos() == 0 )
390 aSearchEntry = sDefaultStyle;
391 bClear = true;
392 //not only apply default style but also call 'ClearFormatting'
393 Sequence< PropertyValue > aEmptyVals;
394 SfxToolBoxControl::Dispatch( m_xDispatchProvider, OUString(".uno:ResetAttributes"),
395 aEmptyVals);
397 else if( aSearchEntry == aMoreKey && GetSelectEntryPos() == ( GetEntryCount() - 1 ) )
399 SfxViewFrame* pViewFrm = SfxViewFrame::Current();
400 DBG_ASSERT( pViewFrm, "SvxStyleBox_Impl::Select(): no viewframe" );
401 pViewFrm->ShowChildWindow( SID_STYLE_DESIGNER );
402 SfxChildWindow* pChildWin = pViewFrm->GetChildWindow( SID_STYLE_DESIGNER );
403 if ( pChildWin && pChildWin->GetWindow() )
405 static_cast< SfxTemplateDialogWrapper* >( pChildWin )->SetParagraphFamily();
406 static_cast< SfxDockingWindow* >( pChildWin->GetWindow() )->AutoShow( sal_True );
407 Application::PostUserEvent(
408 STATIC_LINK( 0, SvxStyleBox_Impl, FocusHdl_Impl ), pChildWin->GetWindow() );
410 bDoIt = false;
414 //Do we need to create a new style?
415 SfxObjectShell *pShell = SfxObjectShell::Current();
416 SfxStyleSheetBasePool* pPool = pShell->GetStyleSheetPool();
417 SfxStyleSheetBase* pStyle = NULL;
419 bool bCreateNew = 0;
421 if ( pPool )
423 pPool->SetSearchMask( eStyleFamily, SFXSTYLEBIT_ALL );
425 pStyle = pPool->First();
426 while ( pStyle && OUString( pStyle->GetName() ) != aSearchEntry )
427 pStyle = pPool->Next();
430 if ( !pStyle )
432 // cannot find the style for whatever reason
433 // therefore create a new style
434 bCreateNew = 1;
437 /* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
438 This instance may be deleted in the meantime (i.e. when a dialog is opened
439 while in Dispatch()), accessing members will crash in this case. */
440 ReleaseFocus();
442 if( bDoIt )
444 if ( bClear )
445 SetText( aSearchEntry );
446 SaveValue();
448 Sequence< PropertyValue > aArgs( 2 );
449 aArgs[0].Value = makeAny( OUString( aSearchEntry ) );
450 aArgs[1].Name = OUString("Family");
451 aArgs[1].Value = makeAny( sal_Int16( eStyleFamily ));
452 if( bCreateNew )
454 aArgs[0].Name = OUString("Param");
455 SfxToolBoxControl::Dispatch( m_xDispatchProvider, OUString(".uno:StyleNewByExample"), aArgs);
457 else
459 aArgs[0].Name = OUString("Template");
460 SfxToolBoxControl::Dispatch( m_xDispatchProvider, m_aCommand, aArgs );
465 // -----------------------------------------------------------------------
467 void SvxStyleBox_Impl::SetFamily( SfxStyleFamily eNewFamily )
469 eStyleFamily = eNewFamily;
472 // -----------------------------------------------------------------------
474 long SvxStyleBox_Impl::PreNotify( NotifyEvent& rNEvt )
476 sal_uInt16 nType = rNEvt.GetType();
478 if ( EVENT_MOUSEBUTTONDOWN == nType || EVENT_GETFOCUS == nType )
479 nCurSel = GetSelectEntryPos();
480 else if ( EVENT_LOSEFOCUS == nType )
482 // don't handle before our Select() is called
483 if ( !HasFocus() && !HasChildPathFocus() )
484 SetText( GetSavedValue() );
486 return ComboBox::PreNotify( rNEvt );
489 // -----------------------------------------------------------------------
491 long SvxStyleBox_Impl::Notify( NotifyEvent& rNEvt )
493 long nHandled = 0;
495 if ( rNEvt.GetType() == EVENT_KEYINPUT )
497 sal_uInt16 nCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
499 switch ( nCode )
501 case KEY_RETURN:
502 case KEY_TAB:
504 if ( KEY_TAB == nCode )
505 bRelease = false;
506 else
507 nHandled = 1;
508 Select();
509 break;
512 case KEY_ESCAPE:
513 SelectEntryPos( nCurSel );
514 ReleaseFocus();
515 nHandled = 1;
516 break;
519 return nHandled ? nHandled : ComboBox::Notify( rNEvt );
522 void SvxStyleBox_Impl::DataChanged( const DataChangedEvent& rDCEvt )
524 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
525 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
527 SetSizePixel(LogicToPixel(aLogicalSize, MAP_APPFONT));
528 Size aDropSize( aLogicalSize.Width(), LOGICAL_EDIT_HEIGHT);
529 SetDropDownSizePixel(LogicToPixel(aDropSize, MAP_APPFONT));
532 ComboBox::DataChanged( rDCEvt );
535 void SvxStyleBox_Impl::StateChanged( StateChangedType nStateChange )
537 ComboBox::StateChanged( nStateChange );
539 if ( nStateChange == STATE_CHANGE_VISIBLE )
541 bVisible = IsReallyVisible();
542 if ( aVisibilityListener.IsSet() )
543 aVisibilityListener.Call( this );
545 else if ( nStateChange == STATE_CHANGE_INITSHOW )
547 bVisible = true;
548 if ( aVisibilityListener.IsSet() )
549 aVisibilityListener.Call( this );
553 void SvxStyleBox_Impl::UserDraw( const UserDrawEvent& rUDEvt )
555 sal_uInt16 nItem = rUDEvt.GetItemId();
557 if ( nItem == 0 || nItem == GetEntryCount() - 1 )
559 // draw the non-style entries, ie. "Clear Formatting" or "More..."
560 DrawEntry( rUDEvt, true, true );
562 else
564 SfxObjectShell *pShell = SfxObjectShell::Current();
565 SfxStyleSheetBasePool* pPool = pShell->GetStyleSheetPool();
566 SfxStyleSheetBase* pStyle = NULL;
568 OUString aStyleName( GetEntry( nItem ) );
570 if ( pPool )
572 pPool->SetSearchMask( eStyleFamily, SFXSTYLEBIT_ALL );
574 pStyle = pPool->First();
575 while ( pStyle && OUString( pStyle->GetName() ) != aStyleName )
576 pStyle = pPool->Next();
579 if ( !pStyle )
581 // cannot find the style for whatever reason
582 DrawEntry( rUDEvt, true, true );
584 else
586 const SfxItemSet& aItemSet = pStyle->GetItemSet();
588 const SvxFontItem *pFontItem = static_cast< const SvxFontItem* >( aItemSet.GetItem( SID_ATTR_CHAR_FONT ) );
589 const SvxFontHeightItem *pFontHeightItem = static_cast< const SvxFontHeightItem* >( aItemSet.GetItem( SID_ATTR_CHAR_FONTHEIGHT ) );
591 if ( pFontItem && pFontHeightItem )
593 OutputDevice *pDevice = rUDEvt.GetDevice();
595 Size aFontSize( 0, pFontHeightItem->GetHeight() );
596 Size aPixelSize( pDevice->LogicToPixel( aFontSize, pShell->GetMapUnit() ) );
598 // setup the font properties
599 Font aFont( pFontItem->GetFamilyName(), pFontItem->GetStyleName(), aPixelSize );
601 const SfxPoolItem *pItem = aItemSet.GetItem( SID_ATTR_CHAR_WEIGHT );
602 if ( pItem )
603 aFont.SetWeight( static_cast< const SvxWeightItem* >( pItem )->GetWeight() );
605 pItem = aItemSet.GetItem( SID_ATTR_CHAR_POSTURE );
606 if ( pItem )
607 aFont.SetItalic( static_cast< const SvxPostureItem* >( pItem )->GetPosture() );
609 pItem = aItemSet.GetItem( SID_ATTR_CHAR_CONTOUR );
610 if ( pItem )
611 aFont.SetOutline( static_cast< const SvxContourItem* >( pItem )->GetValue() );
613 pItem = aItemSet.GetItem( SID_ATTR_CHAR_SHADOWED );
614 if ( pItem )
615 aFont.SetShadow( static_cast< const SvxShadowedItem* >( pItem )->GetValue() );
617 pItem = aItemSet.GetItem( SID_ATTR_CHAR_RELIEF );
618 if ( pItem )
619 aFont.SetRelief( static_cast< FontRelief >( static_cast< const SvxCharReliefItem* >( pItem )->GetValue() ) );
621 pItem = aItemSet.GetItem( SID_ATTR_CHAR_UNDERLINE );
622 if ( pItem )
623 aFont.SetUnderline( static_cast< const SvxUnderlineItem* >( pItem )->GetLineStyle() );
625 pItem = aItemSet.GetItem( SID_ATTR_CHAR_OVERLINE );
626 if ( pItem )
627 aFont.SetOverline( static_cast< FontUnderline >( static_cast< const SvxOverlineItem* >( pItem )->GetValue() ) );
629 pItem = aItemSet.GetItem( SID_ATTR_CHAR_STRIKEOUT );
630 if ( pItem )
631 aFont.SetStrikeout( static_cast< const SvxCrossedOutItem* >( pItem )->GetStrikeout() );
633 pItem = aItemSet.GetItem( SID_ATTR_CHAR_EMPHASISMARK );
634 if ( pItem )
635 aFont.SetEmphasisMark( static_cast< const SvxEmphasisMarkItem* >( pItem )->GetEmphasisMark() );
637 // setup the device & draw
638 Font aOldFont( pDevice->GetFont() );
639 Color aOldColor( pDevice->GetTextColor() );
640 Color aOldFillColor( pDevice->GetFillColor() );
642 pDevice->SetFont( aFont );
644 // text color, when we are not selected
645 pItem = aItemSet.GetItem( SID_ATTR_CHAR_COLOR );
646 if ( pItem && rUDEvt.GetItemId() != GetSelectEntryPos() )
648 Color aColor( static_cast< const SvxColorItem* >( pItem )->GetValue() );
649 if ( aColor != COL_AUTO )
650 pDevice->SetTextColor( aColor );
653 // background color
654 pItem = aItemSet.GetItem( SID_ATTR_BRUSH );
655 if ( pItem && rUDEvt.GetItemId() != GetSelectEntryPos() )
657 Color aColor( static_cast< const SvxBrushItem* >( pItem )->GetColor() );
658 if ( aColor != COL_AUTO )
660 pDevice->SetFillColor( aColor );
661 pDevice->DrawRect( rUDEvt.GetRect() );
665 // IMG_TXT_DISTANCE in ilstbox.hxx is 6, then 1 is added as
666 // nBorder, and we are adding 1 in order to look better when
667 // italics is present
668 const int nLeftDistance = 8;
670 Rectangle aTextRect;
671 pDevice->GetTextBoundRect( aTextRect, aStyleName );
673 Point aPos( rUDEvt.GetRect().TopLeft() );
674 aPos.X() += nLeftDistance;
675 if ( aTextRect.Bottom() > rUDEvt.GetRect().GetHeight() )
677 // the text does not fit, adjust the font size
678 double ratio = static_cast< double >( rUDEvt.GetRect().GetHeight() ) / aTextRect.Bottom();
679 aPixelSize.Width() *= ratio;
680 aPixelSize.Height() *= ratio;
681 aFont.SetSize( aPixelSize );
682 pDevice->SetFont( aFont );
684 else
685 aPos.Y() += ( rUDEvt.GetRect().GetHeight() - aTextRect.Bottom() ) / 2;
687 pDevice->DrawText( aPos, aStyleName );
689 pDevice->SetFillColor( aOldFillColor );
690 pDevice->SetTextColor( aOldColor );
691 pDevice->SetFont( aOldFont );
693 // draw separator, if present
694 DrawEntry( rUDEvt, false, false );
696 else
697 DrawEntry( rUDEvt, true, true );
702 //--------------------------------------------------------------------
704 IMPL_STATIC_LINK( SvxStyleBox_Impl, FocusHdl_Impl, Control*, _pCtrl )
706 (void)pThis;
707 if ( _pCtrl )
708 _pCtrl->GrabFocus();
709 return 0;
712 // -----------------------------------------------------------------------
714 static bool lcl_GetDocFontList( const FontList** ppFontList, SvxFontNameBox_Impl* pBox )
716 bool bChanged = false;
717 const SfxObjectShell* pDocSh = SfxObjectShell::Current();
718 SvxFontListItem* pFontListItem = NULL;
720 if ( pDocSh )
721 pFontListItem =
722 (SvxFontListItem*)pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST );
723 else
725 SAL_WNODEPRECATED_DECLARATIONS_PUSH
726 ::std::auto_ptr<FontList> aFontList(new FontList( pBox ));
727 SAL_WNODEPRECATED_DECLARATIONS_POP
728 *ppFontList = aFontList.get();
729 pBox->SetOwnFontList(aFontList);
730 bChanged = true;
733 if ( pFontListItem )
735 const FontList* pNewFontList = pFontListItem->GetFontList();
736 DBG_ASSERT( pNewFontList, "Doc-FontList not available!" );
738 // No old list, but a new list
739 if ( !*ppFontList && pNewFontList )
741 // => take over
742 *ppFontList = pNewFontList;
743 bChanged = true;
745 else
747 // Comparing the font lists is not perfect.
748 // When you change the font list in the Doc, you can track
749 // changes here only on the Listbox, because ppFontList
750 // has already been updated.
751 bChanged =
752 ( ( *ppFontList != pNewFontList ) ||
753 pBox->GetListCount() != pNewFontList->GetFontNameCount() );
754 // HACK: Comparing is incomplete
756 if ( bChanged )
757 *ppFontList = pNewFontList;
760 if ( pBox )
761 pBox->Enable();
763 else if ( pBox && ( pDocSh || ( !pDocSh && !ppFontList )))
765 // Disable box only when we have a SfxObjectShell and didn't get a font list OR
766 // we don't have a SfxObjectShell and no current font list.
767 // It's possible that we currently have no SfxObjectShell, but a current font list.
768 // See #i58471: When a user set the focus into the font name combo box and opens
769 // the help window with F1. After closing the help window, we disable the font name
770 // combo box. The SfxObjectShell::Current() method returns in that case zero. But the
771 // font list hasn't changed and therefore the combo box shouldn't be disabled!
772 pBox->Disable();
775 // Fill the FontBox, also the new list if necessary
776 if ( pBox && bChanged )
778 if ( *ppFontList )
779 pBox->Fill( *ppFontList );
780 else
781 pBox->Clear();
783 return bChanged;
786 //========================================================================
787 // class SvxFontNameBox_Impl --------------------------------------------------
788 //========================================================================
790 SvxFontNameBox_Impl::SvxFontNameBox_Impl( Window* pParent, const Reference< XDispatchProvider >& rDispatchProvider,const Reference< XFrame >& _xFrame, WinBits nStyle ) :
792 FontNameBox ( pParent, nStyle | WinBits( WB_DROPDOWN | WB_AUTOHSCROLL ) ),
793 pFontList ( NULL ),
794 aLogicalSize ( 60,160 ),
795 nFtCount ( 0 ),
796 bRelease ( true ),
797 m_xDispatchProvider( rDispatchProvider ),
798 m_xFrame (_xFrame),
799 mbEndPreview(false)
801 SetSizePixel(LogicToPixel( aLogicalSize, MAP_APPFONT ));
802 EnableControls_Impl();
803 GetSubEdit()->AddEventListener( LINK( this, SvxFontNameBox_Impl, CheckAndMarkUnknownFont ));
806 SvxFontNameBox_Impl::~SvxFontNameBox_Impl()
808 GetSubEdit()->RemoveEventListener( LINK( this, SvxFontNameBox_Impl, CheckAndMarkUnknownFont ));
811 // -----------------------------------------------------------------------
813 void SvxFontNameBox_Impl::FillList()
815 // Save old Selection, set back in the end
816 Selection aOldSel = GetSelection();
817 // Did Doc-Fontlist change?
818 lcl_GetDocFontList( &pFontList, this );
819 aCurText = GetText();
820 SetSelection( aOldSel );
823 IMPL_LINK( SvxFontNameBox_Impl, CheckAndMarkUnknownFont, VclWindowEvent*, event )
825 if( event->GetId() != VCLEVENT_EDIT_MODIFY )
826 return 0;
827 OUString fontname = GetSubEdit()->GetText();
828 lcl_GetDocFontList( &pFontList, this );
829 // If the font is unknown, show it in italic.
830 Font font = GetControlFont();
831 if( pFontList != NULL && pFontList->IsAvailable( fontname ))
833 if( font.GetItalic() != ITALIC_NONE )
835 font.SetItalic( ITALIC_NONE );
836 SetControlFont( font );
837 SetQuickHelpText( SVX_RESSTR( RID_SVXSTR_CHARFONTNAME ));
840 else
842 if( font.GetItalic() != ITALIC_NORMAL )
844 font.SetItalic( ITALIC_NORMAL );
845 SetControlFont( font );
846 SetQuickHelpText( SVX_RESSTR( RID_SVXSTR_CHARFONTNAME_NOTAVAILABLE ));
849 return 0;
852 // -----------------------------------------------------------------------
854 void SvxFontNameBox_Impl::Update( const SvxFontItem* pFontItem )
856 if ( pFontItem )
858 aCurFont.SetName ( pFontItem->GetFamilyName() );
859 aCurFont.SetFamily ( pFontItem->GetFamily() );
860 aCurFont.SetStyleName ( pFontItem->GetStyleName() );
861 aCurFont.SetPitch ( pFontItem->GetPitch() );
862 aCurFont.SetCharSet ( pFontItem->GetCharSet() );
864 OUString aCurName = aCurFont.GetName();
865 if ( GetText() != aCurName )
866 SetText( aCurName );
869 // -----------------------------------------------------------------------
871 long SvxFontNameBox_Impl::PreNotify( NotifyEvent& rNEvt )
873 sal_uInt16 nType = rNEvt.GetType();
875 if ( EVENT_MOUSEBUTTONDOWN == nType || EVENT_GETFOCUS == nType )
877 EnableControls_Impl();
878 FillList();
880 return FontNameBox::PreNotify( rNEvt );
883 // -----------------------------------------------------------------------
885 long SvxFontNameBox_Impl::Notify( NotifyEvent& rNEvt )
887 long nHandled = 0;
888 mbEndPreview = false;
889 if ( rNEvt.GetType() == EVENT_KEYUP )
890 mbEndPreview = true;
892 if ( rNEvt.GetType() == EVENT_KEYINPUT )
894 sal_uInt16 nCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
896 switch ( nCode )
898 case KEY_RETURN:
899 case KEY_TAB:
901 if ( KEY_TAB == nCode )
902 bRelease = false;
903 else
904 nHandled = 1;
905 Select();
906 break;
909 case KEY_ESCAPE:
910 SetText( aCurText );
911 ReleaseFocus_Impl();
912 EndPreview();
913 break;
916 else if ( EVENT_LOSEFOCUS == rNEvt.GetType() )
918 Window* pFocusWin = Application::GetFocusWindow();
919 if ( !HasFocus() && GetSubEdit() != pFocusWin )
920 SetText( GetSavedValue() );
921 // send EndPreview
922 EndPreview();
925 return nHandled ? nHandled : FontNameBox::Notify( rNEvt );
928 // ---------------------------------------------------------------------------
929 void SvxFontNameBox_Impl::DataChanged( const DataChangedEvent& rDCEvt )
931 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
932 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
934 SetSizePixel(LogicToPixel(aLogicalSize, MAP_APPFONT));
935 Size aDropSize( aLogicalSize.Width(), LOGICAL_EDIT_HEIGHT);
936 SetDropDownSizePixel(LogicToPixel(aDropSize, MAP_APPFONT));
939 FontNameBox::DataChanged( rDCEvt );
942 // -----------------------------------------------------------------------
944 void SvxFontNameBox_Impl::ReleaseFocus_Impl()
946 if ( !bRelease )
948 bRelease = true;
949 return;
951 if ( m_xFrame.is() && m_xFrame->getContainerWindow().is() )
952 m_xFrame->getContainerWindow()->setFocus();
955 // -----------------------------------------------------------------------
957 void SvxFontNameBox_Impl::EnableControls_Impl()
959 SvtFontOptions aFontOpt;
960 sal_Bool bEnable = aFontOpt.IsFontHistoryEnabled();
961 sal_uInt16 nEntries = bEnable ? MAX_MRU_FONTNAME_ENTRIES : 0;
962 if ( GetMaxMRUCount() != nEntries )
964 // refill in the next GetFocus-Handler
965 pFontList = NULL;
966 Clear();
967 SetMaxMRUCount( nEntries );
970 bEnable = aFontOpt.IsFontWYSIWYGEnabled();
971 EnableWYSIWYG( bEnable );
974 // -----------------------------------------------------------------------
976 void SvxFontNameBox_Impl::UserDraw( const UserDrawEvent& rUDEvt )
978 FontNameBox::UserDraw( rUDEvt );
980 // Hack - GetStyle now contains the currently
981 // selected item in the list box
982 // ItemId contains the id of the current item to draw
983 // or select
984 if ( rUDEvt.GetItemId() == rUDEvt.GetStyle() )
986 Sequence< PropertyValue > aArgs( 1 );
987 FontInfo aInfo( pFontList->Get( GetEntry( rUDEvt.GetItemId() ),
988 aCurFont.GetWeight(),
989 aCurFont.GetItalic() ) );
991 SvxFontItem aFontItem( aInfo.GetFamily(),
992 aInfo.GetName(),
993 aInfo.GetStyleName(),
994 aInfo.GetPitch(),
995 aInfo.GetCharSet(),
996 SID_ATTR_CHAR_FONT );
997 aFontItem.QueryValue( aArgs[0].Value );
998 aArgs[0].Name = OUString( "CharPreviewFontName" );
999 SfxToolBoxControl::Dispatch( m_xDispatchProvider,
1000 OUString( ".uno:CharPreviewFontName" ),
1001 aArgs );
1005 void SvxFontNameBox_Impl::Select()
1007 FontNameBox::Select();
1009 Sequence< PropertyValue > aArgs( 1 );
1010 std::auto_ptr<SvxFontItem> pFontItem;
1011 if ( pFontList )
1013 FontInfo aInfo( pFontList->Get( GetText(),
1014 aCurFont.GetWeight(),
1015 aCurFont.GetItalic() ) );
1016 aCurFont = aInfo;
1018 pFontItem.reset( new SvxFontItem( aInfo.GetFamily(),
1019 aInfo.GetName(),
1020 aInfo.GetStyleName(),
1021 aInfo.GetPitch(),
1022 aInfo.GetCharSet(),
1023 SID_ATTR_CHAR_FONT ) );
1025 Any a;
1026 pFontItem->QueryValue( a );
1027 aArgs[0].Value = a;
1029 if ( !IsTravelSelect() )
1031 // #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
1032 // This instance may be deleted in the meantime (i.e. when a dialog is opened
1033 // while in Dispatch()), accessing members will crash in this case.
1034 ReleaseFocus_Impl();
1035 EndPreview();
1036 if ( pFontItem.get() )
1038 aArgs[0].Name = OUString( "CharFontName" );
1039 SfxToolBoxControl::Dispatch( m_xDispatchProvider,
1040 OUString( ".uno:CharFontName" ),
1041 aArgs );
1044 else
1046 if ( mbEndPreview )
1048 EndPreview();
1049 return;
1051 if ( pFontItem.get() )
1053 aArgs[0].Name = OUString( "CharPreviewFontName" );
1054 SfxToolBoxControl::Dispatch( m_xDispatchProvider,
1055 OUString( ".uno:CharPreviewFontName" ),
1056 aArgs );
1061 //========================================================================
1062 // class SvxColorWindow_Impl --------------------------------------------------
1063 //========================================================================
1064 #ifndef WB_NO_DIRECTSELECT
1065 #define WB_NO_DIRECTSELECT ((WinBits)0x04000000)
1066 #endif
1068 SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand,
1069 sal_uInt16 nSlotId,
1070 const Reference< XFrame >& rFrame,
1071 const String& rWndTitle,
1072 Window* pParentWindow,
1073 const ::Color rLastColor ) :
1075 SfxPopupWindow( nSlotId, rFrame, pParentWindow, WinBits( WB_STDPOPUP | WB_OWNERDRAWDECORATION ) ),
1077 theSlotId( nSlotId ),
1078 aColorSet( this, WinBits( WB_ITEMBORDER | WB_NAMEFIELD | WB_3DLOOK | WB_NO_DIRECTSELECT) ),
1079 maCommand( rCommand ),
1080 mLastColor( rLastColor )
1083 SfxObjectShell* pDocSh = SfxObjectShell::Current();
1084 const SfxPoolItem* pItem = NULL;
1085 XColorListRef pColorList;
1087 if ( pDocSh )
1088 if ( 0 != ( pItem = pDocSh->GetItem( SID_COLOR_TABLE ) ) )
1089 pColorList = ( (SvxColorListItem*)pItem )->GetColorList();
1091 if ( !pColorList.is() )
1092 pColorList = XColorList::CreateStdColorList();
1094 if ( SID_ATTR_CHAR_COLOR_BACKGROUND == theSlotId || SID_BACKGROUND_COLOR == theSlotId )
1096 aColorSet.SetStyle( aColorSet.GetStyle() | WB_NONEFIELD );
1097 aColorSet.SetText( SVX_RESSTR( RID_SVXSTR_TRANSPARENT ) );
1098 aColorSet.SetAccessibleName( SVX_RESSTR( RID_SVXSTR_BACKGROUND ) );
1100 else if ( SID_ATTR_CHAR_COLOR == theSlotId || SID_ATTR_CHAR_COLOR2 == theSlotId || SID_EXTRUSION_3D_COLOR == theSlotId )
1102 SfxPoolItem* pDummy;
1104 Reference< XDispatchProvider > aDisp( GetFrame()->getController(), UNO_QUERY );
1105 SfxQueryStatus aQueryStatus( aDisp,
1106 SID_ATTR_AUTO_COLOR_INVALID,
1107 OUString( ".uno:AutoColorInvalid" ));
1108 SfxItemState eState = aQueryStatus.QueryState( pDummy );
1109 if( (SFX_ITEM_DEFAULT > eState) || ( SID_EXTRUSION_3D_COLOR == theSlotId ) )
1111 aColorSet.SetStyle( aColorSet.GetStyle() | WB_NONEFIELD );
1112 aColorSet.SetText( SVX_RESSTR( RID_SVXSTR_AUTOMATIC ) );
1113 aColorSet.SetAccessibleName( SVX_RESSTR( RID_SVXSTR_TEXTCOLOR ) );
1116 else
1118 aColorSet.SetAccessibleName( SVX_RESSTR( RID_SVXSTR_FRAME_COLOR ) );
1121 if ( pColorList.is() )
1123 const long nColorCount(pColorList->Count());
1124 const Size aNewSize(aColorSet.layoutAllVisible(nColorCount));
1125 aColorSet.SetOutputSizePixel(aNewSize);
1126 static sal_Int32 nAdd = 4;
1128 SetOutputSizePixel(Size(aNewSize.Width() + nAdd, aNewSize.Height() + nAdd));
1129 aColorSet.Clear();
1130 aColorSet.addEntriesForXColorList(*pColorList);
1133 aColorSet.SetSelectHdl( LINK( this, SvxColorWindow_Impl, SelectHdl ) );
1134 SetHelpId( HID_POPUP_COLOR );
1135 aColorSet.SetHelpId( HID_POPUP_COLOR_CTRL );
1136 SetText( rWndTitle );
1137 aColorSet.Show();
1139 AddStatusListener( OUString( ".uno:ColorTableState" ));
1142 SvxColorWindow_Impl::~SvxColorWindow_Impl()
1146 void SvxColorWindow_Impl::KeyInput( const KeyEvent& rKEvt )
1148 aColorSet.KeyInput(rKEvt);
1151 SfxPopupWindow* SvxColorWindow_Impl::Clone() const
1153 return new SvxColorWindow_Impl( maCommand, theSlotId, GetFrame(), GetText(), GetParent(), mLastColor );
1156 // -----------------------------------------------------------------------
1158 IMPL_LINK_NOARG(SvxColorWindow_Impl, SelectHdl)
1160 sal_uInt16 nItemId = aColorSet.GetSelectItemId();
1161 SvxColorItem aColorItem( aColorSet.GetItemColor( nItemId ), theSlotId );
1162 /* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() calls.
1163 This instance may be deleted in the meantime (i.e. when a dialog is opened
1164 while in Dispatch()), accessing members will crash in this case. */
1165 aColorSet.SetNoSelection();
1167 if ( IsInPopupMode() )
1168 EndPopupMode();
1170 if ( !nItemId && ( SID_ATTR_CHAR_COLOR_BACKGROUND == theSlotId || SID_BACKGROUND_COLOR == theSlotId ) )
1172 Sequence< PropertyValue > aArgs;
1173 SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( GetFrame()->getController(), UNO_QUERY ),
1174 maCommand,
1175 aArgs );
1177 else if ( !nItemId && (SID_ATTR_CHAR_COLOR == theSlotId || SID_ATTR_CHAR_COLOR2 == theSlotId || SID_EXTRUSION_3D_COLOR == theSlotId) )
1179 SvxColorItem _aColorItem( COL_AUTO, theSlotId );
1180 INetURLObject aObj( maCommand );
1182 Any a;
1183 Sequence< PropertyValue > aArgs( 1 );
1184 aArgs[0].Name = aObj.GetURLPath();
1185 _aColorItem.QueryValue( a );
1186 aArgs[0].Value = a;
1187 SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( GetFrame()->getController(), UNO_QUERY ),
1188 maCommand,
1189 aArgs );
1191 else
1193 INetURLObject aObj( maCommand );
1195 Any a;
1196 Sequence< PropertyValue > aArgs( 1 );
1197 aArgs[0].Name = aObj.GetURLPath();
1198 aColorItem.QueryValue( a );
1199 aArgs[0].Value = a;
1200 SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( GetFrame()->getController(), UNO_QUERY ),
1201 maCommand,
1202 aArgs );
1205 return 0;
1208 // -----------------------------------------------------------------------
1210 void SvxColorWindow_Impl::Resize()
1212 lcl_ResizeValueSet( *this, aColorSet);
1215 // -----------------------------------------------------------------------
1217 void SvxColorWindow_Impl::StartSelection()
1219 aColorSet.StartSelection();
1222 // -----------------------------------------------------------------------
1224 sal_Bool SvxColorWindow_Impl::Close()
1226 return SfxPopupWindow::Close();
1229 // -----------------------------------------------------------------------
1231 void SvxColorWindow_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
1233 if (( SFX_ITEM_DISABLED != eState ) && pState )
1235 if (( nSID == SID_COLOR_TABLE ) && ( pState->ISA( SvxColorListItem )))
1237 if ( pState )
1239 XColorListRef pColorList = ((SvxColorListItem *)pState)->GetColorList();
1240 const long nColorCount(pColorList->Count());
1241 const Size aNewSize(aColorSet.layoutAllVisible(nColorCount));
1242 aColorSet.SetOutputSizePixel(aNewSize);
1243 static sal_Int32 nAdd = 4;
1245 SetOutputSizePixel(Size(aNewSize.Width() + nAdd, aNewSize.Height() + nAdd));
1246 aColorSet.Clear();
1247 aColorSet.addEntriesForXColorList(*pColorList);
1253 //========================================================================
1254 // class SvxFrameWindow_Impl --------------------------------------------------
1255 //========================================================================
1257 SvxFrameWindow_Impl::SvxFrameWindow_Impl( sal_uInt16 nId, const Reference< XFrame >& rFrame, Window* pParentWindow ) :
1259 SfxPopupWindow( nId, rFrame, pParentWindow, WinBits( WB_STDPOPUP | WB_OWNERDRAWDECORATION ) ),
1260 aFrameSet ( this, WinBits( WB_ITEMBORDER | WB_DOUBLEBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT ) ),
1261 bParagraphMode(sal_False)
1264 BindListener();
1265 AddStatusListener(OUString(".uno:BorderReducedMode"));
1266 aImgList = ImageList( SVX_RES( RID_SVXIL_FRAME ) );
1269 * 1 2 3 4
1270 * -------------------------------------
1271 * NONE LEFT RIGHT LEFTRIGHT
1272 * TOP BOTTOM TOPBOTTOM OUTER
1273 * -------------------------------------
1274 * HOR HORINNER VERINNER ALL <- can be switched of via bParagraphMode
1277 sal_uInt16 i = 0;
1279 for ( i=1; i<9; i++ )
1280 aFrameSet.InsertItem( i, aImgList.GetImage(i) );
1282 //bParagraphMode should have been set in StateChanged
1283 if ( !bParagraphMode )
1284 for ( i = 9; i < 13; i++ )
1285 aFrameSet.InsertItem( i, aImgList.GetImage(i) );
1287 aFrameSet.SetColCount( 4 );
1288 aFrameSet.SetSelectHdl( LINK( this, SvxFrameWindow_Impl, SelectHdl ) );
1290 lcl_CalcSizeValueSet( *this, aFrameSet,Size( 20, 20 ));
1292 SetHelpId( HID_POPUP_FRAME );
1293 SetText( SVX_RESSTR(RID_SVXSTR_FRAME) );
1294 aFrameSet.SetAccessibleName( SVX_RESSTR(RID_SVXSTR_FRAME) );
1295 aFrameSet.Show();
1298 SvxFrameWindow_Impl::~SvxFrameWindow_Impl()
1300 UnbindListener();
1303 SfxPopupWindow* SvxFrameWindow_Impl::Clone() const
1305 //! HACK: How do I get the Paragraph mode?
1306 return new SvxFrameWindow_Impl( GetId(), GetFrame(), GetParent() );
1309 Window* SvxFrameWindow_Impl::GetPreferredKeyInputWindow()
1311 return &aFrameSet;
1314 void SvxFrameWindow_Impl::GetFocus()
1316 aFrameSet.GrabFocus();
1319 void SvxFrameWindow_Impl::DataChanged( const DataChangedEvent& rDCEvt )
1321 SfxPopupWindow::DataChanged( rDCEvt );
1323 if( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
1325 aImgList = ImageList( SVX_RES( RID_SVXIL_FRAME ) );
1327 sal_uInt16 nNumOfItems = aFrameSet.GetItemCount();
1329 for( sal_uInt16 i = 1 ; i <= nNumOfItems ; ++i )
1330 aFrameSet.SetItemImage( i, aImgList.GetImage( i ) );
1333 // -----------------------------------------------------------------------
1335 #define FRM_VALID_LEFT 0x01
1336 #define FRM_VALID_RIGHT 0x02
1337 #define FRM_VALID_TOP 0x04
1338 #define FRM_VALID_BOTTOM 0x08
1339 #define FRM_VALID_HINNER 0x10
1340 #define FRM_VALID_VINNER 0x20
1341 #define FRM_VALID_OUTER 0x0f
1342 #define FRM_VALID_ALL 0xff
1344 // By default unset lines remain unchanged.
1345 // Via Shift unset lines are reset
1347 IMPL_LINK_NOARG(SvxFrameWindow_Impl, SelectHdl)
1349 SvxBoxItem aBorderOuter( SID_ATTR_BORDER_OUTER );
1350 SvxBoxInfoItem aBorderInner( SID_ATTR_BORDER_INNER );
1351 SvxBorderLine theDefLine;
1352 SvxBorderLine *pLeft = 0,
1353 *pRight = 0,
1354 *pTop = 0,
1355 *pBottom = 0;
1356 sal_uInt16 nSel = aFrameSet.GetSelectItemId();
1357 sal_uInt16 nModifier = aFrameSet.GetModifier();
1358 sal_uInt8 nValidFlags = 0;
1360 theDefLine.GuessLinesWidths(theDefLine.GetBorderLineStyle(),
1361 DEF_LINE_WIDTH_0);
1362 switch ( nSel )
1364 case 1: nValidFlags |= FRM_VALID_ALL;
1365 break; // NONE
1366 case 2: pLeft = &theDefLine;
1367 nValidFlags |= FRM_VALID_LEFT;
1368 break; // LEFT
1369 case 3: pRight = &theDefLine;
1370 nValidFlags |= FRM_VALID_RIGHT;
1371 break; // RIGHT
1372 case 4: pLeft = pRight = &theDefLine;
1373 nValidFlags |= FRM_VALID_RIGHT|FRM_VALID_LEFT;
1374 break; // LEFTRIGHT
1375 case 5: pTop = &theDefLine;
1376 nValidFlags |= FRM_VALID_TOP;
1377 break; // TOP
1378 case 6: pBottom = &theDefLine;
1379 nValidFlags |= FRM_VALID_BOTTOM;
1380 break; // BOTTOM
1381 case 7: pTop = pBottom = &theDefLine;
1382 nValidFlags |= FRM_VALID_BOTTOM|FRM_VALID_TOP;
1383 break; // TOPBOTTOM
1384 case 8: pLeft = pRight = pTop = pBottom = &theDefLine;
1385 nValidFlags |= FRM_VALID_OUTER;
1386 break; // OUTER
1388 // Inner Table:
1389 case 9: // HOR
1390 pTop = pBottom = &theDefLine;
1391 aBorderInner.SetLine( &theDefLine, BOXINFO_LINE_HORI );
1392 aBorderInner.SetLine( NULL, BOXINFO_LINE_VERT );
1393 nValidFlags |= FRM_VALID_HINNER|FRM_VALID_TOP|FRM_VALID_BOTTOM;
1394 break;
1396 case 10: // HORINNER
1397 pLeft = pRight = pTop = pBottom = &theDefLine;
1398 aBorderInner.SetLine( &theDefLine, BOXINFO_LINE_HORI );
1399 aBorderInner.SetLine( NULL, BOXINFO_LINE_VERT );
1400 nValidFlags |= FRM_VALID_RIGHT|FRM_VALID_LEFT|FRM_VALID_HINNER|FRM_VALID_TOP|FRM_VALID_BOTTOM;
1401 break;
1403 case 11: // VERINNER
1404 pLeft = pRight = pTop = pBottom = &theDefLine;
1405 aBorderInner.SetLine( NULL, BOXINFO_LINE_HORI );
1406 aBorderInner.SetLine( &theDefLine, BOXINFO_LINE_VERT );
1407 nValidFlags |= FRM_VALID_RIGHT|FRM_VALID_LEFT|FRM_VALID_VINNER|FRM_VALID_TOP|FRM_VALID_BOTTOM;
1408 break;
1410 case 12: // ALL
1411 pLeft = pRight = pTop = pBottom = &theDefLine;
1412 aBorderInner.SetLine( &theDefLine, BOXINFO_LINE_HORI );
1413 aBorderInner.SetLine( &theDefLine, BOXINFO_LINE_VERT );
1414 nValidFlags |= FRM_VALID_ALL;
1415 break;
1417 default:
1418 break;
1420 aBorderOuter.SetLine( pLeft, BOX_LINE_LEFT );
1421 aBorderOuter.SetLine( pRight, BOX_LINE_RIGHT );
1422 aBorderOuter.SetLine( pTop, BOX_LINE_TOP );
1423 aBorderOuter.SetLine( pBottom, BOX_LINE_BOTTOM );
1425 if(nModifier == KEY_SHIFT)
1426 nValidFlags |= FRM_VALID_ALL;
1427 aBorderInner.SetValid( VALID_TOP, 0 != (nValidFlags&FRM_VALID_TOP ));
1428 aBorderInner.SetValid( VALID_BOTTOM, 0 != (nValidFlags&FRM_VALID_BOTTOM ));
1429 aBorderInner.SetValid( VALID_LEFT, 0 != (nValidFlags&FRM_VALID_LEFT));
1430 aBorderInner.SetValid( VALID_RIGHT, 0 != (nValidFlags&FRM_VALID_RIGHT ));
1431 aBorderInner.SetValid( VALID_HORI, 0 != (nValidFlags&FRM_VALID_HINNER ));
1432 aBorderInner.SetValid( VALID_VERT, 0 != (nValidFlags&FRM_VALID_VINNER));
1433 aBorderInner.SetValid( VALID_DISTANCE, sal_True );
1434 aBorderInner.SetValid( VALID_DISABLE, sal_False );
1436 if ( IsInPopupMode() )
1437 EndPopupMode();
1439 Any a;
1440 Sequence< PropertyValue > aArgs( 2 );
1441 aArgs[0].Name = OUString( "OuterBorder" );
1442 aBorderOuter.QueryValue( a );
1443 aArgs[0].Value = a;
1444 aArgs[1].Name = OUString( "InnerBorder" );
1445 aBorderInner.QueryValue( a );
1446 aArgs[1].Value = a;
1448 /* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
1449 This instance may be deleted in the meantime (i.e. when a dialog is opened
1450 while in Dispatch()), accessing members will crash in this case. */
1451 aFrameSet.SetNoSelection();
1453 SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( GetFrame()->getController(), UNO_QUERY ),
1454 OUString( ".uno:SetBorderStyle" ),
1455 aArgs );
1456 return 0;
1459 // -----------------------------------------------------------------------
1461 void SvxFrameWindow_Impl::Resize()
1463 lcl_ResizeValueSet( *this, aFrameSet);
1466 // -----------------------------------------------------------------------
1468 void SvxFrameWindow_Impl::StateChanged(
1470 sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
1473 if ( pState && nSID == SID_BORDER_REDUCED_MODE)
1475 const SfxBoolItem* pItem = PTR_CAST( SfxBoolItem, pState );
1477 if ( pItem )
1479 bParagraphMode = (sal_Bool)pItem->GetValue();
1480 //initial calls mustn't insert or remove elements
1481 if(aFrameSet.GetItemCount())
1483 bool bTableMode = ( aFrameSet.GetItemCount() == 12 );
1484 bool bResize = false;
1486 if ( bTableMode && bParagraphMode )
1488 for ( sal_uInt16 i = 9; i < 13; i++ )
1489 aFrameSet.RemoveItem(i);
1490 bResize = true;
1492 else if ( !bTableMode && !bParagraphMode )
1494 for ( sal_uInt16 i = 9; i < 13; i++ )
1495 aFrameSet.InsertItem( i, aImgList.GetImage(i) );
1496 bResize = true;
1499 if ( bResize )
1501 lcl_CalcSizeValueSet( *this, aFrameSet,Size( 20, 20 ));
1506 SfxPopupWindow::StateChanged( nSID, eState, pState );
1509 // -----------------------------------------------------------------------
1511 void SvxFrameWindow_Impl::StartSelection()
1513 aFrameSet.StartSelection();
1516 // -----------------------------------------------------------------------
1518 sal_Bool SvxFrameWindow_Impl::Close()
1520 return SfxPopupWindow::Close();
1523 //========================================================================
1524 // class SvxLineWindow_Impl --------------------------------------------------
1525 //========================================================================
1526 static Color lcl_mediumColor( Color aMain, Color /*aDefault*/ )
1528 return SvxBorderLine::threeDMediumColor( aMain );
1531 SvxLineWindow_Impl::SvxLineWindow_Impl( sal_uInt16 nId, const Reference< XFrame >& rFrame, Window* pParentWindow ) :
1533 SfxPopupWindow( nId, rFrame, pParentWindow, WinBits( WB_STDPOPUP | WB_OWNERDRAWDECORATION | WB_AUTOSIZE ) ),
1534 m_aLineStyleLb( this )
1538 Reference< lang::XServiceInfo > xServices( rFrame->getController()->getModel(), UNO_QUERY_THROW );
1539 m_bIsWriter = xServices->supportsService(OUString("com.sun.star.text.TextDocument"));
1541 catch(const uno::Exception& )
1545 m_aLineStyleLb.setPosSizePixel( 2, 2, 110, 140 );
1546 SetOutputSizePixel( Size( 114, 144 ) );
1548 m_aLineStyleLb.SetSourceUnit( FUNIT_TWIP );
1549 m_aLineStyleLb.SetNone( SVX_RESSTR(RID_SVXSTR_NONE) );
1551 using namespace table::BorderLineStyle;
1552 m_aLineStyleLb.InsertEntry( SvxBorderLine::getWidthImpl( SOLID ), SOLID );
1553 m_aLineStyleLb.InsertEntry( SvxBorderLine::getWidthImpl( DOTTED ), DOTTED );
1554 m_aLineStyleLb.InsertEntry( SvxBorderLine::getWidthImpl( DASHED ), DASHED );
1556 // Double lines
1557 m_aLineStyleLb.InsertEntry( SvxBorderLine::getWidthImpl( DOUBLE ), DOUBLE );
1558 m_aLineStyleLb.InsertEntry( SvxBorderLine::getWidthImpl( THINTHICK_SMALLGAP ), THINTHICK_SMALLGAP, 20 );
1559 m_aLineStyleLb.InsertEntry( SvxBorderLine::getWidthImpl( THINTHICK_MEDIUMGAP ), THINTHICK_MEDIUMGAP );
1560 m_aLineStyleLb.InsertEntry( SvxBorderLine::getWidthImpl( THINTHICK_LARGEGAP ), THINTHICK_LARGEGAP );
1561 m_aLineStyleLb.InsertEntry( SvxBorderLine::getWidthImpl( THICKTHIN_SMALLGAP ), THICKTHIN_SMALLGAP, 20 );
1562 m_aLineStyleLb.InsertEntry( SvxBorderLine::getWidthImpl( THICKTHIN_MEDIUMGAP ), THICKTHIN_MEDIUMGAP );
1563 m_aLineStyleLb.InsertEntry( SvxBorderLine::getWidthImpl( THICKTHIN_LARGEGAP ), THICKTHIN_LARGEGAP );
1565 // Engraved / Embossed
1566 m_aLineStyleLb.InsertEntry( SvxBorderLine::getWidthImpl( EMBOSSED ), EMBOSSED, 15,
1567 &SvxBorderLine::threeDLightColor, &SvxBorderLine::threeDDarkColor,
1568 &lcl_mediumColor );
1569 m_aLineStyleLb.InsertEntry( SvxBorderLine::getWidthImpl( ENGRAVED ), ENGRAVED, 15,
1570 &SvxBorderLine::threeDDarkColor, &SvxBorderLine::threeDLightColor,
1571 &lcl_mediumColor );
1573 // Inset / Outset
1574 m_aLineStyleLb.InsertEntry( SvxBorderLine::getWidthImpl( OUTSET ), OUTSET, 10,
1575 &SvxBorderLine::lightColor, &SvxBorderLine::darkColor );
1576 m_aLineStyleLb.InsertEntry( SvxBorderLine::getWidthImpl( INSET ), INSET, 10,
1577 &SvxBorderLine::darkColor, &SvxBorderLine::lightColor );
1578 m_aLineStyleLb.SetWidth( 20 ); // 1pt by default
1580 m_aLineStyleLb.SetSelectHdl( LINK( this, SvxLineWindow_Impl, SelectHdl ) );
1582 SetHelpId( HID_POPUP_LINE );
1583 SetText( SVX_RESSTR(RID_SVXSTR_FRAME_STYLE) );
1584 m_aLineStyleLb.Show();
1587 SfxPopupWindow* SvxLineWindow_Impl::Clone() const
1589 return new SvxLineWindow_Impl( GetId(), GetFrame(), GetParent() );
1592 // -----------------------------------------------------------------------
1594 IMPL_LINK_NOARG(SvxLineWindow_Impl, SelectHdl)
1596 SvxLineItem aLineItem( SID_FRAME_LINESTYLE );
1597 SvxBorderStyle nStyle = SvxBorderStyle( m_aLineStyleLb.GetSelectEntryStyle() );
1599 if ( m_aLineStyleLb.GetSelectEntryPos( ) > 0 )
1601 SvxBorderLine aTmp;
1602 aTmp.SetBorderLineStyle( nStyle );
1603 aTmp.SetWidth( 20 ); // TODO Make it depend on a width field
1604 aLineItem.SetLine( &aTmp );
1606 else
1607 aLineItem.SetLine( NULL );
1609 if ( IsInPopupMode() )
1610 EndPopupMode();
1612 Any a;
1613 Sequence< PropertyValue > aArgs( 1 );
1614 aArgs[0].Name = OUString( "LineStyle" );
1615 aLineItem.QueryValue( a, m_bIsWriter ? CONVERT_TWIPS : 0 );
1616 aArgs[0].Value = a;
1618 SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( GetFrame()->getController(), UNO_QUERY ),
1619 OUString( ".uno:LineStyle" ),
1620 aArgs );
1621 return 0;
1624 // -----------------------------------------------------------------------
1626 void SvxLineWindow_Impl::Resize()
1628 m_aLineStyleLb.Resize();
1631 // -----------------------------------------------------------------------
1633 sal_Bool SvxLineWindow_Impl::Close()
1635 return SfxPopupWindow::Close();
1638 // -----------------------------------------------------------------------
1640 Window* SvxLineWindow_Impl::GetPreferredKeyInputWindow()
1642 return &m_aLineStyleLb;
1645 // -----------------------------------------------------------------------
1647 void SvxLineWindow_Impl::GetFocus()
1649 m_aLineStyleLb.GrabFocus();
1652 void SvxLineWindow_Impl::DataChanged( const DataChangedEvent& rDCEvt )
1654 SfxPopupWindow::DataChanged( rDCEvt );
1655 #if 0
1656 if( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
1658 CreateBitmaps();
1659 Invalidate();
1661 #endif
1664 // -----------------------------------------------------------------------
1666 //########################################################################
1667 // Hilfsklassen
1669 //========================================================================
1670 // class SfxStyleControllerItem_Impl ------------------------------------------
1671 //========================================================================
1673 SfxStyleControllerItem_Impl::SfxStyleControllerItem_Impl(
1674 const Reference< XDispatchProvider >& rDispatchProvider,
1675 sal_uInt16 nSlotId, // Family-ID
1676 const OUString& rCommand, // .uno: command bound to this item
1677 SvxStyleToolBoxControl& rTbxCtl ) // Controller-Instanz, dem dieses Item zugeordnet ist.
1678 : SfxStatusListener( rDispatchProvider, nSlotId, rCommand ),
1679 rControl( rTbxCtl )
1683 // -----------------------------------------------------------------------
1685 void SfxStyleControllerItem_Impl::StateChanged(
1686 sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
1688 switch ( GetId() )
1690 case SID_STYLE_FAMILY1:
1691 case SID_STYLE_FAMILY2:
1692 case SID_STYLE_FAMILY3:
1693 case SID_STYLE_FAMILY4:
1694 case SID_STYLE_FAMILY5:
1696 const sal_uInt16 nIdx = GetId() - SID_STYLE_FAMILY_START;
1698 if ( SFX_ITEM_AVAILABLE == eState )
1700 const SfxTemplateItem* pStateItem =
1701 PTR_CAST( SfxTemplateItem, pState );
1702 DBG_ASSERT( pStateItem != NULL, "SfxTemplateItem expected" );
1703 rControl.SetFamilyState( nIdx, pStateItem );
1705 else
1706 rControl.SetFamilyState( nIdx, NULL );
1707 break;
1712 //########################################################################
1714 //========================================================================
1715 // class SvxStyleToolBoxControl ------------------------------------------
1716 //========================================================================
1718 struct SvxStyleToolBoxControl::Impl
1720 String aClearForm;
1721 String aMore;
1722 ::std::vector< OUString > aDefaultStyles;
1723 sal_Bool bSpecModeWriter;
1724 sal_Bool bSpecModeCalc;
1726 inline Impl( void )
1727 :aClearForm ( SVX_RESSTR( RID_SVXSTR_CLEARFORM ) )
1728 ,aMore ( SVX_RESSTR( RID_SVXSTR_MORE ) )
1729 ,bSpecModeWriter ( sal_False )
1730 ,bSpecModeCalc ( sal_False )
1735 void InitializeStyles(Reference < frame::XModel > xModel)
1737 //now convert the default style names to the localized names
1740 Reference< style::XStyleFamiliesSupplier > xStylesSupplier( xModel, UNO_QUERY_THROW );
1741 Reference< lang::XServiceInfo > xServices( xModel, UNO_QUERY_THROW );
1742 bSpecModeWriter = xServices->supportsService(OUString("com.sun.star.text.TextDocument"));
1743 if(bSpecModeWriter)
1745 Reference<container::XNameAccess> xParaStyles;
1746 xStylesSupplier->getStyleFamilies()->getByName(OUString("ParagraphStyles")) >>=
1747 xParaStyles;
1748 static const sal_Char* aWriterStyles[] =
1750 "Text body",
1751 "Quotations",
1752 "Title",
1753 "Subtitle",
1754 "Heading 1",
1755 "Heading 2",
1756 "Heading 3"
1758 for( sal_uInt32 nStyle = 0; nStyle < sizeof( aWriterStyles ) / sizeof( sal_Char*); ++nStyle )
1762 Reference< beans::XPropertySet > xStyle;
1763 xParaStyles->getByName( OUString::createFromAscii( aWriterStyles[nStyle] )) >>= xStyle;
1764 OUString sName;
1765 xStyle->getPropertyValue(OUString("DisplayName")) >>= sName;
1766 if( !sName.isEmpty() )
1767 aDefaultStyles.push_back(sName);
1769 catch( const uno::Exception& )
1774 else if( 0 != (
1775 bSpecModeCalc = xServices->supportsService(OUString(
1776 "com.sun.star.sheet.SpreadsheetDocument"))))
1778 static const sal_Char* aCalcStyles[] =
1780 "Default",
1781 "Heading1",
1782 "Result",
1783 "Result2"
1785 Reference<container::XNameAccess> xCellStyles;
1786 xStylesSupplier->getStyleFamilies()->getByName(
1787 OUString("CellStyles")) >>=
1788 xCellStyles;
1789 for( sal_uInt32 nStyle = 0; nStyle < sizeof( aCalcStyles ) / sizeof( sal_Char*); ++nStyle )
1793 const OUString sStyleName( OUString::createFromAscii( aCalcStyles[nStyle] ) );
1794 if( xCellStyles->hasByName( sStyleName ) )
1796 Reference< beans::XPropertySet > xStyle( xCellStyles->getByName( sStyleName), UNO_QUERY_THROW );
1797 OUString sName;
1798 xStyle->getPropertyValue(OUString("DisplayName")) >>= sName;
1799 if( !sName.isEmpty() )
1800 aDefaultStyles.push_back(sName);
1803 catch( const uno::Exception& )
1808 catch(const uno::Exception& )
1810 OSL_FAIL("error while initializing style names");
1816 // mapping table from bound items. BE CAREFUL this table must be in the
1817 // same order as the uno commands bound to the slots SID_STYLE_FAMILY1..n
1818 // MAX_FAMILIES must also be correctly set!
1819 static const char* StyleSlotToStyleCommand[MAX_FAMILIES] =
1821 ".uno:CharStyle",
1822 ".uno:ParaStyle",
1823 ".uno:FrameStyle",
1824 ".uno:PageStyle",
1825 ".uno:TemplateFamily5"
1828 SvxStyleToolBoxControl::SvxStyleToolBoxControl(
1829 sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
1830 : SfxToolBoxControl ( nSlotId, nId, rTbx ),
1831 pStyleSheetPool ( NULL ),
1832 nActFamily ( 0xffff ),
1833 pImpl ( new Impl )
1835 for ( sal_uInt16 i=0; i<MAX_FAMILIES; i++ )
1837 pBoundItems[i] = 0;
1838 m_xBoundItems[i] = Reference< XComponent >();
1839 pFamilyState[i] = NULL;
1843 // -----------------------------------------------------------------------
1844 SvxStyleToolBoxControl::~SvxStyleToolBoxControl()
1846 delete pImpl;
1849 // -----------------------------------------------------------------------
1850 void SAL_CALL SvxStyleToolBoxControl::initialize( const Sequence< Any >& aArguments )
1851 throw ( Exception, RuntimeException)
1853 SfxToolBoxControl::initialize( aArguments );
1855 // After initialize we should have a valid frame member where we can retrieve our
1856 // dispatch provider.
1857 if ( m_xFrame.is() )
1859 pImpl->InitializeStyles(m_xFrame->getController()->getModel());
1860 Reference< XDispatchProvider > xDispatchProvider( m_xFrame->getController(), UNO_QUERY );
1861 for ( sal_uInt16 i=0; i<MAX_FAMILIES; i++ )
1863 pBoundItems[i] = new SfxStyleControllerItem_Impl( xDispatchProvider,
1864 SID_STYLE_FAMILY_START + i,
1865 OUString::createFromAscii( StyleSlotToStyleCommand[i] ),
1866 *this );
1867 m_xBoundItems[i] = Reference< XComponent >( static_cast< OWeakObject* >( pBoundItems[i] ), UNO_QUERY );
1868 pFamilyState[i] = NULL;
1873 // XComponent
1874 void SAL_CALL SvxStyleToolBoxControl::dispose()
1875 throw (::com::sun::star::uno::RuntimeException)
1877 SfxToolBoxControl::dispose();
1879 for( sal_uInt16 i=0; i<MAX_FAMILIES; i++ )
1881 if ( m_xBoundItems[i].is() )
1885 m_xBoundItems[i]->dispose();
1887 catch ( Exception& )
1891 m_xBoundItems[i].clear();
1892 pBoundItems[i] = 0;
1894 DELETEZ( pFamilyState[i] );
1896 pStyleSheetPool = NULL;
1897 DELETEZ( pImpl );
1900 // -----------------------------------------------------------------------
1901 void SAL_CALL SvxStyleToolBoxControl::update() throw (RuntimeException)
1903 // Do nothing, we will start binding our listener when we are visible.
1904 // See link SvxStyleToolBoxControl::VisibilityNotification.
1905 SvxStyleBox_Impl* pBox = (SvxStyleBox_Impl*)GetToolBox().GetItemWindow( GetId() );
1906 if ( pBox->IsVisible() )
1908 for ( int i=0; i<MAX_FAMILIES; i++ )
1909 pBoundItems [i]->ReBind();
1911 bindListener();
1915 // -----------------------------------------------------------------------
1917 SfxStyleFamily SvxStyleToolBoxControl::GetActFamily()
1919 switch ( nActFamily-1 + SID_STYLE_FAMILY_START )
1921 case SID_STYLE_FAMILY1: return SFX_STYLE_FAMILY_CHAR;
1922 case SID_STYLE_FAMILY2: return SFX_STYLE_FAMILY_PARA;
1923 case SID_STYLE_FAMILY3: return SFX_STYLE_FAMILY_FRAME;
1924 case SID_STYLE_FAMILY4: return SFX_STYLE_FAMILY_PAGE;
1925 case SID_STYLE_FAMILY5: return SFX_STYLE_FAMILY_PSEUDO;
1926 default:
1927 OSL_FAIL( "unknown style family" );
1928 break;
1930 return SFX_STYLE_FAMILY_PARA;
1933 // -----------------------------------------------------------------------
1935 void SvxStyleToolBoxControl::FillStyleBox()
1937 SvxStyleBox_Impl* pBox = (SvxStyleBox_Impl*)GetToolBox().GetItemWindow( GetId() );
1939 DBG_ASSERT( pStyleSheetPool, "StyleSheetPool not found!" );
1940 DBG_ASSERT( pBox, "Control not found!" );
1942 if ( pStyleSheetPool && pBox && nActFamily!=0xffff )
1944 const SfxStyleFamily eFamily = GetActFamily();
1945 sal_uInt16 nCount = pStyleSheetPool->Count();
1946 SfxStyleSheetBase* pStyle = NULL;
1947 bool bDoFill = false;
1949 pStyleSheetPool->SetSearchMask( eFamily, SFXSTYLEBIT_USED );
1951 // Check whether fill is necessary
1952 pStyle = pStyleSheetPool->First();
1953 //!!! TODO: This condition isn't right any longer, because we always show some default entries
1954 //!!! so the list doesn't show the count
1955 if ( nCount != pBox->GetEntryCount() )
1957 bDoFill = true;
1959 else
1961 sal_uInt16 i= 0;
1962 while ( pStyle && !bDoFill )
1964 bDoFill = ( pBox->GetEntry(i) != pStyle->GetName() );
1965 pStyle = pStyleSheetPool->Next();
1966 i++;
1970 if ( bDoFill )
1972 pBox->SetUpdateMode( sal_False );
1973 pBox->Clear();
1976 sal_uInt16 _i;
1977 sal_uInt32 nCnt = pImpl->aDefaultStyles.size();
1979 pStyle = pStyleSheetPool->First();
1981 if( pImpl->bSpecModeWriter || pImpl->bSpecModeCalc )
1983 bool bInsert;
1984 while ( pStyle )
1986 // sort out default styles
1987 bInsert = true;
1988 OUString aName( pStyle->GetName() );
1989 for( _i = 0 ; _i < nCnt ; ++_i )
1991 if( pImpl->aDefaultStyles[_i] == aName )
1993 bInsert = false;
1994 break;
1998 if( bInsert )
1999 pBox->InsertEntry( aName );
2000 pStyle = pStyleSheetPool->Next();
2003 else
2005 while ( pStyle )
2007 pBox->InsertEntry( pStyle->GetName() );
2008 pStyle = pStyleSheetPool->Next();
2013 if( pImpl->bSpecModeWriter || pImpl->bSpecModeCalc )
2015 // disable sort to preserve special order
2016 WinBits nWinBits = pBox->GetStyle();
2017 nWinBits &= ~WB_SORT;
2018 pBox->SetStyle( nWinBits );
2020 // insert default styles
2021 sal_uInt16 _i;
2022 sal_uInt32 nCnt = pImpl->aDefaultStyles.size();
2023 sal_uInt16 nPos = 1;
2024 for( _i = 0 ; _i < nCnt ; ++_i )
2026 pBox->InsertEntry( pImpl->aDefaultStyles[_i], nPos );
2027 ++nPos;
2030 pBox->InsertEntry( pImpl->aClearForm, 0 );
2031 pBox->SetSeparatorPos( 0 );
2033 pBox->InsertEntry( pImpl->aMore );
2035 // enable sort again
2036 nWinBits |= WB_SORT;
2037 pBox->SetStyle( nWinBits );
2040 pBox->SetUpdateMode( sal_True );
2041 pBox->SetFamily( eFamily );
2043 sal_uInt16 nLines = std::min( pBox->GetEntryCount(), MAX_STYLES_ENTRIES );
2044 pBox->SetDropDownLineCount( nLines );
2049 // -----------------------------------------------------------------------
2051 void SvxStyleToolBoxControl::SelectStyle( const String& rStyleName )
2053 SvxStyleBox_Impl* pBox = (SvxStyleBox_Impl*)GetToolBox().GetItemWindow( GetId() );
2054 DBG_ASSERT( pBox, "Control not found!" );
2056 if ( pBox )
2058 // String aStrSel( pBox->GetSelectEntry() );
2059 String aStrSel( pBox->GetText() );
2061 if ( rStyleName.Len() > 0 )
2063 if ( rStyleName != aStrSel )
2064 // pBox->SelectEntry( rStyleName );
2065 pBox->SetText( rStyleName );
2067 else
2068 pBox->SetNoSelection();
2069 pBox->SaveValue();
2073 // -----------------------------------------------------------------------
2075 void SvxStyleToolBoxControl::Update()
2077 SfxStyleSheetBasePool* pPool = NULL;
2078 SfxObjectShell* pDocShell = SfxObjectShell::Current();
2080 if ( pDocShell )
2081 pPool = pDocShell->GetStyleSheetPool();
2083 sal_uInt16 i;
2084 for ( i=0; i<MAX_FAMILIES; i++ )
2085 if( pFamilyState[i] )
2086 break;
2088 if ( i==MAX_FAMILIES || !pPool )
2090 pStyleSheetPool = pPool;
2091 return;
2094 //--------------------------------------------------------------------
2095 const SfxTemplateItem* pItem = NULL;
2097 if ( nActFamily == 0xffff || 0 == (pItem = pFamilyState[nActFamily-1]) )
2098 // Current range not within allowed ranges or default
2100 pStyleSheetPool = pPool;
2101 nActFamily = 2;
2103 pItem = pFamilyState[nActFamily-1];
2104 if ( !pItem )
2106 nActFamily++;
2107 pItem = pFamilyState[nActFamily-1];
2110 if ( !pItem )
2112 DBG_WARNING( "Unknown Family" ); // can happen
2115 else if ( pPool != pStyleSheetPool )
2116 pStyleSheetPool = pPool;
2118 FillStyleBox(); // Decides by itself whether Fill is needed
2120 if ( pItem )
2121 SelectStyle( pItem->GetStyleName() );
2124 // -----------------------------------------------------------------------
2126 void SvxStyleToolBoxControl::SetFamilyState( sal_uInt16 nIdx,
2127 const SfxTemplateItem* pItem )
2129 DELETEZ( pFamilyState[nIdx] );
2131 if ( pItem )
2132 pFamilyState[nIdx] = new SfxTemplateItem( *pItem );
2134 Update();
2137 // -----------------------------------------------------------------------
2139 IMPL_LINK_NOARG(SvxStyleToolBoxControl, VisibilityNotification)
2142 sal_uInt16 i;
2144 // Call ReBind() && UnBind() according to visibility
2145 SvxStyleBox_Impl* pBox = (SvxStyleBox_Impl*)( GetToolBox().GetItemWindow( GetId() ));
2146 if ( pBox->IsVisible() && !isBound() )
2148 for ( i=0; i<MAX_FAMILIES; i++ )
2149 pBoundItems [i]->ReBind();
2151 bindListener();
2153 else if ( !pBox->IsVisible() && isBound() )
2155 for ( i=0; i<MAX_FAMILIES; i++ )
2156 pBoundItems[i]->UnBind();
2157 unbindListener();
2160 return 0;
2163 // -----------------------------------------------------------------------
2165 void SvxStyleToolBoxControl::StateChanged(
2167 sal_uInt16 , SfxItemState eState, const SfxPoolItem* pState )
2170 sal_uInt16 nId = GetId();
2171 ToolBox& rTbx = GetToolBox();
2172 SvxStyleBox_Impl* pBox = (SvxStyleBox_Impl*)(rTbx.GetItemWindow( nId ));
2173 TriState eTri = STATE_NOCHECK;
2175 DBG_ASSERT( pBox, "Control not found!" );
2177 if ( SFX_ITEM_DISABLED == eState )
2178 pBox->Disable();
2179 else
2180 pBox->Enable();
2182 rTbx.EnableItem( nId, SFX_ITEM_DISABLED != eState );
2184 switch ( eState )
2186 case SFX_ITEM_AVAILABLE:
2187 eTri = ((const SfxBoolItem*)pState)->GetValue()
2188 ? STATE_CHECK
2189 : STATE_NOCHECK;
2190 break;
2192 case SFX_ITEM_DONTCARE:
2193 eTri = STATE_DONTKNOW;
2194 break;
2197 rTbx.SetItemState( nId, eTri );
2199 if ( SFX_ITEM_DISABLED != eState )
2200 Update();
2203 // -----------------------------------------------------------------------
2205 Window* SvxStyleToolBoxControl::CreateItemWindow( Window *pParent )
2207 SvxStyleBox_Impl* pBox = new SvxStyleBox_Impl( pParent,
2208 OUString( ".uno:StyleApply" ),
2209 SFX_STYLE_FAMILY_PARA,
2210 Reference< XDispatchProvider >( m_xFrame->getController(), UNO_QUERY ),
2211 m_xFrame,
2212 pImpl->aClearForm,
2213 pImpl->aMore,
2214 pImpl->bSpecModeWriter || pImpl->bSpecModeCalc );
2215 if( !pImpl->aDefaultStyles.empty())
2216 pBox->SetDefaultStyle( pImpl->aDefaultStyles[0] );
2217 // Set visibility listener to bind/unbind controller
2218 pBox->SetVisibilityListener( LINK( this, SvxStyleToolBoxControl, VisibilityNotification ));
2220 return pBox;
2223 //========================================================================
2224 // class SvxFontNameToolBoxControl ---------------------------------------
2225 //========================================================================
2227 SvxFontNameToolBoxControl::SvxFontNameToolBoxControl(
2228 sal_uInt16 nSlotId,
2229 sal_uInt16 nId,
2230 ToolBox& rTbx )
2232 : SfxToolBoxControl( nSlotId, nId, rTbx )
2236 // -----------------------------------------------------------------------
2238 void SvxFontNameToolBoxControl::StateChanged(
2240 sal_uInt16 , SfxItemState eState, const SfxPoolItem* pState )
2243 sal_uInt16 nId = GetId();
2244 ToolBox& rTbx = GetToolBox();
2245 SvxFontNameBox_Impl* pBox = (SvxFontNameBox_Impl*)(rTbx.GetItemWindow( nId ));
2247 DBG_ASSERT( pBox, "Control not found!" );
2249 if ( SFX_ITEM_DISABLED == eState )
2251 pBox->Disable();
2252 pBox->Update( (const SvxFontItem*)NULL );
2254 else
2256 pBox->Enable();
2258 if ( SFX_ITEM_AVAILABLE == eState )
2260 const SvxFontItem* pFontItem = dynamic_cast< const SvxFontItem* >( pState );
2262 DBG_ASSERT( pFontItem, "svx::SvxFontNameToolBoxControl::StateChanged(), wrong item type!" );
2263 if( pFontItem )
2264 pBox->Update( pFontItem );
2266 else
2267 pBox->SetText( String() );
2268 pBox->SaveValue();
2271 rTbx.EnableItem( nId, SFX_ITEM_DISABLED != eState );
2274 // -----------------------------------------------------------------------
2276 Window* SvxFontNameToolBoxControl::CreateItemWindow( Window *pParent )
2278 SvxFontNameBox_Impl* pBox = new SvxFontNameBox_Impl( pParent,
2279 Reference< XDispatchProvider >( m_xFrame->getController(), UNO_QUERY ),
2280 m_xFrame,0);
2281 return pBox;
2284 //========================================================================
2285 // class SvxFontColorToolBoxControl --------------------------------------
2286 //========================================================================
2288 SvxFontColorToolBoxControl::SvxFontColorToolBoxControl(
2289 sal_uInt16 nSlotId,
2290 sal_uInt16 nId,
2291 ToolBox& rTbx )
2293 : SfxToolBoxControl( nSlotId, nId, rTbx ),
2294 pBtnUpdater( new ::svx::ToolboxButtonColorUpdater(
2295 nSlotId, nId, &GetToolBox(), TBX_UPDATER_MODE_CHAR_COLOR_NEW )),
2296 mLastColor( COL_AUTO )
2298 rTbx.SetItemBits( nId, TIB_DROPDOWNONLY | rTbx.GetItemBits( nId ) );
2301 // -----------------------------------------------------------------------
2303 SvxFontColorToolBoxControl::~SvxFontColorToolBoxControl()
2305 delete pBtnUpdater;
2308 // -----------------------------------------------------------------------
2310 SfxPopupWindowType SvxFontColorToolBoxControl::GetPopupWindowType() const
2312 return SFX_POPUPWINDOW_ONCLICK;
2315 // -----------------------------------------------------------------------
2317 SfxPopupWindow* SvxFontColorToolBoxControl::CreatePopupWindow()
2319 SvxColorWindow_Impl* pColorWin =
2320 new SvxColorWindow_Impl(
2321 OUString( ".uno:Color" ),
2322 SID_ATTR_CHAR_COLOR,
2323 m_xFrame,
2324 SVX_RESSTR( RID_SVXITEMS_EXTRAS_CHARCOLOR ),
2325 &GetToolBox(),
2326 mLastColor);
2328 pColorWin->StartPopupMode( &GetToolBox(),
2329 FLOATWIN_POPUPMODE_GRABFOCUS|FLOATWIN_POPUPMODE_ALLOWTEAROFF|FLOATWIN_POPUPMODE_NOAPPFOCUSCLOSE );
2330 pColorWin->StartSelection();
2331 SetPopupWindow( pColorWin );
2332 return pColorWin;
2335 // -----------------------------------------------------------------------
2337 void SvxFontColorToolBoxControl::StateChanged(
2339 sal_uInt16 , SfxItemState eState, const SfxPoolItem* pState )
2342 sal_uInt16 nId = GetId();
2343 ToolBox& rTbx = GetToolBox();
2344 const SvxColorItem* pItem = 0;
2346 if ( SFX_ITEM_DONTCARE != eState )
2347 pItem = PTR_CAST( SvxColorItem, pState );
2349 if ( pItem )
2351 pBtnUpdater->Update( pItem->GetValue() );
2352 mLastColor= pItem->GetValue();
2355 rTbx.EnableItem( nId, SFX_ITEM_DISABLED != eState );
2356 rTbx.SetItemState( nId, ( SFX_ITEM_DONTCARE == eState ) ? STATE_DONTKNOW : STATE_NOCHECK );
2359 //========================================================================
2360 // class SvxColorToolBoxControl --------------------------------
2361 //========================================================================
2363 SvxColorToolBoxControl::SvxColorToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
2365 SfxToolBoxControl( nSlotId, nId, rTbx ),
2366 mLastColor( COL_AUTO )
2368 if ( nSlotId == SID_BACKGROUND_COLOR )
2369 rTbx.SetItemBits( nId, TIB_DROPDOWNONLY | rTbx.GetItemBits( nId ) );
2370 else
2371 rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
2372 rTbx.Invalidate();
2373 pBtnUpdater = new ::svx::ToolboxButtonColorUpdater( nSlotId, nId, &GetToolBox() );
2376 // -----------------------------------------------------------------------
2378 SvxColorToolBoxControl::~SvxColorToolBoxControl()
2380 delete pBtnUpdater;
2383 // -----------------------------------------------------------------------
2385 SfxPopupWindowType SvxColorToolBoxControl::GetPopupWindowType() const
2387 return SFX_POPUPWINDOW_ONCLICK;
2390 // -----------------------------------------------------------------------
2392 SfxPopupWindow* SvxColorToolBoxControl::CreatePopupWindow()
2394 sal_uInt16 nResId = GetSlotId() == SID_BACKGROUND_COLOR ?
2395 RID_SVXSTR_BACKGROUND : RID_SVXSTR_COLOR;
2396 SvxColorWindow_Impl* pColorWin = new SvxColorWindow_Impl(
2397 OUString( ".uno:BackgroundColor" ),
2398 SID_BACKGROUND_COLOR,
2399 m_xFrame,
2400 SVX_RESSTR(nResId),
2401 &GetToolBox(),
2402 mLastColor);
2404 pColorWin->StartPopupMode( &GetToolBox(),
2405 FLOATWIN_POPUPMODE_GRABFOCUS|FLOATWIN_POPUPMODE_ALLOWTEAROFF|FLOATWIN_POPUPMODE_NOAPPFOCUSCLOSE );
2406 pColorWin->StartSelection();
2407 SetPopupWindow( pColorWin );
2408 return pColorWin;
2411 // -----------------------------------------------------------------------
2413 void SvxColorToolBoxControl::StateChanged(
2414 sal_uInt16 , SfxItemState eState, const SfxPoolItem* pState )
2416 const SvxColorItem* pItem = 0;
2417 if ( SFX_ITEM_DONTCARE != eState )
2418 pItem = PTR_CAST( SvxColorItem, pState );
2420 if ( pItem ) {
2421 pBtnUpdater->Update( pItem->GetValue() );
2422 mLastColor= pItem->GetValue();
2425 sal_uInt16 nId = GetId();
2426 ToolBox& rTbx = GetToolBox();
2427 rTbx.EnableItem( nId, SFX_ITEM_DISABLED != eState );
2428 rTbx.SetItemState( nId, ( SFX_ITEM_DONTCARE == eState ) ? STATE_DONTKNOW : STATE_NOCHECK );
2431 //========================================================================
2432 // class SvxColorExtToolBoxControl ----------------------------------------
2433 //========================================================================
2434 /* Note:
2435 The initial color shown on the button is set in /core/svx/source/tbxctrls/tbxcolorupdate.cxx
2436 (ToolboxButtonColorUpdater::ToolboxButtonColorUpdater()) .
2437 The initial color used by the button is set in /core/svx/source/tbxcntrls/tbcontrl.cxx
2438 (SvxColorExtToolBoxControl::SvxColorExtToolBoxControl())
2439 and in case of writer for text(background)color also in /core/sw/source/ui/docvw/edtwin.cxx
2440 (SwEditWin::aTextBackColor and SwEditWin::aTextBackColor)
2443 SvxColorExtToolBoxControl::SvxColorExtToolBoxControl(
2444 sal_uInt16 nSlotId,
2445 sal_uInt16 nId,
2446 ToolBox& rTbx ) :
2448 SfxToolBoxControl( nSlotId, nId, rTbx ),
2449 pBtnUpdater(0),
2450 mLastColor( COL_AUTO )
2452 sal_uInt16 nMode;
2454 rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
2455 bChoiceFromPalette = sal_False;
2457 // The following commands are available at the various modules
2458 switch( nSlotId )
2460 case SID_ATTR_CHAR_COLOR:
2461 addStatusListener( OUString( ".uno:Color" ));
2462 nMode = TBX_UPDATER_MODE_CHAR_COLOR_NEW;
2463 mLastColor = COL_RED;
2464 break;
2466 case SID_ATTR_CHAR_COLOR2:
2467 addStatusListener( OUString( ".uno:CharColorExt" ));
2468 nMode = TBX_UPDATER_MODE_CHAR_COLOR_NEW;
2469 mLastColor = COL_RED;
2470 break;
2472 case SID_BACKGROUND_COLOR:
2473 case SID_ATTR_CHAR_COLOR_BACKGROUND:
2474 default:
2475 addStatusListener( OUString( ".uno:CharBackgroundExt" ));
2476 nMode = TBX_UPDATER_MODE_CHAR_COLOR_NEW;
2477 mLastColor = COL_YELLOW;
2478 break;
2480 case SID_FRAME_LINECOLOR:
2481 addStatusListener( OUString( ".uno:FrameLineColor" ));
2482 nMode = 0;
2483 mLastColor = COL_BLUE;
2484 break;
2487 pBtnUpdater = new ::svx::ToolboxButtonColorUpdater( nSlotId, nId, &GetToolBox(), nMode );
2490 // -----------------------------------------------------------------------
2492 SvxColorExtToolBoxControl::~SvxColorExtToolBoxControl()
2494 delete pBtnUpdater;
2497 // -----------------------------------------------------------------------
2499 SfxPopupWindowType SvxColorExtToolBoxControl::GetPopupWindowType() const
2501 return SFX_POPUPWINDOW_ONTIMEOUT;
2504 // -----------------------------------------------------------------------
2506 SfxPopupWindow* SvxColorExtToolBoxControl::CreatePopupWindow()
2508 SvxColorWindow_Impl* pColorWin =
2509 new SvxColorWindow_Impl(
2510 m_aCommandURL,
2511 GetSlotId(),
2512 m_xFrame,
2513 SVX_RESSTR( RID_SVXITEMS_EXTRAS_CHARCOLOR ),
2514 &GetToolBox(),
2515 mLastColor );
2517 switch( GetSlotId() )
2519 case SID_ATTR_CHAR_COLOR_BACKGROUND :
2520 pColorWin->SetText( SVX_RESSTR( RID_SVXSTR_EXTRAS_CHARBACKGROUND ) );
2521 break;
2523 case SID_BACKGROUND_COLOR :
2524 pColorWin->SetText( SVX_RESSTR( RID_SVXSTR_BACKGROUND ) );
2525 break;
2527 case SID_FRAME_LINECOLOR:
2528 pColorWin->SetText( SVX_RESSTR( RID_SVXSTR_FRAME_COLOR ) );
2529 break;
2532 pColorWin->StartPopupMode( &GetToolBox(),
2533 FLOATWIN_POPUPMODE_GRABFOCUS|FLOATWIN_POPUPMODE_ALLOWTEAROFF|FLOATWIN_POPUPMODE_NOAPPFOCUSCLOSE );
2534 pColorWin->StartSelection();
2535 SetPopupWindow( pColorWin );
2536 bChoiceFromPalette = sal_True;
2537 return pColorWin;
2540 // -----------------------------------------------------------------------
2542 void SvxColorExtToolBoxControl::StateChanged(
2544 sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
2547 const SvxColorItem* pItem = 0;
2548 if ( bChoiceFromPalette && nSID == GetSlotId() )
2550 bChoiceFromPalette = sal_False;
2551 switch( nSID )
2553 case SID_ATTR_CHAR_COLOR :
2554 case SID_ATTR_CHAR_COLOR2 :
2555 case SID_ATTR_CHAR_COLOR_BACKGROUND :
2556 case SID_BACKGROUND_COLOR :
2557 if ( SFX_ITEM_DONTCARE != eState )
2558 pItem = PTR_CAST( SvxColorItem, pState );
2560 if ( pItem )
2562 pBtnUpdater->Update( pItem->GetValue() );
2563 mLastColor = pItem->GetValue();
2565 break;
2567 case SID_FRAME_LINECOLOR :
2568 ToolBox& rTbx = GetToolBox();
2569 rTbx.EnableItem( nSID, SFX_ITEM_DISABLED != eState );
2570 rTbx.SetItemState( nSID, ( SFX_ITEM_DONTCARE == eState ) ? STATE_DONTKNOW : STATE_NOCHECK );
2572 if ( SFX_ITEM_DONTCARE != eState )
2574 pItem = PTR_CAST( SvxColorItem, pState );
2575 if ( pItem )
2577 pBtnUpdater->Update( pItem->GetValue());
2578 mLastColor = pItem->GetValue();
2581 break;
2586 // -----------------------------------------------------------------------
2588 void SvxColorExtToolBoxControl::Select( sal_Bool )
2590 OUString aCommand;
2591 OUString aParamName;
2592 bool bNoArgs = false;
2594 switch( GetSlotId() )
2596 case SID_ATTR_CHAR_COLOR2 :
2597 bNoArgs = true;
2598 aCommand = OUString( ".uno:CharColorExt" );
2599 aParamName = OUString( "CharColorExt" );
2600 break;
2602 case SID_ATTR_CHAR_COLOR :
2603 aCommand = OUString( ".uno:Color" );
2604 aParamName = OUString( "Color" );
2605 break;
2607 case SID_BACKGROUND_COLOR :
2608 aCommand = OUString( ".uno:BackgroundColor" );
2609 aParamName = OUString( "BackgroundColor" );
2610 break;
2612 case SID_ATTR_CHAR_COLOR_BACKGROUND :
2613 bNoArgs = true;
2614 aCommand = OUString( ".uno:CharBackgroundExt" );
2615 aParamName = OUString( "CharBackgroundExt" );
2616 break;
2618 case SID_FRAME_LINECOLOR :
2619 aCommand = OUString( ".uno:FrameLineColor" );
2620 aParamName = OUString( "FrameLineColor" );
2621 break;
2624 Sequence< PropertyValue > aArgs( 1 );
2625 aArgs[0].Name = aParamName;
2626 if ( bNoArgs )
2627 aArgs[0].Value = makeAny( GetToolBox().IsItemChecked( GetId() ));
2628 else
2629 aArgs[0].Value = makeAny( (sal_uInt32)( mLastColor.GetColor() ));
2630 Dispatch( aCommand, aArgs );
2633 //========================================================================
2634 // class SvxFrameToolBoxControl ------------------------------------------
2635 //========================================================================
2637 SvxFrameToolBoxControl::SvxFrameToolBoxControl(
2638 sal_uInt16 nSlotId,
2639 sal_uInt16 nId,
2640 ToolBox& rTbx )
2642 : SfxToolBoxControl( nSlotId, nId, rTbx )
2644 rTbx.SetItemBits( nId, TIB_DROPDOWNONLY | rTbx.GetItemBits( nId ) );
2647 // -----------------------------------------------------------------------
2649 SfxPopupWindowType SvxFrameToolBoxControl::GetPopupWindowType() const
2651 return SFX_POPUPWINDOW_ONCLICK;
2654 // -----------------------------------------------------------------------
2656 SfxPopupWindow* SvxFrameToolBoxControl::CreatePopupWindow()
2658 SvxFrameWindow_Impl* pFrameWin = new SvxFrameWindow_Impl(
2659 GetSlotId(), m_xFrame, &GetToolBox() );
2661 pFrameWin->StartPopupMode( &GetToolBox(),
2662 FLOATWIN_POPUPMODE_GRABFOCUS |
2663 FLOATWIN_POPUPMODE_ALLOWTEAROFF |
2664 FLOATWIN_POPUPMODE_NOAPPFOCUSCLOSE );
2665 pFrameWin->StartSelection();
2666 SetPopupWindow( pFrameWin );
2668 return pFrameWin;
2671 // -----------------------------------------------------------------------
2673 void SvxFrameToolBoxControl::StateChanged(
2675 sal_uInt16, SfxItemState eState, const SfxPoolItem* )
2678 sal_uInt16 nId = GetId();
2679 ToolBox& rTbx = GetToolBox();
2681 rTbx.EnableItem( nId, SFX_ITEM_DISABLED != eState );
2682 rTbx.SetItemState( nId, (SFX_ITEM_DONTCARE == eState)
2683 ? STATE_DONTKNOW
2684 : STATE_NOCHECK );
2687 //========================================================================
2688 // class SvxFrameLineStyleToolBoxControl ---------------------------------
2689 //========================================================================
2691 SvxFrameLineStyleToolBoxControl::SvxFrameLineStyleToolBoxControl(
2692 sal_uInt16 nSlotId,
2693 sal_uInt16 nId,
2694 ToolBox& rTbx )
2696 : SfxToolBoxControl( nSlotId, nId, rTbx )
2698 rTbx.SetItemBits( nId, TIB_DROPDOWNONLY | rTbx.GetItemBits( nId ) );
2701 // -----------------------------------------------------------------------
2703 SfxPopupWindowType SvxFrameLineStyleToolBoxControl::GetPopupWindowType() const
2705 return SFX_POPUPWINDOW_ONCLICK;
2708 // -----------------------------------------------------------------------
2710 SfxPopupWindow* SvxFrameLineStyleToolBoxControl::CreatePopupWindow()
2712 SvxLineWindow_Impl* pLineWin = new SvxLineWindow_Impl( GetSlotId(), m_xFrame, &GetToolBox() );
2713 pLineWin->StartPopupMode( &GetToolBox(),
2714 FLOATWIN_POPUPMODE_GRABFOCUS |
2715 FLOATWIN_POPUPMODE_ALLOWTEAROFF |
2716 FLOATWIN_POPUPMODE_NOAPPFOCUSCLOSE );
2717 SetPopupWindow( pLineWin );
2719 return pLineWin;
2722 // -----------------------------------------------------------------------
2724 void SvxFrameLineStyleToolBoxControl::StateChanged(
2726 sal_uInt16 , SfxItemState eState, const SfxPoolItem* )
2728 sal_uInt16 nId = GetId();
2729 ToolBox& rTbx = GetToolBox();
2731 rTbx.EnableItem( nId, SFX_ITEM_DISABLED != eState );
2732 rTbx.SetItemState( nId, (SFX_ITEM_DONTCARE == eState)
2733 ? STATE_DONTKNOW
2734 : STATE_NOCHECK );
2737 //========================================================================
2738 // class SvxFrameLineColorToolBoxControl ---------------------------------
2739 //========================================================================
2741 SvxFrameLineColorToolBoxControl::SvxFrameLineColorToolBoxControl(
2742 sal_uInt16 nSlotId,
2743 sal_uInt16 nId,
2744 ToolBox& rTbx ) :
2746 SfxToolBoxControl( nSlotId, nId, rTbx ),
2747 pBtnUpdater(new ::svx::ToolboxButtonColorUpdater( nSlotId, nId, &GetToolBox() )),
2748 mLastColor( COL_AUTO )
2750 rTbx.SetItemBits( nId, TIB_DROPDOWNONLY | rTbx.GetItemBits( nId ) );
2753 // -----------------------------------------------------------------------
2755 SvxFrameLineColorToolBoxControl::~SvxFrameLineColorToolBoxControl()
2758 delete pBtnUpdater;
2761 // -----------------------------------------------------------------------
2763 SfxPopupWindowType SvxFrameLineColorToolBoxControl::GetPopupWindowType() const
2765 return SFX_POPUPWINDOW_ONCLICK;
2768 // -----------------------------------------------------------------------
2770 SfxPopupWindow* SvxFrameLineColorToolBoxControl::CreatePopupWindow()
2772 SvxColorWindow_Impl* pColorWin = new SvxColorWindow_Impl(
2773 OUString( ".uno:FrameLineColor" ),
2774 SID_FRAME_LINECOLOR,
2775 m_xFrame,
2776 SVX_RESSTR(RID_SVXSTR_FRAME_COLOR),
2777 &GetToolBox(),
2778 mLastColor);
2780 pColorWin->StartPopupMode( &GetToolBox(),
2781 FLOATWIN_POPUPMODE_GRABFOCUS|FLOATWIN_POPUPMODE_ALLOWTEAROFF|FLOATWIN_POPUPMODE_NOAPPFOCUSCLOSE );
2782 pColorWin->StartSelection();
2783 SetPopupWindow( pColorWin );
2784 return pColorWin;
2787 // -----------------------------------------------------------------------
2789 void SvxFrameLineColorToolBoxControl::StateChanged(
2790 sal_uInt16 , SfxItemState eState, const SfxPoolItem* pState )
2792 sal_uInt16 nId = GetId();
2793 ToolBox& rTbx = GetToolBox();
2794 rTbx.EnableItem( nId, SFX_ITEM_DISABLED != eState );
2795 rTbx.SetItemState( nId, ( SFX_ITEM_DONTCARE == eState ) ? STATE_DONTKNOW : STATE_NOCHECK );
2797 const SvxColorItem* pItem = 0;
2798 if ( SFX_ITEM_DONTCARE != eState )
2800 pItem = PTR_CAST( SvxColorItem, pState );
2801 if ( pItem )
2803 pBtnUpdater->Update( pItem->GetValue());
2804 mLastColor = pItem->GetValue();
2809 //========================================================================
2810 // class SvxSimpleUndoRedoController -------------------------------------
2811 //========================================================================
2813 SvxSimpleUndoRedoController::SvxSimpleUndoRedoController( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
2814 :SfxToolBoxControl( nSlotId, nId, rTbx )
2816 aDefaultText = rTbx.GetItemText( nId );
2819 // -----------------------------------------------------------------------
2821 SvxSimpleUndoRedoController::~SvxSimpleUndoRedoController()
2825 // -----------------------------------------------------------------------
2827 void SvxSimpleUndoRedoController::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
2829 SfxStringItem* pItem = PTR_CAST( SfxStringItem, pState );
2830 ToolBox& rBox = GetToolBox();
2831 if ( pItem && eState != SFX_ITEM_DISABLED )
2833 OUString aNewText( MnemonicGenerator::EraseAllMnemonicChars( pItem->GetValue() ) );
2834 rBox.SetQuickHelpText( GetId(), aNewText );
2836 if ( eState == SFX_ITEM_DISABLED )
2837 rBox.SetQuickHelpText( GetId(), aDefaultText );
2838 rBox.EnableItem( GetId(), eState != SFX_ITEM_DISABLED );
2841 //========================================================================
2843 static void lcl_ResizeValueSet( Window &rWin, ValueSet &rValueSet )
2845 Size aSize = rWin.GetOutputSizePixel();
2846 aSize.Width() -= 4;
2847 aSize.Height() -= 4;
2848 rValueSet.SetPosSizePixel( Point(2,2), aSize );
2851 // -----------------------------------------------------------------------
2853 static void lcl_CalcSizeValueSet( Window &rWin, ValueSet &rValueSet, const Size &aItemSize )
2855 Size aSize = rValueSet.CalcWindowSizePixel( aItemSize );
2856 aSize.Width() += 4;
2857 aSize.Height() += 4;
2858 rWin.SetOutputSizePixel( aSize );
2861 // -----------------------------------------------------------------------------
2862 Reference< ::com::sun::star::accessibility::XAccessible > SvxFontNameBox_Impl::CreateAccessible()
2864 FillList();
2865 return FontNameBox::CreateAccessible();
2868 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */