xref: /AOO41X/main/padmin/source/titlectrl.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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 #ifndef _PAD_NEWPPDLG_HXX_
29 #include <titlectrl.hxx>
30 #endif
31 
32 using namespace padmin;
33 
34 TitleImage::TitleImage( Window* pParent, const ResId& rResId ) :
35         Control( pParent, rResId ),
36         m_bArranged( false )
37 {
38     Font aFont = GetFont();
39     aFont.SetHeight( aFont.GetHeight()*3/2 );
40     SetFont( aFont );
41 }
42 
43 // -----------------------------------------------------------------------
44 
45 TitleImage::~TitleImage()
46 {
47 }
48 
49 // -----------------------------------------------------------------------
50 
51 void TitleImage::arrange()
52 {
53     m_bArranged = true;
54     Size aCtrlSize( GetSizePixel() );
55     Size aImageSize( m_aImage.GetSizePixel() );
56     Size aTextSize( GetTextWidth( m_aText ), GetTextHeight() );
57 
58     m_aImagePos.Y() = ( aCtrlSize.Height() - aImageSize.Height() ) / 2;
59     m_aImagePos.X() = m_aImagePos.Y() < 0 ? -m_aImagePos.Y() : m_aImagePos.Y();
60     m_aTextPos.X() = m_aImagePos.X() + aImageSize.Width() + aTextSize.Height()/2;
61     m_aTextPos.Y() = ( aCtrlSize.Height() - aTextSize.Height() ) / 2;
62 }
63 
64 // -----------------------------------------------------------------------
65 
66 void TitleImage::Paint( const Rectangle& )
67 {
68     if( ! m_bArranged )
69         arrange();
70 
71     SetLineColor( m_aBGColor );
72     SetFillColor( m_aBGColor );
73     DrawRect( Rectangle( Point( 0, 0 ), Size( GetSizePixel() ) ) );
74     DrawImage( m_aImagePos, m_aImage );
75     DrawText( m_aTextPos, m_aText );
76 }
77 
78 // -----------------------------------------------------------------------
79 
80 void TitleImage::SetText( const String& rText )
81 {
82     m_aText = rText;
83     m_bArranged = false;
84     Invalidate();
85 }
86 
87 // -----------------------------------------------------------------------
88 
89 void TitleImage::SetImage( const Image& rImage )
90 {
91     m_aImage = rImage;
92     m_bArranged = false;
93     Invalidate();
94 }
95 
96 // -----------------------------------------------------------------------
97 
98 void TitleImage::SetBackgroundColor( const Color& rColor )
99 {
100     m_aBGColor = rColor;
101     Invalidate();
102 }
103