xref: /trunk/main/svx/source/dialog/fontlb.cxx (revision f6e50924)
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 #include "svx/fontlb.hxx"
27 #include <vcl/svapp.hxx>
28 
29 // ============================================================================
30 
31 DBG_NAME( SvLBoxFontString );
32 
SvLBoxFontString()33 SvLBoxFontString::SvLBoxFontString() :
34     SvLBoxString()
35 {
36     DBG_CTOR( SvLBoxFontString, 0 );
37 }
38 
SvLBoxFontString(SvLBoxEntry * pEntry,sal_uInt16 nFlags,const XubString & rString,const Font & rFont,const Color * pColor)39 SvLBoxFontString::SvLBoxFontString(
40         SvLBoxEntry* pEntry, sal_uInt16 nFlags, const XubString& rString,
41         const Font& rFont, const Color* pColor ) :
42     SvLBoxString( pEntry, nFlags, rString ),
43     maFont( rFont ),
44     mbUseColor( pColor != NULL )
45 {
46     DBG_CTOR( SvLBoxFontString, 0 );
47     SetText( pEntry, rString );
48     if( pColor )
49         maFont.SetColor( *pColor );
50 }
51 
~SvLBoxFontString()52 SvLBoxFontString::~SvLBoxFontString()
53 {
54     DBG_DTOR( SvLBoxFontString, 0 );
55 }
56 
57 
Create() const58 SvLBoxItem* SvLBoxFontString::Create() const
59 {
60     DBG_CHKTHIS( SvLBoxFontString, 0 );
61     return new SvLBoxFontString;
62 }
63 
Paint(const Point & rPos,SvLBox & rDev,sal_uInt16 nFlags,SvLBoxEntry * pEntry)64 void SvLBoxFontString::Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags, SvLBoxEntry* pEntry )
65 {
66     DBG_CHKTHIS( SvLBoxFontString, 0 );
67     Font aOldFont( rDev.GetFont() );
68     Font aNewFont( maFont );
69     bool bSel = (nFlags & SVLISTENTRYFLAG_SELECTED) != 0;
70 //  if( !mbUseColor )               // selection gets font color, if available
71     if( !mbUseColor || bSel )       // selection always gets highlight color
72     {
73         const StyleSettings& rSett = Application::GetSettings().GetStyleSettings();
74         aNewFont.SetColor( bSel ? rSett.GetHighlightTextColor() : rSett.GetFieldTextColor() );
75     }
76 
77     rDev.SetFont( aNewFont );
78     SvLBoxString::Paint( rPos, rDev, nFlags, pEntry );
79     rDev.SetFont( aOldFont );
80 }
81 
InitViewData(SvLBox * pView,SvLBoxEntry * pEntry,SvViewDataItem * pViewData)82 void SvLBoxFontString::InitViewData( SvLBox* pView, SvLBoxEntry* pEntry, SvViewDataItem* pViewData )
83 {
84     DBG_CHKTHIS( SvLBoxFontString, 0 );
85     Font aOldFont( pView->GetFont() );
86     pView->SetFont( maFont );
87     SvLBoxString::InitViewData( pView, pEntry, pViewData);
88     pView->SetFont( aOldFont );
89 }
90 
91 
92 // ============================================================================
93 
SvxFontListBox(Window * pParent,const ResId & rResId)94 SvxFontListBox::SvxFontListBox( Window* pParent, const ResId& rResId ) :
95     SvTabListBox( pParent, rResId ),
96     maStdFont( GetFont() ),
97     mbUseFont( false )
98 {
99     maStdFont.SetTransparent( sal_True );
100     maEntryFont = maStdFont;
101 }
102 
InsertFontEntry(const String & rString,const Font & rFont,const Color * pColor)103 void SvxFontListBox::InsertFontEntry( const String& rString, const Font& rFont, const Color* pColor )
104 {
105     mbUseFont = true;           // InitEntry() will use maEntryFont
106     maEntryFont = rFont;        // font to use in InitEntry() over InsertEntry()
107     mpEntryColor = pColor;      // color to use in InitEntry() over InsertEntry()
108     InsertEntry( rString );
109     mbUseFont = false;
110 }
111 
SelectEntryPos(sal_uInt16 nPos,bool bSelect)112 void SvxFontListBox::SelectEntryPos( sal_uInt16 nPos, bool bSelect )
113 {
114     SvLBoxEntry* pEntry = GetEntry( nPos );
115     if( pEntry )
116     {
117         Select( pEntry, bSelect );
118         ShowEntry( pEntry );
119     }
120 }
121 
SetNoSelection()122 void SvxFontListBox::SetNoSelection()
123 {
124     SelectAll( sal_False, sal_True );
125 }
126 
GetSelectEntryPos() const127 sal_uLong SvxFontListBox::GetSelectEntryPos() const
128 {
129     SvLBoxEntry* pSvLBoxEntry = FirstSelected();
130     return pSvLBoxEntry ? GetModel()->GetAbsPos( pSvLBoxEntry ) : LIST_APPEND;
131 }
132 
GetSelectEntry() const133 XubString SvxFontListBox::GetSelectEntry() const
134 {
135     return GetEntryText( GetSelectEntryPos() );
136 }
137 
InitEntry(SvLBoxEntry * pEntry,const XubString & rEntryText,const Image & rCollImg,const Image & rExpImg,SvLBoxButtonKind eButtonKind)138 void SvxFontListBox::InitEntry(
139         SvLBoxEntry* pEntry, const XubString& rEntryText,
140         const Image& rCollImg, const Image& rExpImg,
141         SvLBoxButtonKind eButtonKind )
142 {
143     if( mbUseFont )
144     {
145         if( nTreeFlags & TREEFLAG_CHKBTN )
146             pEntry->AddItem( new SvLBoxButton( pEntry, eButtonKind, 0,
147                                                pCheckButtonData ) );
148         pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, rCollImg, rExpImg, SVLISTENTRYFLAG_EXPANDED ) );
149         pEntry->AddItem( new SvLBoxFontString( pEntry, 0, rEntryText, maEntryFont, mpEntryColor ) );
150     }
151     else
152         SvTreeListBox::InitEntry( pEntry, rEntryText, rCollImg, rExpImg,
153                                   eButtonKind );
154 }
155 
156 #if ENABLE_LAYOUT
157 
158 namespace layout
159 {
160 
~SvxFontListBox()161 SvxFontListBox::~SvxFontListBox ()
162 {
163 }
164 
InsertFontEntry(String const & entry,Font const &,Color const *)165 sal_uInt16 SvxFontListBox::InsertFontEntry (String const& entry, Font const&, Color const*)
166 {
167     return InsertEntry (entry);
168 }
169 
SvxFontListBox(Context * pParent,const char * pFile)170 SvxFontListBox::SvxFontListBox( Context* pParent, const char* pFile)
171 : ListBox( pParent, pFile )
172 {
173 }
174 
175 /*IMPL_IMPL (SvxFontListBox, ListBox);
176 IMPL_CONSTRUCTORS (SvxFontListBox, ListBox, "svxfontlistbox");
177 IMPL_GET_IMPL (SvxFontListBox);
178 IMPL_GET_WINDOW (SvxFontListBox);*/
179 
180 };
181 
182 #endif
183 
184 // ============================================================================
185 
186