xref: /aoo42x/main/svx/source/dialog/fontlb.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 #include "svx/fontlb.hxx"
31 #include <vcl/svapp.hxx>
32 
33 // ============================================================================
34 
35 DBG_NAME( SvLBoxFontString );
36 
37 SvLBoxFontString::SvLBoxFontString() :
38     SvLBoxString()
39 {
40     DBG_CTOR( SvLBoxFontString, 0 );
41 }
42 
43 SvLBoxFontString::SvLBoxFontString(
44         SvLBoxEntry* pEntry, sal_uInt16 nFlags, const XubString& rString,
45         const Font& rFont, const Color* pColor ) :
46     SvLBoxString( pEntry, nFlags, rString ),
47     maFont( rFont ),
48     mbUseColor( pColor != NULL )
49 {
50     DBG_CTOR( SvLBoxFontString, 0 );
51     SetText( pEntry, rString );
52     if( pColor )
53         maFont.SetColor( *pColor );
54 }
55 
56 SvLBoxFontString::~SvLBoxFontString()
57 {
58     DBG_DTOR( SvLBoxFontString, 0 );
59 }
60 
61 
62 SvLBoxItem* SvLBoxFontString::Create() const
63 {
64     DBG_CHKTHIS( SvLBoxFontString, 0 );
65     return new SvLBoxFontString;
66 }
67 
68 void SvLBoxFontString::Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags, SvLBoxEntry* pEntry )
69 {
70     DBG_CHKTHIS( SvLBoxFontString, 0 );
71     Font aOldFont( rDev.GetFont() );
72     Font aNewFont( maFont );
73     bool bSel = (nFlags & SVLISTENTRYFLAG_SELECTED) != 0;
74 //  if( !mbUseColor )               // selection gets font color, if available
75     if( !mbUseColor || bSel )       // selection always gets highlight color
76     {
77         const StyleSettings& rSett = Application::GetSettings().GetStyleSettings();
78         aNewFont.SetColor( bSel ? rSett.GetHighlightTextColor() : rSett.GetFieldTextColor() );
79     }
80 
81     rDev.SetFont( aNewFont );
82     SvLBoxString::Paint( rPos, rDev, nFlags, pEntry );
83     rDev.SetFont( aOldFont );
84 }
85 
86 void SvLBoxFontString::InitViewData( SvLBox* pView, SvLBoxEntry* pEntry, SvViewDataItem* pViewData )
87 {
88     DBG_CHKTHIS( SvLBoxFontString, 0 );
89     Font aOldFont( pView->GetFont() );
90     pView->SetFont( maFont );
91     SvLBoxString::InitViewData( pView, pEntry, pViewData);
92     pView->SetFont( aOldFont );
93 }
94 
95 
96 // ============================================================================
97 
98 SvxFontListBox::SvxFontListBox( Window* pParent, const ResId& rResId ) :
99     SvTabListBox( pParent, rResId ),
100     maStdFont( GetFont() ),
101     mbUseFont( false )
102 {
103     maStdFont.SetTransparent( sal_True );
104     maEntryFont = maStdFont;
105 }
106 
107 void SvxFontListBox::InsertFontEntry( const String& rString, const Font& rFont, const Color* pColor )
108 {
109     mbUseFont = true;           // InitEntry() will use maEntryFont
110     maEntryFont = rFont;        // font to use in InitEntry() over InsertEntry()
111     mpEntryColor = pColor;      // color to use in InitEntry() over InsertEntry()
112     InsertEntry( rString );
113     mbUseFont = false;
114 }
115 
116 void SvxFontListBox::SelectEntryPos( sal_uInt16 nPos, bool bSelect )
117 {
118     SvLBoxEntry* pEntry = GetEntry( nPos );
119     if( pEntry )
120     {
121         Select( pEntry, bSelect );
122         ShowEntry( pEntry );
123     }
124 }
125 
126 void SvxFontListBox::SetNoSelection()
127 {
128     SelectAll( sal_False, sal_True );
129 }
130 
131 sal_uLong SvxFontListBox::GetSelectEntryPos() const
132 {
133     SvLBoxEntry* pSvLBoxEntry = FirstSelected();
134     return pSvLBoxEntry ? GetModel()->GetAbsPos( pSvLBoxEntry ) : LIST_APPEND;
135 }
136 
137 XubString SvxFontListBox::GetSelectEntry() const
138 {
139     return GetEntryText( GetSelectEntryPos() );
140 }
141 
142 void SvxFontListBox::InitEntry(
143         SvLBoxEntry* pEntry, const XubString& rEntryText,
144         const Image& rCollImg, const Image& rExpImg,
145         SvLBoxButtonKind eButtonKind )
146 {
147     if( mbUseFont )
148     {
149         if( nTreeFlags & TREEFLAG_CHKBTN )
150             pEntry->AddItem( new SvLBoxButton( pEntry, eButtonKind, 0,
151                                                pCheckButtonData ) );
152         pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, rCollImg, rExpImg, SVLISTENTRYFLAG_EXPANDED ) );
153         pEntry->AddItem( new SvLBoxFontString( pEntry, 0, rEntryText, maEntryFont, mpEntryColor ) );
154     }
155     else
156         SvTreeListBox::InitEntry( pEntry, rEntryText, rCollImg, rExpImg,
157                                   eButtonKind );
158 }
159 
160 #if ENABLE_LAYOUT
161 
162 namespace layout
163 {
164 
165 SvxFontListBox::~SvxFontListBox ()
166 {
167 }
168 
169 sal_uInt16 SvxFontListBox::InsertFontEntry (String const& entry, Font const&, Color const*)
170 {
171     return InsertEntry (entry);
172 }
173 
174 SvxFontListBox::SvxFontListBox( Context* pParent, const char* pFile)
175 : ListBox( pParent, pFile )
176 {
177 }
178 
179 /*IMPL_IMPL (SvxFontListBox, ListBox);
180 IMPL_CONSTRUCTORS (SvxFontListBox, ListBox, "svxfontlistbox");
181 IMPL_GET_IMPL (SvxFontListBox);
182 IMPL_GET_WINDOW (SvxFontListBox);*/
183 
184 };
185 
186 #endif
187 
188 // ============================================================================
189 
190