File: mycmdwin.cpp

package info (click to toggle)
v1 1.20-2
  • links: PTS
  • area: main
  • in suites: slink
  • size: 6,240 kB
  • ctags: 9,439
  • sloc: cpp: 48,033; ansic: 8,939; makefile: 1,369; sh: 30
file content (404 lines) | stat: -rw-r--r-- 10,552 bytes parent folder | download | duplicates (2)
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
//=======================================================================
//  mycmdwin.cxx:     Source file for app cmdwin class
//  Copyright (C) 1995  Bruce E. Wampler
//
//  This program is part of the V C++ GUI Framework example programs.
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  (see COPYING) along with this program; if not, write to the Free
//  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=======================================================================

#include <v/vnotice.h>	// so we can use notice
#include <v/vkeys.h>	// to map keys
#include <v/vpen.h>
#include <v/vfilesel.h>
#include <v/vutil.h>

#include "mycmdwin.h"	// our header

//	Start defines for the main window with 100

#define m_CheckMe 100
#define m_CopySens 101
#define m_Dialog 102
#define m_ModalDialog 103
#define m_Clear 104

#define m_LineWidth 105
#define m_ChangePen 106

    // Define the pulldown menus
    static vMenu FileMenu[] =
      {
	{"New", M_New, isSens, notChk, noKeyLbl, noKey, noSub},
	{"Open", M_Open, isSens, notChk, noKeyLbl, noKey, noSub},
	{"Save", M_Save, notSens, notChk, noKeyLbl, noKey, noSub},
	{"Save As", M_SaveAs, notSens, notChk, noKeyLbl, noKey, noSub},
#ifdef vDEBUG
	{"-", M_Line, notSens, notChk, noKeyLbl, noKey, noSub},
	{"Debug", M_SetDebug, isSens, notChk, noKeyLbl, noKey, noSub},
#endif
	{"-", M_Line, notSens, notChk, noKeyLbl, noKey, noSub},
	{"Exit", M_Exit, isSens, notChk, noKeyLbl, noKey, noSub},
	{NULL}
      };

    static vMenu EditMenu[] =
      {
	{"Cut", M_Cut, notSens, notChk, noKeyLbl, noKey, noSub},
	{"Copy", M_Copy, notSens, notChk, noKeyLbl, noKey, noSub},
	{"Paste", M_Paste, notSens, notChk, noKeyLbl, noKey, noSub},
	{NULL}
      };

    static vMenu TestMenu[] =
      {
	{"CheckMe", m_CheckMe, isSens, notChk, noKeyLbl, noKey, noSub},
	{"Copy Sensitive", m_CopySens, isSens, notChk, noKeyLbl, noKey, noSub},
	{"Dialog", m_Dialog, isSens, notChk, noKeyLbl, noKey, noSub},
	{"Modal Dialog", m_ModalDialog, isSens, notChk, noKeyLbl, noKey, noSub},
        {NULL}
      };

    // Define a standard menu
    vMenu StandardMenu[] =
      {
	{"File", M_File, isSens, notUsed, notUsed, noKey, &FileMenu[0]},
		// the File menu
	{"Edit", M_Edit, isSens, notUsed, notUsed, noKey, &EditMenu[0]},
		// the Edit menu
	{"Test", M_Test, isSens, notUsed, notUsed, noKey, &TestMenu[0]},
		// the Test menu
	{NULL}
      };

    static int minMaxStep[3] = {1, 20, 1};
    // Define a button bar, usually with something useful
    static CommandObject CommandBar[] =
      {
	{C_Button, M_Copy, M_Copy, "Copy",NoList,CA_None,notSens,NoFrame,0,0},
	{C_Button, m_Clear, m_Clear, "Clear",NoList,CA_None,isSens,NoFrame,0,0},

	{C_Label, 999, 0 ,"Width:",NoList,CA_None, isSens, NoFrame,0,0},
	{C_Spinner,m_LineWidth,1,"",(void*)&minMaxStep[0],CA_None,isSens,NoFrame,0,0},
	{C_Button, m_ChangePen, m_ChangePen, "      Pen: ",NoList,
		CA_None,isSens,NoFrame,0,0},

#define vC_Size 12
#include<v/vcb2x8.h>

	{C_ColorButton, M_Exit, M_Exit, "Exit", &vStdColors[vC_Red],CA_None,isSens,NoFrame, 0, 0},

	{C_EndOfList,0,0,0,0,CA_None,0,0,0}
      };

#define m_cmdMsg 110
#define m_cmdCount 111
#define m_keyMsg 112
#define m_keyVal 113

    // Define a simple status bar
    static vStatus StatBar[] =
      {
	{"Commands issued: ", m_cmdMsg, CA_NoBorder, isSens, 0},
	{"   ", m_cmdCount, CA_None, isSens, 0},
	{"Last keypress: ", m_keyMsg, CA_NoBorder, isSens, 0},
	{"   ", m_keyVal, CA_None, isSens, 0},
	{0,0,0,0,0}
      };

    static char* filter[] =
      {
        "*",
        "*.txt",
        "*.c *.cxx *.h",
        0
      };
    int fi = 0;
    int copy_sens = 0;			// for tracking copy sensitive

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

    // The "Standard" window will consist of a menubar, a canvas,
    // an optional button bar, and an optional status bar.

    // First, create and add the proper panes to the CmdWindow
    // Note: there must be a correspondint delete in the destructor

    // The Menu Bar
    myMenu = new vMenuPane(StandardMenu);	// the standard menu
    AddPane(myMenu);				// add pane to window

    // The Canvas
    myCanvas = new myCanvasPane;		// a new canvas pane
    AddPane(myCanvas);				// add the pane to window

    // The command pane
    myCmdPane = new vCommandPane(CommandBar);
    AddPane(myCmdPane);

    // The Status Bar
    myStatus = new vStatusPane(StatBar);	// a new status bar
    AddPane(myStatus);			// add pane to window

    // Now, cerate whatever dialogs and windows this app defines.

    // Create instance of myDialog, and define default commands
    sampleDialog = new myDialog(this);

    // Create instance of myModalDialog, and define default commands
    sampleModalDialog = new myModalDialog(this);
    
    // FINALLY, after all the panes have been constructed and
    // added, we must show the window!

    changePen = 1;		// we are changing pen
    ShowWindow();
  }

//====================>>> myCmdWindow::myCmdWindow <<<====================
  myCmdWindow::myCmdWindow(const myCmdWindow& w) : vCmdWindow(w)
  {
    // This copy constructor is used to support the shallow destructor
    // convention used by the V framework.

    UserDebug(Constructor,"myCmdWindow::myCmdWindow() Copy constructor\n")
    vSysError("myCmdWindow: V does not support copy constructors");
  }

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

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

    delete myMenu;
    delete myCanvas;
    delete myStatus;
    delete myCmdPane;
    delete sampleDialog;
    delete sampleModalDialog;
  }

//====================>>> myCmdWindow::KeyIn <<<====================
  void myCmdWindow::KeyIn(vKey keysym, unsigned int shift)
  {
    static char ctrl[] = "^X ";
    static char chr[] = " X ";

    if (vk_IsModifier(keysym))
	SetString(m_keyVal, "mod");	// change status bar
    else if (keysym < ' ')		// ctrl char
      {
	ctrl[1] = keysym + '@';
	SetString(m_keyVal, ctrl);	// change status bar
      }
    else if (keysym < 128)		// normal printable char
      {
	chr[1] = keysym;
	SetString(m_keyVal, chr);	// change status bar
      }
    else 
	SetString(m_keyVal, "+++");	// change status bar
  }

