1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fntszctl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <string> // HACK: prevent conflict between STLPORT and Workshop headern
35 #include <svtools/itempool.hxx>
36 #include <svtools/stdmenu.hxx>
37 #include <svtools/ctrltool.hxx>
38 #include <sfx2/app.hxx>
39 #include <sfx2/objsh.hxx>
40 #include <sfx2/viewfrm.hxx>
41 #include <sfx2/dispatch.hxx>
43 #include <svx/fntszctl.hxx> //
44 #include <svx/dialogs.hrc>
45 #include <svx/fhgtitem.hxx>
46 #include "fontitem.hxx"
47 #include "flstitem.hxx"
49 #include "dlgutil.hxx"
50 #include <svx/dialmgr.hxx>
52 #define LOGIC OutputDevice::LogicToLogic
54 SFX_IMPL_MENU_CONTROL(SvxFontSizeMenuControl
, SvxFontHeightItem
);
56 //--------------------------------------------------------------------
60 Select-Handler des Men"us; die aktuelle Fontgr"o\se
61 wird in einem SvxFontHeightItem verschickt.
64 IMPL_LINK( SvxFontSizeMenuControl
, MenuSelect
, FontSizeMenu
*, pMen
)
66 SfxViewFrame
* pFrm
= SfxViewFrame::Current();
67 SfxShell
* pSh
= pFrm
? pFrm
->GetDispatcher()->GetShell( 0 ) : NULL
;
72 const SfxItemPool
& rPool
= pSh
->GetPool();
73 USHORT nWhich
= rPool
.GetWhich( SID_ATTR_CHAR_FONTHEIGHT
);
74 const SfxMapUnit eUnit
= rPool
.GetMetric( nWhich
);
75 long nH
= LOGIC( pMen
->GetCurHeight(), MAP_POINT
, (MapUnit
)eUnit
) / 10;
76 SvxFontHeightItem
aItem( nH
, 100, GetId() );
77 GetBindings().GetDispatcher()->Execute( GetId(), SFX_CALLMODE_RECORD
, &aItem
, 0L );
81 //--------------------------------------------------------------------
85 Statusbenachrichtigung;
86 Ist die Funktionalit"at disabled, wird der entsprechende
87 Men"ueintrag im Parentmenu disabled, andernfalls wird er enabled.
88 die aktuelle Fontgr"o\se wird mit einer Checkmark versehen.
91 void SvxFontSizeMenuControl::StateChanged(
93 USHORT
, SfxItemState eState
, const SfxPoolItem
* pState
)
96 rParent
.EnableItem( GetId(), SFX_ITEM_DISABLED
!= eState
);
98 if ( SFX_ITEM_AVAILABLE
== eState
)
100 if ( pState
->ISA(SvxFontHeightItem
) )
102 const SvxFontHeightItem
* pItem
=
103 PTR_CAST( SvxFontHeightItem
, pState
);
108 SfxViewFrame
* pFrm
= SfxViewFrame::Current();
109 SfxShell
* pSh
= pFrm
? pFrm
->GetDispatcher()->GetShell( 0 )
115 const SfxItemPool
& rPool
= pSh
->GetPool();
116 USHORT nWhich
= rPool
.GetWhich( SID_ATTR_CHAR_FONTHEIGHT
);
117 const SfxMapUnit eUnit
= rPool
.GetMetric( nWhich
);
118 long nH
= pItem
->GetHeight() * 10;
119 nVal
= LOGIC( nH
, (MapUnit
)eUnit
, MAP_POINT
);
121 pMenu
->SetCurHeight( nVal
);
123 else if ( pState
->ISA(SvxFontItem
) )
125 const SvxFontItem
* pItem
= PTR_CAST( SvxFontItem
, pState
);
129 SfxObjectShell
*pDoc
= SfxObjectShell::Current();
133 const SvxFontListItem
* pFonts
= (const SvxFontListItem
*)
134 pDoc
->GetItem( SID_ATTR_CHAR_FONTLIST
);
135 const FontList
* pList
= pFonts
? pFonts
->GetFontList(): 0;
139 FontInfo aFntInf
= pList
->Get( pItem
->GetFamilyName(),
140 pItem
->GetStyleName() );
141 pMenu
->Fill( aFntInf
, pList
);
143 // else manche Shells haben keine Fontliste (z.B. Image)
150 // irgendwie muss man ja das Men"u f"ullen
151 SfxObjectShell
* pSh
= SfxObjectShell::Current();
155 // daf"ur von der Shell eine Fontliste besorgen
156 const SvxFontListItem
* pFonts
=
157 (const SvxFontListItem
*)pSh
->GetItem( SID_ATTR_CHAR_FONTLIST
);
158 const FontList
* pList
= pFonts
? pFonts
->GetFontList(): NULL
;
160 pMenu
->Fill( pList
->GetFontName(0), pList
);
165 //--------------------------------------------------------------------
169 Ctor; setzt den Select-Handler am Men"u und tr"agt Men"u
170 in seinen Parent ein.
173 SvxFontSizeMenuControl::SvxFontSizeMenuControl
177 SfxBindings
& rBindings
179 SfxMenuControl( _nId
, rBindings
),
181 pMenu ( new FontSizeMenu
),
183 aFontNameForwarder( SID_ATTR_CHAR_FONT
, *this )
186 rMenu
.SetPopupMenu( _nId
, pMenu
);
187 pMenu
->SetSelectHdl( LINK( this, SvxFontSizeMenuControl
, MenuSelect
) );
190 //--------------------------------------------------------------------
194 Dtor; gibt das Men"u frei.
197 SvxFontSizeMenuControl::~SvxFontSizeMenuControl()
202 //--------------------------------------------------------------------
206 Gibt das Men"u zur"uck
209 PopupMenu
* SvxFontSizeMenuControl::GetPopup() const