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 #include "precompiled_svx.hxx"
23 
24 #include "SvxSBFontNameBox.hxx"
25 
26 #include <unotools/fontoptions.hxx>
27 #include <sfx2/objsh.hxx>
28 #include <sfx2/dispatch.hxx>
29 #include <editeng/flstitem.hxx>
30 #include <editeng/editids.hrc>
31 #include <editeng/fontitem.hxx>
32 
33 
34 const static sal_uInt16 MAX_MRU_FONTNAME_ENTRIES = 5;
35 
36 
37 namespace svx { namespace sidebar {
38 
39 namespace {
GetDocFontList_Impl(const FontList ** ppFontList,SvxSBFontNameBox * pBox)40     bool GetDocFontList_Impl( const FontList** ppFontList, SvxSBFontNameBox* pBox )
41     {
42         bool bChanged = false;
43         const SfxObjectShell* pDocSh = SfxObjectShell::Current();
44         SvxFontListItem* pFontListItem = NULL;
45 
46         if ( pDocSh )
47             pFontListItem =
48                 (SvxFontListItem*)pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST );
49 
50         if ( pFontListItem )
51         {
52             const FontList*	pNewFontList = pFontListItem->GetFontList();
53             DBG_ASSERT( pNewFontList, "Doc-FontList not available!" );
54 
55             if ( !*ppFontList )
56             {
57                 *ppFontList = pNewFontList;
58                 bChanged = true;
59             }
60             else
61             {
62                 bChanged = ( *ppFontList != pNewFontList );
63                 if( !bChanged && pBox!=NULL )
64                     bChanged = ( pBox->GetListCount() != pNewFontList->GetFontNameCount() );
65                 HACK(vergleich ist unvollstaendig)
66 
67                     if ( bChanged )
68                         *ppFontList = pNewFontList;
69             }
70 
71             if ( pBox )
72                 pBox->Enable();
73         }
74         else if ( pBox )
75             pBox->Disable();
76 
77         // in die FontBox ggf. auch die neue Liste f"ullen
78         if ( pBox && bChanged )
79         {
80             if ( *ppFontList )
81                 pBox->Fill( *ppFontList );
82             else
83                 pBox->Clear();
84         }
85         return bChanged;
86     }
87 }
88 
89 
90 
91 
SvxSBFontNameBox(Window * pParent,const ResId & rResId)92 SvxSBFontNameBox::SvxSBFontNameBox( Window* pParent,  const ResId& rResId  ) :
93 	FontNameBox	( pParent, rResId )
94 ,	pFontList	( NULL )
95 ,	nFtCount	( 0 )
96 ,	bInput(false)
97 ,	pBindings(NULL)
98 {
99     EnableControls_Impl();
100 //	StartListening( *SFX_APP() );
101 }
102 
EnableControls_Impl()103 void SvxSBFontNameBox::EnableControls_Impl()
104 {
105 	SvtFontOptions aFontOpt;
106 	bool bEnable = aFontOpt.IsFontHistoryEnabled();
107 	sal_uInt16 nEntries = bEnable ? MAX_MRU_FONTNAME_ENTRIES : 0;
108 	if ( GetMaxMRUCount() != nEntries )
109 	{
110 		// refill in the next GetFocus-Handler
111 		pFontList = NULL;
112 		Clear();
113 		SetMaxMRUCount( nEntries );
114 	}
115 
116 	bEnable = aFontOpt.IsFontWYSIWYGEnabled();
117 	EnableWYSIWYG( bEnable );
118 	EnableSymbols( bEnable );
119 }
120 
FillList()121 void SvxSBFontNameBox::FillList()
122 {
123 	Selection aOldSel = GetSelection();
124 	GetDocFontList_Impl( &pFontList, this );
125 	aCurText = GetText();
126 	SetSelection( aOldSel );
127 }
128 
PreNotify(NotifyEvent & rNEvt)129 long SvxSBFontNameBox::PreNotify( NotifyEvent& rNEvt )
130 {
131 	const sal_uInt16 nType (rNEvt.GetType());
132 
133 	if ( EVENT_MOUSEBUTTONDOWN == nType || EVENT_GETFOCUS == nType )
134 		FillList();
135     return FontNameBox::PreNotify( rNEvt );
136 }
137 //<<modify
Notify(NotifyEvent & rNEvt)138 long SvxSBFontNameBox::Notify( NotifyEvent& rNEvt) //SfxBroadcaster& rBC, const SfxHint& rHint
139 {
140 	//SfxItemSetHint* pHint = PTR_CAST(SfxItemSetHint, &rHint);
141 	//if ( pHint )
142 	//	EnableControls_Impl();
143 	bool bHandle = 0;
144 	if ( rNEvt.GetType() == EVENT_KEYINPUT )
145 	{
146 		const sal_uInt16 nCode (rNEvt.GetKeyEvent()->GetKeyCode().GetCode());
147 
148 		if( nCode == KEY_RETURN)
149 		{
150 			bHandle = 1;
151 			Select();
152 		}
153 	}
154 
155 	return bHandle ? bHandle : FontNameBox::Notify( rNEvt );
156 }
Select()157 void SvxSBFontNameBox::Select()
158 {
159 	FontNameBox::Select();
160 
161 	if ( !IsTravelSelect() )
162 	{
163 		FillList();
164 		FontInfo aInfo( pFontList->Get( GetText(),WEIGHT_NORMAL, ITALIC_NORMAL ) );//meWeight, meItalic
165 
166 		SvxFontItem aFontItem( aInfo.GetFamily(), aInfo.GetName(), aInfo.GetStyleName(),
167 			aInfo.GetPitch(), aInfo.GetCharSet(), SID_ATTR_CHAR_FONT );
168 
169 		pBindings->GetDispatcher()->Execute( SID_ATTR_CHAR_FONT, SFX_CALLMODE_RECORD, &aFontItem, 0L );
170 		pBindings->Invalidate(SID_ATTR_CHAR_FONT,true,false);
171 	}
172 }
SetBindings(SfxBindings * pB)173 void SvxSBFontNameBox::SetBindings(SfxBindings* pB)
174 {
175 	pBindings = pB;
176 }
177 
178 } } // end of namespace svx::sidebar
179