//====================>>> myCmdWindow::WindowCommand <<<====================
  void myCmdWindow::WindowCommand(ItemVal id, ItemVal val, CmdType cType)
  {
    // route all commands through here - menus and buttons

    static cmdCount = 0;

    vNoticeDialog note(this);		// Used for default actions

    char buff[20];			// buff for status

    ++cmdCount;				// count commands that have been issued
    IntToStr(cmdCount,buff);
    SetString(m_cmdCount, buff);	// change status bar

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

    switch (id)
      {
	case M_New:
	  {
	    note.Notice("New");
	    theApp->NewAppWin(0,"",250,100);	// call our NewAppWin method
	    break;
	  }

	case M_Open:
	  {
	    static char name[100] = ""; // start out with null name
            vFileSelect fsel(this);     // make an instance
	

            int oans = fsel.FileSelect("Open file",name,99,filter,fi);

            vNoticeDialog fsnote(this); // make an instance

            if (oans && *name)
              {
                SetTitle(name);
                (void)note.Notice(name);
              }
            else
                (void)note.Notice("No file name input.");

	    break;
	  }

	case M_Save:
	  {
	    note.Notice("Save");
	    break;
	  }

	case M_SaveAs:
	  {
	    note.Notice("Save As");
	    break;
	  }

        // For case M_SetDebug, Vigr should generate following code,
	// including vDEBUG #ifdef

#ifdef vDEBUG
	case M_SetDebug:
	  {
	    vDebugDialog debug(this);
	    debug.SetDebug();		// select debug

	    break;
	  }
#endif

	case M_Exit:
	  {
	    theApp->Exit();		// Standard action for Exit
	    break;
	  }

	case M_Cut:
	  {
	    note.Notice("Cut");
	    break;
	  }

	case M_Copy:
	  {
	    note.Notice("Copy");
	    break;
	  }

	case M_Paste:
	  {
	    note.Notice("Paste");
	    break;
	  }

	case m_CheckMe:
	  {
	    // This code would be supplied by the user, not Vigr

	    ItemVal curval = GetValue(id);

	    SetValue(m_CheckMe,!curval,Checked);
	    if (curval)
		SetString(m_CheckMe,"Check Me");
	    else
		SetString(m_CheckMe,"UnChk Me");

	    break;
	  }

	case m_CopySens:
	  {
	    // This code would be supplied by the user, not Vigr
	    copy_sens = !copy_sens;
	    SetValue(M_Copy,copy_sens,Sensitive);

	    break;
	  }

	case m_Dialog:
	  {
	    // Ideally, Vigr will generate the following code, too:
	    if (!sampleDialog->IsDisplayed())	// not twice!
		sampleDialog->ShowDialog("Sample Modeless Dialog");
	    break;
	  }

	case m_ModalDialog:
	  {
	    // Ideally, Vigr will generate the following code, too:
	    ItemVal rval, rid;
	    if (!sampleModalDialog->IsDisplayed())	// not twice!
		rid = sampleModalDialog->ShowModalDialog("Sample Modal",rval);
	    break;
	  }

	case m_ChangePen:
	  {
	    if (changePen)
	      {
		SetString(m_ChangePen,"Background:");
		changePen = 0;
	      }
	    else
	      {
		SetString(m_ChangePen,"      Pen: ");
		changePen = 1;
	      }
	    break;
	  }

	case m_LineWidth:
	  {
	    _pen.SetWidth(val);
	    myCanvas->SetPen(_pen);
	    break;
	  }

	case m_Clear:
	  {
	    myCanvas->Clear();
	    break;
	  }

	default:		// route unhandled commands up
	  {
	    if (id >= M_Black && id <= M_White)
	      {
		if (changePen)
		  {
		    _pen.SetColor(vStdColors[val]);
		    myCanvas->SetPen(_pen);
		  }
		else
		    myCanvas->SetBackground(vStdColors[val]);
	      }
	    else
		vCmdWindow::WindowCommand(id, val, cType);
	    break;
	  }
	    
      }
  }