1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _PAD_NEWPPDLG_HXX_ 25 #include <titlectrl.hxx> 26 #endif 27 28 using namespace padmin; 29 30 TitleImage::TitleImage( Window* pParent, const ResId& rResId ) : 31 Control( pParent, rResId ), 32 m_bArranged( false ) 33 { 34 Font aFont = GetFont(); 35 aFont.SetHeight( aFont.GetHeight()*3/2 ); 36 SetFont( aFont ); 37 } 38 39 // ----------------------------------------------------------------------- 40 41 TitleImage::~TitleImage() 42 { 43 } 44 45 // ----------------------------------------------------------------------- 46 47 void TitleImage::arrange() 48 { 49 m_bArranged = true; 50 Size aCtrlSize( GetSizePixel() ); 51 Size aImageSize( m_aImage.GetSizePixel() ); 52 Size aTextSize( GetTextWidth( m_aText ), GetTextHeight() ); 53 54 m_aImagePos.Y() = ( aCtrlSize.Height() - aImageSize.Height() ) / 2; 55 m_aImagePos.X() = m_aImagePos.Y() < 0 ? -m_aImagePos.Y() : m_aImagePos.Y(); 56 m_aTextPos.X() = m_aImagePos.X() + aImageSize.Width() + aTextSize.Height()/2; 57 m_aTextPos.Y() = ( aCtrlSize.Height() - aTextSize.Height() ) / 2; 58 } 59 60 // ----------------------------------------------------------------------- 61 62 void TitleImage::Paint( const Rectangle& ) 63 { 64 if( ! m_bArranged ) 65 arrange(); 66 67 SetLineColor( m_aBGColor ); 68 SetFillColor( m_aBGColor ); 69 DrawRect( Rectangle( Point( 0, 0 ), Size( GetSizePixel() ) ) ); 70 DrawImage( m_aImagePos, m_aImage ); 71 DrawText( m_aTextPos, m_aText ); 72 } 73 74 // ----------------------------------------------------------------------- 75 76 void TitleImage::SetText( const String& rText ) 77 { 78 m_aText = rText; 79 m_bArranged = false; 80 Invalidate(); 81 } 82 83 // ----------------------------------------------------------------------- 84 85 void TitleImage::SetImage( const Image& rImage ) 86 { 87 m_aImage = rImage; 88 m_bArranged = false; 89 Invalidate(); 90 } 91 92 // ----------------------------------------------------------------------- 93 94 void TitleImage::SetBackgroundColor( const Color& rColor ) 95 { 96 m_aBGColor = rColor; 97 Invalidate(); 98 } 99