File: icondemo.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 (343 lines) | stat: -rw-r--r-- 12,470 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
334
335
336
337
338
339
340
341
342
343
//=======================================================================
//  icondemo.cpp:     Source file for icon demo
//  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 "icondemo.h"	// our header
#include <v/vicon.h>

// This program is used to show the sample 16x16 icons provided with the V
// distribution. It doesn't do anything else.

//****************************************************************************

    // Define a  menu and some command bars

    static vMenu ShortFile[] =
      {
        {"E&xit", M_Exit, isSens, notChk, noKeyLbl, noKey, noSub},
        {NULL}
      };

#include "bold.vbm"
    static vIcon boldI(&bold_bits[0],bold_height,bold_width);
#include "brush.vbm"
    static vIcon brushI(&brush_bits[0],brush_height,brush_width);
#include "check.vbm"
    static vIcon checkI(&check_bits[0],check_height,check_width);
#include "copy.vbm"
    static vIcon copyI(&copy_bits[0],copy_height,copy_width);
#include "cut.vbm"
    static vIcon cutI(&cut_bits[0],cut_height,cut_width);
#include "draw.vbm"
    static vIcon drawI(&draw_bits[0],draw_height,draw_width);
#include "ellip.vbm"
    static vIcon ellipI(&ellip_bits[0],ellip_height,ellip_width);
#include "help.vbm"
    static vIcon helpI(&help_bits[0],help_height,help_width);
#include "italic.vbm"
    static vIcon italicI(&italic_bits[0],italic_height,italic_width);
#include "line.vbm"
    static vIcon lineI(&line_bits[0],line_height,line_width);
#include "new.vbm"
    static vIcon newI(&new_bits[0],new_height,new_width);
#include "open.vbm"
    static vIcon openI(&open_bits[0],open_height,open_width);
#include "paste.vbm"
    static vIcon pasteI(&paste_bits[0],paste_height,paste_width);
#include "pencil.vbm"
    static vIcon pencilI(&pencil_bits[0],pencil_height,pencil_width);
#include "poly.vbm"
    static vIcon polyI(&poly_bits[0],poly_height,poly_width);
#include "preview.vbm"
    static vIcon previewI(&preview_bits[0],preview_height,preview_width);
#include "print.vbm"
    static vIcon printI(&print_bits[0],print_height,print_width);
#include "rect.vbm"
    static vIcon rectI(&rect_bits[0],rect_height,rect_width);
#include "redo.vbm"
    static vIcon redoI(&redo_bits[0],redo_height,redo_width);
#include "save.vbm"
    static vIcon saveI(&save_bits[0],save_height,save_width);
#include "underln.vbm"
    static vIcon underlnI(&underln_bits[0],underln_height,underln_width);
#include "undo.vbm"
    static vIcon undoI(&undo_bits[0],undo_height,undo_width);
#include "zoom.vbm"
    static vIcon zoomI(&zoom_bits[0],zoom_height,zoom_width);

#include "alpha.vbm"
    static vIcon alphaI(&alpha_bits[0],alpha_height,alpha_width);
#include "back.vbm"
    static vIcon backI(&back_bits[0],back_height,back_width);
#include "book.vbm"
    static vIcon bookI(&book_bits[0],book_height,book_width);
#include "cursor.vbm"
    static vIcon cursorI(&cursor_bits[0],cursor_height,cursor_width);
#include "down.vbm"
    static vIcon downI(&down_bits[0],down_height,down_width);
#include "drawline.vbm"
    static vIcon drawlineI(&drawline_bits[0],drawline_height,drawline_width);
#include "fill.vbm"
    static vIcon fillI(&fill_bits[0],fill_height,fill_width);
#include "find.vbm"
    static vIcon findI(&find_bits[0],find_height,find_width);
#include "findagn.vbm"
    static vIcon findagnI(&findagn_bits[0],findagn_height,findagn_width);
#include "forward.vbm"
    static vIcon forwardI(&forward_bits[0],forward_height,forward_width);
#include "left.vbm"
    static vIcon leftI(&left_bits[0],left_height,left_width);
#include "page.vbm"
    static vIcon pageI(&page_bits[0],page_height,page_width);
#include "right.vbm"
    static vIcon rightI(&right_bits[0],right_height,right_width);
