update credits
[LibreOffice.git] / svx / source / mnuctrls / fntctl.cxx
blob9aebd0798008f0e480165413ab5a2033a5ebba17
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 <svtools/stdmenu.hxx>
23 #include <sfx2/app.hxx>
24 #include <sfx2/objsh.hxx>
25 #include <sfx2/dispatch.hxx>
27 #include <svx/fntctl.hxx>
28 #include <svx/svxids.hrc>
29 #include "editeng/flstitem.hxx"
30 #include "editeng/fontitem.hxx"
32 // STATIC DATA -----------------------------------------------------------
34 SFX_IMPL_MENU_CONTROL(SvxFontMenuControl, SvxFontItem);
36 //--------------------------------------------------------------------
38 /* [Beschreibung]
40 Ctor; setzt den Select-Handler am Men"u und tr"agt das Men"u
41 in seinen Parent ein.
44 SvxFontMenuControl::SvxFontMenuControl
46 sal_uInt16 _nId,
47 Menu& rMenu,
48 SfxBindings& rBindings
49 ) :
50 pMenu ( new FontNameMenu ),
51 rParent ( rMenu )
53 rMenu.SetPopupMenu( _nId, pMenu );
54 pMenu->SetSelectHdl( LINK( this, SvxFontMenuControl, MenuSelect ) );
55 StartListening( rBindings );
56 FillMenu();
59 //--------------------------------------------------------------------
61 /* [Beschreibung]
63 F"ullt das Men"u mit den aktuellen Fonts aus der Fontlist
64 der DocumentShell.
67 void SvxFontMenuControl::FillMenu()
69 SfxObjectShell *pDoc = SfxObjectShell::Current();
71 if ( pDoc )
73 const SvxFontListItem* pFonts =
74 (const SvxFontListItem*)pDoc->GetItem( SID_ATTR_CHAR_FONTLIST );
75 const FontList* pList = pFonts ? pFonts->GetFontList(): 0;
76 DBG_ASSERT( pList, "Kein Fonts gefunden" );
77 pMenu->Fill( pList );
81 //--------------------------------------------------------------------
83 /* [Beschreibung]
85 Statusbenachrichtigung;
86 f"ullt ggf. das Men"u mit den aktuellen Fonts aus der Fontlist
87 der DocumentShell.
88 Ist die Funktionalit"at disabled, wird der entsprechende
89 Men"ueintrag im Parentmen"u disabled, andernfalls wird er enabled.
90 Der aktuelle Font wird mit einer Checkmark versehen.
93 void SvxFontMenuControl::StateChanged(
95 sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
98 rParent.EnableItem( GetId(), SFX_ITEM_DISABLED != eState );
100 if ( SFX_ITEM_AVAILABLE == eState )
102 if ( !pMenu->GetItemCount() )
103 FillMenu();
104 const SvxFontItem* pFontItem = PTR_CAST( SvxFontItem, pState );
105 String aFont;
107 if ( pFontItem )
108 aFont = pFontItem->GetFamilyName();
109 pMenu->SetCurName( aFont );
113 //--------------------------------------------------------------------
115 /* [Beschreibung]
117 Statusbenachrichtigung "uber Bindings; bei DOCCHANGED
118 wird das Men"u mit den aktuellen Fonts aus der Fontlist
119 der DocumentShell gef"ullt.
122 void SvxFontMenuControl::Notify( SfxBroadcaster&, const SfxHint& rHint )
124 if ( rHint.Type() != TYPE(SfxSimpleHint) &&
125 ( (SfxSimpleHint&)rHint ).GetId() == SFX_HINT_DOCCHANGED )
126 FillMenu();
129 //--------------------------------------------------------------------
131 /* [Beschreibung]
133 Select-Handler des Men"us; der Name des selektierten Fonts
134 wird in einem SvxFontItem verschickt. Das F"ullen mit den
135 weiteren Fontinformationen mu\s durch die Applikation geschehen.
138 IMPL_LINK_INLINE_START( SvxFontMenuControl, MenuSelect, FontNameMenu *, pMen )
140 SvxFontItem aItem( GetId() );
141 aItem.SetFamilyName(pMen->GetCurName());
142 GetBindings().GetDispatcher()->Execute( GetId(), SFX_CALLMODE_RECORD, &aItem, 0L );
143 return 0;
145 IMPL_LINK_INLINE_END( SvxFontMenuControl, MenuSelect, FontNameMenu *, pMen )
147 //--------------------------------------------------------------------
149 /* [Beschreibung]
151 Dtor; gibt das Men"u frei.
154 SvxFontMenuControl::~SvxFontMenuControl()
156 delete pMenu;
159 //--------------------------------------------------------------------
161 /* [Beschreibung]
163 Gibt das Men"u zur"uck
166 PopupMenu* SvxFontMenuControl::GetPopup() const
168 return pMenu;
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */