1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <svl/itempool.hxx>
23 #include <svtools/stdmenu.hxx>
24 #include <svtools/ctrltool.hxx>
25 #include <sfx2/app.hxx>
26 #include <sfx2/objsh.hxx>
27 #include <sfx2/viewfrm.hxx>
28 #include <sfx2/dispatch.hxx>
30 #include <svx/fntszctl.hxx>
31 #include <svx/dialogs.hrc>
32 #include <editeng/fhgtitem.hxx>
33 #include "editeng/fontitem.hxx"
34 #include "editeng/flstitem.hxx"
36 #include "svx/dlgutil.hxx"
37 #include <svx/dialmgr.hxx>
39 #define LOGIC OutputDevice::LogicToLogic
41 SFX_IMPL_MENU_CONTROL(SvxFontSizeMenuControl
, SvxFontHeightItem
);
47 Select-Handler des Men"us; die aktuelle Fontgr"o\se
48 wird in einem SvxFontHeightItem verschickt.
51 IMPL_LINK( SvxFontSizeMenuControl
, MenuSelect
, FontSizeMenu
*, pMen
)
53 SfxViewFrame
* pFrm
= SfxViewFrame::Current();
54 SfxShell
* pSh
= pFrm
? pFrm
->GetDispatcher()->GetShell( 0 ) : NULL
;
59 const SfxItemPool
& rPool
= pSh
->GetPool();
60 sal_uInt16 nWhich
= rPool
.GetWhich( SID_ATTR_CHAR_FONTHEIGHT
);
61 const SfxMapUnit eUnit
= rPool
.GetMetric( nWhich
);
62 long nH
= LOGIC( pMen
->GetCurHeight(), MAP_POINT
, (MapUnit
)eUnit
) / 10;
63 SvxFontHeightItem
aItem( nH
, 100, GetId() );
64 GetBindings().GetDispatcher()->Execute( GetId(), SfxCallMode::RECORD
, &aItem
, 0L );
72 Statusbenachrichtigung;
73 Ist die Funktionalit"at disabled, wird der entsprechende
74 Men"ueintrag im Parentmenu disabled, andernfalls wird er enabled.
75 die aktuelle Fontgr"o\se wird mit einer Checkmark versehen.
78 void SvxFontSizeMenuControl::StateChanged(
80 sal_uInt16
, SfxItemState eState
, const SfxPoolItem
* pState
)
83 rParent
.EnableItem( GetId(), SfxItemState::DISABLED
!= eState
);
85 if ( SfxItemState::DEFAULT
== eState
)
87 if ( pState
->ISA(SvxFontHeightItem
) )
89 const SvxFontHeightItem
* pItem
=
90 PTR_CAST( SvxFontHeightItem
, pState
);
95 SfxViewFrame
* pFrm
= SfxViewFrame::Current();
96 SfxShell
* pSh
= pFrm
? pFrm
->GetDispatcher()->GetShell( 0 )
102 const SfxItemPool
& rPool
= pSh
->GetPool();
103 sal_uInt16 nWhich
= rPool
.GetWhich( SID_ATTR_CHAR_FONTHEIGHT
);
104 const SfxMapUnit eUnit
= rPool
.GetMetric( nWhich
);
105 long nH
= pItem
->GetHeight() * 10;
106 nVal
= LOGIC( nH
, (MapUnit
)eUnit
, MAP_POINT
);
108 pMenu
->SetCurHeight( nVal
);
110 else if ( pState
->ISA(SvxFontItem
) )
112 const SvxFontItem
* pItem
= PTR_CAST( SvxFontItem
, pState
);
116 SfxObjectShell
*pDoc
= SfxObjectShell::Current();
120 const SvxFontListItem
* pFonts
= static_cast<const SvxFontListItem
*>(
121 pDoc
->GetItem( SID_ATTR_CHAR_FONTLIST
));
122 const FontList
* pList
= pFonts
? pFonts
->GetFontList(): 0;
126 vcl::FontInfo aFntInf
= pList
->Get( pItem
->GetFamilyName(),
127 pItem
->GetStyleName() );
128 pMenu
->Fill( aFntInf
, pList
);
130 // else manche Shells haben keine Fontliste (z.B. Image)
137 // irgendwie muss man ja das Men"u f"ullen
138 SfxObjectShell
* pSh
= SfxObjectShell::Current();
142 // daf"ur von der Shell eine Fontliste besorgen
143 const SvxFontListItem
* pFonts
=
144 static_cast<const SvxFontListItem
*>(pSh
->GetItem( SID_ATTR_CHAR_FONTLIST
));
145 const FontList
* pList
= pFonts
? pFonts
->GetFontList(): NULL
;
147 pMenu
->Fill( pList
->GetFontName(0), pList
);
156 Ctor; setzt den Select-Handler am Men"u und tr"agt Men"u
157 in seinen Parent ein.
160 SvxFontSizeMenuControl::SvxFontSizeMenuControl
164 SfxBindings
& rBindings
166 SfxMenuControl( _nId
, rBindings
),
168 pMenu ( new FontSizeMenu
),
170 aFontNameForwarder( SID_ATTR_CHAR_FONT
, *this )
173 rMenu
.SetPopupMenu( _nId
, pMenu
);
174 pMenu
->SetSelectHdl( LINK( this, SvxFontSizeMenuControl
, MenuSelect
) );
181 Dtor; gibt das Men"u frei.
184 SvxFontSizeMenuControl::~SvxFontSizeMenuControl()
193 Gibt das Men"u zur"uck
196 PopupMenu
* SvxFontSizeMenuControl::GetPopup() const
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */