xref: /trunk/main/cui/source/dialogs/srchxtra.cxx (revision 2ee96f1c)
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 ---------------------------------------------------------------
28 
29 #include "srchxtra.hxx"
30 #include <tools/rcid.h>
31 #include <vcl/msgbox.hxx>
32 #include <svl/cjkoptions.hxx>
33 #include <svl/whiter.hxx>
34 #include <sfx2/objsh.hxx>
35 #include <cuires.hrc>
36 #include "srchxtra.hrc"
37 #include <svx/svxitems.hrc> // RID_ATTR_BEGIN
38 #include <svx/dialmgr.hxx>  // item resources
39 #include <editeng/flstitem.hxx>
40 #include "chardlg.hxx"
41 #include "paragrph.hxx"
42 #include <dialmgr.hxx>
43 #include "backgrnd.hxx"
44 #include <svx/dialogs.hrc> // RID_SVXPAGE_...
45 #include <tools/resary.hxx>
46 
47 // class SvxSearchFormatDialog -------------------------------------------
48 
SvxSearchFormatDialog(Window * pParent,const SfxItemSet & rSet)49 SvxSearchFormatDialog::SvxSearchFormatDialog( Window* pParent, const SfxItemSet& rSet ) :
50 
51 	SfxTabDialog( pParent, CUI_RES( RID_SVXDLG_SEARCHFORMAT ), &rSet ),
52 
53 	pFontList( NULL )
54 
55 {
56 	FreeResource();
57 
58 	AddTabPage( RID_SVXPAGE_CHAR_NAME, SvxCharNamePage::Create, 0 );
59 	AddTabPage( RID_SVXPAGE_CHAR_EFFECTS, SvxCharEffectsPage::Create, 0 );
60 	AddTabPage( RID_SVXPAGE_CHAR_POSITION, SvxCharPositionPage::Create, 0 );
61 	AddTabPage( RID_SVXPAGE_CHAR_TWOLINES, SvxCharTwoLinesPage::Create, 0 );
62 	AddTabPage( RID_SVXPAGE_STD_PARAGRAPH, SvxStdParagraphTabPage::Create, 0 );
63 	AddTabPage( RID_SVXPAGE_ALIGN_PARAGRAPH, SvxParaAlignTabPage::Create, 0 );
64 	AddTabPage( RID_SVXPAGE_EXT_PARAGRAPH, SvxExtParagraphTabPage::Create, 0 );
65 	AddTabPage( RID_SVXPAGE_PARA_ASIAN, SvxAsianTabPage::Create, 0 );
66 	AddTabPage( RID_SVXPAGE_BACKGROUND, SvxBackgroundTabPage::Create, 0 );
67 
68 	// remove asian tabpages if necessary
69     SvtCJKOptions aCJKOptions;
70     if ( !aCJKOptions.IsDoubleLinesEnabled() )
71         RemoveTabPage( RID_SVXPAGE_CHAR_TWOLINES );
72     if ( !aCJKOptions.IsAsianTypographyEnabled() )
73 		RemoveTabPage( RID_SVXPAGE_PARA_ASIAN );
74 }
75 
76 // -----------------------------------------------------------------------
77 
~SvxSearchFormatDialog()78 SvxSearchFormatDialog::~SvxSearchFormatDialog()
79 {
80 	delete pFontList;
81 }
82 
83 // -----------------------------------------------------------------------
84 
PageCreated(sal_uInt16 nId,SfxTabPage & rPage)85 void SvxSearchFormatDialog::PageCreated( sal_uInt16 nId, SfxTabPage& rPage )
86 {
87 	switch ( nId )
88 	{
89         case RID_SVXPAGE_CHAR_NAME:
90 		{
91 			const FontList*	pAppFontList = 0;
92 			SfxObjectShell* pSh = SfxObjectShell::Current();
93 
94 			if ( pSh )
95 			{
96 				const SvxFontListItem* pFLItem = (const SvxFontListItem*)
97 					pSh->GetItem( SID_ATTR_CHAR_FONTLIST );
98 				if ( pFLItem )
99 					pAppFontList = pFLItem->GetFontList();
100 			}
101 
102 			const FontList* pList = pAppFontList;
103 
104 			if ( !pList )
105 			{
106 				if ( !pFontList )
107 					pFontList = new FontList( this );
108 				pList = pFontList;
109 			}
110 
111 			if ( pList )
112                 ( (SvxCharNamePage&)rPage ).
113                     SetFontList( SvxFontListItem( pList, SID_ATTR_CHAR_FONTLIST ) );
114             ( (SvxCharNamePage&)rPage ).EnableSearchMode();
115 			break;
116 		}
117 
118 		case RID_SVXPAGE_STD_PARAGRAPH:
119 			( (SvxStdParagraphTabPage&)rPage ).EnableAutoFirstLine();
120 			break;
121 
122 		case RID_SVXPAGE_ALIGN_PARAGRAPH:
123 			( (SvxParaAlignTabPage&)rPage ).EnableJustifyExt();
124 			break;
125 		case RID_SVXPAGE_BACKGROUND :
126 			( (SvxBackgroundTabPage&)rPage ).ShowParaControl(sal_True);
127 			break;
128 	}
129 }
130 
131 // class SvxSearchFormatDialog -------------------------------------------
132 
SvxSearchAttributeDialog(Window * pParent,SearchAttrItemList & rLst,const sal_uInt16 * pWhRanges)133 SvxSearchAttributeDialog::SvxSearchAttributeDialog( Window* pParent,
134 													SearchAttrItemList& rLst,
135 													const sal_uInt16* pWhRanges ) :
136 
137 	ModalDialog( pParent, CUI_RES( RID_SVXDLG_SEARCHATTR )  ),
138 
139     aAttrFL ( this, CUI_RES( FL_ATTR ) ),
140     aAttrLB ( this, CUI_RES( LB_ATTR ) ),
141     aOKBtn  ( this, CUI_RES( BTN_ATTR_OK ) ),
142 	aEscBtn	( this, CUI_RES( BTN_ATTR_CANCEL ) ),
143 	aHelpBtn( this, CUI_RES( BTN_ATTR_HELP ) ),
144 
145 	rList( rLst )
146 
147 {
148 	FreeResource();
149 
150 	aAttrLB.SetStyle( GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL | WB_SORT );
151 	aAttrLB.GetModel()->SetSortMode( SortAscending );
152 
153 	aOKBtn.SetClickHdl( LINK( this, SvxSearchAttributeDialog, OKHdl ) );
154 
155 	SfxObjectShell* pSh = SfxObjectShell::Current();
156 	DBG_ASSERT( pSh, "No DocShell" );
157 
158     ResStringArray aAttrNames( SVX_RES( RID_ATTR_NAMES ) );
159 	SfxItemPool& rPool = pSh->GetPool();
160 	SfxItemSet aSet( rPool, pWhRanges );
161 	SfxWhichIter aIter( aSet );
162 	sal_uInt16 nWhich = aIter.FirstWhich();
163 
164 	while ( nWhich )
165 	{
166 		sal_uInt16 nSlot = rPool.GetSlotId( nWhich );
167 		if ( nSlot >= SID_SVX_START )
168 		{
169 			sal_Bool bChecked = sal_False, bFound = sal_False;
170 			for ( sal_uInt16 i = 0; !bFound && i < rList.Count(); ++i )
171 			{
172 				if ( nSlot == rList[i].nSlot )
173 				{
174 					bFound = sal_True;
175 					if ( IsInvalidItem( rList[i].pItem ) )
176 						bChecked = sal_True;
177 				}
178 			}
179 
180 			// item resources are in svx
181 		    sal_uInt32 nId  = aAttrNames.FindIndex( nSlot );
182 			SvLBoxEntry* pEntry = NULL;
183 		    if ( RESARRAY_INDEX_NOTFOUND != nId )
184 				pEntry = aAttrLB.SvTreeListBox::InsertEntry( aAttrNames.GetString(nId) );
185 			else
186 			{
187 				ByteString sError( "no resource for slot id\nslot = " );
188 				sError += ByteString::CreateFromInt32( nSlot );
189 				DBG_ERRORFILE( sError.GetBuffer() );
190 			}
191 
192 			if ( pEntry )
193 			{
194 				aAttrLB.SetCheckButtonState( pEntry, bChecked ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
195 				pEntry->SetUserData( (void*)(sal_uLong)nSlot );
196 			}
197 		}
198 		nWhich = aIter.NextWhich();
199 	}
200 
201 	aAttrLB.SetHighlightRange();
202 	aAttrLB.SelectEntryPos( 0 );
203 }
204 
205 // -----------------------------------------------------------------------
206 
IMPL_LINK(SvxSearchAttributeDialog,OKHdl,Button *,EMPTYARG)207 IMPL_LINK( SvxSearchAttributeDialog, OKHdl, Button *, EMPTYARG )
208 {
209 	SearchAttrItem aInvalidItem;
210 	aInvalidItem.pItem = (SfxPoolItem*)-1;
211 
212 	for ( sal_uInt16 i = 0; i < aAttrLB.GetEntryCount(); ++i )
213 	{
214 		sal_uInt16 nSlot = (sal_uInt16)(sal_uLong)aAttrLB.GetEntryData(i);
215 		sal_Bool bChecked = aAttrLB.IsChecked(i);
216 
217 		sal_uInt16 j;
218 		for ( j = rList.Count(); j; )
219 		{
220 			SearchAttrItem& rItem = rList[ --j ];
221 			if( rItem.nSlot == nSlot )
222 			{
223 				if( bChecked )
224 				{
225 					if( !IsInvalidItem( rItem.pItem ) )
226 						delete rItem.pItem;
227 					rItem.pItem = (SfxPoolItem*)-1;
228 				}
229 				else if( IsInvalidItem( rItem.pItem ) )
230 					rItem.pItem = 0;
231 				j = 1;
232 				break;
233 			}
234 		}
235 
236 		if ( !j && bChecked )
237 		{
238 			aInvalidItem.nSlot = nSlot;
239 			rList.Insert( aInvalidItem );
240 		}
241 	}
242 
243 	// remove invalid items (pItem == NULL)
244 	for ( sal_uInt16 n = rList.Count(); n; )
245 		if ( !rList[ --n ].pItem )
246 			rList.Remove( n );
247 
248 	EndDialog( RET_OK );
249 	return 0;
250 }
251 
252 // class SvxSearchSimilarityDialog ---------------------------------------
253 
SvxSearchSimilarityDialog(Window * pParent,sal_Bool bRelax,sal_uInt16 nOther,sal_uInt16 nShorter,sal_uInt16 nLonger)254 SvxSearchSimilarityDialog::SvxSearchSimilarityDialog
255 (
256 	Window* pParent,
257 	sal_Bool bRelax,
258 	sal_uInt16 nOther,
259 	sal_uInt16 nShorter,
260 	sal_uInt16 nLonger
261 ) :
262 	ModalDialog( pParent, CUI_RES( RID_SVXDLG_SEARCHSIMILARITY ) ),
263 
264     aFixedLine  ( this, CUI_RES( FL_SIMILARITY ) ),
265     aOtherTxt   ( this, CUI_RES( FT_OTHER ) ),
266 	aOtherFld	( this, CUI_RES( NF_OTHER	) ),
267     aLongerTxt  ( this, CUI_RES( FT_LONGER ) ),
268     aLongerFld  ( this, CUI_RES( NF_LONGER ) ),
269     aShorterTxt ( this, CUI_RES( FT_SHORTER ) ),
270 	aShorterFld	( this, CUI_RES( NF_SHORTER ) ),
271     aRelaxBox   ( this, CUI_RES( CB_RELAX ) ),
272 
273 	aOKBtn		( this, CUI_RES( BTN_ATTR_OK ) ),
274 	aEscBtn		( this, CUI_RES( BTN_ATTR_CANCEL ) ),
275 	aHelpBtn	( this, CUI_RES( BTN_ATTR_HELP ) )
276 
277 {
278 	FreeResource();
279 
280 	aOtherFld.SetValue( nOther );
281 	aShorterFld.SetValue( nShorter );
282 	aLongerFld.SetValue( nLonger );
283 	aRelaxBox.Check( bRelax );
284 }
285 
286