Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / svx / source / tbxctrls / itemwin.cxx
bloba24ae633d8513d84bd32987e6f9da0f48339748a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 // include ---------------------------------------------------------------
31 #include <tools/shl.hxx>
32 #include <sfx2/dispatch.hxx>
33 #include <sfx2/objsh.hxx>
34 #include <sfx2/viewsh.hxx>
35 #include <sfx2/module.hxx>
36 #include <tools/urlobj.hxx>
38 #define _SVX_ITEMWIN_CXX
40 #include <vcl/svapp.hxx>
42 #include <svx/dialogs.hrc>
44 #define DELAY_TIMEOUT 100
46 #include <svx/xlnclit.hxx>
47 #include <svx/xlnwtit.hxx>
48 #include <svx/xlineit0.hxx>
49 #include <svx/xlndsit.hxx>
50 #include <svx/xtable.hxx>
51 #include "svx/drawitem.hxx"
52 #include <svx/dialmgr.hxx>
53 #include "svx/dlgutil.hxx"
54 #include <svx/itemwin.hxx>
55 #include "svx/linectrl.hxx"
56 #include <svtools/colorcfg.hxx>
58 #include "linectrl.hrc"
60 using namespace ::com::sun::star::uno;
61 using namespace ::com::sun::star::frame;
62 using namespace ::com::sun::star::util;
63 using namespace ::com::sun::star::lang;
64 using namespace ::com::sun::star::beans;
66 #define LOGICAL_EDIT_HEIGHT 12
67 //========================================================================
68 // SvxLineBox
69 //========================================================================
71 SvxLineBox::SvxLineBox( Window* pParent, const Reference< XFrame >& rFrame, WinBits nBits ) :
72 LineLB( pParent, nBits ),
73 nCurPos ( 0 ),
74 aLogicalSize(40,140),
75 bRelease ( sal_True ),
76 mpSh ( NULL ),
77 mxFrame ( rFrame )
79 SetSizePixel( LogicToPixel( aLogicalSize, MAP_APPFONT ));
80 Show();
82 aDelayTimer.SetTimeout( DELAY_TIMEOUT );
83 aDelayTimer.SetTimeoutHdl( LINK( this, SvxLineBox, DelayHdl_Impl ) );
84 aDelayTimer.Start();
87 // -----------------------------------------------------------------------
89 SvxLineBox::~SvxLineBox()
93 // -----------------------------------------------------------------------
95 IMPL_LINK_NOARG(SvxLineBox, DelayHdl_Impl)
97 if ( GetEntryCount() == 0 )
99 mpSh = SfxObjectShell::Current();
100 FillControl();
102 return 0;
105 // -----------------------------------------------------------------------
107 void SvxLineBox::Select()
109 // Call the parent's Select() member to trigger accessibility events.
110 LineLB::Select();
112 if ( !IsTravelSelect() )
114 XLineStyle eXLS;
115 sal_uInt16 nPos = GetSelectEntryPos();
117 switch ( nPos )
119 case 0:
120 eXLS = XLINE_NONE;
121 break;
123 case 1:
124 eXLS = XLINE_SOLID;
125 break;
127 default:
129 eXLS = XLINE_DASH;
131 if ( nPos != LISTBOX_ENTRY_NOTFOUND &&
132 SfxObjectShell::Current() &&
133 SfxObjectShell::Current()->GetItem( SID_DASH_LIST ) )
135 // LineDashItem wird nur geschickt, wenn es auch einen Dash besitzt.
136 // Notify k"ummert sich darum!
137 SvxDashListItem aItem( *(const SvxDashListItem*)(
138 SfxObjectShell::Current()->GetItem( SID_DASH_LIST ) ) );
139 XLineDashItem aLineDashItem( GetSelectEntry(),
140 aItem.GetDashList()->GetDash( nPos - 2 )->GetDash() );
142 Any a;
143 Sequence< PropertyValue > aArgs( 1 );
144 aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LineDash" ));
145 aLineDashItem.QueryValue ( a );
146 aArgs[0].Value = a;
147 SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
148 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:LineDash" )),
149 aArgs );
152 break;
155 XLineStyleItem aLineStyleItem( eXLS );
156 Any a;
157 Sequence< PropertyValue > aArgs( 1 );
158 aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XLineStyle" ));
159 aLineStyleItem.QueryValue ( a );
160 aArgs[0].Value = a;
161 SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
162 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:XLineStyle" )),
163 aArgs );
165 nCurPos = GetSelectEntryPos();
166 ReleaseFocus_Impl();
170 // -----------------------------------------------------------------------
172 long SvxLineBox::PreNotify( NotifyEvent& rNEvt )
174 sal_uInt16 nType = rNEvt.GetType();
176 switch(nType)
178 case EVENT_MOUSEBUTTONDOWN:
179 case EVENT_GETFOCUS:
180 nCurPos = GetSelectEntryPos();
181 break;
182 case EVENT_LOSEFOCUS:
183 SelectEntryPos(nCurPos);
184 break;
185 case EVENT_KEYINPUT:
187 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
188 if( pKEvt->GetKeyCode().GetCode() == KEY_TAB)
190 bRelease = sal_False;
191 Select();
194 break;
196 return LineLB::PreNotify( rNEvt );
199 // -----------------------------------------------------------------------
201 long SvxLineBox::Notify( NotifyEvent& rNEvt )
203 long nHandled = LineLB::Notify( rNEvt );
205 if ( rNEvt.GetType() == EVENT_KEYINPUT )
207 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
209 switch ( pKEvt->GetKeyCode().GetCode() )
211 case KEY_RETURN:
212 Select();
213 nHandled = 1;
214 break;
216 case KEY_ESCAPE:
217 SelectEntryPos( nCurPos );
218 ReleaseFocus_Impl();
219 nHandled = 1;
220 break;
223 return nHandled;
226 // -----------------------------------------------------------------------
228 void SvxLineBox::ReleaseFocus_Impl()
230 if(!bRelease)
232 bRelease = sal_True;
233 return;
236 if( SfxViewShell::Current() )
238 Window* pShellWnd = SfxViewShell::Current()->GetWindow();
240 if ( pShellWnd )
241 pShellWnd->GrabFocus();
245 void SvxLineBox::DataChanged( const DataChangedEvent& rDCEvt )
247 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
248 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
250 SetSizePixel(LogicToPixel(aLogicalSize, MAP_APPFONT));
251 Size aDropSize( aLogicalSize.Width(), LOGICAL_EDIT_HEIGHT);
252 SetDropDownSizePixel(LogicToPixel(aDropSize, MAP_APPFONT));
255 LineLB::DataChanged( rDCEvt );
258 void SvxLineBox::FillControl()
260 FillStyles();
261 if ( !mpSh )
262 mpSh = SfxObjectShell::Current();
264 if( mpSh )
266 const SvxDashListItem* pItem = (const SvxDashListItem*)( mpSh->GetItem( SID_DASH_LIST ) );
267 if ( pItem )
268 Fill( pItem->GetDashList() );
272 //========================================================================
273 // SvxColorBox
274 //========================================================================
276 SvxColorBox::SvxColorBox(
277 Window* pParent,
278 const ::rtl::OUString& rCommand,
279 const Reference< XFrame >& rFrame,
280 WinBits nBits ) :
281 ColorLB( pParent, nBits ),
282 nCurPos ( 0 ),
283 aLogicalSize(45,80),
284 bRelease ( sal_True ),
285 maCommand ( rCommand ),
286 mxFrame ( rFrame )
288 SetSizePixel( LogicToPixel( aLogicalSize , MAP_APPFONT));
289 Show();
291 SfxObjectShell* pSh = SfxObjectShell::Current();
293 if ( pSh )
295 const SvxColorListItem* pItem =
296 (const SvxColorListItem*)( pSh->GetItem( SID_COLOR_TABLE ) );
297 if(pItem)
298 Fill( pItem->GetColorList() );
302 // -----------------------------------------------------------------------
304 SvxColorBox::~SvxColorBox()
308 // -----------------------------------------------------------------------
310 void SvxColorBox::Update( const XLineColorItem* pItem )
312 if ( pItem )
313 SelectEntry( pItem->GetColorValue() );
314 else
315 SetNoSelection();
318 // -----------------------------------------------------------------------
320 void SvxColorBox::Select()
322 // OJ: base class call needed here because otherwise no event is send for accessibility
323 ColorLB::Select();
324 if ( !IsTravelSelect() )
326 XLineColorItem aLineColorItem( GetSelectEntry(), GetSelectEntryColor() );
328 INetURLObject aObj( maCommand );
330 Any a;
331 Sequence< PropertyValue > aArgs( 1 );
332 aArgs[0].Name = aObj.GetURLPath();
333 aLineColorItem.QueryValue( a );
334 aArgs[0].Value = a;
335 SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
336 maCommand,
337 aArgs );
339 nCurPos = GetSelectEntryPos();
340 ReleaseFocus_Impl();
344 // -----------------------------------------------------------------------
346 long SvxColorBox::PreNotify( NotifyEvent& rNEvt )
348 sal_uInt16 nType = rNEvt.GetType();
350 switch(nType)
352 case EVENT_MOUSEBUTTONDOWN:
353 case EVENT_GETFOCUS:
354 nCurPos = GetSelectEntryPos();
355 break;
356 case EVENT_LOSEFOCUS:
357 SelectEntryPos(nCurPos);
358 break;
359 case EVENT_KEYINPUT:
361 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
363 if( pKEvt->GetKeyCode().GetCode() == KEY_TAB)
365 bRelease = sal_False;
366 Select();
371 return ColorLB::PreNotify( rNEvt );
374 // -----------------------------------------------------------------------
376 long SvxColorBox::Notify( NotifyEvent& rNEvt )
378 long nHandled = ColorLB::Notify( rNEvt );
380 if ( rNEvt.GetType() == EVENT_KEYINPUT )
382 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
384 switch ( pKEvt->GetKeyCode().GetCode() )
386 case KEY_RETURN:
387 Select();
388 nHandled = 1;
389 break;
391 case KEY_ESCAPE:
392 SelectEntryPos( nCurPos );
393 ReleaseFocus_Impl();
394 nHandled = 1;
395 break;
398 return nHandled;
401 void SvxColorBox::DataChanged( const DataChangedEvent& rDCEvt )
403 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
404 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
406 SetSizePixel(LogicToPixel(aLogicalSize, MAP_APPFONT));
407 Size aDropSize( aLogicalSize.Width(), LOGICAL_EDIT_HEIGHT);
408 SetDropDownSizePixel(LogicToPixel(aDropSize, MAP_APPFONT));
411 ColorLB::DataChanged( rDCEvt );
413 // -----------------------------------------------------------------------
415 void SvxColorBox::ReleaseFocus_Impl()
417 if(!bRelease)
419 bRelease = sal_True;
420 return;
423 if( SfxViewShell::Current() )
425 Window* pShellWnd = SfxViewShell::Current()->GetWindow();
427 if ( pShellWnd )
428 pShellWnd->GrabFocus();
432 //========================================================================
433 // SvxMetricField
434 //========================================================================
436 SvxMetricField::SvxMetricField(
437 Window* pParent, const Reference< XFrame >& rFrame, WinBits nBits ) :
438 MetricField( pParent, nBits ),
439 aCurTxt( String() ),
440 mxFrame( rFrame )
442 Size aSize = Size(GetTextWidth( String::CreateFromAscii("99,99mm") ),GetTextHeight());
443 aSize.Width() += 20;
444 aSize.Height() += 6;
445 SetSizePixel( aSize );
446 aLogicalSize = PixelToLogic(aSize, MAP_APPFONT);
447 SetUnit( FUNIT_MM );
448 SetDecimalDigits( 2 );
449 SetMax( 5000 );
450 SetMin( 0 );
451 SetLast( 5000 );
452 SetFirst( 0 );
454 eDlgUnit = SfxModule::GetModuleFieldUnit( mxFrame );
455 SetFieldUnit( *this, eDlgUnit, sal_False );
456 Show();
459 // -----------------------------------------------------------------------
461 SvxMetricField::~SvxMetricField()
465 // -----------------------------------------------------------------------
467 void SvxMetricField::Update( const XLineWidthItem* pItem )
469 if ( pItem )
471 if ( pItem->GetValue() != GetCoreValue( *this, ePoolUnit ) )
472 SetMetricValue( *this, pItem->GetValue(), ePoolUnit );
474 else
475 SetText( String() );
478 // -----------------------------------------------------------------------
480 void SvxMetricField::Modify()
482 MetricField::Modify();
483 long nTmp = GetCoreValue( *this, ePoolUnit );
484 XLineWidthItem aLineWidthItem( nTmp );
486 Any a;
487 Sequence< PropertyValue > aArgs( 1 );
488 aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LineWidth" ));
489 aLineWidthItem.QueryValue( a );
490 aArgs[0].Value = a;
491 SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
492 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:LineWidth" )),
493 aArgs );
496 // -----------------------------------------------------------------------
498 void SvxMetricField::ReleaseFocus_Impl()
500 if( SfxViewShell::Current() )
502 Window* pShellWnd = SfxViewShell::Current()->GetWindow();
503 if ( pShellWnd )
504 pShellWnd->GrabFocus();
508 // -----------------------------------------------------------------------
510 void SvxMetricField::Down()
512 sal_Int64 nValue = GetValue();
513 nValue -= GetSpinSize();
515 // Um unter OS/2 einen Sprung auf Max zu verhindern
516 if ( nValue >= GetMin() )
517 MetricField::Down();
520 // -----------------------------------------------------------------------
522 void SvxMetricField::Up()
524 MetricField::Up();
527 // -----------------------------------------------------------------------
529 void SvxMetricField::SetCoreUnit( SfxMapUnit eUnit )
531 ePoolUnit = eUnit;
534 // -----------------------------------------------------------------------
536 void SvxMetricField::RefreshDlgUnit()
538 FieldUnit eTmpUnit = SfxModule::GetModuleFieldUnit( mxFrame );
539 if ( eDlgUnit != eTmpUnit )
541 eDlgUnit = eTmpUnit;
542 SetFieldUnit( *this, eDlgUnit, sal_False );
546 // -----------------------------------------------------------------------
548 long SvxMetricField::PreNotify( NotifyEvent& rNEvt )
550 sal_uInt16 nType = rNEvt.GetType();
552 if ( EVENT_MOUSEBUTTONDOWN == nType || EVENT_GETFOCUS == nType )
553 aCurTxt = GetText();
555 return MetricField::PreNotify( rNEvt );
558 // -----------------------------------------------------------------------
560 long SvxMetricField::Notify( NotifyEvent& rNEvt )
562 long nHandled = MetricField::Notify( rNEvt );
564 if ( rNEvt.GetType() == EVENT_KEYINPUT )
566 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
567 const KeyCode& rKey = pKEvt->GetKeyCode();
568 SfxViewShell* pSh = SfxViewShell::Current();
570 if ( rKey.GetModifier() && rKey.GetGroup() != KEYGROUP_CURSOR && pSh )
571 pSh->KeyInput( *pKEvt );
572 else
574 bool bHandled = false;
576 switch ( rKey.GetCode() )
578 case KEY_RETURN:
579 Reformat();
580 bHandled = true;
581 break;
583 case KEY_ESCAPE:
584 SetText( aCurTxt );
585 bHandled = true;
586 break;
589 if ( bHandled )
591 nHandled = 1;
592 Modify();
593 ReleaseFocus_Impl();
597 return nHandled;
600 void SvxMetricField::DataChanged( const DataChangedEvent& rDCEvt )
602 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
603 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
605 SetSizePixel(LogicToPixel(aLogicalSize, MAP_APPFONT));
608 MetricField::DataChanged( rDCEvt );
611 //========================================================================
612 // SvxFillTypeBox
613 //========================================================================
615 SvxFillTypeBox::SvxFillTypeBox( Window* pParent, WinBits nBits ) :
616 FillTypeLB( pParent, nBits | WB_TABSTOP ),
617 nCurPos ( 0 ),
618 bSelect ( sal_False ),
619 bRelease(sal_True)
621 SetSizePixel( LogicToPixel( Size(40, 40 ),MAP_APPFONT ));
622 Fill();
623 SelectEntryPos( XFILL_SOLID );
624 Show();
627 // -----------------------------------------------------------------------
629 SvxFillTypeBox::~SvxFillTypeBox()
633 // -----------------------------------------------------------------------
635 long SvxFillTypeBox::PreNotify( NotifyEvent& rNEvt )
637 sal_uInt16 nType = rNEvt.GetType();
639 if ( EVENT_MOUSEBUTTONDOWN == nType || EVENT_GETFOCUS == nType )
640 nCurPos = GetSelectEntryPos();
641 else if ( EVENT_LOSEFOCUS == nType
642 && Application::GetFocusWindow()
643 && !IsWindowOrChild( Application::GetFocusWindow(), sal_True ) )
645 if ( !bSelect )
646 SelectEntryPos( nCurPos );
647 else
648 bSelect = sal_False;
651 return FillTypeLB::PreNotify( rNEvt );
654 // -----------------------------------------------------------------------
656 long SvxFillTypeBox::Notify( NotifyEvent& rNEvt )
658 long nHandled = FillTypeLB::Notify( rNEvt );
660 if ( rNEvt.GetType() == EVENT_KEYINPUT )
662 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
663 switch ( pKEvt->GetKeyCode().GetCode() )
665 case KEY_RETURN:
666 nHandled = 1;
667 ( (Link&)GetSelectHdl() ).Call( this );
668 break;
669 case KEY_TAB:
670 bRelease = sal_False;
671 ( (Link&)GetSelectHdl() ).Call( this );
672 bRelease = sal_True;
673 break;
675 case KEY_ESCAPE:
676 SelectEntryPos( nCurPos );
677 ReleaseFocus_Impl();
678 nHandled = 1;
679 break;
682 return nHandled;
685 // -----------------------------------------------------------------------
687 void SvxFillTypeBox::ReleaseFocus_Impl()
689 if( SfxViewShell::Current() )
691 Window* pShellWnd = SfxViewShell::Current()->GetWindow();
693 if ( pShellWnd )
694 pShellWnd->GrabFocus();
698 //========================================================================
699 // SvxFillAttrBox
700 //========================================================================
702 SvxFillAttrBox::SvxFillAttrBox( Window* pParent, WinBits nBits ) :
704 FillAttrLB( pParent, nBits | WB_TABSTOP ),
706 nCurPos( 0 ),
707 bRelease( sal_True )
710 SetPosPixel( Point( 90, 0 ) );
711 SetSizePixel( LogicToPixel( Size(50, 80 ), MAP_APPFONT ));
712 Show();
715 // -----------------------------------------------------------------------
717 SvxFillAttrBox::~SvxFillAttrBox()
721 // -----------------------------------------------------------------------
723 long SvxFillAttrBox::PreNotify( NotifyEvent& rNEvt )
725 sal_uInt16 nType = rNEvt.GetType();
727 if ( EVENT_MOUSEBUTTONDOWN == nType || EVENT_GETFOCUS == nType )
728 nCurPos = GetSelectEntryPos();
730 return FillAttrLB::PreNotify( rNEvt );
733 // -----------------------------------------------------------------------
735 long SvxFillAttrBox::Notify( NotifyEvent& rNEvt )
737 long nHandled = FillAttrLB::Notify( rNEvt );
739 if ( rNEvt.GetType() == EVENT_KEYINPUT )
741 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
743 switch ( pKEvt->GetKeyCode().GetCode() )
745 case KEY_RETURN:
746 ( (Link&)GetSelectHdl() ).Call( this );
747 nHandled = 1;
748 break;
749 case KEY_TAB:
750 bRelease = sal_False;
751 GetSelectHdl().Call( this );
752 bRelease = sal_True;
753 break;
754 case KEY_ESCAPE:
755 SelectEntryPos( nCurPos );
756 ReleaseFocus_Impl();
757 nHandled = 1;
758 break;
761 return nHandled;
764 // -----------------------------------------------------------------------
766 void SvxFillAttrBox::Select()
768 FillAttrLB::Select();
771 // -----------------------------------------------------------------------
773 void SvxFillAttrBox::ReleaseFocus_Impl()
775 if( SfxViewShell::Current() )
777 Window* pShellWnd = SfxViewShell::Current()->GetWindow();
779 if ( pShellWnd )
780 pShellWnd->GrabFocus();
784 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */