File: drawcmdw.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 (197 lines) | stat: -rw-r--r-- 5,261 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
//================================================================
//  drawcmdw.cxx:     Source file for drawApp cmdwin class
//  Copyright (C) 1995  Bruce E. Wampler
//================================================================
#include <v/vnotice.h>	// so we can use notice
#include <v/vpen.h>	// for drawing pen
#include <v/vfilesel.h>	// for file selection

#include "drawcmdw.h"	// our header

//	Start defines for the main window with 100

  const ItemVal m_Clear = 100;
  const ItemVal m_LineWidth = 101;
  const ItemVal m_ChangePen = 102;
  const ItemVal m_ColorBtn = 103;

    // Define the File and Edit pulldown menus
    static vMenu FileMenu[] =
      {
	{"New", M_New, isSens, notChk, noKeyLbl, noKey, noSub},
	{"Open", M_Open, isSens, notChk, noKeyLbl, noKey, noSub},
	{"Save", M_Save, isSens, notChk, noKeyLbl, noKey, noSub},
	{"Save As", M_SaveAs, isSens,notChk,noKeyLbl,noKey,noSub},
	{"-", M_Line, notSens, notChk, noKeyLbl, noKey, noSub},
	{"Exit", M_Exit, isSens, notChk, noKeyLbl, noKey, noSub},
	{NULL}
      };

    static vMenu EditMenu[] =
      {
	{"Clear", m_Clear, isSens, notChk, noKeyLbl, noKey,noSub},
	{NULL}
      };

    // Define the main menu
    vMenu MainMenu[] =
      {
	{"File",M_File,isSens,notUsed,notUsed,noKey,&FileMenu[0]},
	{"Edit",M_Edit,isSens,notUsed,notUsed,noKey,&EditMenu[0]},
	{NULL}
      };

    // Define the command bar
    static int minMaxStep[3] = {1, 20, 1};	// for line width
    static vColor btnColor(0,0,0);
    static CommandObject CommandBar[] =
      {
	{C_Button, m_Clear, m_Clear, "Clear", NoList,
		CA_None,isSens,NoFrame,0,0},
	{C_Label, 999, 0 ," Pen Width: ", NoList,
		CA_None, isSens, NoFrame,0,0},
	{C_Spinner,m_LineWidth,1,"",(void*)&minMaxStep[0],
		CA_None,isSens,NoFrame,0,0},
	{C_Label, 999, 0, " Pen Color: ",NoList,
		CA_None,isSens,NoFrame,0,0},
	{C_ColorButton, m_ColorBtn, 0, "", (void*)&btnColor,
		CA_None,isSens,NoFrame,0,0,12},
#define vC_Size 12			// size of color buttons
#include<v/vcb2x8.h>	// define a color selection box
	{C_EndOfList,0,0,0,0,CA_None,0,0,0}
      };

//================>>> myCmdWindow::myCmdWindow <<<================
  myCmdWindow::myCmdWindow(char* name, int width, int height) :
    vCmdWindow(name, width, height)
  {
    // Create and add the proper panes to the CmdWindow

    *_fname = 0;			// no name

    myMenu = new vMenuPane(MainMenu);	// Add the main menu
    AddPane(myMenu);

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

    myCanvas = new myCanvasPane;	// Add the canvas pane
    AddPane(myCanvas);

    ShowWindow();	    // FINALLY, we must show the window!
  }

//===============>>> myCmdWindow::~myCmdWindow <<<================
  myCmdWindow::~myCmdWindow()
  {
    delete myMenu;	// Delete everything new'ed in
    delete myCanvas;	//   the constructor
    delete myCmdPane;
  }

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

    static char* filter[] = {"*.drw","*", 0};	// file filter
    static int fi = 0;
    vNoticeDialog note(this);	// for user notification

    switch (id)		// switch on id of commands
      {
	case M_New:
	  {
	    // call our NewAppWin method
	    theApp->NewAppWin(0,"V Draw - No Name",500,250,0);
	    break;
	  }

	case M_Open:
	  {
	    if (*_fname)
	      {
		note.Notice("Create a New window first.");
		break;
	      }

            vFileSelect fsel(this);     // V file select dialog

            if (!fsel.FileSelect("Open V Draw File",
	      _fname,99,filter,fi) || !*_fname)
		break;			// ignore if no selection

	    if (!myCanvas->Read(_fname))	// Save in _fname
	      {
		note.Notice("Unable to read file");
		break;
	      }
	    SetTitle(_fname);		// show on title bar
	    myCanvas->Redraw(0,0,0,0);	// paint it
	    break;
	  }

	case M_Save:
	  {
	    if (*_fname)			// have a name
	      {
		if (!myCanvas->Save(_fname))	// Save in _fname
		    note.Notice("Unable to save file");
		break;
	      }
	    // else fall through to SaveAs
	  }

	case M_SaveAs:
	  {
            vFileSelect fsel(this);     // V file select dialog

            if (!fsel.FileSelectSave("Save V Draw File As",
	      _fname,99,filter,fi) || !*_fname)
		break;			// ignore if no selection

	    if (!myCanvas->Save(_fname))	// Save in _fname
	      {
		note.Notice("Unable to read file");
		break;
	      }
	    SetTitle(_fname);
	    break;
	  }

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

	case m_LineWidth:
	  {
	    _pen.SetWidth(val);	// set new pen width
	    myCanvas->SetPen(_pen);
	    break;
	  }

	case m_Clear:			// clear the screen
	  {
	    myCanvas->Clear();
	    break;
	  }

	default:			// change pen color?
	  {
	    if (id >= M_Black && id <= M_White)  // color button
	      {
		_pen.SetColor(vStdColors[val]);
		myCanvas->SetPen(_pen);
		SetValue(m_ColorBtn,(ItemVal)_pen.GetColor().r(),Red);
		SetValue(m_ColorBtn,(ItemVal)_pen.GetColor().g(),Green);
		SetValue(m_ColorBtn,(ItemVal)_pen.GetColor().b(),Blue);
	      }
	    else		// pass up hierarchy
		vCmdWindow::WindowCommand(id, val, cType);
	    break;
	  }
      }
  }