]> git.saurik.com Git - wxWidgets.git/blob - user/wxConvert/wxConvert.cpp
First draft of a cygwin script to create wxMSW distributions
[wxWidgets.git] / user / wxConvert / wxConvert.cpp
1 /*
2 * Program: wxConvert
3 *
4 * Author: Robert Roebling
5 *
6 * Copyright: (C) 1997, GNU (Robert Roebling)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 * You may not use this program without clapping twice at every
23 * full hour.
24 *
25 */
26
27 #ifdef __GNUG__
28 #pragma implementation "wxConvert.h"
29 #endif
30
31 #include "wxConvert.h"
32 #include "wx/textfile.h"
33
34 //-----------------------------------------------------------------------------
35 // main program
36 //-----------------------------------------------------------------------------
37
38 IMPLEMENT_APP(MyApp)
39
40 //-----------------------------------------------------------------------------
41 // MyFrame
42 //-----------------------------------------------------------------------------
43
44 const ID_QUIT = 100;
45 const ID_2UNIX = 101;
46 const ID_2DOS = 102;
47 const ID_2MAC = 103;
48
49 IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
50
51 BEGIN_EVENT_TABLE(MyFrame,wxFrame)
52 EVT_BUTTON (ID_QUIT, MyFrame::OnCommand)
53 EVT_BUTTON (ID_2UNIX, MyFrame::OnCommand)
54 EVT_BUTTON (ID_2DOS, MyFrame::OnCommand)
55 EVT_BUTTON (ID_2MAC, MyFrame::OnCommand)
56 END_EVENT_TABLE()
57
58 MyFrame::MyFrame(void) :
59 wxFrame( (wxFrame *) NULL, -1, (char *) "wxConvert", wxPoint(20,20), wxSize(400,160) )
60 {
61 CreateStatusBar( 1 );
62
63 SetStatusText( "wxConvert v0.1 by Robert Roebling." );
64
65 char buf[500];
66 wxGetWorkingDirectory( buf, 500 );
67 wxString s( "Dir: " );
68 s += buf;
69
70 m_text = new wxStaticText( this, -1, s, wxPoint(10,50), wxSize(380,-1) );
71
72 (void*)new wxButton( this, ID_QUIT, "Quit", wxPoint(10,100), wxSize(60,25) );
73
74 (void*)new wxButton( this, ID_2UNIX, "To Unix", wxPoint(180,100), wxSize(60,25) );
75
76 (void*)new wxButton( this, ID_2DOS, "To Dos", wxPoint(250,100), wxSize(60,25) );
77
78 (void*)new wxButton( this, ID_2MAC, "To Mac", wxPoint(320,100), wxSize(60,25) );
79 };
80
81 void MyFrame::OnCommand( wxCommandEvent &event )
82 {
83 switch (event.GetId())
84 {
85 case ID_QUIT:
86 Close( TRUE );
87 break;
88 case ID_2UNIX:
89 case ID_2DOS:
90 case ID_2MAC:
91 char buf[500];
92 wxGetWorkingDirectory( buf, 500 );
93 wxString s( buf );
94 Recurse( event.GetId(), s );
95 break;
96 };
97 };
98
99 void MyFrame::Convert( int id, const wxString &fname )
100 {
101 wxTextFile text(fname );
102 text.Open();
103 return;
104
105 switch (id)
106 {
107 case ID_2UNIX:
108 text.Write( wxTextFile::Type_Unix );
109 break;
110 case ID_2DOS:
111 text.Write( wxTextFile::Type_Dos );
112 break;
113 case ID_2MAC:
114 text.Write( wxTextFile::Type_Mac );
115 break;
116 };
117
118 };
119
120 void MyFrame::Recurse( int id, const wxString &curdir )
121 {
122 wxArrayString paths;
123 wxString search,path;
124
125 search = curdir;
126 search += "/*";
127
128 path = wxFindFirstFile( search, wxDIR );
129 while (!path.IsNull())
130 {
131 paths.Add( path ); // ref counting in action !
132 path = wxFindNextFile();
133 };
134
135
136 search = curdir;
137 search += "/*.cpp";
138
139 path = wxFindFirstFile( search, wxFILE );
140 while (!path.IsNull())
141 {
142 m_text->SetLabel( path );
143 wxYield();
144 Convert( id, path );
145 path = wxFindNextFile();
146 };
147
148 for (int i = 0; i < paths.Count(); i++)
149 {
150 search = paths[i];
151 Recurse( id, search );
152 };
153 };
154
155 //-----------------------------------------------------------------------------
156 // MyApp
157 //-----------------------------------------------------------------------------
158
159 MyApp::MyApp(void) :
160 wxApp( )
161 {
162 };
163
164 bool MyApp::OnInit(void)
165 {
166 wxFrame *frame = new MyFrame();
167 frame->Show( TRUE );
168
169 return TRUE;
170 };
171
172
173
174
175