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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
|
/* -*- 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 <string>
#include <vcl/toolbox.hxx>
#include <sfx2/app.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/objsh.hxx>
#include <svx/dialogs.hrc>
#include "helpid.hrc"
#include "svx/drawitem.hxx"
#include "svx/xattr.hxx"
#include <svx/xtable.hxx>
#include "svx/linectrl.hxx"
#include <svx/itemwin.hxx>
#include <svx/dialmgr.hxx>
#include <svx/unoapi.hxx>
#include <boost/scoped_ptr.hpp>
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::util;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star;
// For End Line Controlleer
#define MAX_LINES 12
SFX_IMPL_TOOLBOX_CONTROL( SvxLineStyleToolBoxControl, XLineStyleItem );
SFX_IMPL_TOOLBOX_CONTROL( SvxLineWidthToolBoxControl, XLineWidthItem );
SFX_IMPL_TOOLBOX_CONTROL( SvxLineEndToolBoxControl, SfxBoolItem );
SvxLineStyleToolBoxControl::SvxLineStyleToolBoxControl( sal_uInt16 nSlotId,
sal_uInt16 nId,
ToolBox& rTbx ) :
SfxToolBoxControl( nSlotId, nId, rTbx ),
pStyleItem ( NULL ),
pDashItem ( NULL ),
bUpdate ( false )
{
addStatusListener( OUString( ".uno:LineDash" ));
addStatusListener( OUString( ".uno:DashListState" ));
}
SvxLineStyleToolBoxControl::~SvxLineStyleToolBoxControl()
{
delete pStyleItem;
delete pDashItem;
}
void SvxLineStyleToolBoxControl::StateChanged (
sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
{
SvxLineBox* pBox = static_cast<SvxLineBox*>( GetToolBox().GetItemWindow( GetId() ) );
DBG_ASSERT( pBox, "Window not found!" );
if( eState == SfxItemState::DISABLED )
{
pBox->Disable();
pBox->SetNoSelection();
}
else
{
pBox->Enable();
if ( eState == SfxItemState::DEFAULT )
{
if( nSID == SID_ATTR_LINE_STYLE )
{
delete pStyleItem;
pStyleItem = static_cast<XLineStyleItem*>(pState->Clone());
}
else if( nSID == SID_ATTR_LINE_DASH )
{
delete pDashItem;
pDashItem = static_cast<XLineDashItem*>(pState->Clone());
}
bUpdate = true;
Update( pState );
}
else if ( nSID != SID_DASH_LIST )
{
// no or ambiguous status
pBox->SetNoSelection();
}
}
}
void SvxLineStyleToolBoxControl::Update( const SfxPoolItem* pState )
{
if ( pState && bUpdate )
{
bUpdate = false;
SvxLineBox* pBox = static_cast<SvxLineBox*>(GetToolBox().GetItemWindow( GetId() ));
DBG_ASSERT( pBox, "Window not found!" );
// Since the timer can strike unexpectedly, it may happen that
// the LB is not yet filled. A ClearCache() on the control
// in DelayHdl () was unsuccessful.
if( pBox->GetEntryCount() == 0 )
pBox->FillControl();
drawing::LineStyle eXLS;
if ( pStyleItem )
eXLS = ( drawing::LineStyle )pStyleItem->GetValue();
else
eXLS = drawing::LineStyle_NONE;
switch( eXLS )
{
case drawing::LineStyle_NONE:
pBox->SelectEntryPos( 0 );
break;
case drawing::LineStyle_SOLID:
pBox->SelectEntryPos( 1 );
break;
case drawing::LineStyle_DASH:
{
if( pDashItem )
{
OUString aString = SvxUnogetInternalNameForItem(
XATTR_LINEDASH, pDashItem->GetName());
pBox->SelectEntry( aString );
}
else
pBox->SetNoSelection();
}
break;
default:
OSL_FAIL( "Unsupported type of line" );
break;
}
}
if ( pState && ( pState->ISA( SvxDashListItem ) ) )
{
// The list of line styles has changed
SvxLineBox* pBox = static_cast<SvxLineBox*>(GetToolBox().GetItemWindow( GetId() ));
DBG_ASSERT( pBox, "Window not found!" );
OUString aString( pBox->GetSelectEntry() );
pBox->Clear();
pBox->InsertEntry( SVX_RESSTR(RID_SVXSTR_INVISIBLE) );
pBox->InsertEntry( SVX_RESSTR(RID_SVXSTR_SOLID) );
pBox->Fill( static_cast<const SvxDashListItem*>(pState)->GetDashList() );
pBox->SelectEntry( aString );
}
}
vcl::Window* SvxLineStyleToolBoxControl::CreateItemWindow( vcl::Window *pParent )
{
return new SvxLineBox( pParent, m_xFrame );
}
SvxLineWidthToolBoxControl::SvxLineWidthToolBoxControl(
sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
SfxToolBoxControl( nSlotId, nId, rTbx )
{
addStatusListener( OUString( ".uno:MetricUnit" ));
}
SvxLineWidthToolBoxControl::~SvxLineWidthToolBoxControl()
{
}
void SvxLineWidthToolBoxControl::StateChanged(
sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
{
SvxMetricField* pFld = static_cast<SvxMetricField*>(
GetToolBox().GetItemWindow( GetId() ));
DBG_ASSERT( pFld, "Window not found" );
if ( nSID == SID_ATTR_METRIC )
{
pFld->RefreshDlgUnit();
}
else
{
if ( eState == SfxItemState::DISABLED )
{
pFld->Disable();
pFld->SetText( "" );
}
else
{
pFld->Enable();
if ( eState == SfxItemState::DEFAULT )
{
DBG_ASSERT( pState->ISA(XLineWidthItem), "wrong ItemType" );
// Core-Unit handed over to MetricField
// Should not happen in CreateItemWin ()!
SfxMapUnit eUnit = SFX_MAPUNIT_100TH_MM; // CD!!! GetCoreMetric();
pFld->SetCoreUnit( eUnit );
pFld->Update( static_cast<const XLineWidthItem*>(pState) );
}
else
pFld->Update( NULL );
}
}
}
vcl::Window* SvxLineWidthToolBoxControl::CreateItemWindow( vcl::Window *pParent )
{
return( new SvxMetricField( pParent, m_xFrame ) );
}
SvxLineEndWindow::SvxLineEndWindow(
sal_uInt16 nSlotId,
const Reference< XFrame >& rFrame,
const OUString& rWndTitle ) :
SfxPopupWindow( nSlotId,
rFrame,
WinBits( WB_STDPOPUP | WB_OWNERDRAWDECORATION ) ),
aLineEndSet ( this, WinBits( WB_ITEMBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT ) ),
nCols ( 2 ),
nLines ( 12 ),
nLineEndWidth ( 400 ),
bPopupMode ( true ),
mbInResize ( false ),
mxFrame ( rFrame )
{
SetText( rWndTitle );
implInit();
}
SvxLineEndWindow::SvxLineEndWindow(
sal_uInt16 nSlotId,
const Reference< XFrame >& rFrame,
vcl::Window* pParentWindow,
const OUString& rWndTitle ) :
SfxPopupWindow( nSlotId,
rFrame,
pParentWindow,
WinBits( WB_STDPOPUP | WB_OWNERDRAWDECORATION ) ),
aLineEndSet ( this, WinBits( WB_ITEMBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT ) ),
nCols ( 2 ),
nLines ( 12 ),
nLineEndWidth ( 400 ),
bPopupMode ( true ),
mbInResize ( false ),
mxFrame ( rFrame )
{
SetText( rWndTitle );
implInit();
}
void SvxLineEndWindow::implInit()
{
SfxObjectShell* pDocSh = SfxObjectShell::Current();
SetHelpId( HID_POPUP_LINEEND );
aLineEndSet.SetHelpId( HID_POPUP_LINEEND_CTRL );
if ( pDocSh )
{
const SfxPoolItem* pItem = pDocSh->GetItem( SID_LINEEND_LIST );
if( pItem )
pLineEndList = static_cast<const SvxLineEndListItem*>( pItem )->GetLineEndList();
pItem = pDocSh->GetItem( SID_ATTR_LINEEND_WIDTH_DEFAULT );
if( pItem )
nLineEndWidth = static_cast<const SfxUInt16Item*>( pItem )->GetValue();
}
DBG_ASSERT( pLineEndList.is(), "LineEndList not found" );
aLineEndSet.SetSelectHdl( LINK( this, SvxLineEndWindow, SelectHdl ) );
aLineEndSet.SetColCount( nCols );
// ValueSet fill with entries of LineEndList
FillValueSet();
AddStatusListener( OUString( ".uno:LineEndListState" ));
//ChangeHelpId( HID_POPUP_LINEENDSTYLE );
aLineEndSet.Show();
}
SfxPopupWindow* SvxLineEndWindow::Clone() const
{
return new SvxLineEndWindow( GetId(), mxFrame, GetText() );
}
SvxLineEndWindow::~SvxLineEndWindow()
{
}
IMPL_LINK_NOARG(SvxLineEndWindow, SelectHdl)
{
boost::scoped_ptr<XLineEndItem> pLineEndItem;
boost::scoped_ptr<XLineStartItem> pLineStartItem;
sal_uInt16 nId = aLineEndSet.GetSelectItemId();
if( nId == 1 )
{
pLineStartItem.reset(new XLineStartItem());
}
else if( nId == 2 )
{
pLineEndItem.reset(new XLineEndItem());
}
else if( nId % 2 ) // beginning of line
{
XLineEndEntry* pEntry = pLineEndList->GetLineEnd( ( nId - 1 ) / 2 - 1 );
pLineStartItem.reset(new XLineStartItem( pEntry->GetName(), pEntry->GetLineEnd() ));
}
else // end of line
{
XLineEndEntry* pEntry = pLineEndList->GetLineEnd( nId / 2 - 2 );
pLineEndItem.reset(new XLineEndItem( pEntry->GetName(), pEntry->GetLineEnd() ));
}
if ( IsInPopupMode() )
EndPopupMode();
Sequence< PropertyValue > aArgs( 1 );
Any a;
if ( pLineStartItem )
{
aArgs[0].Name = "LineStart";
pLineStartItem->QueryValue( a );
aArgs[0].Value = a;
}
else
{
aArgs[0].Name = "LineEnd";
pLineEndItem->QueryValue( a );
aArgs[0].Value = a;
}
/* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
This instance may be deleted in the meantime (i.e. when a dialog is opened
while in Dispatch()), accessing members will crash in this case. */
aLineEndSet.SetNoSelection();
SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
OUString( ".uno:LineEndStyle" ),
aArgs );
return 0;
}
void SvxLineEndWindow::FillValueSet()
{
if( pLineEndList.is() )
{
XLineEndEntry* pEntry = NULL;
VirtualDevice aVD;
long nCount = pLineEndList->Count();
// First entry: no line end.
// An entry is temporarly added to get the UI bitmap
basegfx::B2DPolyPolygon aNothing;
pLineEndList->Insert( new XLineEndEntry( aNothing, SVX_RESSTR( RID_SVXSTR_NONE ) ) );
pEntry = pLineEndList->GetLineEnd( nCount );
Bitmap aBmp = pLineEndList->GetUiBitmap( nCount );
OSL_ENSURE( !aBmp.IsEmpty(), "UI bitmap was not created" );
aBmpSize = aBmp.GetSizePixel();
aVD.SetOutputSizePixel( aBmpSize, false );
aBmpSize.Width() = aBmpSize.Width() / 2;
Point aPt0( 0, 0 );
Point aPt1( aBmpSize.Width(), 0 );
aVD.DrawBitmap( Point(), aBmp );
aLineEndSet.InsertItem(1, Image(aVD.GetBitmap(aPt0, aBmpSize)), pEntry->GetName());
aLineEndSet.InsertItem(2, Image(aVD.GetBitmap(aPt1, aBmpSize)), pEntry->GetName());
delete pLineEndList->Remove( nCount );
for( long i = 0; i < nCount; i++ )
{
pEntry = pLineEndList->GetLineEnd( i );
DBG_ASSERT( pEntry, "Could not access LineEndEntry" );
aBmp = pLineEndList->GetUiBitmap( i );
OSL_ENSURE( !aBmp.IsEmpty(), "UI bitmap was not created" );
aVD.DrawBitmap( aPt0, aBmp );
aLineEndSet.InsertItem((sal_uInt16)((i+1L)*2L+1L),
Image(aVD.GetBitmap(aPt0, aBmpSize)), pEntry->GetName());
aLineEndSet.InsertItem((sal_uInt16)((i+2L)*2L),
Image(aVD.GetBitmap(aPt1, aBmpSize)), pEntry->GetName());
}
nLines = std::min( (sal_uInt16)(nCount + 1), (sal_uInt16) MAX_LINES );
aLineEndSet.SetLineCount( nLines );
SetSize();
}
}
void SvxLineEndWindow::Resize()
{
// since we change the size inside this call, check if we
// are called recursive
if( !mbInResize )
{
mbInResize = true;
if ( !IsRollUp() )
{
aLineEndSet.SetColCount( nCols );
aLineEndSet.SetLineCount( nLines );
SetSize();
Size aSize = GetOutputSizePixel();
aSize.Width() -= 4;
aSize.Height() -= 4;
aLineEndSet.SetPosSizePixel( Point( 2, 2 ), aSize );
}
//SfxPopupWindow::Resize();
mbInResize = false;
}
}
void SvxLineEndWindow::Resizing( Size& rNewSize )
{
Size aBitmapSize = aBmpSize; // -> Member
aBitmapSize.Width() += 6;
aBitmapSize.Height() += 6;
Size aItemSize = aLineEndSet.CalcItemSizePixel( aBitmapSize ); // -> Member
//Size aOldSize = GetOutputSizePixel(); // for width
sal_uInt16 nItemCount = aLineEndSet.GetItemCount(); // -> Member
// identify columns
long nItemW = aItemSize.Width();
long nW = rNewSize.Width();
nCols = (sal_uInt16) std::max( ( (sal_uIntPtr)(( nW + nItemW ) / ( nItemW * 2 ) )),
(sal_uIntPtr) 1L );
nCols *= 2;
// identify lines
long nItemH = aItemSize.Height();
long nH = rNewSize.Height();
nLines = (sal_uInt16) std::max( ( ( nH + nItemH / 2 ) / nItemH ), 1L );
sal_uInt16 nMaxCols = nItemCount / nLines;
if( nItemCount % nLines )
nMaxCols++;
if( nCols > nMaxCols )
nCols = nMaxCols;
nW = nItemW * nCols;
// No odd number of columns
if( nCols % 2 )
nCols--;
nCols = std::max( nCols, (sal_uInt16) 2 );
sal_uInt16 nMaxLines = nItemCount / nCols;
if( nItemCount % nCols )
nMaxLines++;
if( nLines > nMaxLines )
nLines = nMaxLines;
nH = nItemH * nLines;
rNewSize.Width() = nW;
rNewSize.Height() = nH;
}
void SvxLineEndWindow::StartSelection()
{
aLineEndSet.StartSelection();
}
bool SvxLineEndWindow::Close()
{
return SfxPopupWindow::Close();
}
void SvxLineEndWindow::StateChanged(
sal_uInt16 nSID, SfxItemState, const SfxPoolItem* pState )
{
if ( nSID == SID_LINEEND_LIST )
{
// The list of line ends (LineEndList) has changed
if ( pState && pState->ISA( SvxLineEndListItem ))
{
pLineEndList = static_cast<const SvxLineEndListItem*>(pState)->GetLineEndList();
DBG_ASSERT( pLineEndList.is(), "LineEndList not found" );
aLineEndSet.Clear();
FillValueSet();
Size aSize = GetOutputSizePixel();
Resizing( aSize );
Resize();
}
}
}
void SvxLineEndWindow::PopupModeEnd()
{
if ( IsVisible() )
{
bPopupMode = false;
SetSize();
}
SfxPopupWindow::PopupModeEnd();
}
void SvxLineEndWindow::SetSize()
{
//if( !bPopupMode )
if( !IsInPopupMode() )
{
sal_uInt16 nItemCount = aLineEndSet.GetItemCount(); // -> Member
sal_uInt16 nMaxLines = nItemCount / nCols; // -> Member ?
if( nItemCount % nCols )
nMaxLines++;
WinBits nBits = aLineEndSet.GetStyle();
if ( nLines == nMaxLines )
nBits &= ~WB_VSCROLL;
else
nBits |= WB_VSCROLL;
aLineEndSet.SetStyle( nBits );
}
Size aSize( aBmpSize );
aSize.Width() += 6;
aSize.Height() += 6;
aSize = aLineEndSet.CalcWindowSizePixel( aSize );
aSize.Width() += 4;
aSize.Height() += 4;
SetOutputSizePixel( aSize );
aSize.Height() = aBmpSize.Height();
aSize.Height() += 14;
//SetMinOutputSizePixel( aSize );
}
void SvxLineEndWindow::GetFocus (void)
{
SfxPopupWindow::GetFocus();
// Grab the focus to the line ends value set so that it can be controlled
// with the keyboard.
aLineEndSet.GrabFocus();
}
SvxLineEndToolBoxControl::SvxLineEndToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ) :
SfxToolBoxControl( nSlotId, nId, rTbx )
{
rTbx.SetItemBits( nId, ToolBoxItemBits::DROPDOWNONLY | rTbx.GetItemBits( nId ) );
rTbx.Invalidate();
}
SvxLineEndToolBoxControl::~SvxLineEndToolBoxControl()
{
}
SfxPopupWindowType SvxLineEndToolBoxControl::GetPopupWindowType() const
{
return SfxPopupWindowType::ONCLICK;
}
SfxPopupWindow* SvxLineEndToolBoxControl::CreatePopupWindow()
{
SvxLineEndWindow* pLineEndWin =
new SvxLineEndWindow( GetId(), m_xFrame, &GetToolBox(), SVX_RESSTR( RID_SVXSTR_LINEEND ) );
pLineEndWin->StartPopupMode( &GetToolBox(),
FLOATWIN_POPUPMODE_GRABFOCUS |
FLOATWIN_POPUPMODE_ALLOWTEAROFF |
FLOATWIN_POPUPMODE_NOAPPFOCUSCLOSE );
pLineEndWin->StartSelection();
SetPopupWindow( pLineEndWin );
return pLineEndWin;
}
void SvxLineEndToolBoxControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* )
{
sal_uInt16 nId = GetId();
ToolBox& rTbx = GetToolBox();
rTbx.EnableItem( nId, SfxItemState::DISABLED != eState );
rTbx.SetItemState( nId, ( SfxItemState::DONTCARE == eState ) ? TRISTATE_INDET : TRISTATE_FALSE );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|