File: vcanvas.cpp

package info (click to toggle)
libv1.22 1.22-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 7,380 kB
  • ctags: 9,765
  • sloc: cpp: 58,097; ansic: 6,814; makefile: 1,597; java: 515; sh: 24
file content (594 lines) | stat: -rw-r--r-- 15,674 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
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
//===============================================================
// vCanvas - a scrolling window canvas for drawing
//
// Copyright (C) 1995,1996, 1997, 1998  Bruce E. Wampler
//
// This file is part of the V C++ GUI Framework, and is covered
// under the terms of the GNU Library General Public License,
// Version 2. This library has NO WARRANTY. See the source file
// vapp.cxx for more complete information about license terms.
//===============================================================
//#include <stdio.h>

#include <v/vwin32.h>		// for Win 32 stuff
#include <v/vcanvas.h>		// our header
#include <v/vwindow.h>		// need to use some vwindow stuff


    VCursor vCanvasPane::_currentCursor = -1;	// for cursor

//================>>> vCanvasPane::vCanvasPane <<<========================
  vCanvasPane::vCanvasPane(PaneType pt) : vPane(pt)
  {
    SysDebug(Constructor,"vCanvasPane::vCanvasPane() constructor\n")

    _cpDC = 0;		// no pane DC
    _compressRedraw = 1;
    _currentCursor = VC_Arrow;
  }

//================>>> vCanvasPane::~vCanvasPane <<<========================
  vCanvasPane::~vCanvasPane()
  {
    SysDebug(Destructor,"vCanvasPane::~vCanvasPane() destructor\n")
    if (_cpDC != 0)
	delete _cpDC;	// free the DC
  }

//==================>>> vCanvasPane::initialize <<<==========================
  void vCanvasPane::initialize(vWindow* pWindow, HWND pWidget)
  {

    _HScrlShown = 100;
    _HScrlTop =  0;
    _VScrlShown = 100;
    _VScrlTop =  0;

    // now, build the menu items in the widget provided

    vPane::initialize(pWindow, pWidget);	// initialize base class

    pWindow->_canvasPane = this;		// easy access to/from window
    _drawWindow = pWindow->winHwnd();

    _hasFocus = 0;	// we don't start out with focus

    // set the height and width of our window

    if (theApp->simSDI())
      {
	_height = _parentWin->_WinHeight;
	_width = _parentWin->_WinWidth;
      }
    else
      {
	RECT rc;

	::GetClientRect(_drawWindow,&rc);	// area of the window

	_height = rc.bottom - rc.top;	// update the local stuff
	_width = rc.right - rc.left;
      }


    // After the drawing widget has been created, we can create
    // the V DC for it to use.

    CreateDC();

    _parentWin->_WinHeight = _height;
    _parentWin->_WinWidth = _width;

    SetHScroll(_HScrlShown, 0);	// initial values for scroll bar
    SetVScroll(_VScrlShown, 0);

    _HOn = _VOn = 0;			// both start out off
    _parentWin->SetWinCursor(_currentCursor);

    // Now need to fake out enter focus so the first mouse
    // click is ignored.
    if (!_hasFocus)
      {
	_hasFocus = 1;
	EnterFocus();		// call the virtual function
      }

    if (theApp->simSDI())
    	SetWidthHeight(_width, _height);
  }

//==================>>> vCanvasPane::CreateDC <<<========================
  void vCanvasPane::CreateDC(void)
  {
    if (!_cpDC)
	_cpDC = new vCanvasPaneDC(this);	// create a CanvasPaneDC
  }

//====================>>> vCanvasPane::ShowPane <<<======================
  void vCanvasPane::ShowPane(int OnOrOff) VCONST
  {
    if (OnOrOff)
      {
	::ShowWindow(_drawWindow, SW_RESTORE);
      }
    else
      {
	::ShowWindow(_drawWindow, SW_MINIMIZE);
      }
  }

//=====================>>> vCanvasPane::SetWidthHeight <<<=========================
  void vCanvasPane::SetWidthHeight(int width, int height)
  {
    if (height <= 0 || width <= 0)
	return;
    _parentWin->_WinHeight = _height = height;
    _parentWin->_WinWidth = _width = width;

    RECT rect;
    ::GetWindowRect(_drawWindow,&rect);		// rect of  canvas

    if (theApp->simSDI())
      {
        RECT winRect;
        int cW = rect.right - rect.left;	// Width of  canvas
    	int cH = rect.bottom - rect.top;	// height of canvas
    	::GetWindowRect(theApp->winHwnd(),&winRect);

    	int wW = winRect.right - winRect.left - cW;
    	int wH = winRect.bottom - winRect.top - cH;	// WH of  window

	::MoveWindow(theApp->winHwnd(),winRect.left,winRect.top, width+wW,
	   height + wH,1);
      }
    else
      {
        RECT ar;
    	::GetWindowRect(theApp->winClientHwnd(), &ar);
        int left = (rect.left >= ar.left) ? rect.left - ar.left : rect.left;
        int top = (rect.top >= ar.top) ? rect.top - ar.top : rect.top;
	::MoveWindow(_drawWindow,left, top, width, height,1);
      }
  }


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

//------------------------- cursor Stuff ---------------------------------

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

//==================>>> vCanvasPane::SetCursor <<<============================
  void vCanvasPane::SetCursor(VCursor id)
  {
    // Set to current cursor

    if (id < VC_None || id > VC_LAST)
      {
	SysDebug1(BadVals,"vCanvasPane::SetCursor(id=%d)\n",id)
	return;
      }

    if (id == VC_None)		// special case
	UnSetCursor();

    SysDebug1(WindowEvents,"vCanvasPane::SetCursor(id=%d)%d\n",id)

    _currentCursor = id;
    _parentWin->SetWinCursor(_currentCursor);
  }

//===================>>> vCanvasPane::UnSetCursor <<<=========================
  void vCanvasPane::UnSetCursor(void)
  {
    _currentCursor = CA_None;
  }

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

//----------------------- Scrolling Stuff ---------------------------------

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

//=======================>>> vCanvasPane::HPage <<<============================
  void vCanvasPane::HPage(int Shown, int Top)
  {
    // This is the main way a user app gets scrolling events, and
    // will usually override this guy to handle what is actually
    // drawn in the canvas window.
    // This should then be called to actually change the display.

    SysDebug2(WindowEvents,"vCanvasPane::HPage(Shown: %d, Top: %d)\n",Shown, Top);

    SetHScroll(Shown,Top);
  }

//=======================>>> vCanvasPane::HScroll <<<==========================
  void vCanvasPane::HScroll(int step)
  {
    // This is the way the user app gets step events - either page or
    // single step events. The default doesn't have to do anything.

    SysDebug1(WindowEvents,"vCanvasPane::HScroll(%d)\n",step);

    if (step < 0)
      {
	if (_HScrlTop - 1 >= 0)
	    SetHScroll(_HScrlShown, --_HScrlTop);
      }
    else
      {
	if (_HScrlTop + 1 <= 100)
	    SetHScroll(_HScrlShown, ++_HScrlTop);
      }
  }

//=====================>>> vCanvasPane::ShowHScroll <<<=========================
  void vCanvasPane::ShowHScroll(int OnOff)
  {
    if (OnOff)			// Turn on
      {
	if (_HOn)		// Already on
	    return;
	_HOn = 1;
	::ShowScrollBar(_drawWindow, SB_HORZ, 1);
	::SetScrollRange(_drawWindow,SB_HORZ, 0, 100, 0); // set range to 0-100
      }
    else			// Turn off
      {
	if (!_HOn)		// Already off
	    return;
	_HOn = 0;
	::ShowScrollBar(_drawWindow, SB_HORZ, 0);
      }
  }

//=====================>>> vCanvasPane::ShowVScroll <<<=========================
  void vCanvasPane::ShowVScroll(int OnOff)
  {
    if (OnOff)			// Turn on
      {
	if (_VOn)		// Already on
	    return;
	_VOn = 1;
	::ShowScrollBar(_drawWindow, SB_VERT, 1);
	::SetScrollRange(_drawWindow,SB_VERT, 0, 100, 0);
      }
    else			// Turn off
      {
	if (!_VOn)		// Already off
	    return;
	_VOn = 0;
	::ShowScrollBar(_drawWindow, SB_VERT, 0);
      }

  }

//=====================>>> vCanvasPane::SetHScroll <<<=========================
  void vCanvasPane::SetHScroll(int Shown, int Top)
  {
    // Make sure we are setting to valid values, and are changing things!

    if (Shown < 0 || Shown > 100 || Top < 0 || Top > 100)
	return;

    _HScrlShown = Shown;
    _HScrlTop = Top;
#ifndef VWIN16
    SCROLLINFO si;
    si.cbSize = sizeof(si);
    si.fMask = SIF_POS | SIF_PAGE;
    si.nPage = _HScrlShown;
    si.nPos = _HScrlTop;
    ::SetScrollInfo(_drawWindow, SB_HORZ, &si, 1);
#else
    ::SetScrollPos(_drawWindow, SB_HORZ, _HScrlTop, 1);	// Windows just has top
#endif
  }

//========================>>> vCanvasPane::VPage <<<===========================
  void vCanvasPane::VPage(int Shown, int Top)
  {

    SysDebug2(WindowEvents,"vCanvasPane::VPage(Shown: %d, Top: %d)\n",Shown, Top);

    SetVScroll(Shown,Top);

  }

//========================>>> vCanvasPane::VScroll <<<=========================
  void vCanvasPane::VScroll(int step)
  {
    // This is the way the user app gets step events - either page or
    // single step events. Default updates the display

    SysDebug1(WindowEvents,"vCanvasPane::VScroll(%d)\n",step);
    if (step < 0)
      {
	if (_VScrlTop - 1 >= 0)
	    SetVScroll(_VScrlShown, --_VScrlTop);
      }
    else
      {
	if (_VScrlTop + 1 <= 100)
	    SetVScroll(_VScrlShown, ++_VScrlTop);
      }

  }

//=====================>>> vCanvasPane::GetVScroll <<<=========================
  int vCanvasPane::GetVScroll(int& Shown, int& Top) VCONST	// V:1.13
  {
    Shown = _VScrlShown; Top = _VScrlTop;
    return _VOn;
  }

//=====================>>> vCanvasPane::GetHScroll <<<=========================
  int vCanvasPane::GetHScroll(int& Shown, int& Top) VCONST	// V:1.13
  {
    Shown = _HScrlShown; Top = _HScrlTop;
    return _HOn;
  }

//=====================>>> vCanvasPane::SetVScroll <<<=========================
  void vCanvasPane::SetVScroll(int Shown, int Top)
  {
    // Make sure we are setting to valid values, and are changing things!

    if (Shown < 0 || Shown > 100 || Top < 0 || Top > 100)
	return;

    _VScrlShown = Shown;
    _VScrlTop = Top;
#ifndef VWIN16
    SCROLLINFO si;
    si.cbSize = sizeof(si);
    si.fMask = SIF_POS | SIF_PAGE;
    si.nPage = _VScrlShown;
    si.nPos = _VScrlTop;
    ::SetScrollInfo(_drawWindow, SB_VERT, &si, 1);
#else
    ::SetScrollPos(_drawWindow, SB_VERT, _VScrlTop, 1);	// Windows just has top
#endif
  }

//====================>>> vCanvasPane::HScrollEV <<<=======================
  void vCanvasPane::HScrollEV(int code, int pos, HWND /* control */)
  {

    switch (code)
      {
	case SB_BOTTOM:			// Scroll to bottom
	    _HScrlTop = 100;
	    HPage(_HScrlShown, 100);
	    break;

	case SB_LINEDOWN:		// Down one line
	    HScroll(1);
	    break;

	case SB_LINEUP:			// Up one line
	    HScroll(-1);
	    break;

	case SB_PAGEDOWN:		// Page Down - use 10
	    if (_HScrlTop <= 90)
	      {
		_HScrlTop += 10;
		HPage(_HScrlShown, _HScrlTop);
	      }
	    else
	      {
		_HScrlTop = 100;
		HPage(_HScrlShown, 100);
	      }
	    break;

	case SB_PAGEUP:			// Page Up - use -10
	    if (_HScrlTop >= 10)
	      {
		_HScrlTop -= 10;
		HPage(_HScrlShown, _HScrlTop);
	      }
	    else
	      {
		_HScrlTop = 0;
		HPage(_HScrlShown, 0);
	      }
	    break;

	case SB_THUMBPOSITION:		// move to position given
	    _HScrlTop = pos;
	    HPage(_HScrlShown, pos);
	    break;

	case SB_THUMBTRACK:		// for continuous motion - ignore
	    break;

	case SB_TOP:			// top of scroll
	    _HScrlTop = 0;
	    HPage(_HScrlShown, 0);
	    break;
      }
  }

//====================>>> vCanvasPane::VScrollEV <<<=======================
  void vCanvasPane::VScrollEV(int code, int pos, HWND /*control */)
  {
    switch (code)
      {
	case SB_BOTTOM:			// Scroll to bottom
	    _VScrlTop = 100;
	    VPage(_VScrlShown, 100);
	    break;

	case SB_LINEDOWN:		// Down one line
	    VScroll(1);
	    break;

	case SB_LINEUP:			// Up one line
	    VScroll(-1);
	    break;

	case SB_PAGEDOWN:		// Page Down - use 10
	    if (_VScrlTop <= 90)
	      {
		_VScrlTop += 10;
		VPage(_VScrlShown, _VScrlTop);
	      }
	    else
	      {
		_VScrlTop = 100;
		VPage(_VScrlShown, 100);
	      }
	    break;

	case SB_PAGEUP:			// Page Up - use -10
	    if (_VScrlTop >= 10)
	      {
		_VScrlTop -= 10;
		VPage(_VScrlShown, _VScrlTop);
	      }
	    else
	      {
		_VScrlTop = 0;
		VPage(_VScrlShown, 0);
	      }
	    break;

	case SB_THUMBPOSITION:		// move to position given
	    _VScrlTop = pos;
	    VPage(_VScrlShown, pos);
	    break;

	case SB_THUMBTRACK:		// continuous, ignore
	    break;

	case SB_TOP:
	    _VScrlTop = 0;			// top of scroll
	    VPage(_VScrlShown, 0);
	    break;
      }
  }

