-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpclaf.h
699 lines (573 loc) · 17.9 KB
/
pclaf.h
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
//======================================================================
// File: pclaf.h
// Authors: Timothy P. Justice, Yves Peneveyre
// Created: March 24, 1992
// Revised: April 5, 1995
// Spring 1999 (adapt to Win-NT environment & Visual-C++ 5.0
// & Borland C++ (5?)
// September 2006 (adapt to VC++ 6,7,8)
// Description: This file contains the interface of the
// classes for the Little Application Framework.
//----------------------------------------------------------------------
// Copyright (c) 1992, 1993, 1995 by Timothy P. Justice, Oregon State U.
// Copyright (c) 1999, by Yves Peneveyre,
// Ecole d'Ingenieurs du Canton de Vaud, Switzerland
// Copyright (c) 2006, by Doohun Eum,
// Duksung Women's Univ., Seoul, Korea
//
// This file is part of LAF, the Little Application Framework.
//
// Permission is hereby granted to everyone to copy and distribute
// without fee verbatim copies of this file. This copyright notice
// must be retained on all copies. No warranty expressed or implied
// is made concerning this software.
//
// Authors e-mail addresses: justict@cs.orst.edu
// Yves.Peneveyre@eivd.ch (www.eivd.ch)
// dheum@duksung.ac.kr
//======================================================================
#ifndef LAF_H
#define LAF_H
// Header Files
#include <WINDOWS.H> // Microsoft Windows interface
#include <stdio.h> // C++ standard i/o library
#include <stdlib.h> // C++ standard library
//#include <string.h> // C++ string library
// Definitions
#define MAXCONTROLS 100
#define MAXITEMS 20
#define MAXMENUS 20
#define MAKEPOINT(l) (*((POINT FAR *) & (l)))
#define M_PI 3.14
// Class Hierarchy: Little Application Framework
class winostream;
class window;
class application;
class childWindow;
class menu;
class control;
class basicMenuItem;
class basicButton;
class editText;
class staticText;
class listBox;
// Other Types
enum streamBase {octBase, decBase, hexBase};
enum color
{
black, blue, green, cyan, red, magenta, brown, gray,
white, brightBlue, brightGreen, brightCyan, brightRed,
brightMagenta, brightYellow, brightGray
};
enum lineStyle {solidLine, dashedLine, dottedLine, nullLine};
enum textAlign {leftText, centerText, rightText};
typedef HBITMAP bitmap;
typedef POINT point;
// --- Window Stream Class ---------------------------------------------
//
// winostream is used to simulate the behavior of C++ output
// streams in a window.
//----------------------------------------------------------------------
class winostream
{
public:
winostream();
winostream(window *);
streamBase base() const;
streamBase base(streamBase);
int precision() const;
int precision(int);
int width() const;
int width(int);
window *outputWindow();
winostream &operator << (char);
winostream &operator << (char *);
winostream &operator << (double);
winostream &operator << (float);
winostream &operator << (int);
winostream &operator << (long);
private:
int fieldWidth;
int floatPrecision;
streamBase numberBase;
window *winptr;
};
// --- Window Class ----------------------------------------------------
//
// Window is an abstract class that defines the behavior common
// to all windows.
//----------------------------------------------------------------------
class window
{
public:
// constructor
window(char *title, int width, int height, int x, int y);
// destructor
virtual ~window();
// add a control to the window
void add(control *aControl);
// add a menu to the window
void add(menu *aMenu);
// return the average character width
int avgCharWidth();
// return the y coordinate for the bottom of the window
int bottom();
void cartesianOff();
void cartesianOn(color, lineStyle, int);
void circle(const int, const int, const int);
void circle(const POINT &, const int);
void checkMenuItem(int);
void clearAndUpdate();
virtual void command(int);
virtual void create();
editText createEditText(int, int, int, int, int,
textAlign = leftText, int = 1, char * = 0);
listBox createListBox(int, int, int, int, int, int = 1);
staticText createStaticText(int, int, int, int,
textAlign = leftText, int = 0, char * = 0);
virtual void doubleClick(int, int);
void gridOn(color, lineStyle, int);
void gridOff();
HWND handle();
int height();
HINSTANCE instance();
int left();
void line(const int, const int, const int, const int);
void line(const POINT &, const POINT &);
HMENU menuHandle();
virtual void mouseDown(int, int);
virtual void mouseRDown(int, int);
virtual void mouseMDown(int, int);
virtual void paint();
void point(const int, const int);
void polygon(POINT [], int);
LRESULT WINAPI process(HWND, UINT, WPARAM, LPARAM);
virtual void quit();
void rectangle(const int, const int, const int, const int);
int right();
virtual void run();
void scrollToBottom();
void scrollToLeft();
void scrollToRight();
void scrollToTop();
void setBrush(color);
void setMaxX(int);
void setMaxY(int);
void setPen(color, lineStyle=solidLine, int=1);
void setTextColor(color);
void setTextPosition(int, int);
int show(int);
virtual void size(int, int);
int textHeight();
int textWidth(char *);
void textPosition(int &, int &);
virtual void timer();
int top();
void uncheckMenuItem(int);
void update();
void vector(const int, const int, const int, const int);
int width();
void drawBitmap(bitmap,int,int,int,int);
bitmap loadBitmap(int);
bitmap loadBitmap(const char *);
winostream wout;
// friends
friend class winostream;
friend class menu;
protected:
void createBrush();
void createPen();
void deleteBrush();
void deletePen();
void _initialize_();
void print(char *);
COLORREF brushColor;
color cartesianColor;
lineStyle cartesianStyle;
int cartesianWidth;
int charHeight;
int charWidth;
int clientX;
int clientY;
control *ctl[MAXCONTROLS];
int ctlCount;
HBRUSH currentBrush;
HPEN currentPen;
HDC device;
color gridColor;
lineStyle gridStyle;
int gridWidth;
HMENU hmenu;
int hScrollPos;
HWND hwnd;
int initialHeight;
int initialWidth;
int initialX;
int initialY;
POINT lowerRight;
int maxHScroll;
int maxVScroll;
int maxX;
int maxY;
TEXTMETRIC metric;
menu *mnu[MAXMENUS];
int mnuCount;
char *name;
POINT nextPos;
COLORREF penColor;
int penStyle;
int penWidth;
POINT upperLeft;
int vScrollPos;
HINSTANCE prevInstance;
POINT prevPos;
int tabStop[10];
COLORREF textColor;
HINSTANCE thisInstance;
char *title;
};
// --- Application Class -----------------------------------------------
//
// Application is the basic framework class. It is a special kind
// of window that is opened when the application is started. By
// itself, application is not very functional. If you create an
// instance of application and send it the message "run", a blank
// window is displayed. The only functionality available is to
// resize, move, minimize, maximize, and close the window (i.e.,
// terminate the application). The main work done by an application
// that is visible to the user is performed by the "paint" method.
// Normally, you will create a subclass of application and override
// the "paint" method (and probably other methods) to perform the
// processing required by your application.
//----------------------------------------------------------------------
class application : public window
{
public:
// constructor
application(char *title,
int width = CW_USEDEFAULT, int height = CW_USEDEFAULT,
int x = CW_USEDEFAULT, int y = CW_USEDEFAULT);
// destructor
virtual ~application();
// event handling
virtual void create();
virtual void doubleClick(int, int);
virtual void mouseDown(int, int);
virtual void mouseRDown(int, int);
virtual void mouseMDown(int, int);
virtual void paint();
virtual void size(int, int);
virtual void timer();
// non-event behavior
virtual int okBox(const char *, char * = 0);
virtual int debugBox(char *);
virtual void run();
virtual void quit();
virtual void startTimer(unsigned int = 1000);
virtual void stopTimer();
virtual void sendTimerMessage();
private:
int timerInterval;
};
// --- childWindow Class -----------------------------------------------
//
// A childWindow is a separate window from the main application
// window.
//----------------------------------------------------------------------
class childWindow : public window
{
public:
// constructor
childWindow(char *title,
int width = CW_USEDEFAULT, int height = CW_USEDEFAULT,
int x = CW_USEDEFAULT, int y = CW_USEDEFAULT);
// destructor
virtual ~childWindow();
// event handling
void create();
void doubleClick(int, int);
void mouseDown(int, int);
void mouseRDown(int, int);
void mouseMDown(int, int);
void paint();
void size(int, int);
void timer();
// non-event behavior
void run();
};
// --- Menu Class ------------------------------------------------------
//
// The menu class implements menus.
//----------------------------------------------------------------------
class menu
{
public:
// constructors
menu(window &aWindow, char *text, char choice = '\0');
// destructor
virtual ~menu();
// add the menu item to menu
virtual void add(basicMenuItem & anItem);
// add the menu to a window
virtual void add(window & aWindow);
// create the control
virtual void create();
// friends
friend class window;
private:
window &theWindow;
char *textValue;
char choiceValue;
basicMenuItem *item[MAXITEMS];
int itemCount;
HMENU handleValue;
};
// --- Control Class ---------------------------------------------------
//
// The control class is an abstract superclass for all controls.
//----------------------------------------------------------------------
class control
{
public:
// constructors
control(window &aWindow);
// equality operator
int operator == (const control &);
// return the identifier
virtual int id() const;
// select the control
virtual void select() = 0;
// create the control
virtual void create() = 0;
protected:
window &theWindow;
int idValue;
HWND hwnd;
};
// --- Menu Item Class -------------------------------------------------
//
// The menu items class implements individual menu items.
//----------------------------------------------------------------------
class basicMenuItem : public control
{
public:
// constructors
basicMenuItem(window &aWindow, char *text, char choice,
menu &aMenu);
// destructor
virtual ~basicMenuItem();
// select the control
virtual void select();
// create the control
virtual void create();
// friends
friend class menu;
protected:
menu &menuValue;
char *textValue;
char choiceValue;
};
template <class T> class menuItem : public basicMenuItem
{
public:
menuItem(T &anApp, char *text, char choice, menu &aMenu)
: basicMenuItem(anApp, text, choice, aMenu), app(anApp)
{ /* do nothing */ }
// select the menu item
void select()
{ /* do nothing */ }
protected:
T &app;
};
// --- Button Classes --------------------------------------------------
//
// The button class implements buttons.
//----------------------------------------------------------------------
class basicButton : public control
{
public:
// constructors
basicButton(window &aWindow, char *aTitle = "Button",
int aWidth = 50, int aHeight = 50, int x = 0, int y = 0);
basicButton(const basicButton &);
// destructor
virtual ~basicButton();
// assignment operator
basicButton & operator = (const basicButton &);
// select the control
virtual void select();
// create the control
virtual void create();
protected:
char *titleValue;
POINT upperLeft;
int heightValue;
int widthValue;
};
template <class T> class button : public basicButton
{
public:
// constructor
button(T &anApp, char *aTitle,
int aWidth, int aHeight, int x, int y)
: basicButton(anApp, aTitle, aWidth, aHeight, x, y), app(anApp)
{ /* do nothing */ }
// select the button
void select()
{ /* do nothing */ }
protected:
T &app;
};
// --- EditText Class --------------------------------------------------
//
// The editText class implements fields of editable text.
//----------------------------------------------------------------------
class editText
{
public:
// constructors
editText();
editText(window *, int, int, int, int, int,
textAlign = leftText, int = 1, char * = 0);
editText(const editText &);
// destructor
~editText();
// set input focus on
void setFocus();
// get the maximum number of characters
int size();
// copy text to string
char *text(char *);
// assignment operator
editText & operator = (const editText &);
// "get from" operator
editText & operator >> (char *);
// "put to" operator
editText & operator << (char *);
editText & operator << (char);
editText & operator << (int);
editText & operator << (editText & (*)(editText &));
private:
window *win;
int idValue;
POINT upperLeft;
int heightValue;
int widthValue;
DWORD style;
HWND hwnd;
};
// --- Static Text Class -----------------------------------------------
//
// The staticText class implements fields of fixed text.
//----------------------------------------------------------------------
class staticText
{
public:
// constructors
staticText();
staticText(window *, int, int, int, int,
textAlign = leftText, int = 0, char * = 0);
staticText(const staticText &);
// destructor
~staticText();
// assignment operator
staticText & operator = (const staticText &);
// equality operator
int operator == (const staticText &);
// text output
staticText & operator << (char *);
staticText & operator << (char);
staticText & operator << (int);
staticText & operator << (staticText & (*)(staticText &));
protected:
window *win;
POINT upperLeft;
int heightValue;
int widthValue;
DWORD style;
HWND hwnd;
};
// --- List Box Class --------------------------------------------------
//
// The listBox class implements a scrollable list of strings.
//----------------------------------------------------------------------
class listBox
{
public:
// constructors
listBox();
listBox(window *, int, int, int, int, int, int = 1);
listBox(const listBox &);
// destructor
~listBox();
// list manipulation
void clear();
char *add(char *);
// assignment operator
listBox & operator = (const listBox &);
protected:
window *win;
int idValue;
POINT upperLeft;
int heightValue;
int widthValue;
DWORD style;
HWND hwnd;
};
//--- Templates --------------------------------------------------------
template <class T>
T maximum(T x, T y)
{
return (x > y) ? x : y;
};
template <class T>
T minimum(T x, T y)
{
return (x < y) ? x : y;
};
template <class T>
class WO_MANIP
{
public:
WO_MANIP(winostream &(*ff)(winostream &, T), T ii)
: f(ff), i(ii)
{ }
friend winostream & operator << (winostream &wos, WO_MANIP &m)
{ return (*m.f)(wos, m.i); }
private:
T i;
winostream &(*f)(winostream &, T);
};
template <class T>
class WO_MANIP2
{
public:
WO_MANIP2(winostream & (*ff)(winostream &, T, T), T aa, T bb)
: f(ff), a(aa), b(bb)
{ }
friend winostream & operator << (winostream &wos, WO_MANIP2 &m)
{ return (*m.f)(wos, m.a, m.b); }
private:
T a;
T b;
winostream &(*f)(winostream &, T, T);
};
//--- Function Prototypes ----------------------------------------------
editText &eraseText(editText &);
staticText &eraseText(staticText &);
winostream &dec(winostream &);
winostream &hex(winostream &);
winostream &oct(winostream &);
winostream &endl(winostream &);
winostream &eraseToEol(winostream &);
winostream &operator << (winostream &wos, winostream &(*)(winostream &));
WO_MANIP<streamBase> setbase(streamBase);
WO_MANIP<color> setcolor(color);
WO_MANIP2<int> setpos(int, int);
WO_MANIP<int> setprecision(int);
WO_MANIP<int> setw(int);
void debugBox();
int randomInt(int, int);
//--- External Variables -----------------------------------------------
//extern ostrstream dout; // debug output stream
#endif