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