File: vgcmdw.cpp

package info (click to toggle)
v1 1.17-4
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 5,812 kB
  • ctags: 6,780
  • sloc: cpp: 43,604; ansic: 5,003; makefile: 955; sh: 30
file content (333 lines) | stat: -rw-r--r-- 9,338 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
//=======================================================================
//@V@:Note: This file generated by vappgen V 1.00.
//	vgcmdw.cpp:	Source for vgCmdWindow class
//=======================================================================

#include <v/vnotice.h>	// for vNoticeDialog
#include <v/vkeys.h>	// to map keys
#include <v/vynreply.h>	// for overwrite
#include <fstream.h>

#include "vgcmdw.h"	// our header
#include "vgcode.h"

//	Start defines for the main window with 100

    enum {
	m_Generate = 100,	// Generate menu
	m_GenStdApp,		// A standard app
	m_GenExtraDialog,	// An extra dialog
	m_GenTinyApp		//
      };

    static vMenu FileMenu[] =
      {
	{"Exit", M_Exit, isSens, notChk, noKeyLbl, noKey, noSub},
	{NULL}
      };

    static vMenu GenerateMenu[] =
      {
	{"Standard Application",m_GenStdApp , isSens, notChk, noKeyLbl, noKey, noSub},
	{"Extra Dialog",m_GenExtraDialog , isSens, notChk, noKeyLbl, noKey, noSub},
	{"Menuless/Canvasless App",m_GenTinyApp , isSens, notChk, noKeyLbl, noKey, noSub},
	{NULL}
      };

    static vMenu StandardMenu[] =
      {
	{"File", M_File, isSens, notUsed, notUsed, noKey, &FileMenu[0]},
	{"Generate", m_Generate, isSens, notUsed, notUsed, noKey, &GenerateMenu[0]},
	{NULL}
      };
 
    static CommandObject ToolBar[] =
      {
	{C_Button,m_GenStdApp,0,"Standard App",NoList,CA_None,isSens,NoFrame,0,0},
	{C_Button,m_GenExtraDialog,0,"Extra Dialog",NoList,CA_None,isSens,NoFrame,0,0},
	{C_EndOfList,0,0,0,0,CA_None,0,0,0}
      }; 


//====================>>> vgCmdWindow::vgCmdWindow <<<====================
  vgCmdWindow::vgCmdWindow(char* name, int width, int height) :
    vCmdWindow(name, width, height)
  {
    UserDebug1(Constructor,"vgCmdWindow::vgCmdWindow(%s) Constructor\n",name)

    // The Menu Bar
    vgMenu = new vMenuPane(StandardMenu);
    AddPane(vgMenu);

    // The Command Pane
    vgCmdPane = new vCommandPane(ToolBar);
    AddPane(vgCmdPane);

    // The Canvas
    vgCanvas = new vgTextCanvasPane;
    AddPane(vgCanvas);

    // Show Window

    ShowWindow();

    // Setup default options
    strcpy(opts.appName,"my");
    strcpy(opts.fileName,"my");
    strcpy(opts.title, "My V App");
    strcpy(opts.home, DEF_HOMEV);

    opts.addDialog = 1;
    opts.addModal = 1;
    opts.extraDialog = 0;
    opts.addMake = 1;
    opts.addToolBar = 1;
    opts.addStatus = 1;
    opts.addDate = 1;
    opts.vScroll = 1;
    opts.hScroll = 1;
    opts.canvasType = 1;
    opts.fullMenu = 1;
    opts.winSDI = 0;
    opts.tinyApp = 0;

  }

//====================>>> vgCmdWindow::~vgCmdWindow <<<====================
  vgCmdWindow::~vgCmdWindow()
  {
    UserDebug(Destructor,"vgCmdWindow::~vgCmdWindow() destructor\n")

    // Now put a delete for each new in the constructor.

    delete vgMenu;
    delete vgCmdPane;
    delete vgCanvas;

  }

//====================>>> vgCmdWindow::KeyIn <<<====================
  void vgCmdWindow::KeyIn(vKey keysym, unsigned int shift)
  {
    vCmdWindow::KeyIn(keysym, shift);
  }

