bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / mnuctrls / fntszctl.cxx
blobae0c13c5bc57903ff97b3c87ba96a1c5ef4d9566
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <string>
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);
45 /* [Beschreibung]
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;
56 if ( !pSh )
57 return 0;
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 );
65 return 1;
70 /* [Beschreibung]
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 );
91 long nVal = 0;
93 if ( pItem )
95 SfxViewFrame* pFrm = SfxViewFrame::Current();
96 SfxShell* pSh = pFrm ? pFrm->GetDispatcher()->GetShell( 0 )
97 : NULL;
99 if ( !pSh )
100 return;
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 );
114 if ( pItem )
116 SfxObjectShell *pDoc = SfxObjectShell::Current();
118 if ( pDoc )
120 const SvxFontListItem* pFonts = static_cast<const SvxFontListItem*>(
121 pDoc->GetItem( SID_ATTR_CHAR_FONTLIST ));
122 const FontList* pList = pFonts ? pFonts->GetFontList(): 0;
124 if ( pList )
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)
135 else
137 // irgendwie muss man ja das Men"u f"ullen
138 SfxObjectShell* pSh = SfxObjectShell::Current();
140 if ( pSh )
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;
146 if ( pList )
147 pMenu->Fill( pList->GetFontName(0), pList );
154 /* [Beschreibung]
156 Ctor; setzt den Select-Handler am Men"u und tr"agt Men"u
157 in seinen Parent ein.
160 SvxFontSizeMenuControl::SvxFontSizeMenuControl
162 sal_uInt16 _nId,
163 Menu& rMenu,
164 SfxBindings& rBindings
166 SfxMenuControl( _nId, rBindings ),
168 pMenu ( new FontSizeMenu ),
169 rParent ( rMenu ),
170 aFontNameForwarder( SID_ATTR_CHAR_FONT, *this )
173 rMenu.SetPopupMenu( _nId, pMenu );
174 pMenu->SetSelectHdl( LINK( this, SvxFontSizeMenuControl, MenuSelect ) );
179 /* [Beschreibung]
181 Dtor; gibt das Men"u frei.
184 SvxFontSizeMenuControl::~SvxFontSizeMenuControl()
186 delete pMenu;
191 /* [Beschreibung]
193 Gibt das Men"u zur"uck
196 PopupMenu* SvxFontSizeMenuControl::GetPopup() const
198 return pMenu;
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */