bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / tbxctrls / itemwin.cxx
blobe4e207ff7d185e820c5b052cffa509623485d480
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 ),
57 nCurPos ( 0 ),
58 aLogicalSize(40,140),
59 bRelease ( true ),
60 mpSh ( NULL ),
61 mxFrame ( rFrame )
63 SetSizePixel( LogicToPixel( aLogicalSize, MAP_APPFONT ));
64 Show();
66 aDelayTimer.SetTimeout( DELAY_TIMEOUT );
67 aDelayTimer.SetTimeoutHdl( LINK( this, SvxLineBox, DelayHdl_Impl ) );
68 aDelayTimer.Start();
73 IMPL_LINK_NOARG_TYPED(SvxLineBox, DelayHdl_Impl, Timer *, void)
75 if ( GetEntryCount() == 0 )
77 mpSh = SfxObjectShell::Current();
78 FillControl();
84 void SvxLineBox::Select()
86 // Call the parent's Select() member to trigger accessibility events.
87 LineLB::Select();
89 if ( !IsTravelSelect() )
91 drawing::LineStyle eXLS;
92 sal_Int32 nPos = GetSelectEntryPos();
94 switch ( nPos )
96 case 0:
97 eXLS = drawing::LineStyle_NONE;
98 break;
100 case 1:
101 eXLS = drawing::LineStyle_SOLID;
102 break;
104 default:
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.
113 // Notify cares!
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() );
119 Any a;
120 Sequence< PropertyValue > aArgs( 1 );
121 aArgs[0].Name = "LineDash";
122 aLineDashItem.QueryValue ( a );
123 aArgs[0].Value = a;
124 SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
125 OUString( ".uno:LineDash" ),
126 aArgs );
129 break;
132 XLineStyleItem aLineStyleItem( eXLS );
133 Any a;
134 Sequence< PropertyValue > aArgs( 1 );
135 aArgs[0].Name = "XLineStyle";
136 aLineStyleItem.QueryValue ( a );
137 aArgs[0].Value = a;
138 SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
139 OUString( ".uno:XLineStyle" ),
140 aArgs );
142 nCurPos = GetSelectEntryPos();
143 ReleaseFocus_Impl();
149 bool SvxLineBox::PreNotify( NotifyEvent& rNEvt )
151 MouseNotifyEvent nType = rNEvt.GetType();
153 switch(nType)
155 case MouseNotifyEvent::MOUSEBUTTONDOWN:
156 case MouseNotifyEvent::GETFOCUS:
157 nCurPos = GetSelectEntryPos();
158 break;
159 case MouseNotifyEvent::LOSEFOCUS:
160 SelectEntryPos(nCurPos);
161 break;
162 case MouseNotifyEvent::KEYINPUT:
164 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
165 if( pKEvt->GetKeyCode().GetCode() == KEY_TAB)
167 bRelease = false;
168 Select();
171 break;
172 default:
173 break;
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() )
190 case KEY_RETURN:
191 Select();
192 nHandled = true;
193 break;
195 case KEY_ESCAPE:
196 SelectEntryPos( nCurPos );
197 ReleaseFocus_Impl();
198 nHandled = true;
199 break;
202 return nHandled;
207 void SvxLineBox::ReleaseFocus_Impl()
209 if(!bRelease)
211 bRelease = true;
212 return;
215 if( SfxViewShell::Current() )
217 vcl::Window* pShellWnd = SfxViewShell::Current()->GetWindow();
219 if ( pShellWnd )
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()
237 // FillStyles();
238 if ( !mpSh )
239 mpSh = SfxObjectShell::Current();
241 if( mpSh )
243 const SvxDashListItem* pItem = static_cast<const SvxDashListItem*>( mpSh->GetItem( SID_DASH_LIST ) );
244 if ( pItem )
245 Fill( pItem->GetDashList() );
249 SvxMetricField::SvxMetricField(
250 vcl::Window* pParent, const Reference< XFrame >& rFrame, WinBits nBits )
251 : MetricField(pParent, nBits)
252 , aCurTxt()
253 , ePoolUnit(SFX_MAPUNIT_CM)
254 , mxFrame(rFrame)
256 Size aSize = Size(GetTextWidth( OUString("99,99mm") ),GetTextHeight());
257 aSize.Width() += 20;
258 aSize.Height() += 6;
259 SetSizePixel( aSize );
260 aLogicalSize = PixelToLogic(aSize, MAP_APPFONT);
261 SetUnit( FUNIT_MM );
262 SetDecimalDigits( 2 );
263 SetMax( 5000 );
264 SetMin( 0 );
265 SetLast( 5000 );
266 SetFirst( 0 );
268 eDlgUnit = SfxModule::GetModuleFieldUnit( mxFrame );
269 SetFieldUnit( *this, eDlgUnit, false );
270 Show();
275 void SvxMetricField::Update( const XLineWidthItem* pItem )
277 if ( pItem )
279 if ( pItem->GetValue() != GetCoreValue( *this, ePoolUnit ) )
280 SetMetricValue( *this, pItem->GetValue(), ePoolUnit );
282 else
283 SetText( "" );
288 void SvxMetricField::Modify()
290 MetricField::Modify();
291 long nTmp = GetCoreValue( *this, ePoolUnit );
292 XLineWidthItem aLineWidthItem( nTmp );
294 Any a;
295 Sequence< PropertyValue > aArgs( 1 );
296 aArgs[0].Name = "LineWidth";
297 aLineWidthItem.QueryValue( a );
298 aArgs[0].Value = a;
299 SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
300 OUString( ".uno:LineWidth" ),
301 aArgs );
306 void SvxMetricField::ReleaseFocus_Impl()
308 if( SfxViewShell::Current() )
310 vcl::Window* pShellWnd = SfxViewShell::Current()->GetWindow();
311 if ( pShellWnd )
312 pShellWnd->GrabFocus();
316 void SvxMetricField::Down()
318 MetricField::Down();
321 void SvxMetricField::Up()
323 MetricField::Up();
326 void SvxMetricField::SetCoreUnit( SfxMapUnit eUnit )
328 ePoolUnit = eUnit;
331 void SvxMetricField::RefreshDlgUnit()
333 FieldUnit eTmpUnit = SfxModule::GetModuleFieldUnit( mxFrame );
334 if ( eDlgUnit != eTmpUnit )
336 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 )
346 aCurTxt = GetText();
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 );
365 else
367 bool bHandled = false;
369 switch ( rKey.GetCode() )
371 case KEY_RETURN:
372 Reformat();
373 bHandled = true;
374 break;
376 case KEY_ESCAPE:
377 SetText( aCurTxt );
378 bHandled = true;
379 break;
382 if ( bHandled )
384 nHandled = true;
385 Modify();
386 ReleaseFocus_Impl();
390 return nHandled;
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 ),
406 nCurPos ( 0 ),
407 bSelect ( false ),
408 bRelease( true )
410 SetSizePixel( LogicToPixel( Size(40, 40 ),MAP_APPFONT ));
411 Fill();
412 SelectEntryPos( drawing::FillStyle_SOLID );
413 Show();
416 VCL_BUILDER_FACTORY(SvxFillTypeBox)
418 bool SvxFillTypeBox::PreNotify( NotifyEvent& rNEvt )
420 MouseNotifyEvent nType = rNEvt.GetType();
422 if (!isDisposed())
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 ) )
430 if ( !bSelect )
431 SelectEntryPos( nCurPos );
432 else
433 bSelect = false;
437 return FillTypeLB::PreNotify( rNEvt );
442 bool SvxFillTypeBox::Notify( NotifyEvent& rNEvt )
444 bool nHandled = FillTypeLB::Notify( rNEvt );
446 if (isDisposed())
447 return false;
449 if ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
451 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
452 switch ( pKEvt->GetKeyCode().GetCode() )
454 case KEY_RETURN:
455 nHandled = true;
456 ( (Link<>&)GetSelectHdl() ).Call( this );
457 break;
458 case KEY_TAB:
459 bRelease = false;
460 ( (Link<>&)GetSelectHdl() ).Call( this );
461 bRelease = true;
462 break;
464 case KEY_ESCAPE:
465 SelectEntryPos( nCurPos );
466 ReleaseFocus_Impl();
467 nHandled = true;
468 break;
471 return nHandled;
476 void SvxFillTypeBox::ReleaseFocus_Impl()
478 if( SfxViewShell::Current() )
480 vcl::Window* pShellWnd = SfxViewShell::Current()->GetWindow();
482 if ( pShellWnd )
483 pShellWnd->GrabFocus();
487 SvxFillAttrBox::SvxFillAttrBox( vcl::Window* pParent, WinBits nBits ) :
488 FillAttrLB( pParent, nBits | WB_TABSTOP ),
489 nCurPos( 0 ),
490 bRelease( true )
493 SetPosPixel( Point( 90, 0 ) );
494 SetSizePixel( LogicToPixel( Size(50, 80 ), MAP_APPFONT ));
495 Show();
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() )
522 case KEY_RETURN:
523 ( (Link<>&)GetSelectHdl() ).Call( this );
524 nHandled = true;
525 break;
526 case KEY_TAB:
527 bRelease = false;
528 GetSelectHdl().Call( this );
529 bRelease = true;
530 break;
531 case KEY_ESCAPE:
532 SelectEntryPos( nCurPos );
533 ReleaseFocus_Impl();
534 nHandled = true;
535 break;
538 return nHandled;
543 void SvxFillAttrBox::Select()
545 FillAttrLB::Select();
550 void SvxFillAttrBox::ReleaseFocus_Impl()
552 if( SfxViewShell::Current() )
554 vcl::Window* pShellWnd = SfxViewShell::Current()->GetWindow();
556 if ( pShellWnd )
557 pShellWnd->GrabFocus();
561 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */