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 : #include "inspectorhelpwindow.hxx"
20 : #include "modulepcr.hxx"
21 : #include "propresid.hrc"
22 :
23 :
24 : namespace pcr
25 : {
26 :
27 : //= InspectorHelpWindow
28 :
29 :
30 0 : InspectorHelpWindow::InspectorHelpWindow( vcl::Window* _pParent )
31 : :Window( _pParent, WB_DIALOGCONTROL )
32 : ,m_aSeparator( VclPtr<FixedLine>::Create(this) )
33 : ,m_aHelpText( VclPtr<MultiLineEdit>::Create(this, WB_LEFT | WB_READONLY | WB_AUTOVSCROLL) )
34 : ,m_nMinLines( 3 )
35 0 : ,m_nMaxLines( 8 )
36 : {
37 0 : SetBackground();
38 0 : SetPaintTransparent(true);
39 0 : m_aSeparator->SetText( PcrRes(RID_STR_HELP_SECTION_LABEL).toString() );
40 0 : m_aSeparator->SetBackground();
41 0 : m_aSeparator->Show();
42 :
43 0 : m_aHelpText->SetControlBackground( /*m_aSeparator->GetBackground().GetColor() */);
44 0 : m_aHelpText->SetBackground();
45 0 : m_aHelpText->SetPaintTransparent(true);
46 0 : m_aHelpText->Show();
47 0 : }
48 :
49 0 : InspectorHelpWindow::~InspectorHelpWindow()
50 : {
51 0 : disposeOnce();
52 0 : }
53 :
54 0 : void InspectorHelpWindow::dispose()
55 : {
56 0 : m_aSeparator.disposeAndClear();
57 0 : m_aHelpText.disposeAndClear();
58 0 : vcl::Window::dispose();
59 0 : }
60 :
61 0 : void InspectorHelpWindow::SetText( const OUString& _rStr )
62 : {
63 0 : m_aHelpText->SetText( _rStr );
64 0 : }
65 :
66 :
67 0 : void InspectorHelpWindow::SetLimits( sal_Int32 _nMinLines, sal_Int32 _nMaxLines )
68 : {
69 0 : m_nMinLines = _nMinLines;
70 0 : m_nMaxLines = _nMaxLines;
71 0 : }
72 :
73 :
74 0 : long InspectorHelpWindow::impl_getHelpTextBorderHeight()
75 : {
76 0 : sal_Int32 nTop(0), nBottom(0), nDummy(0);
77 0 : m_aHelpText->GetBorder( nDummy, nTop, nDummy, nBottom );
78 0 : return nTop + nBottom;
79 : }
80 :
81 :
82 0 : long InspectorHelpWindow::impl_getSpaceAboveTextWindow()
83 : {
84 0 : Size aSeparatorSize( LogicToPixel( Size( 0, 8 ), MAP_APPFONT ) );
85 0 : Size a3AppFontSize( LogicToPixel( Size( 3, 3 ), MAP_APPFONT ) );
86 0 : return aSeparatorSize.Height() + a3AppFontSize.Height();
87 : }
88 :
89 :
90 0 : long InspectorHelpWindow::GetMinimalHeightPixel()
91 : {
92 0 : return impl_getMinimalTextWindowHeight() + impl_getSpaceAboveTextWindow();
93 : }
94 :
95 :
96 0 : long InspectorHelpWindow::impl_getMinimalTextWindowHeight()
97 : {
98 0 : return impl_getHelpTextBorderHeight() + m_aHelpText->GetTextHeight() * m_nMinLines;
99 : }
100 :
101 :
102 0 : long InspectorHelpWindow::impl_getMaximalTextWindowHeight()
103 : {
104 0 : return impl_getHelpTextBorderHeight() + m_aHelpText->GetTextHeight() * m_nMaxLines;
105 : }
106 :
107 :
108 0 : long InspectorHelpWindow::GetOptimalHeightPixel()
109 : {
110 : // --- calc the height as needed for the mere text window
111 0 : long nMinTextWindowHeight = impl_getMinimalTextWindowHeight();
112 0 : long nMaxTextWindowHeight = impl_getMaximalTextWindowHeight();
113 :
114 0 : Rectangle aTextRect( Point( 0, 0 ), m_aHelpText->GetOutputSizePixel() );
115 0 : aTextRect = m_aHelpText->GetTextRect( aTextRect, m_aHelpText->GetText(),
116 0 : DrawTextFlags::Left | DrawTextFlags::Top | DrawTextFlags::MultiLine | DrawTextFlags::WordBreak );
117 0 : long nActTextWindowHeight = impl_getHelpTextBorderHeight() + aTextRect.GetHeight();
118 :
119 0 : long nOptTextWindowHeight = ::std::max( nMinTextWindowHeight, ::std::min( nMaxTextWindowHeight, nActTextWindowHeight ) );
120 :
121 : // --- then add the space above the text window
122 0 : return nOptTextWindowHeight + impl_getSpaceAboveTextWindow();
123 : }
124 :
125 :
126 0 : void InspectorHelpWindow::Resize()
127 : {
128 0 : Size a3AppFont( LogicToPixel( Size( 3, 3 ), MAP_APPFONT ) );
129 :
130 0 : Rectangle aPlayground( Point( 0, 0 ), GetOutputSizePixel() );
131 :
132 0 : Rectangle aSeparatorArea( aPlayground );
133 0 : aSeparatorArea.Bottom() = aSeparatorArea.Top() + LogicToPixel( Size( 0, 8 ), MAP_APPFONT ).Height();
134 0 : m_aSeparator->SetPosSizePixel( aSeparatorArea.TopLeft(), aSeparatorArea.GetSize() );
135 :
136 0 : Rectangle aTextArea( aPlayground );
137 0 : aTextArea.Top() = aSeparatorArea.Bottom() + a3AppFont.Height();
138 0 : m_aHelpText->SetPosSizePixel( aTextArea.TopLeft(), aTextArea.GetSize() );
139 0 : }
140 :
141 :
142 6 : } // namespace pcr
143 :
144 :
145 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|