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 "hintwin.hxx"
21 : #include "global.hxx"
22 :
23 : #define HINT_LINESPACE 2
24 : #define HINT_INDENT 3
25 : #define HINT_MARGIN 4
26 :
27 0 : ScHintWindow::ScHintWindow( Window* pParent, const OUString& rTit, const OUString& rMsg ) :
28 : Window( pParent, WinBits( WB_BORDER ) ),
29 : aTitle( rTit ),
30 0 : aMessage( convertLineEnd(rMsg, LINEEND_CR) )
31 : {
32 : // Hellgelb, wie Notizen in detfunc.cxx
33 0 : Color aYellow( 255,255,192 ); // hellgelb
34 0 : SetBackground( aYellow );
35 :
36 0 : aTextFont = GetFont();
37 0 : aTextFont.SetTransparent( true );
38 0 : aTextFont.SetWeight( WEIGHT_NORMAL );
39 0 : aHeadFont = aTextFont;
40 0 : aHeadFont.SetWeight( WEIGHT_BOLD );
41 :
42 0 : SetFont( aHeadFont );
43 0 : Size aHeadSize( GetTextWidth( aTitle ), GetTextHeight() );
44 0 : SetFont( aTextFont );
45 :
46 0 : Size aTextSize;
47 0 : sal_Int32 nIndex = 0;
48 0 : while ( nIndex != -1 )
49 : {
50 0 : OUString aLine = aMessage.getToken( 0, CHAR_CR, nIndex );
51 0 : Size aLineSize( GetTextWidth( aLine ), GetTextHeight() );
52 0 : nTextHeight = aLineSize.Height();
53 0 : aTextSize.Height() += nTextHeight;
54 0 : if ( aLineSize.Width() > aTextSize.Width() )
55 0 : aTextSize.Width() = aLineSize.Width();
56 0 : }
57 0 : aTextSize.Width() += HINT_INDENT;
58 :
59 : aTextStart = Point( HINT_MARGIN + HINT_INDENT,
60 0 : aHeadSize.Height() + HINT_MARGIN + HINT_LINESPACE );
61 :
62 0 : Size aWinSize( std::max( aHeadSize.Width(), aTextSize.Width() ) + 2 * HINT_MARGIN + 1,
63 0 : aHeadSize.Height() + aTextSize.Height() + HINT_LINESPACE + 2 * HINT_MARGIN + 1 );
64 0 : SetOutputSizePixel( aWinSize );
65 0 : }
66 :
67 :
68 0 : ScHintWindow::~ScHintWindow()
69 : {
70 0 : }
71 :
72 :
73 0 : void ScHintWindow::Paint( const Rectangle& /* rRect */ )
74 : {
75 0 : SetFont( aHeadFont );
76 0 : DrawText( Point(HINT_MARGIN,HINT_MARGIN), aTitle );
77 :
78 0 : SetFont( aTextFont );
79 0 : sal_Int32 nIndex = 0;
80 0 : Point aLineStart = aTextStart;
81 0 : while ( nIndex != -1 )
82 : {
83 0 : OUString aLine = aMessage.getToken( 0, CHAR_CR, nIndex );
84 0 : DrawText( aLineStart, aLine );
85 0 : aLineStart.Y() += nTextHeight;
86 0 : }
87 0 : }
88 :
89 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|