summaryrefslogtreecommitdiffstats
path: root/src/mac/gss/GSSSample.cp
blob: 6d13a8aba3b8296da8b04ff34e7236fcc6c4a48f (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
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
// ===========================================================================
//	GSSSample.cp
//	©1997 Massachusetts Institute of Technology, All Rights Reserved
//	Based on <PP StarterApp>.cp by Metrowerks Inc.
//	Modification by meeroh@mit.edu
//	Started 2/28/97
// ===========================================================================
//
// Implementation of CGSSSample, an application class derived from LDocApplication
// Handles top-level chores: initialization, destruction, AppleEvent dispatch

#include "gss.h"
#include "GSSSample.h"

#include <LGrowZone.h>
#include <LWindow.h>
#include <PP_Messages.h>
#include <PP_Resources.h>
#include <PPobClasses.h>
#include <UDrawingState.h>
#include <UMemoryMgr.h>
#include <URegistrar.h>
#include <LEditField.h>
#include <LActiveScroller.h>

extern "C" {
#include <mit-sock.h>
}

// for mit-sock
OSErr MacOSErr;

#include "CGSSDocument.h"

// ===========================================================================
//		€ Main Program
// ===========================================================================

void main(void)
{
									// Set Debugging options
	SetDebugThrow_(debugAction_Alert);
	SetDebugSignal_(debugAction_Alert);

	InitializeHeap(3);				// Initialize Memory Manager
									// Parameter is number of Master Pointer
									//   blocks to allocate
	
									// Initialize standard Toolbox managers
	UQDGlobals::InitializeToolbox(&qd);
	
	new LGrowZone(20000);			// Install a GrowZone function to catch
									//    low memory situations.

	CGSSSample theApp;
	theApp.Run();
}


// ---------------------------------------------------------------------------
//		€ CGSSSample
// ---------------------------------------------------------------------------
//	Constructor

CGSSSample::CGSSSample():
	mGSSDocument (nil)
{
	// Register functions to create core PowerPlant classes
	
	URegistrar::RegisterClass(LButton::class_ID,		(ClassCreatorFunc) LButton::CreateButtonStream);
	URegistrar::RegisterClass(LCaption::class_ID,		(ClassCreatorFunc) LCaption::CreateCaptionStream);
	URegistrar::RegisterClass(LDialogBox::class_ID,		(ClassCreatorFunc) LDialogBox::CreateDialogBoxStream);
	URegistrar::RegisterClass(LEditField::class_ID,		(ClassCreatorFunc) LEditField::CreateEditFieldStream);
	URegistrar::RegisterClass(LPane::class_ID,			(ClassCreatorFunc) LPane::CreatePaneStream);
	URegistrar::RegisterClass(LScroller::class_ID,		(ClassCreatorFunc) LScroller::CreateScrollerStream);
	URegistrar::RegisterClass(LStdControl::class_ID,	(ClassCreatorFunc) LStdControl::CreateStdControlStream);
	URegistrar::RegisterClass(LStdButton::class_ID,		(ClassCreatorFunc) LStdButton::CreateStdButtonStream);
	URegistrar::RegisterClass(LTextEdit::class_ID,		(ClassCreatorFunc) LTextEdit::CreateTextEditStream);
	URegistrar::RegisterClass(LView::class_ID,			(ClassCreatorFunc) LView::CreateViewStream);
	URegistrar::RegisterClass(LWindow::class_ID,		(ClassCreatorFunc) LWindow::CreateWindowStream);

	URegistrar::RegisterClass(LActiveScroller::class_ID,		(ClassCreatorFunc) LActiveScroller::CreateActiveScrollerStream);
//	URegistrar::RegisterClass(CGSSWindow::class_ID,				(ClassCreatorFunc) CGSSWindow::CreateGSSWindowStream);

	// Initialize sockets library	
	init_network (nil, true);
}


// ---------------------------------------------------------------------------
//		€ ~CGSSSample
// ---------------------------------------------------------------------------
//	Destructor
//

CGSSSample::~CGSSSample()
{
}

void
CGSSSample::StartUp ()
{
	// On startup, always create a new document
	MakeNewDocument ();
}

// ---------------------------------------------------------------------------
//		€ ObeyCommand
// ---------------------------------------------------------------------------
//	Respond to commands

Boolean
CGSSSample::ObeyCommand(
	CommandT	inCommand,
	void		*ioParam)
{
	Boolean		cmdHandled = true;

	switch (inCommand) {
	
		// Deal with command messages
		// Any that you don't handle will be passed to LDocApplication
 			
		case cmd_Close:
		// Quit when the window is closed
			inCommand = cmd_Quit;
			
		default:
			cmdHandled = LDocApplication::ObeyCommand (inCommand, ioParam);
			break;
	}
	
	return cmdHandled;
}

// ---------------------------------------------------------------------------
//		€ FindCommandStatus
// ---------------------------------------------------------------------------
//	This function enables menu commands as needed
//

void
CGSSSample::FindCommandStatus(
	CommandT	inCommand,
	Boolean		&outEnabled,
	Boolean		&outUsesMark,
	Char16		&outMark,
	Str255		outName)
{

	switch (inCommand) {
	
		// Return menu item status according to command messages.
		// Any that you don't handle will be passed to LDocApplication

		case cmd_Close:
			// Always enabled
			outEnabled = true;
			break;

		default:
			LDocApplication::FindCommandStatus(inCommand, outEnabled,
												outUsesMark, outMark, outName);
			break;
	}
}

// ---------------------------------------------------------------------------
//		€ MakeNewDocument
// ---------------------------------------------------------------------------
//	This function creates a new document
//

LModelObject*
CGSSSample::MakeNewDocument ()
{
	// There should be only one document!
	SignalIf_ (mGSSDocument != nil);
	
	return (mGSSDocument = new CGSSDocument ());
}


// ===========================================================================
// € Apple Event Handlers								Apple Event Handlers €
// ===========================================================================

void
CGSSSample::HandleAppleEvent (
	const AppleEvent&	inAppleEvent,
	AppleEvent&			outAEReply,
	AEDesc&				outResult,
	long				inAENumber)
{
	switch (inAENumber) {

		// Deal with AppleEvents
		// Any that you don't handle will be passed to LDocApplication

		case ae_Query:
		// Dispatch query to the document
			mGSSDocument -> HandleAppleEvent (inAppleEvent, outAEReply, outResult, inAENumber);
			break;

		default:
			LDocApplication::HandleAppleEvent (inAppleEvent, outAEReply, outResult, inAENumber);
			break;
	}
}