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