xref: /aoo4110/main/svx/source/mnuctrls/fntszctl.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include <string> // HACK: prevent conflict between STLPORT and Workshop headern
28 #include <svl/itempool.hxx>
29 #include <svtools/stdmenu.hxx>
30 #include <svtools/ctrltool.hxx>
31 #include <sfx2/app.hxx>
32 #include <sfx2/objsh.hxx>
33 #include <sfx2/viewfrm.hxx>
34 #include <sfx2/dispatch.hxx>
35 
36 #include <svx/fntszctl.hxx>     //
37 #include <svx/dialogs.hrc>
38 #include <editeng/fhgtitem.hxx>
39 #include "editeng/fontitem.hxx"
40 #include "editeng/flstitem.hxx"
41 
42 #include "svx/dlgutil.hxx"
43 #include <svx/dialmgr.hxx>
44 
45 #define LOGIC 	OutputDevice::LogicToLogic
46 
47 SFX_IMPL_MENU_CONTROL(SvxFontSizeMenuControl, SvxFontHeightItem);
48 
49 //--------------------------------------------------------------------
50 
51 /*	[Beschreibung]
52 
53 	Select-Handler des Men"us; die aktuelle Fontgr"o\se
54 	wird in einem SvxFontHeightItem verschickt.
55 */
56 
IMPL_LINK(SvxFontSizeMenuControl,MenuSelect,FontSizeMenu *,pMen)57 IMPL_LINK( SvxFontSizeMenuControl, MenuSelect, FontSizeMenu*, pMen )
58 {
59 	SfxViewFrame* pFrm = SfxViewFrame::Current();
60 	SfxShell* pSh = pFrm ? pFrm->GetDispatcher()->GetShell( 0 ) : NULL;
61 
62 	if ( !pSh )
63 		return 0;
64 
65 	const SfxItemPool& rPool = pSh->GetPool();
66 	sal_uInt16 nWhich = rPool.GetWhich( SID_ATTR_CHAR_FONTHEIGHT );
67 	const SfxMapUnit eUnit = rPool.GetMetric( nWhich );
68 	long nH = LOGIC( pMen->GetCurHeight(), MAP_POINT, (MapUnit)eUnit ) / 10;
69 	SvxFontHeightItem aItem( nH, 100, GetId() );
70 	GetBindings().GetDispatcher()->Execute( GetId(), SFX_CALLMODE_RECORD, &aItem, 0L );
71 	return 1;
72 }
73 
74 //--------------------------------------------------------------------
75 
76 /*	[Beschreibung]
77 
78 	Statusbenachrichtigung;
79 	Ist die Funktionalit"at disabled, wird der entsprechende
80 	Men"ueintrag im Parentmenu disabled, andernfalls wird er enabled.
81 	die aktuelle Fontgr"o\se wird mit einer Checkmark versehen.
82 */
83 
StateChanged(sal_uInt16,SfxItemState eState,const SfxPoolItem * pState)84 void SvxFontSizeMenuControl::StateChanged(
85 
86 	sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
87 
88 {
89 	rParent.EnableItem( GetId(), SFX_ITEM_DISABLED != eState );
90 
91 	if ( SFX_ITEM_AVAILABLE == eState )
92 	{
93 		if ( pState->ISA(SvxFontHeightItem) )
94 		{
95 			const SvxFontHeightItem* pItem =
96 				PTR_CAST( SvxFontHeightItem, pState );
97 			long nVal = 0;
98 
99 			if ( pItem )
100 			{
101 				SfxViewFrame* pFrm = SfxViewFrame::Current();
102 				SfxShell* pSh = pFrm ? pFrm->GetDispatcher()->GetShell( 0 )
103 									 : NULL;
104 
105 				if ( !pSh )
106 					return;
107 
108 				const SfxItemPool& rPool = pSh->GetPool();
109 				sal_uInt16 nWhich = rPool.GetWhich( SID_ATTR_CHAR_FONTHEIGHT );
110 				const SfxMapUnit eUnit = rPool.GetMetric( nWhich );
111 				long nH = pItem->GetHeight() * 10;
112 				nVal = LOGIC( nH, (MapUnit)eUnit, MAP_POINT );
113 			}
114 			pMenu->SetCurHeight( nVal );
115 		}
116 		else if ( pState->ISA(SvxFontItem) )
117 		{
118 			const SvxFontItem* pItem = PTR_CAST( SvxFontItem, pState );
119 
120 			if ( pItem )
121 			{
122 				SfxObjectShell *pDoc = SfxObjectShell::Current();
123 
124 				if ( pDoc )
125 				{
126 					const SvxFontListItem* pFonts =	(const SvxFontListItem*)
127 						pDoc->GetItem( SID_ATTR_CHAR_FONTLIST );
128 					const FontList* pList = pFonts ? pFonts->GetFontList(): 0;
129 
130 					if ( pList )
131 					{
132 						FontInfo aFntInf = pList->Get( pItem->GetFamilyName(),
133 													   pItem->GetStyleName() );
134 						pMenu->Fill( aFntInf, pList );
135 					}
136 					// else manche Shells haben keine Fontliste (z.B. Image)
137 				}
138 			}
139 		}
140 	}
141 	else
142 	{
143 		// irgendwie muss man ja das Men"u f"ullen
144 		SfxObjectShell* pSh = SfxObjectShell::Current();
145 
146 		if ( pSh )
147 		{
148 			// daf"ur von der Shell eine Fontliste besorgen
149 			const SvxFontListItem* pFonts =
150 				(const SvxFontListItem*)pSh->GetItem( SID_ATTR_CHAR_FONTLIST );
151 			const FontList* pList = pFonts ? pFonts->GetFontList(): NULL;
152 			if ( pList )
153 				pMenu->Fill( pList->GetFontName(0), pList );
154 		}
155 	}
156 }
157 
158 //--------------------------------------------------------------------
159 
160 /*	[Beschreibung]
161 
162 	Ctor; setzt den Select-Handler am Men"u und tr"agt Men"u
163 	in seinen Parent ein.
164 */
165 
SvxFontSizeMenuControl(sal_uInt16 _nId,Menu & rMenu,SfxBindings & rBindings)166 SvxFontSizeMenuControl::SvxFontSizeMenuControl
167 (
168 	sal_uInt16 			_nId,
169 	Menu&			rMenu,
170 	SfxBindings&	rBindings
171 ) :
172 	SfxMenuControl( _nId, rBindings ),
173 
174 	pMenu	( new FontSizeMenu ),
175 	rParent	( rMenu ),
176 	aFontNameForwarder( SID_ATTR_CHAR_FONT, *this )
177 
178 {
179 	rMenu.SetPopupMenu( _nId, pMenu );
180 	pMenu->SetSelectHdl( LINK( this, SvxFontSizeMenuControl, MenuSelect ) );
181 }
182 
183 //--------------------------------------------------------------------
184 
185 /*	[Beschreibung]
186 
187 	Dtor; gibt das Men"u frei.
188 */
189 
~SvxFontSizeMenuControl()190 SvxFontSizeMenuControl::~SvxFontSizeMenuControl()
191 {
192 	delete pMenu;
193 }
194 
195 //--------------------------------------------------------------------
196 
197 /*	[Beschreibung]
198 
199 	Gibt das Men"u zur"uck
200 */
201 
GetPopup() const202 PopupMenu* SvxFontSizeMenuControl::GetPopup() const
203 {
204 	return pMenu;
205 }
206 
207 
208