#include "up.vbm"
    static vIcon upI(&up_bits[0],up_height,up_width);

    static CommandObject CommandBar[] =
      {
	{C_Button, M_Exit, 1, "Exit", NoList,CA_None, isSens, 0, 0, 0},
	{C_IconButton,20,20,"",&newI,CA_None,isSens,0,0,0},
	{C_IconButton,21,21,"",&openI,CA_None,isSens,0,0,0},
	{C_IconButton,29,29,"",&saveI,CA_None,isSens,0,0,0},
	{C_IconButton,14,14,"",&cutI,CA_None,isSens,0,0,0},
	{C_IconButton,13,13,"",&copyI,CA_None,isSens,0,0,0},
	{C_IconButton,22,22,"",&pasteI,CA_None,isSens,0,0,0},
	{C_IconButton,31,31,"",&undoI,CA_None,isSens,0,0,0},
	{C_IconButton,28,28,"",&redoI,CA_None,isSens,0,0,0},
	{C_IconButton,26,26,"",&printI,CA_None,isSens,0,0,0},
	{C_IconButton,25,25,"",&previewI,CA_None,isSens,0,0,0},
	{C_IconButton,44,44,"",&pageI,CA_None,isSens,0,0,0},
        {C_EndOfList,0,0,0,0,CA_None,0,0,0}
      };

    static CommandObject CommandBar2[] =
      {
	{C_IconButton,33,33,"",&alphaI,CA_None,isSens,0,0,0},
	{C_Frame,90,0,"",NoList,CA_NoSpace | CA_NoBorder,isSens,0,0,0},
	{C_ToggleIconButton,10,0,"",&boldI,CA_None,isSens,90,0,0},
	{C_ToggleIconButton,18,0,"",&italicI,CA_None,isSens,90,10,0},
	{C_ToggleIconButton,30,0,"",&underlnI,CA_None,isSens,90,18,0},
	{C_IconButton,15,15,"",&drawI,CA_None,isSens,0,0,0},
	{C_IconButton,11,11,"",&brushI,CA_None,isSens,0,0,0},
	{C_IconButton,23,23,"",&pencilI,CA_None,isSens,0,0,0},
	{C_IconButton,38,38,"",&drawlineI,CA_None,isSens,0,0,0},
	{C_IconButton,39,39,"",&fillI,CA_None,isSens,0,0,0},
	{C_IconButton,19,19,"",&lineI,CA_None,isSens,0,0,0},
	{C_IconButton,27,27,"",&rectI,CA_None,isSens,0,0,0},
	{C_IconButton,16,16,"",&ellipI,CA_None,isSens,0,0,0},
	{C_IconButton,24,24,"",&polyI,CA_None,isSens,0,0,0},
        {C_EndOfList,0,0,0,0,CA_None,0,0,0}
      };

    static CommandObject CommandBar3[] =
      {
	{C_IconButton,40,40,"",&findI,CA_None,isSens,0,0,0},
	{C_IconButton,41,41,"",&findagnI,CA_None,isSens,0,0,0},
	{C_IconButton,34,34,"",&backI,CA_None,isSens,0,0,0},
	{C_IconButton,42,42,"",&forwardI,CA_None,isSens,0,0,0},
	{C_IconButton,46,46,"",&upI,CA_None,isSens,0,0,0},
	{C_IconButton,37,37,"",&downI,CA_None,isSens,0,0,0},
	{C_IconButton,43,43,"",&leftI,CA_None,isSens,0,0,0},
	{C_IconButton,45,45,"",&rightI,CA_None,isSens,0,0,0},
	{C_IconButton,36,36,"",&cursorI,CA_None,isSens,0,0,0},
	{C_IconButton,35,35,"",&bookI,CA_None,isSens,0,0,0},
	{C_IconButton,12,12,"",&checkI,CA_None,isSens,0,0,0},
	{C_IconButton,32,32,"",&zoomI,CA_None,isSens,0,0,0},
	{C_IconButton,17,17,"",&helpI,CA_None,isSens,0,0,0},
        {C_EndOfList,0,0,0,0,CA_None,0,0,0}
      };

    static vMenu StandardMenu[] =
      {
	{"&File", M_File, isSens, notUsed, notUsed, noKey, &ShortFile[0]},
	{NULL}
      };


