xref: /AOO41X/main/cui/source/dialogs/srchxtra.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_cui.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir // include ---------------------------------------------------------------
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "srchxtra.hxx"
34*cdf0e10cSrcweir #include <tools/rcid.h>
35*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
36*cdf0e10cSrcweir #include <svl/cjkoptions.hxx>
37*cdf0e10cSrcweir #include <svl/whiter.hxx>
38*cdf0e10cSrcweir #include <sfx2/objsh.hxx>
39*cdf0e10cSrcweir #include <cuires.hrc>
40*cdf0e10cSrcweir #include "srchxtra.hrc"
41*cdf0e10cSrcweir #include <svx/svxitems.hrc> // RID_ATTR_BEGIN
42*cdf0e10cSrcweir #include <svx/dialmgr.hxx>  // item resources
43*cdf0e10cSrcweir #include <editeng/flstitem.hxx>
44*cdf0e10cSrcweir #include "chardlg.hxx"
45*cdf0e10cSrcweir #include "paragrph.hxx"
46*cdf0e10cSrcweir #include <dialmgr.hxx>
47*cdf0e10cSrcweir #include "backgrnd.hxx"
48*cdf0e10cSrcweir #include <svx/dialogs.hrc> // RID_SVXPAGE_...
49*cdf0e10cSrcweir #include <tools/resary.hxx>
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir // class SvxSearchFormatDialog -------------------------------------------
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir SvxSearchFormatDialog::SvxSearchFormatDialog( Window* pParent, const SfxItemSet& rSet ) :
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir 	SfxTabDialog( pParent, CUI_RES( RID_SVXDLG_SEARCHFORMAT ), &rSet ),
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir 	pFontList( NULL )
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir {
60*cdf0e10cSrcweir 	FreeResource();
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir 	AddTabPage( RID_SVXPAGE_CHAR_NAME, SvxCharNamePage::Create, 0 );
63*cdf0e10cSrcweir 	AddTabPage( RID_SVXPAGE_CHAR_EFFECTS, SvxCharEffectsPage::Create, 0 );
64*cdf0e10cSrcweir 	AddTabPage( RID_SVXPAGE_CHAR_POSITION, SvxCharPositionPage::Create, 0 );
65*cdf0e10cSrcweir 	AddTabPage( RID_SVXPAGE_CHAR_TWOLINES, SvxCharTwoLinesPage::Create, 0 );
66*cdf0e10cSrcweir 	AddTabPage( RID_SVXPAGE_STD_PARAGRAPH, SvxStdParagraphTabPage::Create, 0 );
67*cdf0e10cSrcweir 	AddTabPage( RID_SVXPAGE_ALIGN_PARAGRAPH, SvxParaAlignTabPage::Create, 0 );
68*cdf0e10cSrcweir 	AddTabPage( RID_SVXPAGE_EXT_PARAGRAPH, SvxExtParagraphTabPage::Create, 0 );
69*cdf0e10cSrcweir 	AddTabPage( RID_SVXPAGE_PARA_ASIAN, SvxAsianTabPage::Create, 0 );
70*cdf0e10cSrcweir 	AddTabPage( RID_SVXPAGE_BACKGROUND, SvxBackgroundTabPage::Create, 0 );
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir 	// remove asian tabpages if necessary
73*cdf0e10cSrcweir     SvtCJKOptions aCJKOptions;
74*cdf0e10cSrcweir     if ( !aCJKOptions.IsDoubleLinesEnabled() )
75*cdf0e10cSrcweir         RemoveTabPage( RID_SVXPAGE_CHAR_TWOLINES );
76*cdf0e10cSrcweir     if ( !aCJKOptions.IsAsianTypographyEnabled() )
77*cdf0e10cSrcweir 		RemoveTabPage( RID_SVXPAGE_PARA_ASIAN );
78*cdf0e10cSrcweir }
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir // -----------------------------------------------------------------------
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir SvxSearchFormatDialog::~SvxSearchFormatDialog()
83*cdf0e10cSrcweir {
84*cdf0e10cSrcweir 	delete pFontList;
85*cdf0e10cSrcweir }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir // -----------------------------------------------------------------------
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir void SvxSearchFormatDialog::PageCreated( sal_uInt16 nId, SfxTabPage& rPage )
90*cdf0e10cSrcweir {
91*cdf0e10cSrcweir 	switch ( nId )
92*cdf0e10cSrcweir 	{
93*cdf0e10cSrcweir         case RID_SVXPAGE_CHAR_NAME:
94*cdf0e10cSrcweir 		{
95*cdf0e10cSrcweir 			const FontList*	pAppFontList = 0;
96*cdf0e10cSrcweir 			SfxObjectShell* pSh = SfxObjectShell::Current();
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 			if ( pSh )
99*cdf0e10cSrcweir 			{
100*cdf0e10cSrcweir 				const SvxFontListItem* pFLItem = (const SvxFontListItem*)
101*cdf0e10cSrcweir 					pSh->GetItem( SID_ATTR_CHAR_FONTLIST );
102*cdf0e10cSrcweir 				if ( pFLItem )
103*cdf0e10cSrcweir 					pAppFontList = pFLItem->GetFontList();
104*cdf0e10cSrcweir 			}
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir 			const FontList* pList = pAppFontList;
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 			if ( !pList )
109*cdf0e10cSrcweir 			{
110*cdf0e10cSrcweir 				if ( !pFontList )
111*cdf0e10cSrcweir 					pFontList = new FontList( this );
112*cdf0e10cSrcweir 				pList = pFontList;
113*cdf0e10cSrcweir 			}
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 			if ( pList )
116*cdf0e10cSrcweir                 ( (SvxCharNamePage&)rPage ).
117*cdf0e10cSrcweir                     SetFontList( SvxFontListItem( pList, SID_ATTR_CHAR_FONTLIST ) );
118*cdf0e10cSrcweir             ( (SvxCharNamePage&)rPage ).EnableSearchMode();
119*cdf0e10cSrcweir 			break;
120*cdf0e10cSrcweir 		}
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 		case RID_SVXPAGE_STD_PARAGRAPH:
123*cdf0e10cSrcweir 			( (SvxStdParagraphTabPage&)rPage ).EnableAutoFirstLine();
124*cdf0e10cSrcweir 			break;
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir 		case RID_SVXPAGE_ALIGN_PARAGRAPH:
127*cdf0e10cSrcweir 			( (SvxParaAlignTabPage&)rPage ).EnableJustifyExt();
128*cdf0e10cSrcweir 			break;
129*cdf0e10cSrcweir 		case RID_SVXPAGE_BACKGROUND :
130*cdf0e10cSrcweir 			( (SvxBackgroundTabPage&)rPage ).ShowParaControl(sal_True);
131*cdf0e10cSrcweir 			break;
132*cdf0e10cSrcweir 	}
133*cdf0e10cSrcweir }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir // class SvxSearchFormatDialog -------------------------------------------
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir SvxSearchAttributeDialog::SvxSearchAttributeDialog( Window* pParent,
138*cdf0e10cSrcweir 													SearchAttrItemList& rLst,
139*cdf0e10cSrcweir 													const sal_uInt16* pWhRanges ) :
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 	ModalDialog( pParent, CUI_RES( RID_SVXDLG_SEARCHATTR )  ),
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir     aAttrFL ( this, CUI_RES( FL_ATTR ) ),
144*cdf0e10cSrcweir     aAttrLB ( this, CUI_RES( LB_ATTR ) ),
145*cdf0e10cSrcweir     aOKBtn  ( this, CUI_RES( BTN_ATTR_OK ) ),
146*cdf0e10cSrcweir 	aEscBtn	( this, CUI_RES( BTN_ATTR_CANCEL ) ),
147*cdf0e10cSrcweir 	aHelpBtn( this, CUI_RES( BTN_ATTR_HELP ) ),
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir 	rList( rLst )
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir {
152*cdf0e10cSrcweir 	FreeResource();
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 	aAttrLB.SetStyle( GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL | WB_SORT );
155*cdf0e10cSrcweir 	aAttrLB.GetModel()->SetSortMode( SortAscending );
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 	aOKBtn.SetClickHdl( LINK( this, SvxSearchAttributeDialog, OKHdl ) );
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 	SfxObjectShell* pSh = SfxObjectShell::Current();
160*cdf0e10cSrcweir 	DBG_ASSERT( pSh, "No DocShell" );
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir     ResStringArray aAttrNames( SVX_RES( RID_ATTR_NAMES ) );
163*cdf0e10cSrcweir 	SfxItemPool& rPool = pSh->GetPool();
164*cdf0e10cSrcweir 	SfxItemSet aSet( rPool, pWhRanges );
165*cdf0e10cSrcweir 	SfxWhichIter aIter( aSet );
166*cdf0e10cSrcweir 	sal_uInt16 nWhich = aIter.FirstWhich();
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 	while ( nWhich )
169*cdf0e10cSrcweir 	{
170*cdf0e10cSrcweir 		sal_uInt16 nSlot = rPool.GetSlotId( nWhich );
171*cdf0e10cSrcweir 		if ( nSlot >= SID_SVX_START )
172*cdf0e10cSrcweir 		{
173*cdf0e10cSrcweir 			sal_Bool bChecked = sal_False, bFound = sal_False;
174*cdf0e10cSrcweir 			for ( sal_uInt16 i = 0; !bFound && i < rList.Count(); ++i )
175*cdf0e10cSrcweir 			{
176*cdf0e10cSrcweir 				if ( nSlot == rList[i].nSlot )
177*cdf0e10cSrcweir 				{
178*cdf0e10cSrcweir 					bFound = sal_True;
179*cdf0e10cSrcweir 					if ( IsInvalidItem( rList[i].pItem ) )
180*cdf0e10cSrcweir 						bChecked = sal_True;
181*cdf0e10cSrcweir 				}
182*cdf0e10cSrcweir 			}
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir 			// item resources are in svx
185*cdf0e10cSrcweir 		    sal_uInt32 nId  = aAttrNames.FindIndex( nSlot );
186*cdf0e10cSrcweir 			SvLBoxEntry* pEntry = NULL;
187*cdf0e10cSrcweir 		    if ( RESARRAY_INDEX_NOTFOUND != nId )
188*cdf0e10cSrcweir 				pEntry = aAttrLB.SvTreeListBox::InsertEntry( aAttrNames.GetString(nId) );
189*cdf0e10cSrcweir 			else
190*cdf0e10cSrcweir 			{
191*cdf0e10cSrcweir 				ByteString sError( "no resource for slot id\nslot = " );
192*cdf0e10cSrcweir 				sError += ByteString::CreateFromInt32( nSlot );
193*cdf0e10cSrcweir 				DBG_ERRORFILE( sError.GetBuffer() );
194*cdf0e10cSrcweir 			}
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir 			if ( pEntry )
197*cdf0e10cSrcweir 			{
198*cdf0e10cSrcweir 				aAttrLB.SetCheckButtonState( pEntry, bChecked ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
199*cdf0e10cSrcweir 				pEntry->SetUserData( (void*)(sal_uLong)nSlot );
200*cdf0e10cSrcweir 			}
201*cdf0e10cSrcweir 		}
202*cdf0e10cSrcweir 		nWhich = aIter.NextWhich();
203*cdf0e10cSrcweir 	}
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir 	aAttrLB.SetHighlightRange();
206*cdf0e10cSrcweir 	aAttrLB.SelectEntryPos( 0 );
207*cdf0e10cSrcweir }
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir // -----------------------------------------------------------------------
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir IMPL_LINK( SvxSearchAttributeDialog, OKHdl, Button *, EMPTYARG )
212*cdf0e10cSrcweir {
213*cdf0e10cSrcweir 	SearchAttrItem aInvalidItem;
214*cdf0e10cSrcweir 	aInvalidItem.pItem = (SfxPoolItem*)-1;
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < aAttrLB.GetEntryCount(); ++i )
217*cdf0e10cSrcweir 	{
218*cdf0e10cSrcweir 		sal_uInt16 nSlot = (sal_uInt16)(sal_uLong)aAttrLB.GetEntryData(i);
219*cdf0e10cSrcweir 		sal_Bool bChecked = aAttrLB.IsChecked(i);
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 		sal_uInt16 j;
222*cdf0e10cSrcweir 		for ( j = rList.Count(); j; )
223*cdf0e10cSrcweir 		{
224*cdf0e10cSrcweir 			SearchAttrItem& rItem = rList[ --j ];
225*cdf0e10cSrcweir 			if( rItem.nSlot == nSlot )
226*cdf0e10cSrcweir 			{
227*cdf0e10cSrcweir 				if( bChecked )
228*cdf0e10cSrcweir 				{
229*cdf0e10cSrcweir 					if( !IsInvalidItem( rItem.pItem ) )
230*cdf0e10cSrcweir 						delete rItem.pItem;
231*cdf0e10cSrcweir 					rItem.pItem = (SfxPoolItem*)-1;
232*cdf0e10cSrcweir 				}
233*cdf0e10cSrcweir 				else if( IsInvalidItem( rItem.pItem ) )
234*cdf0e10cSrcweir 					rItem.pItem = 0;
235*cdf0e10cSrcweir 				j = 1;
236*cdf0e10cSrcweir 				break;
237*cdf0e10cSrcweir 			}
238*cdf0e10cSrcweir 		}
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir 		if ( !j && bChecked )
241*cdf0e10cSrcweir 		{
242*cdf0e10cSrcweir 			aInvalidItem.nSlot = nSlot;
243*cdf0e10cSrcweir 			rList.Insert( aInvalidItem );
244*cdf0e10cSrcweir 		}
245*cdf0e10cSrcweir 	}
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 	// remove invalid items (pItem == NULL)
248*cdf0e10cSrcweir 	for ( sal_uInt16 n = rList.Count(); n; )
249*cdf0e10cSrcweir 		if ( !rList[ --n ].pItem )
250*cdf0e10cSrcweir 			rList.Remove( n );
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir 	EndDialog( RET_OK );
253*cdf0e10cSrcweir 	return 0;
254*cdf0e10cSrcweir }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir // class SvxSearchSimilarityDialog ---------------------------------------
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir SvxSearchSimilarityDialog::SvxSearchSimilarityDialog
259*cdf0e10cSrcweir (
260*cdf0e10cSrcweir 	Window* pParent,
261*cdf0e10cSrcweir 	sal_Bool bRelax,
262*cdf0e10cSrcweir 	sal_uInt16 nOther,
263*cdf0e10cSrcweir 	sal_uInt16 nShorter,
264*cdf0e10cSrcweir 	sal_uInt16 nLonger
265*cdf0e10cSrcweir ) :
266*cdf0e10cSrcweir 	ModalDialog( pParent, CUI_RES( RID_SVXDLG_SEARCHSIMILARITY ) ),
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir     aFixedLine  ( this, CUI_RES( FL_SIMILARITY ) ),
269*cdf0e10cSrcweir     aOtherTxt   ( this, CUI_RES( FT_OTHER ) ),
270*cdf0e10cSrcweir 	aOtherFld	( this, CUI_RES( NF_OTHER	) ),
271*cdf0e10cSrcweir     aLongerTxt  ( this, CUI_RES( FT_LONGER ) ),
272*cdf0e10cSrcweir     aLongerFld  ( this, CUI_RES( NF_LONGER ) ),
273*cdf0e10cSrcweir     aShorterTxt ( this, CUI_RES( FT_SHORTER ) ),
274*cdf0e10cSrcweir 	aShorterFld	( this, CUI_RES( NF_SHORTER ) ),
275*cdf0e10cSrcweir     aRelaxBox   ( this, CUI_RES( CB_RELAX ) ),
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir 	aOKBtn		( this, CUI_RES( BTN_ATTR_OK ) ),
278*cdf0e10cSrcweir 	aEscBtn		( this, CUI_RES( BTN_ATTR_CANCEL ) ),
279*cdf0e10cSrcweir 	aHelpBtn	( this, CUI_RES( BTN_ATTR_HELP ) )
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir {
282*cdf0e10cSrcweir 	FreeResource();
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir 	aOtherFld.SetValue( nOther );
285*cdf0e10cSrcweir 	aShorterFld.SetValue( nShorter );
286*cdf0e10cSrcweir 	aLongerFld.SetValue( nLonger );
287*cdf0e10cSrcweir 	aRelaxBox.Check( bRelax );
288*cdf0e10cSrcweir }
289*cdf0e10cSrcweir 
290