xref: /trunk/main/svtools/workben/stest.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svtools.hxx"
30 #include <svtools/svmedit.hxx>
31 #include <txtcmp.hxx>
32 
33 #ifndef _SV_BUTTON_HXX //autogen
34 #include <vcl/button.hxx>
35 #endif
36 #include <vcl/wrkwin.hxx>
37 #include <vcl/fixed.hxx>
38 #include <vcl/svapp.hxx>
39 
40 class MyApp : public Application
41 {
42 public:
43     virtual void Main( );
44 };
45 
46 class SearchWindow : public WorkWindow
47 {
48     PushButton      aPB;
49     FixedText       aFT1, aFT2, aFT3;
50     MultiLineEdit   aEText, aESrch;
51     RadioButton     aModeN, aModeR, aModeL;
52     SearchParam     aParam;
53 
54 public:
55                     SearchWindow();
56 
57     DECL_LINK( ClickHdl, Button * );
58 };
59 
60 // --- SearchWindow::SearchWindow() ------------------------------------
61 
62 SearchWindow::SearchWindow() :
63                 WorkWindow( NULL, WinBits( WB_APP | WB_STDWORK )),
64     aPB( this, WinBits( 0 )),
65     aFT1( this, WinBits( 0 )),
66     aFT2( this, WinBits( 0 )),
67     aFT3( this, WinBits( 0 )),
68     aEText( this, WinBits( WB_BORDER )),
69     aESrch( this, WinBits( WB_BORDER )),
70     aModeN( this, WinBits( 0 )),
71     aModeR( this, WinBits( 0 )),
72     aModeL( this, WinBits( 0 )),
73     aParam( "" )
74 {
75     aPB.SetClickHdl( LINK( this, SearchWindow, ClickHdl ));
76     aModeN.SetClickHdl( LINK( this, SearchWindow, ClickHdl ));
77     aModeR.SetClickHdl( LINK( this, SearchWindow, ClickHdl ));
78     aModeL.SetClickHdl( LINK( this, SearchWindow, ClickHdl ));
79 
80     SetMapMode( MapMode( MAP_APPFONT ));
81     SetSizePixel( LogicToPixel( Size( 300, 180 ) ) );
82 
83     aEText.SetPosSizePixel( LogicToPixel( Point( 0, 22 )), LogicToPixel(Size( 270, 32 )) );
84     aFT1.SetPosSizePixel( LogicToPixel( Point( 0, 10 )), LogicToPixel(Size( 18, 11 )) );
85     aFT2.SetPosSizePixel( LogicToPixel( Point( 0, 60 )), LogicToPixel(Size( 24, 10 )) );
86     aESrch.SetPosSizePixel( LogicToPixel( Point( 0, 70 )), LogicToPixel(Size( 270, 24 )) );
87     aPB.SetPosSizePixel( LogicToPixel( Point( 223, 139 )), LogicToPixel(Size( 48, 12 )) );
88     aFT3.SetPosSizePixel( LogicToPixel( Point( 0, 104 )), LogicToPixel(Size( 270, 15 )) );
89     aModeN.SetPosSizePixel( LogicToPixel( Point( 5, 116 ) ), LogicToPixel( Size( 40, 12 ) ) );
90     aModeR.SetPosSizePixel( LogicToPixel( Point( 5, 126 ) ), LogicToPixel( Size( 40, 12 ) ) );
91     aModeL.SetPosSizePixel( LogicToPixel( Point( 5, 136 ) ), LogicToPixel( Size( 40, 12 ) ) );
92 
93     aEText.Show();
94     aFT1.Show();
95     aFT2.Show();
96     aESrch.Show();
97     aPB.Show();
98     aFT3.Show();
99     aModeN.Show();
100     aModeR.Show();
101     aModeL.Show();
102 
103     aFT3.SetText( "gefunden:" );
104     aFT1.SetText( "Text:" );
105     aFT2.SetText( "Suche:" );
106     aPB.SetText( "starte Suche" );
107     aModeN.SetText( "normal" );
108     aModeR.SetText( "RegExp" );
109     aModeL.SetText( "LevDis" );
110 
111     SetText( "Such-Demo" );
112 }
113 
114 
115 // --- SearchWindow::SearchSelectHdl() ---------------------------------
116 
117 IMPL_LINK( SearchWindow, ClickHdl, Button *, pButton )
118 {
119     if( pButton == &aPB )
120     {
121         String sText( aEText.GetText() );
122         String sSrch( aESrch.GetText() );
123 
124 /*      InfoBox( this, String( "T: " ) + sText +
125                        String( "\nS: " ) + sSrch ).Execute();
126 */
127         sal_Bool bRet = sal_False;
128         sal_uInt16 nStt = 0, nEnd = sText.Len();
129 
130         {
131             aParam.SetSrchStr( sSrch );
132             SearchText aSrchText( aParam, GetpApp()->GetAppInternational() );
133             bRet = aSrchText.SearchFrwrd( sText, &nStt, &nEnd );
134 
135 //          sal_Bool SearchBkwrd( const String &rStr, sal_uInt16* pStart, sal_uInt16* pEnde );
136         }
137 
138         String sFound( "gefunden" );
139         if( !bRet )
140             sFound.Insert( "nicht ", 0 );
141 
142         sFound += ": S<";
143         sFound += nStt;
144         sFound += "> E<";
145         sFound += nEnd;
146         sFound += '>';
147 
148         if( bRet )
149         {
150             sFound += '<';
151             sFound += sText.Copy( nStt, nEnd - nStt +1 );
152             sFound += '>';
153         }
154 
155         aFT3.SetText( sFound );
156     }
157     else if( pButton == &aModeN )
158     {
159         aParam.SetSrchType( SearchParam::SRCH_NORMAL );
160     }
161     else if( pButton == &aModeR )
162     {
163         aParam.SetSrchType( SearchParam::SRCH_REGEXP );
164     }
165     else if( pButton == &aModeL )
166     {
167         aParam.SetSrchType( SearchParam::SRCH_LEVDIST );
168     }
169     return 0;
170 }
171 
172 
173 // --- MyApp::Main() -----------------------------------------------
174 
175 void MyApp::Main( )
176 {
177     SearchWindow*   pSearchWindow = new SearchWindow;
178     pSearchWindow->Show();
179     Execute();
180     delete pSearchWindow;
181 
182 }
183 
184 // --- aMyApp ------------------------------------------------------
185 
186 MyApp aMyApp;
187