//====================>>> iconCmdWindow::iconCmdWindow <<<====================
  iconCmdWindow::iconCmdWindow(char* name, int width, int height) :
    vCmdWindow(name, width, height)
  {

    // 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);		// A short menu
    AddPane(myMenu);                            // add pane to window

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

    // The command pane (2)
    myCmdPane2 = new vCommandPane(CommandBar2);
    AddPane(myCmdPane2);

    // The command pane (3)
    myCmdPane3 = new vCommandPane(CommandBar3);
    AddPane(myCmdPane3);

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

    ShowWindow();

  }

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

    delete myMenu;
    delete myCanvas;
    delete myCmdPane;
    delete myCmdPane2;
    delete myCmdPane3;
  }

//====================>>> testCmdWindow::WindowCommand <<<====================
  void iconCmdWindow::WindowCommand(ItemVal id, ItemVal val, CmdType cType)
  {

    // route all commands through here - menus and buttons
    char buff[20];

    switch (id)
      {
        case M_Exit:
          {
            theApp->Exit();
            break;
          }

      }
  }
//****************************************************************************
//=========================>>> iconApp::NewAppWin <<<==========================
  vWindow* iconApp::NewAppWin(vWindow* win, char* name, int w, int h, 
			      vAppWinInfo* winInfo)
  {
    // This version of NewAppWin is provided with the information
    // required to name and size a window.

    // Typically, these would get a file name or other information
    // that will setup the AppWinInfo class for information
    // specific to the application. Thus, each open window
    // usually represents a view of a file or data object.

    vWindow* thisWin = win;		// local copy to use
    vAppWinInfo* awinfo = winInfo;

    char *myname = name;

    if (!*name)
      {
	myname = "Icon Demo";		// make up a name
      }
	
    UserDebug1(Build,"iconApp::NewAppWin(%s)\n",myname);

    if (!thisWin)			// need to new a window
      {
	thisWin = new iconCmdWindow(myname, w, h);
      }

    // The real app will no doubt have its own AppWinInfo class.

    if (!awinfo)
	awinfo = new vAppWinInfo(myname);

    return vApp::NewAppWin(thisWin, myname, w, h, awinfo);
  }

//========================>>> iconApp::Exit <<<======================
  void iconApp::Exit(void)
  {
    // This is called to close all windows. If the app needs to
    // do something special, it can. Otherwise, it can call the
    // general vApp::Exit method, which will generate
    // appropriate calls the the specialized iconApp::CloseAppWin

    UserDebug(Build,"iconApp::Exit()\n");

    vApp::Exit();	// easy default behavior
  }

//=======================>>> iconApp::CloseAppWin <<<===========================
  void iconApp::CloseAppWin(vWindow* win)
  {
    // This will be called BEFORE a window has been unregistered or
    // closed.  The app can do whatever it needs to to close down
    // the data associated with this window. Then it can call the
    // general vApp::CloseAppWin to unregister and close this window.
    // Note that the win gives a handle that can be used with
    // vApp::getAppWinInfo to retrieve the AppWinInfo class.

    // Code to handle close of window (such as saving/closing a file)
    // would go here...

    // Now unregister and close the window.

    UserDebug(Build,"iconApp::CloseAppWin()\n");

    vApp::CloseAppWin(win);
  }

//========================>>> iconApp::AppCommand <<<==============================
  void iconApp::AppCommand(vWindow* win, ItemVal id, ItemVal val, CmdType cType)
  {
    // Any commands not processed by the window will be passed
    // along to here for default treatment.

    UserDebug1(Build,"iconApp::AppCmd(ID: %d)\n",id);
    vApp::AppCommand(win, id, val, cType);
  }

//=========================>>> iconApp::KeyIn <<<==============================
  void iconApp::KeyIn(vWindow* win, vKey key, unsigned int shift)
  {
    // Any key strokes not processed by the window will be passed
    // along to here for default treatment.

    vApp::KeyIn(win, key, shift);
  }

//###########################################################################

  // EVERY V application needs the equivalent of the following line

  static iconApp icon_App("Icon Demo App");	// The instance of the app

//============================>>> AppMain <<<==============================
  int AppMain(int argc, char** argv)
  {
    // Use AppMain to create the main window

    (void) theApp->NewAppWin(0, "Icon Demo", 450, 50);

    return 0;
  }