1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/drawing/FillStyle.hpp>
22 #include <sfx2/dispatch.hxx>
23 #include <sfx2/objsh.hxx>
24 #include <sfx2/viewsh.hxx>
25 #include <sfx2/module.hxx>
26 #include <tools/urlobj.hxx>
28 #include <vcl/svapp.hxx>
29 #include <vcl/settings.hxx>
30 #include <vcl/builderfactory.hxx>
32 #include <svx/dialogs.hrc>
34 #define DELAY_TIMEOUT 100
36 #include <svx/xlnclit.hxx>
37 #include <svx/xlnwtit.hxx>
38 #include <svx/xlineit0.hxx>
39 #include <svx/xlndsit.hxx>
40 #include <svx/xtable.hxx>
41 #include "svx/drawitem.hxx"
42 #include <svx/dialmgr.hxx>
43 #include "svx/dlgutil.hxx"
44 #include <svx/itemwin.hxx>
45 #include "svx/linectrl.hxx"
46 #include <svtools/colorcfg.hxx>
48 using namespace ::com::sun::star
;
49 using namespace ::com::sun::star::uno
;
50 using namespace ::com::sun::star::frame
;
51 using namespace ::com::sun::star::util
;
52 using namespace ::com::sun::star::lang
;
53 using namespace ::com::sun::star::beans
;
55 SvxLineBox::SvxLineBox( vcl::Window
* pParent
, const Reference
< XFrame
>& rFrame
, WinBits nBits
) :
56 LineLB( pParent
, nBits
),
63 SetSizePixel( LogicToPixel( aLogicalSize
, MAP_APPFONT
));
66 aDelayTimer
.SetTimeout( DELAY_TIMEOUT
);
67 aDelayTimer
.SetTimeoutHdl( LINK( this, SvxLineBox
, DelayHdl_Impl
) );
73 IMPL_LINK_NOARG_TYPED(SvxLineBox
, DelayHdl_Impl
, Timer
*, void)
75 if ( GetEntryCount() == 0 )
77 mpSh
= SfxObjectShell::Current();
84 void SvxLineBox::Select()
86 // Call the parent's Select() member to trigger accessibility events.
89 if ( !IsTravelSelect() )
91 drawing::LineStyle eXLS
;
92 sal_Int32 nPos
= GetSelectEntryPos();
97 eXLS
= drawing::LineStyle_NONE
;
101 eXLS
= drawing::LineStyle_SOLID
;
106 eXLS
= drawing::LineStyle_DASH
;
108 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
&&
109 SfxObjectShell::Current() &&
110 SfxObjectShell::Current()->GetItem( SID_DASH_LIST
) )
112 // LineDashItem will only be sent if it also has a dash.
114 SvxDashListItem
aItem( *static_cast<const SvxDashListItem
*>(
115 SfxObjectShell::Current()->GetItem( SID_DASH_LIST
) ) );
116 XLineDashItem
aLineDashItem( GetSelectEntry(),
117 aItem
.GetDashList()->GetDash( nPos
- 2 )->GetDash() );
120 Sequence
< PropertyValue
> aArgs( 1 );
121 aArgs
[0].Name
= "LineDash";
122 aLineDashItem
.QueryValue ( a
);
124 SfxToolBoxControl::Dispatch( Reference
< XDispatchProvider
>( mxFrame
->getController(), UNO_QUERY
),
125 OUString( ".uno:LineDash" ),
132 XLineStyleItem
aLineStyleItem( eXLS
);
134 Sequence
< PropertyValue
> aArgs( 1 );
135 aArgs
[0].Name
= "XLineStyle";
136 aLineStyleItem
.QueryValue ( a
);
138 SfxToolBoxControl::Dispatch( Reference
< XDispatchProvider
>( mxFrame
->getController(), UNO_QUERY
),
139 OUString( ".uno:XLineStyle" ),
142 nCurPos
= GetSelectEntryPos();
149 bool SvxLineBox::PreNotify( NotifyEvent
& rNEvt
)
151 MouseNotifyEvent nType
= rNEvt
.GetType();
155 case MouseNotifyEvent::MOUSEBUTTONDOWN
:
156 case MouseNotifyEvent::GETFOCUS
:
157 nCurPos
= GetSelectEntryPos();
159 case MouseNotifyEvent::LOSEFOCUS
:
160 SelectEntryPos(nCurPos
);
162 case MouseNotifyEvent::KEYINPUT
:
164 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
165 if( pKEvt
->GetKeyCode().GetCode() == KEY_TAB
)
175 return LineLB::PreNotify( rNEvt
);
180 bool SvxLineBox::Notify( NotifyEvent
& rNEvt
)
182 bool nHandled
= LineLB::Notify( rNEvt
);
184 if ( rNEvt
.GetType() == MouseNotifyEvent::KEYINPUT
)
186 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
188 switch ( pKEvt
->GetKeyCode().GetCode() )
196 SelectEntryPos( nCurPos
);
207 void SvxLineBox::ReleaseFocus_Impl()
215 if( SfxViewShell::Current() )
217 vcl::Window
* pShellWnd
= SfxViewShell::Current()->GetWindow();
220 pShellWnd
->GrabFocus();
224 void SvxLineBox::DataChanged( const DataChangedEvent
& rDCEvt
)
226 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
227 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
229 SetSizePixel(LogicToPixel(aLogicalSize
, MAP_APPFONT
));
232 LineLB::DataChanged( rDCEvt
);
235 void SvxLineBox::FillControl()
239 mpSh
= SfxObjectShell::Current();
243 const SvxDashListItem
* pItem
= static_cast<const SvxDashListItem
*>( mpSh
->GetItem( SID_DASH_LIST
) );
245 Fill( pItem
->GetDashList() );
249 SvxMetricField::SvxMetricField(
250 vcl::Window
* pParent
, const Reference
< XFrame
>& rFrame
, WinBits nBits
)
251 : MetricField(pParent
, nBits
)
253 , ePoolUnit(SFX_MAPUNIT_CM
)
256 Size aSize
= Size(GetTextWidth( OUString("99,99mm") ),GetTextHeight());
259 SetSizePixel( aSize
);
260 aLogicalSize
= PixelToLogic(aSize
, MAP_APPFONT
);
262 SetDecimalDigits( 2 );
268 eDlgUnit
= SfxModule::GetModuleFieldUnit( mxFrame
);
269 SetFieldUnit( *this, eDlgUnit
, false );
275 void SvxMetricField::Update( const XLineWidthItem
* pItem
)
279 if ( pItem
->GetValue() != GetCoreValue( *this, ePoolUnit
) )
280 SetMetricValue( *this, pItem
->GetValue(), ePoolUnit
);
288 void SvxMetricField::Modify()
290 MetricField::Modify();
291 long nTmp
= GetCoreValue( *this, ePoolUnit
);
292 XLineWidthItem
aLineWidthItem( nTmp
);
295 Sequence
< PropertyValue
> aArgs( 1 );
296 aArgs
[0].Name
= "LineWidth";
297 aLineWidthItem
.QueryValue( a
);
299 SfxToolBoxControl::Dispatch( Reference
< XDispatchProvider
>( mxFrame
->getController(), UNO_QUERY
),
300 OUString( ".uno:LineWidth" ),
306 void SvxMetricField::ReleaseFocus_Impl()
308 if( SfxViewShell::Current() )
310 vcl::Window
* pShellWnd
= SfxViewShell::Current()->GetWindow();
312 pShellWnd
->GrabFocus();
316 void SvxMetricField::Down()
321 void SvxMetricField::Up()
326 void SvxMetricField::SetCoreUnit( SfxMapUnit eUnit
)
331 void SvxMetricField::RefreshDlgUnit()
333 FieldUnit eTmpUnit
= SfxModule::GetModuleFieldUnit( mxFrame
);
334 if ( eDlgUnit
!= eTmpUnit
)
337 SetFieldUnit( *this, eDlgUnit
, false );
341 bool SvxMetricField::PreNotify( NotifyEvent
& rNEvt
)
343 MouseNotifyEvent nType
= rNEvt
.GetType();
345 if ( MouseNotifyEvent::MOUSEBUTTONDOWN
== nType
|| MouseNotifyEvent::GETFOCUS
== nType
)
348 return MetricField::PreNotify( rNEvt
);
353 bool SvxMetricField::Notify( NotifyEvent
& rNEvt
)
355 bool nHandled
= MetricField::Notify( rNEvt
);
357 if ( rNEvt
.GetType() == MouseNotifyEvent::KEYINPUT
)
359 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
360 const vcl::KeyCode
& rKey
= pKEvt
->GetKeyCode();
361 SfxViewShell
* pSh
= SfxViewShell::Current();
363 if ( rKey
.GetModifier() && rKey
.GetGroup() != KEYGROUP_CURSOR
&& pSh
)
364 (void)pSh
->KeyInput( *pKEvt
);
367 bool bHandled
= false;
369 switch ( rKey
.GetCode() )
393 void SvxMetricField::DataChanged( const DataChangedEvent
& rDCEvt
)
395 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
396 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
398 SetSizePixel(LogicToPixel(aLogicalSize
, MAP_APPFONT
));
401 MetricField::DataChanged( rDCEvt
);
404 SvxFillTypeBox::SvxFillTypeBox( vcl::Window
* pParent
, WinBits nBits
) :
405 FillTypeLB( pParent
, nBits
| WB_TABSTOP
),
410 SetSizePixel( LogicToPixel( Size(40, 40 ),MAP_APPFONT
));
412 SelectEntryPos( drawing::FillStyle_SOLID
);
416 VCL_BUILDER_FACTORY(SvxFillTypeBox
)
418 bool SvxFillTypeBox::PreNotify( NotifyEvent
& rNEvt
)
420 MouseNotifyEvent nType
= rNEvt
.GetType();
424 if ( MouseNotifyEvent::MOUSEBUTTONDOWN
== nType
|| MouseNotifyEvent::GETFOCUS
== nType
)
425 nCurPos
= GetSelectEntryPos();
426 else if ( MouseNotifyEvent::LOSEFOCUS
== nType
427 && Application::GetFocusWindow()
428 && !IsWindowOrChild( Application::GetFocusWindow(), true ) )
431 SelectEntryPos( nCurPos
);
437 return FillTypeLB::PreNotify( rNEvt
);
442 bool SvxFillTypeBox::Notify( NotifyEvent
& rNEvt
)
444 bool nHandled
= FillTypeLB::Notify( rNEvt
);
449 if ( rNEvt
.GetType() == MouseNotifyEvent::KEYINPUT
)
451 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
452 switch ( pKEvt
->GetKeyCode().GetCode() )
456 ( (Link
<>&)GetSelectHdl() ).Call( this );
460 ( (Link
<>&)GetSelectHdl() ).Call( this );
465 SelectEntryPos( nCurPos
);
476 void SvxFillTypeBox::ReleaseFocus_Impl()
478 if( SfxViewShell::Current() )
480 vcl::Window
* pShellWnd
= SfxViewShell::Current()->GetWindow();
483 pShellWnd
->GrabFocus();
487 SvxFillAttrBox::SvxFillAttrBox( vcl::Window
* pParent
, WinBits nBits
) :
488 FillAttrLB( pParent
, nBits
| WB_TABSTOP
),
493 SetPosPixel( Point( 90, 0 ) );
494 SetSizePixel( LogicToPixel( Size(50, 80 ), MAP_APPFONT
));
498 VCL_BUILDER_FACTORY(SvxFillAttrBox
)
500 bool SvxFillAttrBox::PreNotify( NotifyEvent
& rNEvt
)
502 MouseNotifyEvent nType
= rNEvt
.GetType();
504 if ( MouseNotifyEvent::MOUSEBUTTONDOWN
== nType
|| MouseNotifyEvent::GETFOCUS
== nType
)
505 nCurPos
= GetSelectEntryPos();
507 return FillAttrLB::PreNotify( rNEvt
);
512 bool SvxFillAttrBox::Notify( NotifyEvent
& rNEvt
)
514 bool nHandled
= FillAttrLB::Notify( rNEvt
);
516 if ( rNEvt
.GetType() == MouseNotifyEvent::KEYINPUT
)
518 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
520 switch ( pKEvt
->GetKeyCode().GetCode() )
523 ( (Link
<>&)GetSelectHdl() ).Call( this );
528 GetSelectHdl().Call( this );
532 SelectEntryPos( nCurPos
);
543 void SvxFillAttrBox::Select()
545 FillAttrLB::Select();
550 void SvxFillAttrBox::ReleaseFocus_Impl()
552 if( SfxViewShell::Current() )
554 vcl::Window
* pShellWnd
= SfxViewShell::Current()->GetWindow();
557 pShellWnd
->GrabFocus();
561 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */