xref: /aoo41x/main/svx/source/dialog/fontlb.cxx (revision f6e50924)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f6e50924SAndrew Rist  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19*f6e50924SAndrew Rist  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir #include "svx/fontlb.hxx"
27cdf0e10cSrcweir #include <vcl/svapp.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir // ============================================================================
30cdf0e10cSrcweir 
31cdf0e10cSrcweir DBG_NAME( SvLBoxFontString );
32cdf0e10cSrcweir 
SvLBoxFontString()33cdf0e10cSrcweir SvLBoxFontString::SvLBoxFontString() :
34cdf0e10cSrcweir     SvLBoxString()
35cdf0e10cSrcweir {
36cdf0e10cSrcweir     DBG_CTOR( SvLBoxFontString, 0 );
37cdf0e10cSrcweir }
38cdf0e10cSrcweir 
SvLBoxFontString(SvLBoxEntry * pEntry,sal_uInt16 nFlags,const XubString & rString,const Font & rFont,const Color * pColor)39cdf0e10cSrcweir SvLBoxFontString::SvLBoxFontString(
40cdf0e10cSrcweir         SvLBoxEntry* pEntry, sal_uInt16 nFlags, const XubString& rString,
41cdf0e10cSrcweir         const Font& rFont, const Color* pColor ) :
42cdf0e10cSrcweir     SvLBoxString( pEntry, nFlags, rString ),
43cdf0e10cSrcweir     maFont( rFont ),
44cdf0e10cSrcweir     mbUseColor( pColor != NULL )
45cdf0e10cSrcweir {
46cdf0e10cSrcweir     DBG_CTOR( SvLBoxFontString, 0 );
47cdf0e10cSrcweir     SetText( pEntry, rString );
48cdf0e10cSrcweir     if( pColor )
49cdf0e10cSrcweir         maFont.SetColor( *pColor );
50cdf0e10cSrcweir }
51cdf0e10cSrcweir 
~SvLBoxFontString()52cdf0e10cSrcweir SvLBoxFontString::~SvLBoxFontString()
53cdf0e10cSrcweir {
54cdf0e10cSrcweir     DBG_DTOR( SvLBoxFontString, 0 );
55cdf0e10cSrcweir }
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 
Create() const58cdf0e10cSrcweir SvLBoxItem* SvLBoxFontString::Create() const
59cdf0e10cSrcweir {
60cdf0e10cSrcweir     DBG_CHKTHIS( SvLBoxFontString, 0 );
61cdf0e10cSrcweir     return new SvLBoxFontString;
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
Paint(const Point & rPos,SvLBox & rDev,sal_uInt16 nFlags,SvLBoxEntry * pEntry)64cdf0e10cSrcweir void SvLBoxFontString::Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags, SvLBoxEntry* pEntry )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir     DBG_CHKTHIS( SvLBoxFontString, 0 );
67cdf0e10cSrcweir     Font aOldFont( rDev.GetFont() );
68cdf0e10cSrcweir     Font aNewFont( maFont );
69cdf0e10cSrcweir     bool bSel = (nFlags & SVLISTENTRYFLAG_SELECTED) != 0;
70cdf0e10cSrcweir //  if( !mbUseColor )               // selection gets font color, if available
71cdf0e10cSrcweir     if( !mbUseColor || bSel )       // selection always gets highlight color
72cdf0e10cSrcweir     {
73cdf0e10cSrcweir         const StyleSettings& rSett = Application::GetSettings().GetStyleSettings();
74cdf0e10cSrcweir         aNewFont.SetColor( bSel ? rSett.GetHighlightTextColor() : rSett.GetFieldTextColor() );
75cdf0e10cSrcweir     }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     rDev.SetFont( aNewFont );
78cdf0e10cSrcweir     SvLBoxString::Paint( rPos, rDev, nFlags, pEntry );
79cdf0e10cSrcweir     rDev.SetFont( aOldFont );
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
InitViewData(SvLBox * pView,SvLBoxEntry * pEntry,SvViewDataItem * pViewData)82cdf0e10cSrcweir void SvLBoxFontString::InitViewData( SvLBox* pView, SvLBoxEntry* pEntry, SvViewDataItem* pViewData )
83cdf0e10cSrcweir {
84cdf0e10cSrcweir     DBG_CHKTHIS( SvLBoxFontString, 0 );
85cdf0e10cSrcweir     Font aOldFont( pView->GetFont() );
86cdf0e10cSrcweir     pView->SetFont( maFont );
87cdf0e10cSrcweir     SvLBoxString::InitViewData( pView, pEntry, pViewData);
88cdf0e10cSrcweir     pView->SetFont( aOldFont );
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 
92cdf0e10cSrcweir // ============================================================================
93cdf0e10cSrcweir 
SvxFontListBox(Window * pParent,const ResId & rResId)94cdf0e10cSrcweir SvxFontListBox::SvxFontListBox( Window* pParent, const ResId& rResId ) :
95cdf0e10cSrcweir     SvTabListBox( pParent, rResId ),
96cdf0e10cSrcweir     maStdFont( GetFont() ),
97cdf0e10cSrcweir     mbUseFont( false )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir     maStdFont.SetTransparent( sal_True );
100cdf0e10cSrcweir     maEntryFont = maStdFont;
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
InsertFontEntry(const String & rString,const Font & rFont,const Color * pColor)103cdf0e10cSrcweir void SvxFontListBox::InsertFontEntry( const String& rString, const Font& rFont, const Color* pColor )
104cdf0e10cSrcweir {
105cdf0e10cSrcweir     mbUseFont = true;           // InitEntry() will use maEntryFont
106cdf0e10cSrcweir     maEntryFont = rFont;        // font to use in InitEntry() over InsertEntry()
107cdf0e10cSrcweir     mpEntryColor = pColor;      // color to use in InitEntry() over InsertEntry()
108cdf0e10cSrcweir     InsertEntry( rString );
109cdf0e10cSrcweir     mbUseFont = false;
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
SelectEntryPos(sal_uInt16 nPos,bool bSelect)112cdf0e10cSrcweir void SvxFontListBox::SelectEntryPos( sal_uInt16 nPos, bool bSelect )
113cdf0e10cSrcweir {
114cdf0e10cSrcweir     SvLBoxEntry* pEntry = GetEntry( nPos );
115cdf0e10cSrcweir     if( pEntry )
116cdf0e10cSrcweir     {
117cdf0e10cSrcweir         Select( pEntry, bSelect );
118cdf0e10cSrcweir         ShowEntry( pEntry );
119cdf0e10cSrcweir     }
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
SetNoSelection()122cdf0e10cSrcweir void SvxFontListBox::SetNoSelection()
123cdf0e10cSrcweir {
124cdf0e10cSrcweir     SelectAll( sal_False, sal_True );
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
GetSelectEntryPos() const127cdf0e10cSrcweir sal_uLong SvxFontListBox::GetSelectEntryPos() const
128cdf0e10cSrcweir {
129cdf0e10cSrcweir     SvLBoxEntry* pSvLBoxEntry = FirstSelected();
130cdf0e10cSrcweir     return pSvLBoxEntry ? GetModel()->GetAbsPos( pSvLBoxEntry ) : LIST_APPEND;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
GetSelectEntry() const133cdf0e10cSrcweir XubString SvxFontListBox::GetSelectEntry() const
134cdf0e10cSrcweir {
135cdf0e10cSrcweir     return GetEntryText( GetSelectEntryPos() );
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
InitEntry(SvLBoxEntry * pEntry,const XubString & rEntryText,const Image & rCollImg,const Image & rExpImg,SvLBoxButtonKind eButtonKind)138cdf0e10cSrcweir void SvxFontListBox::InitEntry(
139cdf0e10cSrcweir         SvLBoxEntry* pEntry, const XubString& rEntryText,
140cdf0e10cSrcweir         const Image& rCollImg, const Image& rExpImg,
141cdf0e10cSrcweir         SvLBoxButtonKind eButtonKind )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir     if( mbUseFont )
144cdf0e10cSrcweir     {
145cdf0e10cSrcweir         if( nTreeFlags & TREEFLAG_CHKBTN )
146cdf0e10cSrcweir             pEntry->AddItem( new SvLBoxButton( pEntry, eButtonKind, 0,
147cdf0e10cSrcweir                                                pCheckButtonData ) );
148cdf0e10cSrcweir         pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, rCollImg, rExpImg, SVLISTENTRYFLAG_EXPANDED ) );
149cdf0e10cSrcweir         pEntry->AddItem( new SvLBoxFontString( pEntry, 0, rEntryText, maEntryFont, mpEntryColor ) );
150cdf0e10cSrcweir     }
151cdf0e10cSrcweir     else
152cdf0e10cSrcweir         SvTreeListBox::InitEntry( pEntry, rEntryText, rCollImg, rExpImg,
153cdf0e10cSrcweir                                   eButtonKind );
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir #if ENABLE_LAYOUT
157cdf0e10cSrcweir 
158cdf0e10cSrcweir namespace layout
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 
~SvxFontListBox()161cdf0e10cSrcweir SvxFontListBox::~SvxFontListBox ()
162cdf0e10cSrcweir {
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
InsertFontEntry(String const & entry,Font const &,Color const *)165cdf0e10cSrcweir sal_uInt16 SvxFontListBox::InsertFontEntry (String const& entry, Font const&, Color const*)
166cdf0e10cSrcweir {
167cdf0e10cSrcweir     return InsertEntry (entry);
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
SvxFontListBox(Context * pParent,const char * pFile)170cdf0e10cSrcweir SvxFontListBox::SvxFontListBox( Context* pParent, const char* pFile)
171cdf0e10cSrcweir : ListBox( pParent, pFile )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir /*IMPL_IMPL (SvxFontListBox, ListBox);
176cdf0e10cSrcweir IMPL_CONSTRUCTORS (SvxFontListBox, ListBox, "svxfontlistbox");
177cdf0e10cSrcweir IMPL_GET_IMPL (SvxFontListBox);
178cdf0e10cSrcweir IMPL_GET_WINDOW (SvxFontListBox);*/
179cdf0e10cSrcweir 
180cdf0e10cSrcweir };
181cdf0e10cSrcweir 
182cdf0e10cSrcweir #endif
183cdf0e10cSrcweir 
184cdf0e10cSrcweir // ============================================================================
185cdf0e10cSrcweir 
186