xref: /trunk/main/svx/source/mnuctrls/fntszctl.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <string> // HACK: prevent conflict between STLPORT and Workshop headern
28cdf0e10cSrcweir #include <svl/itempool.hxx>
29cdf0e10cSrcweir #include <svtools/stdmenu.hxx>
30cdf0e10cSrcweir #include <svtools/ctrltool.hxx>
31cdf0e10cSrcweir #include <sfx2/app.hxx>
32cdf0e10cSrcweir #include <sfx2/objsh.hxx>
33cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
34cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <svx/fntszctl.hxx>     //
37cdf0e10cSrcweir #include <svx/dialogs.hrc>
38cdf0e10cSrcweir #include <editeng/fhgtitem.hxx>
39cdf0e10cSrcweir #include "editeng/fontitem.hxx"
40cdf0e10cSrcweir #include "editeng/flstitem.hxx"
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include "svx/dlgutil.hxx"
43cdf0e10cSrcweir #include <svx/dialmgr.hxx>
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #define LOGIC   OutputDevice::LogicToLogic
46cdf0e10cSrcweir 
47cdf0e10cSrcweir SFX_IMPL_MENU_CONTROL(SvxFontSizeMenuControl, SvxFontHeightItem);
48cdf0e10cSrcweir 
49cdf0e10cSrcweir //--------------------------------------------------------------------
50cdf0e10cSrcweir 
51cdf0e10cSrcweir /*  [Beschreibung]
52cdf0e10cSrcweir 
53cdf0e10cSrcweir     Select-Handler des Men"us; die aktuelle Fontgr"o\se
54cdf0e10cSrcweir     wird in einem SvxFontHeightItem verschickt.
55cdf0e10cSrcweir */
56cdf0e10cSrcweir 
IMPL_LINK(SvxFontSizeMenuControl,MenuSelect,FontSizeMenu *,pMen)57cdf0e10cSrcweir IMPL_LINK( SvxFontSizeMenuControl, MenuSelect, FontSizeMenu*, pMen )
58cdf0e10cSrcweir {
59cdf0e10cSrcweir     SfxViewFrame* pFrm = SfxViewFrame::Current();
60cdf0e10cSrcweir     SfxShell* pSh = pFrm ? pFrm->GetDispatcher()->GetShell( 0 ) : NULL;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     if ( !pSh )
63cdf0e10cSrcweir         return 0;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     const SfxItemPool& rPool = pSh->GetPool();
66cdf0e10cSrcweir     sal_uInt16 nWhich = rPool.GetWhich( SID_ATTR_CHAR_FONTHEIGHT );
67cdf0e10cSrcweir     const SfxMapUnit eUnit = rPool.GetMetric( nWhich );
68cdf0e10cSrcweir     long nH = LOGIC( pMen->GetCurHeight(), MAP_POINT, (MapUnit)eUnit ) / 10;
69cdf0e10cSrcweir     SvxFontHeightItem aItem( nH, 100, GetId() );
70cdf0e10cSrcweir     GetBindings().GetDispatcher()->Execute( GetId(), SFX_CALLMODE_RECORD, &aItem, 0L );
71cdf0e10cSrcweir     return 1;
72cdf0e10cSrcweir }
73cdf0e10cSrcweir 
74cdf0e10cSrcweir //--------------------------------------------------------------------
75cdf0e10cSrcweir 
76cdf0e10cSrcweir /*  [Beschreibung]
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     Statusbenachrichtigung;
79cdf0e10cSrcweir     Ist die Funktionalit"at disabled, wird der entsprechende
80cdf0e10cSrcweir     Men"ueintrag im Parentmenu disabled, andernfalls wird er enabled.
81cdf0e10cSrcweir     die aktuelle Fontgr"o\se wird mit einer Checkmark versehen.
82cdf0e10cSrcweir */
83cdf0e10cSrcweir 
StateChanged(sal_uInt16,SfxItemState eState,const SfxPoolItem * pState)84cdf0e10cSrcweir void SvxFontSizeMenuControl::StateChanged(
85cdf0e10cSrcweir 
86cdf0e10cSrcweir     sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
87cdf0e10cSrcweir 
88cdf0e10cSrcweir {
89cdf0e10cSrcweir     rParent.EnableItem( GetId(), SFX_ITEM_DISABLED != eState );
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     if ( SFX_ITEM_AVAILABLE == eState )
92cdf0e10cSrcweir     {
93cdf0e10cSrcweir         if ( pState->ISA(SvxFontHeightItem) )
94cdf0e10cSrcweir         {
95cdf0e10cSrcweir             const SvxFontHeightItem* pItem =
96cdf0e10cSrcweir                 PTR_CAST( SvxFontHeightItem, pState );
97cdf0e10cSrcweir             long nVal = 0;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir             if ( pItem )
100cdf0e10cSrcweir             {
101cdf0e10cSrcweir                 SfxViewFrame* pFrm = SfxViewFrame::Current();
102cdf0e10cSrcweir                 SfxShell* pSh = pFrm ? pFrm->GetDispatcher()->GetShell( 0 )
103cdf0e10cSrcweir                                      : NULL;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir                 if ( !pSh )
106cdf0e10cSrcweir                     return;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir                 const SfxItemPool& rPool = pSh->GetPool();
109cdf0e10cSrcweir                 sal_uInt16 nWhich = rPool.GetWhich( SID_ATTR_CHAR_FONTHEIGHT );
110cdf0e10cSrcweir                 const SfxMapUnit eUnit = rPool.GetMetric( nWhich );
111cdf0e10cSrcweir                 long nH = pItem->GetHeight() * 10;
112cdf0e10cSrcweir                 nVal = LOGIC( nH, (MapUnit)eUnit, MAP_POINT );
113cdf0e10cSrcweir             }
114cdf0e10cSrcweir             pMenu->SetCurHeight( nVal );
115cdf0e10cSrcweir         }
116cdf0e10cSrcweir         else if ( pState->ISA(SvxFontItem) )
117cdf0e10cSrcweir         {
118cdf0e10cSrcweir             const SvxFontItem* pItem = PTR_CAST( SvxFontItem, pState );
119cdf0e10cSrcweir 
120cdf0e10cSrcweir             if ( pItem )
121cdf0e10cSrcweir             {
122cdf0e10cSrcweir                 SfxObjectShell *pDoc = SfxObjectShell::Current();
123cdf0e10cSrcweir 
124cdf0e10cSrcweir                 if ( pDoc )
125cdf0e10cSrcweir                 {
126cdf0e10cSrcweir                     const SvxFontListItem* pFonts = (const SvxFontListItem*)
127cdf0e10cSrcweir                         pDoc->GetItem( SID_ATTR_CHAR_FONTLIST );
128cdf0e10cSrcweir                     const FontList* pList = pFonts ? pFonts->GetFontList(): 0;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir                     if ( pList )
131cdf0e10cSrcweir                     {
132cdf0e10cSrcweir                         FontInfo aFntInf = pList->Get( pItem->GetFamilyName(),
133cdf0e10cSrcweir                                                        pItem->GetStyleName() );
134cdf0e10cSrcweir                         pMenu->Fill( aFntInf, pList );
135cdf0e10cSrcweir                     }
136cdf0e10cSrcweir                     // else manche Shells haben keine Fontliste (z.B. Image)
137cdf0e10cSrcweir                 }
138cdf0e10cSrcweir             }
139cdf0e10cSrcweir         }
140cdf0e10cSrcweir     }
141cdf0e10cSrcweir     else
142cdf0e10cSrcweir     {
143cdf0e10cSrcweir         // irgendwie muss man ja das Men"u f"ullen
144cdf0e10cSrcweir         SfxObjectShell* pSh = SfxObjectShell::Current();
145cdf0e10cSrcweir 
146cdf0e10cSrcweir         if ( pSh )
147cdf0e10cSrcweir         {
148cdf0e10cSrcweir             // daf"ur von der Shell eine Fontliste besorgen
149cdf0e10cSrcweir             const SvxFontListItem* pFonts =
150cdf0e10cSrcweir                 (const SvxFontListItem*)pSh->GetItem( SID_ATTR_CHAR_FONTLIST );
151cdf0e10cSrcweir             const FontList* pList = pFonts ? pFonts->GetFontList(): NULL;
152cdf0e10cSrcweir             if ( pList )
153cdf0e10cSrcweir                 pMenu->Fill( pList->GetFontName(0), pList );
154cdf0e10cSrcweir         }
155cdf0e10cSrcweir     }
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir //--------------------------------------------------------------------
159cdf0e10cSrcweir 
160cdf0e10cSrcweir /*  [Beschreibung]
161cdf0e10cSrcweir 
162cdf0e10cSrcweir     Ctor; setzt den Select-Handler am Men"u und tr"agt Men"u
163cdf0e10cSrcweir     in seinen Parent ein.
164cdf0e10cSrcweir */
165cdf0e10cSrcweir 
SvxFontSizeMenuControl(sal_uInt16 _nId,Menu & rMenu,SfxBindings & rBindings)166cdf0e10cSrcweir SvxFontSizeMenuControl::SvxFontSizeMenuControl
167cdf0e10cSrcweir (
168cdf0e10cSrcweir     sal_uInt16          _nId,
169cdf0e10cSrcweir     Menu&           rMenu,
170cdf0e10cSrcweir     SfxBindings&    rBindings
171cdf0e10cSrcweir ) :
172cdf0e10cSrcweir     SfxMenuControl( _nId, rBindings ),
173cdf0e10cSrcweir 
174cdf0e10cSrcweir     pMenu   ( new FontSizeMenu ),
175cdf0e10cSrcweir     rParent ( rMenu ),
176cdf0e10cSrcweir     aFontNameForwarder( SID_ATTR_CHAR_FONT, *this )
177cdf0e10cSrcweir 
178cdf0e10cSrcweir {
179cdf0e10cSrcweir     rMenu.SetPopupMenu( _nId, pMenu );
180cdf0e10cSrcweir     pMenu->SetSelectHdl( LINK( this, SvxFontSizeMenuControl, MenuSelect ) );
181cdf0e10cSrcweir }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir //--------------------------------------------------------------------
184cdf0e10cSrcweir 
185cdf0e10cSrcweir /*  [Beschreibung]
186cdf0e10cSrcweir 
187cdf0e10cSrcweir     Dtor; gibt das Men"u frei.
188cdf0e10cSrcweir */
189cdf0e10cSrcweir 
~SvxFontSizeMenuControl()190cdf0e10cSrcweir SvxFontSizeMenuControl::~SvxFontSizeMenuControl()
191cdf0e10cSrcweir {
192cdf0e10cSrcweir     delete pMenu;
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir //--------------------------------------------------------------------
196cdf0e10cSrcweir 
197cdf0e10cSrcweir /*  [Beschreibung]
198cdf0e10cSrcweir 
199cdf0e10cSrcweir     Gibt das Men"u zur"uck
200cdf0e10cSrcweir */
201cdf0e10cSrcweir 
GetPopup() const202cdf0e10cSrcweir PopupMenu* SvxFontSizeMenuControl::GetPopup() const
203cdf0e10cSrcweir {
204cdf0e10cSrcweir     return pMenu;
205cdf0e10cSrcweir }
206