File: GPWindow.cpp

package info (click to toggle)
gnuplot 3.7.2-4
  • links: PTS
  • area: main
  • in suites: woody
  • size: 6,212 kB
  • ctags: 4,635
  • sloc: ansic: 43,538; cpp: 970; makefile: 883; lisp: 661; sh: 578; asm: 539; objc: 379; csh: 297; pascal: 192; perl: 138
file content (332 lines) | stat: -rw-r--r-- 8,599 bytes parent folder | download
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
/*[
 * Copyright 1986 - 1993, 1998   Thomas Williams, Colin Kelley
 *
 * Permission to use, copy, and distribute this software and its
 * documentation for any purpose with or without fee is hereby granted,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.
 *
 * Permission to modify the software is granted, but not the right to
 * distribute the complete modified source code.  Modifications are to
 * be distributed as patches to the released version.  Permission to
 * distribute binaries produced by compiling modified sources is granted,
 * provided you
 *   1. distribute the corresponding source modifications from the
 *    released version in the form of a patch file along with the binaries,
 *   2. add special version identification to distinguish your version
 *    in addition to the base release version number,
 *   3. provide your name and address as the primary contact for the
 *    support of your modified version, and
 *   4. retain our contact information in regard to use of the base
 *    software.
 * Permission to distribute the released version of the source code along
 * with corresponding source modifications in the form of a patch file is
 * granted with same provisions 2 through 4 for binary distributions.
 *
 * This software is provided "as is" without express or implied warranty
 * to the extent permitted by applicable law.
]*/

#include <Application.h>
#include <Messenger.h>
#include <Message.h>
#include <Alert.h>
#include <Roster.h>
#include <Window.h>
#include <View.h>
#include <MenuBar.h>
#include <Menu.h>
#include <MenuField.h>
#include <Entry.h>
#include <Path.h>
#include <Box.h>
#include <MenuItem.h>
#include <TextView.h>
#include <FilePanel.h>
#include <ScrollView.h>
#include <OutlineListView.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#include "constants.h"
#include "GPApp.h"
#include "GPBitmap.h"
#include "GPView.h"
#include "GPWindow.h"

// Constructs the window we'll be drawing into.
//
GPWindow::GPWindow(BRect frame)
			: BWindow(frame, " ", B_TITLED_WINDOW, 0) {
	_InitWindow();
	Show();
}


// Create a window from a file.
//
GPWindow::GPWindow(BRect frame, plot_struct *plot)
			: BWindow(frame, "Untitled ", B_TITLED_WINDOW, 0) {
	
	_InitWindow();
	
	Show();
}


void GPWindow::_InitWindow(void) {
	BRect r, rtool, plotframe;
	BMenu *menu;
	BMenuItem *item;

	 
	// Initialize variables
	
	savemessage = NULL;			// No saved path yet
	r = rtool = plotframe = Bounds();
//	rtool = Bounds();
//	plotframe = Bounds();
	
	// Add the menu bar
	menubar = new BMenuBar(r, "menu_bar");

	// Add File menu to menu bar
	menu = new BMenu("File");
	menu->AddItem(new BMenuItem("New", new BMessage(MENU_FILE_NEW), 'N'));
	
	menu->AddItem(item=new BMenuItem("Open" B_UTF8_ELLIPSIS, new BMessage(MENU_FILE_OPEN), 'O'));
	item->SetTarget(be_app);
	menu->AddItem(new BMenuItem("Close", new BMessage(MENU_FILE_CLOSE), 'W'));
	menu->AddSeparatorItem();
	menu->AddItem(saveitem=new BMenuItem("Save", new BMessage(MENU_FILE_SAVE), 'S'));
	saveitem->SetEnabled(false);
	menu->AddItem(new BMenuItem("Save as" B_UTF8_ELLIPSIS, new BMessage(MENU_FILE_SAVEAS)));
					
	menu->AddSeparatorItem();
	menu->AddItem(item=new BMenuItem("Page Setup" B_UTF8_ELLIPSIS, new BMessage(MENU_FILE_PAGESETUP)));
	item->SetEnabled(false);
	menu->AddItem(item=new BMenuItem("Print" B_UTF8_ELLIPSIS, new BMessage(MENU_FILE_PRINT), 'P'));
	item->SetEnabled(false);

	menu->AddSeparatorItem();
	menu->AddItem(new BMenuItem("Quit", new BMessage(MENU_FILE_QUIT), 'Q'));
	menubar->AddItem(menu);
	
	// Attach the menu bar to the window
	AddChild(menubar);
	
	// Add the plot view
//	plotframe.left +=rtool.right+5;
	plotframe.top = menubar->Bounds().bottom+2;
//	plotframe.right -= B_V_SCROLL_BAR_WIDTH;
//	plotframe.bottom -= B_H_SCROLL_BAR_HEIGHT;
	
	BRect plotrect = plotframe;
	plotrect.OffsetTo(B_ORIGIN);
	r.InsetBy(3.0,3.0);
	
	plotview = new GPView(plotframe, B_FOLLOW_ALL_SIDES, B_WILL_DRAW|B_PULSE_NEEDED, NULL);
//	plotview = new BView(plotframe, "test", B_FOLLOW_ALL_SIDES, B_WILL_DRAW|B_PULSE_NEEDED);
	AddChild(plotview);
	//help menu
	menu = new BMenu("Help");
	menu->AddItem(new BMenuItem("Help",new BMessage(MENU_HELP_REQUESTED)));
	menu->AddItem(new BMenuItem("About...",new BMessage(MENU_HELP_ABOUT)));
	
	menubar->AddItem(menu);
	
	// Create the save filepanel for this window
	
	savePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this), NULL, B_FILE_NODE, false);

	// Tell the application that there's one more window
	// and get the number for this untitled window.
	Register(true);
	Minimize(false);		// So Show() doesn't really make it visible
}


