1*b9e67834SAndre Fischer /**************************************************************
2*b9e67834SAndre Fischer *
3*b9e67834SAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one
4*b9e67834SAndre Fischer * or more contributor license agreements. See the NOTICE file
5*b9e67834SAndre Fischer * distributed with this work for additional information
6*b9e67834SAndre Fischer * regarding copyright ownership. The ASF licenses this file
7*b9e67834SAndre Fischer * to you under the Apache License, Version 2.0 (the
8*b9e67834SAndre Fischer * "License"); you may not use this file except in compliance
9*b9e67834SAndre Fischer * with the License. You may obtain a copy of the License at
10*b9e67834SAndre Fischer *
11*b9e67834SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0
12*b9e67834SAndre Fischer *
13*b9e67834SAndre Fischer * Unless required by applicable law or agreed to in writing,
14*b9e67834SAndre Fischer * software distributed under the License is distributed on an
15*b9e67834SAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b9e67834SAndre Fischer * KIND, either express or implied. See the License for the
17*b9e67834SAndre Fischer * specific language governing permissions and limitations
18*b9e67834SAndre Fischer * under the License.
19*b9e67834SAndre Fischer *
20*b9e67834SAndre Fischer *************************************************************/
21*b9e67834SAndre Fischer
22*b9e67834SAndre Fischer #include "precompiled_svx.hxx"
23*b9e67834SAndre Fischer
24*b9e67834SAndre Fischer #include "SvxSBFontNameBox.hxx"
25*b9e67834SAndre Fischer
26*b9e67834SAndre Fischer #include <unotools/fontoptions.hxx>
27*b9e67834SAndre Fischer #include <sfx2/objsh.hxx>
28*b9e67834SAndre Fischer #include <sfx2/dispatch.hxx>
29*b9e67834SAndre Fischer #include <editeng/flstitem.hxx>
30*b9e67834SAndre Fischer #include <editeng/editids.hrc>
31*b9e67834SAndre Fischer #include <editeng/fontitem.hxx>
32*b9e67834SAndre Fischer
33*b9e67834SAndre Fischer
34*b9e67834SAndre Fischer const static sal_uInt16 MAX_MRU_FONTNAME_ENTRIES = 5;
35*b9e67834SAndre Fischer
36*b9e67834SAndre Fischer
37*b9e67834SAndre Fischer namespace svx { namespace sidebar {
38*b9e67834SAndre Fischer
39*b9e67834SAndre Fischer namespace {
GetDocFontList_Impl(const FontList ** ppFontList,SvxSBFontNameBox * pBox)40*b9e67834SAndre Fischer bool GetDocFontList_Impl( const FontList** ppFontList, SvxSBFontNameBox* pBox )
41*b9e67834SAndre Fischer {
42*b9e67834SAndre Fischer bool bChanged = false;
43*b9e67834SAndre Fischer const SfxObjectShell* pDocSh = SfxObjectShell::Current();
44*b9e67834SAndre Fischer SvxFontListItem* pFontListItem = NULL;
45*b9e67834SAndre Fischer
46*b9e67834SAndre Fischer if ( pDocSh )
47*b9e67834SAndre Fischer pFontListItem =
48*b9e67834SAndre Fischer (SvxFontListItem*)pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST );
49*b9e67834SAndre Fischer
50*b9e67834SAndre Fischer if ( pFontListItem )
51*b9e67834SAndre Fischer {
52*b9e67834SAndre Fischer const FontList* pNewFontList = pFontListItem->GetFontList();
53*b9e67834SAndre Fischer DBG_ASSERT( pNewFontList, "Doc-FontList not available!" );
54*b9e67834SAndre Fischer
55*b9e67834SAndre Fischer if ( !*ppFontList )
56*b9e67834SAndre Fischer {
57*b9e67834SAndre Fischer *ppFontList = pNewFontList;
58*b9e67834SAndre Fischer bChanged = true;
59*b9e67834SAndre Fischer }
60*b9e67834SAndre Fischer else
61*b9e67834SAndre Fischer {
62*b9e67834SAndre Fischer bChanged = ( *ppFontList != pNewFontList );
63*b9e67834SAndre Fischer if( !bChanged && pBox!=NULL )
64*b9e67834SAndre Fischer bChanged = ( pBox->GetListCount() != pNewFontList->GetFontNameCount() );
65*b9e67834SAndre Fischer HACK(vergleich ist unvollstaendig)
66*b9e67834SAndre Fischer
67*b9e67834SAndre Fischer if ( bChanged )
68*b9e67834SAndre Fischer *ppFontList = pNewFontList;
69*b9e67834SAndre Fischer }
70*b9e67834SAndre Fischer
71*b9e67834SAndre Fischer if ( pBox )
72*b9e67834SAndre Fischer pBox->Enable();
73*b9e67834SAndre Fischer }
74*b9e67834SAndre Fischer else if ( pBox )
75*b9e67834SAndre Fischer pBox->Disable();
76*b9e67834SAndre Fischer
77*b9e67834SAndre Fischer // in die FontBox ggf. auch die neue Liste f"ullen
78*b9e67834SAndre Fischer if ( pBox && bChanged )
79*b9e67834SAndre Fischer {
80*b9e67834SAndre Fischer if ( *ppFontList )
81*b9e67834SAndre Fischer pBox->Fill( *ppFontList );
82*b9e67834SAndre Fischer else
83*b9e67834SAndre Fischer pBox->Clear();
84*b9e67834SAndre Fischer }
85*b9e67834SAndre Fischer return bChanged;
86*b9e67834SAndre Fischer }
87*b9e67834SAndre Fischer }
88*b9e67834SAndre Fischer
89*b9e67834SAndre Fischer
90*b9e67834SAndre Fischer
91*b9e67834SAndre Fischer
SvxSBFontNameBox(Window * pParent,const ResId & rResId)92*b9e67834SAndre Fischer SvxSBFontNameBox::SvxSBFontNameBox( Window* pParent, const ResId& rResId ) :
93*b9e67834SAndre Fischer FontNameBox ( pParent, rResId )
94*b9e67834SAndre Fischer , pFontList ( NULL )
95*b9e67834SAndre Fischer , nFtCount ( 0 )
96*b9e67834SAndre Fischer , bInput(false)
97*b9e67834SAndre Fischer , pBindings(NULL)
98*b9e67834SAndre Fischer {
99*b9e67834SAndre Fischer EnableControls_Impl();
100*b9e67834SAndre Fischer // StartListening( *SFX_APP() );
101*b9e67834SAndre Fischer }
102*b9e67834SAndre Fischer
EnableControls_Impl()103*b9e67834SAndre Fischer void SvxSBFontNameBox::EnableControls_Impl()
104*b9e67834SAndre Fischer {
105*b9e67834SAndre Fischer SvtFontOptions aFontOpt;
106*b9e67834SAndre Fischer bool bEnable = aFontOpt.IsFontHistoryEnabled();
107*b9e67834SAndre Fischer sal_uInt16 nEntries = bEnable ? MAX_MRU_FONTNAME_ENTRIES : 0;
108*b9e67834SAndre Fischer if ( GetMaxMRUCount() != nEntries )
109*b9e67834SAndre Fischer {
110*b9e67834SAndre Fischer // refill in the next GetFocus-Handler
111*b9e67834SAndre Fischer pFontList = NULL;
112*b9e67834SAndre Fischer Clear();
113*b9e67834SAndre Fischer SetMaxMRUCount( nEntries );
114*b9e67834SAndre Fischer }
115*b9e67834SAndre Fischer
116*b9e67834SAndre Fischer bEnable = aFontOpt.IsFontWYSIWYGEnabled();
117*b9e67834SAndre Fischer EnableWYSIWYG( bEnable );
118*b9e67834SAndre Fischer EnableSymbols( bEnable );
119*b9e67834SAndre Fischer }
120*b9e67834SAndre Fischer
FillList()121*b9e67834SAndre Fischer void SvxSBFontNameBox::FillList()
122*b9e67834SAndre Fischer {
123*b9e67834SAndre Fischer Selection aOldSel = GetSelection();
124*b9e67834SAndre Fischer GetDocFontList_Impl( &pFontList, this );
125*b9e67834SAndre Fischer aCurText = GetText();
126*b9e67834SAndre Fischer SetSelection( aOldSel );
127*b9e67834SAndre Fischer }
128*b9e67834SAndre Fischer
PreNotify(NotifyEvent & rNEvt)129*b9e67834SAndre Fischer long SvxSBFontNameBox::PreNotify( NotifyEvent& rNEvt )
130*b9e67834SAndre Fischer {
131*b9e67834SAndre Fischer const sal_uInt16 nType (rNEvt.GetType());
132*b9e67834SAndre Fischer
133*b9e67834SAndre Fischer if ( EVENT_MOUSEBUTTONDOWN == nType || EVENT_GETFOCUS == nType )
134*b9e67834SAndre Fischer FillList();
135*b9e67834SAndre Fischer return FontNameBox::PreNotify( rNEvt );
136*b9e67834SAndre Fischer }
137*b9e67834SAndre Fischer //<<modify
Notify(NotifyEvent & rNEvt)138*b9e67834SAndre Fischer long SvxSBFontNameBox::Notify( NotifyEvent& rNEvt) //SfxBroadcaster& rBC, const SfxHint& rHint
139*b9e67834SAndre Fischer {
140*b9e67834SAndre Fischer //SfxItemSetHint* pHint = PTR_CAST(SfxItemSetHint, &rHint);
141*b9e67834SAndre Fischer //if ( pHint )
142*b9e67834SAndre Fischer // EnableControls_Impl();
143*b9e67834SAndre Fischer bool bHandle = 0;
144*b9e67834SAndre Fischer if ( rNEvt.GetType() == EVENT_KEYINPUT )
145*b9e67834SAndre Fischer {
146*b9e67834SAndre Fischer const sal_uInt16 nCode (rNEvt.GetKeyEvent()->GetKeyCode().GetCode());
147*b9e67834SAndre Fischer
148*b9e67834SAndre Fischer if( nCode == KEY_RETURN)
149*b9e67834SAndre Fischer {
150*b9e67834SAndre Fischer bHandle = 1;
151*b9e67834SAndre Fischer Select();
152*b9e67834SAndre Fischer }
153*b9e67834SAndre Fischer }
154*b9e67834SAndre Fischer
155*b9e67834SAndre Fischer return bHandle ? bHandle : FontNameBox::Notify( rNEvt );
156*b9e67834SAndre Fischer }
Select()157*b9e67834SAndre Fischer void SvxSBFontNameBox::Select()
158*b9e67834SAndre Fischer {
159*b9e67834SAndre Fischer FontNameBox::Select();
160*b9e67834SAndre Fischer
161*b9e67834SAndre Fischer if ( !IsTravelSelect() )
162*b9e67834SAndre Fischer {
163*b9e67834SAndre Fischer FillList();
164*b9e67834SAndre Fischer FontInfo aInfo( pFontList->Get( GetText(),WEIGHT_NORMAL, ITALIC_NORMAL ) );//meWeight, meItalic
165*b9e67834SAndre Fischer
166*b9e67834SAndre Fischer SvxFontItem aFontItem( aInfo.GetFamily(), aInfo.GetName(), aInfo.GetStyleName(),
167*b9e67834SAndre Fischer aInfo.GetPitch(), aInfo.GetCharSet(), SID_ATTR_CHAR_FONT );
168*b9e67834SAndre Fischer
169*b9e67834SAndre Fischer pBindings->GetDispatcher()->Execute( SID_ATTR_CHAR_FONT, SFX_CALLMODE_RECORD, &aFontItem, 0L );
170*b9e67834SAndre Fischer pBindings->Invalidate(SID_ATTR_CHAR_FONT,true,false);
171*b9e67834SAndre Fischer }
172*b9e67834SAndre Fischer }
SetBindings(SfxBindings * pB)173*b9e67834SAndre Fischer void SvxSBFontNameBox::SetBindings(SfxBindings* pB)
174*b9e67834SAndre Fischer {
175*b9e67834SAndre Fischer pBindings = pB;
176*b9e67834SAndre Fischer }
177*b9e67834SAndre Fischer
178*b9e67834SAndre Fischer } } // end of namespace svx::sidebar
179