update credits
[LibreOffice.git] / svx / source / dialog / fontlb.cxx
blobf5a4d32844fea6e39d0238bffc6f70542e60f74d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "svx/fontlb.hxx"
21 #include <vcl/builder.hxx>
22 #include <vcl/svapp.hxx>
23 #include "svtools/treelistentry.hxx"
24 #include "svtools/viewdataentry.hxx"
26 // ============================================================================
28 DBG_NAME( SvLBoxFontString );
30 SvLBoxFontString::SvLBoxFontString() :
31 SvLBoxString()
33 DBG_CTOR( SvLBoxFontString, 0 );
36 SvLBoxFontString::SvLBoxFontString(
37 SvTreeListEntry* pEntry, sal_uInt16 nFlags, const XubString& rString,
38 const Font& rFont, const Color* pColor ) :
39 SvLBoxString( pEntry, nFlags, rString ),
40 maFont( rFont ),
41 mbUseColor( pColor != NULL )
43 DBG_CTOR( SvLBoxFontString, 0 );
44 SetText( rString );
45 if( pColor )
46 maFont.SetColor( *pColor );
49 SvLBoxFontString::~SvLBoxFontString()
51 DBG_DTOR( SvLBoxFontString, 0 );
55 SvLBoxItem* SvLBoxFontString::Create() const
57 DBG_CHKTHIS( SvLBoxFontString, 0 );
58 return new SvLBoxFontString;
61 void SvLBoxFontString::Paint(
62 const Point& rPos, SvTreeListBox& rDev, const SvViewDataEntry* pView, const SvTreeListEntry* pEntry)
64 DBG_CHKTHIS( SvLBoxFontString, 0 );
65 Font aOldFont( rDev.GetFont() );
66 Font aNewFont( maFont );
67 bool bSel = pView->IsSelected();
68 if( !mbUseColor || bSel ) // selection always gets highlight color
70 const StyleSettings& rSett = Application::GetSettings().GetStyleSettings();
71 aNewFont.SetColor( bSel ? rSett.GetHighlightTextColor() : rSett.GetFieldTextColor() );
74 rDev.SetFont( aNewFont );
75 SvLBoxString::Paint(rPos, rDev, pView, pEntry);
76 rDev.SetFont( aOldFont );
79 void SvLBoxFontString::InitViewData( SvTreeListBox* pView, SvTreeListEntry* pEntry, SvViewDataItem* pViewData )
81 DBG_CHKTHIS( SvLBoxFontString, 0 );
82 Font aOldFont( pView->GetFont() );
83 pView->Control::SetFont( maFont );
84 SvLBoxString::InitViewData( pView, pEntry, pViewData);
85 pView->Control::SetFont( aOldFont );
89 // ============================================================================
91 SvxFontListBox::SvxFontListBox(Window* pParent, WinBits nStyle)
92 : SvTabListBox(pParent, nStyle)
93 , maStdFont(GetFont())
94 , mbUseFont(false)
96 maStdFont.SetTransparent(sal_True);
97 maEntryFont = maStdFont;
100 extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSvxFontListBox(Window *pParent, VclBuilder::stringmap &rMap)
102 WinBits nWinStyle = WB_TABSTOP;
103 OString sBorder = VclBuilder::extractCustomProperty(rMap);
104 if (!sBorder.isEmpty())
105 nWinStyle |= WB_BORDER;
106 return new SvxFontListBox(pParent, nWinStyle);
109 void SvxFontListBox::InsertFontEntry( const String& rString, const Font& rFont, const Color* pColor )
111 mbUseFont = true; // InitEntry() will use maEntryFont
112 maEntryFont = rFont; // font to use in InitEntry() over InsertEntry()
113 mpEntryColor = pColor; // color to use in InitEntry() over InsertEntry()
114 InsertEntry( rString );
115 mbUseFont = false;
118 void SvxFontListBox::SelectEntryPos( sal_uInt16 nPos, bool bSelect )
120 SvTreeListEntry* pEntry = GetEntry( nPos );
121 if( pEntry )
123 Select( pEntry, bSelect );
124 ShowEntry( pEntry );
128 void SvxFontListBox::SetNoSelection()
130 SelectAll( sal_False, sal_True );
133 sal_uLong SvxFontListBox::GetSelectEntryPos() const
135 SvTreeListEntry* pSvLBoxEntry = FirstSelected();
136 return pSvLBoxEntry ? GetModel()->GetAbsPos( pSvLBoxEntry ) : LIST_APPEND;
139 XubString SvxFontListBox::GetSelectEntry() const
141 return GetEntryText( GetSelectEntryPos() );
144 void SvxFontListBox::InitEntry(
145 SvTreeListEntry* pEntry, const OUString& rEntryText,
146 const Image& rCollImg, const Image& rExpImg,
147 SvLBoxButtonKind eButtonKind)
149 if( mbUseFont )
151 if( nTreeFlags & TREEFLAG_CHKBTN )
152 pEntry->AddItem( new SvLBoxButton( pEntry, eButtonKind, 0,
153 pCheckButtonData ) );
154 pEntry->AddItem( new SvLBoxContextBmp(pEntry, 0, rCollImg, rExpImg, true) );
155 pEntry->AddItem( new SvLBoxFontString( pEntry, 0, rEntryText, maEntryFont, mpEntryColor ) );
157 else
158 SvTreeListBox::InitEntry( pEntry, rEntryText, rCollImg, rExpImg,
159 eButtonKind );
162 // ============================================================================
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */