xref: /AOO41X/main/extensions/source/propctrlr/inspectorhelpwindow.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 // MARKER(update_precomp.py): autogen include statement, do not remove
28 #include "precompiled_extensions.hxx"
29 #include "inspectorhelpwindow.hxx"
30 #include "modulepcr.hxx"
31 #ifndef EXTENSIONS_PROPRESID_HRC
32 #include "propresid.hrc"
33 #endif
34 
35 /** === begin UNO includes === **/
36 /** === end UNO includes === **/
37 
38 //........................................................................
39 namespace pcr
40 {
41 //........................................................................
42 
43 	/** === begin UNO using === **/
44 	/** === end UNO using === **/
45 
46 	//====================================================================
47 	//= InspectorHelpWindow
48 	//====================================================================
49 	//--------------------------------------------------------------------
50     InspectorHelpWindow::InspectorHelpWindow( Window* _pParent )
51         :Window( _pParent, WB_DIALOGCONTROL )
52         ,m_aSeparator( this )
53         ,m_aHelpText( this, WB_LEFT | WB_READONLY | WB_AUTOVSCROLL )
54         ,m_nMinLines( 3 )
55         ,m_nMaxLines( 8 )
56     {
57         SetBackground();
58         SetPaintTransparent(sal_True);
59         m_aSeparator.SetText( String( PcrRes( RID_STR_HELP_SECTION_LABEL ) ) );
60         m_aSeparator.SetBackground();
61         m_aSeparator.Show();
62 
63         m_aHelpText.SetControlBackground( /*m_aSeparator.GetBackground().GetColor() */);
64         m_aHelpText.SetBackground();
65         m_aHelpText.SetPaintTransparent(sal_True);
66         m_aHelpText.Show();
67     }
68 
69 	//--------------------------------------------------------------------
70     void InspectorHelpWindow::SetText( const XubString& _rStr )
71     {
72         m_aHelpText.SetText( _rStr );
73     }
74 
75 	//--------------------------------------------------------------------
76     void InspectorHelpWindow::SetLimits( sal_Int32 _nMinLines, sal_Int32 _nMaxLines )
77     {
78         m_nMinLines = _nMinLines;
79         m_nMaxLines = _nMaxLines;
80     }
81 
82 	//--------------------------------------------------------------------
83     long InspectorHelpWindow::impl_getHelpTextBorderHeight()
84     {
85 	    sal_Int32 nTop(0), nBottom(0), nDummy(0);
86 	    m_aHelpText.GetBorder( nDummy, nTop, nDummy, nBottom );
87         return nTop + nBottom;
88     }
89 
90 	//--------------------------------------------------------------------
91     long InspectorHelpWindow::impl_getSpaceAboveTextWindow()
92     {
93         Size aSeparatorSize( LogicToPixel( Size( 0, 8 ), MAP_APPFONT ) );
94         Size a3AppFontSize( LogicToPixel( Size( 3, 3 ), MAP_APPFONT ) );
95         return aSeparatorSize.Height() + a3AppFontSize.Height();
96     }
97 
98     //--------------------------------------------------------------------
99     long InspectorHelpWindow::GetMinimalHeightPixel()
100     {
101         return impl_getMinimalTextWindowHeight() + impl_getSpaceAboveTextWindow();
102     }
103 
104     //--------------------------------------------------------------------
105     long InspectorHelpWindow::impl_getMinimalTextWindowHeight()
106     {
107         return impl_getHelpTextBorderHeight() + m_aHelpText.GetTextHeight() * m_nMinLines;
108     }
109 
110 	//--------------------------------------------------------------------
111     long InspectorHelpWindow::impl_getMaximalTextWindowHeight()
112     {
113         return impl_getHelpTextBorderHeight() + m_aHelpText.GetTextHeight() * m_nMaxLines;
114     }
115 
116 	//--------------------------------------------------------------------
117     long InspectorHelpWindow::GetOptimalHeightPixel()
118     {
119         // --- calc the height as needed for the mere text window
120         long nMinTextWindowHeight = impl_getMinimalTextWindowHeight();
121         long nMaxTextWindowHeight = impl_getMaximalTextWindowHeight();
122 
123         Rectangle aTextRect( Point( 0, 0 ), m_aHelpText.GetOutputSizePixel() );
124         aTextRect = m_aHelpText.GetTextRect( aTextRect, m_aHelpText.GetText(),
125             TEXT_DRAW_LEFT | TEXT_DRAW_TOP | TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK );
126         long nActTextWindowHeight = impl_getHelpTextBorderHeight() + aTextRect.GetHeight();
127 
128         long nOptTextWindowHeight = ::std::max( nMinTextWindowHeight, ::std::min( nMaxTextWindowHeight, nActTextWindowHeight ) );
129 
130         // --- then add the space above the text window
131         return nOptTextWindowHeight + impl_getSpaceAboveTextWindow();
132     }
133 
134 	//--------------------------------------------------------------------
135     void InspectorHelpWindow::Resize()
136     {
137         Size a3AppFont( LogicToPixel( Size( 3, 3 ), MAP_APPFONT ) );
138 
139         Rectangle aPlayground( Point( 0, 0 ), GetOutputSizePixel() );
140 
141         Rectangle aSeparatorArea( aPlayground );
142         aSeparatorArea.Bottom() = aSeparatorArea.Top() + LogicToPixel( Size( 0, 8 ), MAP_APPFONT ).Height();
143         m_aSeparator.SetPosSizePixel( aSeparatorArea.TopLeft(), aSeparatorArea.GetSize() );
144 
145         Rectangle aTextArea( aPlayground );
146         aTextArea.Top() = aSeparatorArea.Bottom() + a3AppFont.Height();
147         m_aHelpText.SetPosSizePixel( aTextArea.TopLeft(), aTextArea.GetSize() );
148     }
149 
150 //........................................................................
151 } // namespace pcr
152 //........................................................................
153 
154