xref: /aoo42x/main/svx/source/mnuctrls/fntszctl.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 <svl/itempool.hxx>
33 #include <svtools/stdmenu.hxx>
34 #include <svtools/ctrltool.hxx>
35 #include <sfx2/app.hxx>
36 #include <sfx2/objsh.hxx>
37 #include <sfx2/viewfrm.hxx>
38 #include <sfx2/dispatch.hxx>
39 
40 #include <svx/fntszctl.hxx>     //
41 #include <svx/dialogs.hrc>
42 #include <editeng/fhgtitem.hxx>
43 #include "editeng/fontitem.hxx"
44 #include "editeng/flstitem.hxx"
45 
46 #include "svx/dlgutil.hxx"
47 #include <svx/dialmgr.hxx>
48 
49 #define LOGIC 	OutputDevice::LogicToLogic
50 
51 SFX_IMPL_MENU_CONTROL(SvxFontSizeMenuControl, SvxFontHeightItem);
52 
53 //--------------------------------------------------------------------
54 
55 /*	[Beschreibung]
56 
57 	Select-Handler des Men"us; die aktuelle Fontgr"o\se
58 	wird in einem SvxFontHeightItem verschickt.
59 */
60 
61 IMPL_LINK( SvxFontSizeMenuControl, MenuSelect, FontSizeMenu*, pMen )
62 {
63 	SfxViewFrame* pFrm = SfxViewFrame::Current();
64 	SfxShell* pSh = pFrm ? pFrm->GetDispatcher()->GetShell( 0 ) : NULL;
65 
66 	if ( !pSh )
67 		return 0;
68 
69 	const SfxItemPool& rPool = pSh->GetPool();
70 	sal_uInt16 nWhich = rPool.GetWhich( SID_ATTR_CHAR_FONTHEIGHT );
71 	const SfxMapUnit eUnit = rPool.GetMetric( nWhich );
72 	long nH = LOGIC( pMen->GetCurHeight(), MAP_POINT, (MapUnit)eUnit ) / 10;
73 	SvxFontHeightItem aItem( nH, 100, GetId() );
74 	GetBindings().GetDispatcher()->Execute( GetId(), SFX_CALLMODE_RECORD, &aItem, 0L );
75 	return 1;
76 }
77 
78 //--------------------------------------------------------------------
79 
80 /*	[Beschreibung]
81 
82 	Statusbenachrichtigung;
83 	Ist die Funktionalit"at disabled, wird der entsprechende
84 	Men"ueintrag im Parentmenu disabled, andernfalls wird er enabled.
85 	die aktuelle Fontgr"o\se wird mit einer Checkmark versehen.
86 */
87 
88 void SvxFontSizeMenuControl::StateChanged(
89 
90 	sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
91 
92 {
93 	rParent.EnableItem( GetId(), SFX_ITEM_DISABLED != eState );
94 
95 	if ( SFX_ITEM_AVAILABLE == eState )
96 	{
97 		if ( pState->ISA(SvxFontHeightItem) )
98 		{
99 			const SvxFontHeightItem* pItem =
100 				PTR_CAST( SvxFontHeightItem, pState );
101 			long nVal = 0;
102 
103 			if ( pItem )
104 			{
105 				SfxViewFrame* pFrm = SfxViewFrame::Current();
106 				SfxShell* pSh = pFrm ? pFrm->GetDispatcher()->GetShell( 0 )
107 									 : NULL;
108 
109 				if ( !pSh )
110 					return;
111 
112 				const SfxItemPool& rPool = pSh->GetPool();
113 				sal_uInt16 nWhich = rPool.GetWhich( SID_ATTR_CHAR_FONTHEIGHT );
114 				const SfxMapUnit eUnit = rPool.GetMetric( nWhich );
115 				long nH = pItem->GetHeight() * 10;
116 				nVal = LOGIC( nH, (MapUnit)eUnit, MAP_POINT );
117 			}
118 			pMenu->SetCurHeight( nVal );
119 		}
120 		else if ( pState->ISA(SvxFontItem) )
121 		{
122 			const SvxFontItem* pItem = PTR_CAST( SvxFontItem, pState );
123 
124 			if ( pItem )
125 			{
126 				SfxObjectShell *pDoc = SfxObjectShell::Current();
127 
128 				if ( pDoc )
129 				{
130 					const SvxFontListItem* pFonts =	(const SvxFontListItem*)
131 						pDoc->GetItem( SID_ATTR_CHAR_FONTLIST );
132 					const FontList* pList = pFonts ? pFonts->GetFontList(): 0;
133 
134 					if ( pList )
135 					{
136 						FontInfo aFntInf = pList->Get( pItem->GetFamilyName(),
137 													   pItem->GetStyleName() );
138 						pMenu->Fill( aFntInf, pList );
139 					}
140 					// else manche Shells haben keine Fontliste (z.B. Image)
141 				}
142 			}
143 		}
144 	}
145 	else
146 	{
147 		// irgendwie muss man ja das Men"u f"ullen
148 		SfxObjectShell* pSh = SfxObjectShell::Current();
149 
150 		if ( pSh )
151 		{
152 			// daf"ur von der Shell eine Fontliste besorgen
153 			const SvxFontListItem* pFonts =
154 				(const SvxFontListItem*)pSh->GetItem( SID_ATTR_CHAR_FONTLIST );
155 			const FontList* pList = pFonts ? pFonts->GetFontList(): NULL;
156 			if ( pList )
157 				pMenu->Fill( pList->GetFontName(0), pList );
158 		}
159 	}
160 }
161 
162 //--------------------------------------------------------------------
163 
164 /*	[Beschreibung]
165 
166 	Ctor; setzt den Select-Handler am Men"u und tr"agt Men"u
167 	in seinen Parent ein.
168 */
169 
170 SvxFontSizeMenuControl::SvxFontSizeMenuControl
171 (
172 	sal_uInt16 			_nId,
173 	Menu&			rMenu,
174 	SfxBindings&	rBindings
175 ) :
176 	SfxMenuControl( _nId, rBindings ),
177 
178 	pMenu	( new FontSizeMenu ),
179 	rParent	( rMenu ),
180 	aFontNameForwarder( SID_ATTR_CHAR_FONT, *this )
181 
182 {
183 	rMenu.SetPopupMenu( _nId, pMenu );
184 	pMenu->SetSelectHdl( LINK( this, SvxFontSizeMenuControl, MenuSelect ) );
185 }
186 
187 //--------------------------------------------------------------------
188 
189 /*	[Beschreibung]
190 
191 	Dtor; gibt das Men"u frei.
192 */
193 
194 SvxFontSizeMenuControl::~SvxFontSizeMenuControl()
195 {
196 	delete pMenu;
197 }
198 
199 //--------------------------------------------------------------------
200 
201 /*	[Beschreibung]
202 
203 	Gibt das Men"u zur"uck
204 */
205 
206 PopupMenu* SvxFontSizeMenuControl::GetPopup() const
207 {
208 	return pMenu;
209 }
210 
211 
212