merge the formfield patch from ooo-build
[ooovba.git] / svx / source / dialog / fontlb.cxx
blob13580806002123a39c70d3645b5a4aebeb3fba19
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fontlb.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include "fontlb.hxx"
34 #include <vcl/svapp.hxx>
36 // ============================================================================
38 DBG_NAME( SvLBoxFontString );
40 SvLBoxFontString::SvLBoxFontString() :
41 SvLBoxString()
43 DBG_CTOR( SvLBoxFontString, 0 );
46 SvLBoxFontString::SvLBoxFontString(
47 SvLBoxEntry* pEntry, sal_uInt16 nFlags, const XubString& rString,
48 const Font& rFont, const Color* pColor ) :
49 SvLBoxString( pEntry, nFlags, rString ),
50 maFont( rFont ),
51 mbUseColor( pColor != NULL )
53 DBG_CTOR( SvLBoxFontString, 0 );
54 SetText( pEntry, rString );
55 if( pColor )
56 maFont.SetColor( *pColor );
59 SvLBoxFontString::~SvLBoxFontString()
61 DBG_DTOR( SvLBoxFontString, 0 );
65 SvLBoxItem* SvLBoxFontString::Create() const
67 DBG_CHKTHIS( SvLBoxFontString, 0 );
68 return new SvLBoxFontString;
71 void SvLBoxFontString::Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags, SvLBoxEntry* pEntry )
73 DBG_CHKTHIS( SvLBoxFontString, 0 );
74 Font aOldFont( rDev.GetFont() );
75 Font aNewFont( maFont );
76 bool bSel = (nFlags & SVLISTENTRYFLAG_SELECTED) != 0;
77 // if( !mbUseColor ) // selection gets font color, if available
78 if( !mbUseColor || bSel ) // selection always gets highlight color
80 const StyleSettings& rSett = Application::GetSettings().GetStyleSettings();
81 aNewFont.SetColor( bSel ? rSett.GetHighlightTextColor() : rSett.GetFieldTextColor() );
84 rDev.SetFont( aNewFont );
85 SvLBoxString::Paint( rPos, rDev, nFlags, pEntry );
86 rDev.SetFont( aOldFont );
89 void SvLBoxFontString::InitViewData( SvLBox* pView, SvLBoxEntry* pEntry, SvViewDataItem* pViewData )
91 DBG_CHKTHIS( SvLBoxFontString, 0 );
92 Font aOldFont( pView->GetFont() );
93 pView->SetFont( maFont );
94 SvLBoxString::InitViewData( pView, pEntry, pViewData);
95 pView->SetFont( aOldFont );
99 // ============================================================================
101 SvxFontListBox::SvxFontListBox( Window* pParent, const ResId& rResId ) :
102 SvTabListBox( pParent, rResId ),
103 maStdFont( GetFont() ),
104 mbUseFont( false )
106 maStdFont.SetTransparent( TRUE );
107 maEntryFont = maStdFont;
110 void SvxFontListBox::InsertFontEntry( const String& rString, const Font& rFont, const Color* pColor )
112 mbUseFont = true; // InitEntry() will use maEntryFont
113 maEntryFont = rFont; // font to use in InitEntry() over InsertEntry()
114 mpEntryColor = pColor; // color to use in InitEntry() over InsertEntry()
115 InsertEntry( rString );
116 mbUseFont = false;
119 void SvxFontListBox::SelectEntryPos( sal_uInt16 nPos, bool bSelect )
121 SvLBoxEntry* pEntry = GetEntry( nPos );
122 if( pEntry )
124 Select( pEntry, bSelect );
125 ShowEntry( pEntry );
129 void SvxFontListBox::SetNoSelection()
131 SelectAll( FALSE, TRUE );
134 ULONG SvxFontListBox::GetSelectEntryPos() const
136 SvLBoxEntry* pSvLBoxEntry = FirstSelected();
137 return pSvLBoxEntry ? GetModel()->GetAbsPos( pSvLBoxEntry ) : LIST_APPEND;
140 XubString SvxFontListBox::GetSelectEntry() const
142 return GetEntryText( GetSelectEntryPos() );
145 void SvxFontListBox::InitEntry(
146 SvLBoxEntry* pEntry, const XubString& rEntryText,
147 const Image& rCollImg, const Image& rExpImg,
148 SvLBoxButtonKind eButtonKind )
150 if( mbUseFont )
152 if( nTreeFlags & TREEFLAG_CHKBTN )
153 pEntry->AddItem( new SvLBoxButton( pEntry, eButtonKind, 0,
154 pCheckButtonData ) );
155 pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, rCollImg, rExpImg, SVLISTENTRYFLAG_EXPANDED ) );
156 pEntry->AddItem( new SvLBoxFontString( pEntry, 0, rEntryText, maEntryFont, mpEntryColor ) );
158 else
159 SvTreeListBox::InitEntry( pEntry, rEntryText, rCollImg, rExpImg,
160 eButtonKind );
163 #if ENABLE_LAYOUT
165 namespace layout
168 SvxFontListBox::~SvxFontListBox ()
172 sal_uInt16 SvxFontListBox::InsertFontEntry (String const& entry, Font const&, Color const*)
174 return InsertEntry (entry);
177 SvxFontListBox::SvxFontListBox( Context* pParent, const char* pFile)
178 : ListBox( pParent, pFile )
182 /*IMPL_IMPL (SvxFontListBox, ListBox);
183 IMPL_CONSTRUCTORS (SvxFontListBox, ListBox, "svxfontlistbox");
184 IMPL_GET_IMPL (SvxFontListBox);
185 IMPL_GET_WINDOW (SvxFontListBox);*/
189 #endif
191 // ============================================================================