1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: itemwin.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 // include ---------------------------------------------------------------
35 #include <tools/shl.hxx>
36 #include <sfx2/dispatch.hxx>
37 #include <sfx2/objsh.hxx>
38 #include <sfx2/viewsh.hxx>
39 #include <sfx2/module.hxx>
40 #include <tools/urlobj.hxx>
42 #define _SVX_ITEMWIN_CXX
44 #include <vcl/svapp.hxx>
46 #include <svx/dialogs.hrc>
48 #define DELAY_TIMEOUT 100
50 #include <svx/xlnclit.hxx>
51 #include <svx/xlnwtit.hxx>
52 #include <svx/xlineit0.hxx>
53 #include <svx/xlndsit.hxx>
54 #include <svx/xtable.hxx>
55 #include "drawitem.hxx"
56 #include <svx/dialmgr.hxx>
57 #include "dlgutil.hxx"
58 #include <svx/itemwin.hxx>
59 #include "linectrl.hxx"
60 #include <svtools/colorcfg.hxx>
62 #include "linectrl.hrc"
64 using namespace ::com::sun::star::uno
;
65 using namespace ::com::sun::star::frame
;
66 using namespace ::com::sun::star::util
;
67 using namespace ::com::sun::star::lang
;
68 using namespace ::com::sun::star::beans
;
70 #define LOGICAL_EDIT_HEIGHT 12
71 //========================================================================
73 //========================================================================
75 SvxLineBox::SvxLineBox( Window
* pParent
, const Reference
< XFrame
>& rFrame
, WinBits nBits
) :
76 LineLB( pParent
, nBits
),
77 meBmpMode ( GetDisplayBackground().GetColor().IsDark() ? BMP_COLOR_HIGHCONTRAST
: BMP_COLOR_NORMAL
),
84 SetSizePixel( LogicToPixel( aLogicalSize
, MAP_APPFONT
));
87 aDelayTimer
.SetTimeout( DELAY_TIMEOUT
);
88 aDelayTimer
.SetTimeoutHdl( LINK( this, SvxLineBox
, DelayHdl_Impl
) );
92 // -----------------------------------------------------------------------
94 SvxLineBox::~SvxLineBox()
98 // -----------------------------------------------------------------------
100 IMPL_LINK( SvxLineBox
, DelayHdl_Impl
, Timer
*, EMPTYARG
)
102 if ( GetEntryCount() == 0 )
104 mpSh
= SfxObjectShell::Current();
110 // -----------------------------------------------------------------------
112 void SvxLineBox::Select()
114 // Call the parent's Select() member to trigger accessibility events.
117 if ( !IsTravelSelect() )
120 USHORT nPos
= GetSelectEntryPos();
121 // SfxDispatcher* pDisp = rBindings.GetDispatcher();
122 //DBG_ASSERT( pDisp, "invalid Dispatcher" );
138 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
&&
139 SfxObjectShell::Current() &&
140 SfxObjectShell::Current()->GetItem( SID_DASH_LIST
) )
142 // LineDashItem wird nur geschickt, wenn es auch einen Dash besitzt.
143 // Notify k"ummert sich darum!
144 SvxDashListItem
aItem( *(const SvxDashListItem
*)(
145 SfxObjectShell::Current()->GetItem( SID_DASH_LIST
) ) );
146 XLineDashItem
aLineDashItem( GetSelectEntry(),
147 aItem
.GetDashList()->GetDash( nPos
- 2 )->GetDash() );
150 Sequence
< PropertyValue
> aArgs( 1 );
151 aArgs
[0].Name
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LineDash" ));
152 aLineDashItem
.QueryValue ( a
);
154 SfxToolBoxControl::Dispatch( Reference
< XDispatchProvider
>( mxFrame
->getController(), UNO_QUERY
),
155 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:LineDash" )),
157 // pDisp->Execute( SID_ATTR_LINE_DASH, SFX_CALLMODE_RECORD, &aLineDashItem, 0L );
163 XLineStyleItem
aLineStyleItem( eXLS
);
165 Sequence
< PropertyValue
> aArgs( 1 );
166 aArgs
[0].Name
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XLineStyle" ));
167 aLineStyleItem
.QueryValue ( a
);
169 SfxToolBoxControl::Dispatch( Reference
< XDispatchProvider
>( mxFrame
->getController(), UNO_QUERY
),
170 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:XLineStyle" )),
172 // pDisp->Execute( SID_ATTR_LINE_STYLE, SFX_CALLMODE_RECORD, &aLineStyleItem, 0L );
174 nCurPos
= GetSelectEntryPos();
179 // -----------------------------------------------------------------------
181 long SvxLineBox::PreNotify( NotifyEvent
& rNEvt
)
183 USHORT nType
= rNEvt
.GetType();
187 case EVENT_MOUSEBUTTONDOWN
:
189 nCurPos
= GetSelectEntryPos();
191 case EVENT_LOSEFOCUS
:
192 SelectEntryPos(nCurPos
);
196 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
197 if( pKEvt
->GetKeyCode().GetCode() == KEY_TAB
)
205 return LineLB::PreNotify( rNEvt
);
208 // -----------------------------------------------------------------------
210 long SvxLineBox::Notify( NotifyEvent
& rNEvt
)
212 long nHandled
= LineLB::Notify( rNEvt
);
214 if ( rNEvt
.GetType() == EVENT_KEYINPUT
)
216 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
218 switch ( pKEvt
->GetKeyCode().GetCode() )
226 SelectEntryPos( nCurPos
);
235 // -----------------------------------------------------------------------
237 void SvxLineBox::ReleaseFocus_Impl()
245 if( SfxViewShell::Current() )
247 Window
* pShellWnd
= SfxViewShell::Current()->GetWindow();
250 pShellWnd
->GrabFocus();
253 /* -----------------------------08.03.2002 15:39------------------------------
255 ---------------------------------------------------------------------------*/
256 void SvxLineBox::DataChanged( const DataChangedEvent
& rDCEvt
)
258 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
259 (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
261 SetSizePixel(LogicToPixel(aLogicalSize
, MAP_APPFONT
));
262 Size
aDropSize( aLogicalSize
.Width(), LOGICAL_EDIT_HEIGHT
);
263 SetDropDownSizePixel(LogicToPixel(aDropSize
, MAP_APPFONT
));
266 LineLB::DataChanged( rDCEvt
);
268 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
269 (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
271 BmpColorMode eMode
= GetDisplayBackground().GetColor().IsDark() ? BMP_COLOR_HIGHCONTRAST
: BMP_COLOR_NORMAL
;
272 if( eMode
!= meBmpMode
)
280 void SvxLineBox::FillControl()
284 InsertEntry( SVX_RESSTR(RID_SVXSTR_INVISIBLE
) );
286 Bitmap
aBitmap ( SVX_RES ( RID_SVXCTRL_LINECTRL
) );
288 ::Color aSourceColors
[2];
289 ::Color aDestColors
[2];
291 aSourceColors
[0] = ::Color( COL_WHITE
);
292 aSourceColors
[1] = ::Color( COL_BLACK
);
294 const StyleSettings
& rStyles
= Application::GetSettings().GetStyleSettings();
295 aDestColors
[0] = rStyles
.GetFieldColor();
296 aDestColors
[1] = rStyles
.GetFieldTextColor();
298 aBitmap
.Replace ( aSourceColors
, aDestColors
, 2 );
299 Image
aSolidLine ( aBitmap
);
300 InsertEntry( SVX_RESSTR(RID_SVXSTR_SOLID
), aSolidLine
);
303 mpSh
= SfxObjectShell::Current();
307 const SvxDashListItem
* pItem
= (const SvxDashListItem
*)( mpSh
->GetItem( SID_DASH_LIST
) );
309 Fill( pItem
->GetDashList() );
312 // rBindings.Invalidate( SID_ATTR_LINE_DASH );
314 //========================================================================
316 //========================================================================
318 SvxColorBox::SvxColorBox(
320 const ::rtl::OUString
& rCommand
,
321 const Reference
< XFrame
>& rFrame
,
323 ColorLB( pParent
, nBits
),
327 maCommand ( rCommand
),
330 SetSizePixel( LogicToPixel( aLogicalSize
, MAP_APPFONT
));
333 SfxObjectShell
* pSh
= SfxObjectShell::Current();
337 const SvxColorTableItem
* pItem
=
338 (const SvxColorTableItem
*)( pSh
->GetItem( SID_COLOR_TABLE
) );
340 Fill( pItem
->GetColorTable() );
344 // -----------------------------------------------------------------------
346 IMPL_LINK( SvxColorBox
, DelayHdl_Impl
, Timer
*, EMPTYARG
)
348 SfxObjectShell
* pSh
= SfxObjectShell::Current();
352 const SvxColorTableItem
* pItem
= (const SvxColorTableItem
*)( pSh
->GetItem( SID_COLOR_TABLE
) );
354 Fill( pItem
->GetColorTable() );
355 // rBindings.Invalidate( nId );
360 // -----------------------------------------------------------------------
362 SvxColorBox::~SvxColorBox()
366 // -----------------------------------------------------------------------
368 void SvxColorBox::Update( const XLineColorItem
* pItem
)
371 SelectEntry( pItem
->GetColorValue() );
376 // -----------------------------------------------------------------------
378 void SvxColorBox::Select()
380 // OJ: base class call needed here because otherwise no event is send for accessibility
382 if ( !IsTravelSelect() )
384 XLineColorItem
aLineColorItem( GetSelectEntry(), GetSelectEntryColor() );
386 INetURLObject
aObj( maCommand
);
389 Sequence
< PropertyValue
> aArgs( 1 );
390 aArgs
[0].Name
= aObj
.GetURLPath();
391 aLineColorItem
.QueryValue( a
);
393 SfxToolBoxControl::Dispatch( Reference
< XDispatchProvider
>( mxFrame
->getController(), UNO_QUERY
),
396 // rBindings.GetDispatcher()->Execute( nId, SFX_CALLMODE_RECORD, &aLineColorItem, 0L );
398 nCurPos
= GetSelectEntryPos();
403 // -----------------------------------------------------------------------
405 long SvxColorBox::PreNotify( NotifyEvent
& rNEvt
)
407 USHORT nType
= rNEvt
.GetType();
411 case EVENT_MOUSEBUTTONDOWN
:
413 nCurPos
= GetSelectEntryPos();
415 case EVENT_LOSEFOCUS
:
416 SelectEntryPos(nCurPos
);
420 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
422 if( pKEvt
->GetKeyCode().GetCode() == KEY_TAB
)
430 return ColorLB::PreNotify( rNEvt
);
433 // -----------------------------------------------------------------------
435 long SvxColorBox::Notify( NotifyEvent
& rNEvt
)
437 long nHandled
= ColorLB::Notify( rNEvt
);
439 if ( rNEvt
.GetType() == EVENT_KEYINPUT
)
441 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
443 switch ( pKEvt
->GetKeyCode().GetCode() )
451 SelectEntryPos( nCurPos
);
459 /* -----------------------------08.03.2002 15:35------------------------------
461 ---------------------------------------------------------------------------*/
462 void SvxColorBox::DataChanged( const DataChangedEvent
& rDCEvt
)
464 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
465 (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
467 SetSizePixel(LogicToPixel(aLogicalSize
, MAP_APPFONT
));
468 Size
aDropSize( aLogicalSize
.Width(), LOGICAL_EDIT_HEIGHT
);
469 SetDropDownSizePixel(LogicToPixel(aDropSize
, MAP_APPFONT
));
472 ColorLB::DataChanged( rDCEvt
);
474 // -----------------------------------------------------------------------
476 void SvxColorBox::ReleaseFocus_Impl()
484 if( SfxViewShell::Current() )
486 Window
* pShellWnd
= SfxViewShell::Current()->GetWindow();
489 pShellWnd
->GrabFocus();
493 //========================================================================
495 //========================================================================
497 SvxMetricField::SvxMetricField(
498 Window
* pParent
, const Reference
< XFrame
>& rFrame
, WinBits nBits
) :
499 MetricField( pParent
, nBits
),
503 Size aSize
= Size(GetTextWidth( String::CreateFromAscii("99,99mm") ),GetTextHeight());
506 SetSizePixel( aSize
);
507 aLogicalSize
= PixelToLogic(aSize
, MAP_APPFONT
);
509 SetDecimalDigits( 2 );
515 eDlgUnit
= GetModuleFieldUnit( NULL
);
516 SetFieldUnit( *this, eDlgUnit
, FALSE
);
520 // -----------------------------------------------------------------------
522 SvxMetricField::~SvxMetricField()
526 // -----------------------------------------------------------------------
528 void SvxMetricField::Update( const XLineWidthItem
* pItem
)
532 if ( pItem
->GetValue() != GetCoreValue( *this, ePoolUnit
) )
533 SetMetricValue( *this, pItem
->GetValue(), ePoolUnit
);
539 // -----------------------------------------------------------------------
541 void SvxMetricField::Modify()
543 MetricField::Modify();
544 long nTmp
= GetCoreValue( *this, ePoolUnit
);
545 XLineWidthItem
aLineWidthItem( nTmp
);
548 Sequence
< PropertyValue
> aArgs( 1 );
549 aArgs
[0].Name
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LineWidth" ));
550 aLineWidthItem
.QueryValue( a
);
552 SfxToolBoxControl::Dispatch( Reference
< XDispatchProvider
>( mxFrame
->getController(), UNO_QUERY
),
553 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:LineWidth" )),
555 // rBindings.GetDispatcher()->Execute( SID_ATTR_LINE_WIDTH, SFX_CALLMODE_RECORD, &aLineWidthItem, 0L );
558 // -----------------------------------------------------------------------
560 void SvxMetricField::ReleaseFocus_Impl()
562 if( SfxViewShell::Current() )
564 Window
* pShellWnd
= SfxViewShell::Current()->GetWindow();
566 pShellWnd
->GrabFocus();
570 // -----------------------------------------------------------------------
572 void SvxMetricField::Down()
574 sal_Int64 nValue
= GetValue();
575 nValue
-= GetSpinSize();
577 // Um unter OS/2 einen Sprung auf Max zu verhindern
578 if ( nValue
>= GetMin() )
582 // -----------------------------------------------------------------------
584 void SvxMetricField::Up()
589 // -----------------------------------------------------------------------
591 void SvxMetricField::SetCoreUnit( SfxMapUnit eUnit
)
596 // -----------------------------------------------------------------------
598 void SvxMetricField::RefreshDlgUnit()
600 FieldUnit eTmpUnit
= GetModuleFieldUnit( NULL
);
602 if ( eDlgUnit
!= eTmpUnit
)
605 SetFieldUnit( *this, eDlgUnit
, FALSE
);
609 // -----------------------------------------------------------------------
611 long SvxMetricField::PreNotify( NotifyEvent
& rNEvt
)
613 USHORT nType
= rNEvt
.GetType();
615 if ( EVENT_MOUSEBUTTONDOWN
== nType
|| EVENT_GETFOCUS
== nType
)
618 return MetricField::PreNotify( rNEvt
);
621 // -----------------------------------------------------------------------
623 long SvxMetricField::Notify( NotifyEvent
& rNEvt
)
625 long nHandled
= MetricField::Notify( rNEvt
);
627 if ( rNEvt
.GetType() == EVENT_KEYINPUT
)
629 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
630 const KeyCode
& rKey
= pKEvt
->GetKeyCode();
631 SfxViewShell
* pSh
= SfxViewShell::Current();
633 if ( rKey
.GetModifier() && rKey
.GetGroup() != KEYGROUP_CURSOR
&& pSh
)
634 pSh
->KeyInput( *pKEvt
);
637 FASTBOOL bHandled
= FALSE
;
639 switch ( rKey
.GetCode() )
662 /* -----------------------------08.03.2002 15:32------------------------------
664 ---------------------------------------------------------------------------*/
665 void SvxMetricField::DataChanged( const DataChangedEvent
& rDCEvt
)
667 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
668 (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
670 SetSizePixel(LogicToPixel(aLogicalSize
, MAP_APPFONT
));
673 MetricField::DataChanged( rDCEvt
);
676 //========================================================================
678 //========================================================================
680 SvxFillTypeBox::SvxFillTypeBox( Window
* pParent
, WinBits nBits
) :
681 FillTypeLB( pParent
, nBits
| WB_TABSTOP
),
686 SetSizePixel( LogicToPixel( Size(40, 40 ),MAP_APPFONT
));
688 SelectEntryPos( XFILL_SOLID
);
692 // -----------------------------------------------------------------------
694 SvxFillTypeBox::~SvxFillTypeBox()
698 // -----------------------------------------------------------------------
700 long SvxFillTypeBox::PreNotify( NotifyEvent
& rNEvt
)
702 USHORT nType
= rNEvt
.GetType();
704 if ( EVENT_MOUSEBUTTONDOWN
== nType
|| EVENT_GETFOCUS
== nType
)
705 nCurPos
= GetSelectEntryPos();
706 else if ( EVENT_LOSEFOCUS
== nType
707 && Application::GetFocusWindow()
708 && !IsWindowOrChild( Application::GetFocusWindow(), TRUE
) )
711 SelectEntryPos( nCurPos
);
716 return FillTypeLB::PreNotify( rNEvt
);
719 // -----------------------------------------------------------------------
721 long SvxFillTypeBox::Notify( NotifyEvent
& rNEvt
)
723 long nHandled
= FillTypeLB::Notify( rNEvt
);
725 if ( rNEvt
.GetType() == EVENT_KEYINPUT
)
727 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
728 switch ( pKEvt
->GetKeyCode().GetCode() )
732 ( (Link
&)GetSelectHdl() ).Call( this );
736 ( (Link
&)GetSelectHdl() ).Call( this );
741 SelectEntryPos( nCurPos
);
750 // -----------------------------------------------------------------------
752 void SvxFillTypeBox::ReleaseFocus_Impl()
754 if( SfxViewShell::Current() )
756 Window
* pShellWnd
= SfxViewShell::Current()->GetWindow();
759 pShellWnd
->GrabFocus();
763 //========================================================================
765 //========================================================================
767 SvxFillAttrBox::SvxFillAttrBox( Window
* pParent
, WinBits nBits
) :
769 FillAttrLB( pParent
, nBits
| WB_TABSTOP
),
775 SetPosPixel( Point( 90, 0 ) );
776 SetSizePixel( LogicToPixel( Size(50, 80 ), MAP_APPFONT
));
780 // -----------------------------------------------------------------------
782 SvxFillAttrBox::~SvxFillAttrBox()
786 // -----------------------------------------------------------------------
788 long SvxFillAttrBox::PreNotify( NotifyEvent
& rNEvt
)
790 USHORT nType
= rNEvt
.GetType();
792 if ( EVENT_MOUSEBUTTONDOWN
== nType
|| EVENT_GETFOCUS
== nType
)
793 nCurPos
= GetSelectEntryPos();
795 return FillAttrLB::PreNotify( rNEvt
);
798 // -----------------------------------------------------------------------
800 long SvxFillAttrBox::Notify( NotifyEvent
& rNEvt
)
802 long nHandled
= FillAttrLB::Notify( rNEvt
);
804 if ( rNEvt
.GetType() == EVENT_KEYINPUT
)
806 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
808 switch ( pKEvt
->GetKeyCode().GetCode() )
811 ( (Link
&)GetSelectHdl() ).Call( this );
816 GetSelectHdl().Call( this );
820 SelectEntryPos( nCurPos
);
829 // -----------------------------------------------------------------------
831 void SvxFillAttrBox::Select()
833 FillAttrLB::Select();
836 // -----------------------------------------------------------------------
838 void SvxFillAttrBox::ReleaseFocus_Impl()
840 if( SfxViewShell::Current() )
842 Window
* pShellWnd
= SfxViewShell::Current()->GetWindow();
845 pShellWnd
->GrabFocus();