summaryrefslogtreecommitdiff
path: root/app/wlib/mswlib/mswbox.c
blob: 04b365664cc7c7d655d3329c5235397ef2767d05 (plain)
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
#include <windows.h>
#include <string.h>
#include <malloc.h>
#include <stdlib.h>
#include <commdlg.h>
#include <math.h>
#include "mswint.h"

/*
 *****************************************************************************
 *
 * Boxes
 *
 *****************************************************************************
 */

struct wBox_t {
		WOBJ_COMMON
		wBoxType_e boxTyp;
		};

#define B (1)
#define W (2)
#define SETCOLOR( S, N ) \
		if ( lastColor != colors[bb->boxTyp][S][N] ) { \
			lastColor = colors[bb->boxTyp][S][N]; \
			SetROP2( hDc, (lastColor==B?R2_BLACK:R2_WHITE) ); \
		}


void wBoxSetSize(
		wBox_p bb,
		wPos_t w,
		wPos_t h )
{
	bb->w = w;
	bb->h = h;
}


static void repaintBox( HWND hWnd, wControl_p b )
{						  
	HDC hDc;
	wBox_p bb = (wBox_p)(b);
	wPos_t x0, y0, x1, y1;
	char lastColor;
	int lastRop;
	static char colors[8][4][2] = {
		{ /* ThinB	*/ {B,0}, {B,0}, {B,0}, {B,0} },
		{ /* ThinW	*/ {W,0}, {W,0}, {W,0}, {W,0} },
		{ /* AboveW */ {W,0}, {W,0}, {B,0}, {B,0} },
		{ /* BelowW */ {B,0}, {B,0}, {W,0}, {W,0} },
		{ /* ThickB */ {B,B}, {B,B}, {B,B}, {B,B} },
		{ /* ThickW */ {W,W}, {W,W}, {W,W}, {W,W} },
		{ /* RidgeW */ {W,B}, {W,B}, {B,W}, {B,W} },
		{ /* TroughW*/ {B,W}, {B,W}, {W,B}, {W,B} } };

	x0 = bb->x;
	x1 = bb->x+bb->w;
	y0 = bb->y;
	y1 = bb->y+bb->h;
	hDc = GetDC( hWnd );
	MoveTo( hDc, x0, y1 );
	/*SETCOLOR( 0, 0 );*/
	lastColor = colors[bb->boxTyp][0][0];
	lastRop = SetROP2( hDc, (lastColor==B?R2_BLACK:R2_WHITE) );
	LineTo( hDc, x0, y0 );
	SETCOLOR( 1, 0 );
	LineTo( hDc, x1, y0 );
	SETCOLOR( 2, 0 );
	LineTo( hDc, x1, y1 );
	SETCOLOR( 3, 0 );
	LineTo( hDc, x0, y1 );
	if (bb->boxTyp >= wBoxThickB) {
		x0++; y0++; x1--; y1--;
		MoveTo( hDc, x0, y1 );
		SETCOLOR( 0, 1 );
		LineTo( hDc, x0, y0 );
		SETCOLOR( 1, 1 );
		LineTo( hDc, x1, y0 );
		SETCOLOR( 2, 1 );
		LineTo( hDc, x1, y1 );
		SETCOLOR( 3, 1 );
		LineTo( hDc, x0, y1 );
	}
	SetROP2( hDc, lastRop );
	ReleaseDC( hWnd, hDc );
}


static callBacks_t boxCallBacks = {
		repaintBox,
		NULL,
		NULL };

wBox_p wBoxCreate(
		wWin_p	parent,
		wPos_t	origX,
		wPos_t	origY,
		const char	* labelStr,
		wBoxType_e typ,
		wPos_t	width,
		wPos_t	height )
{
	wBox_p b;
	int index;

	b = (wBox_p)mswAlloc( parent, B_BOX, labelStr, sizeof *b, NULL, &index );
	b->boxTyp = typ;

	b->x = origX;
	b->y = origY;
	b->w = width;
	b->h = height;
	mswAddButton( (wControl_p)b, FALSE, NULL );
	mswCallBacks[B_BOX] = &boxCallBacks; 
	repaintBox( ((wControl_p)parent)->hWnd, (wControl_p)b );
	return b;
}