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