xref: /aoo41x/main/svx/source/tbxctrls/itemwin.cxx (revision 97e8a929)
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 	sal_Int64 nValue = GetValue();
548 	nValue -= GetSpinSize();
549 
550 	// Um unter OS/2 einen Sprung auf Max zu verhindern
551 	if ( nValue >= GetMin() )
552 		MetricField::Down();
553 }
554 
555 // -----------------------------------------------------------------------
556 
Up()557 void SvxMetricField::Up()
558 {
559 	MetricField::Up();
560 }
561 
562 // -----------------------------------------------------------------------
563 
SetCoreUnit(SfxMapUnit eUnit)564 void SvxMetricField::SetCoreUnit( SfxMapUnit eUnit )
565 {
566 	ePoolUnit = eUnit;
567 }
568 
569 // -----------------------------------------------------------------------
570 
RefreshDlgUnit()571 void SvxMetricField::RefreshDlgUnit()
572 {
573 	FieldUnit eTmpUnit = SfxModule::GetModuleFieldUnit( mxFrame );
574 	if ( eDlgUnit != eTmpUnit )
575 	{
576 		eDlgUnit = eTmpUnit;
577 		SetFieldUnit( *this, eDlgUnit, sal_False );
578 	}
579 }
580 
581 // -----------------------------------------------------------------------
582 
PreNotify(NotifyEvent & rNEvt)583 long SvxMetricField::PreNotify( NotifyEvent& rNEvt )
584 {
585 	sal_uInt16 nType = rNEvt.GetType();
586 
587 	if ( EVENT_MOUSEBUTTONDOWN == nType || EVENT_GETFOCUS == nType )
588 		aCurTxt = GetText();
589 
590 	return MetricField::PreNotify( rNEvt );
591 }
592 
593 // -----------------------------------------------------------------------
594 
Notify(NotifyEvent & rNEvt)595 long SvxMetricField::Notify( NotifyEvent& rNEvt )
596 {
597 	long nHandled = MetricField::Notify( rNEvt );
598 
599 	if ( rNEvt.GetType() == EVENT_KEYINPUT )
600 	{
601 		const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
602 		const KeyCode& rKey = pKEvt->GetKeyCode();
603 		SfxViewShell* pSh = SfxViewShell::Current();
604 
605 		if ( rKey.GetModifier() && rKey.GetGroup() != KEYGROUP_CURSOR && pSh )
606 			pSh->KeyInput( *pKEvt );
607 		else
608 		{
609 			bool bHandled = sal_False;
610 
611 			switch ( rKey.GetCode() )
612 			{
613 				case KEY_RETURN:
614 					Reformat();
615 					bHandled = sal_True;
616 					break;
617 
618 				case KEY_ESCAPE:
619 					SetText( aCurTxt );
620 					bHandled = sal_True;
621 					break;
622 			}
623 
624 			if ( bHandled )
625 			{
626 				nHandled = 1;
627 				Modify();
628 				ReleaseFocus_Impl();
629 			}
630 		}
631 	}
632 	return nHandled;
633 }
634 /* -----------------------------08.03.2002 15:32------------------------------
635 
636  ---------------------------------------------------------------------------*/
DataChanged(const DataChangedEvent & rDCEvt)637 void SvxMetricField::DataChanged( const DataChangedEvent& rDCEvt )
638 {
639 	if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
640          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
641     {
642         SetSizePixel(LogicToPixel(aLogicalSize, MAP_APPFONT));
643     }
644 
645     MetricField::DataChanged( rDCEvt );
646 }
647 
648 //========================================================================
649 // SvxFillTypeBox
650 //========================================================================
651 
SvxFillTypeBox(Window * pParent,WinBits nBits)652 SvxFillTypeBox::SvxFillTypeBox( Window* pParent, WinBits nBits ) :
653 	FillTypeLB( pParent, nBits | WB_TABSTOP ),
654 	nCurPos	( 0 ),
655     bSelect ( sal_False ),
656     bRelease(sal_True)
657 {
658     SetSizePixel( LogicToPixel( Size(40, 40 ),MAP_APPFONT ));
659     Fill();
660 	SelectEntryPos( XFILL_SOLID );
661 	Show();
662 }
663 
664 // -----------------------------------------------------------------------
665 
~SvxFillTypeBox()666 SvxFillTypeBox::~SvxFillTypeBox()
667 {
668 }
669 
670 // -----------------------------------------------------------------------
671 
PreNotify(NotifyEvent & rNEvt)672 long SvxFillTypeBox::PreNotify( NotifyEvent& rNEvt )
673 {
674 	sal_uInt16 nType = rNEvt.GetType();
675 
676 	if ( EVENT_MOUSEBUTTONDOWN == nType || EVENT_GETFOCUS == nType )
677 		nCurPos = GetSelectEntryPos();
678 	else if ( EVENT_LOSEFOCUS == nType
679 		&& Application::GetFocusWindow()
680 		&& !IsWindowOrChild( Application::GetFocusWindow(), sal_True ) )
681 	{
682 		if ( !bSelect )
683 			SelectEntryPos( nCurPos );
684 		else
685 			bSelect = sal_False;
686 	}
687 
688 	return FillTypeLB::PreNotify( rNEvt );
689 }
690 
691 // -----------------------------------------------------------------------
692 
Notify(NotifyEvent & rNEvt)693 long SvxFillTypeBox::Notify( NotifyEvent& rNEvt )
694 {
695 	long nHandled = FillTypeLB::Notify( rNEvt );
696 
697 	if ( rNEvt.GetType() == EVENT_KEYINPUT )
698 	{
699 		const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
700 		switch ( pKEvt->GetKeyCode().GetCode() )
701 		{
702             case KEY_RETURN:
703                 nHandled = 1;
704                 ( (Link&)GetSelectHdl() ).Call( this );
705             break;
706             case KEY_TAB:
707                 bRelease = sal_False;
708                 ( (Link&)GetSelectHdl() ).Call( this );
709                 bRelease = sal_True;
710                 break;
711 
712 			case KEY_ESCAPE:
713 				SelectEntryPos( nCurPos );
714 				ReleaseFocus_Impl();
715 				nHandled = 1;
716 				break;
717 		}
718 	}
719 	return nHandled;
720 }
721 
722 // -----------------------------------------------------------------------
723 
ReleaseFocus_Impl()724 void SvxFillTypeBox::ReleaseFocus_Impl()
725 {
726 	if( SfxViewShell::Current() )
727 	{
728 		Window* pShellWnd = SfxViewShell::Current()->GetWindow();
729 
730 		if ( pShellWnd )
731 			pShellWnd->GrabFocus();
732 	}
733 }
734 
735 //========================================================================
736 // SvxFillAttrBox
737 //========================================================================
738 
SvxFillAttrBox(Window * pParent,WinBits nBits)739 SvxFillAttrBox::SvxFillAttrBox( Window* pParent, WinBits nBits ) :
740 
741 	FillAttrLB( pParent, nBits | WB_TABSTOP ),
742 
743     nCurPos( 0 ),
744     bRelease( sal_True )
745 
746 {
747 	SetPosPixel( Point( 90, 0 ) );
748     SetSizePixel( LogicToPixel( Size(50, 80 ), MAP_APPFONT ));
749 	Show();
750 }
751 
752 // -----------------------------------------------------------------------
753 
~SvxFillAttrBox()754 SvxFillAttrBox::~SvxFillAttrBox()
755 {
756 }
757 
758 // -----------------------------------------------------------------------
759 
PreNotify(NotifyEvent & rNEvt)760 long SvxFillAttrBox::PreNotify( NotifyEvent& rNEvt )
761 {
762 	sal_uInt16 nType = rNEvt.GetType();
763 
764 	if ( EVENT_MOUSEBUTTONDOWN == nType || EVENT_GETFOCUS == nType )
765 		nCurPos = GetSelectEntryPos();
766 
767 	return FillAttrLB::PreNotify( rNEvt );
768 }
769 
770 // -----------------------------------------------------------------------
771 
Notify(NotifyEvent & rNEvt)772 long SvxFillAttrBox::Notify( NotifyEvent& rNEvt )
773 {
774 	long nHandled = FillAttrLB::Notify( rNEvt );
775 
776 	if ( rNEvt.GetType() == EVENT_KEYINPUT )
777 	{
778 		const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
779 
780 		switch ( pKEvt->GetKeyCode().GetCode() )
781 		{
782 			case KEY_RETURN:
783 				( (Link&)GetSelectHdl() ).Call( this );
784 				nHandled = 1;
785             break;
786             case KEY_TAB:
787                 bRelease = sal_False;
788                 GetSelectHdl().Call( this );
789                 bRelease = sal_True;
790             break;
791 			case KEY_ESCAPE:
792 				SelectEntryPos( nCurPos );
793 				ReleaseFocus_Impl();
794 				nHandled = 1;
795 				break;
796 		}
797 	}
798 	return nHandled;
799 }
800 
801 // -----------------------------------------------------------------------
802 
Select()803 void SvxFillAttrBox::Select()
804 {
805 	FillAttrLB::Select();
806 }
807 
808 // -----------------------------------------------------------------------
809 
ReleaseFocus_Impl()810 void SvxFillAttrBox::ReleaseFocus_Impl()
811 {
812 	if( SfxViewShell::Current() )
813 	{
814 		Window* pShellWnd = SfxViewShell::Current()->GetWindow();
815 
816 		if ( pShellWnd )
817 			pShellWnd->GrabFocus();
818 	}
819 }
820