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