xref: /aoo42x/main/svx/source/mnuctrls/fntctl.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 
31 #include <string> // HACK: prevent conflict between STLPORT and Workshop headern
32 #include <svtools/stdmenu.hxx>
33 #include <sfx2/app.hxx>
34 #include <sfx2/objsh.hxx>
35 #include <sfx2/dispatch.hxx>
36 
37 #include <svx/fntctl.hxx>       //
38 #include <svx/svxids.hrc>
39 #include "editeng/flstitem.hxx"
40 #include "editeng/fontitem.hxx"
41 
42 // STATIC DATA -----------------------------------------------------------
43 
44 SFX_IMPL_MENU_CONTROL(SvxFontMenuControl, SvxFontItem);
45 
46 //--------------------------------------------------------------------
47 
48 /*	[Beschreibung]
49 
50 	Ctor; setzt den Select-Handler am Men"u und tr"agt das Men"u
51 	in seinen Parent ein.
52 */
53 
54 SvxFontMenuControl::SvxFontMenuControl
55 (
56 	sal_uInt16 			_nId,
57 	Menu&			rMenu,
58 	SfxBindings&	rBindings
59 ) :
60 	pMenu	( new FontNameMenu ),
61 	rParent	( rMenu )
62 {
63 	rMenu.SetPopupMenu( _nId, pMenu );
64 	pMenu->SetSelectHdl( LINK( this, SvxFontMenuControl, MenuSelect ) );
65 	StartListening( rBindings );
66 	FillMenu();
67 }
68 
69 //--------------------------------------------------------------------
70 
71 /*	[Beschreibung]
72 
73 	F"ullt das Men"u mit den aktuellen Fonts aus der Fontlist
74 	der DocumentShell.
75 */
76 
77 void SvxFontMenuControl::FillMenu()
78 {
79 	SfxObjectShell *pDoc = SfxObjectShell::Current();
80 
81 	if ( pDoc )
82 	{
83 		const SvxFontListItem* pFonts =
84 			(const SvxFontListItem*)pDoc->GetItem( SID_ATTR_CHAR_FONTLIST );
85 		const FontList* pList = pFonts ? pFonts->GetFontList(): 0;
86 		DBG_ASSERT( pList, "Kein Fonts gefunden" );
87 		pMenu->Fill( pList );
88 	}
89 }
90 
91 //--------------------------------------------------------------------
92 
93 /*	[Beschreibung]
94 
95 	Statusbenachrichtigung;
96 	f"ullt ggf. das Men"u mit den aktuellen Fonts aus der Fontlist
97 	der DocumentShell.
98 	Ist die Funktionalit"at disabled, wird der entsprechende
99 	Men"ueintrag im Parentmen"u disabled, andernfalls wird er enabled.
100 	Der aktuelle Font wird mit einer Checkmark versehen.
101 */
102 
103 void SvxFontMenuControl::StateChanged(
104 
105 	sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
106 
107 {
108 	rParent.EnableItem( GetId(), SFX_ITEM_DISABLED != eState );
109 
110 	if ( SFX_ITEM_AVAILABLE == eState )
111 	{
112 		if ( !pMenu->GetItemCount() )
113 			FillMenu();
114 		const SvxFontItem* pFontItem = PTR_CAST( SvxFontItem, pState );
115 		String aFont;
116 
117 		if ( pFontItem )
118 			aFont = pFontItem->GetFamilyName();
119 		pMenu->SetCurName( aFont );
120 	}
121 }
122 
123 //--------------------------------------------------------------------
124 
125 /*	[Beschreibung]
126 
127 	Statusbenachrichtigung "uber Bindings;  bei DOCCHANGED
128 	wird das Men"u mit den aktuellen Fonts aus der Fontlist
129 	der DocumentShell gef"ullt.
130 */
131 
132 void SvxFontMenuControl::Notify( SfxBroadcaster&, const SfxHint& rHint )
133 {
134 	if ( rHint.Type() != TYPE(SfxSimpleHint) &&
135 		 ( (SfxSimpleHint&)rHint ).GetId() == SFX_HINT_DOCCHANGED )
136 		FillMenu();
137 }
138 
139 //--------------------------------------------------------------------
140 
141 /*	[Beschreibung]
142 
143 	Select-Handler des Men"us; der Name des selektierten Fonts
144 	wird in einem SvxFontItem verschickt. Das F"ullen mit den
145 	weiteren Fontinformationen mu\s durch die Applikation geschehen.
146 */
147 
148 IMPL_LINK_INLINE_START( SvxFontMenuControl, MenuSelect, FontNameMenu *, pMen )
149 {
150 	SvxFontItem aItem( GetId() );
151     aItem.SetFamilyName(pMen->GetCurName());
152 	GetBindings().GetDispatcher()->Execute( GetId(), SFX_CALLMODE_RECORD, &aItem, 0L );
153 	return 0;
154 }
155 IMPL_LINK_INLINE_END( SvxFontMenuControl, MenuSelect, FontNameMenu *, pMen )
156 
157 //--------------------------------------------------------------------
158 
159 /*	[Beschreibung]
160 
161 	Dtor; gibt das Men"u frei.
162 */
163 
164 SvxFontMenuControl::~SvxFontMenuControl()
165 {
166 	delete pMenu;
167 }
168 
169 //--------------------------------------------------------------------
170 
171 /*	[Beschreibung]
172 
173 	Gibt das Men"u zur"uck
174 */
175 
176 PopupMenu* SvxFontMenuControl::GetPopup() const
177 {
178 	return pMenu;
179 }
180 
181 
182 
183