Line data Source code
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 <string>
21 :
22 : #include <vcl/toolbox.hxx>
23 : #include <sfx2/app.hxx>
24 : #include <sfx2/dispatch.hxx>
25 : #include <sfx2/objsh.hxx>
26 :
27 : #include <svx/dialogs.hrc>
28 : #include "helpid.hrc"
29 :
30 : #include "svx/drawitem.hxx"
31 : #include "svx/xattr.hxx"
32 : #include <svx/xtable.hxx>
33 : #include "svx/linectrl.hxx"
34 : #include <svx/itemwin.hxx>
35 : #include <svx/dialmgr.hxx>
36 : #include <svx/unoapi.hxx>
37 :
38 : using namespace ::com::sun::star::uno;
39 : using namespace ::com::sun::star::beans;
40 : using namespace ::com::sun::star::util;
41 : using namespace ::com::sun::star::frame;
42 : using namespace ::com::sun::star::lang;
43 :
44 : // Fuer Linienenden-Controller
45 : #define MAX_LINES 12
46 :
47 : // STATIC DATA -----------------------------------------------------------
48 :
49 139 : SFX_IMPL_TOOLBOX_CONTROL( SvxLineStyleToolBoxControl, XLineStyleItem );
50 139 : SFX_IMPL_TOOLBOX_CONTROL( SvxLineWidthToolBoxControl, XLineWidthItem );
51 139 : SFX_IMPL_TOOLBOX_CONTROL( SvxLineColorToolBoxControl, XLineColorItem );
52 139 : SFX_IMPL_TOOLBOX_CONTROL( SvxLineEndToolBoxControl, SfxBoolItem );
53 :
54 : /*************************************************************************
55 : |*
56 : |* SvxLineStyleToolBoxControl
57 : |*
58 : \************************************************************************/
59 :
60 64 : SvxLineStyleToolBoxControl::SvxLineStyleToolBoxControl( sal_uInt16 nSlotId,
61 : sal_uInt16 nId,
62 : ToolBox& rTbx ) :
63 : SfxToolBoxControl( nSlotId, nId, rTbx ),
64 : pStyleItem ( NULL ),
65 : pDashItem ( NULL ),
66 64 : bUpdate ( sal_False )
67 : {
68 64 : addStatusListener( OUString( ".uno:LineDash" ));
69 64 : addStatusListener( OUString( ".uno:DashListState" ));
70 64 : }
71 :
72 : //========================================================================
73 :
74 192 : SvxLineStyleToolBoxControl::~SvxLineStyleToolBoxControl()
75 : {
76 64 : delete pStyleItem;
77 64 : delete pDashItem;
78 128 : }
79 :
80 : //========================================================================
81 :
82 246 : void SvxLineStyleToolBoxControl::StateChanged (
83 :
84 : sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
85 :
86 : {
87 246 : SvxLineBox* pBox = (SvxLineBox*)GetToolBox().GetItemWindow( GetId() );
88 : DBG_ASSERT( pBox, "Window not found!" );
89 :
90 246 : if( eState == SFX_ITEM_DISABLED )
91 : {
92 0 : pBox->Disable();
93 0 : pBox->SetNoSelection();
94 : }
95 : else
96 : {
97 246 : pBox->Enable();
98 :
99 246 : if ( eState == SFX_ITEM_AVAILABLE )
100 : {
101 164 : if( nSID == SID_ATTR_LINE_STYLE )
102 : {
103 82 : delete pStyleItem;
104 82 : pStyleItem = (XLineStyleItem*)pState->Clone();
105 : }
106 82 : else if( nSID == SID_ATTR_LINE_DASH )
107 : {
108 82 : delete pDashItem;
109 82 : pDashItem = (XLineDashItem*)pState->Clone();
110 : }
111 :
112 164 : bUpdate = sal_True;
113 164 : Update( pState );
114 : }
115 82 : else if ( nSID != SID_DASH_LIST )
116 : {
117 : // kein oder uneindeutiger Status
118 0 : pBox->SetNoSelection();
119 : }
120 : }
121 246 : }
122 :
123 : //========================================================================
124 :
125 164 : void SvxLineStyleToolBoxControl::Update( const SfxPoolItem* pState )
126 : {
127 164 : if ( pState && bUpdate )
128 : {
129 164 : bUpdate = sal_False;
130 :
131 164 : SvxLineBox* pBox = (SvxLineBox*)GetToolBox().GetItemWindow( GetId() );
132 : DBG_ASSERT( pBox, "Window not found!" );
133 :
134 : // Da der Timer unerwartet zuschlagen kann, kann es vorkommen, dass
135 : // die LB noch nicht gefuellt ist. Ein ClearCache() am Control im
136 : // DelayHdl() blieb ohne Erfolg.
137 164 : if( pBox->GetEntryCount() == 0 )
138 0 : pBox->FillControl();
139 :
140 : XLineStyle eXLS;
141 :
142 164 : if ( pStyleItem )
143 164 : eXLS = ( XLineStyle )pStyleItem->GetValue();
144 : else
145 0 : eXLS = XLINE_NONE;
146 :
147 164 : switch( eXLS )
148 : {
149 : case XLINE_NONE:
150 0 : pBox->SelectEntryPos( 0 );
151 0 : break;
152 :
153 : case XLINE_SOLID:
154 164 : pBox->SelectEntryPos( 1 );
155 164 : break;
156 :
157 : case XLINE_DASH:
158 : {
159 0 : if( pDashItem )
160 : {
161 : OUString aString = SvxUnogetInternalNameForItem(
162 0 : XATTR_LINEDASH, pDashItem->GetName());
163 0 : pBox->SelectEntry( aString );
164 : }
165 : else
166 0 : pBox->SetNoSelection();
167 : }
168 0 : break;
169 :
170 : default:
171 : OSL_FAIL( "Nicht unterstuetzter Linientyp" );
172 0 : break;
173 : }
174 : }
175 :
176 164 : if ( pState && ( pState->ISA( SvxDashListItem ) ) )
177 : {
178 : // Die Liste der Linienstile hat sich geaendert
179 0 : SvxLineBox* pBox = (SvxLineBox*)GetToolBox().GetItemWindow( GetId() );
180 : DBG_ASSERT( pBox, "Window not found!" );
181 :
182 0 : String aString( pBox->GetSelectEntry() );
183 0 : pBox->Clear();
184 0 : pBox->InsertEntry( SVX_RESSTR(RID_SVXSTR_INVISIBLE) );
185 0 : pBox->InsertEntry( SVX_RESSTR(RID_SVXSTR_SOLID) );
186 0 : pBox->Fill( ((SvxDashListItem*)pState )->GetDashList() );
187 0 : pBox->SelectEntry( aString );
188 : }
189 164 : }
190 :
191 : //========================================================================
192 :
193 64 : Window* SvxLineStyleToolBoxControl::CreateItemWindow( Window *pParent )
194 : {
195 64 : return new SvxLineBox( pParent, m_xFrame );
196 : }
197 :
198 : /*************************************************************************
199 : |*
200 : |* SvxLineWidthToolBoxControl
201 : |*
202 : \************************************************************************/
203 :
204 64 : SvxLineWidthToolBoxControl::SvxLineWidthToolBoxControl(
205 : sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
206 64 : SfxToolBoxControl( nSlotId, nId, rTbx )
207 : {
208 64 : addStatusListener( OUString( ".uno:MetricUnit" ));
209 64 : }
210 :
211 : //========================================================================
212 :
213 128 : SvxLineWidthToolBoxControl::~SvxLineWidthToolBoxControl()
214 : {
215 128 : }
216 :
217 : //========================================================================
218 :
219 186 : void SvxLineWidthToolBoxControl::StateChanged(
220 : sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
221 : {
222 : SvxMetricField* pFld = (SvxMetricField*)
223 186 : GetToolBox().GetItemWindow( GetId() );
224 : DBG_ASSERT( pFld, "Window not found" );
225 :
226 186 : if ( nSID == SID_ATTR_METRIC )
227 : {
228 104 : pFld->RefreshDlgUnit();
229 : }
230 : else
231 : {
232 82 : if ( eState == SFX_ITEM_DISABLED )
233 : {
234 0 : pFld->Disable();
235 0 : pFld->SetText( String() );
236 : }
237 : else
238 : {
239 82 : pFld->Enable();
240 :
241 82 : if ( eState == SFX_ITEM_AVAILABLE )
242 : {
243 : DBG_ASSERT( pState->ISA(XLineWidthItem), "falscher ItemType" );
244 :
245 : // Core-Unit an MetricField uebergeben
246 : // Darf nicht in CreateItemWin() geschehen!
247 82 : SfxMapUnit eUnit = SFX_MAPUNIT_100TH_MM; // CD!!! GetCoreMetric();
248 82 : pFld->SetCoreUnit( eUnit );
249 :
250 82 : pFld->Update( (const XLineWidthItem*)pState );
251 : }
252 : else
253 0 : pFld->Update( NULL );
254 : }
255 : }
256 186 : }
257 :
258 : //========================================================================
259 :
260 64 : Window* SvxLineWidthToolBoxControl::CreateItemWindow( Window *pParent )
261 : {
262 64 : return( new SvxMetricField( pParent, m_xFrame ) );
263 : }
264 :
265 : /*************************************************************************
266 : |*
267 : |* SvxLineColorToolBoxControl
268 : |*
269 : \************************************************************************/
270 :
271 64 : SvxLineColorToolBoxControl::SvxLineColorToolBoxControl(
272 : sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
273 64 : SfxToolBoxControl( nSlotId, nId, rTbx )
274 : {
275 64 : addStatusListener( OUString( ".uno:ColorTableState" ));
276 64 : }
277 :
278 : //========================================================================
279 :
280 128 : SvxLineColorToolBoxControl::~SvxLineColorToolBoxControl()
281 : {
282 128 : }
283 :
284 : //========================================================================
285 :
286 164 : void SvxLineColorToolBoxControl::StateChanged(
287 :
288 : sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
289 :
290 : {
291 164 : SvxColorBox* pBox = (SvxColorBox*)GetToolBox().GetItemWindow( GetId() );
292 : DBG_ASSERT( pBox, "Window not found" );
293 :
294 164 : if ( nSID != SID_COLOR_TABLE )
295 : {
296 82 : if ( eState == SFX_ITEM_DISABLED )
297 : {
298 0 : pBox->Disable();
299 0 : pBox->SetNoSelection();
300 : }
301 : else
302 : {
303 82 : pBox->Enable();
304 :
305 82 : if ( eState == SFX_ITEM_AVAILABLE )
306 : {
307 : DBG_ASSERT( pState->ISA(XLineColorItem), "falscher ItemTyoe" );
308 82 : pBox->Update( (const XLineColorItem*) pState );
309 : }
310 : else
311 0 : pBox->Update( NULL );
312 : }
313 : }
314 : else
315 82 : Update( pState );
316 164 : }
317 :
318 : //========================================================================
319 :
320 82 : void SvxLineColorToolBoxControl::Update( const SfxPoolItem* pState )
321 : {
322 82 : if ( pState && ( pState->ISA( SvxColorListItem ) ) )
323 : {
324 0 : SvxColorBox* pBox = (SvxColorBox*)GetToolBox().GetItemWindow( GetId() );
325 :
326 : DBG_ASSERT( pBox, "Window not found" );
327 :
328 : // Die Liste der Farben (ColorTable) hat sich geaendert:
329 0 : ::Color aTmpColor( pBox->GetSelectEntryColor() );
330 0 : pBox->Clear();
331 0 : pBox->Fill( ( (SvxColorListItem*)pState )->GetColorList() );
332 0 : pBox->SelectEntry( aTmpColor );
333 : }
334 82 : }
335 :
336 : //========================================================================
337 :
338 64 : Window* SvxLineColorToolBoxControl::CreateItemWindow( Window *pParent )
339 : {
340 64 : return new SvxColorBox( pParent, m_aCommandURL, m_xFrame );
341 : }
342 :
343 : /*************************************************************************
344 : |*
345 : |* SvxLineEndWindow
346 : |*
347 : \************************************************************************/
348 :
349 0 : SvxLineEndWindow::SvxLineEndWindow(
350 : sal_uInt16 nSlotId,
351 : const Reference< XFrame >& rFrame,
352 : const String& rWndTitle ) :
353 : SfxPopupWindow( nSlotId,
354 : rFrame,
355 : WinBits( WB_STDPOPUP | WB_OWNERDRAWDECORATION ) ),
356 : aLineEndSet ( this, WinBits( WB_ITEMBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT ) ),
357 : nCols ( 2 ),
358 : nLines ( 12 ),
359 : nLineEndWidth ( 400 ),
360 : bPopupMode ( sal_True ),
361 : mbInResize ( false ),
362 0 : mxFrame ( rFrame )
363 : {
364 0 : SetText( rWndTitle );
365 0 : implInit();
366 0 : }
367 :
368 0 : SvxLineEndWindow::SvxLineEndWindow(
369 : sal_uInt16 nSlotId,
370 : const Reference< XFrame >& rFrame,
371 : Window* pParentWindow,
372 : const String& rWndTitle ) :
373 : SfxPopupWindow( nSlotId,
374 : rFrame,
375 : pParentWindow,
376 : WinBits( WB_STDPOPUP | WB_OWNERDRAWDECORATION ) ),
377 : aLineEndSet ( this, WinBits( WB_ITEMBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT ) ),
378 : nCols ( 2 ),
379 : nLines ( 12 ),
380 : nLineEndWidth ( 400 ),
381 : bPopupMode ( sal_True ),
382 : mbInResize ( false ),
383 0 : mxFrame ( rFrame )
384 : {
385 0 : SetText( rWndTitle );
386 0 : implInit();
387 0 : }
388 :
389 0 : void SvxLineEndWindow::implInit()
390 : {
391 0 : SfxObjectShell* pDocSh = SfxObjectShell::Current();
392 0 : const SfxPoolItem* pItem = NULL;
393 :
394 0 : SetHelpId( HID_POPUP_LINEEND );
395 0 : aLineEndSet.SetHelpId( HID_POPUP_LINEEND_CTRL );
396 :
397 0 : if ( pDocSh )
398 : {
399 0 : pItem = pDocSh->GetItem( SID_LINEEND_LIST );
400 0 : if( pItem )
401 0 : pLineEndList = ( (SvxLineEndListItem*) pItem )->GetLineEndList();
402 :
403 0 : pItem = pDocSh->GetItem( SID_ATTR_LINEEND_WIDTH_DEFAULT );
404 0 : if( pItem )
405 0 : nLineEndWidth = ( (SfxUInt16Item*) pItem )->GetValue();
406 : }
407 : DBG_ASSERT( pLineEndList.is(), "LineEndList wurde nicht gefunden" );
408 :
409 0 : aLineEndSet.SetSelectHdl( LINK( this, SvxLineEndWindow, SelectHdl ) );
410 0 : aLineEndSet.SetColCount( nCols );
411 :
412 : // ValueSet mit Eintraegen der LineEndList fuellen
413 0 : FillValueSet();
414 :
415 0 : AddStatusListener( OUString( ".uno:LineEndListState" ));
416 :
417 : //ChangeHelpId( HID_POPUP_LINEENDSTYLE );
418 0 : aLineEndSet.Show();
419 0 : }
420 :
421 0 : SfxPopupWindow* SvxLineEndWindow::Clone() const
422 : {
423 0 : return new SvxLineEndWindow( GetId(), mxFrame, GetText() );
424 : }
425 :
426 : // -----------------------------------------------------------------------
427 :
428 0 : SvxLineEndWindow::~SvxLineEndWindow()
429 : {
430 0 : }
431 :
432 : // -----------------------------------------------------------------------
433 :
434 0 : IMPL_LINK_NOARG(SvxLineEndWindow, SelectHdl)
435 : {
436 0 : XLineEndItem* pLineEndItem = NULL;
437 0 : XLineStartItem* pLineStartItem = NULL;
438 0 : sal_uInt16 nId = aLineEndSet.GetSelectItemId();
439 :
440 0 : if( nId == 1 )
441 : {
442 0 : pLineStartItem = new XLineStartItem();
443 : }
444 0 : else if( nId == 2 )
445 : {
446 0 : pLineEndItem = new XLineEndItem();
447 : }
448 0 : else if( nId % 2 ) // LinienAnfang
449 : {
450 0 : XLineEndEntry* pEntry = pLineEndList->GetLineEnd( ( nId - 1 ) / 2 - 1 );
451 0 : pLineStartItem = new XLineStartItem( pEntry->GetName(), pEntry->GetLineEnd() );
452 : }
453 : else // LinienEnde
454 : {
455 0 : XLineEndEntry* pEntry = pLineEndList->GetLineEnd( nId / 2 - 2 );
456 0 : pLineEndItem = new XLineEndItem( pEntry->GetName(), pEntry->GetLineEnd() );
457 : }
458 :
459 0 : if ( IsInPopupMode() )
460 0 : EndPopupMode();
461 :
462 0 : Sequence< PropertyValue > aArgs( 1 );
463 0 : Any a;
464 :
465 0 : if ( pLineStartItem )
466 : {
467 0 : aArgs[0].Name = OUString( "LineStart" );
468 0 : pLineStartItem->QueryValue( a );
469 0 : aArgs[0].Value = a;
470 : }
471 : else
472 : {
473 0 : aArgs[0].Name = OUString( "LineEnd" );
474 0 : pLineEndItem->QueryValue( a );
475 0 : aArgs[0].Value = a;
476 : }
477 :
478 : /* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
479 : This instance may be deleted in the meantime (i.e. when a dialog is opened
480 : while in Dispatch()), accessing members will crash in this case. */
481 0 : aLineEndSet.SetNoSelection();
482 :
483 0 : SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
484 : OUString( ".uno:LineEndStyle" ),
485 0 : aArgs );
486 :
487 0 : delete pLineEndItem;
488 0 : delete pLineStartItem;
489 :
490 0 : return 0;
491 : }
492 :
493 : // -----------------------------------------------------------------------
494 :
495 0 : void SvxLineEndWindow::FillValueSet()
496 : {
497 0 : if( pLineEndList.is() )
498 : {
499 0 : XLineEndEntry* pEntry = NULL;
500 0 : VirtualDevice aVD;
501 :
502 0 : long nCount = pLineEndList->Count();
503 :
504 : // Erster Eintrag: kein LinienEnde
505 : // Temporaer wird ein Eintrag hinzugefuegt, um die UI-Bitmap zu erhalten
506 0 : basegfx::B2DPolyPolygon aNothing;
507 0 : pLineEndList->Insert( new XLineEndEntry( aNothing, SVX_RESSTR( RID_SVXSTR_NONE ) ) );
508 0 : pEntry = pLineEndList->GetLineEnd( nCount );
509 0 : Bitmap aBmp = pLineEndList->GetUiBitmap( nCount );
510 : OSL_ENSURE( !aBmp.IsEmpty(), "UI-Bitmap wurde nicht erzeugt" );
511 :
512 0 : aBmpSize = aBmp.GetSizePixel();
513 0 : aVD.SetOutputSizePixel( aBmpSize, sal_False );
514 0 : aBmpSize.Width() = aBmpSize.Width() / 2;
515 0 : Point aPt0( 0, 0 );
516 0 : Point aPt1( aBmpSize.Width(), 0 );
517 :
518 0 : aVD.DrawBitmap( Point(), aBmp );
519 0 : aLineEndSet.InsertItem( 1, aVD.GetBitmap( aPt0, aBmpSize ), pEntry->GetName() );
520 0 : aLineEndSet.InsertItem( 2, aVD.GetBitmap( aPt1, aBmpSize ), pEntry->GetName() );
521 :
522 0 : delete pLineEndList->Remove( nCount );
523 :
524 0 : for( long i = 0; i < nCount; i++ )
525 : {
526 0 : pEntry = pLineEndList->GetLineEnd( i );
527 : DBG_ASSERT( pEntry, "Konnte auf LineEndEntry nicht zugreifen" );
528 0 : aBmp = pLineEndList->GetUiBitmap( i );
529 : OSL_ENSURE( !aBmp.IsEmpty(), "UI-Bitmap wurde nicht erzeugt" );
530 :
531 0 : aVD.DrawBitmap( aPt0, aBmp );
532 0 : aLineEndSet.InsertItem( (sal_uInt16)((i+1L)*2L+1L), aVD.GetBitmap( aPt0, aBmpSize ), pEntry->GetName() );
533 0 : aLineEndSet.InsertItem( (sal_uInt16)((i+2L)*2L), aVD.GetBitmap( aPt1, aBmpSize ), pEntry->GetName() );
534 : }
535 0 : nLines = std::min( (sal_uInt16)(nCount + 1), (sal_uInt16) MAX_LINES );
536 0 : aLineEndSet.SetLineCount( nLines );
537 :
538 0 : SetSize();
539 : }
540 0 : }
541 :
542 : // -----------------------------------------------------------------------
543 :
544 0 : void SvxLineEndWindow::Resize()
545 : {
546 : // since we change the size inside this call, check if we
547 : // are called recursive
548 0 : if( !mbInResize )
549 : {
550 0 : mbInResize = true;
551 0 : if ( !IsRollUp() )
552 : {
553 0 : aLineEndSet.SetColCount( nCols );
554 0 : aLineEndSet.SetLineCount( nLines );
555 :
556 0 : SetSize();
557 :
558 0 : Size aSize = GetOutputSizePixel();
559 0 : aSize.Width() -= 4;
560 0 : aSize.Height() -= 4;
561 0 : aLineEndSet.SetPosSizePixel( Point( 2, 2 ), aSize );
562 : }
563 : //SfxPopupWindow::Resize();
564 0 : mbInResize = false;
565 : }
566 0 : }
567 :
568 : // -----------------------------------------------------------------------
569 :
570 0 : void SvxLineEndWindow::Resizing( Size& rNewSize )
571 : {
572 0 : Size aBitmapSize = aBmpSize; // -> Member
573 0 : aBitmapSize.Width() += 6; //
574 0 : aBitmapSize.Height() += 6; //
575 :
576 0 : Size aItemSize = aLineEndSet.CalcItemSizePixel( aBitmapSize ); // -> Member
577 : //Size aOldSize = GetOutputSizePixel(); // fuer Breite
578 :
579 0 : sal_uInt16 nItemCount = aLineEndSet.GetItemCount(); // -> Member
580 :
581 : // Spalten ermitteln
582 0 : long nItemW = aItemSize.Width();
583 0 : long nW = rNewSize.Width();
584 0 : nCols = (sal_uInt16) std::max( ( (sal_uIntPtr)(( nW + nItemW ) / ( nItemW * 2 ) )),
585 0 : (sal_uIntPtr) 1L );
586 0 : nCols *= 2;
587 :
588 : // Reihen ermitteln
589 0 : long nItemH = aItemSize.Height();
590 0 : long nH = rNewSize.Height();
591 0 : nLines = (sal_uInt16) std::max( ( ( nH + nItemH / 2 ) / nItemH ), 1L );
592 :
593 0 : sal_uInt16 nMaxCols = nItemCount / nLines;
594 0 : if( nItemCount % nLines )
595 0 : nMaxCols++;
596 0 : if( nCols > nMaxCols )
597 0 : nCols = nMaxCols;
598 0 : nW = nItemW * nCols;
599 :
600 : // Keine ungerade Anzahl von Spalten
601 0 : if( nCols % 2 )
602 0 : nCols--;
603 0 : nCols = std::max( nCols, (sal_uInt16) 2 );
604 :
605 0 : sal_uInt16 nMaxLines = nItemCount / nCols;
606 0 : if( nItemCount % nCols )
607 0 : nMaxLines++;
608 0 : if( nLines > nMaxLines )
609 0 : nLines = nMaxLines;
610 0 : nH = nItemH * nLines;
611 :
612 0 : rNewSize.Width() = nW;
613 0 : rNewSize.Height() = nH;
614 0 : }
615 : // -----------------------------------------------------------------------
616 :
617 0 : void SvxLineEndWindow::StartSelection()
618 : {
619 0 : aLineEndSet.StartSelection();
620 0 : }
621 :
622 : // -----------------------------------------------------------------------
623 :
624 0 : sal_Bool SvxLineEndWindow::Close()
625 : {
626 0 : return SfxPopupWindow::Close();
627 : }
628 :
629 : // -----------------------------------------------------------------------
630 :
631 0 : void SvxLineEndWindow::StateChanged(
632 : sal_uInt16 nSID, SfxItemState, const SfxPoolItem* pState )
633 : {
634 0 : if ( nSID == SID_LINEEND_LIST )
635 : {
636 : // Die Liste der LinienEnden (LineEndList) hat sich geaendert:
637 0 : if ( pState && pState->ISA( SvxLineEndListItem ))
638 : {
639 0 : pLineEndList = ((SvxLineEndListItem*)pState)->GetLineEndList();
640 : DBG_ASSERT( pLineEndList.is(), "LineEndList nicht gefunden" );
641 :
642 0 : aLineEndSet.Clear();
643 0 : FillValueSet();
644 :
645 0 : Size aSize = GetOutputSizePixel();
646 0 : Resizing( aSize );
647 0 : Resize();
648 : }
649 : }
650 0 : }
651 :
652 : // -----------------------------------------------------------------------
653 :
654 0 : void SvxLineEndWindow::PopupModeEnd()
655 : {
656 0 : if ( IsVisible() )
657 : {
658 0 : bPopupMode = sal_False;
659 0 : SetSize();
660 : }
661 0 : SfxPopupWindow::PopupModeEnd();
662 0 : }
663 :
664 : // -----------------------------------------------------------------------
665 :
666 0 : void SvxLineEndWindow::SetSize()
667 : {
668 : //if( !bPopupMode )
669 0 : if( !IsInPopupMode() )
670 : {
671 0 : sal_uInt16 nItemCount = aLineEndSet.GetItemCount(); // -> Member
672 0 : sal_uInt16 nMaxLines = nItemCount / nCols; // -> Member ?
673 0 : if( nItemCount % nCols )
674 0 : nMaxLines++;
675 :
676 0 : WinBits nBits = aLineEndSet.GetStyle();
677 0 : if ( nLines == nMaxLines )
678 0 : nBits &= ~WB_VSCROLL;
679 : else
680 0 : nBits |= WB_VSCROLL;
681 0 : aLineEndSet.SetStyle( nBits );
682 : }
683 :
684 0 : Size aSize( aBmpSize );
685 0 : aSize.Width() += 6;
686 0 : aSize.Height() += 6;
687 0 : aSize = aLineEndSet.CalcWindowSizePixel( aSize );
688 0 : aSize.Width() += 4;
689 0 : aSize.Height() += 4;
690 0 : SetOutputSizePixel( aSize );
691 0 : aSize.Height() = aBmpSize.Height();
692 0 : aSize.Height() += 14;
693 : //SetMinOutputSizePixel( aSize );
694 0 : }
695 :
696 0 : void SvxLineEndWindow::GetFocus (void)
697 : {
698 0 : SfxPopupWindow::GetFocus();
699 : // Grab the focus to the line ends value set so that it can be controlled
700 : // with the keyboard.
701 0 : aLineEndSet.GrabFocus();
702 0 : }
703 :
704 : /*************************************************************************
705 : |*
706 : |* SvxLineEndToolBoxControl
707 : |*
708 : \************************************************************************/
709 :
710 64 : SvxLineEndToolBoxControl::SvxLineEndToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ) :
711 64 : SfxToolBoxControl( nSlotId, nId, rTbx )
712 : {
713 64 : rTbx.SetItemBits( nId, TIB_DROPDOWNONLY | rTbx.GetItemBits( nId ) );
714 64 : rTbx.Invalidate();
715 64 : }
716 :
717 : // -----------------------------------------------------------------------
718 :
719 128 : SvxLineEndToolBoxControl::~SvxLineEndToolBoxControl()
720 : {
721 128 : }
722 :
723 : // -----------------------------------------------------------------------
724 :
725 0 : SfxPopupWindowType SvxLineEndToolBoxControl::GetPopupWindowType() const
726 : {
727 0 : return SFX_POPUPWINDOW_ONCLICK;
728 : }
729 :
730 : // -----------------------------------------------------------------------
731 :
732 0 : SfxPopupWindow* SvxLineEndToolBoxControl::CreatePopupWindow()
733 : {
734 : SvxLineEndWindow* pLineEndWin =
735 0 : new SvxLineEndWindow( GetId(), m_xFrame, &GetToolBox(), SVX_RESSTR( RID_SVXSTR_LINEEND ) );
736 0 : pLineEndWin->StartPopupMode( &GetToolBox(),
737 : FLOATWIN_POPUPMODE_GRABFOCUS |
738 : FLOATWIN_POPUPMODE_ALLOWTEAROFF |
739 0 : FLOATWIN_POPUPMODE_NOAPPFOCUSCLOSE );
740 0 : pLineEndWin->StartSelection();
741 0 : SetPopupWindow( pLineEndWin );
742 0 : return pLineEndWin;
743 : }
744 :
745 : // -----------------------------------------------------------------------
746 :
747 82 : void SvxLineEndToolBoxControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* )
748 : {
749 82 : sal_uInt16 nId = GetId();
750 82 : ToolBox& rTbx = GetToolBox();
751 :
752 82 : rTbx.EnableItem( nId, SFX_ITEM_DISABLED != eState );
753 82 : rTbx.SetItemState( nId, ( SFX_ITEM_DONTCARE == eState ) ? STATE_DONTKNOW : STATE_NOCHECK );
754 298 : }
755 :
756 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|