xref: /AOO41X/main/reportdesign/source/ui/report/StartMarker.cxx (revision 9e0e41911c53968aad5ad356e2b2126da667034f)
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 #include "precompiled_reportdesign.hxx"
24 #include "StartMarker.hxx"
25 #include <vcl/image.hxx>
26 #include <vcl/svapp.hxx>
27 #include "RptResId.hrc"
28 #include "ModuleHelper.hxx"
29 #include "ColorChanger.hxx"
30 #include "ReportDefines.hxx"
31 #include "SectionWindow.hxx"
32 #include "helpids.hrc"
33 #include <vcl/help.hxx>
34 #include <vcl/gradient.hxx>
35 #include <vcl/lineinfo.hxx>
36 #include <toolkit/helper/vclunohelper.hxx>
37 #include <unotools/syslocale.hxx>
38 #include <svl/smplhint.hxx>
39 
40 #define CORNER_SPACE     5
41 
42 //=====================================================================
43 namespace rptui
44 {
45 //=====================================================================
46 
47 Image*  OStartMarker::s_pDefCollapsed       = NULL;
48 Image*  OStartMarker::s_pDefExpanded        = NULL;
49 Image*  OStartMarker::s_pDefCollapsedHC = NULL;
50 Image*  OStartMarker::s_pDefExpandedHC  = NULL;
51 oslInterlockedCount OStartMarker::s_nImageRefCount  = 0;
52 
DBG_NAME(rpt_OStartMarker)53 DBG_NAME( rpt_OStartMarker )
54 // -----------------------------------------------------------------------------
55 OStartMarker::OStartMarker(OSectionWindow* _pParent,const ::rtl::OUString& _sColorEntry)
56 : OColorListener(_pParent,_sColorEntry)
57 ,m_aVRuler(this,WB_VERT)
58 ,m_aText(this,WB_HYPHENATION)
59 ,m_aImage(this,WB_LEFT|WB_TOP|WB_SCALE)
60 ,m_pParent(_pParent)
61 ,m_bShowRuler(sal_True)
62 {
63     DBG_CTOR( rpt_OStartMarker,NULL);
64     SetUniqueId(HID_RPT_STARTMARKER);
65 
66     osl_incrementInterlockedCount(&s_nImageRefCount);
67     initDefaultNodeImages();
68     ImplInitSettings();
69     m_aText.SetHelpId(HID_RPT_START_TITLE);
70     m_aText.SetPaintTransparent(sal_True);
71     m_aImage.SetHelpId(HID_RPT_START_IMAGE);
72     m_aText.Show();
73     m_aImage.Show();
74     m_aVRuler.Show();
75     m_aVRuler.Activate();
76     m_aVRuler.SetPagePos(0);
77     m_aVRuler.SetBorders();
78     m_aVRuler.SetIndents();
79     m_aVRuler.SetMargin1();
80     m_aVRuler.SetMargin2();
81     const MeasurementSystem eSystem = SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
82     m_aVRuler.SetUnit(MEASURE_METRIC == eSystem ? FUNIT_CM : FUNIT_INCH);
83     EnableChildTransparentMode( sal_True );
84     SetParentClipMode( PARENTCLIPMODE_NOCLIP );
85     SetPaintTransparent( sal_True );
86 }
87 // -----------------------------------------------------------------------------
~OStartMarker()88 OStartMarker::~OStartMarker()
89 {
90     DBG_DTOR( rpt_OStartMarker,NULL);
91     if ( osl_decrementInterlockedCount(&s_nImageRefCount) == 0 )
92     {
93         DELETEZ(s_pDefCollapsed);
94         DELETEZ(s_pDefExpanded);
95         DELETEZ(s_pDefCollapsedHC);
96         DELETEZ(s_pDefExpandedHC);
97     } // if ( osl_decrementInterlockedCount(&s_nImageRefCount) == 0 )
98 }
99 // -----------------------------------------------------------------------------
getMinHeight() const100 sal_Int32 OStartMarker::getMinHeight() const
101 {
102     Fraction aExtraWidth(long(2*REPORT_EXTRA_SPACE));
103     aExtraWidth *= GetMapMode().GetScaleX();
104     return LogicToPixel(Size(0,m_aText.GetTextHeight())).Height() + (long)aExtraWidth;
105 }
106 // -----------------------------------------------------------------------------
Paint(const Rectangle & rRect)107 void OStartMarker::Paint( const Rectangle& rRect )
108 {
109     (void)rRect;
110     //SetUpdateMode(sal_False);
111     Size aSize = GetOutputSizePixel();
112     long nSize = aSize.Width();
113     const long nCornerWidth = long(CORNER_SPACE * (double)GetMapMode().GetScaleX());
114 
115     if ( isCollapsed() )
116     {
117         SetClipRegion();
118     }
119     else
120     {
121         const long nVRulerWidth = m_aVRuler.GetSizePixel().Width();
122         nSize = aSize.Width() - nVRulerWidth/* - m_nCornerSize*/;
123         aSize.Width() += nCornerWidth;
124         SetClipRegion(Region(PixelToLogic(Rectangle(Point(),Size(nSize,aSize.Height())))));
125     }
126 
127     const Point aGcc3WorkaroundTemporary;
128     Rectangle aWholeRect(aGcc3WorkaroundTemporary,aSize);
129     {
130         const ColorChanger aColors( this, m_nTextBoundaries, m_nColor );
131         PolyPolygon aPoly;
132         aPoly.Insert(Polygon(aWholeRect,nCornerWidth,nCornerWidth));
133 
134         Color aStartColor(m_nColor);
135         aStartColor.IncreaseLuminance(10);
136         sal_uInt16 nHue = 0;
137         sal_uInt16 nSat = 0;
138         sal_uInt16 nBri = 0;
139         aStartColor.RGBtoHSB(nHue, nSat, nBri);
140         nSat += 40;
141         Color aEndColor(Color::HSBtoRGB(nHue, nSat, nBri));
142         Gradient aGradient(GRADIENT_LINEAR,aStartColor,aEndColor);
143         aGradient.SetSteps(static_cast<sal_uInt16>(aSize.Height()));
144 
145         DrawGradient(PixelToLogic(aPoly) ,aGradient);
146     }
147     if ( m_bMarked )
148     {
149         const long nCornerHeight = long(CORNER_SPACE * (double)GetMapMode().GetScaleY());
150         Rectangle aRect( Point(nCornerWidth,nCornerHeight),
151                          Size(aSize.Width() - nCornerWidth - nCornerWidth,aSize.Height() - nCornerHeight - nCornerHeight));
152         ColorChanger aColors( this, COL_WHITE, COL_WHITE );
153         DrawPolyLine(Polygon(PixelToLogic(aRect)),LineInfo(LINE_SOLID,2 ));
154     }
155 }
156 // -----------------------------------------------------------------------------
setColor()157 void OStartMarker::setColor()
158 {
159     const Color aColor(m_nColor);
160     Color aTextColor = GetTextColor();
161     if ( aColor.GetLuminance() < 128 )
162         aTextColor = COL_WHITE;
163     m_aText.SetTextColor(aTextColor);
164     m_aText.SetLineColor(m_nColor);
165 }
166 // -----------------------------------------------------------------------
MouseButtonUp(const MouseEvent & rMEvt)167 void OStartMarker::MouseButtonUp( const MouseEvent& rMEvt )
168 {
169     if ( !rMEvt.IsLeft() )
170         return;
171 
172     Point aPos( rMEvt.GetPosPixel());
173 
174     const Size aOutputSize = GetOutputSizePixel();
175     if( aPos.X() > aOutputSize.Width() || aPos.Y() > aOutputSize.Height() )
176         return;
177     Rectangle aRect(m_aImage.GetPosPixel(),m_aImage.GetSizePixel());
178     if ( rMEvt.GetClicks() == 2 || aRect.IsInside( aPos ) )
179     {
180         m_bCollapsed = !m_bCollapsed;
181 
182         changeImage();
183 
184         m_aVRuler.Show(!m_bCollapsed && m_bShowRuler);
185         if ( m_aCollapsedLink.IsSet() )
186             m_aCollapsedLink.Call(this);
187     }
188 
189     m_pParent->showProperties();
190 }
191 // -----------------------------------------------------------------------------
changeImage()192 void OStartMarker::changeImage()
193 {
194     Image* pImage = NULL;
195     if ( GetSettings().GetStyleSettings().GetHighContrastMode() )
196         pImage = m_bCollapsed ? s_pDefCollapsedHC : s_pDefExpandedHC;
197     else
198         pImage = m_bCollapsed ? s_pDefCollapsed : s_pDefExpanded;
199     m_aImage.SetImage(*pImage);
200 }
201 // -----------------------------------------------------------------------
initDefaultNodeImages()202 void OStartMarker::initDefaultNodeImages()
203 {
204     if ( !s_pDefCollapsed )
205     {
206         s_pDefCollapsed     = new Image( ModuleRes( RID_IMG_TREENODE_COLLAPSED      ) );
207         s_pDefCollapsedHC   = new Image( ModuleRes( RID_IMG_TREENODE_COLLAPSED_HC   ) );
208         s_pDefExpanded      = new Image( ModuleRes( RID_IMG_TREENODE_EXPANDED       ) );
209         s_pDefExpandedHC    = new Image( ModuleRes( RID_IMG_TREENODE_EXPANDED_HC    ) );
210     }
211 
212     Image* pImage = NULL;
213     if ( GetSettings().GetStyleSettings().GetHighContrastMode() )
214     {
215         pImage = m_bCollapsed ? s_pDefCollapsedHC : s_pDefExpandedHC;
216     }
217     else
218     {
219         pImage = m_bCollapsed ? s_pDefCollapsed : s_pDefExpanded;
220     }
221     m_aImage.SetImage(*pImage);
222     m_aImage.SetMouseTransparent(sal_True);
223     m_aImage.SetBackground();
224     m_aText.SetBackground();
225     m_aText.SetMouseTransparent(sal_True);
226 }
227 // -----------------------------------------------------------------------
ImplInitSettings()228 void OStartMarker::ImplInitSettings()
229 {
230     // SetBackground( Wallpaper( COL_YELLOW ));
231     SetBackground( );
232     SetFillColor( Application::GetSettings().GetStyleSettings().GetDialogColor() );
233     setColor();
234 }
235 //------------------------------------------------------------------------------
Resize()236 void OStartMarker::Resize()
237 {
238     const Size aOutputSize( GetOutputSizePixel() );
239     const long nOutputWidth  = aOutputSize.Width();
240     const long nOutputHeight = aOutputSize.Height();
241 
242     const long nVRulerWidth = m_aVRuler.GetSizePixel().Width();
243     const Point aRulerPos(nOutputWidth - nVRulerWidth,0);
244     m_aVRuler.SetPosSizePixel(aRulerPos,Size(nVRulerWidth,nOutputHeight));
245 
246     Size aImageSize = m_aImage.GetImage().GetSizePixel();
247     const MapMode& rMapMode = GetMapMode();
248     aImageSize.Width() = long(aImageSize.Width() * (double)rMapMode.GetScaleX());
249     aImageSize.Height() = long(aImageSize.Height() * (double)rMapMode.GetScaleY());
250 
251     Fraction aExtraWidth(long(REPORT_EXTRA_SPACE));
252     aExtraWidth *= rMapMode.GetScaleX();
253 
254     Point aPos(aImageSize.Width() + (long)(aExtraWidth + aExtraWidth), aExtraWidth);
255     const long nHeight = ::std::max<sal_Int32>(nOutputHeight - 2*aPos.Y(),LogicToPixel(Size(0,m_aText.GetTextHeight())).Height());
256     m_aText.SetPosSizePixel(aPos,Size(aRulerPos.X() - aPos.X(),nHeight));
257 
258     aPos.X() = aExtraWidth;
259     aPos.Y() += static_cast<sal_Int32>((LogicToPixel(Size(0,m_aText.GetTextHeight())).Height() - aImageSize.Height()) * 0.5) ;
260     m_aImage.SetPosSizePixel(aPos,aImageSize);
261 }
262 // -----------------------------------------------------------------------------
setTitle(const String & _sTitle)263 void OStartMarker::setTitle(const String& _sTitle)
264 {
265     m_aText.SetText(_sTitle);
266 }
267 // -----------------------------------------------------------------------------
Notify(SfxBroadcaster & rBc,SfxHint const & rHint)268 void OStartMarker::Notify(SfxBroadcaster & rBc, SfxHint const & rHint)
269 {
270     OColorListener::Notify(rBc, rHint);
271     if (rHint.ISA(SfxSimpleHint)
272         && (static_cast< SfxSimpleHint const & >(rHint).GetId()
273             == SFX_HINT_COLORS_CHANGED))
274     {
275         setColor();
276         Invalidate(INVALIDATE_CHILDREN);
277     }
278 }
279 //----------------------------------------------------------------------------
showRuler(sal_Bool _bShow)280 void OStartMarker::showRuler(sal_Bool _bShow)
281 {
282     m_bShowRuler = _bShow;
283     m_aVRuler.Show(!m_bCollapsed && m_bShowRuler);
284 }
285 //------------------------------------------------------------------------------
RequestHelp(const HelpEvent & rHEvt)286 void OStartMarker::RequestHelp( const HelpEvent& rHEvt )
287 {
288     if( m_aText.GetText().Len())
289     {
290         // Hilfe anzeigen
291         Rectangle aItemRect(rHEvt.GetMousePosPixel(),Size(GetSizePixel().Width(),getMinHeight()));
292         //aItemRect = LogicToPixel( aItemRect );
293         Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
294         aItemRect.Left()   = aPt.X();
295         aItemRect.Top()    = aPt.Y();
296         aPt = OutputToScreenPixel( aItemRect.BottomRight() );
297         aItemRect.Right()  = aPt.X();
298         aItemRect.Bottom() = aPt.Y();
299         if( rHEvt.GetMode() == HELPMODE_BALLOON )
300             Help::ShowBalloon( this, aItemRect.Center(), aItemRect, m_aText.GetText());
301         else
302             Help::ShowQuickHelp( this, aItemRect, m_aText.GetText() );
303     }
304 }
305 // -----------------------------------------------------------------------------
setCollapsed(sal_Bool _bCollapsed)306 void OStartMarker::setCollapsed(sal_Bool _bCollapsed)
307 {
308     OColorListener::setCollapsed(_bCollapsed);
309     showRuler(_bCollapsed);
310     changeImage();
311 }
312 // -----------------------------------------------------------------------
zoom(const Fraction & _aZoom)313 void OStartMarker::zoom(const Fraction& _aZoom)
314 {
315     setZoomFactor(_aZoom,*this);
316     m_aVRuler.SetZoom(_aZoom);
317     setZoomFactor(_aZoom,m_aText);
318     Resize();
319     Invalidate();
320 }
321 // -----------------------------------------------------------------------
322 // =======================================================================
323 }
324 // =======================================================================
325