merge the formfield patch from ooo-build
[ooovba.git] / svx / source / cui / srchxtra.cxx
blobae5f2d7365bb72c1d21d01e2bd6e6567cb5b4d18
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: srchxtra.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
36 #endif
38 // include ---------------------------------------------------------------
40 #include "srchxtra.hxx"
41 #include <tools/rcid.h>
42 #include <vcl/msgbox.hxx>
43 #include <svtools/cjkoptions.hxx>
44 #include <svtools/whiter.hxx>
45 #include <sfx2/objsh.hxx>
47 #ifndef _SVX_DIALOGS_HRC
48 #include <svx/dialogs.hrc>
49 #endif
50 #ifndef _SVX_SRCHXTRA_HRC
51 #include "srchxtra.hrc"
52 #endif
53 #ifndef _SVXITEMS_HRC
54 #include <svx/svxitems.hrc>
55 #endif
57 #ifndef _SVX_FLSTITEM_HXX
59 #include "flstitem.hxx"
60 #endif
61 #include "chardlg.hxx"
62 #include "paragrph.hxx"
63 #include <svx/dialmgr.hxx>
64 #include "backgrnd.hxx"
66 // class SvxSearchFormatDialog -------------------------------------------
68 SvxSearchFormatDialog::SvxSearchFormatDialog( Window* pParent, const SfxItemSet& rSet ) :
70 SfxTabDialog( pParent, SVX_RES( RID_SVXDLG_SEARCHFORMAT ), &rSet ),
72 pFontList( NULL )
75 FreeResource();
77 AddTabPage( RID_SVXPAGE_CHAR_NAME, SvxCharNamePage::Create, 0 );
78 AddTabPage( RID_SVXPAGE_CHAR_EFFECTS, SvxCharEffectsPage::Create, 0 );
79 AddTabPage( RID_SVXPAGE_CHAR_POSITION, SvxCharPositionPage::Create, 0 );
80 AddTabPage( RID_SVXPAGE_CHAR_TWOLINES, SvxCharTwoLinesPage::Create, 0 );
81 AddTabPage( RID_SVXPAGE_STD_PARAGRAPH, SvxStdParagraphTabPage::Create, 0 );
82 AddTabPage( RID_SVXPAGE_ALIGN_PARAGRAPH, SvxParaAlignTabPage::Create, 0 );
83 AddTabPage( RID_SVXPAGE_EXT_PARAGRAPH, SvxExtParagraphTabPage::Create, 0 );
84 AddTabPage( RID_SVXPAGE_PARA_ASIAN, SvxAsianTabPage::Create, 0 );
85 AddTabPage( RID_SVXPAGE_BACKGROUND, SvxBackgroundTabPage::Create, 0 );
87 // remove asian tabpages if necessary
88 SvtCJKOptions aCJKOptions;
89 if ( !aCJKOptions.IsDoubleLinesEnabled() )
90 RemoveTabPage( RID_SVXPAGE_CHAR_TWOLINES );
91 if ( !aCJKOptions.IsAsianTypographyEnabled() )
92 RemoveTabPage( RID_SVXPAGE_PARA_ASIAN );
95 // -----------------------------------------------------------------------
97 SvxSearchFormatDialog::~SvxSearchFormatDialog()
99 delete pFontList;
102 // -----------------------------------------------------------------------
104 void SvxSearchFormatDialog::PageCreated( USHORT nId, SfxTabPage& rPage )
106 switch ( nId )
108 case RID_SVXPAGE_CHAR_NAME:
110 const FontList* pAppFontList = 0;
111 SfxObjectShell* pSh = SfxObjectShell::Current();
113 if ( pSh )
115 const SvxFontListItem* pFLItem = (const SvxFontListItem*)
116 pSh->GetItem( SID_ATTR_CHAR_FONTLIST );
117 if ( pFLItem )
118 pAppFontList = pFLItem->GetFontList();
121 const FontList* pList = pAppFontList;
123 if ( !pList )
125 if ( !pFontList )
126 pFontList = new FontList( this );
127 pList = pFontList;
130 if ( pList )
131 ( (SvxCharNamePage&)rPage ).
132 SetFontList( SvxFontListItem( pList, SID_ATTR_CHAR_FONTLIST ) );
133 ( (SvxCharNamePage&)rPage ).EnableSearchMode();
134 break;
137 case RID_SVXPAGE_STD_PARAGRAPH:
138 ( (SvxStdParagraphTabPage&)rPage ).EnableAutoFirstLine();
139 break;
141 case RID_SVXPAGE_ALIGN_PARAGRAPH:
142 ( (SvxParaAlignTabPage&)rPage ).EnableJustifyExt();
143 break;
144 case RID_SVXPAGE_BACKGROUND :
145 ( (SvxBackgroundTabPage&)rPage ).ShowParaControl(TRUE);
146 break;
150 // class SvxSearchFormatDialog -------------------------------------------
152 SvxSearchAttributeDialog::SvxSearchAttributeDialog( Window* pParent,
153 SearchAttrItemList& rLst,
154 const USHORT* pWhRanges ) :
156 ModalDialog( pParent, SVX_RES( RID_SVXDLG_SEARCHATTR ) ),
158 aAttrFL ( this, SVX_RES( FL_ATTR ) ),
159 aAttrLB ( this, SVX_RES( LB_ATTR ) ),
160 aOKBtn ( this, SVX_RES( BTN_ATTR_OK ) ),
161 aEscBtn ( this, SVX_RES( BTN_ATTR_CANCEL ) ),
162 aHelpBtn( this, SVX_RES( BTN_ATTR_HELP ) ),
164 rList( rLst )
167 FreeResource();
169 aAttrLB.SetWindowBits( GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL | WB_SORT );
170 aAttrLB.GetModel()->SetSortMode( SortAscending );
172 aOKBtn.SetClickHdl( LINK( this, SvxSearchAttributeDialog, OKHdl ) );
174 SfxObjectShell* pSh = SfxObjectShell::Current();
175 DBG_ASSERT( pSh, "No DocShell" );
177 SfxItemPool& rPool = pSh->GetPool();
178 SfxItemSet aSet( rPool, pWhRanges );
179 SfxWhichIter aIter( aSet );
180 USHORT nWhich = aIter.FirstWhich();
182 while ( nWhich )
184 USHORT nSlot = rPool.GetSlotId( nWhich );
185 if ( nSlot >= SID_SVX_START )
187 BOOL bChecked = FALSE, bFound = FALSE;
188 for ( USHORT i = 0; !bFound && i < rList.Count(); ++i )
190 if ( nSlot == rList[i].nSlot )
192 bFound = TRUE;
193 if ( IsInvalidItem( rList[i].pItem ) )
194 bChecked = TRUE;
198 USHORT nResId = nSlot - SID_SVX_START + RID_ATTR_BEGIN;
199 SvLBoxEntry* pEntry = NULL;
200 ResId aId( nResId, DIALOG_MGR() );
201 aId.SetRT( RSC_STRING );
202 if ( DIALOG_MGR().IsAvailable( aId ) )
203 pEntry = aAttrLB.SvTreeListBox::InsertEntry( SVX_RESSTR( nResId ) );
204 else
206 ByteString sError( "no resource for slot id\nslot = " );
207 sError += ByteString::CreateFromInt32( nSlot );
208 sError += ByteString( "\nresid = " );
209 sError += ByteString::CreateFromInt32( nResId );
210 DBG_ERRORFILE( sError.GetBuffer() );
213 if ( pEntry )
215 aAttrLB.SetCheckButtonState( pEntry, bChecked ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
216 pEntry->SetUserData( (void*)(ULONG)nSlot );
219 nWhich = aIter.NextWhich();
222 aAttrLB.SetHighlightRange();
223 aAttrLB.SelectEntryPos( 0 );
226 // -----------------------------------------------------------------------
228 IMPL_LINK( SvxSearchAttributeDialog, OKHdl, Button *, EMPTYARG )
230 SearchAttrItem aInvalidItem;
231 aInvalidItem.pItem = (SfxPoolItem*)-1;
233 for ( USHORT i = 0; i < aAttrLB.GetEntryCount(); ++i )
235 USHORT nSlot = (USHORT)(ULONG)aAttrLB.GetEntryData(i);
236 BOOL bChecked = aAttrLB.IsChecked(i);
238 USHORT j;
239 for ( j = rList.Count(); j; )
241 SearchAttrItem& rItem = rList[ --j ];
242 if( rItem.nSlot == nSlot )
244 if( bChecked )
246 if( !IsInvalidItem( rItem.pItem ) )
247 delete rItem.pItem;
248 rItem.pItem = (SfxPoolItem*)-1;
250 else if( IsInvalidItem( rItem.pItem ) )
251 rItem.pItem = 0;
252 j = 1;
253 break;
257 if ( !j && bChecked )
259 aInvalidItem.nSlot = nSlot;
260 rList.Insert( aInvalidItem );
264 // remove invalid items (pItem == NULL)
265 for ( USHORT n = rList.Count(); n; )
266 if ( !rList[ --n ].pItem )
267 rList.Remove( n );
269 EndDialog( RET_OK );
270 return 0;
273 // class SvxSearchSimilarityDialog ---------------------------------------
275 SvxSearchSimilarityDialog::SvxSearchSimilarityDialog
277 Window* pParent,
278 BOOL bRelax,
279 USHORT nOther,
280 USHORT nShorter,
281 USHORT nLonger
283 ModalDialog( pParent, SVX_RES( RID_SVXDLG_SEARCHSIMILARITY ) ),
285 aFixedLine ( this, SVX_RES( FL_SIMILARITY ) ),
286 aOtherTxt ( this, SVX_RES( FT_OTHER ) ),
287 aOtherFld ( this, SVX_RES( NF_OTHER ) ),
288 aLongerTxt ( this, SVX_RES( FT_LONGER ) ),
289 aLongerFld ( this, SVX_RES( NF_LONGER ) ),
290 aShorterTxt ( this, SVX_RES( FT_SHORTER ) ),
291 aShorterFld ( this, SVX_RES( NF_SHORTER ) ),
292 aRelaxBox ( this, SVX_RES( CB_RELAX ) ),
294 aOKBtn ( this, SVX_RES( BTN_ATTR_OK ) ),
295 aEscBtn ( this, SVX_RES( BTN_ATTR_CANCEL ) ),
296 aHelpBtn ( this, SVX_RES( BTN_ATTR_HELP ) )
299 FreeResource();
301 aOtherFld.SetValue( nOther );
302 aShorterFld.SetValue( nShorter );
303 aLongerFld.SetValue( nLonger );
304 aRelaxBox.Check( bRelax );