xref: /trunk/main/svx/source/tbxctrls/itemwin.cxx (revision 948ff262)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 // include ---------------------------------------------------------------
28 #include <tools/shl.hxx>
29 #include <sfx2/dispatch.hxx>
30 #include <sfx2/objsh.hxx>
31 #include <sfx2/viewsh.hxx>
32 #include <sfx2/module.hxx>
33 #include <tools/urlobj.hxx>
34 
35 #define _SVX_ITEMWIN_CXX
36 
37 #include <vcl/svapp.hxx>
38 
39 #include <svx/dialogs.hrc>
40 
41 #define DELAY_TIMEOUT			100
42 
43 #include <svx/xlnclit.hxx>
44 #include <svx/xlnwtit.hxx>
45 #include <svx/xlineit0.hxx>
46 #include <svx/xlndsit.hxx>
47 #include <svx/xtable.hxx>
48 #include "svx/drawitem.hxx"
49 #include <svx/dialmgr.hxx>
50 #include "svx/dlgutil.hxx"
51 #include <svx/itemwin.hxx>
52 #include "svx/linectrl.hxx"
53 #include <svtools/colorcfg.hxx>
54 
55 using namespace ::com::sun::star::uno;
56 using namespace ::com::sun::star::frame;
57 using namespace ::com::sun::star::util;
58 using namespace ::com::sun::star::lang;
59 using namespace ::com::sun::star::beans;
60 
61 #define LOGICAL_EDIT_HEIGHT         12
62 //========================================================================
63 // SvxLineBox
64 //========================================================================
65 
SvxLineBox(Window * pParent,const Reference<XFrame> & rFrame,WinBits nBits)66 SvxLineBox::SvxLineBox( Window* pParent, const Reference< XFrame >& rFrame, WinBits nBits ) :
67 	LineLB( pParent, nBits ),
68 	meBmpMode	( GetSettings().GetStyleSettings().GetHighContrastMode() ? BMP_COLOR_HIGHCONTRAST : BMP_COLOR_NORMAL ),
69 	nCurPos		( 0 ),
70     aLogicalSize(40,140),
71     bRelease    ( sal_True ),
72 	mpSh		( NULL ),
73     mxFrame     ( rFrame )
74 {
75     SetSizePixel( LogicToPixel( aLogicalSize, MAP_APPFONT ));
76     Show();
77 
78 	aDelayTimer.SetTimeout( DELAY_TIMEOUT );
79 	aDelayTimer.SetTimeoutHdl( LINK( this, SvxLineBox, DelayHdl_Impl ) );
80 	aDelayTimer.Start();
81 }
82 
83 // -----------------------------------------------------------------------
84 
~SvxLineBox()85 SvxLineBox::~SvxLineBox()
86 {
87 }
88 
89 // -----------------------------------------------------------------------
90 
IMPL_LINK(SvxLineBox,DelayHdl_Impl,Timer *,EMPTYARG)91 IMPL_LINK( SvxLineBox, DelayHdl_Impl, Timer *, EMPTYARG )
92 {
93 	if ( GetEntryCount() == 0 )
94 	{
95 		mpSh = SfxObjectShell::Current();
96 		FillControl();
97 	}
98 	return 0;
99 }
100 
101 // -----------------------------------------------------------------------
102 
Select()103 void SvxLineBox::Select()
104 {
105     // Call the parent's Select() member to trigger accessibility events.
106     LineLB::Select();
107 
108 	if ( !IsTravelSelect() )
109 	{
110 		XLineStyle eXLS;
111 		sal_uInt16 nPos = GetSelectEntryPos();
112 //		SfxDispatcher* pDisp = rBindings.GetDispatcher();
113 		//DBG_ASSERT( pDisp, "invalid Dispatcher" );
114 
115 		switch ( nPos )
116 		{
117 			case 0:
118 				eXLS = XLINE_NONE;
119 				break;
120 
121 			case 1:
122 				eXLS = XLINE_SOLID;
123 				break;
124 
125 			default:
126 			{
127 				eXLS = XLINE_DASH;
128 
129 				if ( nPos != LISTBOX_ENTRY_NOTFOUND &&
130 					 SfxObjectShell::Current()	&&
131 					 SfxObjectShell::Current()->GetItem( SID_DASH_LIST ) )
132 				{
133 					// LineDashItem wird nur geschickt, wenn es auch einen Dash besitzt.
134 					// Notify k"ummert sich darum!
135 					SvxDashListItem aItem( *(const SvxDashListItem*)(
136 						SfxObjectShell::Current()->GetItem( SID_DASH_LIST ) ) );
137 					XLineDashItem aLineDashItem( GetSelectEntry(),
138 						aItem.GetDashList()->GetDash( nPos - 2 )->GetDash() );
139 
140                     Any a;
141                     Sequence< PropertyValue > aArgs( 1 );
142                     aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LineDash" ));
143                     aLineDashItem.QueryValue ( a );
144                     aArgs[0].Value = a;
145                     SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
146                                                  ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:LineDash" )),
147                                                  aArgs );
148 //                    pDisp->Execute( SID_ATTR_LINE_DASH, SFX_CALLMODE_RECORD, &aLineDashItem, 0L );
149 				}
150 			}
151 			break;
152 		}
153 
154 		XLineStyleItem aLineStyleItem( eXLS );
155         Any a;
156         Sequence< PropertyValue > aArgs( 1 );
157         aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XLineStyle" ));
158         aLineStyleItem.QueryValue ( a );
159         aArgs[0].Value = a;
160         SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
161                                      ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:XLineStyle" )),
162                                      aArgs );
163 //		pDisp->Execute( SID_ATTR_LINE_STYLE, SFX_CALLMODE_RECORD, &aLineStyleItem, 0L );
164 
165         nCurPos = GetSelectEntryPos();
166 		ReleaseFocus_Impl();
167 	}
168 }
169 
170 // -----------------------------------------------------------------------
171 
PreNotify(NotifyEvent & rNEvt)172 long SvxLineBox::PreNotify( NotifyEvent& rNEvt )
173 {
174 	sal_uInt16 nType = rNEvt.GetType();
175 
176     switch(nType)
177     {
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:
186         {
187             const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
188             if( pKEvt->GetKeyCode().GetCode() == KEY_TAB)
189             {
190                 bRelease = sal_False;
191                 Select();
192             }
193         }
194         break;
195     }
196 	return LineLB::PreNotify( rNEvt );
197 }
198 
199 // -----------------------------------------------------------------------
200 
Notify(NotifyEvent & rNEvt)201 long SvxLineBox::Notify( NotifyEvent& rNEvt )
202 {
203 	long nHandled = LineLB::Notify( rNEvt );
204 
205 	if ( rNEvt.GetType() == EVENT_KEYINPUT )
206 	{
207 		const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
208 
209 		switch ( pKEvt->GetKeyCode().GetCode() )
210 		{
211 			case KEY_RETURN:
212 				Select();
213 				nHandled = 1;
214 				break;
215 
216 			case KEY_ESCAPE:
217 				SelectEntryPos( nCurPos );
218 				ReleaseFocus_Impl();
219 				nHandled = 1;
220 				break;
221         }
222 	}
223 	return nHandled;
224 }
225 
226 // -----------------------------------------------------------------------
227 
ReleaseFocus_Impl()228 void SvxLineBox::ReleaseFocus_Impl()
229 {
230     if(!bRelease)
231     {
232         bRelease = sal_True;
233         return;
234     }
235 
236 	if( SfxViewShell::Current() )
237 	{
238 		Window* pShellWnd = SfxViewShell::Current()->GetWindow();
239 
240 		if ( pShellWnd )
241 			pShellWnd->GrabFocus();
242 	}
243 }
244 /* -----------------------------08.03.2002 15:39------------------------------
245 
246  ---------------------------------------------------------------------------*/
DataChanged(const DataChangedEvent & rDCEvt)247 void SvxLineBox::DataChanged( const DataChangedEvent& rDCEvt )
248 {
249 	if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
250          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
251     {
252         SetSizePixel(LogicToPixel(aLogicalSize, MAP_APPFONT));
253         Size aDropSize( aLogicalSize.Width(), LOGICAL_EDIT_HEIGHT);
254         SetDropDownSizePixel(LogicToPixel(aDropSize, MAP_APPFONT));
255    }
256 
257     LineLB::DataChanged( rDCEvt );
258 
259 	if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
260          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
261     {
262 		BmpColorMode eMode = GetSettings().GetStyleSettings().GetHighContrastMode() ? BMP_COLOR_HIGHCONTRAST : BMP_COLOR_NORMAL;
263 		if( eMode != meBmpMode )
264 		{
265 			meBmpMode = eMode;
266 			FillControl();
267 		}
268  	}
269 }
270 
FillControl()271 void SvxLineBox::FillControl()
272 {
273 	// FillStyles();
274     if ( !mpSh )
275         mpSh = SfxObjectShell::Current();
276 
277     if( mpSh )
278 	{
279 		const SvxDashListItem* pItem = (const SvxDashListItem*)( mpSh->GetItem( SID_DASH_LIST ) );
280 		if ( pItem )
281 			Fill( pItem->GetDashList() );
282 	}
283 
284 
285 //	rBindings.Invalidate( SID_ATTR_LINE_DASH );
286 }
287 //========================================================================
288 // SvxColorBox
289 //========================================================================
290 
SvxColorBox(Window * pParent,const::rtl::OUString & rCommand,const Reference<XFrame> & rFrame,WinBits nBits)291 SvxColorBox::SvxColorBox(
292     Window* pParent,
293     const ::rtl::OUString& rCommand,
294     const Reference< XFrame >& rFrame,
295     WinBits nBits ) :
296 	ColorLB( pParent, nBits ),
297 	nCurPos		( 0 ),
298     aLogicalSize(45,80),
299     bRelease    ( sal_True ),
300     maCommand   ( rCommand ),
301     mxFrame     ( rFrame )
302 {
303     SetSizePixel( LogicToPixel( aLogicalSize , MAP_APPFONT));
304     Show();
305 
306     SfxObjectShell* pSh = SfxObjectShell::Current();
307 
308 	if ( pSh )
309 	{
310 		const SvxColorTableItem* pItem =
311 			(const SvxColorTableItem*)(	pSh->GetItem( SID_COLOR_TABLE ) );
312 		if(pItem)
313 			Fill( pItem->GetColorTable() );
314 	}
315 }
316 
317 // -----------------------------------------------------------------------
318 
IMPL_LINK(SvxColorBox,DelayHdl_Impl,Timer *,EMPTYARG)319 IMPL_LINK( SvxColorBox, DelayHdl_Impl, Timer *, EMPTYARG )
320 {
321 	SfxObjectShell* pSh = SfxObjectShell::Current();
322 
323 	if ( pSh )
324 	{
325 		const SvxColorTableItem* pItem = (const SvxColorTableItem*)( pSh->GetItem( SID_COLOR_TABLE ) );
326 		if ( pItem )
327 			Fill( pItem->GetColorTable() );
328 //		rBindings.Invalidate( nId );
329 	}
330 	return 0;
331 }
332 
333 // -----------------------------------------------------------------------
334 
~SvxColorBox()335 SvxColorBox::~SvxColorBox()
336 {
337 }
338 
339 // -----------------------------------------------------------------------
340 
Update(const XLineColorItem * pItem)341 void SvxColorBox::Update( const XLineColorItem* pItem )
342 {
343 	if ( pItem )
344 		SelectEntry( pItem->GetColorValue() );
345 	else
346 		SetNoSelection();
347 }
348 
349 // -----------------------------------------------------------------------
350 
Select()351 void SvxColorBox::Select()
352 {
353 	// OJ: base class call needed here because otherwise no event is send for accessibility
354 	ColorLB::Select();
355 	if ( !IsTravelSelect() )
356 	{
357 		XLineColorItem aLineColorItem( GetSelectEntry(), GetSelectEntryColor() );
358 
359         INetURLObject aObj( maCommand );
360 
361         Any a;
362         Sequence< PropertyValue > aArgs( 1 );
363         aArgs[0].Name = aObj.GetURLPath();
364         aLineColorItem.QueryValue( a );
365         aArgs[0].Value = a;
366         SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
367                                      maCommand,
368                                      aArgs );
369 //        rBindings.GetDispatcher()->Execute( nId, SFX_CALLMODE_RECORD, &aLineColorItem, 0L );
370 
371         nCurPos = GetSelectEntryPos();
372 		ReleaseFocus_Impl();
373 	}
374 }
375 
376 // -----------------------------------------------------------------------
377 
PreNotify(NotifyEvent & rNEvt)378 long SvxColorBox::PreNotify( NotifyEvent& rNEvt )
379 {
380 	sal_uInt16 nType = rNEvt.GetType();
381 
382     switch(nType)
383     {
384         case  EVENT_MOUSEBUTTONDOWN:
385         case EVENT_GETFOCUS:
386             nCurPos = GetSelectEntryPos();
387         break;
388         case EVENT_LOSEFOCUS:
389             SelectEntryPos(nCurPos);
390         break;
391         case EVENT_KEYINPUT:
392         {
393             const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
394 
395             if( pKEvt->GetKeyCode().GetCode() == KEY_TAB)
396             {
397                 bRelease = sal_False;
398                 Select();
399             }
400         }
401     }
402 
403 	return ColorLB::PreNotify( rNEvt );
404 }
405 
406 // -----------------------------------------------------------------------
407 
Notify(NotifyEvent & rNEvt)408 long SvxColorBox::Notify( NotifyEvent& rNEvt )
409 {
410 	long nHandled = ColorLB::Notify( rNEvt );
411 
412 	if ( rNEvt.GetType() == EVENT_KEYINPUT )
413 	{
414 		const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
415 
416 		switch ( pKEvt->GetKeyCode().GetCode() )
417 		{
418 			case KEY_RETURN:
419 				Select();
420 				nHandled = 1;
421 				break;
422 
423 			case KEY_ESCAPE:
424 				SelectEntryPos( nCurPos );
425 				ReleaseFocus_Impl();
426 				nHandled = 1;
427 				break;
428         }
429 	}
430 	return nHandled;
431 }
432 /* -----------------------------08.03.2002 15:35------------------------------
433 
434  ---------------------------------------------------------------------------*/
DataChanged(const DataChangedEvent & rDCEvt)435 void SvxColorBox::DataChanged( const DataChangedEvent& rDCEvt )
436 {
437 	if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
438          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
439     {
440         SetSizePixel(LogicToPixel(aLogicalSize, MAP_APPFONT));
441         Size aDropSize( aLogicalSize.Width(), LOGICAL_EDIT_HEIGHT);
442         SetDropDownSizePixel(LogicToPixel(aDropSize, MAP_APPFONT));
443     }
444 
445     ColorLB::DataChanged( rDCEvt );
446 }
447 // -----------------------------------------------------------------------
448 
ReleaseFocus_Impl()449 void SvxColorBox::ReleaseFocus_Impl()
450 {
451     if(!bRelease)
452     {
453         bRelease = sal_True;
454         return;
455     }
456 
457 	if( SfxViewShell::Current() )
458 	{
459 		Window* pShellWnd = SfxViewShell::Current()->GetWindow();
460 
461 		if ( pShellWnd )
462 			pShellWnd->GrabFocus();
463 	}
464 }
465 
466 //========================================================================
467 // SvxMetricField
468 //========================================================================
469 
SvxMetricField(Window * pParent,const Reference<XFrame> & rFrame,WinBits nBits)470 SvxMetricField::SvxMetricField(
471     Window* pParent, const Reference< XFrame >& rFrame, WinBits nBits ) :
472 	MetricField( pParent, nBits ),
473 	aCurTxt( String() ),
474     mxFrame( rFrame )
475 {
476 	Size aSize = Size(GetTextWidth( String::CreateFromAscii("99,99mm") ),GetTextHeight());
477 	aSize.Width() += 20;
478 	aSize.Height() += 6;
479 	SetSizePixel( aSize );
480     aLogicalSize = PixelToLogic(aSize, MAP_APPFONT);
481 	SetUnit( FUNIT_MM );
482 	SetDecimalDigits( 2 );
483 	SetMax( 5000 );
484 	SetMin( 0 );
485 	SetLast( 5000 );
486 	SetFirst( 0 );
487 
488 	eDlgUnit = SfxModule::GetModuleFieldUnit( mxFrame );
489 	SetFieldUnit( *this, eDlgUnit, sal_False );
490 	Show();
491 }
492 
493 // -----------------------------------------------------------------------
494 
~SvxMetricField()495 SvxMetricField::~SvxMetricField()
496 {
497 }
498 
499 // -----------------------------------------------------------------------
500 
Update(const XLineWidthItem * pItem)501 void SvxMetricField::Update( const XLineWidthItem* pItem )
502 {
503 	if ( pItem )
504 	{
505 		if ( pItem->GetValue() != GetCoreValue( *this, ePoolUnit ) )
506 			SetMetricValue( *this, pItem->GetValue(), ePoolUnit );
507 	}
508 	else
509 		SetText( String() );
510 }
511 
512 // -----------------------------------------------------------------------
513 
Modify()514 void SvxMetricField::Modify()
515 {
516 	MetricField::Modify();
517 	long nTmp = GetCoreValue( *this, ePoolUnit );
518 	XLineWidthItem aLineWidthItem( nTmp );
519 
520     Any a;
521     Sequence< PropertyValue > aArgs( 1 );
522     aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LineWidth" ));
523     aLineWidthItem.QueryValue( a );
524     aArgs[0].Value = a;
525     SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
526                                  ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:LineWidth" )),
527                                  aArgs );
528 //	rBindings.GetDispatcher()->Execute( SID_ATTR_LINE_WIDTH, SFX_CALLMODE_RECORD, &aLineWidthItem, 0L );
529 }
530 
531 // -----------------------------------------------------------------------
532 
ReleaseFocus_Impl()533 void SvxMetricField::ReleaseFocus_Impl()
534 {
535 	if( SfxViewShell::Current() )
536 	{
537 		Window* pShellWnd = SfxViewShell::Current()->GetWindow();
538 		if ( pShellWnd )
539 			pShellWnd->GrabFocus();
540 	}
541 }
542 
543 // -----------------------------------------------------------------------
544 
Down()545 void SvxMetricField::Down()
546 {
547     // #124425# make the OS2 case OS2-only (if still needed); under
548     // non-OS2 it prevents the value to go to zero on down presses,
549     // s do not use there. Also added a fix for OS2, but could not test
550 #ifdef OS2
551     const sal_Int64 nValue(GetValue() - GetSpinSize());
552 
553     // prevent a jump to spin max on OS2
554     if ( nValue >= GetMin() )
555     {
556         MetricField::Down();
557     }
558     else if ( nValue < GetMin() )
559     {
560         // still set to GetMin() when spin min is reached
561         SetMetricValue( *this, GetMin(), ePoolUnit );
562     }
563 
564 #else
565     MetricField::Down();
566 #endif
567 }
568 
569 // -----------------------------------------------------------------------
570 
Up()571 void SvxMetricField::Up()
572 {
573 	MetricField::Up();
574 }
575 
576 // -----------------------------------------------------------------------
577 
SetCoreUnit(SfxMapUnit eUnit)578 void SvxMetricField::SetCoreUnit( SfxMapUnit eUnit )
579 {
580 	ePoolUnit = eUnit;
581 }
582 
583 // -----------------------------------------------------------------------
584 
RefreshDlgUnit()585 void SvxMetricField::RefreshDlgUnit()
586 {
587 	FieldUnit eTmpUnit = SfxModule::GetModuleFieldUnit( mxFrame );
588 	if ( eDlgUnit != eTmpUnit )
589 	{
590 		eDlgUnit = eTmpUnit;
591 		SetFieldUnit( *this, eDlgUnit, sal_False );
592 	}
593 }
594 
595 // -----------------------------------------------------------------------
596 
PreNotify(NotifyEvent & rNEvt)597 long SvxMetricField::PreNotify( NotifyEvent& rNEvt )
598 {
599 	sal_uInt16 nType = rNEvt.GetType();
600 
601 	if ( EVENT_MOUSEBUTTONDOWN == nType || EVENT_GETFOCUS == nType )
602 		aCurTxt = GetText();
603 
604 	return MetricField::PreNotify( rNEvt );
605 }
606 
607 // -----------------------------------------------------------------------
608 
Notify(NotifyEvent & rNEvt)609 long SvxMetricField::Notify( NotifyEvent& rNEvt )
610 {
611 	long nHandled = MetricField::Notify( rNEvt );
612 
613 	if ( rNEvt.GetType() == EVENT_KEYINPUT )
614 	{
615 		const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
616 		const KeyCode& rKey = pKEvt->GetKeyCode();
617 		SfxViewShell* pSh = SfxViewShell::Current();
618 
619 		if ( rKey.GetModifier() && rKey.GetGroup() != KEYGROUP_CURSOR && pSh )
620 			pSh->KeyInput( *pKEvt );
621 		else
622 		{
623 			bool bHandled = sal_False;
624 
625 			switch ( rKey.GetCode() )
626 			{
627 				case KEY_RETURN:
628 					Reformat();
629 					bHandled = sal_True;
630 					break;
631 
632 				case KEY_ESCAPE:
633 					SetText( aCurTxt );
634 					bHandled = sal_True;
635 					break;
636 			}
637 
638 			if ( bHandled )
639 			{
640 				nHandled = 1;
641 				Modify();
642 				ReleaseFocus_Impl();
643 			}
644 		}
645 	}
646 	return nHandled;
647 }
648 /* -----------------------------08.03.2002 15:32------------------------------
649 
650  ---------------------------------------------------------------------------*/
DataChanged(const DataChangedEvent & rDCEvt)651 void SvxMetricField::DataChanged( const DataChangedEvent& rDCEvt )
652 {
653 	if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
654          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
655     {
656         SetSizePixel(LogicToPixel(aLogicalSize, MAP_APPFONT));
657     }
658 
659     MetricField::DataChanged( rDCEvt );
660 }
661 
662 //========================================================================
663 // SvxFillTypeBox
664 //========================================================================
665 
SvxFillTypeBox(Window * pParent,WinBits nBits)666 SvxFillTypeBox::SvxFillTypeBox( Window* pParent, WinBits nBits ) :
667 	FillTypeLB( pParent, nBits | WB_TABSTOP ),
668 	nCurPos	( 0 ),
669     bSelect ( sal_False ),
670     bRelease(sal_True)
671 {
672     SetSizePixel( LogicToPixel( Size(40, 40 ),MAP_APPFONT ));
673     Fill();
674 	SelectEntryPos( XFILL_SOLID );
675 	Show();
676 }
677 
678 // -----------------------------------------------------------------------
679 
~SvxFillTypeBox()680 SvxFillTypeBox::~SvxFillTypeBox()
681 {
682 }
683 
684 // -----------------------------------------------------------------------
685 
PreNotify(NotifyEvent & rNEvt)686 long SvxFillTypeBox::PreNotify( NotifyEvent& rNEvt )
687 {
688 	sal_uInt16 nType = rNEvt.GetType();
689 
690 	if ( EVENT_MOUSEBUTTONDOWN == nType || EVENT_GETFOCUS == nType )
691 		nCurPos = GetSelectEntryPos();
692 	else if ( EVENT_LOSEFOCUS == nType
693 		&& Application::GetFocusWindow()
694 		&& !IsWindowOrChild( Application::GetFocusWindow(), sal_True ) )
695 	{
696 		if ( !bSelect )
697 			SelectEntryPos( nCurPos );
698 		else
699 			bSelect = sal_False;
700 	}
701 
702 	return FillTypeLB::PreNotify( rNEvt );
703 }
704 
705 // -----------------------------------------------------------------------
706 
Notify(NotifyEvent & rNEvt)707 long SvxFillTypeBox::Notify( NotifyEvent& rNEvt )
708 {
709 	long nHandled = FillTypeLB::Notify( rNEvt );
710 
711 	if ( rNEvt.GetType() == EVENT_KEYINPUT )
712 	{
713 		const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
714 		switch ( pKEvt->GetKeyCode().GetCode() )
715 		{
716             case KEY_RETURN:
717                 nHandled = 1;
718                 ( (Link&)GetSelectHdl() ).Call( this );
719             break;
720             case KEY_TAB:
721                 bRelease = sal_False;
722                 ( (Link&)GetSelectHdl() ).Call( this );
723                 bRelease = sal_True;
724                 break;
725 
726 			case KEY_ESCAPE:
727 				SelectEntryPos( nCurPos );
728 				ReleaseFocus_Impl();
729 				nHandled = 1;
730 				break;
731 		}
732 	}
733 	return nHandled;
734 }
735 
736 // -----------------------------------------------------------------------
737 
ReleaseFocus_Impl()738 void SvxFillTypeBox::ReleaseFocus_Impl()
739 {
740 	if( SfxViewShell::Current() )
741 	{
742 		Window* pShellWnd = SfxViewShell::Current()->GetWindow();
743 
744 		if ( pShellWnd )
745 			pShellWnd->GrabFocus();
746 	}
747 }
748 
749 //========================================================================
750 // SvxFillAttrBox
751 //========================================================================
752 
SvxFillAttrBox(Window * pParent,WinBits nBits)753 SvxFillAttrBox::SvxFillAttrBox( Window* pParent, WinBits nBits ) :
754 
755 	FillAttrLB( pParent, nBits | WB_TABSTOP ),
756 
757     nCurPos( 0 ),
758     bRelease( sal_True )
759 
760 {
761 	SetPosPixel( Point( 90, 0 ) );
762     SetSizePixel( LogicToPixel( Size(50, 80 ), MAP_APPFONT ));
763 	Show();
764 }
765 
766 // -----------------------------------------------------------------------
767 
~SvxFillAttrBox()768 SvxFillAttrBox::~SvxFillAttrBox()
769 {
770 }
771 
772 // -----------------------------------------------------------------------
773 
PreNotify(NotifyEvent & rNEvt)774 long SvxFillAttrBox::PreNotify( NotifyEvent& rNEvt )
775 {
776 	sal_uInt16 nType = rNEvt.GetType();
777 
778 	if ( EVENT_MOUSEBUTTONDOWN == nType || EVENT_GETFOCUS == nType )
779 		nCurPos = GetSelectEntryPos();
780 
781 	return FillAttrLB::PreNotify( rNEvt );
782 }
783 
784 // -----------------------------------------------------------------------
785 
Notify(NotifyEvent & rNEvt)786 long SvxFillAttrBox::Notify( NotifyEvent& rNEvt )
787 {
788 	long nHandled = FillAttrLB::Notify( rNEvt );
789 
790 	if ( rNEvt.GetType() == EVENT_KEYINPUT )
791 	{
792 		const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
793 
794 		switch ( pKEvt->GetKeyCode().GetCode() )
795 		{
796 			case KEY_RETURN:
797 				( (Link&)GetSelectHdl() ).Call( this );
798 				nHandled = 1;
799             break;
800             case KEY_TAB:
801                 bRelease = sal_False;
802                 GetSelectHdl().Call( this );
803                 bRelease = sal_True;
804             break;
805 			case KEY_ESCAPE:
806 				SelectEntryPos( nCurPos );
807 				ReleaseFocus_Impl();
808 				nHandled = 1;
809 				break;
810 		}
811 	}
812 	return nHandled;
813 }
814 
815 // -----------------------------------------------------------------------
816 
Select()817 void SvxFillAttrBox::Select()
818 {
819 	FillAttrLB::Select();
820 }
821 
822 // -----------------------------------------------------------------------
823 
ReleaseFocus_Impl()824 void SvxFillAttrBox::ReleaseFocus_Impl()
825 {
826 	if( SfxViewShell::Current() )
827 	{
828 		Window* pShellWnd = SfxViewShell::Current()->GetWindow();
829 
830 		if ( pShellWnd )
831 			pShellWnd->GrabFocus();
832 	}
833 }
834