2 * Copyright 1986 - 1993, 1998, 2004 Thomas Williams, Colin Kelley
4 * Permission to use, copy, and distribute this software and its
5 * documentation for any purpose with or without fee is hereby granted,
6 * provided that the above copyright notice appear in all copies and
7 * that both that copyright notice and this permission notice appear
8 * in supporting documentation.
10 * Permission to modify the software is granted, but not the right to
11 * distribute the complete modified source code. Modifications are to
12 * be distributed as patches to the released version. Permission to
13 * distribute binaries produced by compiling modified sources is granted,
15 * 1. distribute the corresponding source modifications from the
16 * released version in the form of a patch file along with the binaries,
17 * 2. add special version identification to distinguish your version
18 * in addition to the base release version number,
19 * 3. provide your name and address as the primary contact for the
20 * support of your modified version, and
21 * 4. retain our contact information in regard to use of the base
23 * Permission to distribute the released version of the source code along
24 * with corresponding source modifications in the form of a patch file is
25 * granted with same provisions 2 through 4 for binary distributions.
27 * This software is provided "as is" without express or implied warranty
28 * to the extent permitted by applicable law.
31 #include <Application.h>
32 #include <Messenger.h>
40 #include <MenuField.h>
46 #include <FilePanel.h>
47 #include <ScrollView.h>
48 #include <OutlineListView.h>
53 #include "constants.h"
59 // Constructs the window we'll be drawing into.
61 GPWindow::GPWindow(BRect frame)
62 : BWindow(frame, " ", B_TITLED_WINDOW, 0) {
68 // Create a window from a file.
70 GPWindow::GPWindow(BRect frame, plot_struct *plot)
71 : BWindow(frame, "Untitled ", B_TITLED_WINDOW, 0) {
79 void GPWindow::_InitWindow(void) {
80 BRect r, rtool, plotframe;
85 // Initialize variables
87 savemessage = NULL; // No saved path yet
88 r = rtool = plotframe = Bounds();
90 // plotframe = Bounds();
93 menubar = new BMenuBar(r, "menu_bar");
95 // Add File menu to menu bar
96 menu = new BMenu("File");
97 menu->AddItem(new BMenuItem("New", new BMessage(MENU_FILE_NEW), 'N'));
99 menu->AddItem(item=new BMenuItem("Open" B_UTF8_ELLIPSIS, new BMessage(MENU_FILE_OPEN), 'O'));
100 item->SetTarget(be_app);
101 menu->AddItem(new BMenuItem("Close", new BMessage(MENU_FILE_CLOSE), 'W'));
102 menu->AddSeparatorItem();
103 menu->AddItem(saveitem=new BMenuItem("Save", new BMessage(MENU_FILE_SAVE), 'S'));
104 saveitem->SetEnabled(false);
105 menu->AddItem(new BMenuItem("Save as" B_UTF8_ELLIPSIS, new BMessage(MENU_FILE_SAVEAS)));
107 menu->AddSeparatorItem();
108 menu->AddItem(item=new BMenuItem("Page Setup" B_UTF8_ELLIPSIS, new BMessage(MENU_FILE_PAGESETUP)));
109 item->SetEnabled(false);
110 menu->AddItem(item=new BMenuItem("Print" B_UTF8_ELLIPSIS, new BMessage(MENU_FILE_PRINT), 'P'));
111 item->SetEnabled(false);
113 menu->AddSeparatorItem();
114 menu->AddItem(new BMenuItem("Quit", new BMessage(MENU_FILE_QUIT), 'Q'));
115 menubar->AddItem(menu);
117 // Attach the menu bar to the window
121 // plotframe.left +=rtool.right+5;
122 plotframe.top = menubar->Bounds().bottom+2;
123 // plotframe.right -= B_V_SCROLL_BAR_WIDTH;
124 // plotframe.bottom -= B_H_SCROLL_BAR_HEIGHT;
126 BRect plotrect = plotframe;
127 plotrect.OffsetTo(B_ORIGIN);
130 plotview = new GPView(plotframe, B_FOLLOW_ALL_SIDES, B_WILL_DRAW|B_PULSE_NEEDED, NULL);
131 // plotview = new BView(plotframe, "test", B_FOLLOW_ALL_SIDES, B_WILL_DRAW|B_PULSE_NEEDED);
134 menu = new BMenu("Help");
135 menu->AddItem(new BMenuItem("Help",new BMessage(MENU_HELP_REQUESTED)));
136 menu->AddItem(new BMenuItem("About...",new BMessage(MENU_HELP_ABOUT)));
138 menubar->AddItem(menu);
140 // Create the save filepanel for this window
142 savePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this), NULL, B_FILE_NODE, false);
144 // Tell the application that there's one more window
145 // and get the number for this untitled window.
147 Minimize(false); // So Show() doesn't really make it visible
152 // GPWindow::FrameResized
154 // Adjust the size of the BTextView's text rectangle
155 // when the window is resized.
157 void GPWindow::FrameResized(float width, float height) {
158 BRect plotrect = plotview->Bounds();
160 plotrect.right = plotrect.left + (width - 3.0);
161 // plotview->SetTextRect(plotrect);
166 // GPWindow::~GPWindow
168 // Destruct the window. This calls Unregister().
170 GPWindow::~GPWindow() {
180 // GPWindow::MessageReceived
182 // Called when a message is received by our
185 void GPWindow::MessageReceived(BMessage *message) {
187 switch(message->what) {
189 case WINDOW_REGISTRY_ADDED:
193 if (message->FindInt32("new_window_number", &window_id) == B_OK) {
194 if (!savemessage) { // if it's untitled
195 sprintf(s, "File%ld.html", window_id);
199 if (message->FindRect("rect", &rect) == B_OK) {
200 MoveTo(rect.LeftTop());
201 ResizeTo(rect.Width(), rect.Height());
215 case MENU_FILE_CLOSE:
219 be_app->PostMessage(B_QUIT_REQUESTED);
221 case MENU_FILE_SAVEAS:
227 case B_SAVE_REQUESTED:
231 case MENU_HELP_REQUESTED:{
235 _arg = (char **)malloc(sizeof(char *) * (arg_c+ 1));
236 _arg[0]="/boot/home/peojects/WebEditor/help.html";
238 be_roster->Launch("application/x-vnd.Be-NPOS",arg_c,_arg,NULL);
243 case MENU_HELP_ABOUT:{
245 alert= new BAlert("About ", "WebEditor for BeOS™\n©François Jouen 1999.\ne-mail:jouen@epeire.univ-rouen.fr", "OK");
252 // printf("gor something\n");
257 case bmsgBitmapDirty:
258 case bmsgBitmapResize:
259 // printf("gor something\n");
260 plotview->MessageReceived(message);
264 BWindow::MessageReceived(message);
271 // GPWindow::Register
273 // Since MessageWorld can have multiple windows and
274 // we need to know when there aren't any left so the
275 // application can be shut down, this function is used
276 // to tell the application that a new window has been
279 // If the need_id argument is true, we'll specify true
280 // for the "need_id" field in the message we send; this
281 // will cause the application to send back a
282 // WINDOW_REGISTRY_ADDED message containing the window's
283 // unique ID number. If this argument is false, we won't
286 void GPWindow::Register(bool need_id) {
287 BMessenger messenger(APP_SIGNATURE);
288 BMessage message(WINDOW_REGISTRY_ADD);
290 message.AddBool("need_id", need_id);
291 messenger.SendMessage(&message, this);
296 // GPWindow::Unregister
298 // Unregisters a window. This tells the application that
299 // one fewer windows are open. The application will
300 // automatically quit if the count goes to zero because
303 void GPWindow::Unregister(void) {
304 BMessenger messenger(APP_SIGNATURE);
306 messenger.SendMessage(new BMessage(WINDOW_REGISTRY_SUB));
311 // GPWindow::QuitRequested
313 // Here we just give permission to close the window.
315 bool GPWindow::QuitRequested() {
323 // Save the contents of the window. The message specifies
324 // where to save it (see BFilePanel in the Storage Kit chapter
327 status_t GPWindow::Save(BMessage *message) {
328 entry_ref ref; // For the directory to save into
329 status_t err = B_OK; // For the return code