//
// GPWindow::FrameResized
//
// Adjust the size of the BTextView's text rectangle
// when the window is resized.
//
void GPWindow::FrameResized(float width, float height) {
	BRect plotrect = plotview->Bounds();
	
	plotrect.right = plotrect.left + (width - 3.0);
//	plotview->SetTextRect(plotrect);
}


//
// GPWindow::~GPWindow
//
// Destruct the window.  This calls Unregister().
//
GPWindow::~GPWindow() {
	Unregister();
	if (savemessage) {
		delete savemessage;
	}
	delete savePanel;
}


//
// GPWindow::MessageReceived
//
// Called when a message is received by our
// application.
//
void GPWindow::MessageReceived(BMessage *message) {

	switch(message->what) {

		case WINDOW_REGISTRY_ADDED:
			{
				char s[22];
				BRect rect;
				if (message->FindInt32("new_window_number", &window_id) == B_OK) {
					if (!savemessage) {		// if it's untitled
						sprintf(s, "File%ld.html", window_id);
						SetTitle(s);
					}
				}
				if (message->FindRect("rect", &rect) == B_OK) {
					MoveTo(rect.LeftTop());
					ResizeTo(rect.Width(), rect.Height());
				}
				Minimize(false);
			}
			break;
			
		case MENU_FILE_NEW:
			{
				BRect r;
				r = Frame();
				new GPWindow(r);
			}
			break;
		
		case MENU_FILE_CLOSE:
			Quit();
			break;
		case MENU_FILE_QUIT:
			be_app->PostMessage(B_QUIT_REQUESTED);
			break;
		case MENU_FILE_SAVEAS:
			savePanel->Show();
			break;
		case MENU_FILE_SAVE:
			Save(NULL);
			break;
		case B_SAVE_REQUESTED:
			Save(message);
			break;
		
		case MENU_HELP_REQUESTED:{
		int arg_c;
		char **_arg;
		arg_c=1;
		_arg = (char **)malloc(sizeof(char *) * (arg_c+ 1));
		_arg[0]="/boot/home/peojects/WebEditor/help.html";
		_arg[1]=NULL;
		be_roster->Launch("application/x-vnd.Be-NPOS",arg_c,_arg,NULL);
		free(_arg);
		}	
		break; 
		
		case MENU_HELP_ABOUT:{
			BAlert		*alert;
			alert= new BAlert("About ", "WebEditor for BeOS™\n©François Jouen 1999.\ne-mail:jouen@epeire.univ-rouen.fr", "OK");
			alert->Go();
	
		}	
		break;				
					
//		case B_MOUSE_UP:
//			printf("gor something\n");
//		break;				

		case bmsgNewCmd:
		case bmsgClrCmd:
		case bmsgBitmapDirty:
		case bmsgBitmapResize:
//			printf("gor something\n");
			plotview->MessageReceived(message);
		break;				
					
		default:
			BWindow::MessageReceived(message);
			break;
	}
}


//
// GPWindow::Register
//
// Since MessageWorld can have multiple windows and
// we need to know when there aren't any left so the
// application can be shut down, this function is used
// to tell the application that a new window has been
// opened.
//
// If the need_id argument is true, we'll specify true
// for the "need_id" field in the message we send; this
// will cause the application to send back a
// WINDOW_REGISTRY_ADDED message containing the window's
// unique ID number.  If this argument is false, we won't
// request an ID.
//
void GPWindow::Register(bool need_id) {
	BMessenger messenger(APP_SIGNATURE);
	BMessage message(WINDOW_REGISTRY_ADD);
	
	message.AddBool("need_id", need_id);
	messenger.SendMessage(&message, this);
}


//
// GPWindow::Unregister
//
// Unregisters a window.  This tells the application that
// one fewer windows are open.  The application will
// automatically quit if the count goes to zero because
// of this call.
//
void GPWindow::Unregister(void) {
	BMessenger messenger(APP_SIGNATURE);
	
	messenger.SendMessage(new BMessage(WINDOW_REGISTRY_SUB));
}


//
// GPWindow::QuitRequested
//
// Here we just give permission to close the window.
//
bool GPWindow::QuitRequested() {
	return true;
}


//
// GPWindow::Save
//
// Save the contents of the window.  The message specifies
// where to save it (see BFilePanel in the Storage Kit chapter
// of the Be Book).
//
status_t GPWindow::Save(BMessage *message) {
	entry_ref ref;		// For the directory to save into
	status_t err = B_OK;		// For the return code

	return err;
}