xref: /AOO41X/main/svtools/workben/stest.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_svtools.hxx"
30*cdf0e10cSrcweir #include <svtools/svmedit.hxx>
31*cdf0e10cSrcweir #include <txtcmp.hxx>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #ifndef _SV_BUTTON_HXX //autogen
34*cdf0e10cSrcweir #include <vcl/button.hxx>
35*cdf0e10cSrcweir #endif
36*cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
37*cdf0e10cSrcweir #include <vcl/fixed.hxx>
38*cdf0e10cSrcweir #include <vcl/svapp.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir class MyApp : public Application
41*cdf0e10cSrcweir {
42*cdf0e10cSrcweir public:
43*cdf0e10cSrcweir 	virtual void Main( );
44*cdf0e10cSrcweir };
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir class SearchWindow : public WorkWindow
47*cdf0e10cSrcweir {
48*cdf0e10cSrcweir 	PushButton		aPB;
49*cdf0e10cSrcweir 	FixedText 		aFT1, aFT2, aFT3;
50*cdf0e10cSrcweir 	MultiLineEdit 	aEText, aESrch;
51*cdf0e10cSrcweir 	RadioButton 	aModeN, aModeR, aModeL;
52*cdf0e10cSrcweir 	SearchParam 	aParam;
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir public:
55*cdf0e10cSrcweir 					SearchWindow();
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir 	DECL_LINK( ClickHdl, Button * );
58*cdf0e10cSrcweir };
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir // --- SearchWindow::SearchWindow() ------------------------------------
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir SearchWindow::SearchWindow() :
63*cdf0e10cSrcweir 				WorkWindow( NULL, WinBits( WB_APP | WB_STDWORK )),
64*cdf0e10cSrcweir 	aPB( this, WinBits( 0 )),
65*cdf0e10cSrcweir 	aFT1( this, WinBits( 0 )),
66*cdf0e10cSrcweir 	aFT2( this, WinBits( 0 )),
67*cdf0e10cSrcweir 	aFT3( this, WinBits( 0 )),
68*cdf0e10cSrcweir 	aEText( this, WinBits( WB_BORDER )),
69*cdf0e10cSrcweir 	aESrch( this, WinBits( WB_BORDER )),
70*cdf0e10cSrcweir 	aModeN( this, WinBits( 0 )),
71*cdf0e10cSrcweir 	aModeR( this, WinBits( 0 )),
72*cdf0e10cSrcweir 	aModeL( this, WinBits( 0 )),
73*cdf0e10cSrcweir 	aParam( "" )
74*cdf0e10cSrcweir {
75*cdf0e10cSrcweir 	aPB.SetClickHdl( LINK( this, SearchWindow, ClickHdl ));
76*cdf0e10cSrcweir 	aModeN.SetClickHdl( LINK( this, SearchWindow, ClickHdl ));
77*cdf0e10cSrcweir 	aModeR.SetClickHdl( LINK( this, SearchWindow, ClickHdl ));
78*cdf0e10cSrcweir 	aModeL.SetClickHdl( LINK( this, SearchWindow, ClickHdl ));
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 	SetMapMode( MapMode( MAP_APPFONT ));
81*cdf0e10cSrcweir 	SetSizePixel( LogicToPixel( Size( 300, 180 ) ) );
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir 	aEText.SetPosSizePixel( LogicToPixel( Point( 0, 22 )), LogicToPixel(Size( 270, 32 )) );
84*cdf0e10cSrcweir 	aFT1.SetPosSizePixel( LogicToPixel( Point( 0, 10 )), LogicToPixel(Size( 18, 11 )) );
85*cdf0e10cSrcweir 	aFT2.SetPosSizePixel( LogicToPixel( Point( 0, 60 )), LogicToPixel(Size( 24, 10 )) );
86*cdf0e10cSrcweir 	aESrch.SetPosSizePixel( LogicToPixel( Point( 0, 70 )), LogicToPixel(Size( 270, 24 )) );
87*cdf0e10cSrcweir 	aPB.SetPosSizePixel( LogicToPixel( Point( 223, 139 )), LogicToPixel(Size( 48, 12 )) );
88*cdf0e10cSrcweir 	aFT3.SetPosSizePixel( LogicToPixel( Point( 0, 104 )), LogicToPixel(Size( 270, 15 )) );
89*cdf0e10cSrcweir 	aModeN.SetPosSizePixel( LogicToPixel( Point( 5, 116 ) ), LogicToPixel( Size( 40, 12 ) ) );
90*cdf0e10cSrcweir 	aModeR.SetPosSizePixel( LogicToPixel( Point( 5, 126 ) ), LogicToPixel( Size( 40, 12 ) ) );
91*cdf0e10cSrcweir 	aModeL.SetPosSizePixel( LogicToPixel( Point( 5, 136 ) ), LogicToPixel( Size( 40, 12 ) ) );
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 	aEText.Show();
94*cdf0e10cSrcweir 	aFT1.Show();
95*cdf0e10cSrcweir 	aFT2.Show();
96*cdf0e10cSrcweir 	aESrch.Show();
97*cdf0e10cSrcweir 	aPB.Show();
98*cdf0e10cSrcweir 	aFT3.Show();
99*cdf0e10cSrcweir 	aModeN.Show();
100*cdf0e10cSrcweir 	aModeR.Show();
101*cdf0e10cSrcweir 	aModeL.Show();
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 	aFT3.SetText( "gefunden:" );
104*cdf0e10cSrcweir 	aFT1.SetText( "Text:" );
105*cdf0e10cSrcweir 	aFT2.SetText( "Suche:" );
106*cdf0e10cSrcweir 	aPB.SetText( "starte Suche" );
107*cdf0e10cSrcweir 	aModeN.SetText( "normal" );
108*cdf0e10cSrcweir 	aModeR.SetText( "RegExp" );
109*cdf0e10cSrcweir 	aModeL.SetText( "LevDis" );
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir 	SetText( "Such-Demo" );
112*cdf0e10cSrcweir }
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir // --- SearchWindow::SearchSelectHdl() ---------------------------------
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir IMPL_LINK( SearchWindow, ClickHdl, Button *, pButton )
118*cdf0e10cSrcweir {
119*cdf0e10cSrcweir 	if( pButton == &aPB )
120*cdf0e10cSrcweir 	{
121*cdf0e10cSrcweir 		String sText( aEText.GetText() );
122*cdf0e10cSrcweir 		String sSrch( aESrch.GetText() );
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir /*		InfoBox( this, String( "T: " ) + sText +
125*cdf0e10cSrcweir 					   String( "\nS: " ) + sSrch ).Execute();
126*cdf0e10cSrcweir */
127*cdf0e10cSrcweir 		sal_Bool bRet = sal_False;
128*cdf0e10cSrcweir 		sal_uInt16 nStt = 0, nEnd = sText.Len();
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 		{
131*cdf0e10cSrcweir 			aParam.SetSrchStr( sSrch );
132*cdf0e10cSrcweir 			SearchText aSrchText( aParam, GetpApp()->GetAppInternational() );
133*cdf0e10cSrcweir 			bRet = aSrchText.SearchFrwrd( sText, &nStt, &nEnd );
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir //			sal_Bool SearchBkwrd( const String &rStr, sal_uInt16* pStart, sal_uInt16* pEnde );
136*cdf0e10cSrcweir 		}
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 		String sFound( "gefunden" );
139*cdf0e10cSrcweir 		if( !bRet )
140*cdf0e10cSrcweir 			sFound.Insert( "nicht ", 0 );
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 		sFound += ": S<";
143*cdf0e10cSrcweir 		sFound += nStt;
144*cdf0e10cSrcweir 		sFound += "> E<";
145*cdf0e10cSrcweir 		sFound += nEnd;
146*cdf0e10cSrcweir 		sFound += '>';
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 		if( bRet )
149*cdf0e10cSrcweir 		{
150*cdf0e10cSrcweir 			sFound += '<';
151*cdf0e10cSrcweir 			sFound += sText.Copy( nStt, nEnd - nStt +1 );
152*cdf0e10cSrcweir 			sFound += '>';
153*cdf0e10cSrcweir 		}
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 		aFT3.SetText( sFound );
156*cdf0e10cSrcweir 	}
157*cdf0e10cSrcweir 	else if( pButton == &aModeN )
158*cdf0e10cSrcweir 	{
159*cdf0e10cSrcweir 		aParam.SetSrchType( SearchParam::SRCH_NORMAL );
160*cdf0e10cSrcweir 	}
161*cdf0e10cSrcweir 	else if( pButton == &aModeR )
162*cdf0e10cSrcweir 	{
163*cdf0e10cSrcweir 		aParam.SetSrchType( SearchParam::SRCH_REGEXP );
164*cdf0e10cSrcweir 	}
165*cdf0e10cSrcweir 	else if( pButton == &aModeL )
166*cdf0e10cSrcweir 	{
167*cdf0e10cSrcweir 		aParam.SetSrchType( SearchParam::SRCH_LEVDIST );
168*cdf0e10cSrcweir 	}
169*cdf0e10cSrcweir 	return 0;
170*cdf0e10cSrcweir }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir // --- MyApp::Main() -----------------------------------------------
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir void MyApp::Main( )
176*cdf0e10cSrcweir {
177*cdf0e10cSrcweir 	SearchWindow*	pSearchWindow = new SearchWindow;
178*cdf0e10cSrcweir 	pSearchWindow->Show();
179*cdf0e10cSrcweir 	Execute();
180*cdf0e10cSrcweir 	delete pSearchWindow;
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir // --- aMyApp ------------------------------------------------------
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir MyApp aMyApp;
187