xref: /trunk/main/cui/source/dialogs/iconcdlg.cxx (revision 9b8096d0)
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_cui.hxx"
26 
27 #include <sfx2/app.hxx>
28 #include <tools/rc.h>
29 #include <tools/shl.hxx>
30 
31 #define _SVSTDARR_USHORTS
32 #include <svl/svstdarr.hxx>
33 #include <dialmgr.hxx>
34 
35 #include "iconcdlg.hxx"
36 
37 #include "helpid.hrc"
38 #include <cuires.hrc>
39 #include <unotools/viewoptions.hxx>
40 #include <svtools/apearcfg.hxx>
41 #include <vcl/mnemonic.hxx>
42 #include <vcl/i18nhelp.hxx>
43 
44 #ifdef WNT
IconcDlgCmpUS_Impl(const void * p1,const void * p2)45 int __cdecl IconcDlgCmpUS_Impl( const void* p1, const void* p2 )
46 #else
47 #if defined(OS2) && defined(ICC)
48 int _Optlink IconcDlgCmpUS_Impl( const void* p1, const void* p2 )
49 #else
50 int IconcDlgCmpUS_Impl( const void* p1, const void* p2 )
51 #endif
52 #endif
53 {
54 	return *(sal_uInt16*)p1 - *(sal_uInt16*)p2;
55 }
56 
57 // some stuff for easier changes for SvtViewOptions
58 static const sal_Char*		pViewOptDataName = "dialog data";
59 #define VIEWOPT_DATANAME	::rtl::OUString::createFromAscii( pViewOptDataName )
60 
SetViewOptUserItem(SvtViewOptions & rOpt,const String & rData)61 static inline void SetViewOptUserItem( SvtViewOptions& rOpt, const String& rData )
62 {
63 	rOpt.SetUserItem( VIEWOPT_DATANAME, ::com::sun::star::uno::makeAny( ::rtl::OUString( rData ) ) );
64 }
65 
GetViewOptUserItem(const SvtViewOptions & rOpt)66 static inline String GetViewOptUserItem( const SvtViewOptions& rOpt )
67 {
68 	::com::sun::star::uno::Any aAny( rOpt.GetUserItem( VIEWOPT_DATANAME ) );
69 	::rtl::OUString aUserData;
70 	aAny >>= aUserData;
71 
72 	return String( aUserData );
73 }
74 
75 
76 //#####################################################################
77 //
78 // Class IconChoicePage
79 //
80 //#####################################################################
81 
82 /**********************************************************************
83 |
84 | Ctor / Dtor
85 |
86 \**********************************************************************/
87 
IconChoicePage(Window * pParent,const ResId & rResId,const SfxItemSet & rAttrSet)88 IconChoicePage::IconChoicePage( Window *pParent, const ResId &rResId,
89 							    const SfxItemSet &rAttrSet )
90 :	TabPage					  ( pParent, rResId ),
91 	pSet					  ( &rAttrSet ),
92 	bHasExchangeSupport		  ( sal_False ),
93 	pDialog					  ( NULL ),
94 	bStandard				  ( sal_False )
95 {
96 	SetStyle ( GetStyle()  | WB_DIALOGCONTROL | WB_HIDE );
97 }
98 
99 // -----------------------------------------------------------------------
100 
~IconChoicePage()101 IconChoicePage::~IconChoicePage()
102 {
103 }
104 
105 /**********************************************************************
106 |
107 | Activate / Deaktivate
108 |
109 \**********************************************************************/
110 
ActivatePage(const SfxItemSet &)111 void IconChoicePage::ActivatePage( const SfxItemSet& )
112 {
113 }
114 
115 // -----------------------------------------------------------------------
116 
DeactivatePage(SfxItemSet *)117 int IconChoicePage::DeactivatePage( SfxItemSet* )
118 {
119 	return LEAVE_PAGE;
120 }
121 
122 /**********************************************************************
123 |
124 | ...
125 |
126 \**********************************************************************/
127 
FillUserData()128 void IconChoicePage::FillUserData()
129 {
130 }
131 
132 // -----------------------------------------------------------------------
133 
IsReadOnly() const134 sal_Bool IconChoicePage::IsReadOnly() const
135 {
136     return sal_False;
137 }
138 
139 // -----------------------------------------------------------------------
140 
QueryClose()141 sal_Bool IconChoicePage::QueryClose()
142 {
143     return sal_True;
144 }
145 
146 /**********************************************************************
147 |
148 | window-methods
149 |
150 \**********************************************************************/
151 
ImplInitSettings()152 void IconChoicePage::ImplInitSettings()
153 {
154 	Window* pParent = GetParent();
155 	if ( pParent->IsChildTransparentModeEnabled() && !IsControlBackground() )
156 	{
157 		EnableChildTransparentMode( sal_True );
158 		SetParentClipMode( PARENTCLIPMODE_NOCLIP );
159 		SetPaintTransparent( sal_True );
160 		SetBackground();
161 	}
162 	else
163 	{
164 		EnableChildTransparentMode( sal_False );
165 		SetParentClipMode( 0 );
166 		SetPaintTransparent( sal_False );
167 
168 		if ( IsControlBackground() )
169 			SetBackground( GetControlBackground() );
170 		else
171 			SetBackground( pParent->GetBackground() );
172 	}
173 }
174 
175 // -----------------------------------------------------------------------
176 
StateChanged(StateChangedType nType)177 void IconChoicePage::StateChanged( StateChangedType nType )
178 {
179 	Window::StateChanged( nType );
180 
181 	if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
182 	{
183 		ImplInitSettings();
184 		Invalidate();
185 	}
186 }
187 
188 // -----------------------------------------------------------------------
189 
DataChanged(const DataChangedEvent & rDCEvt)190 void IconChoicePage::DataChanged( const DataChangedEvent& rDCEvt )
191 {
192 	Window::DataChanged( rDCEvt );
193 
194 	if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
195 		 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
196 	{
197 		ImplInitSettings();
198 		Invalidate();
199 	}
200 }
201 
202 //#####################################################################
203 //
204 // Class IconChoiceDialog
205 //
206 //#####################################################################
207 
208 /**********************************************************************
209 |
210 | Ctor / Dtor
211 |
212 \**********************************************************************/
213 
IconChoiceDialog(Window * pParent,const ResId & rResId,const EIconChoicePos ePos,const SfxItemSet * pItemSet)214 IconChoiceDialog::IconChoiceDialog ( Window* pParent, const ResId &rResId,
215 									 const EIconChoicePos ePos,
216 									 const SfxItemSet *pItemSet )//, sal_Bool bEditFmt, const String *pUserButtonText = 0 )
217 : 	ModalDialog			( pParent, rResId ),
218     meChoicePos     ( ePos ),
219     maIconCtrl      ( this, WB_3DLOOK | WB_ICON | WB_BORDER |
220                             WB_NOCOLUMNHEADER | WB_HIGHLIGHTFRAME |
221                             /* WB_NOSELECTION | */ WB_NODRAGSELECTION | WB_TABSTOP ),
222     mnCurrentPageId ( USHRT_MAX ),
223 
224     aOKBtn          ( this, WB_DEFBUTTON ),
225 	aCancelBtn		( this, WB_DEFBUTTON ),
226 	aHelpBtn		( this ),
227 	aResetBtn		( this ),
228     pSet            ( pItemSet ),
229     pOutSet         ( NULL ),
230     pExampleSet     ( NULL ),
231     pRanges         ( NULL ),
232     nResId          ( rResId.GetId() ),
233 
234     bHideResetBtn   ( sal_False ),
235 	bModal			( sal_False ),
236 	bInOK			( sal_False ),
237 	bModified		( sal_False ),
238     bItemsReset     ( sal_False )
239 {
240 	// IconChoiceCtrl-Settings
241 	//maIconCtrl.SetBackground ( Wallpaper( Color (146, 146, 186) ) );
242 
243 	maIconCtrl.SetStyle (WB_3DLOOK | WB_ICON | WB_BORDER | WB_NOCOLUMNHEADER | WB_HIGHLIGHTFRAME | /* WB_NOSELECTION | */ WB_NODRAGSELECTION | WB_TABSTOP | WB_CLIPCHILDREN );
244 	SetCtrlPos ( meChoicePos );
245 	maIconCtrl.SetClickHdl ( LINK ( this, IconChoiceDialog , ChosePageHdl_Impl ) );
246 	maIconCtrl.Show();
247 	maIconCtrl.SetChoiceWithCursor ( sal_True );
248 	maIconCtrl.SetSelectionMode( SINGLE_SELECTION );
249 	maIconCtrl.SetHelpId( HID_ICCDIALOG_CHOICECTRL );
250 
251 	// ItemSet
252 	if ( pSet )
253 	{
254 		pExampleSet = new SfxItemSet( *pSet );
255 		pOutSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() );
256 	}
257 
258 	// Buttons
259 	aOKBtn.SetClickHdl	 ( LINK( this, IconChoiceDialog, OkHdl ) );
260 	aOKBtn.SetHelpId( HID_ICCDIALOG_OK_BTN );
261 	aCancelBtn.SetHelpId( HID_ICCDIALOG_CANCEL_BTN );
262 	aResetBtn.SetClickHdl( LINK( this, IconChoiceDialog, ResetHdl ) );
263 	aResetBtn.SetText( CUI_RESSTR(RID_SVXSTR_ICONCHOICEDLG_RESETBUT) );
264 	aResetBtn.SetHelpId( HID_ICCDIALOG_RESET_BTN );
265 	aOKBtn.Show();
266 	aCancelBtn.Show();
267 	aHelpBtn.Show();
268 	aResetBtn.Show();
269 
270 	SetPosSizeCtrls ( sal_True );
271 }
272 
273 // -----------------------------------------------------------------------
274 
275 /*
276 IconChoiceDialog ::IconChoiceDialog ( SfxViewFrame *pViewFrame, Window* pParent, const ResId &rResId,
277 				   const SfxItemSet * = 0, sal_Bool bEditFmt = sal_False,
278 				   const String *pUserButtonText = 0 )
279 : 	meChoicePos		( PosLeft ),	// Default erst ma Links
280 	maIconCtrl		( this, Die_Winbits ),
281 	aOKBtn			( this ),
282 	pUserBtn		( pUserButtonText? new PushButton(this): 0 ),
283 	aCancelBtn		( this ),
284 	aHelpBtn		( this ),
285 	aResetBtn		( this ),
286 	aBaseFmtBtn		( this ),
287 	mnCurrentPageId	( 0 )
288 {
289 	FreeResource();
290 }
291 */
292 
293 // -----------------------------------------------------------------------
294 
~IconChoiceDialog()295 IconChoiceDialog ::~IconChoiceDialog ()
296 {
297 	sal_uLong i;
298 
299 	// save configuration at INI-Manager
300 	// and remove pages
301 	SvtViewOptions aTabDlgOpt( E_TABDIALOG, String::CreateFromInt32( nResId ) );
302 	aTabDlgOpt.SetWindowState( ::rtl::OUString::createFromAscii( GetWindowState((WINDOWSTATE_MASK_X | WINDOWSTATE_MASK_Y | WINDOWSTATE_MASK_STATE | WINDOWSTATE_MASK_MINIMIZED)).GetBuffer() ) );
303 	aTabDlgOpt.SetPageID( mnCurrentPageId );
304 
305 	const sal_uLong nCount = maPageList.Count();
306 
307 	for ( i = 0; i < nCount; ++i )
308 	{
309 		IconChoicePageData* pData = maPageList.GetObject(i);
310 
311 		if ( pData->pPage )
312 		{
313 			pData->pPage->FillUserData();
314 			String aPageData(pData->pPage->GetUserData());
315 			if ( aPageData.Len() )
316 			{
317 				SvtViewOptions aTabPageOpt( E_TABPAGE, String::CreateFromInt32( pData->nId ) );
318 
319 				SetViewOptUserItem( aTabPageOpt, aPageData );
320 			}
321 
322 			if ( pData->bOnDemand )
323 				delete (SfxItemSet*)&pData->pPage->GetItemSet();
324 			delete pData->pPage;
325 		}
326 		delete pData;
327 	}
328 
329 	// remove Userdata from Icons
330 	for ( i=0; i<maIconCtrl.GetEntryCount(); i++)
331 	{
332 		SvxIconChoiceCtrlEntry* pEntry = maIconCtrl.GetEntry ( i );
333 		sal_uInt16* pUserData = (sal_uInt16*) pEntry->GetUserData();
334 		delete pUserData;
335 	}
336 
337 	//
338 	if ( pRanges )
339 		delete pRanges;
340 	if ( pOutSet )
341 		delete pOutSet;
342 }
343 
344 /**********************************************************************
345 |
346 | add new page
347 |
348 \**********************************************************************/
349 
AddTabPage(sal_uInt16 nId,const String & rIconText,const Image & rChoiceIcon,const Image & rChoiceIconHC,CreatePage pCreateFunc,GetPageRanges pRangesFunc,sal_Bool bItemsOnDemand,sal_uLong)350 SvxIconChoiceCtrlEntry* IconChoiceDialog::AddTabPage( sal_uInt16 nId, const String& rIconText,
351 								   const Image& rChoiceIcon,
352 								   const Image& rChoiceIconHC,
353 								   CreatePage pCreateFunc /* != 0 */,
354 								   GetPageRanges pRangesFunc /* darf 0 sein */,
355                                    sal_Bool bItemsOnDemand, sal_uLong /*nPos*/ )
356 {
357 	IconChoicePageData* pData = new IconChoicePageData ( nId, pCreateFunc,
358 		                                                 pRangesFunc,
359 														 bItemsOnDemand );
360 	maPageList.Insert ( pData, LIST_APPEND );
361 
362 	pData->fnGetRanges = pRangesFunc;
363 	pData->bOnDemand = bItemsOnDemand;
364 
365 	sal_uInt16 *pId = new sal_uInt16 ( nId );
366 	SvxIconChoiceCtrlEntry*	pEntry = maIconCtrl.InsertEntry( rIconText, rChoiceIcon, rChoiceIconHC );
367 	pEntry->SetUserData ( (void*) pId );
368 	return pEntry;
369 }
370 
371 /**********************************************************************
372 |
373 | Paint-method
374 |
375 \**********************************************************************/
376 
Paint(const Rectangle & rRect)377 void IconChoiceDialog::Paint( const Rectangle& rRect )
378 {
379 	Dialog::Paint ( rRect );
380 
381 	for ( sal_uLong i=0; i<maPageList.Count(); i++ )
382 	{
383 		IconChoicePageData* pData = (IconChoicePageData*)maPageList.GetObject ( i );
384 
385 		if ( pData->nId == mnCurrentPageId )
386 		{
387 			ShowPageImpl ( pData );
388 		}
389 		else
390 		{
391 			HidePageImpl ( pData );
392 		}
393 	}
394 }
395 
SetCtrlPos(const EIconChoicePos & rPos)396 EIconChoicePos IconChoiceDialog::SetCtrlPos( const EIconChoicePos& rPos )
397 {
398 	WinBits aWinBits = maIconCtrl.GetStyle ();
399 
400 	switch ( meChoicePos )
401 	{
402 		case PosLeft :
403 			aWinBits &= ~WB_ALIGN_TOP & ~WB_NOVSCROLL;
404 			aWinBits |= WB_ALIGN_LEFT | WB_NOHSCROLL;
405 			break;
406 		case PosRight :
407 			aWinBits &= ~WB_ALIGN_TOP & ~WB_NOVSCROLL;
408 			aWinBits |= WB_ALIGN_LEFT | WB_NOHSCROLL;
409 			break;
410 		case PosTop :
411 			aWinBits &= ~WB_ALIGN_LEFT & ~WB_NOHSCROLL;
412 			aWinBits |= WB_ALIGN_TOP | WB_NOVSCROLL;
413 			break;
414 		case PosBottom :
415 			aWinBits &= ~WB_ALIGN_LEFT & ~WB_NOHSCROLL;
416 			aWinBits |= WB_ALIGN_TOP | WB_NOVSCROLL;
417 			break;
418 	};
419 	maIconCtrl.SetStyle ( aWinBits );
420 
421 	SetPosSizeCtrls();
422 
423 
424 	EIconChoicePos eOldPos = meChoicePos;
425 	meChoicePos = rPos;
426 
427 	return eOldPos;
428 }
429 
430 /**********************************************************************
431 |
432 | Show / Hide page or button
433 |
434 \**********************************************************************/
435 
ShowPageImpl(IconChoicePageData * pData)436 void IconChoiceDialog::ShowPageImpl ( IconChoicePageData* pData )
437 {
438 	if ( pData->pPage )
439 		pData->pPage->Show();
440 }
441 
442 // -----------------------------------------------------------------------
443 
HidePageImpl(IconChoicePageData * pData)444 void IconChoiceDialog::HidePageImpl ( IconChoicePageData* pData )
445 {
446 	if ( pData->pPage )
447 		pData->pPage->Hide();
448 }
449 
450 // -----------------------------------------------------------------------
451 
ShowPage(sal_uInt16 nId)452 void IconChoiceDialog::ShowPage( sal_uInt16 nId )
453 {
454     bool bInvalidate = GetCurPageId() != nId;
455     SetCurPageId( nId );
456 	ActivatePageImpl( );
457     if(bInvalidate)
458         Invalidate();
459 
460 	// IA2 CWS. MT: I guess we want the event now, and not in Paint()?
461 	IconChoicePageData* pData = GetPageData ( mnCurrentPageId );
462 	if(pData)
463 		ShowPageImpl ( pData );
464 }
465 
466 /**********************************************************************
467 |
468 | Resize Dialog
469 |
470 \**********************************************************************/
471 
472 #define ICONCTRL_WIDTH_PIXEL	   110
473 #define ICONCTRL_HEIGHT_PIXEL	    75
474 #define MINSIZE_BUTTON_WIDTH		70
475 #define MINSIZE_BUTTON_HEIGHT		22
476 
Resize()477 void IconChoiceDialog::Resize()
478 {
479 	Dialog::Resize ();
480 
481 	if ( IsReallyVisible() )
482 	{
483 		SetPosSizeCtrls ();
484 	}
485 }
486 
SetPosSizeCtrls(sal_Bool bInit)487 void IconChoiceDialog::SetPosSizeCtrls ( sal_Bool bInit )
488 {
489 	const Point aCtrlOffset ( LogicToPixel( Point( CTRLS_OFFSET, CTRLS_OFFSET ), MAP_APPFONT ) );
490 	Size aOutSize ( GetOutputSizePixel() );
491 
492 	////////////////////////////////////////
493 	// Button-Defaults
494 	//
495 	Size aDefaultButtonSize = LogicToPixel( Size( 50, 14 ), MAP_APPFONT );
496 
497 	// Reset-Button
498 	Size aResetButtonSize ( bInit ? aDefaultButtonSize :
499 	                                aResetBtn.GetSizePixel () );
500 
501 	////////////////////////////////////////
502 	// IconChoiceCtrl resizen & positionieren
503 	//
504     SvtTabAppearanceCfg aCfg;
505     const long nDefaultWidth = (aCfg.GetScaleFactor() * ICONCTRL_WIDTH_PIXEL) / 100;
506     const long nDefaultHeight = (aCfg.GetScaleFactor() * ICONCTRL_HEIGHT_PIXEL) / 100;
507 
508     Size aNewIconCtrlSize  ( nDefaultWidth,
509                              aOutSize.Height()-(2*aCtrlOffset.X()) );
510 	Point aIconCtrlPos;
511 	switch ( meChoicePos )
512 	{
513 		case PosLeft :
514 			aIconCtrlPos = aCtrlOffset;
515             aNewIconCtrlSize = Size ( nDefaultWidth,
516 		                              aOutSize.Height()-(2*aCtrlOffset.X()) );
517 			break;
518 		case PosRight :
519             aIconCtrlPos = Point ( aOutSize.Width() - nDefaultWidth -
520 				                   aCtrlOffset.X(), aCtrlOffset.X() );
521             aNewIconCtrlSize = Size ( nDefaultWidth,
522 		                              aOutSize.Height()-(2*aCtrlOffset.X()) );
523 			break;
524 		case PosTop :
525 			aIconCtrlPos = aCtrlOffset;
526 			aNewIconCtrlSize = Size ( aOutSize.Width()-(2*aCtrlOffset.X()),
527                                       nDefaultHeight );
528 			break;
529 		case PosBottom :
530 			aIconCtrlPos = Point ( aCtrlOffset.X(), aOutSize.Height() -
531 				                   aResetButtonSize.Height() - (2*aCtrlOffset.X()) -
532                                    nDefaultHeight );
533 			aNewIconCtrlSize = Size ( aOutSize.Width()-(2*aCtrlOffset.X()),
534                                       nDefaultHeight );
535 			break;
536 	};
537 	maIconCtrl.SetPosSizePixel ( aIconCtrlPos, aNewIconCtrlSize );
538 	maIconCtrl.ArrangeIcons();
539 
540 	////////////////////////////////////////
541 	// Pages resizen & positionieren
542 	//
543 	for ( sal_uLong i=0; i<maPageList.Count(); i++ )
544 	{
545 		IconChoicePageData* pData = (IconChoicePageData*)maPageList.GetObject ( i );
546 
547 		Point aNewPagePos;
548 		Size aNewPageSize;
549 		switch ( meChoicePos )
550 		{
551 			case PosLeft :
552 				aNewPagePos = Point ( aNewIconCtrlSize.Width() + (2*CTRLS_OFFSET),
553 			                          CTRLS_OFFSET );
554 				aNewPageSize = Size ( aOutSize.Width() - aNewIconCtrlSize.Width() -
555 							          (3*CTRLS_OFFSET),
556 							          aOutSize.Height() - aOKBtn.GetSizePixel().Height() -
557 							          (3*CTRLS_OFFSET) );
558 				break;
559 			case PosRight :
560 				aNewPagePos = aCtrlOffset;
561 				aNewPageSize = Size ( aOutSize.Width() - aNewIconCtrlSize.Width() -
562 							          (3*aCtrlOffset.X()),
563 							          aOutSize.Height() - aOKBtn.GetSizePixel().Height() -
564 							          (3*aCtrlOffset.X()) );
565 				break;
566 			case PosTop :
567 				aNewPagePos = Point ( aCtrlOffset.X(), aNewIconCtrlSize.Height() +
568 					                  (2*aCtrlOffset.X()) );
569 				aNewPageSize = Size ( aOutSize.Width() - (2*aCtrlOffset.X()),
570 							          aOutSize.Height() - aOKBtn.GetSizePixel().Height() -
571 							          aNewIconCtrlSize.Height() - (4*aCtrlOffset.X()) );
572 				break;
573 			case PosBottom :
574 				aNewPagePos = aCtrlOffset;
575 				aNewPageSize = Size ( aOutSize.Width() - (2*aCtrlOffset.X()),
576 							          aOutSize.Height() - aOKBtn.GetSizePixel().Height() -
577 							          aNewIconCtrlSize.Height() - (4*aCtrlOffset.X()) );
578 				break;
579 		};
580 
581 		if ( pData->pPage )
582 			pData->pPage->SetPosSizePixel ( aNewPagePos, aNewPageSize );
583 	}
584 
585 	////////////////////////////////////////
586 	// Buttons positionieren
587 	//
588 	sal_uLong nXOffset=0;
589 	if ( meChoicePos == PosRight )
590 		nXOffset = aNewIconCtrlSize.Width()+(2*aCtrlOffset.X());
591 
592 	aResetBtn.SetPosSizePixel ( Point( aOutSize.Width() - nXOffset -
593 		                               aResetButtonSize.Width()-aCtrlOffset.X(),
594 								       aOutSize.Height()-aResetButtonSize.Height()-
595 									   aCtrlOffset.X() ),
596 							   aResetButtonSize );
597 	// Help-Button
598 	Size aHelpButtonSize ( bInit ? aDefaultButtonSize :
599 	                               aHelpBtn.GetSizePixel () );
600 	aHelpBtn.SetPosSizePixel ( Point( aOutSize.Width()-aResetButtonSize.Width()-
601 		                              aHelpButtonSize.Width()- nXOffset -
602 								      (2*aCtrlOffset.X()),
603 								      aOutSize.Height()-aHelpButtonSize.Height()-
604 									  aCtrlOffset.X() ),
605 							   aHelpButtonSize );
606 	// Cancel-Button
607 	Size aCancelButtonSize ( bInit ? aDefaultButtonSize :
608 	                                 aCancelBtn.GetSizePixel () );
609 	aCancelBtn.SetPosSizePixel ( Point( aOutSize.Width()-aCancelButtonSize.Width()-
610 									    aResetButtonSize.Width()-aHelpButtonSize.Width()-
611 									    (3*aCtrlOffset.X()) -  nXOffset,
612 								        aOutSize.Height()-aCancelButtonSize.Height()-
613 										aCtrlOffset.X() ),
614 								aCancelButtonSize );
615 	// OK-Button
616 	Size aOKButtonSize ( bInit ? aDefaultButtonSize : aOKBtn.GetSizePixel () );
617 	aOKBtn.SetPosSizePixel ( Point( aOutSize.Width()-aOKButtonSize.Width()-
618 		                            aCancelButtonSize.Width()-aResetButtonSize.Width()-
619 									aHelpButtonSize.Width()-(4*aCtrlOffset.X())-  nXOffset,
620 								    aOutSize.Height()-aOKButtonSize.Height()-aCtrlOffset.X() ),
621 							aOKButtonSize );
622 
623 	Invalidate();
624 }
625 
SetPosSizePages(sal_uInt16 nId)626 void IconChoiceDialog::SetPosSizePages ( sal_uInt16 nId )
627 {
628 	const Point aCtrlOffset ( LogicToPixel( Point( CTRLS_OFFSET, CTRLS_OFFSET ), MAP_APPFONT ) );
629 	IconChoicePageData* pData = GetPageData ( nId );
630 
631 	if ( pData->pPage )
632 	{
633 		Size aOutSize ( GetOutputSizePixel() );
634 		Size aIconCtrlSize ( maIconCtrl.GetSizePixel() );
635 
636 		Point aNewPagePos;
637 		Size aNewPageSize;
638 		switch ( meChoicePos )
639 		{
640 			case PosLeft :
641 				aNewPagePos = Point ( aIconCtrlSize.Width() + (2*aCtrlOffset.X()),
642 			                          aCtrlOffset.X() );
643 				aNewPageSize = Size ( aOutSize.Width() - maIconCtrl.GetSizePixel().Width() -
644 							          (3*aCtrlOffset.X()),
645 							          aOutSize.Height() - aOKBtn.GetSizePixel().Height() -
646 							          (3*aCtrlOffset.X()) );
647 				break;
648 			case PosRight :
649 				aNewPagePos = aCtrlOffset;
650 				aNewPageSize = Size ( aOutSize.Width() - maIconCtrl.GetSizePixel().Width() -
651 							          (3*aCtrlOffset.X()),
652 							          aOutSize.Height() - aOKBtn.GetSizePixel().Height() -
653 							          (3*aCtrlOffset.X()) );
654 				break;
655 			case PosTop :
656 				aNewPagePos = Point ( aCtrlOffset.X(), aIconCtrlSize.Height() +
657 					                  (2*aCtrlOffset.X()) );
658 				aNewPageSize = Size ( aOutSize.Width() - (2*aCtrlOffset.X()),
659 							          aOutSize.Height() - aOKBtn.GetSizePixel().Height() -
660 							          maIconCtrl.GetSizePixel().Height() - (4*aCtrlOffset.X()) );
661 				break;
662 			case PosBottom :
663 				aNewPagePos = aCtrlOffset;
664 				aNewPageSize = Size ( aOutSize.Width() - (2*aCtrlOffset.X()),
665 							          aOutSize.Height() - aOKBtn.GetSizePixel().Height() -
666 							          maIconCtrl.GetSizePixel().Height() - (4*aCtrlOffset.X()) );
667 				break;
668 		};
669 
670 		pData->pPage->SetPosSizePixel ( aNewPagePos, aNewPageSize );
671 	}
672 }
673 
674 /**********************************************************************
675 |
676 | select a page
677 |
678 \**********************************************************************/
679 
IMPL_LINK(IconChoiceDialog,ChosePageHdl_Impl,void *,EMPTYARG)680 IMPL_LINK ( IconChoiceDialog , ChosePageHdl_Impl, void *, EMPTYARG )
681 {
682 	sal_uLong nPos;
683 
684 	SvxIconChoiceCtrlEntry *pEntry = maIconCtrl.GetSelectedEntry ( nPos );
685 	if ( !pEntry )
686 		pEntry = maIconCtrl.GetCursor( );
687 
688 	sal_uInt16 *pId = (sal_uInt16*)pEntry->GetUserData ();
689 
690 	if( *pId != mnCurrentPageId )
691 	{
692 		IconChoicePageData* pData = GetPageData ( mnCurrentPageId );
693 		if ( pData->pPage )
694 			DeActivatePageImpl();
695 
696 		SetCurPageId ( *pId );
697 
698 		ActivatePageImpl();
699         Invalidate();
700 	}
701 
702 	return 0L;
703 }
704 
705 /**********************************************************************
706 |
707 | Button-handler
708 |
709 \**********************************************************************/
710 
IMPL_LINK(IconChoiceDialog,OkHdl,Button *,EMPTYARG)711 IMPL_LINK( IconChoiceDialog, OkHdl, Button *, EMPTYARG )
712 {
713 	bInOK = sal_True;
714 
715 	if ( OK_Impl() )
716 	{
717 		if ( bModal )
718 			EndDialog( Ok() );
719 		else
720 		{
721 			Ok();
722 			Close();
723 		}
724 	}
725 	return 0;
726 }
727 
728 // -----------------------------------------------------------------------
729 
IMPL_LINK(IconChoiceDialog,ResetHdl,Button *,EMPTYARG)730 IMPL_LINK( IconChoiceDialog, ResetHdl, Button *, EMPTYARG )
731 {
732 	ResetPageImpl ();
733 
734 	IconChoicePageData* pData = GetPageData ( mnCurrentPageId );
735 	DBG_ASSERT( pData, "Id nicht bekannt" );
736 
737 	if ( pData->bOnDemand )
738 	{
739 		// CSet auf AIS hat hier Probleme, daher getrennt
740         const SfxItemSet* _pSet = &( pData->pPage->GetItemSet() );
741         pData->pPage->Reset( *(SfxItemSet*)_pSet );
742 	}
743 	else
744         pData->pPage->Reset( *pSet );
745 
746 
747 	return 0;
748 }
749 
750 // -----------------------------------------------------------------------
751 
IMPL_LINK(IconChoiceDialog,CancelHdl,Button *,EMPTYARG)752 IMPL_LINK( IconChoiceDialog, CancelHdl, Button*, EMPTYARG )
753 {
754 	Close();
755 
756 	return 0;
757 }
758 
759 /**********************************************************************
760 |
761 | call page
762 |
763 \**********************************************************************/
764 
ActivatePageImpl()765 void IconChoiceDialog::ActivatePageImpl ()
766 {
767 	DBG_ASSERT( maPageList.Count(), "keine Pages angemeldet" );
768 	IconChoicePageData* pData = GetPageData ( mnCurrentPageId );
769 	DBG_ASSERT( pData, "Id nicht bekannt" );
770 	if ( pData )
771 	{
772 		if ( !pData->pPage )
773 		{
774 			const SfxItemSet* pTmpSet = 0;
775 
776 			if ( pSet )
777 			{
778 				if ( bItemsReset && pSet->GetParent() )
779 					pTmpSet = pSet->GetParent();
780 				else
781 					pTmpSet = pSet;
782 			}
783 
784 			if ( pTmpSet && !pData->bOnDemand )
785 				pData->pPage = (pData->fnCreatePage)( this, *pTmpSet );
786 			else
787 				pData->pPage = (pData->fnCreatePage)( this, *CreateInputItemSet( mnCurrentPageId ) );
788 
789 			SvtViewOptions aTabPageOpt( E_TABPAGE, String::CreateFromInt32( pData->nId ) );
790 			pData->pPage->SetUserData( GetViewOptUserItem( aTabPageOpt ) );
791 			SetPosSizePages ( pData->nId );
792 
793 			if ( pData->bOnDemand )
794 				pData->pPage->Reset( (SfxItemSet &)pData->pPage->GetItemSet() );
795 			else
796 				pData->pPage->Reset( *pSet );
797 
798             PageCreated( mnCurrentPageId, *pData->pPage );
799 		}
800 		else if ( pData->bRefresh )
801 		{
802 			pData->pPage->Reset( *pSet );
803 		}
804 
805 		pData->bRefresh = sal_False;
806 
807 		if ( pExampleSet )
808 			pData->pPage->ActivatePage( *pExampleSet );
809 	}
810 
811 	SetHelpId( pData->pPage->GetHelpId() );
812 
813 	sal_Bool bReadOnly = pData->pPage->IsReadOnly();
814 	if ( bReadOnly || bHideResetBtn )
815 		aResetBtn.Hide();
816 	else
817 		aResetBtn.Show();
818 
819 }
820 
821 // -----------------------------------------------------------------------
822 
DeActivatePageImpl()823 sal_Bool IconChoiceDialog::DeActivatePageImpl ()
824 {
825 	IconChoicePageData *pData = GetPageData ( mnCurrentPageId );
826 
827 	int nRet = IconChoicePage::LEAVE_PAGE;
828 
829 	if ( pData )
830 	{
831 		IconChoicePage * pPage = pData->pPage;
832 
833 		if ( !pExampleSet && pPage->HasExchangeSupport() && pSet )
834 			pExampleSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() );
835 
836 		if ( pSet )
837 		{
838 			SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
839 
840 			if ( pPage->HasExchangeSupport() )
841 				nRet = pPage->DeactivatePage( &aTmp );
842 
843 			if ( ( IconChoicePage::LEAVE_PAGE & nRet ) == IconChoicePage::LEAVE_PAGE &&
844 				 aTmp.Count() )
845 			{
846 				pExampleSet->Put( aTmp );
847 				pOutSet->Put( aTmp );
848 			}
849 		}
850 		else
851 		{
852 			if ( pPage->HasExchangeSupport() ) //!!!
853 			{
854 				if ( !pExampleSet )
855 				{
856 					SfxItemPool* pPool = pPage->GetItemSet().GetPool();
857 					pExampleSet =
858 						new SfxItemSet( *pPool, GetInputRanges( *pPool ) );
859 				}
860 				nRet = pPage->DeactivatePage( pExampleSet );
861 			}
862 			else
863 				nRet = pPage->DeactivatePage( NULL );
864 		}
865 
866 		if ( nRet & IconChoicePage::REFRESH_SET )
867 		{
868 			pSet = GetRefreshedSet();
869 			DBG_ASSERT( pSet, "GetRefreshedSet() liefert NULL" );
870 			// alle Pages als neu zu initialsieren flaggen
871 			const sal_uLong nCount = maPageList.Count();
872 
873 			for ( sal_uInt16 i = 0; i < nCount; ++i )
874 			{
875 				IconChoicePageData* pObj = (IconChoicePageData*)maPageList.GetObject(i);
876 
877 				if ( pObj->pPage != pPage ) // eigene Page nicht mehr refreshen
878 					pObj->bRefresh = sal_True;
879 				else
880 					pObj->bRefresh = sal_False;
881 			}
882 		}
883 	}
884 
885 	if ( nRet & IconChoicePage::LEAVE_PAGE )
886 		return sal_True;
887 	else
888 		return sal_False;
889 }
890 
891 // -----------------------------------------------------------------------
892 
ResetPageImpl()893 void IconChoiceDialog::ResetPageImpl ()
894 {
895 	IconChoicePageData *pData = GetPageData ( mnCurrentPageId );
896 
897 	DBG_ASSERT( pData, "Id nicht bekannt" );
898 
899 	if ( pData->bOnDemand )
900 	{
901 		// CSet auf AIS hat hier Probleme, daher getrennt
902         const SfxItemSet* _pSet = &pData->pPage->GetItemSet();
903         pData->pPage->Reset( *(SfxItemSet*)_pSet );
904 	}
905 	else
906         pData->pPage->Reset( *pSet );
907 }
908 
909 /**********************************************************************
910 |
911 | handling itemsets
912 |
913 \**********************************************************************/
914 
GetInputRanges(const SfxItemPool & rPool)915 const sal_uInt16* IconChoiceDialog::GetInputRanges( const SfxItemPool& rPool )
916 {
917 	if ( pSet )
918 	{
919 		DBG_ERRORFILE( "Set bereits vorhanden!" );
920 		return pSet->GetRanges();
921 	}
922 
923 	if ( pRanges )
924 		return pRanges;
925 	SvUShorts aUS( 16, 16 );
926 	sal_uLong nCount = maPageList.Count();
927 
928 	sal_uInt16 i;
929 	for ( i = 0; i < nCount; ++i )
930 	{
931 		IconChoicePageData* pData = maPageList.GetObject (i);
932 
933 		if ( pData->fnGetRanges )
934 		{
935 			const sal_uInt16* pTmpRanges = (pData->fnGetRanges)();
936 			const sal_uInt16* pIter = pTmpRanges;
937 
938 			sal_uInt16 nLen;
939 			for( nLen = 0; *pIter; ++nLen, ++pIter )
940 				;
941 			aUS.Insert( pTmpRanges, nLen, aUS.Count() );
942 		}
943 	}
944 
945 	// remove double Id's
946 #ifndef TF_POOLABLE
947 	if ( rPool.HasMap() )
948 #endif
949 	{
950 		nCount = aUS.Count();
951 
952 		for ( i = 0; i < nCount; ++i )
953 			aUS[i] = rPool.GetWhich( aUS[i] );
954 	}
955 
956 	// sortieren
957 	if ( aUS.Count() > 1 )
958 	{
959 #if defined __SUNPRO_CC
960 #pragma disable_warn
961 #endif
962 		qsort( (void*)aUS.GetData(), aUS.Count(), sizeof(sal_uInt16), IconcDlgCmpUS_Impl );
963 #if defined __SUNPRO_CC
964 #pragma enable_warn
965 #endif
966 	}
967 
968 	pRanges = new sal_uInt16[aUS.Count() + 1];
969 	memcpy(pRanges, aUS.GetData(), sizeof(sal_uInt16) * aUS.Count());
970 	pRanges[aUS.Count()] = 0;
971 
972 	return pRanges;
973 }
974 
975 // -----------------------------------------------------------------------
976 
SetInputSet(const SfxItemSet * pInSet)977 void IconChoiceDialog::SetInputSet( const SfxItemSet* pInSet )
978 {
979 	FASTBOOL bSet = ( pSet != NULL );
980 
981 	pSet = pInSet;
982 
983 	if ( !bSet && !pExampleSet && !pOutSet )
984 	{
985 		pExampleSet = new SfxItemSet( *pSet );
986 		pOutSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() );
987 	}
988 }
989 
990 // -----------------------------------------------------------------------
991 
PageCreated(sal_uInt16,IconChoicePage &)992 void IconChoiceDialog::PageCreated( sal_uInt16 /*nId*/, IconChoicePage& /*rPage*/ )
993 {
994     // not interested in
995 }
996 
997 // -----------------------------------------------------------------------
998 
CreateInputItemSet(sal_uInt16)999 SfxItemSet* IconChoiceDialog::CreateInputItemSet( sal_uInt16 )
1000 {
1001 	DBG_WARNINGFILE( "CreateInputItemSet nicht implementiert" );
1002 
1003 	return 0;
1004 }
1005 
1006 /**********************************************************************
1007 |
1008 | start dialog
1009 |
1010 \**********************************************************************/
1011 
Execute()1012 short IconChoiceDialog::Execute()
1013 {
1014 	if ( !maPageList.Count() )
1015 		return RET_CANCEL;
1016 
1017 	Start_Impl();
1018 
1019 	return Dialog::Execute();
1020 }
1021 
1022 // -----------------------------------------------------------------------
1023 
Start(sal_Bool bShow)1024 void IconChoiceDialog::Start( sal_Bool bShow )
1025 {
1026 
1027 	aCancelBtn.SetClickHdl( LINK( this, IconChoiceDialog, CancelHdl ) );
1028 	bModal = sal_False;
1029 
1030 	Start_Impl();
1031 
1032 	if ( bShow )
1033 		Window::Show();
1034 
1035 }
1036 
1037 // -----------------------------------------------------------------------
1038 
QueryClose()1039 sal_Bool IconChoiceDialog::QueryClose()
1040 {
1041     sal_Bool bRet = sal_True;
1042     const sal_uLong nCount = maPageList.Count();
1043     for ( sal_uLong i = 0; i < nCount; ++i )
1044     {
1045         IconChoicePageData* pData = maPageList.GetObject(i);
1046         if ( pData->pPage && !pData->pPage->QueryClose() )
1047         {
1048             bRet = sal_False;
1049             break;
1050         }
1051     }
1052     return bRet;
1053 }
1054 
1055 // -----------------------------------------------------------------------
1056 
Start_Impl()1057 void IconChoiceDialog::Start_Impl()
1058 {
1059 	Point aPos;
1060 	sal_uInt16 nActPage;
1061 
1062 	if ( mnCurrentPageId == 0 || mnCurrentPageId == USHRT_MAX )
1063 		nActPage = maPageList.GetObject(0)->nId;//First()->nId;
1064 	else
1065 		nActPage = mnCurrentPageId;
1066 
1067 	// Konfiguration vorhanden?
1068 	SvtViewOptions aTabDlgOpt( E_TABDIALOG, String::CreateFromInt32( nResId ) );
1069 
1070 	if ( aTabDlgOpt.Exists() )
1071 	{
1072 		// ggf. Position aus Konfig
1073 		SetWindowState( ByteString( aTabDlgOpt.GetWindowState().getStr(), RTL_TEXTENCODING_ASCII_US ) );
1074 
1075 		// initiale TabPage aus Programm/Hilfe/Konfig
1076 		nActPage = (sal_uInt16)aTabDlgOpt.GetPageID();
1077 
1078 		if ( USHRT_MAX != mnCurrentPageId )
1079 			nActPage = mnCurrentPageId;
1080 
1081 		if ( GetPageData ( nActPage ) == NULL )
1082 			nActPage = ( (IconChoicePageData*)maPageList.GetObject(0) )->nId;
1083 	}
1084 	else if ( USHRT_MAX != mnCurrentPageId && GetPageData ( mnCurrentPageId ) != NULL )
1085 		nActPage = mnCurrentPageId;
1086 
1087 	mnCurrentPageId = nActPage;
1088 
1089 	FocusOnIcon( mnCurrentPageId );
1090 
1091 	ActivatePageImpl();
1092 }
1093 
1094 // -----------------------------------------------------------------------
1095 
GetRefreshedSet()1096 const SfxItemSet* IconChoiceDialog::GetRefreshedSet()
1097 {
1098 	DBG_ERRORFILE( "GetRefreshedSet nicht implementiert" );
1099 	return 0;
1100 }
1101 
1102 /**********************************************************************
1103 |
1104 | tool-methods
1105 |
1106 \**********************************************************************/
1107 
GetPageData(sal_uInt16 nId)1108 IconChoicePageData* IconChoiceDialog::GetPageData ( sal_uInt16 nId )
1109 {
1110 	IconChoicePageData *pRet = NULL;
1111 	sal_Bool bFound = sal_False;
1112 
1113 	for ( sal_uLong i=0; i<maPageList.Count() && !bFound; i++ )
1114 	{
1115 		IconChoicePageData* pData = (IconChoicePageData*)maPageList.GetObject ( i );
1116 
1117 		if ( pData->nId == nId )
1118 		{
1119 			pRet = pData;
1120 		}
1121 	}
1122 
1123 	return pRet;
1124 }
1125 
1126 /**********************************************************************
1127 |
1128 | OK-Status
1129 |
1130 \**********************************************************************/
1131 
OK_Impl()1132 sal_Bool IconChoiceDialog::OK_Impl()
1133 {
1134 	IconChoicePage* pPage = GetPageData ( mnCurrentPageId )->pPage;
1135 
1136 	bool bEnd = !pPage;
1137 	if ( pPage )
1138 	{
1139 		int nRet = IconChoicePage::LEAVE_PAGE;
1140 		if ( pSet )
1141 		{
1142 			SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
1143 			sal_Bool bRet = sal_False;
1144 
1145 			if ( pPage->HasExchangeSupport() )
1146 				nRet = pPage->DeactivatePage( &aTmp );
1147 
1148 			if ( ( IconChoicePage::LEAVE_PAGE & nRet ) == IconChoicePage::LEAVE_PAGE
1149 				 && aTmp.Count() )
1150 			{
1151 				pExampleSet->Put( aTmp );
1152 				pOutSet->Put( aTmp );
1153 			}
1154 			else if ( bRet )
1155 				bModified |= sal_True;
1156 		}
1157 		else
1158 			nRet = pPage->DeactivatePage( NULL );
1159 		bEnd = nRet;
1160 	}
1161 
1162 	return bEnd;
1163 }
1164 
1165 // -----------------------------------------------------------------------
1166 
Ok()1167 short IconChoiceDialog::Ok()
1168 {
1169 	bInOK = sal_True;
1170 
1171 	if ( !pOutSet )
1172 	{
1173 		if ( !pExampleSet && pSet )
1174 			pOutSet = pSet->Clone( sal_False );	// ohne Items
1175 		else if ( pExampleSet )
1176 			pOutSet = new SfxItemSet( *pExampleSet );
1177 	}
1178     sal_Bool _bModified = sal_False;
1179 
1180 	const sal_uLong nCount = maPageList.Count();
1181 
1182 	for ( sal_uInt16 i = 0; i < nCount; ++i )
1183 	{
1184 		IconChoicePageData* pData = GetPageData ( i );
1185 
1186 		IconChoicePage* pPage = pData->pPage;
1187 
1188 		if ( pPage )
1189 		{
1190 			if ( pData->bOnDemand )
1191 			{
1192 				SfxItemSet& rSet = (SfxItemSet&)pPage->GetItemSet();
1193 				rSet.ClearItem();
1194                 _bModified |= pPage->FillItemSet( rSet );
1195 			}
1196 			else if ( pSet && !pPage->HasExchangeSupport() )
1197 			{
1198 				SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
1199 
1200 				if ( pPage->FillItemSet( aTmp ) )
1201 				{
1202                     _bModified |= sal_True;
1203 					pExampleSet->Put( aTmp );
1204 					pOutSet->Put( aTmp );
1205 				}
1206 			}
1207 		}
1208 	}
1209 
1210     if ( _bModified || ( pOutSet && pOutSet->Count() > 0 ) )
1211         _bModified |= sal_True;
1212 
1213     return _bModified ? RET_OK : RET_CANCEL;
1214 }
1215 
1216 // -----------------------------------------------------------------------
1217 
FocusOnIcon(sal_uInt16 nId)1218 void IconChoiceDialog::FocusOnIcon( sal_uInt16 nId )
1219 {
1220 	// set focus to icon for the current visible page
1221 	for ( sal_uInt16 i=0; i<maIconCtrl.GetEntryCount(); i++)
1222 	{
1223 		SvxIconChoiceCtrlEntry* pEntry = maIconCtrl.GetEntry ( i );
1224 		sal_uInt16* pUserData = (sal_uInt16*) pEntry->GetUserData();
1225 
1226 		if ( pUserData && *pUserData == nId )
1227 		{
1228 			maIconCtrl.SetCursor( pEntry );
1229 			break;
1230 		}
1231 	}
1232 }
1233