merge the formfield patch from ooo-build
[ooovba.git] / svx / source / mnuctrls / fntctl.cxx
blob0ab16726aad8c7153f7692a8ab68647e2a0c924b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fntctl.cxx,v $
10 * $Revision: 1.8.76.1 $
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/stdmenu.hxx>
36 #include <sfx2/app.hxx>
37 #include <sfx2/objsh.hxx>
38 #include <sfx2/dispatch.hxx>
40 #include <svx/fntctl.hxx> //
41 #include <svx/svxids.hrc>
42 #include "flstitem.hxx"
43 #include "fontitem.hxx"
45 // STATIC DATA -----------------------------------------------------------
47 SFX_IMPL_MENU_CONTROL(SvxFontMenuControl, SvxFontItem);
49 //--------------------------------------------------------------------
51 /* [Beschreibung]
53 Ctor; setzt den Select-Handler am Men"u und tr"agt das Men"u
54 in seinen Parent ein.
57 SvxFontMenuControl::SvxFontMenuControl
59 USHORT _nId,
60 Menu& rMenu,
61 SfxBindings& rBindings
62 ) :
63 pMenu ( new FontNameMenu ),
64 rParent ( rMenu )
66 rMenu.SetPopupMenu( _nId, pMenu );
67 pMenu->SetSelectHdl( LINK( this, SvxFontMenuControl, MenuSelect ) );
68 StartListening( rBindings );
69 FillMenu();
72 //--------------------------------------------------------------------
74 /* [Beschreibung]
76 F"ullt das Men"u mit den aktuellen Fonts aus der Fontlist
77 der DocumentShell.
80 void SvxFontMenuControl::FillMenu()
82 SfxObjectShell *pDoc = SfxObjectShell::Current();
84 if ( pDoc )
86 const SvxFontListItem* pFonts =
87 (const SvxFontListItem*)pDoc->GetItem( SID_ATTR_CHAR_FONTLIST );
88 const FontList* pList = pFonts ? pFonts->GetFontList(): 0;
89 DBG_ASSERT( pList, "Kein Fonts gefunden" );
90 pMenu->Fill( pList );
94 //--------------------------------------------------------------------
96 /* [Beschreibung]
98 Statusbenachrichtigung;
99 f"ullt ggf. das Men"u mit den aktuellen Fonts aus der Fontlist
100 der DocumentShell.
101 Ist die Funktionalit"at disabled, wird der entsprechende
102 Men"ueintrag im Parentmen"u disabled, andernfalls wird er enabled.
103 Der aktuelle Font wird mit einer Checkmark versehen.
106 void SvxFontMenuControl::StateChanged(
108 USHORT, SfxItemState eState, const SfxPoolItem* pState )
111 rParent.EnableItem( GetId(), SFX_ITEM_DISABLED != eState );
113 if ( SFX_ITEM_AVAILABLE == eState )
115 if ( !pMenu->GetItemCount() )
116 FillMenu();
117 const SvxFontItem* pFontItem = PTR_CAST( SvxFontItem, pState );
118 String aFont;
120 if ( pFontItem )
121 aFont = pFontItem->GetFamilyName();
122 pMenu->SetCurName( aFont );
126 //--------------------------------------------------------------------
128 /* [Beschreibung]
130 Statusbenachrichtigung "uber Bindings; bei DOCCHANGED
131 wird das Men"u mit den aktuellen Fonts aus der Fontlist
132 der DocumentShell gef"ullt.
135 void SvxFontMenuControl::Notify( SfxBroadcaster&, const SfxHint& rHint )
137 if ( rHint.Type() != TYPE(SfxSimpleHint) &&
138 ( (SfxSimpleHint&)rHint ).GetId() == SFX_HINT_DOCCHANGED )
139 FillMenu();
142 //--------------------------------------------------------------------
144 /* [Beschreibung]
146 Select-Handler des Men"us; der Name des selektierten Fonts
147 wird in einem SvxFontItem verschickt. Das F"ullen mit den
148 weiteren Fontinformationen mu\s durch die Applikation geschehen.
151 IMPL_LINK_INLINE_START( SvxFontMenuControl, MenuSelect, FontNameMenu *, pMen )
153 SvxFontItem aItem( GetId() );
154 aItem.GetFamilyName() = pMen->GetCurName();
155 GetBindings().GetDispatcher()->Execute( GetId(), SFX_CALLMODE_RECORD, &aItem, 0L );
156 return 0;
158 IMPL_LINK_INLINE_END( SvxFontMenuControl, MenuSelect, FontNameMenu *, pMen )
160 //--------------------------------------------------------------------
162 /* [Beschreibung]
164 Dtor; gibt das Men"u frei.
167 SvxFontMenuControl::~SvxFontMenuControl()
169 delete pMenu;
172 //--------------------------------------------------------------------
174 /* [Beschreibung]
176 Gibt das Men"u zur"uck
179 PopupMenu* SvxFontMenuControl::GetPopup() const
181 return pMenu;