Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include <titlectrl.hxx>
21 : :
22 : : using namespace padmin;
23 : :
24 : 0 : TitleImage::TitleImage( Window* pParent, const ResId& rResId ) :
25 : : Control( pParent, rResId ),
26 : 0 : m_bArranged( false )
27 : : {
28 : 0 : Font aFont = GetFont();
29 : 0 : aFont.SetHeight( aFont.GetHeight()*3/2 );
30 : 0 : SetFont( aFont );
31 : 0 : }
32 : :
33 : : // -----------------------------------------------------------------------
34 : :
35 : 0 : TitleImage::~TitleImage()
36 : : {
37 : 0 : }
38 : :
39 : : // -----------------------------------------------------------------------
40 : :
41 : 0 : void TitleImage::arrange()
42 : : {
43 : 0 : m_bArranged = true;
44 : 0 : Size aCtrlSize( GetSizePixel() );
45 : 0 : Size aImageSize( m_aImage.GetSizePixel() );
46 : 0 : Size aTextSize( GetTextWidth( m_aText ), GetTextHeight() );
47 : :
48 : 0 : m_aImagePos.Y() = ( aCtrlSize.Height() - aImageSize.Height() ) / 2;
49 : 0 : m_aImagePos.X() = m_aImagePos.Y() < 0 ? -m_aImagePos.Y() : m_aImagePos.Y();
50 : 0 : m_aTextPos.X() = m_aImagePos.X() + aImageSize.Width() + aTextSize.Height()/2;
51 : 0 : m_aTextPos.Y() = ( aCtrlSize.Height() - aTextSize.Height() ) / 2;
52 : 0 : }
53 : :
54 : : // -----------------------------------------------------------------------
55 : :
56 : 0 : void TitleImage::Paint( const Rectangle& )
57 : : {
58 : 0 : if( ! m_bArranged )
59 : 0 : arrange();
60 : :
61 : 0 : SetLineColor( m_aBGColor );
62 : 0 : SetFillColor( m_aBGColor );
63 : 0 : DrawRect( Rectangle( Point( 0, 0 ), Size( GetSizePixel() ) ) );
64 : 0 : DrawImage( m_aImagePos, m_aImage );
65 : 0 : DrawText( m_aTextPos, m_aText );
66 : 0 : }
67 : :
68 : : // -----------------------------------------------------------------------
69 : :
70 : 0 : void TitleImage::SetText( const String& rText )
71 : : {
72 : 0 : m_aText = rText;
73 : 0 : m_bArranged = false;
74 : 0 : Invalidate();
75 : 0 : }
76 : :
77 : : // -----------------------------------------------------------------------
78 : :
79 : 0 : void TitleImage::SetImage( const Image& rImage )
80 : : {
81 : 0 : m_aImage = rImage;
82 : 0 : m_bArranged = false;
83 : 0 : Invalidate();
84 : 0 : }
85 : :
86 : : // -----------------------------------------------------------------------
87 : :
88 : 0 : void TitleImage::SetBackgroundColor( const Color& rColor )
89 : : {
90 : 0 : m_aBGColor = rColor;
91 : 0 : Invalidate();
92 : 0 : }
93 : :
94 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|