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 <svtools/stdmenu.hxx> 29 #include <sfx2/app.hxx> 30 #include <sfx2/objsh.hxx> 31 #include <sfx2/dispatch.hxx> 32 33 #include <svx/fntctl.hxx> // 34 #include <svx/svxids.hrc> 35 #include "editeng/flstitem.hxx" 36 #include "editeng/fontitem.hxx" 37 38 // STATIC DATA ----------------------------------------------------------- 39 40 SFX_IMPL_MENU_CONTROL(SvxFontMenuControl, SvxFontItem); 41 42 //-------------------------------------------------------------------- 43 44 /* [Beschreibung] 45 46 Ctor; setzt den Select-Handler am Men"u und tr"agt das Men"u 47 in seinen Parent ein. 48 */ 49 50 SvxFontMenuControl::SvxFontMenuControl 51 ( 52 sal_uInt16 _nId, 53 Menu& rMenu, 54 SfxBindings& rBindings 55 ) : 56 pMenu ( new FontNameMenu ), 57 rParent ( rMenu ) 58 { 59 rMenu.SetPopupMenu( _nId, pMenu ); 60 pMenu->SetSelectHdl( LINK( this, SvxFontMenuControl, MenuSelect ) ); 61 StartListening( rBindings ); 62 FillMenu(); 63 } 64 65 //-------------------------------------------------------------------- 66 67 /* [Beschreibung] 68 69 F"ullt das Men"u mit den aktuellen Fonts aus der Fontlist 70 der DocumentShell. 71 */ 72 73 void SvxFontMenuControl::FillMenu() 74 { 75 SfxObjectShell *pDoc = SfxObjectShell::Current(); 76 77 if ( pDoc ) 78 { 79 const SvxFontListItem* pFonts = 80 (const SvxFontListItem*)pDoc->GetItem( SID_ATTR_CHAR_FONTLIST ); 81 const FontList* pList = pFonts ? pFonts->GetFontList(): 0; 82 DBG_ASSERT( pList, "Kein Fonts gefunden" ); 83 pMenu->Fill( pList ); 84 } 85 } 86 87 //-------------------------------------------------------------------- 88 89 /* [Beschreibung] 90 91 Statusbenachrichtigung; 92 f"ullt ggf. das Men"u mit den aktuellen Fonts aus der Fontlist 93 der DocumentShell. 94 Ist die Funktionalit"at disabled, wird der entsprechende 95 Men"ueintrag im Parentmen"u disabled, andernfalls wird er enabled. 96 Der aktuelle Font wird mit einer Checkmark versehen. 97 */ 98 99 void SvxFontMenuControl::StateChanged( 100 101 sal_uInt16, SfxItemState eState, const SfxPoolItem* pState ) 102 103 { 104 rParent.EnableItem( GetId(), SFX_ITEM_DISABLED != eState ); 105 106 if ( SFX_ITEM_AVAILABLE == eState ) 107 { 108 if ( !pMenu->GetItemCount() ) 109 FillMenu(); 110 const SvxFontItem* pFontItem = PTR_CAST( SvxFontItem, pState ); 111 String aFont; 112 113 if ( pFontItem ) 114 aFont = pFontItem->GetFamilyName(); 115 pMenu->SetCurName( aFont ); 116 } 117 } 118 119 //-------------------------------------------------------------------- 120 121 /* [Beschreibung] 122 123 Statusbenachrichtigung "uber Bindings; bei DOCCHANGED 124 wird das Men"u mit den aktuellen Fonts aus der Fontlist 125 der DocumentShell gef"ullt. 126 */ 127 128 void SvxFontMenuControl::Notify( SfxBroadcaster&, const SfxHint& rHint ) 129 { 130 if ( rHint.Type() != TYPE(SfxSimpleHint) && 131 ( (SfxSimpleHint&)rHint ).GetId() == SFX_HINT_DOCCHANGED ) 132 FillMenu(); 133 } 134 135 //-------------------------------------------------------------------- 136 137 /* [Beschreibung] 138 139 Select-Handler des Men"us; der Name des selektierten Fonts 140 wird in einem SvxFontItem verschickt. Das F"ullen mit den 141 weiteren Fontinformationen mu\s durch die Applikation geschehen. 142 */ 143 144 IMPL_LINK_INLINE_START( SvxFontMenuControl, MenuSelect, FontNameMenu *, pMen ) 145 { 146 SvxFontItem aItem( GetId() ); 147 aItem.SetFamilyName(pMen->GetCurName()); 148 GetBindings().GetDispatcher()->Execute( GetId(), SFX_CALLMODE_RECORD, &aItem, 0L ); 149 return 0; 150 } 151 IMPL_LINK_INLINE_END( SvxFontMenuControl, MenuSelect, FontNameMenu *, pMen ) 152 153 //-------------------------------------------------------------------- 154 155 /* [Beschreibung] 156 157 Dtor; gibt das Men"u frei. 158 */ 159 160 SvxFontMenuControl::~SvxFontMenuControl() 161 { 162 delete pMenu; 163 } 164 165 //-------------------------------------------------------------------- 166 167 /* [Beschreibung] 168 169 Gibt das Men"u zur"uck 170 */ 171 172 PopupMenu* SvxFontMenuControl::GetPopup() const 173 { 174 return pMenu; 175 } 176 177 178 179