//====================>>> vgCmdWindow::WindowCommand <<<====================
  void vgCmdWindow::WindowCommand(ItemVal id, ItemVal val, CmdType cType)
  {
    // Default: route menu and toolbar commands here


    UserDebug1(CmdEvents,"vgCmdWindow:WindowCommand(%d)\n",id)

    switch (id)
      {
	//@V@:Case M_New
	case M_New:
	  {
	    vNoticeDialog note(this);
	    note.Notice("New");
	    break;
	  }	//@V@:EndCase

	//@V@:Case M_Open
	case M_Open:
	  {
	    vNoticeDialog note(this);
	    note.Notice("Open");
	    break;
	  }	//@V@:EndCase

	//@V@:Case M_Save
	case M_Save:
	  {
	    vNoticeDialog note(this);
	    note.Notice("Save");
	    break;
	  }	//@V@:EndCase

	//@V@:Case M_SaveAs
	case M_SaveAs:
	  {
	    vNoticeDialog note(this);
	    note.Notice("Save As");
	    break;
	  }	//@V@:EndCase

	//@V@:Case M_Exit
	case M_Exit:
	  {
	    theApp->Exit();
	    break;
	  }	//@V@:EndCase

	case m_GenStdApp:
	  {
	    strcpy(opts.appName,"my");		// initial names
	    strcpy(opts.fileName,"my");
	    strcpy(opts.title, "My V App");
	    opts.tinyApp = 0;
	    vgModalDialog vgMDlg(this);
	    if (vgMDlg.vgAction("Generate Standard V Appication", opts))
	      {
		char name[100];
		strcpy(name,opts.fileName); strcat(name,"app.cpp");
		ifstream ifile(name);		// see if open
		if (ifile)
		  {
		    ifile.close();
		    vYNReplyDialog ynd(this);
		    if (ynd.AskYN("An application with this name exists. Overwrite it?") != 1)
			break;
		  }

		opts.extraDialog = 0;
		vgCanvas->DrawText("************************************************\n");
		vgCanvas->DrawText("Generated class ");
		vgCanvas->DrawText(opts.appName); vgCanvas->DrawText("App            -> ");
		vgCanvas->DrawText(opts.fileName); vgCanvas->DrawText("app[.cpp & .h]\n");
		genApp(opts);

		vgCanvas->DrawText("Generated class ");
		vgCanvas->DrawText(opts.appName); vgCanvas->DrawText("CmdWindow      -> ");
		vgCanvas->DrawText(opts.fileName); vgCanvas->DrawText("cmdw[.cpp & .h]\n");
		genCmdw(opts);

		vgCanvas->DrawText("Generated class ");
		vgCanvas->DrawText(opts.appName); 
		if (opts.canvasType == 0)
		  {
		    vgCanvas->DrawText("CanvasPane     -> ");
		    genCnv(opts);
		  }
		else
		  {
		    vgCanvas->DrawText("TextCanvasPane -> ");
		    genTextCnv(opts);
		  }
		vgCanvas->DrawText(opts.fileName); vgCanvas->DrawText("cnv[.cpp & .h]\n");

		if (opts.addDialog)
		  {
		    vgCanvas->DrawText("Generated class ");
		    vgCanvas->DrawText(opts.appName); vgCanvas->DrawText("Dialog         -> ");
		    vgCanvas->DrawText(opts.fileName); vgCanvas->DrawText("dlg[.cpp & .h]\n");
		    genDlg(opts);
		  }

		if (opts.addModal)
		  {
		    vgCanvas->DrawText("Generated class ");
		    vgCanvas->DrawText(opts.appName); vgCanvas->DrawText("ModalDialog    -> ");
		    vgCanvas->DrawText(opts.fileName); vgCanvas->DrawText("mdlg[.cpp & .h]\n");
		    genMDlg(opts);
		  }

		if (opts.addMake)
		  {
		    vgCanvas->DrawText("Generated makefile.");
		    vgCanvas->DrawText(opts.fileName); vgCanvas->DrawText(" for V application ");
		    vgCanvas->DrawText(opts.appName); vgCanvas->DrawText(".\n");
		    genMake(opts);
		  }
	        vgCanvas->DrawText("\nDone.\n");
		vgCanvas->DrawText("************************************************\n");
	      }

	    break;
	  }	//@V@:EndCase

        case m_GenExtraDialog:	// An extra dialog
	  {
	    opts.extraDialog = 1;
	    strcpy(opts.appName,"xtra");
	    strcpy(opts.fileName,"xtra");
	    strcpy(opts.title, "Extra Dialog");
	    opts.tinyApp = 0;
	    vgdlgModalDialog vgdlgMDlg(this);
	    if (vgdlgMDlg.vgdlgAction("Generate Extra Dialog", opts))
	      {
		char name[100];
		strcpy(name,opts.fileName);
		if (opts.addDialog)
		    strcat(name,"dlg.cpp");
		else
		    strcat(name,"mdlg.cpp");
		ifstream ifile(name);		// see if open
		if (ifile)
		  {
		    ifile.close();
		    vYNReplyDialog ynd(this);
		    if (ynd.AskYN("A dialog with this name exists. Overwrite it?") != 1)
			break;
		  }
		vgCanvas->DrawText("************************************************\n");
		if (opts.addDialog)
		  {
		    vgCanvas->DrawText("Generated class ");
		    vgCanvas->DrawText(opts.appName); vgCanvas->DrawText("Dialog         -> ");
		    vgCanvas->DrawText(opts.fileName); vgCanvas->DrawText("dlg[.cpp & .h]\n");
		    genDlg(opts);
		  }
		else if (opts.addModal)
		  {
		    vgCanvas->DrawText("Generated class ");
		    vgCanvas->DrawText(opts.appName); vgCanvas->DrawText("ModalDialog    -> ");
		    vgCanvas->DrawText(opts.fileName); vgCanvas->DrawText("mdlg[.cpp & .h]\n");
		    genMDlg(opts);
		  }
	        vgCanvas->DrawText("\n!!!! You must add this dialog to your app manually!\nDone.\n");
		vgCanvas->DrawText("************************************************\n");
	      }
	    break;
	  }

        case m_GenTinyApp:		// Canvasless/Menuless app
	  {
	    strcpy(opts.appName,"tiny");
	    strcpy(opts.fileName,"tiny");
	    strcpy(opts.title, "Simple App");
	    vgTinyModalDialog vgtinyMDlg(this);
	    if (vgtinyMDlg.vgTinyAction("Generate Menuless/Canvasless App", opts))
	      {
		char name[100];
		strcpy(name,opts.fileName); strcat(name,"app.cpp");
		ifstream ifile(name);		// see if open
		if (ifile)
		  {
		    ifile.close();
		    vYNReplyDialog ynd(this);
		    if (ynd.AskYN("An application with this name exists. Overwrite it?") != 1)
			break;
		  }

		vgCanvas->DrawText("************************************************\n");
		vgCanvas->DrawText("Generated class ");
		vgCanvas->DrawText(opts.appName); vgCanvas->DrawText("App            -> ");
		vgCanvas->DrawText(opts.fileName); vgCanvas->DrawText("app[.cpp & .h]\n");
		genApp(opts);

		vgCanvas->DrawText("Generated class ");
		vgCanvas->DrawText(opts.appName); vgCanvas->DrawText("CmdWindow      -> ");
		vgCanvas->DrawText(opts.fileName); vgCanvas->DrawText("cmdw[.cpp & .h]\n");
		genCmdw(opts);

		if (opts.addMake)
		  {
		    vgCanvas->DrawText("Generated makefile.");
		    vgCanvas->DrawText(opts.fileName); vgCanvas->DrawText(" for V application ");
		    vgCanvas->DrawText(opts.appName); vgCanvas->DrawText(".\n");
		    genMake(opts);
		  }
		vgCanvas->DrawText("************************************************\nDone.\n");
	      }
	    break;
	  }

	default:		// route unhandled commands up
	  {
	    vCmdWindow::WindowCommand(id, val, cType);
	    break;
	  }
      }
  }