LibreOffice Module svx (master)  1
contwnd.cxx
Go to the documentation of this file.
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 "contwnd.hxx"
21 #include <svx/svdpage.hxx>
22 #include <svx/svdopath.hxx>
23 #include <svx/xfillit0.hxx>
24 #include <svx/xfltrit.hxx>
25 #include <svx/xflclit.hxx>
27 #include <svx/sdrpaintwindow.hxx>
28 #include <vcl/ptrstyle.hxx>
29 
30 using namespace css;
31 
32 #define TRANSCOL COL_WHITE
33 
35  : GraphCtrl(pDialog)
36  , aWorkRect(0, 0, 0, 0)
37  , bPipetteMode(false)
38  , bWorkplaceMode(false)
39  , bClickValid(false)
40 {
41 }
42 
44 {
45  SdrPage* pPage = pModel->GetPage(0);
46  const sal_uInt16 nPolyCount = rPolyPoly.Count();
47 
48  // First delete all drawing objects
49  aPolyPoly = rPolyPoly;
50 
51  // To avoid to have destroyed objects which are still selected, it is necessary to deselect
52  // them first (!)
53  pView->UnmarkAllObj();
54 
55  // clear SdrObjects with broadcasting
56  pPage->ClearSdrObjList();
57 
58  for (sal_uInt16 i = 0; i < nPolyCount; i++)
59  {
60  basegfx::B2DPolyPolygon aPolyPolygon;
61  aPolyPolygon.append(aPolyPoly[ i ].getB2DPolygon());
62  SdrPathObj* pPathObj = new SdrPathObj(
63  *pModel,
65  aPolyPolygon);
66 
67  SfxItemSet aSet(pModel->GetItemPool());
68 
69  aSet.Put(XFillStyleItem(drawing::FillStyle_SOLID));
70  aSet.Put(XFillColorItem("", TRANSCOL));
71  aSet.Put(XFillTransparenceItem(50) );
72 
73  pPathObj->SetMergedItemSetAndBroadcast(aSet);
74 
75  pPage->InsertObject( pPathObj );
76  }
77 
78  if (nPolyCount)
79  {
80  pView->MarkAll();
81  pView->CombineMarkedObjects(false);
82  }
83 
84  pModel->SetChanged(false);
85 }
86 
88 {
89  if ( pModel->IsChanged() )
90  {
91  SdrPage* pPage = pModel->GetPage( 0 );
92 
94 
95  if ( pPage && pPage->GetObjCount() )
96  {
97  SdrPathObj* pPathObj = static_cast<SdrPathObj*>(pPage->GetObj(0));
98  // Not sure if subdivision is needed for ContourWindow, but maybe it cannot handle
99  // curves at all. Keeping subdivision here for security
101  aPolyPoly = tools::PolyPolygon(aB2DPolyPolygon);
102  }
103 
104  pModel->SetChanged( false );
105  }
106 
107  return aPolyPoly;
108 }
109 
111 {
113 
114  SfxItemSet aSet( pModel->GetItemPool() );
115 
116  aSet.Put( XFillColorItem( "", TRANSCOL ) );
117  aSet.Put( XFillTransparenceItem( 50 ) );
118  pView->SetAttributes( aSet );
119  pView->SetFrameDragSingles();
120 }
121 
123 {
124  pView->MarkAll();
125  pView->CombineMarkedObjects( false );
126 }
127 
129 {
130  SdrPage* pPage = pModel->GetPage( 0 );
131  bool bRet = false;
132 
133  if ( pPage && pPage->GetObjCount() )
134  bRet = static_cast<SdrPathObj*>( pPage->GetObj( 0 ) )->GetPathPoly().count() && pModel->IsChanged();
135 
136  return bRet;
137 }
138 
140 {
141  if ( bWorkplaceMode )
142  {
143  const Point aLogPt(GetDrawingArea()->get_ref_device().PixelToLogic(rMEvt.GetPosPixel()));
144 
146  aWorkRect = tools::Rectangle( aLogPt, aLogPt );
148  SetEditMode( true );
149  }
150 
151  if (!bPipetteMode)
152  return GraphCtrl::MouseButtonDown( rMEvt );
153 
154  return true;
155 }
156 
158 {
159  bClickValid = false;
160 
161  if ( bPipetteMode )
162  {
163  const Point aLogPt( GetDrawingArea()->get_ref_device().PixelToLogic( rMEvt.GetPosPixel() ) );
164 
167 
168  if ( aPipetteLink.IsSet() && tools::Rectangle( Point(), GetGraphicSize() ).IsInside( aLogPt ) )
169  {
170  SetPointer( PointerStyle::RefHand );
171  aPipetteLink.Call( *this );
172  }
173 
174  return true;
175  }
176 
177  return GraphCtrl::MouseMove( rMEvt );
178 }
179 
181 {
182  const tools::Rectangle aGraphRect( Point(), GetGraphicSize() );
183  const Point aLogPt( GetDrawingArea()->get_ref_device().PixelToLogic( rMEvt.GetPosPixel() ) );
184 
185  bClickValid = aGraphRect.IsInside( aLogPt );
186  ReleaseMouse();
187 
188  if ( bPipetteMode )
189  {
191 
192  aPipetteClickLink.Call( *this );
193 
194  return true;
195  }
196  else if ( bWorkplaceMode )
197  {
198  GraphCtrl::MouseButtonUp( rMEvt );
199 
200  aWorkRect.SetRight( aLogPt.X() );
201  aWorkRect.SetBottom( aLogPt.Y() );
202  aWorkRect.Intersection( aGraphRect );
203  aWorkRect.Justify();
204 
205  if ( aWorkRect.Left() != aWorkRect.Right() && aWorkRect.Top() != aWorkRect.Bottom() )
206  {
207  tools::PolyPolygon _aPolyPoly( GetPolyPolygon() );
208 
209  _aPolyPoly.Clip( aWorkRect );
210  SetPolyPolygon( _aPolyPoly );
211  pView->SetWorkArea( aWorkRect );
212  }
213  else
214  pView->SetWorkArea( aGraphRect );
215 
216  Invalidate( aGraphRect );
217 
218  aWorkplaceClickLink.Call( *this );
219 
220  return false;
221  }
222 
223  return GraphCtrl::MouseButtonUp( rMEvt );
224 }
225 
226 void ContourWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
227 {
228  // #i75482#
229  // encapsulate the redraw using Begin/End and use the returned
230  // data to get the target output device (e.g. when pre-rendering)
231  SdrPaintWindow* pPaintWindow = pView->BeginCompleteRedraw(&rRenderContext);
232  pPaintWindow->SetOutputToWindow(true);
233  OutputDevice& rTarget = pPaintWindow->GetTargetOutputDevice();
234 
235  const Graphic& rGraphic = GetGraphic();
236  rTarget.Push(PushFlags::LINECOLOR |PushFlags::FILLCOLOR);
237  rTarget.SetLineColor(COL_BLACK);
238  rTarget.SetFillColor(COL_WHITE);
239  rTarget.DrawRect( tools::Rectangle( Point(), GetGraphicSize() ) );
240  rTarget.Pop();
241 
242  if (rGraphic.GetType() != GraphicType::NONE)
243  rGraphic.Draw(&rTarget, Point(), GetGraphicSize());
244 
245  if (aWorkRect.Left() != aWorkRect.Right() && aWorkRect.Top() != aWorkRect.Bottom())
246  {
247  tools::PolyPolygon _aPolyPoly(2);
248  rTarget.Push(PushFlags::FILLCOLOR);
249  _aPolyPoly.Insert(tools::Rectangle(Point(), GetGraphicSize()));
250  _aPolyPoly.Insert(aWorkRect);
251  rTarget.SetFillColor(COL_LIGHTRED);
252  rTarget.DrawTransparent(_aPolyPoly, 50);
253  rTarget.Pop();
254  }
255 
256  // #i75482#
257  const vcl::Region aRepaintRegion(rRect);
258  pView->DoCompleteRedraw(*pPaintWindow, aRepaintRegion);
259  pView->EndCompleteRedraw(*pPaintWindow, true);
260 }
261 
263 {
264  GraphCtrl::SetDrawingArea(pDrawingArea);
265  Size aSize(pDrawingArea->get_ref_device().LogicToPixel(Size(270, 170), MapMode(MapUnit::MapAppFont)));
266  pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
267  SetOutputSizePixel(aSize);
268  SetSdrMode(true);
269 }
270 
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 Count() const
bool bPipetteMode
Definition: contwnd.hxx:34
const Graphic & GetGraphic() const
Definition: graphctl.hxx:101
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
Definition: graphctl.cxx:67
constexpr::Color COL_BLACK(0x00, 0x00, 0x00)
std::unique_ptr< SdrModel > pModel
Definition: graphctl.hxx:74
tools::Rectangle & Intersection(const tools::Rectangle &rRect)
const tools::PolyPolygon & GetPolyPolygon()
Definition: contwnd.cxx:87
FilterGroup & rTarget
virtual bool MouseButtonUp(const MouseEvent &)
SdrObject * GetObj(size_t nNum) const
Definition: svdpage.cxx:758
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
Definition: contwnd.cxx:262
size_t GetObjCount() const
Definition: svdpage.cxx:752
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: contwnd.cxx:226
constexpr::Color COL_LIGHTRED(0xFF, 0x00, 0x00)
virtual bool MouseMove(const MouseEvent &)
virtual bool MouseButtonUp(const MouseEvent &rMEvt) override
Definition: contwnd.cxx:180
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
Definition: svdpage.cxx:343
ContourWindow(weld::Dialog *pDialog)
Definition: contwnd.cxx:34
tools::Rectangle aWorkRect
Definition: contwnd.hxx:30
long Right() const
OutputDevice & GetTargetOutputDevice()
const Size & GetGraphicSize() const
Definition: graphctl.hxx:102
void Insert(const tools::Polygon &rPoly, sal_uInt16 nPos=POLYPOLY_APPEND)
long Top() const
virtual OutputDevice & get_ref_device()=0
void DrawRect(const tools::Rectangle &rRect)
Link< ContourWindow &, void > aWorkplaceClickLink
Definition: contwnd.hxx:33
bool bClickValid
Definition: contwnd.hxx:36
void SetLineColor()
Link< ContourWindow &, void > aPipetteClickLink
Definition: contwnd.hxx:32
void Draw(OutputDevice *pOutDev, const Point &rDestPt) const
int i
GraphicType GetType() const
virtual void InitSdrModel()
Definition: graphctl.cxx:107
void DrawTransparent(const tools::PolyPolygon &rPolyPoly, sal_uInt16 nTransparencePercent)
Link< ContourWindow &, void > aPipetteLink
Definition: contwnd.hxx:31
void SetRight(long v)
void SetOutputToWindow(bool bOutputToWindow)
void SetFillColor()
void SetMergedItemSetAndBroadcast(const SfxItemSet &rSet, bool bClearAllItems=false)
Definition: svdobj.cxx:1929
long Bottom() const
virtual bool MouseMove(const MouseEvent &rMEvt) override
Definition: graphctl.cxx:625
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: graphctl.cxx:580
bool IsInside(const Point &rPOINT) const
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: contwnd.cxx:139
Abstract DrawObject.
Definition: svdobj.hxx:312
void SetOutputSizePixel(const Size &rSize)
virtual bool MouseMove(const MouseEvent &rMEvt) override
Definition: contwnd.cxx:157
Point LogicToPixel(const Point &rLogicPt) const
void Clip(const tools::Rectangle &rRect)
void append(const B2DPolygon &rPolygon, sal_uInt32 nCount=1)
tools::PolyPolygon aPolyPoly
Definition: contwnd.hxx:28
weld::DrawingArea * GetDrawingArea() const
B2DPolygon adaptiveSubdivideByAngle(const B2DPolygon &rCandidate, double fAngleBound)
bool bWorkplaceMode
Definition: contwnd.hxx:35
virtual void SdrObjCreated(const SdrObject &rObj) override
Definition: contwnd.cxx:122
void ClearSdrObjList()
Definition: svdpage.cxx:119
virtual void InitSdrModel() override
Definition: contwnd.cxx:110
void SetBottom(long v)
#define TRANSCOL
Definition: contwnd.cxx:32
std::unique_ptr< SdrView > pView
Definition: graphctl.hxx:75
const Point & GetPosPixel() const
constexpr::Color COL_WHITE(0xFF, 0xFF, 0xFF)
long Left() const
const basegfx::B2DPolyPolygon & GetPathPoly() const
Definition: svdopath.hxx:139
bool IsContourChanged() const
Definition: contwnd.cxx:128
void SetSdrMode(bool b)
Definition: graphctl.cxx:87
A SdrPage contains exactly one SdrObjList and a description of the physical page dimensions (size / m...
Definition: svdpage.hxx:365
Color GetPixel(const Point &rPt) const
Color aPipetteColor
Definition: contwnd.hxx:29
void SetEditMode(const bool bEditMode)
Definition: graphctl.cxx:698
void SetPolyPolygon(const tools::PolyPolygon &rPolyPoly)
Definition: contwnd.cxx:43
virtual void set_size_request(int nWidth, int nHeight)=0
void Push(PushFlags nFlags=PushFlags::ALL)
void SetPointer(PointerStyle ePointerStyle)
virtual bool MouseButtonUp(const MouseEvent &rMEvt) override
Definition: graphctl.cxx:661
open Bezier-curve
Definition: svdobj.hxx:128