xref: /aoo41x/main/svx/source/mnuctrls/fntctl.cxx (revision 79aad27f)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f6e50924SAndrew Rist  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19*f6e50924SAndrew Rist  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <string> // HACK: prevent conflict between STLPORT and Workshop headern
28cdf0e10cSrcweir #include <svtools/stdmenu.hxx>
29cdf0e10cSrcweir #include <sfx2/app.hxx>
30cdf0e10cSrcweir #include <sfx2/objsh.hxx>
31cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <svx/fntctl.hxx>       //
34cdf0e10cSrcweir #include <svx/svxids.hrc>
35cdf0e10cSrcweir #include "editeng/flstitem.hxx"
36cdf0e10cSrcweir #include "editeng/fontitem.hxx"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
39cdf0e10cSrcweir 
40cdf0e10cSrcweir SFX_IMPL_MENU_CONTROL(SvxFontMenuControl, SvxFontItem);
41cdf0e10cSrcweir 
42cdf0e10cSrcweir //--------------------------------------------------------------------
43cdf0e10cSrcweir 
44cdf0e10cSrcweir /*	[Beschreibung]
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 	Ctor; setzt den Select-Handler am Men"u und tr"agt das Men"u
47cdf0e10cSrcweir 	in seinen Parent ein.
48cdf0e10cSrcweir */
49cdf0e10cSrcweir 
SvxFontMenuControl(sal_uInt16 _nId,Menu & rMenu,SfxBindings & rBindings)50cdf0e10cSrcweir SvxFontMenuControl::SvxFontMenuControl
51cdf0e10cSrcweir (
52cdf0e10cSrcweir 	sal_uInt16 			_nId,
53cdf0e10cSrcweir 	Menu&			rMenu,
54cdf0e10cSrcweir 	SfxBindings&	rBindings
55cdf0e10cSrcweir ) :
56cdf0e10cSrcweir 	pMenu	( new FontNameMenu ),
57cdf0e10cSrcweir 	rParent	( rMenu )
58cdf0e10cSrcweir {
59cdf0e10cSrcweir 	rMenu.SetPopupMenu( _nId, pMenu );
60cdf0e10cSrcweir 	pMenu->SetSelectHdl( LINK( this, SvxFontMenuControl, MenuSelect ) );
61cdf0e10cSrcweir 	StartListening( rBindings );
62cdf0e10cSrcweir 	FillMenu();
63cdf0e10cSrcweir }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir //--------------------------------------------------------------------
66cdf0e10cSrcweir 
67cdf0e10cSrcweir /*	[Beschreibung]
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 	F"ullt das Men"u mit den aktuellen Fonts aus der Fontlist
70cdf0e10cSrcweir 	der DocumentShell.
71cdf0e10cSrcweir */
72cdf0e10cSrcweir 
FillMenu()73cdf0e10cSrcweir void SvxFontMenuControl::FillMenu()
74cdf0e10cSrcweir {
75cdf0e10cSrcweir 	SfxObjectShell *pDoc = SfxObjectShell::Current();
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 	if ( pDoc )
78cdf0e10cSrcweir 	{
79cdf0e10cSrcweir 		const SvxFontListItem* pFonts =
80cdf0e10cSrcweir 			(const SvxFontListItem*)pDoc->GetItem( SID_ATTR_CHAR_FONTLIST );
81cdf0e10cSrcweir 		const FontList* pList = pFonts ? pFonts->GetFontList(): 0;
82cdf0e10cSrcweir 		DBG_ASSERT( pList, "Kein Fonts gefunden" );
83cdf0e10cSrcweir 		pMenu->Fill( pList );
84cdf0e10cSrcweir 	}
85cdf0e10cSrcweir }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir //--------------------------------------------------------------------
88cdf0e10cSrcweir 
89cdf0e10cSrcweir /*	[Beschreibung]
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 	Statusbenachrichtigung;
92cdf0e10cSrcweir 	f"ullt ggf. das Men"u mit den aktuellen Fonts aus der Fontlist
93cdf0e10cSrcweir 	der DocumentShell.
94cdf0e10cSrcweir 	Ist die Funktionalit"at disabled, wird der entsprechende
95cdf0e10cSrcweir 	Men"ueintrag im Parentmen"u disabled, andernfalls wird er enabled.
96cdf0e10cSrcweir 	Der aktuelle Font wird mit einer Checkmark versehen.
97cdf0e10cSrcweir */
98cdf0e10cSrcweir 
StateChanged(sal_uInt16,SfxItemState eState,const SfxPoolItem * pState)99cdf0e10cSrcweir void SvxFontMenuControl::StateChanged(
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 	sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
102cdf0e10cSrcweir 
103cdf0e10cSrcweir {
104cdf0e10cSrcweir 	rParent.EnableItem( GetId(), SFX_ITEM_DISABLED != eState );
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	if ( SFX_ITEM_AVAILABLE == eState )
107cdf0e10cSrcweir 	{
108cdf0e10cSrcweir 		if ( !pMenu->GetItemCount() )
109cdf0e10cSrcweir 			FillMenu();
110cdf0e10cSrcweir 		const SvxFontItem* pFontItem = PTR_CAST( SvxFontItem, pState );
111cdf0e10cSrcweir 		String aFont;
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 		if ( pFontItem )
114cdf0e10cSrcweir 			aFont = pFontItem->GetFamilyName();
115cdf0e10cSrcweir 		pMenu->SetCurName( aFont );
116cdf0e10cSrcweir 	}
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir //--------------------------------------------------------------------
120cdf0e10cSrcweir 
121cdf0e10cSrcweir /*	[Beschreibung]
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 	Statusbenachrichtigung "uber Bindings;  bei DOCCHANGED
124cdf0e10cSrcweir 	wird das Men"u mit den aktuellen Fonts aus der Fontlist
125cdf0e10cSrcweir 	der DocumentShell gef"ullt.
126cdf0e10cSrcweir */
127cdf0e10cSrcweir 
Notify(SfxBroadcaster &,const SfxHint & rHint)128cdf0e10cSrcweir void SvxFontMenuControl::Notify( SfxBroadcaster&, const SfxHint& rHint )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir 	if ( rHint.Type() != TYPE(SfxSimpleHint) &&
131cdf0e10cSrcweir 		 ( (SfxSimpleHint&)rHint ).GetId() == SFX_HINT_DOCCHANGED )
132cdf0e10cSrcweir 		FillMenu();
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
135cdf0e10cSrcweir //--------------------------------------------------------------------
136cdf0e10cSrcweir 
137cdf0e10cSrcweir /*	[Beschreibung]
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 	Select-Handler des Men"us; der Name des selektierten Fonts
140cdf0e10cSrcweir 	wird in einem SvxFontItem verschickt. Das F"ullen mit den
141cdf0e10cSrcweir 	weiteren Fontinformationen mu\s durch die Applikation geschehen.
142cdf0e10cSrcweir */
143cdf0e10cSrcweir 
IMPL_LINK_INLINE_START(SvxFontMenuControl,MenuSelect,FontNameMenu *,pMen)144cdf0e10cSrcweir IMPL_LINK_INLINE_START( SvxFontMenuControl, MenuSelect, FontNameMenu *, pMen )
145cdf0e10cSrcweir {
146cdf0e10cSrcweir 	SvxFontItem aItem( GetId() );
147cdf0e10cSrcweir     aItem.SetFamilyName(pMen->GetCurName());
148cdf0e10cSrcweir 	GetBindings().GetDispatcher()->Execute( GetId(), SFX_CALLMODE_RECORD, &aItem, 0L );
149cdf0e10cSrcweir 	return 0;
150cdf0e10cSrcweir }
IMPL_LINK_INLINE_END(SvxFontMenuControl,MenuSelect,FontNameMenu *,pMen)151cdf0e10cSrcweir IMPL_LINK_INLINE_END( SvxFontMenuControl, MenuSelect, FontNameMenu *, pMen )
152cdf0e10cSrcweir 
153cdf0e10cSrcweir //--------------------------------------------------------------------
154cdf0e10cSrcweir 
155cdf0e10cSrcweir /*	[Beschreibung]
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 	Dtor; gibt das Men"u frei.
158cdf0e10cSrcweir */
159cdf0e10cSrcweir 
160cdf0e10cSrcweir SvxFontMenuControl::~SvxFontMenuControl()
161cdf0e10cSrcweir {
162cdf0e10cSrcweir 	delete pMenu;
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir //--------------------------------------------------------------------
166cdf0e10cSrcweir 
167cdf0e10cSrcweir /*	[Beschreibung]
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 	Gibt das Men"u zur"uck
170cdf0e10cSrcweir */
171cdf0e10cSrcweir 
GetPopup() const172cdf0e10cSrcweir PopupMenu* SvxFontMenuControl::GetPopup() const
173cdf0e10cSrcweir {
174cdf0e10cSrcweir 	return pMenu;
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 
179