xref: /AOO41X/main/svx/source/tbxctrls/tbcontrl.cxx (revision 707fc0d4d52eb4f69d89a98ffec6918ca5de6326)
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 ---------------------------------------------------------------
28 
29 
30 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers
31 #include <tools/shl.hxx>
32 #include <svl/poolitem.hxx>
33 #include <svl/eitem.hxx>
34 #include <vcl/toolbox.hxx>
35 #include <vcl/bmpacc.hxx>
36 #include <svtools/valueset.hxx>
37 #include <svtools/ctrlbox.hxx>
38 #include <svl/style.hxx>
39 #include <svtools/ctrltool.hxx>
40 #include <svl/stritem.hxx>
41 #include <unotools/pathoptions.hxx>
42 #include <sfx2/tplpitem.hxx>
43 #include <sfx2/dispatch.hxx>
44 #include <sfx2/viewsh.hxx>
45 #include <sfx2/objsh.hxx>
46 #include <sfx2/docfac.hxx>
47 #include <sfx2/templdlg.hxx>
48 #include <svl/isethint.hxx>
49 #include <sfx2/querystatus.hxx>
50 #include <sfx2/sfxstatuslistener.hxx>
51 #include <tools/urlobj.hxx>
52 #include <sfx2/childwin.hxx>
53 #include <sfx2/viewfrm.hxx>
54 #include <unotools/fontoptions.hxx>
55 #include <vcl/mnemonic.hxx>
56 
57 #include <vcl/svapp.hxx>
58 #include <svl/smplhint.hxx>
59 
60 #define _SVX_TBCONTRL_CXX
61 #include <svtools/colorcfg.hxx>
62 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
63 #include <com/sun/star/lang/XServiceInfo.hpp>
64 #include <com/sun/star/beans/XPropertySet.hpp>
65 #include <com/sun/star/frame/status/ItemStatus.hpp>
66 #include <com/sun/star/frame/status/FontHeight.hpp>
67 
68 #include <svx/dialogs.hrc>
69 #include <svx/svxitems.hrc>
70 #include "helpid.hrc"
71 #include "svx/htmlmode.hxx"
72 #include <svx/xtable.hxx>
73 #include "editeng/fontitem.hxx"
74 #include <editeng/fhgtitem.hxx>
75 #include <editeng/brshitem.hxx>
76 #include <editeng/boxitem.hxx>
77 #include <editeng/colritem.hxx>
78 #include "editeng/flstitem.hxx"
79 #include "editeng/bolnitem.hxx"
80 #include "svx/drawitem.hxx"
81 #include <svx/tbcontrl.hxx>
82 #include "svx/dlgutil.hxx"
83 #include <svx/dialmgr.hxx>
84 #include "colorwindow.hxx"
85 #include <memory>
86 
87 #include <svx/tbxcolorupdate.hxx>
88 #include <editeng/eerdll.hxx>
89 #include <editeng/editrids.hrc>
90 
91 // ------------------------------------------------------------------------
92 
93 #define MAX_MRU_FONTNAME_ENTRIES    5
94 #define LOGICAL_EDIT_HEIGHT         12
95 
96 // STATIC DATA -----------------------------------------------------------
97 
98 #ifndef DELETEZ
99 #define DELETEZ(p) (delete (p), (p)=NULL)
100 #endif
101 // don't make more than 15 entries visible at once
102 #define MAX_STYLES_ENTRIES          static_cast< sal_uInt16 >( 15 )
103 
104 void lcl_ResizeValueSet( Window &rWin, ValueSet &rValueSet );
105 void lcl_CalcSizeValueSet( Window &rWin, ValueSet &rValueSet, const Size &aItemSize );
106 sal_Bool lcl_FontChangedHint( const SfxHint &rHint );
107 
108 // namespaces
109 using ::rtl::OUString;
110 using namespace ::com::sun::star;
111 using namespace ::com::sun::star::uno;
112 using namespace ::com::sun::star::frame;
113 using namespace ::com::sun::star::util;
114 using namespace ::com::sun::star::beans;
115 using namespace ::com::sun::star::lang;
116 
117 SFX_IMPL_TOOLBOX_CONTROL( SvxStyleToolBoxControl, SfxTemplateItem );
118 SFX_IMPL_TOOLBOX_CONTROL( SvxFontNameToolBoxControl, SvxFontItem );
119 SFX_IMPL_TOOLBOX_CONTROL( SvxFontColorToolBoxControl, SvxColorItem );
120 SFX_IMPL_TOOLBOX_CONTROL( SvxFontColorExtToolBoxControl, SvxColorItem );
121 SFX_IMPL_TOOLBOX_CONTROL( SvxColorToolBoxControl, SvxColorItem );
122 SFX_IMPL_TOOLBOX_CONTROL( SvxFrameToolBoxControl, SvxBoxItem );
123 SFX_IMPL_TOOLBOX_CONTROL( SvxFrameLineStyleToolBoxControl, SvxLineItem );
124 SFX_IMPL_TOOLBOX_CONTROL( SvxFrameLineColorToolBoxControl, SvxColorItem );
125 SFX_IMPL_TOOLBOX_CONTROL( SvxReloadControllerItem,  SfxBoolItem );
126 SFX_IMPL_TOOLBOX_CONTROL( SvxSimpleUndoRedoController, SfxStringItem );
127 
128 //========================================================================
129 // class SvxStyleBox_Impl -----------------------------------------------------
130 //========================================================================
131 
132 
133 class SvxStyleBox_Impl : public ComboBox
134 {
135     using Window::IsVisible;
136 public:
137     SvxStyleBox_Impl( Window* pParent, sal_uInt16 nSlot, const OUString& rCommand, SfxStyleFamily eFamily, const Reference< XDispatchProvider >& rDispatchProvider,
138                         const Reference< XFrame >& _xFrame,const String& rClearFormatKey, const String& rMoreKey, sal_Bool bInSpecialMode );
139     ~SvxStyleBox_Impl();
140 
141     void            SetFamily( SfxStyleFamily eNewFamily );
142     inline sal_Bool     IsVisible() { return bVisible; }
143 
144     virtual long    PreNotify( NotifyEvent& rNEvt );
145     virtual long    Notify( NotifyEvent& rNEvt );
146     virtual void    DataChanged( const DataChangedEvent& rDCEvt );
147     virtual void    StateChanged( StateChangedType nStateChange );
148 
149     inline void     SetVisibilityListener( const Link& aVisListener ) { aVisibilityListener = aVisListener; }
150     inline void     RemoveVisibilityListener() { aVisibilityListener = Link(); }
151 
152     void            SetDefaultStyle( const ::rtl::OUString& rDefault ) { sDefaultStyle = rDefault; }
153     DECL_STATIC_LINK( SvxStyleBox_Impl, FocusHdl_Impl, Control* );
154 
155 protected:
156     virtual void    Select();
157 
158 private:
159     sal_uInt16                          nSlotId;
160     SfxStyleFamily                  eStyleFamily;
161     sal_uInt16                          nCurSel;
162     sal_Bool                            bRelease;
163     Size                            aLogicalSize;
164     Link                            aVisibilityListener;
165     sal_Bool                            bVisible;
166     Reference< XDispatchProvider >  m_xDispatchProvider;
167     Reference< XFrame >             m_xFrame;
168     OUString                        m_aCommand;
169     String                          aClearFormatKey;
170     String                          aMoreKey;
171     String                          sDefaultStyle;
172     sal_Bool                            bInSpecialMode;
173 
174     void            ReleaseFocus();
175 };
176 
177 //========================================================================
178 // class SvxFontNameBox --------------------------------------------------
179 //========================================================================
180 
181 class SvxFontNameBox_Impl : public FontNameBox
182 {
183     using Window::Update;
184 private:
185     const FontList*                pFontList;
186     ::std::auto_ptr<FontList>      m_aOwnFontList;
187     Font                           aCurFont;
188     Size                           aLogicalSize;
189     String                         aCurText;
190     sal_uInt16                         nFtCount;
191     sal_Bool                           bRelease;
192     Reference< XDispatchProvider > m_xDispatchProvider;
193     Reference< XFrame >            m_xFrame;
194 
195     void            ReleaseFocus_Impl();
196     void            EnableControls_Impl();
197 
198 protected:
199     virtual void    Select();
200     virtual void    DataChanged( const DataChangedEvent& rDCEvt );
201 
202 public:
203     SvxFontNameBox_Impl( Window* pParent, const Reference< XDispatchProvider >& rDispatchProvider,const Reference< XFrame >& _xFrame
204         , WinBits nStyle = WB_SORT
205         );
206 
207     void            FillList();
208     void            Update( const SvxFontItem* pFontItem );
209     sal_uInt16          GetListCount() { return nFtCount; }
210     void            Clear() { FontNameBox::Clear(); nFtCount = 0; }
211     void            Fill( const FontList* pList )
212                         { FontNameBox::Fill( pList );
213                           nFtCount = pList->GetFontNameCount(); }
214     virtual long    PreNotify( NotifyEvent& rNEvt );
215     virtual long    Notify( NotifyEvent& rNEvt );
216     virtual Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible();
217     inline void     SetOwnFontList(::std::auto_ptr<FontList> _aOwnFontList) { m_aOwnFontList = _aOwnFontList; }
218 };
219 
220 //========================================================================
221 // class SvxFrameWindow_Impl --------------------------------------------------
222 //========================================================================
223 
224 // fuer den SelectHdl werden die Modifier gebraucht, also
225 // muss man sie im MouseButtonUp besorgen
226 
227 class SvxFrmValueSet_Impl : public ValueSet
228 {
229     sal_uInt16          nModifier;
230     virtual void    MouseButtonUp( const MouseEvent& rMEvt );
231 public:
232     SvxFrmValueSet_Impl(Window* pParent,  WinBits nWinStyle)
233         : ValueSet(pParent, nWinStyle), nModifier(0) {}
234     sal_uInt16          GetModifier() const {return nModifier;}
235 
236 };
237 
238 void SvxFrmValueSet_Impl::MouseButtonUp( const MouseEvent& rMEvt )
239 {
240     nModifier = rMEvt.GetModifier();
241     ValueSet::MouseButtonUp(rMEvt);
242 }
243 
244 class SvxFrameWindow_Impl : public SfxPopupWindow
245 {
246     using FloatingWindow::StateChanged;
247 
248 private:
249     SvxFrmValueSet_Impl  aFrameSet;
250     ImageList       aImgList;
251     sal_Bool        bParagraphMode;
252 
253 #if _SOLAR__PRIVATE
254     DECL_LINK( SelectHdl, void * );
255 #endif
256 
257 protected:
258     virtual void    Resize();
259     virtual sal_Bool    Close();
260     virtual Window* GetPreferredKeyInputWindow();
261     virtual void    GetFocus();
262 
263 public:
264     SvxFrameWindow_Impl( sal_uInt16 nId, const Reference< XFrame >& rFrame, Window* pParentWindow );
265     ~SvxFrameWindow_Impl();
266     void            StartSelection();
267 
268     virtual void    StateChanged( sal_uInt16 nSID, SfxItemState eState,
269                                   const SfxPoolItem* pState );
270     virtual SfxPopupWindow* Clone() const;
271     virtual void    DataChanged( const DataChangedEvent& rDCEvt );
272 
273     inline sal_Bool     IsHighContrast( void ) const;
274 };
275 
276 inline sal_Bool SvxFrameWindow_Impl::IsHighContrast( void ) const
277 {
278     return GetSettings().GetStyleSettings().GetHighContrastMode();
279 }
280 
281 //========================================================================
282 // class SvxLineWindow_Impl ---------------------------------------------------
283 //========================================================================
284 class SvxLineWindow_Impl : public SfxPopupWindow
285 {
286 private:
287     ValueSet            aLineSet;
288     bool                m_bIsWriter;
289 
290 #if _SOLAR__PRIVATE
291     void            MakeLineBitmap( sal_uInt16 nNo, Bitmap& rBmp, const Size& rSize, String& rStr,
292                                     const ::Color& rLine, const ::Color& rBack );
293     DECL_LINK( SelectHdl, void * );
294 #endif
295 
296 protected:
297     virtual void    Resize();
298     virtual sal_Bool    Close();
299     virtual Window* GetPreferredKeyInputWindow();
300     virtual void    GetFocus();
301     virtual void    DataChanged( const DataChangedEvent& rDCEvt );
302     void            CreateBitmaps( void );
303 public:
304     SvxLineWindow_Impl( sal_uInt16 nId, const Reference< XFrame >& rFrame, Window* pParentWindow );
305 
306     void                    StartSelection();
307     virtual SfxPopupWindow* Clone() const;
308 };
309 
310 //########################################################################
311 // Hilfsklassen:
312 //========================================================================
313 // class SfxStyleControllerItem ------------------------------------------
314 //========================================================================
315 class SvxStyleToolBoxControl;
316 
317 class SfxStyleControllerItem_Impl : public SfxStatusListener
318 {
319     public:
320         SfxStyleControllerItem_Impl( const Reference< XDispatchProvider >& rDispatchProvider,
321                                      sal_uInt16 nSlotId,
322                                      const rtl::OUString& rCommand,
323                                      SvxStyleToolBoxControl& rTbxCtl );
324 
325     protected:
326         virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState );
327 
328     private:
329         SvxStyleToolBoxControl& rControl;
330 };
331 
332 //========================================================================
333 // class SvxStyleBox_Impl -----------------------------------------------------
334 //========================================================================
335 
336 SvxStyleBox_Impl::SvxStyleBox_Impl(
337     Window*                                 pParent,
338     sal_uInt16                                  nSlot,
339     const rtl::OUString&                    rCommand,
340     SfxStyleFamily                          eFamily,
341     const Reference< XDispatchProvider >&   rDispatchProvider,
342     const Reference< XFrame >&              _xFrame,
343     const String&                           rClearFormatKey,
344     const String&                           rMoreKey,
345     sal_Bool                                    bInSpec) :
346 
347     ComboBox( pParent, SVX_RES( RID_SVXTBX_STYLE ) ),
348 
349     nSlotId     ( nSlot ),
350     eStyleFamily( eFamily ),
351     bRelease    ( sal_True ),
352     bVisible(sal_False),
353     m_xDispatchProvider( rDispatchProvider ),
354     m_xFrame(_xFrame),
355     m_aCommand  ( rCommand ),
356     aClearFormatKey ( rClearFormatKey ),
357     aMoreKey        ( rMoreKey ),
358     bInSpecialMode  ( bInSpec )
359 {
360     aLogicalSize = PixelToLogic( GetSizePixel(), MAP_APPFONT );
361     EnableAutocomplete( sal_True );
362 }
363 
364 SvxStyleBox_Impl::~SvxStyleBox_Impl()
365 {
366 }
367 
368 // -----------------------------------------------------------------------
369 
370 void SvxStyleBox_Impl::ReleaseFocus()
371 {
372     if ( !bRelease )
373     {
374         bRelease = sal_True;
375         return;
376     }
377     if ( m_xFrame.is() && m_xFrame->getContainerWindow().is() )
378         m_xFrame->getContainerWindow()->setFocus();
379 }
380 
381 // -----------------------------------------------------------------------
382 
383 void SvxStyleBox_Impl::Select()
384 {
385     // Tell base class about selection so that AT get informed about it.
386     ComboBox::Select();
387 
388     if ( !IsTravelSelect() )
389     {
390         String aSelEntry( GetText() );
391         bool bDoIt = true, bClear = false;
392         if( bInSpecialMode )
393         {
394             if( aSelEntry == aClearFormatKey && GetSelectEntryPos() == 0 )
395             {
396                 aSelEntry = sDefaultStyle;
397                 bClear = true;
398                 //not only apply default style but also call 'ClearFormatting'
399                 Sequence< PropertyValue > aEmptyVals;
400                 SfxToolBoxControl::Dispatch( m_xDispatchProvider, String::CreateFromAscii(".uno:ResetAttributes"),
401                     aEmptyVals);
402             }
403             else if( aSelEntry == aMoreKey && GetSelectEntryPos() == ( GetEntryCount() - 1 ) )
404             {
405                 SfxViewFrame* pViewFrm = SfxViewFrame::Current();
406                 DBG_ASSERT( pViewFrm, "SvxStyleBox_Impl::Select(): no viewframe" );
407                 pViewFrm->ShowChildWindow( SID_STYLE_DESIGNER );
408                 SfxChildWindow* pChildWin = pViewFrm->GetChildWindow( SID_STYLE_DESIGNER );
409                 if ( pChildWin && pChildWin->GetWindow() )
410                 {
411                     static_cast< SfxTemplateDialogWrapper* >( pChildWin )->SetParagraphFamily();
412                     static_cast< SfxDockingWindow* >( pChildWin->GetWindow() )->AutoShow( sal_True );
413                     Application::PostUserEvent(
414                         STATIC_LINK( 0, SvxStyleBox_Impl, FocusHdl_Impl ), pChildWin->GetWindow() );
415                 }
416                 bDoIt = false;
417             }
418         }
419 
420         // #i36723# after ReleaseFocus() the new entry is included into the List
421         sal_Bool bCreateNew = GetSelectEntryPos() == LISTBOX_ENTRY_NOTFOUND;
422 
423         /*  #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
424             This instance may be deleted in the meantime (i.e. when a dialog is opened
425             while in Dispatch()), accessing members will crash in this case. */
426         ReleaseFocus();
427 
428         if( bDoIt )
429         {
430             if ( bClear )
431                 SetText( aSelEntry );
432             SaveValue();
433 
434             Sequence< PropertyValue > aArgs( 2 );
435             aArgs[0].Value  = makeAny( OUString( aSelEntry ) );
436             aArgs[1].Name   = OUString::createFromAscii( "Family" );
437             aArgs[1].Value  = makeAny( sal_Int16( eStyleFamily ));
438             if( bCreateNew )
439             {
440                 aArgs[0].Name   = OUString::createFromAscii( "Param" );
441                 SfxToolBoxControl::Dispatch( m_xDispatchProvider, String::CreateFromAscii(".uno:StyleNewByExample"), aArgs);
442             }
443             else
444             {
445                 aArgs[0].Name   = OUString::createFromAscii( "Template" );
446                 SfxToolBoxControl::Dispatch( m_xDispatchProvider, m_aCommand, aArgs );
447             }
448         }
449     }
450 }
451 // -----------------------------------------------------------------------
452 
453 void SvxStyleBox_Impl::SetFamily( SfxStyleFamily eNewFamily )
454 {
455     eStyleFamily = eNewFamily;
456 }
457 
458 // -----------------------------------------------------------------------
459 
460 long SvxStyleBox_Impl::PreNotify( NotifyEvent& rNEvt )
461 {
462     sal_uInt16 nType = rNEvt.GetType();
463 
464     if ( EVENT_MOUSEBUTTONDOWN == nType || EVENT_GETFOCUS == nType )
465         nCurSel = GetSelectEntryPos();
466     else if ( EVENT_LOSEFOCUS == nType )
467     {
468         // don't handle before our Select() is called
469         if ( !HasFocus() && !HasChildPathFocus() )
470             SetText( GetSavedValue() );
471     }
472     return ComboBox::PreNotify( rNEvt );
473 }
474 
475 // -----------------------------------------------------------------------
476 
477 long SvxStyleBox_Impl::Notify( NotifyEvent& rNEvt )
478 {
479     long nHandled = 0;
480 
481     if ( rNEvt.GetType() == EVENT_KEYINPUT )
482     {
483         sal_uInt16 nCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
484 
485         switch ( nCode )
486         {
487             case KEY_RETURN:
488             case KEY_TAB:
489             {
490                 if ( KEY_TAB == nCode )
491                     bRelease = sal_False;
492                 else
493                     nHandled = 1;
494                 Select();
495                 break;
496             }
497 
498             case KEY_ESCAPE:
499                 SelectEntryPos( nCurSel );
500                 ReleaseFocus();
501                 nHandled = 1;
502                 break;
503         }
504     }
505     return nHandled ? nHandled : ComboBox::Notify( rNEvt );
506 }
507 /* -----------------------------08.03.2002 13:03------------------------------
508 
509  ---------------------------------------------------------------------------*/
510 void SvxStyleBox_Impl::DataChanged( const DataChangedEvent& rDCEvt )
511 {
512     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
513          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
514     {
515         SetSizePixel(LogicToPixel(aLogicalSize, MAP_APPFONT));
516         Size aDropSize( aLogicalSize.Width(), LOGICAL_EDIT_HEIGHT);
517         SetDropDownSizePixel(LogicToPixel(aDropSize, MAP_APPFONT));
518     }
519 
520     ComboBox::DataChanged( rDCEvt );
521 }
522 
523 void SvxStyleBox_Impl::StateChanged( StateChangedType nStateChange )
524 {
525     ComboBox::StateChanged( nStateChange );
526 
527     if ( nStateChange == STATE_CHANGE_VISIBLE )
528     {
529         bVisible = IsReallyVisible();
530         if ( aVisibilityListener.IsSet() )
531             aVisibilityListener.Call( this );
532     }
533     else if ( nStateChange == STATE_CHANGE_INITSHOW )
534     {
535         bVisible = sal_True;
536         if ( aVisibilityListener.IsSet() )
537             aVisibilityListener.Call( this );
538     }
539 }
540 
541 //--------------------------------------------------------------------
542 
543 IMPL_STATIC_LINK( SvxStyleBox_Impl, FocusHdl_Impl, Control*, _pCtrl )
544 {
545     (void)pThis;
546     if ( _pCtrl )
547         _pCtrl->GrabFocus();
548     return 0;
549 }
550 
551 // -----------------------------------------------------------------------
552 
553 sal_Bool GetDocFontList_Impl( const FontList** ppFontList, SvxFontNameBox_Impl* pBox )
554 {
555     sal_Bool bChanged = sal_False;
556     const SfxObjectShell* pDocSh = SfxObjectShell::Current();
557     SvxFontListItem* pFontListItem = NULL;
558 
559     if ( pDocSh )
560         pFontListItem =
561             (SvxFontListItem*)pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST );
562     else
563     {
564         ::std::auto_ptr<FontList> aFontList(new FontList( pBox ));
565         *ppFontList = aFontList.get();
566         pBox->SetOwnFontList(aFontList);
567         bChanged = sal_True;
568     }
569 
570     if ( pFontListItem )
571     {
572         const FontList* pNewFontList = pFontListItem->GetFontList();
573         DBG_ASSERT( pNewFontList, "Doc-FontList not available!" );
574 
575         // keine alte Liste, aber neue Liste
576         if ( !*ppFontList && pNewFontList )
577         {
578             // => "ubernehmen
579             *ppFontList = pNewFontList;
580             bChanged = sal_True;
581         }
582         else
583         {
584             // Vergleich der Fontlisten ist nicht vollkommen
585             // wird die Fontliste am Doc geaendert, kann man hier
586             // nur ueber die Listbox Aenderungen feststellen, weil
587             // ppFontList dabei schon upgedatet wurde
588             bChanged =
589                 ( ( *ppFontList != pNewFontList ) ||
590                   pBox->GetListCount() != pNewFontList->GetFontNameCount() );
591             HACK(vergleich ist unvollstaendig)
592 
593             if ( bChanged )
594                 *ppFontList = pNewFontList;
595         }
596 
597         if ( pBox )
598             pBox->Enable();
599     }
600     else if ( pBox && ( pDocSh || ( !pDocSh && !ppFontList )))
601     {
602         // Disable box only when we have a SfxObjectShell and didn't get a font list OR
603         // we don't have a SfxObjectShell and no current font list.
604         // It's possible that we currently have no SfxObjectShell, but a current font list.
605         // See #i58471: When a user set the focus into the font name combo box and opens
606         // the help window with F1. After closing the help window, we disable the font name
607         // combo box. The SfxObjectShell::Current() method returns in that case zero. But the
608         // font list hasn't changed and therefore the combo box shouldn't be disabled!
609         pBox->Disable();
610     }
611 
612     // in die FontBox ggf. auch die neue Liste f"ullen
613     if ( pBox && bChanged )
614     {
615         if ( *ppFontList )
616             pBox->Fill( *ppFontList );
617         else
618             pBox->Clear();
619     }
620     return bChanged;
621 }
622 
623 //========================================================================
624 // class SvxFontNameBox_Impl --------------------------------------------------
625 //========================================================================
626 
627 SvxFontNameBox_Impl::SvxFontNameBox_Impl( Window* pParent, const Reference< XDispatchProvider >& rDispatchProvider,const Reference< XFrame >& _xFrame, WinBits nStyle ) :
628 
629     FontNameBox        ( pParent, nStyle | WinBits( WB_DROPDOWN | WB_AUTOHSCROLL ) ),
630     pFontList          ( NULL ),
631     aLogicalSize       ( 75,160 ),
632     nFtCount           ( 0 ),
633     bRelease           ( sal_True ),
634     m_xDispatchProvider( rDispatchProvider ),
635     m_xFrame (_xFrame)
636 {
637     SetSizePixel(LogicToPixel( aLogicalSize, MAP_APPFONT ));
638     EnableControls_Impl();
639 }
640 // -----------------------------------------------------------------------
641 
642 void SvxFontNameBox_Impl::FillList()
643 {
644     // alte Selektion merken, und am Ende wieder setzen
645     Selection aOldSel = GetSelection();
646     // hat sich Doc-Fontlist geaendert?
647     GetDocFontList_Impl( &pFontList, this );
648     aCurText = GetText();
649     SetSelection( aOldSel );
650 }
651 
652 // -----------------------------------------------------------------------
653 
654 void SvxFontNameBox_Impl::Update( const SvxFontItem* pFontItem )
655 {
656     if ( pFontItem )
657     {
658         aCurFont.SetName        ( pFontItem->GetFamilyName() );
659         aCurFont.SetFamily      ( pFontItem->GetFamily() );
660         aCurFont.SetStyleName   ( pFontItem->GetStyleName() );
661         aCurFont.SetPitch       ( pFontItem->GetPitch() );
662         aCurFont.SetCharSet     ( pFontItem->GetCharSet() );
663     }
664     String aCurName = aCurFont.GetName();
665     if ( GetText() != aCurName )
666         SetText( aCurName );
667 }
668 
669 // -----------------------------------------------------------------------
670 
671 long SvxFontNameBox_Impl::PreNotify( NotifyEvent& rNEvt )
672 {
673     sal_uInt16 nType = rNEvt.GetType();
674 
675     if ( EVENT_MOUSEBUTTONDOWN == nType || EVENT_GETFOCUS == nType )
676     {
677         EnableControls_Impl();
678         FillList();
679     }
680     return FontNameBox::PreNotify( rNEvt );
681 }
682 
683 // -----------------------------------------------------------------------
684 
685 long SvxFontNameBox_Impl::Notify( NotifyEvent& rNEvt )
686 {
687     long nHandled = 0;
688 
689     if ( rNEvt.GetType() == EVENT_KEYINPUT )
690     {
691         sal_uInt16 nCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
692 
693         switch ( nCode )
694         {
695             case KEY_RETURN:
696             case KEY_TAB:
697             {
698                 if ( KEY_TAB == nCode )
699                     bRelease = sal_False;
700                 else
701                     nHandled = 1;
702                 Select();
703                 break;
704             }
705 
706             case KEY_ESCAPE:
707                 SetText( aCurText );
708                 ReleaseFocus_Impl();
709                 break;
710         }
711     }
712     else if ( EVENT_LOSEFOCUS == rNEvt.GetType() )
713     {
714         Window* pFocusWin = Application::GetFocusWindow();
715         if ( !HasFocus() && GetSubEdit() != pFocusWin )
716             SetText( GetSavedValue() );
717     }
718 
719     return nHandled ? nHandled : FontNameBox::Notify( rNEvt );
720 }
721 
722 // ---------------------------------------------------------------------------
723 void SvxFontNameBox_Impl::DataChanged( const DataChangedEvent& rDCEvt )
724 {
725     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
726          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
727     {
728         SetSizePixel(LogicToPixel(aLogicalSize, MAP_APPFONT));
729         Size aDropSize( aLogicalSize.Width(), LOGICAL_EDIT_HEIGHT);
730         SetDropDownSizePixel(LogicToPixel(aDropSize, MAP_APPFONT));
731     }
732 
733     FontNameBox::DataChanged( rDCEvt );
734 }
735 
736 // -----------------------------------------------------------------------
737 
738 void SvxFontNameBox_Impl::ReleaseFocus_Impl()
739 {
740     if ( !bRelease )
741     {
742         bRelease = sal_True;
743         return;
744     }
745     if ( m_xFrame.is() && m_xFrame->getContainerWindow().is() )
746         m_xFrame->getContainerWindow()->setFocus();
747 }
748 
749 // -----------------------------------------------------------------------
750 
751 void SvxFontNameBox_Impl::EnableControls_Impl()
752 {
753     SvtFontOptions aFontOpt;
754     sal_Bool bEnable = aFontOpt.IsFontHistoryEnabled();
755     sal_uInt16 nEntries = bEnable ? MAX_MRU_FONTNAME_ENTRIES : 0;
756     if ( GetMaxMRUCount() != nEntries )
757     {
758         // refill in the next GetFocus-Handler
759         pFontList = NULL;
760         Clear();
761         SetMaxMRUCount( nEntries );
762     }
763 
764     bEnable = aFontOpt.IsFontWYSIWYGEnabled();
765     EnableWYSIWYG( bEnable );
766     EnableSymbols( bEnable );
767 }
768 
769 // -----------------------------------------------------------------------
770 
771 void SvxFontNameBox_Impl::Select()
772 {
773     FontNameBox::Select();
774 
775     if ( !IsTravelSelect() )
776     {
777         if ( pFontList )
778         {
779             FontInfo aInfo( pFontList->Get( GetText(),
780                                             aCurFont.GetWeight(),
781                                             aCurFont.GetItalic() ) );
782             aCurFont = aInfo;
783 
784             SvxFontItem aFontItem( aInfo.GetFamily(),
785                                    aInfo.GetName(),
786                                    aInfo.GetStyleName(),
787                                    aInfo.GetPitch(),
788                                    aInfo.GetCharSet(),
789                                    SID_ATTR_CHAR_FONT );
790 
791             Any a;
792             Sequence< PropertyValue > aArgs( 1 );
793             aArgs[0].Name   = OUString( RTL_CONSTASCII_USTRINGPARAM( "CharFontName" ));
794             aFontItem.QueryValue( a );
795             aArgs[0].Value  = a;
796 
797             //  #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
798             //  This instance may be deleted in the meantime (i.e. when a dialog is opened
799             //  while in Dispatch()), accessing members will crash in this case.
800             ReleaseFocus_Impl();
801 
802             SfxToolBoxControl::Dispatch( m_xDispatchProvider,
803                                          OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CharFontName" )),
804                                          aArgs );
805         }
806         else
807             ReleaseFocus_Impl();
808     }
809 }
810 
811 //========================================================================
812 // class SvxColorWindow_Impl --------------------------------------------------
813 //========================================================================
814 #ifndef WB_NO_DIRECTSELECT
815 #define WB_NO_DIRECTSELECT      ((WinBits)0x04000000)
816 #endif
817 
818 #define PALETTE_X 10
819 #define PALETTE_Y 11
820 #define PALETTE_SIZE (PALETTE_X * PALETTE_Y)
821 
822 SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString&            rCommand,
823                                           sal_uInt16                     nSlotId,
824                                           const Reference< XFrame >& rFrame,
825                                           const String&              rWndTitle,
826                                           Window*                    pParentWindow ) :
827 
828     SfxPopupWindow( nSlotId, rFrame, pParentWindow, WinBits( WB_BORDER | WB_STDFLOATWIN | WB_3DLOOK|WB_DIALOGCONTROL ) ),
829 
830     theSlotId( nSlotId ),
831     aColorSet( this, WinBits( WB_ITEMBORDER | WB_NAMEFIELD | WB_3DLOOK | WB_NO_DIRECTSELECT) ),
832     maCommand( rCommand )
833 
834 {
835     SfxObjectShell* pDocSh = SfxObjectShell::Current();
836     const SfxPoolItem* pItem = NULL;
837     XColorTable* pColorTable = NULL;
838     sal_Bool bKillTable = sal_False;
839     const Size aSize12( 13, 13 );
840 
841     if ( pDocSh )
842         if ( 0 != ( pItem = pDocSh->GetItem( SID_COLOR_TABLE ) ) )
843             pColorTable = ( (SvxColorTableItem*)pItem )->GetColorTable();
844 
845     if ( !pColorTable )
846     {
847         pColorTable = new XColorTable( SvtPathOptions().GetPalettePath() );
848         bKillTable = sal_True;
849     }
850 
851     if ( SID_ATTR_CHAR_COLOR_BACKGROUND == theSlotId || SID_BACKGROUND_COLOR == theSlotId )
852     {
853         aColorSet.SetStyle( aColorSet.GetStyle() | WB_NONEFIELD );
854         aColorSet.SetText( SVX_RESSTR( RID_SVXSTR_TRANSPARENT ) );
855         aColorSet.SetAccessibleName( SVX_RESSTR( RID_SVXSTR_BACKGROUND ) );
856     }
857     else if ( SID_ATTR_CHAR_COLOR == theSlotId || SID_ATTR_CHAR_COLOR2 == theSlotId || SID_EXTRUSION_3D_COLOR == theSlotId )
858     {
859         SfxPoolItem* pDummy;
860 
861         Reference< XDispatchProvider > aDisp( GetFrame()->getController(), UNO_QUERY );
862         SfxQueryStatus aQueryStatus( aDisp,
863                                      SID_ATTR_AUTO_COLOR_INVALID,
864                                      rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:AutoColorInvalid" )));
865         SfxItemState eState = aQueryStatus.QueryState( pDummy );
866         if( (SFX_ITEM_DEFAULT > eState) || ( SID_EXTRUSION_3D_COLOR == theSlotId ) )
867         {
868             aColorSet.SetStyle( aColorSet.GetStyle() | WB_NONEFIELD );
869             aColorSet.SetText( SVX_RESSTR( RID_SVXSTR_AUTOMATIC ) );
870             aColorSet.SetAccessibleName( SVX_RESSTR( RID_SVXSTR_TEXTCOLOR ) );
871         }
872     }
873     else
874     {
875         aColorSet.SetAccessibleName( SVX_RESSTR( RID_SVXSTR_FRAME_COLOR ) );
876     }
877 
878     if ( pColorTable )
879     {
880         short i = 0;
881         long nCount = pColorTable->Count();
882         XColorEntry* pEntry = NULL;
883         ::Color aColWhite( COL_WHITE );
884         String aStrWhite( EditResId(RID_SVXITEMS_COLOR_WHITE) );
885 
886         if ( nCount > PALETTE_SIZE )
887             // Show scrollbar if more than PALLETTE_SIZE colors are available
888             aColorSet.SetStyle( aColorSet.GetStyle() | WB_VSCROLL );
889 
890         for ( i = 0; i < nCount; i++ )
891         {
892             pEntry = pColorTable->GetColor(i);
893             aColorSet.InsertItem( i+1, pEntry->GetColor(), pEntry->GetName() );
894         }
895 
896         while ( i < PALETTE_SIZE )
897         {
898             // fill empty elements if less then PALLETTE_SIZE colors are available
899             aColorSet.InsertItem( i+1, aColWhite, aStrWhite );
900             i++;
901         }
902     }
903 
904     aColorSet.SetSelectHdl( LINK( this, SvxColorWindow_Impl, SelectHdl ) );
905     aColorSet.SetColCount( PALETTE_X );
906     aColorSet.SetLineCount( PALETTE_Y );
907 
908     lcl_CalcSizeValueSet( *this, aColorSet, aSize12 );
909 
910     SetHelpId( HID_POPUP_COLOR );
911     aColorSet.SetHelpId( HID_POPUP_COLOR_CTRL );
912 
913     SetText( rWndTitle );
914     aColorSet.Show();
915 
916     AddStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ColorTableState" )));
917     if ( bKillTable )
918         delete pColorTable;
919 }
920 
921 SvxColorWindow_Impl::~SvxColorWindow_Impl()
922 {
923 }
924 
925 void SvxColorWindow_Impl::KeyInput( const KeyEvent& rKEvt )
926 {
927     aColorSet.KeyInput(rKEvt);
928 }
929 
930 SfxPopupWindow* SvxColorWindow_Impl::Clone() const
931 {
932     return new SvxColorWindow_Impl( maCommand, theSlotId, GetFrame(), GetText(), GetParent() );
933 }
934 
935 // -----------------------------------------------------------------------
936 
937 IMPL_LINK( SvxColorWindow_Impl, SelectHdl, void *, EMPTYARG )
938 {
939     sal_uInt16 nItemId = aColorSet.GetSelectItemId();
940     SvxColorItem aColorItem( aColorSet.GetItemColor( nItemId ), theSlotId );
941 
942     /*  #i33380# DR 2004-09-03 Moved the following line above the Dispatch() calls.
943         This instance may be deleted in the meantime (i.e. when a dialog is opened
944         while in Dispatch()), accessing members will crash in this case. */
945     aColorSet.SetNoSelection();
946 
947     if ( IsInPopupMode() )
948         EndPopupMode();
949 
950     if ( !nItemId && ( SID_ATTR_CHAR_COLOR_BACKGROUND == theSlotId  || SID_BACKGROUND_COLOR == theSlotId ) )
951     {
952         Sequence< PropertyValue > aArgs;
953         SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( GetFrame()->getController(), UNO_QUERY ),
954                                      maCommand,
955                                      aArgs );
956     }
957     else if ( !nItemId && (SID_ATTR_CHAR_COLOR == theSlotId || SID_ATTR_CHAR_COLOR2  == theSlotId || SID_EXTRUSION_3D_COLOR == theSlotId) )
958     {
959         SvxColorItem _aColorItem( COL_AUTO, theSlotId );
960         INetURLObject aObj( maCommand );
961 
962         Any a;
963         Sequence< PropertyValue > aArgs( 1 );
964         aArgs[0].Name = aObj.GetURLPath();
965         _aColorItem.QueryValue( a );
966         aArgs[0].Value = a;
967         SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( GetFrame()->getController(), UNO_QUERY ),
968                                      maCommand,
969                                      aArgs );
970     }
971     else
972     {
973         INetURLObject aObj( maCommand );
974 
975         Any a;
976         Sequence< PropertyValue > aArgs( 1 );
977         aArgs[0].Name = aObj.GetURLPath();
978         aColorItem.QueryValue( a );
979         aArgs[0].Value = a;
980         SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( GetFrame()->getController(), UNO_QUERY ),
981                                      maCommand,
982                                      aArgs );
983     }
984 
985     return 0;
986 }
987 
988 // -----------------------------------------------------------------------
989 
990 void SvxColorWindow_Impl::Resize()
991 {
992     lcl_ResizeValueSet( *this, aColorSet);
993 }
994 
995 // -----------------------------------------------------------------------
996 
997 void SvxColorWindow_Impl::StartSelection()
998 {
999     aColorSet.StartSelection();
1000 }
1001 
1002 // -----------------------------------------------------------------------
1003 
1004 sal_Bool SvxColorWindow_Impl::Close()
1005 {
1006     return SfxPopupWindow::Close();
1007 }
1008 
1009 // -----------------------------------------------------------------------
1010 
1011 void SvxColorWindow_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
1012 {
1013     if (( SFX_ITEM_DISABLED != eState ) && pState )
1014     {
1015         if (( nSID == SID_COLOR_TABLE ) && ( pState->ISA( SvxColorTableItem )))
1016         {
1017             XColorTable* pColorTable = pState ? ((SvxColorTableItem *)pState)->GetColorTable() : NULL;
1018 
1019             if ( pColorTable )
1020             {
1021                 // Die Liste der Farben (ColorTable) hat sich ge"andert:
1022                 short i = 0;
1023                 long nCount = pColorTable->Count();
1024                 XColorEntry* pEntry = NULL;
1025                 ::Color aColWhite( COL_WHITE );
1026                 String aStrWhite( SVX_RES( RID_SVXITEMS_COLOR_WHITE ) );
1027 
1028                 // ScrollBar an oder aus
1029                 WinBits nBits = aColorSet.GetStyle();
1030                 if ( nCount > PALETTE_SIZE )
1031                     nBits &= ~WB_VSCROLL;
1032                 else
1033                     nBits |= WB_VSCROLL;
1034                 aColorSet.SetStyle( nBits );
1035 
1036                 for ( i = 0; i < nCount; ++i )
1037                 {
1038                     pEntry = pColorTable->GetColor(i);
1039                     aColorSet.SetItemColor( i + 1, pEntry->GetColor() );
1040                     aColorSet.SetItemText ( i + 1, pEntry->GetName() );
1041                 }
1042 
1043                 while ( i < PALETTE_SIZE )
1044                 {
1045                     aColorSet.SetItemColor( i + 1, aColWhite );
1046                     aColorSet.SetItemText ( i + 1, aStrWhite );
1047                     i++;
1048                 }
1049             }
1050         }
1051     }
1052 }
1053 
1054 //========================================================================
1055 // class SvxFrameWindow_Impl --------------------------------------------------
1056 //========================================================================
1057 
1058 SvxFrameWindow_Impl::SvxFrameWindow_Impl( sal_uInt16 nId, const Reference< XFrame >& rFrame, Window* pParentWindow ) :
1059 
1060     SfxPopupWindow( nId, rFrame, pParentWindow, WinBits( WB_BORDER | WB_STDFLOATWIN | WB_3DLOOK | WB_DIALOGCONTROL ) ),
1061     aFrameSet   ( this, WinBits( WB_ITEMBORDER | WB_DOUBLEBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT ) ),
1062     bParagraphMode(sal_False)
1063 
1064 {
1065     BindListener();
1066     String sCommand(String::CreateFromAscii( ".uno:BorderReducedMode" ));
1067     AddStatusListener( sCommand );
1068     aImgList = ImageList( SVX_RES( IsHighContrast()? RID_SVXIL_FRAME_HC : RID_SVXIL_FRAME ) );
1069 
1070     /*
1071      *  1       2        3         4
1072      *  -------------------------------------
1073      *  NONE    LEFT     RIGHT     LEFTRIGHT
1074      *  TOP     BOTTOM   TOPBOTTOM OUTER
1075      *  -------------------------------------
1076      *  HOR     HORINNER VERINNER   ALL         <- kann ueber bParagraphMode
1077      *                                             abgeschaltet werden
1078      */
1079 
1080     sal_uInt16 i = 0;
1081 
1082     for ( i=1; i<9; i++ )
1083         aFrameSet.InsertItem( i, aImgList.GetImage(i) );
1084 
1085     //bParagraphMode should have been set in StateChanged
1086     if ( !bParagraphMode )
1087         for ( i = 9; i < 13; i++ )
1088             aFrameSet.InsertItem( i, aImgList.GetImage(i) );
1089 
1090     aFrameSet.SetColCount( 4 );
1091     aFrameSet.SetSelectHdl( LINK( this, SvxFrameWindow_Impl, SelectHdl ) );
1092 
1093     lcl_CalcSizeValueSet( *this, aFrameSet,Size( 20, 20 ));
1094 
1095     SetHelpId( HID_POPUP_FRAME );
1096     SetText( SVX_RESSTR(RID_SVXSTR_FRAME) );
1097     aFrameSet.SetAccessibleName( SVX_RESSTR(RID_SVXSTR_FRAME) );
1098     aFrameSet.Show();
1099 }
1100 /*-- 22.09.2004 12:27:50---------------------------------------------------
1101 
1102   -----------------------------------------------------------------------*/
1103 SvxFrameWindow_Impl::~SvxFrameWindow_Impl()
1104 {
1105     UnbindListener();
1106 }
1107 
1108 SfxPopupWindow* SvxFrameWindow_Impl::Clone() const
1109 {
1110     //! HACK: wie bekomme ich den Paragraph-Mode ??
1111     return new SvxFrameWindow_Impl( GetId(), GetFrame(), GetParent() );
1112 }
1113 
1114 Window* SvxFrameWindow_Impl::GetPreferredKeyInputWindow()
1115 {
1116     return &aFrameSet;
1117 }
1118 
1119 void SvxFrameWindow_Impl::GetFocus()
1120 {
1121     aFrameSet.GrabFocus();
1122 }
1123 
1124 void SvxFrameWindow_Impl::DataChanged( const DataChangedEvent& rDCEvt )
1125 {
1126     SfxPopupWindow::DataChanged( rDCEvt );
1127 
1128     if( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
1129     {
1130         aImgList = ImageList( SVX_RES( IsHighContrast()? RID_SVXIL_FRAME_HC : RID_SVXIL_FRAME ) );
1131 
1132         sal_uInt16  nNumOfItems = aFrameSet.GetItemCount();
1133 
1134         for( sal_uInt16 i = 1 ; i <= nNumOfItems ; ++i )
1135             aFrameSet.SetItemImage( i, aImgList.GetImage( i ) );
1136     }
1137 }
1138 // -----------------------------------------------------------------------
1139 
1140 #define FRM_VALID_LEFT      0x01
1141 #define FRM_VALID_RIGHT     0x02
1142 #define FRM_VALID_TOP       0x04
1143 #define FRM_VALID_BOTTOM    0x08
1144 #define FRM_VALID_HINNER    0x10
1145 #define FRM_VALID_VINNER    0x20
1146 #define FRM_VALID_OUTER     0x0f
1147 #define FRM_VALID_ALL       0xff
1148 
1149 //
1150 // Per default bleiben ungesetzte Linien unveraendert
1151 // Mit Shift werden ungesetzte Linien zurueckgsetzt
1152 //
1153 IMPL_LINK( SvxFrameWindow_Impl, SelectHdl, void *, EMPTYARG )
1154 {
1155     ::Color             aColBlack( COL_BLACK );
1156     SvxBoxItem          aBorderOuter( SID_ATTR_BORDER_OUTER );
1157     SvxBoxInfoItem      aBorderInner( SID_ATTR_BORDER_INNER );
1158     SvxBorderLine       theDefLine;
1159     SvxBorderLine       *pLeft = 0,
1160                         *pRight = 0,
1161                         *pTop = 0,
1162                         *pBottom = 0;
1163     sal_uInt16              nSel = aFrameSet.GetSelectItemId();
1164     sal_uInt16              nModifier = aFrameSet.GetModifier();
1165     sal_uInt8               nValidFlags = 0;
1166 
1167     theDefLine.SetOutWidth( DEF_LINE_WIDTH_0 );
1168     switch ( nSel )
1169     {
1170         case 1: nValidFlags |= FRM_VALID_ALL;
1171         break;  // NONE
1172         case 2: pLeft = &theDefLine;
1173                 nValidFlags |= FRM_VALID_LEFT;
1174         break;  // LEFT
1175         case 3: pRight = &theDefLine;
1176                 nValidFlags |= FRM_VALID_RIGHT;
1177         break;  // RIGHT
1178         case 4: pLeft = pRight = &theDefLine;
1179                 nValidFlags |=  FRM_VALID_RIGHT|FRM_VALID_LEFT;
1180         break;  // LEFTRIGHT
1181         case 5: pTop = &theDefLine;
1182                 nValidFlags |= FRM_VALID_TOP;
1183         break;  // TOP
1184         case 6: pBottom = &theDefLine;
1185                 nValidFlags |= FRM_VALID_BOTTOM;
1186         break;  // BOTTOM
1187         case 7: pTop =  pBottom = &theDefLine;
1188                 nValidFlags |= FRM_VALID_BOTTOM|FRM_VALID_TOP;
1189         break;  // TOPBOTTOM
1190         case 8: pLeft = pRight = pTop = pBottom = &theDefLine;
1191                 nValidFlags |= FRM_VALID_OUTER;
1192         break;  // OUTER
1193 
1194         // Tabelle innen:
1195         case 9: // HOR
1196             pTop = pBottom = &theDefLine;
1197             aBorderInner.SetLine( &theDefLine, BOXINFO_LINE_HORI );
1198             aBorderInner.SetLine( NULL, BOXINFO_LINE_VERT );
1199             nValidFlags |= FRM_VALID_HINNER|FRM_VALID_TOP|FRM_VALID_BOTTOM;
1200             break;
1201 
1202         case 10: // HORINNER
1203             pLeft = pRight = pTop = pBottom = &theDefLine;
1204             aBorderInner.SetLine( &theDefLine, BOXINFO_LINE_HORI );
1205             aBorderInner.SetLine( NULL, BOXINFO_LINE_VERT );
1206             nValidFlags |= FRM_VALID_RIGHT|FRM_VALID_LEFT|FRM_VALID_HINNER|FRM_VALID_TOP|FRM_VALID_BOTTOM;
1207             break;
1208 
1209         case 11: // VERINNER
1210             pLeft = pRight = pTop = pBottom = &theDefLine;
1211             aBorderInner.SetLine( NULL, BOXINFO_LINE_HORI );
1212             aBorderInner.SetLine( &theDefLine, BOXINFO_LINE_VERT );
1213             nValidFlags |= FRM_VALID_RIGHT|FRM_VALID_LEFT|FRM_VALID_VINNER|FRM_VALID_TOP|FRM_VALID_BOTTOM;
1214         break;
1215 
1216         case 12: // ALL
1217             pLeft = pRight = pTop = pBottom = &theDefLine;
1218             aBorderInner.SetLine( &theDefLine, BOXINFO_LINE_HORI );
1219             aBorderInner.SetLine( &theDefLine, BOXINFO_LINE_VERT );
1220             nValidFlags |= FRM_VALID_ALL;
1221             break;
1222 
1223         default:
1224         break;
1225     }
1226     aBorderOuter.SetLine( pLeft, BOX_LINE_LEFT );
1227     aBorderOuter.SetLine( pRight, BOX_LINE_RIGHT );
1228     aBorderOuter.SetLine( pTop, BOX_LINE_TOP );
1229     aBorderOuter.SetLine( pBottom, BOX_LINE_BOTTOM );
1230 
1231     if(nModifier == KEY_SHIFT)
1232         nValidFlags |= FRM_VALID_ALL;
1233     aBorderInner.SetValid( VALID_TOP,       0 != (nValidFlags&FRM_VALID_TOP ));
1234     aBorderInner.SetValid( VALID_BOTTOM,    0 != (nValidFlags&FRM_VALID_BOTTOM ));
1235     aBorderInner.SetValid( VALID_LEFT,      0 != (nValidFlags&FRM_VALID_LEFT));
1236     aBorderInner.SetValid( VALID_RIGHT,     0 != (nValidFlags&FRM_VALID_RIGHT ));
1237     aBorderInner.SetValid( VALID_HORI,      0 != (nValidFlags&FRM_VALID_HINNER ));
1238     aBorderInner.SetValid( VALID_VERT,      0 != (nValidFlags&FRM_VALID_VINNER));
1239     aBorderInner.SetValid( VALID_DISTANCE, sal_True );
1240     aBorderInner.SetValid( VALID_DISABLE, sal_False );
1241 
1242     if ( IsInPopupMode() )
1243         EndPopupMode();
1244 
1245     Any a;
1246     Sequence< PropertyValue > aArgs( 2 );
1247     aArgs[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "OuterBorder" ));
1248     aBorderOuter.QueryValue( a );
1249     aArgs[0].Value = a;
1250     aArgs[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "InnerBorder" ));
1251     aBorderInner.QueryValue( a );
1252     aArgs[1].Value = a;
1253 
1254     /*  #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
1255         This instance may be deleted in the meantime (i.e. when a dialog is opened
1256         while in Dispatch()), accessing members will crash in this case. */
1257     aFrameSet.SetNoSelection();
1258 
1259     SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( GetFrame()->getController(), UNO_QUERY ),
1260                                  OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:SetBorderStyle" )),
1261                                  aArgs );
1262     return 0;
1263 }
1264 
1265 // -----------------------------------------------------------------------
1266 
1267 void SvxFrameWindow_Impl::Resize()
1268 {
1269     lcl_ResizeValueSet( *this, aFrameSet);
1270 }
1271 
1272 // -----------------------------------------------------------------------
1273 
1274 void SvxFrameWindow_Impl::StateChanged(
1275 
1276     sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
1277 
1278 {
1279     if ( pState && nSID == SID_BORDER_REDUCED_MODE)
1280     {
1281         const SfxBoolItem* pItem = PTR_CAST( SfxBoolItem, pState );
1282 
1283         if ( pItem )
1284         {
1285             bParagraphMode = (sal_Bool)pItem->GetValue();
1286             //initial calls mustn't insert or remove elements
1287             if(aFrameSet.GetItemCount())
1288             {
1289                 sal_Bool bTableMode = ( aFrameSet.GetItemCount() == 12 );
1290                 sal_Bool bResize    = sal_False;
1291 
1292                 if ( bTableMode && bParagraphMode )
1293                 {
1294                     for ( sal_uInt16 i = 9; i < 13; i++ )
1295                         aFrameSet.RemoveItem(i);
1296                     bResize = sal_True;
1297                 }
1298                 else if ( !bTableMode && !bParagraphMode )
1299                 {
1300                     for ( sal_uInt16 i = 9; i < 13; i++ )
1301                         aFrameSet.InsertItem( i, aImgList.GetImage(i) );
1302                     bResize = sal_True;
1303                 }
1304 
1305                 if ( bResize )
1306                 {
1307                     lcl_CalcSizeValueSet( *this, aFrameSet,Size( 20, 20 ));
1308                 }
1309             }
1310         }
1311     }
1312     SfxPopupWindow::StateChanged( nSID, eState, pState );
1313 }
1314 
1315 // -----------------------------------------------------------------------
1316 
1317 void SvxFrameWindow_Impl::StartSelection()
1318 {
1319     aFrameSet.StartSelection();
1320 }
1321 
1322 // -----------------------------------------------------------------------
1323 
1324 sal_Bool SvxFrameWindow_Impl::Close()
1325 {
1326     return SfxPopupWindow::Close();
1327 }
1328 
1329 //========================================================================
1330 // class SvxLineWindow_Impl --------------------------------------------------
1331 //========================================================================
1332 
1333 SvxLineWindow_Impl::SvxLineWindow_Impl( sal_uInt16 nId, const Reference< XFrame >& rFrame, Window* pParentWindow ) :
1334 
1335     SfxPopupWindow( nId, rFrame, pParentWindow, WinBits( WB_BORDER | WB_STDFLOATWIN | WB_3DLOOK | WB_DIALOGCONTROL ) ),
1336 
1337     aLineSet( this, WinBits( WB_3DLOOK | WB_ITEMBORDER | WB_DOUBLEBORDER | WB_NAMEFIELD | WB_NONEFIELD | WB_NO_DIRECTSELECT ) )
1338 {
1339     try
1340     {
1341         Reference< lang::XServiceInfo > xServices( rFrame->getController()->getModel(), UNO_QUERY_THROW );
1342         m_bIsWriter = xServices->supportsService(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextDocument")));
1343     }
1344     catch(const uno::Exception& )
1345     {
1346     }
1347     Size    aBmpSize( 55, 12 );
1348     CreateBitmaps();
1349 
1350     aLineSet.SetColCount( 2 );
1351     aLineSet.SetSelectHdl( LINK( this, SvxLineWindow_Impl, SelectHdl ) );
1352     aLineSet.SetText( SVX_RESSTR(RID_SVXSTR_NONE) );
1353 
1354     aLineSet.SetAccessibleName( SVX_RESSTR(RID_SVXSTR_FRAME_STYLE) );
1355     lcl_CalcSizeValueSet( *this, aLineSet, aBmpSize );
1356 
1357     SetHelpId( HID_POPUP_LINE );
1358     SetText( SVX_RESSTR(RID_SVXSTR_FRAME_STYLE) );
1359     aLineSet.Show();
1360 }
1361 
1362 SfxPopupWindow* SvxLineWindow_Impl::Clone() const
1363 {
1364     return new SvxLineWindow_Impl( GetId(), GetFrame(), GetParent() );
1365 }
1366 
1367 // -----------------------------------------------------------------------
1368 
1369 void SvxLineWindow_Impl::MakeLineBitmap( sal_uInt16 nNo, Bitmap& rBmp, const Size& rSize, String& rStr,
1370                                             const ::Color& rLineCol, const ::Color& rBackCol )
1371 {
1372     VirtualDevice   aVirDev( *this );
1373     Rectangle       aRect( Point(2,0), Size(rSize.Width()-4,0) );
1374 
1375     // grau einfaerben und Bitmap sichern:
1376     aVirDev.SetOutputSizePixel( rSize );
1377     aVirDev.SetLineColor();
1378     aVirDev.SetFillColor( rBackCol );
1379     aVirDev.DrawRect( Rectangle( Point(0,0), rSize ) );
1380     aVirDev.SetFillColor( rLineCol );
1381 
1382     sal_uInt16 nLineWidth = 0;
1383     switch ( nNo )
1384     {
1385         case 1: // DEF_LINE_WIDTH_0
1386             aRect.Top()     = 6;
1387             aRect.Bottom()  = 6;
1388             aVirDev.DrawRect( aRect );
1389             break;
1390 
1391         case 2: // DEF_LINE_WIDTH_1
1392             aRect.Top()     = 5;
1393             aRect.Bottom()  = 6;
1394             aVirDev.DrawRect( aRect );
1395             nLineWidth = (sal_uInt16) DEF_LINE_WIDTH_1/20;
1396             break;
1397 
1398         case 3: // DEF_LINE_WIDTH_2
1399             aRect.Top()     = 5;
1400             aRect.Bottom()  = 7;
1401             aVirDev.DrawRect( aRect );
1402             nLineWidth = (sal_uInt16) DEF_LINE_WIDTH_2/20;
1403             break;
1404 
1405         case 4: // DEF_LINE_WIDTH_3
1406             aRect.Top()     = 4;
1407             aRect.Bottom()  = 7;
1408             aVirDev.DrawRect( aRect );
1409             aVirDev.DrawRect( Rectangle( Point(2,4), Point(37,7) ) );
1410             nLineWidth = (sal_uInt16) DEF_LINE_WIDTH_3/20;
1411             break;
1412 
1413         case 5: // DEF_LINE_WIDTH_4
1414             aRect.Top()     = 4;
1415             aRect.Bottom()  = 8;
1416             aVirDev.DrawRect( aRect );
1417             nLineWidth = (sal_uInt16) DEF_LINE_WIDTH_4/20;
1418             break;
1419 
1420         case 6: // DEF_DOUBLE_LINE0
1421             aRect.Top()     = 5;
1422             aRect.Bottom()  = 5;
1423             aVirDev.DrawRect( aRect );
1424             aRect.Top()     = 7;
1425             aRect.Bottom()  = 7;
1426             aVirDev.DrawRect( aRect );
1427             nLineWidth = (sal_uInt16) (DEF_DOUBLE_LINE0_OUT+DEF_DOUBLE_LINE0_IN+DEF_DOUBLE_LINE0_DIST)/20;
1428             break;
1429 
1430         case 7: // DEF_DOUBLE_LINE7
1431             aRect.Top()     = 4;
1432             aRect.Bottom()  = 4;
1433             aVirDev.DrawRect( aRect );
1434             aRect.Top()     = 7;
1435             aRect.Bottom()  = 7;
1436             aVirDev.DrawRect( aRect );
1437             nLineWidth = (sal_uInt16) (DEF_DOUBLE_LINE7_OUT+DEF_DOUBLE_LINE7_IN+DEF_DOUBLE_LINE7_DIST)/20;
1438             break;
1439 
1440         case 8: // DEF_DOUBLE_LINE1
1441             aRect.Top()     = 4;
1442             aRect.Bottom()  = 5;
1443             aVirDev.DrawRect( aRect );
1444             aRect.Top()     = 7;
1445             aRect.Bottom()  = 8;
1446             aVirDev.DrawRect( aRect );
1447             nLineWidth = (sal_uInt16) (DEF_DOUBLE_LINE1_OUT+DEF_DOUBLE_LINE1_IN+DEF_DOUBLE_LINE1_DIST)/20;
1448             break;
1449 
1450         case 9: // DEF_DOUBLE_LINE2
1451             aRect.Top()     = 3;
1452             aRect.Bottom()  = 5;
1453             aVirDev.DrawRect( aRect );
1454             aRect.Top()     = 8;
1455             aRect.Bottom()  = 10;
1456             aVirDev.DrawRect( aRect );
1457             nLineWidth = (sal_uInt16) (DEF_DOUBLE_LINE2_OUT+DEF_DOUBLE_LINE2_IN+DEF_DOUBLE_LINE2_DIST)/20;
1458             break;
1459 
1460         case 10: // DEF_DOUBLE_LINE8
1461             aRect.Top()     = 3;
1462             aRect.Bottom()  = 4;
1463             aVirDev.DrawRect( aRect );
1464             aRect.Top()     = 7;
1465             aRect.Bottom()  = 7;
1466             aVirDev.DrawRect( aRect );
1467             nLineWidth = (sal_uInt16) (DEF_DOUBLE_LINE8_OUT+DEF_DOUBLE_LINE8_IN+DEF_DOUBLE_LINE8_DIST)/20;
1468             break;
1469 
1470         case 11: // DEF_DOUBLE_LINE9
1471             aRect.Top()     = 3;
1472             aRect.Bottom()  = 5;
1473             aVirDev.DrawRect( aRect );
1474             aRect.Top()     = 8;
1475             aRect.Bottom()  = 8;
1476             aVirDev.DrawRect( aRect );
1477             nLineWidth = (sal_uInt16) (DEF_DOUBLE_LINE9_OUT+DEF_DOUBLE_LINE9_IN+DEF_DOUBLE_LINE9_DIST)/20;
1478             break;
1479 
1480         case 12: // DEF_DOUBLE_LINE10
1481             aRect.Top()     = 2;
1482             aRect.Bottom()  = 5;
1483             aVirDev.DrawRect( aRect );
1484             aRect.Top()     = 8;
1485             aRect.Bottom()  = 8;
1486             aVirDev.DrawRect( aRect );
1487             nLineWidth = (sal_uInt16) (DEF_DOUBLE_LINE10_OUT+DEF_DOUBLE_LINE10_IN+DEF_DOUBLE_LINE10_DIST)/20;
1488             break;
1489 
1490         case 13: // DEF_DOUBLE_LINE3
1491             aRect.Top()     = 4;
1492             aRect.Bottom()  = 5;
1493             aVirDev.DrawRect( aRect );
1494             aRect.Top()     = 7;
1495             aRect.Bottom()  = 7;
1496             aVirDev.DrawRect( aRect );
1497             nLineWidth = (sal_uInt16) (DEF_DOUBLE_LINE3_OUT+DEF_DOUBLE_LINE3_IN+DEF_DOUBLE_LINE3_DIST)/20;
1498             break;
1499 
1500         case 14: // DEF_DOUBLE_LINE4
1501             aRect.Top()     = 4;
1502             aRect.Bottom()  = 4;
1503             aVirDev.DrawRect( aRect );
1504             aRect.Top()     = 6;
1505             aRect.Bottom()  = 7;
1506             aVirDev.DrawRect( aRect );
1507             nLineWidth = (sal_uInt16) (DEF_DOUBLE_LINE4_OUT+DEF_DOUBLE_LINE4_IN+DEF_DOUBLE_LINE4_DIST)/20;
1508             break;
1509 
1510         case 15: // DEF_DOUBLE_LINE5
1511             aRect.Top()     = 3;
1512             aRect.Bottom()  = 5;
1513             aVirDev.DrawRect( aRect );
1514             aRect.Top()     = 8;
1515             aRect.Bottom()  = 9;
1516             aVirDev.DrawRect( aRect );
1517             nLineWidth = (sal_uInt16) (DEF_DOUBLE_LINE5_OUT+DEF_DOUBLE_LINE5_IN+DEF_DOUBLE_LINE5_DIST)/20;
1518             break;
1519 
1520         case 16: // DEF_DOUBLE_LINE6
1521             aRect.Top()     = 3;
1522             aRect.Bottom()  = 4;
1523             aVirDev.DrawRect( aRect );
1524             aRect.Top()     = 7;
1525             aRect.Bottom()  = 9;
1526             aVirDev.DrawRect( aRect );
1527             nLineWidth = (sal_uInt16) (DEF_DOUBLE_LINE6_OUT+DEF_DOUBLE_LINE6_IN+DEF_DOUBLE_LINE6_DIST)/20;
1528             break;
1529 
1530         default:
1531             break;
1532     }
1533     if ( nLineWidth )
1534     {
1535         rStr = String::CreateFromInt32( nLineWidth );
1536         rStr.AppendAscii(" pt");
1537     }
1538     rBmp = aVirDev.GetBitmap( Point(0,0), rSize );
1539 }
1540 
1541 // -----------------------------------------------------------------------
1542 
1543 IMPL_LINK( SvxLineWindow_Impl, SelectHdl, void *, EMPTYARG )
1544 {
1545     SvxLineItem     aLineItem( SID_FRAME_LINESTYLE );
1546     sal_uInt16          n1 = 0,
1547                     n2 = 0,
1548                     n3 = 0;
1549     sal_Bool            bSetLine = sal_True;
1550 
1551     switch ( aLineSet.GetSelectItemId() )
1552     {
1553         case  1: n1 = DEF_LINE_WIDTH_0; break;
1554         case  2: n1 = DEF_LINE_WIDTH_1; break;
1555         case  3: n1 = DEF_LINE_WIDTH_2; break;
1556         case  4: n1 = DEF_LINE_WIDTH_3; break;
1557         case  5: n1 = DEF_LINE_WIDTH_4; break;
1558 
1559         case  6: n1 = DEF_DOUBLE_LINE0_OUT;
1560                  n2 = DEF_DOUBLE_LINE0_IN;
1561                  n3 = DEF_DOUBLE_LINE0_DIST;     break;
1562         case  7: n1 = DEF_DOUBLE_LINE7_OUT;
1563                  n2 = DEF_DOUBLE_LINE7_IN;
1564                  n3 = DEF_DOUBLE_LINE7_DIST;     break;
1565         case  8: n1 = DEF_DOUBLE_LINE1_OUT;
1566                  n2 = DEF_DOUBLE_LINE1_IN;
1567                  n3 = DEF_DOUBLE_LINE1_DIST;     break;
1568         case  9: n1 = DEF_DOUBLE_LINE2_OUT;
1569                  n2 = DEF_DOUBLE_LINE2_IN;
1570                  n3 = DEF_DOUBLE_LINE2_DIST;     break;
1571         case 10: n1 = DEF_DOUBLE_LINE8_OUT;
1572                  n2 = DEF_DOUBLE_LINE8_IN;
1573                  n3 = DEF_DOUBLE_LINE8_DIST;     break;
1574         case 11: n1 = DEF_DOUBLE_LINE9_OUT;
1575                  n2 = DEF_DOUBLE_LINE9_IN;
1576                  n3 = DEF_DOUBLE_LINE9_DIST;     break;
1577         case 12: n1 = DEF_DOUBLE_LINE10_OUT;
1578                  n2 = DEF_DOUBLE_LINE10_IN;
1579                  n3 = DEF_DOUBLE_LINE10_DIST; break;
1580         case 13: n1 = DEF_DOUBLE_LINE3_OUT;
1581                  n2 = DEF_DOUBLE_LINE3_IN;
1582                  n3 = DEF_DOUBLE_LINE3_DIST;     break;
1583         case 14: n1 = DEF_DOUBLE_LINE4_OUT;
1584                  n2 = DEF_DOUBLE_LINE4_IN;
1585                  n3 = DEF_DOUBLE_LINE4_DIST;     break;
1586         case 15: n1 = DEF_DOUBLE_LINE5_OUT;
1587                  n2 = DEF_DOUBLE_LINE5_IN;
1588                  n3 = DEF_DOUBLE_LINE5_DIST;     break;
1589         case 16: n1 = DEF_DOUBLE_LINE6_OUT;
1590                  n2 = DEF_DOUBLE_LINE6_IN;
1591                  n3 = DEF_DOUBLE_LINE6_DIST;     break;
1592         case  0:
1593         default:
1594             bSetLine = sal_False;
1595             break;
1596     }
1597     if ( bSetLine )
1598     {
1599         SvxBorderLine aTmp( NULL, n1, n2, n3 );
1600         aLineItem.SetLine( &aTmp );
1601     }
1602     else
1603         aLineItem.SetLine( 0 );
1604 
1605     if ( IsInPopupMode() )
1606         EndPopupMode();
1607 
1608     Any a;
1609     Sequence< PropertyValue > aArgs( 1 );
1610     aArgs[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "LineStyle" ));
1611     aLineItem.QueryValue( a, m_bIsWriter ? CONVERT_TWIPS : 0 );
1612     aArgs[0].Value = a;
1613 
1614     /*  #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
1615         This instance may be deleted in the meantime (i.e. when a dialog is opened
1616         while in Dispatch()), accessing members will crash in this case. */
1617     aLineSet.SetNoSelection();
1618 
1619     SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( GetFrame()->getController(), UNO_QUERY ),
1620                                  OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:LineStyle" )),
1621                                  aArgs );
1622     return 0;
1623 }
1624 
1625 // -----------------------------------------------------------------------
1626 
1627 void SvxLineWindow_Impl::Resize()
1628 {
1629     lcl_ResizeValueSet( *this, aLineSet);
1630 }
1631 
1632 // -----------------------------------------------------------------------
1633 
1634 void SvxLineWindow_Impl::StartSelection()
1635 {
1636     aLineSet.StartSelection();
1637 }
1638 
1639 // -----------------------------------------------------------------------
1640 
1641 sal_Bool SvxLineWindow_Impl::Close()
1642 {
1643     return SfxPopupWindow::Close();
1644 }
1645 
1646 // -----------------------------------------------------------------------
1647 
1648 Window* SvxLineWindow_Impl::GetPreferredKeyInputWindow()
1649 {
1650     return &aLineSet;
1651 }
1652 
1653 // -----------------------------------------------------------------------
1654 
1655 void SvxLineWindow_Impl::GetFocus()
1656 {
1657     aLineSet.GrabFocus();
1658 }
1659 
1660 void SvxLineWindow_Impl::DataChanged( const DataChangedEvent& rDCEvt )
1661 {
1662     SfxPopupWindow::DataChanged( rDCEvt );
1663 
1664     if( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
1665     {
1666         CreateBitmaps();
1667         Invalidate();
1668     }
1669 }
1670 
1671 void SvxLineWindow_Impl::CreateBitmaps( void )
1672 {
1673     Size                    aBmpSize( 55, 12 );
1674     Bitmap                  aBmp;
1675     String                  aStr;
1676 
1677     const StyleSettings&    rStyleSettings = Application::GetSettings().GetStyleSettings();
1678     svtools::ColorConfig aColorConfig;
1679     ::Color                 aLineCol( aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor );
1680     ::Color                 aBackCol( rStyleSettings.GetWindowColor() );
1681     aLineSet.Clear();
1682 
1683     for( sal_uInt16 i = 1 ; i < 17 ; ++i )
1684     {
1685         MakeLineBitmap( i, aBmp, aBmpSize, aStr, aLineCol, aBackCol );
1686         aLineSet.InsertItem( i, aBmp, aStr );
1687     }
1688 }
1689 
1690 // -----------------------------------------------------------------------
1691 
1692 //########################################################################
1693 // Hilfsklassen
1694 
1695 //========================================================================
1696 // class SfxStyleControllerItem_Impl ------------------------------------------
1697 //========================================================================
1698 
1699 SfxStyleControllerItem_Impl::SfxStyleControllerItem_Impl(
1700     const Reference< XDispatchProvider >& rDispatchProvider,
1701     sal_uInt16                                nSlotId,      // Family-ID
1702     const rtl::OUString&                  rCommand,     // .uno: command bound to this item
1703     SvxStyleToolBoxControl&               rTbxCtl )     // Controller-Instanz, dem dieses Item zugeordnet ist.
1704     :   SfxStatusListener( rDispatchProvider, nSlotId, rCommand ),
1705         rControl( rTbxCtl )
1706 {
1707 }
1708 
1709 // -----------------------------------------------------------------------
1710 
1711 void SfxStyleControllerItem_Impl::StateChanged(
1712     sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
1713 {
1714     switch ( GetId() )
1715     {
1716         case SID_STYLE_FAMILY1:
1717         case SID_STYLE_FAMILY2:
1718         case SID_STYLE_FAMILY3:
1719         case SID_STYLE_FAMILY4:
1720         case SID_STYLE_FAMILY5:
1721         {
1722             const sal_uInt16 nIdx = GetId() - SID_STYLE_FAMILY_START;
1723 
1724             if ( SFX_ITEM_AVAILABLE == eState )
1725             {
1726                 const SfxTemplateItem* pStateItem =
1727                     PTR_CAST( SfxTemplateItem, pState );
1728                 DBG_ASSERT( pStateItem != NULL, "SfxTemplateItem expected" );
1729                 rControl.SetFamilyState( nIdx, pStateItem );
1730             }
1731             else
1732                 rControl.SetFamilyState( nIdx, NULL );
1733             break;
1734         }
1735     }
1736 }
1737 
1738 //########################################################################
1739 
1740 //========================================================================
1741 // class SvxStyleToolBoxControl ------------------------------------------
1742 //========================================================================
1743 
1744 struct SvxStyleToolBoxControl::Impl
1745 {
1746     String                              aClearForm;
1747     String                              aMore;
1748     ::std::vector< ::rtl::OUString >    aDefaultStyles;
1749     sal_Bool                        bListening;
1750     sal_Bool                        bSpecModeWriter;
1751     sal_Bool                        bSpecModeCalc;
1752 
1753     inline Impl( void )
1754         :aClearForm         ( SVX_RESSTR( RID_SVXSTR_CLEARFORM ) )
1755         ,aMore              ( SVX_RESSTR( RID_SVXSTR_MORE ) )
1756         ,bListening         ( sal_False )
1757         ,bSpecModeWriter    ( sal_False )
1758         ,bSpecModeCalc      ( sal_False )
1759     {
1760 
1761 
1762     }
1763     void InitializeStyles(Reference < frame::XModel > xModel)
1764     {
1765         //now convert the default style names to the localized names
1766         try
1767         {
1768             Reference< style::XStyleFamiliesSupplier > xStylesSupplier( xModel, UNO_QUERY_THROW );
1769             Reference< lang::XServiceInfo > xServices( xModel, UNO_QUERY_THROW );
1770             bSpecModeWriter = xServices->supportsService(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextDocument")));
1771             if(bSpecModeWriter)
1772             {
1773                 Reference<container::XNameAccess> xParaStyles;
1774                     xStylesSupplier->getStyleFamilies()->getByName(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParagraphStyles"))) >>=
1775                     xParaStyles;
1776                 static const sal_Char* aWriterStyles[] =
1777                 {
1778                     "Standard",
1779                     "Heading 1",
1780                     "Heading 2",
1781                     "Heading 3",
1782                     "Text body"
1783                 };
1784                 for( sal_uInt32 nStyle = 0; nStyle < sizeof( aWriterStyles ) / sizeof( sal_Char*); ++nStyle )
1785                 {
1786                     try
1787                     {
1788                         Reference< beans::XPropertySet > xStyle;
1789                         xParaStyles->getByName( rtl::OUString::createFromAscii( aWriterStyles[nStyle] )) >>= xStyle;
1790                         ::rtl::OUString sName;
1791                         xStyle->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DisplayName"))) >>= sName;
1792                         if( sName.getLength() )
1793                             aDefaultStyles.push_back(sName);
1794                     }
1795                     catch( const uno::Exception& )
1796                     {}
1797                 }
1798 
1799             }
1800             else if( 0 != (
1801                 bSpecModeCalc = xServices->supportsService(::rtl::OUString(
1802                     RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SpreadsheetDocument")))))
1803             {
1804                 static const sal_Char* aCalcStyles[] =
1805                 {
1806                     "Default",
1807                     "Heading1",
1808                     "Result",
1809                     "Result2"
1810                 };
1811                 Reference<container::XNameAccess> xCellStyles;
1812                     xStylesSupplier->getStyleFamilies()->getByName(
1813                         ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CellStyles"))) >>=
1814                         xCellStyles;
1815                 for( sal_uInt32 nStyle = 0; nStyle < sizeof( aCalcStyles ) / sizeof( sal_Char*); ++nStyle )
1816                 {
1817                     try
1818                     {
1819                         const rtl::OUString sStyleName( rtl::OUString::createFromAscii( aCalcStyles[nStyle] ) );
1820                         if( xCellStyles->hasByName( sStyleName ) )
1821                         {
1822                             Reference< beans::XPropertySet > xStyle( xCellStyles->getByName( sStyleName), UNO_QUERY_THROW );
1823                             ::rtl::OUString sName;
1824                             xStyle->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DisplayName"))) >>= sName;
1825                             if( sName.getLength() )
1826                                 aDefaultStyles.push_back(sName);
1827                         }
1828                     }
1829                     catch( const uno::Exception& )
1830                     {}
1831                 }
1832             }
1833         }
1834         catch(const uno::Exception& )
1835         {
1836             DBG_ERROR("error while initializing style names");
1837         }
1838     }
1839 };
1840 
1841 
1842 // mapping table from bound items. BE CAREFUL this table must be in the
1843 // same order as the uno commands bound to the slots SID_STYLE_FAMILY1..n
1844 // MAX_FAMILIES must also be correctly set!
1845 static const char* StyleSlotToStyleCommand[MAX_FAMILIES] =
1846 {
1847     ".uno:CharStyle",
1848     ".uno:ParaStyle",
1849     ".uno:FrameStyle",
1850     ".uno:PageStyle",
1851     ".uno:TemplateFamily5"
1852 };
1853 
1854 SvxStyleToolBoxControl::SvxStyleToolBoxControl(
1855     sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
1856     :   SfxToolBoxControl   ( nSlotId, nId, rTbx ),
1857         pStyleSheetPool     ( NULL ),
1858         nActFamily          ( 0xffff ),
1859         bListening          ( sal_False ),
1860         pImpl               ( new Impl )
1861 {
1862     for ( sal_uInt16 i=0; i<MAX_FAMILIES; i++ )
1863     {
1864         pBoundItems[i] = 0;
1865         m_xBoundItems[i] = Reference< XComponent >();
1866         pFamilyState[i]  = NULL;
1867     }
1868 }
1869 
1870 // -----------------------------------------------------------------------
1871 SvxStyleToolBoxControl::~SvxStyleToolBoxControl()
1872 {
1873 }
1874 
1875 // -----------------------------------------------------------------------
1876 void SAL_CALL SvxStyleToolBoxControl::initialize( const Sequence< Any >& aArguments )
1877 throw ( Exception, RuntimeException)
1878 {
1879     SfxToolBoxControl::initialize( aArguments );
1880 
1881     // After initialize we should have a valid frame member where we can retrieve our
1882     // dispatch provider.
1883     if ( m_xFrame.is() )
1884     {
1885         pImpl->InitializeStyles(m_xFrame->getController()->getModel());
1886         Reference< XDispatchProvider > xDispatchProvider( m_xFrame->getController(), UNO_QUERY );
1887         for ( sal_uInt16 i=0; i<MAX_FAMILIES; i++ )
1888         {
1889             pBoundItems[i]   = new SfxStyleControllerItem_Impl( xDispatchProvider,
1890                                                                 SID_STYLE_FAMILY_START + i,
1891                                                                 OUString::createFromAscii( StyleSlotToStyleCommand[i] ),
1892                                                                 *this );
1893             m_xBoundItems[i] = Reference< XComponent >( static_cast< OWeakObject* >( pBoundItems[i] ), UNO_QUERY );
1894             pFamilyState[i]  = NULL;
1895         }
1896     }
1897 }
1898 
1899 // XComponent
1900 void SAL_CALL SvxStyleToolBoxControl::dispose()
1901 throw (::com::sun::star::uno::RuntimeException)
1902 {
1903     SfxToolBoxControl::dispose();
1904 
1905     for( sal_uInt16 i=0; i<MAX_FAMILIES; i++ )
1906     {
1907         if ( m_xBoundItems[i].is() )
1908         {
1909             try
1910             {
1911                 m_xBoundItems[i]->dispose();
1912             }
1913             catch ( Exception& )
1914             {
1915             }
1916 
1917             m_xBoundItems[i].clear();
1918             pBoundItems[i] = 0;
1919         }
1920         DELETEZ( pFamilyState[i] );
1921     }
1922     pStyleSheetPool = NULL;
1923     DELETEZ( pImpl );
1924 }
1925 
1926 // -----------------------------------------------------------------------
1927 void SAL_CALL SvxStyleToolBoxControl::update() throw (RuntimeException)
1928 {
1929     // Do nothing, we will start binding our listener when we are visible.
1930     // See link SvxStyleToolBoxControl::VisibilityNotification.
1931     SvxStyleBox_Impl* pBox = (SvxStyleBox_Impl*)GetToolBox().GetItemWindow( GetId() );
1932     if ( pBox->IsVisible() )
1933     {
1934         for ( int i=0; i<MAX_FAMILIES; i++ )
1935             pBoundItems [i]->ReBind();
1936 
1937         bindListener();
1938     }
1939 }
1940 
1941 // -----------------------------------------------------------------------
1942 
1943 SfxStyleFamily SvxStyleToolBoxControl::GetActFamily()
1944 {
1945     switch ( nActFamily-1 + SID_STYLE_FAMILY_START )
1946     {
1947         case SID_STYLE_FAMILY1: return SFX_STYLE_FAMILY_CHAR;
1948         case SID_STYLE_FAMILY2: return SFX_STYLE_FAMILY_PARA;
1949         case SID_STYLE_FAMILY3: return SFX_STYLE_FAMILY_FRAME;
1950         case SID_STYLE_FAMILY4: return SFX_STYLE_FAMILY_PAGE;
1951         case SID_STYLE_FAMILY5: return SFX_STYLE_FAMILY_PSEUDO;
1952         default:
1953             DBG_ERROR( "unknown style family" );
1954             break;
1955     }
1956     return SFX_STYLE_FAMILY_PARA;
1957 }
1958 
1959 // -----------------------------------------------------------------------
1960 
1961 void SvxStyleToolBoxControl::FillStyleBox()
1962 {
1963     SvxStyleBox_Impl* pBox = (SvxStyleBox_Impl*)GetToolBox().GetItemWindow( GetId() );
1964 
1965     DBG_ASSERT( pStyleSheetPool, "StyleSheetPool not found!" );
1966     DBG_ASSERT( pBox,            "Control not found!" );
1967 
1968     if ( pStyleSheetPool && pBox && nActFamily!=0xffff )
1969     {
1970         const SfxStyleFamily    eFamily     = GetActFamily();
1971         sal_uInt16                  nCount      = pStyleSheetPool->Count();
1972         sal_uInt16                  i           = 0;
1973         SfxStyleSheetBase*      pStyle      = NULL;
1974         sal_Bool                    bDoFill     = sal_False;
1975 
1976         pStyleSheetPool->SetSearchMask( eFamily, SFXSTYLEBIT_USED );
1977 
1978         //------------------------------
1979         // Ueberpruefen, ob Fill noetig:
1980         //------------------------------
1981 
1982         pStyle = pStyleSheetPool->First();
1983         //!!! TODO: This condition isn't right any longer, because we always show some default entries
1984         //!!! so the list doesn't show the count
1985         if ( nCount != pBox->GetEntryCount() )
1986         {
1987             bDoFill = sal_True;
1988         }
1989         else
1990         {
1991             while ( pStyle && !bDoFill )
1992             {
1993                 bDoFill = ( pBox->GetEntry(i) != pStyle->GetName() );
1994                 pStyle = pStyleSheetPool->Next();
1995                 i++;
1996             }
1997         }
1998 
1999         if ( bDoFill )
2000         {
2001             pBox->SetUpdateMode( sal_False );
2002             pBox->Clear();
2003 
2004             {
2005                 sal_uInt16  _i;
2006                 sal_uInt32  nCnt = pImpl->aDefaultStyles.size();
2007                 bool    bInsert;
2008 
2009                 pStyle = pStyleSheetPool->First();
2010 
2011                 if( pImpl->bSpecModeWriter || pImpl->bSpecModeCalc )
2012                 {
2013                     while ( pStyle )
2014                     {
2015                         // sort out default styles
2016                         bInsert = true;
2017                         ::rtl::OUString aName( pStyle->GetName() );
2018                         for( _i = 0 ; _i < nCnt ; ++_i )
2019                         {
2020                             if( pImpl->aDefaultStyles[_i] == aName )
2021                             {
2022                                 bInsert = false;
2023                                 break;
2024                             }
2025                         }
2026 
2027                         if( bInsert )
2028                             pBox->InsertEntry( aName );
2029                         pStyle = pStyleSheetPool->Next();
2030                     }
2031                 }
2032                 else
2033                 {
2034                     while ( pStyle )
2035                     {
2036                         pBox->InsertEntry( pStyle->GetName() );
2037                         pStyle = pStyleSheetPool->Next();
2038                     }
2039                 }
2040             }
2041 
2042             if( pImpl->bSpecModeWriter || pImpl->bSpecModeCalc )
2043             {
2044                 // insert default styles
2045                 sal_uInt16  _i;
2046                 sal_uInt32  nCnt = pImpl->aDefaultStyles.size();
2047                 sal_uInt16 nPos = 1;
2048                 for( _i = 0 ; _i < nCnt ; ++_i )
2049                 {
2050                     pBox->InsertEntry( pImpl->aDefaultStyles[_i], nPos );
2051                     ++nPos;
2052                 }
2053 
2054                 // disable sort to preserve special order
2055                 WinBits nWinBits = pBox->GetStyle();
2056                 nWinBits &= ~WB_SORT;
2057                 pBox->SetStyle( nWinBits );
2058 
2059                 pBox->InsertEntry( pImpl->aClearForm, 0 );
2060                 pBox->SetSeparatorPos( 0 );
2061 
2062                 pBox->InsertEntry( pImpl->aMore );
2063 
2064                 // enable sort again
2065                 nWinBits |= WB_SORT;
2066                 pBox->SetStyle( nWinBits );
2067             }
2068 
2069             pBox->SetUpdateMode( sal_True );
2070             pBox->SetFamily( eFamily );
2071 
2072             sal_uInt16 nLines = Min( pBox->GetEntryCount(), MAX_STYLES_ENTRIES );
2073             pBox->SetDropDownLineCount( nLines );
2074         }
2075     }
2076 }
2077 
2078 // -----------------------------------------------------------------------
2079 
2080 void SvxStyleToolBoxControl::SelectStyle( const String& rStyleName )
2081 {
2082     SvxStyleBox_Impl* pBox = (SvxStyleBox_Impl*)GetToolBox().GetItemWindow( GetId() );
2083     DBG_ASSERT( pBox, "Control not found!" );
2084 
2085     if ( pBox )
2086     {
2087 //      String aStrSel( pBox->GetSelectEntry() );
2088         String aStrSel( pBox->GetText() );
2089 
2090         if ( rStyleName.Len() > 0 )
2091         {
2092             if ( rStyleName != aStrSel )
2093 //              pBox->SelectEntry( rStyleName );
2094                 pBox->SetText( rStyleName );
2095         }
2096         else
2097             pBox->SetNoSelection();
2098         pBox->SaveValue();
2099     }
2100 }
2101 
2102 // -----------------------------------------------------------------------
2103 
2104 void SvxStyleToolBoxControl::Update()
2105 {
2106     SfxStyleSheetBasePool*  pPool     = NULL;
2107     SfxObjectShell*         pDocShell = SfxObjectShell::Current();
2108 
2109     if ( pDocShell )
2110         pPool = pDocShell->GetStyleSheetPool();
2111 
2112     sal_uInt16 i;
2113     for ( i=0; i<MAX_FAMILIES; i++ )
2114         if( pFamilyState[i] )
2115             break;
2116 
2117     if ( i==MAX_FAMILIES || !pPool )
2118     {
2119         pStyleSheetPool = pPool;
2120         return;
2121     }
2122 
2123     //--------------------------------------------------------------------
2124     const SfxTemplateItem* pItem = NULL;
2125 
2126     if ( nActFamily == 0xffff || 0 == (pItem = pFamilyState[nActFamily-1]) )
2127         // aktueller Bereich nicht innerhalb der erlaubten Bereiche
2128         // oder Default
2129     {
2130         pStyleSheetPool = pPool;
2131         nActFamily      = 2;
2132 
2133         pItem = pFamilyState[nActFamily-1];
2134         if ( !pItem )
2135         {
2136             nActFamily++;
2137             pItem = pFamilyState[nActFamily-1];
2138         }
2139 
2140         if ( !pItem )
2141         {
2142             DBG_WARNING( "Unknown Family" ); // can happen
2143         }
2144     }
2145     else if ( pPool != pStyleSheetPool )
2146         pStyleSheetPool = pPool;
2147 
2148     FillStyleBox(); // entscheidet selbst, ob gefuellt werden muss
2149 
2150     if ( pItem )
2151         SelectStyle( pItem->GetStyleName() );
2152 }
2153 
2154 // -----------------------------------------------------------------------
2155 
2156 void SvxStyleToolBoxControl::SetFamilyState( sal_uInt16 nIdx,
2157                                              const SfxTemplateItem* pItem )
2158 {
2159     DELETEZ( pFamilyState[nIdx] );
2160 
2161     if ( pItem )
2162         pFamilyState[nIdx] = new SfxTemplateItem( *pItem );
2163 
2164     Update();
2165 }
2166 
2167 // -----------------------------------------------------------------------
2168 
2169 IMPL_LINK( SvxStyleToolBoxControl, VisibilityNotification, void*, EMPTYARG )
2170 {
2171 
2172     sal_uInt16 i;
2173 
2174     // Call ReBind() && UnBind() according to visibility
2175     SvxStyleBox_Impl* pBox = (SvxStyleBox_Impl*)( GetToolBox().GetItemWindow( GetId() ));
2176     if ( pBox->IsVisible() && !isBound() )
2177     {
2178         for ( i=0; i<MAX_FAMILIES; i++ )
2179             pBoundItems [i]->ReBind();
2180 
2181         bindListener();
2182     }
2183     else if ( !pBox->IsVisible() && isBound() )
2184     {
2185         for ( i=0; i<MAX_FAMILIES; i++ )
2186             pBoundItems[i]->UnBind();
2187         unbindListener();
2188     }
2189 
2190     return 0;
2191 }
2192 
2193 // -----------------------------------------------------------------------
2194 
2195 void SvxStyleToolBoxControl::StateChanged(
2196 
2197     sal_uInt16 , SfxItemState eState, const SfxPoolItem* pState )
2198 
2199 {
2200     sal_uInt16       nId    = GetId();
2201     ToolBox&     rTbx   = GetToolBox();
2202     SvxStyleBox_Impl* pBox   = (SvxStyleBox_Impl*)(rTbx.GetItemWindow( nId ));
2203     TriState     eTri   = STATE_NOCHECK;
2204 
2205     DBG_ASSERT( pBox, "Control not found!" );
2206 
2207     if ( SFX_ITEM_DISABLED == eState )
2208         pBox->Disable();
2209     else
2210         pBox->Enable();
2211 
2212     rTbx.EnableItem( nId, SFX_ITEM_DISABLED != eState );
2213 
2214     switch ( eState )
2215     {
2216         case SFX_ITEM_AVAILABLE:
2217             eTri = ((const SfxBoolItem*)pState)->GetValue()
2218                         ? STATE_CHECK
2219                         : STATE_NOCHECK;
2220             break;
2221 
2222         case SFX_ITEM_DONTCARE:
2223             eTri = STATE_DONTKNOW;
2224             break;
2225     }
2226 
2227     rTbx.SetItemState( nId, eTri );
2228 
2229     if ( SFX_ITEM_DISABLED != eState )
2230         Update();
2231 }
2232 
2233 // -----------------------------------------------------------------------
2234 
2235 Window* SvxStyleToolBoxControl::CreateItemWindow( Window *pParent )
2236 {
2237     SvxStyleBox_Impl* pBox = new SvxStyleBox_Impl( pParent,
2238                                                    SID_STYLE_APPLY,
2239                                                    OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:StyleApply" )),
2240                                                    SFX_STYLE_FAMILY_PARA,
2241                                                    Reference< XDispatchProvider >( m_xFrame->getController(), UNO_QUERY ),
2242                                                    m_xFrame,
2243                                                    pImpl->aClearForm,
2244                                                    pImpl->aMore,
2245                                                    pImpl->bSpecModeWriter || pImpl->bSpecModeCalc );
2246     if( !pImpl->aDefaultStyles.empty())
2247         pBox->SetDefaultStyle( pImpl->aDefaultStyles[0] );
2248     // Set visibility listener to bind/unbind controller
2249     pBox->SetVisibilityListener( LINK( this, SvxStyleToolBoxControl, VisibilityNotification ));
2250 
2251     return pBox;
2252 }
2253 
2254 //========================================================================
2255 // class SvxFontNameToolBoxControl ---------------------------------------
2256 //========================================================================
2257 
2258 SvxFontNameToolBoxControl::SvxFontNameToolBoxControl(
2259                                             sal_uInt16          nSlotId,
2260                                             sal_uInt16          nId,
2261                                             ToolBox&        rTbx )
2262 
2263     :   SfxToolBoxControl( nSlotId, nId, rTbx )
2264 {
2265 }
2266 
2267 // -----------------------------------------------------------------------
2268 
2269 void SvxFontNameToolBoxControl::StateChanged(
2270 
2271     sal_uInt16 , SfxItemState eState, const SfxPoolItem* pState )
2272 
2273 {
2274     sal_uInt16               nId    = GetId();
2275     ToolBox&             rTbx   = GetToolBox();
2276     SvxFontNameBox_Impl* pBox   = (SvxFontNameBox_Impl*)(rTbx.GetItemWindow( nId ));
2277 
2278     DBG_ASSERT( pBox, "Control not found!" );
2279 
2280     if ( SFX_ITEM_DISABLED == eState )
2281     {
2282         pBox->Disable();
2283         pBox->Update( (const SvxFontItem*)NULL );
2284     }
2285     else
2286     {
2287         pBox->Enable();
2288 
2289         if ( SFX_ITEM_AVAILABLE == eState )
2290         {
2291             const SvxFontItem* pFontItem = dynamic_cast< const SvxFontItem* >( pState );
2292 
2293             DBG_ASSERT( pFontItem, "svx::SvxFontNameToolBoxControl::StateChanged(), wrong item type!" );
2294             if( pFontItem )
2295                 pBox->Update( pFontItem );
2296         }
2297         else
2298             pBox->SetText( String() );
2299         pBox->SaveValue();
2300     }
2301 
2302     rTbx.EnableItem( nId, SFX_ITEM_DISABLED != eState );
2303 }
2304 
2305 // -----------------------------------------------------------------------
2306 
2307 Window* SvxFontNameToolBoxControl::CreateItemWindow( Window *pParent )
2308 {
2309     SvxFontNameBox_Impl* pBox = new SvxFontNameBox_Impl( pParent,
2310                                                          Reference< XDispatchProvider >( m_xFrame->getController(), UNO_QUERY ),
2311                                                          m_xFrame,0);
2312     return pBox;
2313 }
2314 
2315 //========================================================================
2316 // class SvxFontColorToolBoxControl --------------------------------------
2317 //========================================================================
2318 
2319 SvxFontColorToolBoxControl::SvxFontColorToolBoxControl(
2320     sal_uInt16          nSlotId,
2321     sal_uInt16          nId,
2322     ToolBox&        rTbx )
2323 
2324     :   SfxToolBoxControl( nSlotId, nId, rTbx ),
2325     pBtnUpdater( new ::svx::ToolboxButtonColorUpdater(
2326                     nSlotId, nId, &GetToolBox(), TBX_UPDATER_MODE_CHAR_COLOR_NEW ))
2327 {
2328     rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
2329 }
2330 
2331 // -----------------------------------------------------------------------
2332 
2333 SvxFontColorToolBoxControl::~SvxFontColorToolBoxControl()
2334 {
2335     delete pBtnUpdater;
2336 }
2337 
2338 // -----------------------------------------------------------------------
2339 
2340 SfxPopupWindowType SvxFontColorToolBoxControl::GetPopupWindowType() const
2341 {
2342     return SFX_POPUPWINDOW_ONCLICK;
2343 }
2344 
2345 // -----------------------------------------------------------------------
2346 
2347 SfxPopupWindow* SvxFontColorToolBoxControl::CreatePopupWindow()
2348 {
2349     SvxColorWindow_Impl* pColorWin =
2350         new SvxColorWindow_Impl(
2351                 OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:Color" )),
2352                 SID_ATTR_CHAR_COLOR,
2353                 m_xFrame,
2354                 SVX_RESSTR( RID_SVXITEMS_EXTRAS_CHARCOLOR ),
2355                 &GetToolBox() );
2356 
2357     pColorWin->StartPopupMode( &GetToolBox(),
2358         FLOATWIN_POPUPMODE_GRABFOCUS|FLOATWIN_POPUPMODE_ALLOWTEAROFF );
2359     pColorWin->StartSelection();
2360     SetPopupWindow( pColorWin );
2361     return pColorWin;
2362 }
2363 
2364 // -----------------------------------------------------------------------
2365 
2366 void SvxFontColorToolBoxControl::StateChanged(
2367 
2368     sal_uInt16 , SfxItemState eState, const SfxPoolItem* pState )
2369 
2370 {
2371     sal_uInt16 nId = GetId();
2372     ToolBox& rTbx = GetToolBox();
2373     const SvxColorItem* pItem = 0;
2374 
2375     if ( SFX_ITEM_DONTCARE != eState )
2376        pItem = PTR_CAST( SvxColorItem, pState );
2377 
2378     if ( pItem )
2379         pBtnUpdater->Update( pItem->GetValue());
2380 
2381     rTbx.EnableItem( nId, SFX_ITEM_DISABLED != eState );
2382     rTbx.SetItemState( nId, ( SFX_ITEM_DONTCARE == eState ) ? STATE_DONTKNOW : STATE_NOCHECK );
2383 }
2384 
2385 //========================================================================
2386 // class SvxColorToolBoxControl --------------------------------
2387 //========================================================================
2388 
2389 SvxColorToolBoxControl::SvxColorToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
2390 
2391     SfxToolBoxControl( nSlotId, nId, rTbx )
2392 {
2393     if ( nSlotId == SID_BACKGROUND_COLOR )
2394         rTbx.SetItemBits( nId, TIB_DROPDOWNONLY | rTbx.GetItemBits( nId ) );
2395     else
2396         rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
2397     rTbx.Invalidate();
2398     pBtnUpdater = new ::svx::ToolboxButtonColorUpdater( nSlotId, nId, &GetToolBox() );
2399 }
2400 
2401 // -----------------------------------------------------------------------
2402 
2403 SvxColorToolBoxControl::~SvxColorToolBoxControl()
2404 {
2405     delete pBtnUpdater;
2406 }
2407 
2408 // -----------------------------------------------------------------------
2409 
2410 SfxPopupWindowType SvxColorToolBoxControl::GetPopupWindowType() const
2411 {
2412     return SFX_POPUPWINDOW_ONCLICK;
2413 }
2414 
2415 // -----------------------------------------------------------------------
2416 
2417 SfxPopupWindow* SvxColorToolBoxControl::CreatePopupWindow()
2418 {
2419     sal_uInt16 nResId = GetSlotId() == SID_BACKGROUND_COLOR ?
2420                         RID_SVXSTR_BACKGROUND : RID_SVXSTR_COLOR;
2421     SvxColorWindow_Impl* pColorWin = new SvxColorWindow_Impl(
2422         OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:BackgroundColor" )),
2423                                     SID_BACKGROUND_COLOR,
2424                                     m_xFrame,
2425                                     SVX_RESSTR(nResId),
2426                                     &GetToolBox() );
2427 
2428     pColorWin->StartPopupMode( &GetToolBox(),
2429         FLOATWIN_POPUPMODE_GRABFOCUS|FLOATWIN_POPUPMODE_ALLOWTEAROFF );
2430     pColorWin->StartSelection();
2431     SetPopupWindow( pColorWin );
2432     return pColorWin;
2433 }
2434 
2435 // -----------------------------------------------------------------------
2436 
2437 void SvxColorToolBoxControl::StateChanged(
2438 
2439     sal_uInt16 , SfxItemState eState, const SfxPoolItem* pState )
2440 
2441 {
2442     const SvxColorItem* pItem   = 0;
2443     if ( SFX_ITEM_DONTCARE != eState )
2444         pItem = PTR_CAST( SvxColorItem, pState );
2445 
2446     if ( pItem )
2447         pBtnUpdater->Update( pItem->GetValue() );
2448 
2449     sal_uInt16 nId = GetId();
2450     ToolBox& rTbx = GetToolBox();
2451     rTbx.EnableItem( nId, SFX_ITEM_DISABLED != eState );
2452     rTbx.SetItemState( nId, ( SFX_ITEM_DONTCARE == eState ) ? STATE_DONTKNOW : STATE_NOCHECK );
2453 }
2454 
2455 //========================================================================
2456 // class SvxFontColorExtToolBoxControl --------------------------------------
2457 //========================================================================
2458 
2459 SvxFontColorExtToolBoxControl::SvxFontColorExtToolBoxControl(
2460     sal_uInt16 nSlotId,
2461     sal_uInt16 nId,
2462     ToolBox& rTbx ) :
2463 
2464     SfxToolBoxControl( nSlotId, nId, rTbx ),
2465     pBtnUpdater(0)
2466 {
2467     rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
2468     // The following commands are available at the writer module.
2469     if ( SID_ATTR_CHAR_COLOR2 == nSlotId )
2470         addStatusListener( OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CharColorExt" )));
2471     else
2472         addStatusListener( OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CharBackgroundExt" )));
2473 
2474     sal_uInt16 nMode =  SID_ATTR_CHAR_COLOR2 == nSlotId
2475         ? TBX_UPDATER_MODE_CHAR_COLOR_NEW : TBX_UPDATER_MODE_CHAR_COLOR_NEW;
2476     pBtnUpdater = new ::svx::ToolboxButtonColorUpdater( nSlotId, nId, &GetToolBox(), nMode );
2477 }
2478 
2479 // -----------------------------------------------------------------------
2480 
2481 SvxFontColorExtToolBoxControl::~SvxFontColorExtToolBoxControl()
2482 {
2483     delete pBtnUpdater;
2484 }
2485 
2486 // -----------------------------------------------------------------------
2487 
2488 SfxPopupWindowType SvxFontColorExtToolBoxControl::GetPopupWindowType() const
2489 {
2490     return SFX_POPUPWINDOW_ONTIMEOUT;
2491 }
2492 
2493 // -----------------------------------------------------------------------
2494 
2495 SfxPopupWindow* SvxFontColorExtToolBoxControl::CreatePopupWindow()
2496 {
2497     SvxColorWindow_Impl* pColorWin =
2498         new SvxColorWindow_Impl(
2499                             m_aCommandURL,
2500                             GetSlotId(),
2501                             m_xFrame,
2502                             SVX_RESSTR( RID_SVXITEMS_EXTRAS_CHARCOLOR ),
2503                             &GetToolBox() );
2504 
2505     if ( GetSlotId() == SID_ATTR_CHAR_COLOR_BACKGROUND )
2506         pColorWin->SetText( SVX_RESSTR( RID_SVXSTR_EXTRAS_CHARBACKGROUND ) );
2507 
2508     pColorWin->StartPopupMode( &GetToolBox(),
2509         FLOATWIN_POPUPMODE_GRABFOCUS|FLOATWIN_POPUPMODE_ALLOWTEAROFF );
2510     pColorWin->StartSelection();
2511     SetPopupWindow( pColorWin );
2512     return pColorWin;
2513 }
2514 
2515 // -----------------------------------------------------------------------
2516 
2517 void SvxFontColorExtToolBoxControl::StateChanged(
2518 
2519     sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
2520 
2521 {
2522     sal_uInt16 nId = GetId();
2523     ToolBox& rTbx = GetToolBox();
2524     const SvxColorItem* pItem = 0;
2525 
2526     if ( nSID == SID_ATTR_CHAR_COLOR_EXT ||
2527          nSID == SID_ATTR_CHAR_COLOR_BACKGROUND_EXT )
2528     {
2529         if ( SFX_ITEM_DONTCARE != eState )
2530         {
2531             const SfxBoolItem* pBool = PTR_CAST( SfxBoolItem, pState );
2532             rTbx.CheckItem( nId, pBool && pBool->GetValue());
2533         }
2534         rTbx.EnableItem( nId, SFX_ITEM_DISABLED != eState );
2535     }
2536     else
2537     {
2538         if ( SFX_ITEM_DONTCARE != eState )
2539            pItem = PTR_CAST( SvxColorItem, pState );
2540 
2541         if ( pItem )
2542             pBtnUpdater->Update( pItem->GetValue() );
2543     }
2544 }
2545 
2546 // -----------------------------------------------------------------------
2547 
2548 void SvxFontColorExtToolBoxControl::Select( sal_Bool )
2549 {
2550     OUString aCommand;
2551     OUString aParamName;
2552     if ( SID_ATTR_CHAR_COLOR2 == GetSlotId() )
2553     {
2554         aCommand    = OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CharColorExt" ));
2555         aParamName  = OUString( RTL_CONSTASCII_USTRINGPARAM( "CharColorExt" ));
2556     }
2557     else
2558     {
2559         aCommand    = OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CharBackgroundExt" ));
2560         aParamName  = OUString( RTL_CONSTASCII_USTRINGPARAM( "CharBackgroundExt" ));
2561     }
2562 
2563     Sequence< PropertyValue > aArgs( 1 );
2564     aArgs[0].Name  = aParamName;
2565     aArgs[0].Value = makeAny( GetToolBox().IsItemChecked( GetId() ));
2566     Dispatch( aCommand, aArgs );
2567 }
2568 
2569 //========================================================================
2570 // class SvxFrameToolBoxControl ------------------------------------------
2571 //========================================================================
2572 
2573 SvxFrameToolBoxControl::SvxFrameToolBoxControl(
2574     sal_uInt16      nSlotId,
2575     sal_uInt16      nId,
2576     ToolBox&    rTbx )
2577 
2578     :   SfxToolBoxControl( nSlotId, nId, rTbx )
2579 {
2580     rTbx.SetItemBits( nId, TIB_DROPDOWNONLY | rTbx.GetItemBits( nId ) );
2581 }
2582 
2583 // -----------------------------------------------------------------------
2584 
2585 SfxPopupWindowType SvxFrameToolBoxControl::GetPopupWindowType() const
2586 {
2587     return SFX_POPUPWINDOW_ONCLICK;
2588 }
2589 
2590 // -----------------------------------------------------------------------
2591 
2592 SfxPopupWindow* SvxFrameToolBoxControl::CreatePopupWindow()
2593 {
2594     SvxFrameWindow_Impl* pFrameWin = new SvxFrameWindow_Impl(
2595                                         GetSlotId(), m_xFrame, &GetToolBox() );
2596 
2597     pFrameWin->StartPopupMode( &GetToolBox(), FLOATWIN_POPUPMODE_GRABFOCUS | FLOATWIN_POPUPMODE_ALLOWTEAROFF );
2598     pFrameWin->StartSelection();
2599     SetPopupWindow( pFrameWin );
2600 
2601     return pFrameWin;
2602 }
2603 
2604 // -----------------------------------------------------------------------
2605 
2606 void SvxFrameToolBoxControl::StateChanged(
2607 
2608     sal_uInt16, SfxItemState eState, const SfxPoolItem*  )
2609 
2610 {
2611     sal_uInt16                  nId     = GetId();
2612     ToolBox&                rTbx    = GetToolBox();
2613 
2614     rTbx.EnableItem( nId, SFX_ITEM_DISABLED != eState );
2615     rTbx.SetItemState( nId, (SFX_ITEM_DONTCARE == eState)
2616                             ? STATE_DONTKNOW
2617                             : STATE_NOCHECK );
2618 }
2619 
2620 //========================================================================
2621 // class SvxFrameLineStyleToolBoxControl ---------------------------------
2622 //========================================================================
2623 
2624 SvxFrameLineStyleToolBoxControl::SvxFrameLineStyleToolBoxControl(
2625     sal_uInt16          nSlotId,
2626     sal_uInt16          nId,
2627     ToolBox&        rTbx )
2628 
2629     :    SfxToolBoxControl( nSlotId, nId, rTbx )
2630 {
2631     rTbx.SetItemBits( nId, TIB_DROPDOWNONLY | rTbx.GetItemBits( nId ) );
2632 }
2633 
2634 // -----------------------------------------------------------------------
2635 
2636 SfxPopupWindowType SvxFrameLineStyleToolBoxControl::GetPopupWindowType() const
2637 {
2638     return SFX_POPUPWINDOW_ONCLICK;
2639 }
2640 
2641 // -----------------------------------------------------------------------
2642 
2643 SfxPopupWindow* SvxFrameLineStyleToolBoxControl::CreatePopupWindow()
2644 {
2645     SvxLineWindow_Impl* pLineWin = new SvxLineWindow_Impl( GetSlotId(), m_xFrame, &GetToolBox() );
2646     pLineWin->StartPopupMode( &GetToolBox(), sal_True );
2647     pLineWin->StartSelection();
2648     SetPopupWindow( pLineWin );
2649 
2650     return pLineWin;
2651 }
2652 
2653 // -----------------------------------------------------------------------
2654 
2655 void SvxFrameLineStyleToolBoxControl::StateChanged(
2656 
2657     sal_uInt16 , SfxItemState eState, const SfxPoolItem*  )
2658 {
2659     sal_uInt16       nId    = GetId();
2660     ToolBox&     rTbx   = GetToolBox();
2661 
2662     rTbx.EnableItem( nId, SFX_ITEM_DISABLED != eState );
2663     rTbx.SetItemState( nId, (SFX_ITEM_DONTCARE == eState)
2664                                 ? STATE_DONTKNOW
2665                                 : STATE_NOCHECK );
2666 }
2667 
2668 //========================================================================
2669 // class SvxFrameLineColorToolBoxControl ---------------------------------
2670 //========================================================================
2671 
2672 SvxFrameLineColorToolBoxControl::SvxFrameLineColorToolBoxControl(
2673     sal_uInt16      nSlotId,
2674     sal_uInt16      nId,
2675     ToolBox&    rTbx ) :
2676 
2677     SfxToolBoxControl( nSlotId, nId, rTbx ),
2678     pBtnUpdater(new ::svx::ToolboxButtonColorUpdater( nSlotId, nId, &GetToolBox() ))
2679 {
2680     rTbx.SetItemBits( nId, TIB_DROPDOWNONLY | rTbx.GetItemBits( nId ) );
2681 }
2682 
2683 // -----------------------------------------------------------------------
2684 
2685 SvxFrameLineColorToolBoxControl::~SvxFrameLineColorToolBoxControl()
2686 {
2687 
2688     delete pBtnUpdater;
2689 }
2690 
2691 // -----------------------------------------------------------------------
2692 
2693 SfxPopupWindowType SvxFrameLineColorToolBoxControl::GetPopupWindowType() const
2694 {
2695     return SFX_POPUPWINDOW_ONCLICK;
2696 }
2697 
2698 // -----------------------------------------------------------------------
2699 
2700 SfxPopupWindow* SvxFrameLineColorToolBoxControl::CreatePopupWindow()
2701 {
2702     SvxColorWindow_Impl* pColorWin = new SvxColorWindow_Impl(
2703                                         OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FrameLineColor" )),
2704                                         SID_FRAME_LINECOLOR,
2705                                         m_xFrame,
2706                                         SVX_RESSTR(RID_SVXSTR_FRAME_COLOR),
2707                                         &GetToolBox() );
2708 
2709     pColorWin->StartPopupMode( &GetToolBox(),
2710         FLOATWIN_POPUPMODE_GRABFOCUS|FLOATWIN_POPUPMODE_ALLOWTEAROFF );
2711     pColorWin->StartSelection();
2712     SetPopupWindow( pColorWin );
2713     return pColorWin;
2714 }
2715 
2716 // -----------------------------------------------------------------------
2717 
2718 void SvxFrameLineColorToolBoxControl::StateChanged(
2719 
2720     sal_uInt16 , SfxItemState eState, const SfxPoolItem* pState )
2721 
2722 {
2723     sal_uInt16 nId = GetId();
2724     ToolBox& rTbx = GetToolBox();
2725     rTbx.EnableItem( nId, SFX_ITEM_DISABLED != eState );
2726     rTbx.SetItemState( nId, ( SFX_ITEM_DONTCARE == eState ) ? STATE_DONTKNOW : STATE_NOCHECK );
2727 
2728     const SvxColorItem* pItem = 0;
2729     if ( SFX_ITEM_DONTCARE != eState )
2730     {
2731        pItem = PTR_CAST( SvxColorItem, pState );
2732         if ( pItem )
2733             pBtnUpdater->Update( pItem->GetValue());
2734     }
2735 }
2736 
2737 // class SvxReloadControllerItem_Impl ------------------------------------
2738 
2739 class SvxReloadControllerItem_Impl
2740 {
2741 public:
2742     Image* pNormalImage;
2743     Image* pSpecialImage;
2744 
2745     SvxReloadControllerItem_Impl() :
2746         pNormalImage( new Image( SVX_RES( RID_SVX_RELOAD_NORMAL ) ) ), pSpecialImage( 0 ) {}
2747     ~SvxReloadControllerItem_Impl() { delete pNormalImage; delete pSpecialImage; }
2748 
2749     Image& GetNormalImage() { return *pNormalImage; }
2750     Image& GetSpecialImage()
2751         {
2752             if ( !pSpecialImage )
2753                 pSpecialImage = new Image( SVX_RES( RID_SVX_RELOAD_SPECIAL ) );
2754             return *pSpecialImage;
2755         }
2756 };
2757 
2758 // -----------------------------------------------------------------------
2759 
2760 SvxReloadControllerItem::SvxReloadControllerItem( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
2761 :   SfxToolBoxControl( nSlotId, nId, rTbx )
2762 ,   pImpl( new SvxReloadControllerItem_Impl )
2763 {
2764     rTbx.SetItemImage( nId, pImpl->GetNormalImage() );
2765 }
2766 
2767 // -----------------------------------------------------------------------
2768 
2769 SvxReloadControllerItem::~SvxReloadControllerItem()
2770 {
2771     delete pImpl;
2772 }
2773 
2774 // -----------------------------------------------------------------------
2775 
2776 void SvxReloadControllerItem::StateChanged(
2777     sal_uInt16 , SfxItemState eState, const SfxPoolItem* pState )
2778 {
2779     SfxBoolItem* pItem = PTR_CAST( SfxBoolItem, pState );
2780     ToolBox& rBox = GetToolBox();
2781     if( pItem )
2782     {
2783         rBox.SetItemImage( GetId(),
2784                 pItem->GetValue() ? pImpl->GetSpecialImage() :
2785                 pImpl->GetNormalImage() );
2786     }
2787     rBox.EnableItem( GetId(), eState != SFX_ITEM_DISABLED );
2788 }
2789 
2790 //========================================================================
2791 // class SvxSimpleUndoRedoController -------------------------------------
2792 //========================================================================
2793 
2794 SvxSimpleUndoRedoController::SvxSimpleUndoRedoController( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx  )
2795     :SfxToolBoxControl( nSlotId, nId, rTbx )
2796 {
2797     aDefaultText = rTbx.GetItemText( nId );
2798 }
2799 
2800 // -----------------------------------------------------------------------
2801 
2802 SvxSimpleUndoRedoController::~SvxSimpleUndoRedoController()
2803 {
2804 }
2805 
2806 // -----------------------------------------------------------------------
2807 
2808 void SvxSimpleUndoRedoController::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
2809 {
2810     SfxStringItem* pItem = PTR_CAST( SfxStringItem, pState );
2811     ToolBox& rBox = GetToolBox();
2812     if ( pItem && eState != SFX_ITEM_DISABLED )
2813     {
2814         ::rtl::OUString aNewText( MnemonicGenerator::EraseAllMnemonicChars( pItem->GetValue() ) );
2815         rBox.SetQuickHelpText( GetId(), aNewText );
2816     }
2817     if ( eState == SFX_ITEM_DISABLED )
2818         rBox.SetQuickHelpText( GetId(), aDefaultText );
2819     rBox.EnableItem( GetId(), eState != SFX_ITEM_DISABLED );
2820 }
2821 
2822 //========================================================================
2823 
2824 void lcl_ResizeValueSet( Window &rWin, ValueSet &rValueSet )
2825 {
2826     Size aSize = rWin.GetOutputSizePixel();
2827     aSize.Width()  -= 4;
2828     aSize.Height() -= 4;
2829     rValueSet.SetPosSizePixel( Point(2,2), aSize );
2830 }
2831 
2832 // -----------------------------------------------------------------------
2833 
2834 void lcl_CalcSizeValueSet( Window &rWin, ValueSet &rValueSet, const Size &aItemSize )
2835 {
2836     Size aSize = rValueSet.CalcWindowSizePixel( aItemSize );
2837     aSize.Width()  += 4;
2838     aSize.Height() += 4;
2839     rWin.SetOutputSizePixel( aSize );
2840 }
2841 
2842 // -----------------------------------------------------------------------
2843 
2844 sal_Bool lcl_FontChangedHint( const SfxHint &rHint )
2845 {
2846     SfxPoolItemHint *pItemHint = PTR_CAST(SfxPoolItemHint, &rHint);
2847     if ( pItemHint )
2848     {
2849         SfxPoolItem *pItem = pItemHint->GetObject();
2850         return ( pItem->Which() == SID_ATTR_CHAR_FONTLIST );
2851     }
2852     else
2853     {
2854         SfxSimpleHint* pSimpleHint = PTR_CAST(SfxSimpleHint, &rHint);
2855         return pSimpleHint && ( SFX_HINT_DATACHANGED ==
2856                             ( pSimpleHint->GetId() & SFX_HINT_DATACHANGED ) );
2857     }
2858 }
2859 // -----------------------------------------------------------------------------
2860 Reference< ::com::sun::star::accessibility::XAccessible > SvxFontNameBox_Impl::CreateAccessible()
2861 {
2862     FillList();
2863     return FontNameBox::CreateAccessible();
2864 }
2865