// ************************************************************************
//
// Redraw/resize/focus
//
// ************************************************************************


//=====================>>> vCanvasPane::ExposeEV <<<==========================
  void vCanvasPane::ExposeEV(void)
  {
    int x = 0, y = 0, height = 0, width = 0;
    RECT rect;
    if (::GetUpdateRect(_drawWindow, &rect, 0))
      {
  	x = rect.left ; y = rect.top;
  	height = rect.bottom - rect.top;
  	width = rect.right - rect.left;
     	_cpDC->ClearRect(x, y, width, height);
      }

    Redraw(x, y , width, height);
  }

//=====================>>> vCanvasPane::EnterFocus <<<========================
  void vCanvasPane::EnterFocus(void)
  {
    SysDebug(WindowEvents,"vCanvasPane::EnterFocus()\n")
  }

//=====================>>> vCanvasPane::EnterEV <<<==========================
  void vCanvasPane::EnterEV(void)
  {
    if (_hasFocus)		// don't double enter focus
	return;
    _hasFocus = 1;

    EnterFocus();		// call the virtual function
  }

//======================>>> vCanvasPane::FontChanged <<<===========================
  void vCanvasPane::FontChanged(VCONST vFont& vf)
  {
    // Called when the font is changed.

    SysDebug1(WindowEvents,"vCanvasPane::FontChanged(%d)\n",vf)
  }

//=====================>>> vCanvasPane::LeaveFocus <<<=======================
  void vCanvasPane::LeaveFocus()
  {
    SysDebug(WindowEvents,"vCanvasPane::LeaveFocus()\n")
  }

//=====================>>> vCanvasPane::LeaveEV <<<==========================
  void vCanvasPane::LeaveEV()
  {
    if (!_hasFocus)		// don't double leave focus
	return;
    _hasFocus = 0;

    LeaveFocus();		// call the virtual function
  }

//=====================>>> vCanvasPane::MouseDown <<<==========================
  void vCanvasPane::MouseDown(int x, int y, int button)
  {
    // Mouse events in vCanvasPane are no-ops.

#ifdef vDEBUG		// Don't have a SysDebug4 macro, so do it by hand
    char msg[10];
    sprintf(msg,"Button = %d",button);
#endif

    SysDebug3(MouseEvents,"vCanvasPane::MouseDown(x:%d,y:%d,btn:%d)\n",x,y,button)
  }

//=====================>>> vCanvasPane::MouseUp <<<============================
  void vCanvasPane::MouseUp(int x, int y, int button)
  {
    // Mouse events in vCanvasPane are no-ops.

    SysDebug3(MouseEvents,"vCanvasPane::MouseUp(x:%d,y:%d,btn:%d)\n",x,y,button)
  }

//=====================>>> vCanvasPane::MouseMove <<<==========================
  void vCanvasPane::MouseMove(int x, int y, int button)
  {
    // Mouse events in vCanvasPane are no-ops.

    SysDebug3(MouseEvents,"vCanvasPane::MouseMove(x:%d,y:%d,btn:%d)\n",x,y,button)
  }

//=======================>>> vCanvasPane::Redraw <<<==========================
  void vCanvasPane::Redraw(int x, int y, int width, int height)
  {
    // Redraw in vCanvasPane is a no-op.

#ifdef vDEBUG		// Don't have a SysDebug4 macro, so do it by hand
    if (DebugState.WindowEvents && DebugState.System)
	fprintf(stderr,"vCanvasPane::Redraw(x=%d, y=%d, w=%d, h=%d)\n",x,y,width,height);
#endif

  }

//=====================>>> vCanvasPane::Resize <<<============================
  void vCanvasPane::Resize(int newW, int newH)
  {
    // This is the routine the user will override to intercept size changes

    SysDebug2(WindowEvents,"vCanvasPane::Resize(newH:%d, newW:%d)\n",newH,newW)

  }

//==================>>> vCanvasPane::ResizeEV <<<========================
  void vCanvasPane::ResizeEV(int w, int h)
  {
    _parentWin->_WinHeight = _height = h;
    _parentWin->_WinWidth = _width = w;

    Resize((int)w, (int)h);	// Call the virtual function
  }