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 //========================================================================
69 //========================================================================
71 SvxLineBox::SvxLineBox( Window
* pParent
, const Reference
< XFrame
>& rFrame
, WinBits nBits
) :
72 LineLB( pParent
, nBits
),
75 bRelease ( sal_True
),
79 SetSizePixel( LogicToPixel( aLogicalSize
, MAP_APPFONT
));
82 aDelayTimer
.SetTimeout( DELAY_TIMEOUT
);
83 aDelayTimer
.SetTimeoutHdl( LINK( this, SvxLineBox
, DelayHdl_Impl
) );
87 // -----------------------------------------------------------------------
89 SvxLineBox::~SvxLineBox()
93 // -----------------------------------------------------------------------
95 IMPL_LINK_NOARG(SvxLineBox
, DelayHdl_Impl
)
97 if ( GetEntryCount() == 0 )
99 mpSh
= SfxObjectShell::Current();
105 // -----------------------------------------------------------------------
107 void SvxLineBox::Select()
109 // Call the parent's Select() member to trigger accessibility events.
112 if ( !IsTravelSelect() )
115 sal_uInt16 nPos
= GetSelectEntryPos();
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() );
143 Sequence
< PropertyValue
> aArgs( 1 );
144 aArgs
[0].Name
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LineDash" ));
145 aLineDashItem
.QueryValue ( a
);
147 SfxToolBoxControl::Dispatch( Reference
< XDispatchProvider
>( mxFrame
->getController(), UNO_QUERY
),
148 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:LineDash" )),
155 XLineStyleItem
aLineStyleItem( eXLS
);
157 Sequence
< PropertyValue
> aArgs( 1 );
158 aArgs
[0].Name
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XLineStyle" ));
159 aLineStyleItem
.QueryValue ( a
);
161 SfxToolBoxControl::Dispatch( Reference
< XDispatchProvider
>( mxFrame
->getController(), UNO_QUERY
),
162 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:XLineStyle" )),
165 nCurPos
= GetSelectEntryPos();
170 // -----------------------------------------------------------------------
172 long SvxLineBox::PreNotify( NotifyEvent
& rNEvt
)
174 sal_uInt16 nType
= rNEvt
.GetType();
178 case EVENT_MOUSEBUTTONDOWN
:
180 nCurPos
= GetSelectEntryPos();
182 case EVENT_LOSEFOCUS
:
183 SelectEntryPos(nCurPos
);
187 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
188 if( pKEvt
->GetKeyCode().GetCode() == KEY_TAB
)
190 bRelease
= sal_False
;
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() )
217 SelectEntryPos( nCurPos
);
226 // -----------------------------------------------------------------------
228 void SvxLineBox::ReleaseFocus_Impl()
236 if( SfxViewShell::Current() )
238 Window
* pShellWnd
= SfxViewShell::Current()->GetWindow();
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()
262 mpSh
= SfxObjectShell::Current();
266 const SvxDashListItem
* pItem
= (const SvxDashListItem
*)( mpSh
->GetItem( SID_DASH_LIST
) );
268 Fill( pItem
->GetDashList() );
272 //========================================================================
274 //========================================================================
276 SvxColorBox::SvxColorBox(
278 const ::rtl::OUString
& rCommand
,
279 const Reference
< XFrame
>& rFrame
,
281 ColorLB( pParent
, nBits
),
284 bRelease ( sal_True
),
285 maCommand ( rCommand
),
288 SetSizePixel( LogicToPixel( aLogicalSize
, MAP_APPFONT
));
291 SfxObjectShell
* pSh
= SfxObjectShell::Current();
295 const SvxColorListItem
* pItem
=
296 (const SvxColorListItem
*)( pSh
->GetItem( SID_COLOR_TABLE
) );
298 Fill( pItem
->GetColorList() );
302 // -----------------------------------------------------------------------
304 SvxColorBox::~SvxColorBox()
308 // -----------------------------------------------------------------------
310 void SvxColorBox::Update( const XLineColorItem
* pItem
)
313 SelectEntry( pItem
->GetColorValue() );
318 // -----------------------------------------------------------------------
320 void SvxColorBox::Select()
322 // OJ: base class call needed here because otherwise no event is send for accessibility
324 if ( !IsTravelSelect() )
326 XLineColorItem
aLineColorItem( GetSelectEntry(), GetSelectEntryColor() );
328 INetURLObject
aObj( maCommand
);
331 Sequence
< PropertyValue
> aArgs( 1 );
332 aArgs
[0].Name
= aObj
.GetURLPath();
333 aLineColorItem
.QueryValue( a
);
335 SfxToolBoxControl::Dispatch( Reference
< XDispatchProvider
>( mxFrame
->getController(), UNO_QUERY
),
339 nCurPos
= GetSelectEntryPos();
344 // -----------------------------------------------------------------------
346 long SvxColorBox::PreNotify( NotifyEvent
& rNEvt
)
348 sal_uInt16 nType
= rNEvt
.GetType();
352 case EVENT_MOUSEBUTTONDOWN
:
354 nCurPos
= GetSelectEntryPos();
356 case EVENT_LOSEFOCUS
:
357 SelectEntryPos(nCurPos
);
361 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
363 if( pKEvt
->GetKeyCode().GetCode() == KEY_TAB
)
365 bRelease
= sal_False
;
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() )
392 SelectEntryPos( nCurPos
);
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()
423 if( SfxViewShell::Current() )
425 Window
* pShellWnd
= SfxViewShell::Current()->GetWindow();
428 pShellWnd
->GrabFocus();
432 //========================================================================
434 //========================================================================
436 SvxMetricField::SvxMetricField(
437 Window
* pParent
, const Reference
< XFrame
>& rFrame
, WinBits nBits
) :
438 MetricField( pParent
, nBits
),
442 Size aSize
= Size(GetTextWidth( String::CreateFromAscii("99,99mm") ),GetTextHeight());
445 SetSizePixel( aSize
);
446 aLogicalSize
= PixelToLogic(aSize
, MAP_APPFONT
);
448 SetDecimalDigits( 2 );
454 eDlgUnit
= SfxModule::GetModuleFieldUnit( mxFrame
);
455 SetFieldUnit( *this, eDlgUnit
, sal_False
);
459 // -----------------------------------------------------------------------
461 SvxMetricField::~SvxMetricField()
465 // -----------------------------------------------------------------------
467 void SvxMetricField::Update( const XLineWidthItem
* pItem
)
471 if ( pItem
->GetValue() != GetCoreValue( *this, ePoolUnit
) )
472 SetMetricValue( *this, pItem
->GetValue(), ePoolUnit
);
478 // -----------------------------------------------------------------------
480 void SvxMetricField::Modify()
482 MetricField::Modify();
483 long nTmp
= GetCoreValue( *this, ePoolUnit
);
484 XLineWidthItem
aLineWidthItem( nTmp
);
487 Sequence
< PropertyValue
> aArgs( 1 );
488 aArgs
[0].Name
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LineWidth" ));
489 aLineWidthItem
.QueryValue( a
);
491 SfxToolBoxControl::Dispatch( Reference
< XDispatchProvider
>( mxFrame
->getController(), UNO_QUERY
),
492 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:LineWidth" )),
496 // -----------------------------------------------------------------------
498 void SvxMetricField::ReleaseFocus_Impl()
500 if( SfxViewShell::Current() )
502 Window
* pShellWnd
= SfxViewShell::Current()->GetWindow();
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() )
520 // -----------------------------------------------------------------------
522 void SvxMetricField::Up()
527 // -----------------------------------------------------------------------
529 void SvxMetricField::SetCoreUnit( SfxMapUnit eUnit
)
534 // -----------------------------------------------------------------------
536 void SvxMetricField::RefreshDlgUnit()
538 FieldUnit eTmpUnit
= SfxModule::GetModuleFieldUnit( mxFrame
);
539 if ( 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
)
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
);
574 bool bHandled
= false;
576 switch ( rKey
.GetCode() )
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 //========================================================================
613 //========================================================================
615 SvxFillTypeBox::SvxFillTypeBox( Window
* pParent
, WinBits nBits
) :
616 FillTypeLB( pParent
, nBits
| WB_TABSTOP
),
618 bSelect ( sal_False
),
621 SetSizePixel( LogicToPixel( Size(40, 40 ),MAP_APPFONT
));
623 SelectEntryPos( XFILL_SOLID
);
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
) )
646 SelectEntryPos( nCurPos
);
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() )
667 ( (Link
&)GetSelectHdl() ).Call( this );
670 bRelease
= sal_False
;
671 ( (Link
&)GetSelectHdl() ).Call( this );
676 SelectEntryPos( nCurPos
);
685 // -----------------------------------------------------------------------
687 void SvxFillTypeBox::ReleaseFocus_Impl()
689 if( SfxViewShell::Current() )
691 Window
* pShellWnd
= SfxViewShell::Current()->GetWindow();
694 pShellWnd
->GrabFocus();
698 //========================================================================
700 //========================================================================
702 SvxFillAttrBox::SvxFillAttrBox( Window
* pParent
, WinBits nBits
) :
704 FillAttrLB( pParent
, nBits
| WB_TABSTOP
),
710 SetPosPixel( Point( 90, 0 ) );
711 SetSizePixel( LogicToPixel( Size(50, 80 ), MAP_APPFONT
));
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() )
746 ( (Link
&)GetSelectHdl() ).Call( this );
750 bRelease
= sal_False
;
751 GetSelectHdl().Call( this );
755 SelectEntryPos( nCurPos
);
764 // -----------------------------------------------------------------------
766 void SvxFillAttrBox::Select()
768 FillAttrLB::Select();
771 // -----------------------------------------------------------------------
773 void SvxFillAttrBox::ReleaseFocus_Impl()
775 if( SfxViewShell::Current() )
777 Window
* pShellWnd
= SfxViewShell::Current()->GetWindow();
780 pShellWnd
->GrabFocus();
784 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */