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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412 | /* -*- 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 <ScrollHelper.hxx>
#include <DesignView.hxx>
#include <ReportController.hxx>
#include <ReportWindow.hxx>
#include <UITools.hxx>
#include <com/sun/star/accessibility/AccessibleRole.hpp>
#include <vcl/commandevent.hxx>
#include <vcl/settings.hxx>
#include <vcl/svapp.hxx>
namespace rptui
{
#define SECTION_OFFSET 3
#define SCR_LINE_SIZE 10
using namespace ::com::sun::star;
static void lcl_setScrollBar(sal_Int32 _nNewValue,const Point& _aPos,const Size& _aSize,ScrollBar& _rScrollBar)
{
_rScrollBar.SetPosSizePixel(_aPos,_aSize);
_rScrollBar.SetPageSize( _nNewValue );
_rScrollBar.SetVisibleSize( _nNewValue );
}
OScrollWindowHelper::OScrollWindowHelper( ODesignView* _pDesignView)
: OScrollWindowHelper_BASE( _pDesignView,WB_DIALOGCONTROL)
,OPropertyChangeListener(m_aMutex)
,m_aHScroll( VclPtr<ScrollBar>::Create(this, WB_HSCROLL|WB_REPEAT|WB_DRAG) )
,m_aVScroll( VclPtr<ScrollBar>::Create(this, WB_VSCROLL|WB_REPEAT|WB_DRAG) )
,m_aCornerWin( VclPtr<ScrollBarBox>::Create(this) )
,m_pParent(_pDesignView)
,m_aReportWindow(VclPtr<rptui::OReportWindow>::Create(this,m_pParent))
{
SetMapMode( MapMode( MapUnit::Map100thMM ) );
impl_initScrollBar( *m_aHScroll );
impl_initScrollBar( *m_aVScroll );
m_aReportWindow->SetMapMode( MapMode( MapUnit::Map100thMM ) );
m_aReportWindow->Show();
// normally we should be SCROLL_PANE
SetAccessibleRole(css::accessibility::AccessibleRole::SCROLL_PANE);
ImplInitSettings();
}
OScrollWindowHelper::~OScrollWindowHelper()
{
disposeOnce();
}
void OScrollWindowHelper::dispose()
{
if ( m_pReportDefinitionMultiPlexer.is() )
m_pReportDefinitionMultiPlexer->dispose();
m_aHScroll.disposeAndClear();
m_aVScroll.disposeAndClear();
m_aCornerWin.disposeAndClear();
m_aReportWindow.disposeAndClear();
m_pParent.clear();
OScrollWindowHelper_BASE::dispose();
}
void OScrollWindowHelper::impl_initScrollBar( ScrollBar& _rScrollBar ) const
{
AllSettings aSettings( _rScrollBar.GetSettings() );
StyleSettings aStyle( aSettings.GetStyleSettings() );
aStyle.SetDragFullOptions( aStyle.GetDragFullOptions() | DragFullOptions::Scroll ); // live scrolling
aSettings.SetStyleSettings( aStyle );
_rScrollBar.SetSettings( aSettings );
_rScrollBar.SetScrollHdl( LINK( const_cast<OScrollWindowHelper*>(this), OScrollWindowHelper, ScrollHdl ) );
_rScrollBar.SetLineSize( SCR_LINE_SIZE );
}
void OScrollWindowHelper::initialize()
{
uno::Reference<report::XReportDefinition> xReportDefinition = m_pParent->getController().getReportDefinition();
m_pReportDefinitionMultiPlexer = addStyleListener(xReportDefinition,this);
}
void OScrollWindowHelper::setTotalSize(sal_Int32 _nWidth ,sal_Int32 _nHeight)
{
m_aTotalPixelSize.setWidth( _nWidth );
m_aTotalPixelSize.setHeight( _nHeight );
// now set the ranges without start marker
Fraction aStartWidth(REPORT_STARTMARKER_WIDTH * m_pParent->getController().getZoomValue(),100);
long nWidth = long(_nWidth - static_cast<double>(aStartWidth));
m_aHScroll->SetRangeMax( nWidth );
m_aVScroll->SetRangeMax( m_aTotalPixelSize.Height() );
Resize();
}
Size OScrollWindowHelper::ResizeScrollBars()
{
// get the new output-size in pixel
Size aOutPixSz = GetOutputSizePixel();
if ( aOutPixSz.IsEmpty() )
return aOutPixSz;
aOutPixSz.AdjustHeight( -(m_aReportWindow->getRulerHeight()) );
// determine the size of the output-area and if we need scrollbars
const long nScrSize = GetSettings().GetStyleSettings().GetScrollBarSize();
bool bVVisible = false; // by default no vertical-ScrollBar
bool bHVisible = false; // by default no horizontal-ScrollBar
bool bChanged; // determines if a visiblility was changed
do
{
bChanged = false;
// does we need a vertical ScrollBar
if ( aOutPixSz.Width() < m_aTotalPixelSize.Width() && !bHVisible )
{
bHVisible = true;
aOutPixSz.AdjustHeight( -nScrSize );
bChanged = true;
}
// does we need a horizontal ScrollBar
if ( aOutPixSz.Height() < m_aTotalPixelSize.Height() && !bVVisible )
{
bVVisible = true;
aOutPixSz.AdjustWidth( -nScrSize );
bChanged = true;
}
}
while ( bChanged ); // until no visibility has changed
aOutPixSz.AdjustHeight(m_aReportWindow->getRulerHeight() );
// show or hide scrollbars
m_aVScroll->Show( bVVisible );
m_aHScroll->Show( bHVisible );
// disable painting in the corner between the scrollbars
if ( bVVisible && bHVisible )
{
m_aCornerWin->SetPosSizePixel(Point(aOutPixSz.Width(), aOutPixSz.Height()), Size(nScrSize, nScrSize) );
m_aCornerWin->Show();
}
else
m_aCornerWin->Hide();
const Point aOffset = LogicToPixel(Point(SECTION_OFFSET, SECTION_OFFSET), MapMode(MapUnit::MapAppFont));
// resize scrollbars and set their ranges
{
Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH*m_pParent->getController().getZoomValue()),100);
const sal_Int32 nNewWidth = aOutPixSz.Width() - aOffset.X() - static_cast<long>(aStartWidth);
lcl_setScrollBar(nNewWidth,Point( static_cast<long>(aStartWidth) + aOffset.X(), aOutPixSz.Height() ), Size( nNewWidth, nScrSize ), *m_aHScroll);
}
{
const sal_Int32 nNewHeight = aOutPixSz.Height() - m_aReportWindow->getRulerHeight();
lcl_setScrollBar(nNewHeight,Point( aOutPixSz.Width(), m_aReportWindow->getRulerHeight() ), Size( nScrSize,nNewHeight), *m_aVScroll);
}
return aOutPixSz;
}
void OScrollWindowHelper::Resize()
{
OScrollWindowHelper_BASE::Resize();
const Size aTotalOutputSize = ResizeScrollBars();
m_aReportWindow->SetPosSizePixel(Point( 0, 0 ),aTotalOutputSize);
}
IMPL_LINK( OScrollWindowHelper, ScrollHdl, ScrollBar*, /*pScroll*/, void )<--- syntax error
{
m_aReportWindow->ScrollChildren( getThumbPos() );
}
void OScrollWindowHelper::addSection(const uno::Reference< report::XSection >& _xSection
,const OUString& _sColorEntry
,sal_uInt16 _nPosition)
{
m_aReportWindow->addSection(_xSection,_sColorEntry,_nPosition);
}
void OScrollWindowHelper::removeSection(sal_uInt16 _nPosition)
{
m_aReportWindow->removeSection(_nPosition);
}
void OScrollWindowHelper::toggleGrid(bool _bVisible)
{
m_aReportWindow->toggleGrid(_bVisible);
}
sal_uInt16 OScrollWindowHelper::getSectionCount() const
{
return m_aReportWindow->getSectionCount();
}
void OScrollWindowHelper::SetInsertObj( sal_uInt16 eObj,const OUString& _sShapeType )
{
m_aReportWindow->SetInsertObj(eObj,_sShapeType);
}
OUString const & OScrollWindowHelper::GetInsertObjString() const
{
return m_aReportWindow->GetInsertObjString();
}
void OScrollWindowHelper::SetMode( DlgEdMode _eNewMode )
{
m_aReportWindow->SetMode(_eNewMode);
}
bool OScrollWindowHelper::HasSelection() const
{
return m_aReportWindow->HasSelection();
}
void OScrollWindowHelper::Delete()
{
m_aReportWindow->Delete();
}
void OScrollWindowHelper::Copy()
{
m_aReportWindow->Copy();
}
void OScrollWindowHelper::Paste()
{
m_aReportWindow->Paste();
}
bool OScrollWindowHelper::IsPasteAllowed() const
{
return m_aReportWindow->IsPasteAllowed();
}
void OScrollWindowHelper::SelectAll(const sal_uInt16 _nObjectType)
{
m_aReportWindow->SelectAll(_nObjectType);
}
void OScrollWindowHelper::unmarkAllObjects()
{
m_aReportWindow->unmarkAllObjects();
}
sal_Int32 OScrollWindowHelper::getMaxMarkerWidth() const
{
return m_aReportWindow->getMaxMarkerWidth();
}
void OScrollWindowHelper::showRuler(bool _bShow)
{
m_aReportWindow->showRuler(_bShow);
}
bool OScrollWindowHelper::handleKeyEvent(const KeyEvent& _rEvent)
{
return m_aReportWindow->handleKeyEvent(_rEvent);
}
void OScrollWindowHelper::setMarked(OSectionView const * _pSectionView, bool _bMark)
{
m_aReportWindow->setMarked(_pSectionView,_bMark);
}
void OScrollWindowHelper::setMarked(const uno::Reference< report::XSection>& _xSection, bool _bMark)
{
m_aReportWindow->setMarked(_xSection,_bMark);
}
void OScrollWindowHelper::setMarked(const uno::Sequence< uno::Reference< report::XReportComponent> >& _xShape, bool _bMark)
{
m_aReportWindow->setMarked(_xShape,_bMark);
}
OSectionWindow* OScrollWindowHelper::getMarkedSection(NearSectionAccess nsa) const
{
return m_aReportWindow->getMarkedSection(nsa);
}
OSectionWindow* OScrollWindowHelper::getSectionWindow(const css::uno::Reference< css::report::XSection>& _xSection) const
{
return m_aReportWindow->getSectionWindow(_xSection);
}
void OScrollWindowHelper::markSection(const sal_uInt16 _nPos)
{
m_aReportWindow->markSection(_nPos);
}
void OScrollWindowHelper::fillCollapsedSections(::std::vector<sal_uInt16>& _rCollapsedPositions) const
{
m_aReportWindow->fillCollapsedSections(_rCollapsedPositions);
}
void OScrollWindowHelper::collapseSections(const uno::Sequence< css::beans::PropertyValue>& _aCollapsedSections)
{
m_aReportWindow->collapseSections(_aCollapsedSections);
}
bool OScrollWindowHelper::EventNotify( NotifyEvent& rNEvt )
{
const CommandEvent* pCommandEvent = rNEvt.GetCommandEvent();
if ( pCommandEvent &&
((pCommandEvent->GetCommand() == CommandEventId::Wheel) ||
(pCommandEvent->GetCommand() == CommandEventId::StartAutoScroll) ||
(pCommandEvent->GetCommand() == CommandEventId::AutoScroll)) )
{
ScrollBar* pHScrBar = nullptr;
ScrollBar* pVScrBar = nullptr;
if ( m_aHScroll->IsVisible() )
pHScrBar = m_aHScroll.get();
if ( m_aVScroll->IsVisible() )
pVScrBar = m_aVScroll.get();
if ( HandleScrollCommand( *pCommandEvent, pHScrBar, pVScrBar ) )
return true;
}
return OScrollWindowHelper_BASE::EventNotify(rNEvt);
}
void OScrollWindowHelper::alignMarkedObjects(ControlModification _nControlModification, bool _bAlignAtSection)
{
m_aReportWindow->alignMarkedObjects(_nControlModification, _bAlignAtSection);
}
void OScrollWindowHelper::ImplInitSettings()
{
SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor() ));
SetFillColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
SetTextFillColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
}
void OScrollWindowHelper::DataChanged( const DataChangedEvent& rDCEvt )
{
Window::DataChanged( rDCEvt );
if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
(rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
{
ImplInitSettings();
Invalidate();
}
}
void OScrollWindowHelper::_propertyChanged(const beans::PropertyChangeEvent& /*_rEvent*/)
{
m_aReportWindow->notifySizeChanged();
}
void OScrollWindowHelper::setGridSnap(bool bOn)
{
m_aReportWindow->setGridSnap(bOn);
}
void OScrollWindowHelper::setDragStripes(bool bOn)
{
m_aReportWindow->setDragStripes(bOn);
}
sal_uInt32 OScrollWindowHelper::getMarkedObjectCount() const
{
return m_aReportWindow->getMarkedObjectCount();
}
void OScrollWindowHelper::zoom(const Fraction& _aZoom)
{
m_aReportWindow->zoom(_aZoom);
Resize();
Invalidate(InvalidateFlags::NoChildren|InvalidateFlags::Transparent);
}
void OScrollWindowHelper::fillControlModelSelection(::std::vector< uno::Reference< uno::XInterface > >& _rSelection) const
{
m_aReportWindow->fillControlModelSelection(_rSelection);
}
sal_uInt16 OScrollWindowHelper::getZoomFactor(SvxZoomType _eType) const
{
return m_aReportWindow->getZoomFactor(_eType);
}
} // rptui
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|