1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <vcl/svapp.hxx>
#include "svx/connctrl.hxx"
#include "svx/dlgutil.hxx"
#include <svx/dialmgr.hxx>
#include <svx/sdr/contact/displayinfo.hxx>
#include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
#include <svx/svdmark.hxx>
#include <svx/svdoedge.hxx>
#include <svx/svdpage.hxx>
#include <svx/svdview.hxx>
#include <svx/sxelditm.hxx>
#include <sxmkitm.hxx>
#include <vcl/builderfactory.hxx>
#include <vcl/settings.hxx>
#include <memory>
SvxXConnectionPreview::SvxXConnectionPreview( vcl::Window* pParent, WinBits nStyle)
: Control(pParent, nStyle)
, pEdgeObj(nullptr)
, pObjList(nullptr)
, pView(nullptr)
{
SetMapMode( MapUnit::Map100thMM );
SetStyles();
}
VCL_BUILDER_DECL_FACTORY(SvxXConnectionPreview)
{
WinBits nWinStyle = 0;
OString sBorder = VclBuilder::extractCustomProperty(rMap);
if (!sBorder.isEmpty())
nWinStyle |= WB_BORDER;
rRet = VclPtr<SvxXConnectionPreview>::Create(pParent, nWinStyle);
}
SvxXConnectionPreview::~SvxXConnectionPreview()
{
disposeOnce();
}
void SvxXConnectionPreview::dispose()
{
delete pObjList;
Control::dispose();
}
void SvxXConnectionPreview::Resize()
{
Control::Resize();
AdaptSize();
Invalidate();
}
Size SvxXConnectionPreview::GetOptimalSize() const
{
return LogicToPixel(Size(118 , 121), MapMode(MapUnit::MapAppFont));
}
void SvxXConnectionPreview::AdaptSize()
{
// Adapt size
if( pObjList )
{
SetMapMode( MapUnit::Map100thMM );
OutputDevice* pOD = pView->GetFirstOutputDevice(); // GetWin( 0 );
Rectangle aRect = pObjList->GetAllObjBoundRect();
MapMode aMapMode = GetMapMode();
aMapMode.SetMapUnit( pOD->GetMapMode().GetMapUnit() );
SetMapMode( aMapMode );
MapMode aDisplayMap( aMapMode );
Point aNewPos;
Size aNewSize;
const Size aWinSize = PixelToLogic( GetOutputSizePixel(), aDisplayMap );
const long nWidth = aWinSize.Width();
const long nHeight = aWinSize.Height();
if (aRect.GetHeight() == 0)
return;
double fRectWH = (double) aRect.GetWidth() / aRect.GetHeight();
if (nHeight == 0)
return;
double fWinWH = (double) nWidth / nHeight;
// Adapt bitmap to Thumb size (not here!)
if ( fRectWH < fWinWH)
{
aNewSize.Width() = (long) ( (double) nHeight * fRectWH );
aNewSize.Height()= nHeight;
}
else
{
aNewSize.Width() = nWidth;
aNewSize.Height()= (long) ( (double) nWidth / fRectWH );
}
Fraction aFrac1( aWinSize.Width(), aRect.GetWidth() );
Fraction aFrac2( aWinSize.Height(), aRect.GetHeight() );
Fraction aMinFrac( aFrac1 <= aFrac2 ? aFrac1 : aFrac2 );
// Implement MapMode
aDisplayMap.SetScaleX( aMinFrac );
aDisplayMap.SetScaleY( aMinFrac );
// Centering
aNewPos.X() = ( nWidth - aNewSize.Width() ) >> 1;
aNewPos.Y() = ( nHeight - aNewSize.Height() ) >> 1;
aDisplayMap.SetOrigin( LogicToLogic( aNewPos, aMapMode, aDisplayMap ) );
SetMapMode( aDisplayMap );
// Origin
aNewPos = aDisplayMap.GetOrigin();
aNewPos -= Point( aRect.TopLeft().X(), aRect.TopLeft().Y() );
aDisplayMap.SetOrigin( aNewPos );
SetMapMode( aDisplayMap );
Point aPos;
MouseEvent aMEvt( aPos, 1, MouseEventModifiers::NONE, MOUSE_RIGHT );
MouseButtonDown( aMEvt );
}
}
void SvxXConnectionPreview::Construct()
{
DBG_ASSERT( pView, "No valid view is passed on! ");
const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
const size_t nMarkCount = rMarkList.GetMarkCount();
if( nMarkCount >= 1 )
{
bool bFound = false;
for( size_t i = 0; i < nMarkCount && !bFound; ++i )
{
const SdrObject* pObj = rMarkList.GetMark( i )->GetMarkedSdrObj();
sal_uInt32 nInv = pObj->GetObjInventor();
sal_uInt16 nId = pObj->GetObjIdentifier();
if( nInv == SdrInventor && nId == OBJ_EDGE )
{
bFound = true;
const SdrEdgeObj* pTmpEdgeObj = static_cast<const SdrEdgeObj*>(pObj);
pEdgeObj = pTmpEdgeObj->Clone();
SdrObjConnection& rConn1 = (SdrObjConnection&)pEdgeObj->GetConnection( true );
SdrObjConnection& rConn2 = (SdrObjConnection&)pEdgeObj->GetConnection( false );
rConn1 = pTmpEdgeObj->GetConnection( true );
rConn2 = pTmpEdgeObj->GetConnection( false );
SdrObject* pTmpObj1 = pTmpEdgeObj->GetConnectedNode( true );
SdrObject* pTmpObj2 = pTmpEdgeObj->GetConnectedNode( false );
// potential memory leak here (!). Create SdrObjList only when there is
// not yet one.
if(!pObjList)
{
pObjList = new SdrObjList( pView->GetModel(), nullptr );
}
if( pTmpObj1 )
{
SdrObject* pObj1 = pTmpObj1->Clone();
pObjList->InsertObject( pObj1 );
pEdgeObj->ConnectToNode( true, pObj1 );
}
if( pTmpObj2 )
{
SdrObject* pObj2 = pTmpObj2->Clone();
pObjList->InsertObject( pObj2 );
pEdgeObj->ConnectToNode( false, pObj2 );
}
pObjList->InsertObject( pEdgeObj );
}
}
}
if( !pEdgeObj )
pEdgeObj = new SdrEdgeObj();
AdaptSize();
}
void SvxXConnectionPreview::Paint(vcl::RenderContext& rRenderContext, const Rectangle&)
{
if (pObjList)
{
// This will not work anymore. To not start at Adam and Eve, i will
// ATM not try to change all this stuff to really using an own model
// and a view. I will just try to provide a mechanism to paint such
// objects without own model and without a page/view with the new
// mechanism.
// New stuff: Use a ObjectContactOfObjListPainter.
sdr::contact::SdrObjectVector aObjectVector;
for (size_t a = 0; a < pObjList->GetObjCount(); ++a)
{
SdrObject* pObject = pObjList->GetObj(a);
DBG_ASSERT(pObject,
"SvxXConnectionPreview::Paint: Corrupt ObjectList (!)");
aObjectVector.push_back(pObject);
}
sdr::contact::ObjectContactOfObjListPainter aPainter(rRenderContext, aObjectVector, nullptr);
sdr::contact::DisplayInfo aDisplayInfo;
// do processing
aPainter.ProcessDisplay(aDisplayInfo);
}
}
void SvxXConnectionPreview::SetAttributes( const SfxItemSet& rInAttrs )
{
pEdgeObj->SetMergedItemSetAndBroadcast(rInAttrs);
Invalidate();
}
// Get number of lines which are offset based on the preview object
sal_uInt16 SvxXConnectionPreview::GetLineDeltaCount()
{
const SfxItemSet& rSet = pEdgeObj->GetMergedItemSet();
sal_uInt16 nCount(0);
if(SfxItemState::DONTCARE != rSet.GetItemState(SDRATTR_EDGELINEDELTAANZ))
nCount = static_cast<const SdrEdgeLineDeltaCountItem&>(rSet.Get(SDRATTR_EDGELINEDELTAANZ)).GetValue();
return nCount;
}
void SvxXConnectionPreview::MouseButtonDown( const MouseEvent& rMEvt )
{
bool bZoomIn = rMEvt.IsLeft() && !rMEvt.IsShift();
bool bZoomOut = rMEvt.IsRight() || rMEvt.IsShift();
bool bCtrl = rMEvt.IsMod1();
if( bZoomIn || bZoomOut )
{
MapMode aMapMode = GetMapMode();
Fraction aXFrac = aMapMode.GetScaleX();
Fraction aYFrac = aMapMode.GetScaleY();
std::unique_ptr<Fraction> pMultFrac;
if( bZoomIn )
{
if( bCtrl )
pMultFrac.reset(new Fraction( 3, 2 ));
else
pMultFrac.reset(new Fraction( 11, 10 ));
}
else
{
if( bCtrl )
pMultFrac.reset(new Fraction( 2, 3 ));
else
pMultFrac.reset(new Fraction( 10, 11 ));
}
aXFrac *= *pMultFrac;
aYFrac *= *pMultFrac;
if( (double)aXFrac > 0.001 && (double)aXFrac < 1000.0 &&
(double)aYFrac > 0.001 && (double)aYFrac < 1000.0 )
{
aMapMode.SetScaleX( aXFrac );
aMapMode.SetScaleY( aYFrac );
SetMapMode( aMapMode );
Size aOutSize( GetOutputSize() );
Point aPt( aMapMode.GetOrigin() );
long nX = (long)( ( (double)aOutSize.Width() - ( (double)aOutSize.Width() * (double)*pMultFrac ) ) / 2.0 + 0.5 );
long nY = (long)( ( (double)aOutSize.Height() - ( (double)aOutSize.Height() * (double)*pMultFrac ) ) / 2.0 + 0.5 );
aPt.X() += nX;
aPt.Y() += nY;
aMapMode.SetOrigin( aPt );
SetMapMode( aMapMode );
Invalidate();
}
}
}
void SvxXConnectionPreview::SetStyles()
{
const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
SetBackground( Wallpaper( Color( rStyles.GetFieldColor() ) ) );
}
void SvxXConnectionPreview::DataChanged( const DataChangedEvent& rDCEvt )
{
Control::DataChanged( rDCEvt );
if ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) && (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
{
SetStyles();
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|