summaryrefslogtreecommitdiffstats
path: root/Mac/Wastemods/WETabs.c
blob: 6f59e371cae38093d01d9a334c70de3675b2d374 (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
/*
 *	WETabs.c
 *
 *	WASTE TABS PACKAGE
 *	Routines for installing/removing tab hooks; accessors
 *
 */


#include "WETabs.h"
#include "WETabHooks.h"

#ifndef __ERRORS__
#include <Errors.h>
#endif

/* static UPP's */
static WEDrawTextUPP		_weTabDrawTextProc = nil;
static WEPixelToCharUPP		_weTabPixelToCharProc = nil;
static WECharToPixelUPP		_weTabCharToPixelProc = nil;
static WELineBreakUPP		_weTabLineBreakProc = nil;

pascal OSErr WEInstallTabHooks(WEReference we)
{
	OSErr err;

	/* if first time, create routine descriptors */
	if (_weTabDrawTextProc == nil)
	{
		_weTabDrawTextProc = NewWEDrawTextProc(_WETabDrawText);
		_weTabPixelToCharProc = NewWEPixelToCharProc(_WETabPixelToChar);
		_weTabCharToPixelProc = NewWECharToPixelProc(_WETabCharToPixel);
		_weTabLineBreakProc = NewWELineBreakProc(_WETabLineBreak);
	}

	if ((err = WESetInfo( weDrawTextHook, &_weTabDrawTextProc, we )) != noErr)
	{
		goto cleanup;
	}
	if ((err = WESetInfo( wePixelToCharHook, &_weTabPixelToCharProc, we )) != noErr)
	{
		goto cleanup;
	}
	if ((err = WESetInfo( weCharToPixelHook, &_weTabCharToPixelProc, we )) != noErr)
	{
		goto cleanup;
	}
	if ((err = WESetInfo( weLineBreakHook, &_weTabLineBreakProc, we )) != noErr)
	{
		goto cleanup;
	}

cleanup:
	return err;
}

pascal OSErr WERemoveTabHooks(WEReference we)
{
	UniversalProcPtr nullHook = nil;
	OSErr err;

	if ((err = WESetInfo( weDrawTextHook, &nullHook, we )) != noErr)
	{
		goto cleanup;
	}
	if ((err = WESetInfo( wePixelToCharHook, &nullHook, we )) != noErr)
	{
		goto cleanup;
	}
	if ((err = WESetInfo( weCharToPixelHook, &nullHook, we )) != noErr)
	{
		goto cleanup;
	}
	if ((err = WESetInfo( weLineBreakHook, &nullHook, we )) != noErr)
	{
		goto cleanup;
	}

cleanup:
	return err;
}

pascal Boolean WEIsTabHooks(WEReference we)
{
	WEPixelToCharUPP hook = nil;

	/* return true if our tab hooks are installed */

	return 	( _weTabPixelToCharProc != nil ) &&
			( WEGetInfo( wePixelToCharHook, &hook, we ) == noErr) &&
			( _weTabPixelToCharProc == hook );
}

pascal SInt16 WEGetTabSize(WEReference we)
{
	SInt32 result;

	if (WEGetUserInfo( kTabSizeTag, &result, we ) != noErr)
	{
		result = kDefaultTabSize;
	}
	return result;
}

pascal OSErr WESetTabSize(SInt16 tabSize, WEReference we)
{
	//	make sure tabSize is a reasonable size
	if ((tabSize < kMinTabSize) || (tabSize > kMaxTabSize))
	{
		return paramErr;
	}
	else
	{
		return WESetUserInfo( kTabSizeTag, tabSize, we );
	}
}