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>
28#include <vcl/ptrstyle.hxx>
29
30using 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() ).Contains( 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.Contains( aLogPt );
186 ReleaseMouse();
187
188 if ( bPipetteMode )
189 {
191
192 aPipetteClickLink.Call( *this );
193
194 return true;
195 }
196 else if ( bWorkplaceMode )
197 {
199
200 aWorkRect.SetRight( aLogPt.X() );
201 aWorkRect.SetBottom( aLogPt.Y() );
202 aWorkRect.Intersection( aGraphRect );
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
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();
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
246 {
247 tools::PolyPolygon _aPolyPoly(2);
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: */
bool bClickValid
Definition: contwnd.hxx:36
tools::PolyPolygon aPolyPoly
Definition: contwnd.hxx:28
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: contwnd.cxx:139
bool IsContourChanged() const
Definition: contwnd.cxx:128
void SetPolyPolygon(const tools::PolyPolygon &rPolyPoly)
Definition: contwnd.cxx:43
const tools::PolyPolygon & GetPolyPolygon()
Definition: contwnd.cxx:87
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
Definition: contwnd.cxx:262
Link< ContourWindow &, void > aPipetteClickLink
Definition: contwnd.hxx:32
virtual bool MouseMove(const MouseEvent &rMEvt) override
Definition: contwnd.cxx:157
virtual void SdrObjCreated(const SdrObject &rObj) override
Definition: contwnd.cxx:122
virtual void InitSdrModel() override
Definition: contwnd.cxx:110
Link< ContourWindow &, void > aPipetteLink
Definition: contwnd.hxx:31
Color aPipetteColor
Definition: contwnd.hxx:29
bool bWorkplaceMode
Definition: contwnd.hxx:35
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: contwnd.cxx:226
tools::Rectangle aWorkRect
Definition: contwnd.hxx:30
virtual bool MouseButtonUp(const MouseEvent &rMEvt) override
Definition: contwnd.cxx:180
ContourWindow(weld::Dialog *pDialog)
Definition: contwnd.cxx:34
bool bPipetteMode
Definition: contwnd.hxx:34
Link< ContourWindow &, void > aWorkplaceClickLink
Definition: contwnd.hxx:33
virtual bool MouseButtonUp(const MouseEvent &rMEvt) override
Definition: graphctl.cxx:668
void SetSdrMode(bool b)
Definition: graphctl.cxx:92
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: graphctl.cxx:587
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
Definition: graphctl.cxx:69
std::unique_ptr< SdrView > pView
Definition: graphctl.hxx:75
std::unique_ptr< SdrModel > pModel
Definition: graphctl.hxx:74
void SetEditMode(const bool bEditMode)
Definition: graphctl.cxx:705
const Graphic & GetGraphic() const
Definition: graphctl.hxx:101
virtual bool MouseMove(const MouseEvent &rMEvt) override
Definition: graphctl.cxx:632
virtual void InitSdrModel()
Definition: graphctl.cxx:112
const Size & GetGraphicSize() const
Definition: graphctl.hxx:102
GraphicType GetType() const
void Draw(OutputDevice &rOutDev, const Point &rDestPt) const
const Point & GetPosPixel() const
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
Color GetPixel(const Point &rPt) const
void ClearSdrObjList()
Definition: svdpage.cxx:105
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
Definition: svdpage.cxx:327
SdrObject * GetObj(size_t nNum) const
Definition: svdpage.cxx:805
size_t GetObjCount() const
Definition: svdpage.cxx:799
Abstract DrawObject.
Definition: svdobj.hxx:261
void SetMergedItemSetAndBroadcast(const SfxItemSet &rSet, bool bClearAllItems=false)
Definition: svdobj.cxx:2017
A SdrPage contains exactly one SdrObjList and a description of the physical page dimensions (size / m...
Definition: svdpage.hxx:374
OutputDevice & GetTargetOutputDevice()
void SetOutputToWindow(bool bOutputToWindow)
const basegfx::B2DPolyPolygon & GetPathPoly() const
Definition: svdopath.hxx:141
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
constexpr tools::Long Height() const
constexpr tools::Long Width() const
void append(const B2DPolygon &rPolygon, sal_uInt32 nCount=1)
sal_uInt16 Count() const
void Clip(const tools::Rectangle &rRect)
void Insert(const tools::Polygon &rPoly, sal_uInt16 nPos=POLYPOLY_APPEND)
bool Contains(const Point &rPOINT) const
constexpr tools::Long Top() const
constexpr void SetRight(tools::Long v)
constexpr tools::Long Right() const
constexpr void SetBottom(tools::Long v)
tools::Rectangle & Intersection(const tools::Rectangle &rRect)
constexpr tools::Long Left() const
constexpr tools::Long Bottom() const
void SetPointer(PointerStyle ePointerStyle)
virtual bool MouseMove(const MouseEvent &)
weld::DrawingArea * GetDrawingArea() const
virtual bool MouseButtonUp(const MouseEvent &)
void SetOutputSizePixel(const Size &rSize)
virtual OutputDevice & get_ref_device()=0
virtual void set_size_request(int nWidth, int nHeight)=0
constexpr ::Color COL_LIGHTRED(0xFF, 0x00, 0x00)
constexpr ::Color COL_WHITE(0xFF, 0xFF, 0xFF)
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
#define TRANSCOL
Definition: contwnd.cxx:32
FilterGroup & rTarget
B2DPolygon adaptiveSubdivideByAngle(const B2DPolygon &rCandidate, double fAngleBound)
int i
@ PathFill
open Bezier-curve