2002-09-23 23:01:55 +00:00
|
|
|
|
2003-08-10 11:46:37 +00:00
|
|
|
#include <Alert.h>
|
2002-11-05 09:24:25 +00:00
|
|
|
#include <Autolock.h>
|
2002-11-20 23:29:00 +00:00
|
|
|
#include <Path.h>
|
2003-07-06 04:05:22 +00:00
|
|
|
#include <MenuItem.h>
|
2003-07-26 22:56:30 +00:00
|
|
|
#include <CharacterSet.h>
|
|
|
|
|
#include <CharacterSetRoster.h>
|
2003-08-10 11:46:37 +00:00
|
|
|
#include <Screen.h>
|
2003-08-01 01:09:50 +00:00
|
|
|
#include <stdio.h>
|
2003-08-10 11:46:37 +00:00
|
|
|
|
2005-10-29 16:27:43 +00:00
|
|
|
#include "Constants.h"
|
|
|
|
|
#include "StyledEditApp.h"
|
|
|
|
|
#include "StyledEditWindow.h"
|
2002-09-23 23:01:55 +00:00
|
|
|
|
2003-07-26 22:56:30 +00:00
|
|
|
using namespace BPrivate;
|
|
|
|
|
|
2003-08-10 11:46:37 +00:00
|
|
|
BRect windowRect(7-15,26-15,507,426);
|
|
|
|
|
|
|
|
|
|
void cascade() {
|
|
|
|
|
BScreen screen(NULL);
|
|
|
|
|
BRect screenBorder = screen.Frame();
|
|
|
|
|
float left = windowRect.left + 15;
|
|
|
|
|
if (left + windowRect.Width() > screenBorder.right) {
|
|
|
|
|
left = 7;
|
|
|
|
|
}
|
|
|
|
|
float top = windowRect.top + 15;
|
|
|
|
|
if (top + windowRect.Height() > screenBorder.bottom) {
|
|
|
|
|
top = 26;
|
|
|
|
|
}
|
|
|
|
|
windowRect.OffsetTo(BPoint(left,top));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void uncascade() {
|
|
|
|
|
BScreen screen(NULL);
|
|
|
|
|
BRect screenBorder = screen.Frame();
|
|
|
|
|
float left = windowRect.left - 15;
|
|
|
|
|
if (left < 7) {
|
|
|
|
|
left = screenBorder.right - windowRect.Width() - 7;
|
|
|
|
|
left = left - ((int)left % 15) + 7;
|
|
|
|
|
}
|
|
|
|
|
float top = windowRect.top - 15;
|
|
|
|
|
if (top < 26) {
|
|
|
|
|
top = screenBorder.bottom - windowRect.Height() - 26;
|
|
|
|
|
top = top - ((int)left % 15) + 26;
|
|
|
|
|
}
|
|
|
|
|
windowRect.OffsetTo(BPoint(left,top));
|
|
|
|
|
}
|
2002-09-23 23:01:55 +00:00
|
|
|
|
2002-11-05 09:24:25 +00:00
|
|
|
StyledEditApp * styled_edit_app;
|
2002-09-23 23:01:55 +00:00
|
|
|
|
|
|
|
|
StyledEditApp::StyledEditApp()
|
|
|
|
|
: BApplication(APP_SIGNATURE)
|
2002-11-05 09:24:25 +00:00
|
|
|
{
|
2002-11-06 23:03:34 +00:00
|
|
|
fOpenPanel= new BFilePanel();
|
|
|
|
|
BMenuBar * menuBar =
|
|
|
|
|
dynamic_cast<BMenuBar*>(fOpenPanel->Window()->FindView("MenuBar"));
|
|
|
|
|
|
2003-07-06 04:05:22 +00:00
|
|
|
fOpenAsEncoding = 0;
|
2002-11-06 23:03:34 +00:00
|
|
|
fOpenPanelEncodingMenu= new BMenu("Encoding");
|
|
|
|
|
menuBar->AddItem(fOpenPanelEncodingMenu);
|
2003-07-06 04:05:22 +00:00
|
|
|
fOpenPanelEncodingMenu->SetRadioMode(true);
|
2002-11-06 23:03:34 +00:00
|
|
|
|
2003-07-26 22:56:30 +00:00
|
|
|
BCharacterSetRoster roster;
|
|
|
|
|
BCharacterSet charset;
|
|
|
|
|
while (roster.GetNextCharacterSet(&charset) == B_NO_ERROR) {
|
|
|
|
|
BString name(charset.GetPrintName());
|
|
|
|
|
const char * mime = charset.GetMIMEName();
|
|
|
|
|
if (mime) {
|
|
|
|
|
name.Append(" (");
|
|
|
|
|
name.Append(mime);
|
|
|
|
|
name.Append(")");
|
|
|
|
|
}
|
|
|
|
|
BMenuItem * item = new BMenuItem(name.String(),new BMessage(OPEN_AS_ENCODING));
|
|
|
|
|
item->SetTarget(this);
|
|
|
|
|
fOpenPanelEncodingMenu->AddItem(item);
|
|
|
|
|
if (charset.GetFontID() == fOpenAsEncoding) {
|
|
|
|
|
item->SetMarked(true);
|
2003-07-06 04:05:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
2002-11-06 23:03:34 +00:00
|
|
|
|
2002-09-23 23:01:55 +00:00
|
|
|
fWindowCount= 0;
|
|
|
|
|
fNext_Untitled_Window= 1;
|
2002-11-05 09:24:25 +00:00
|
|
|
styled_edit_app = this;
|
|
|
|
|
} /***StyledEditApp::StyledEditApp()***/
|
2002-09-23 23:01:55 +00:00
|
|
|
|
2002-11-20 23:29:00 +00:00
|
|
|
void StyledEditApp::DispatchMessage(BMessage *msg, BHandler *handler)
|
|
|
|
|
{
|
|
|
|
|
if ( msg->what == B_ARGV_RECEIVED ) {
|
|
|
|
|
int32 argc;
|
|
|
|
|
if (msg->FindInt32("argc",&argc) != B_OK) {
|
|
|
|
|
argc=0;
|
|
|
|
|
}
|
2005-11-12 23:27:14 +00:00
|
|
|
const char ** argv = new const char*[argc];
|
2002-11-20 23:29:00 +00:00
|
|
|
for (int arg = 0; (arg < argc) ; arg++) {
|
|
|
|
|
if (msg->FindString("argv",arg,&argv[arg]) != B_OK) {
|
|
|
|
|
argv[arg] = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const char * cwd;
|
|
|
|
|
if (msg->FindString("cwd",&cwd) != B_OK) {
|
|
|
|
|
cwd = "";
|
|
|
|
|
}
|
|
|
|
|
ArgvReceived(argc, argv, cwd);
|
|
|
|
|
} else {
|
|
|
|
|
BApplication::DispatchMessage(msg,handler);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-09-23 23:01:55 +00:00
|
|
|
|
2002-11-05 09:24:25 +00:00
|
|
|
void
|
|
|
|
|
StyledEditApp::MessageReceived(BMessage *message)
|
|
|
|
|
{
|
|
|
|
|
switch(message->what) {
|
|
|
|
|
case MENU_NEW:
|
|
|
|
|
OpenDocument();
|
|
|
|
|
break;
|
2002-09-23 23:01:55 +00:00
|
|
|
case MENU_OPEN:
|
|
|
|
|
fOpenPanel->Show(); //
|
|
|
|
|
break;
|
2002-11-20 22:40:28 +00:00
|
|
|
case B_SILENT_RELAUNCH:
|
|
|
|
|
OpenDocument();
|
|
|
|
|
break;
|
2003-07-06 04:05:22 +00:00
|
|
|
case OPEN_AS_ENCODING:
|
|
|
|
|
void * ptr;
|
|
|
|
|
if (message->FindPointer("source",&ptr) == B_OK) {
|
|
|
|
|
if (fOpenPanelEncodingMenu != 0) {
|
|
|
|
|
fOpenAsEncoding = (uint32)fOpenPanelEncodingMenu->IndexOf((BMenuItem*)ptr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2002-09-23 23:01:55 +00:00
|
|
|
default:
|
|
|
|
|
BApplication::MessageReceived(message);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-05 09:24:25 +00:00
|
|
|
void
|
|
|
|
|
StyledEditApp::OpenDocument()
|
|
|
|
|
{
|
2003-08-10 11:46:37 +00:00
|
|
|
cascade();
|
2003-07-06 04:05:22 +00:00
|
|
|
new StyledEditWindow(windowRect,fNext_Untitled_Window++,fOpenAsEncoding);
|
2002-11-05 09:24:25 +00:00
|
|
|
fWindowCount++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
StyledEditApp::OpenDocument(entry_ref * ref)
|
|
|
|
|
{
|
2003-08-10 11:46:37 +00:00
|
|
|
cascade();
|
2003-07-06 04:05:22 +00:00
|
|
|
new StyledEditWindow(windowRect,ref,fOpenAsEncoding);
|
2002-11-05 09:24:25 +00:00
|
|
|
fWindowCount++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
StyledEditApp::CloseDocument()
|
|
|
|
|
{
|
2003-08-10 11:46:37 +00:00
|
|
|
uncascade();
|
2002-11-05 09:24:25 +00:00
|
|
|
fWindowCount--;
|
|
|
|
|
if (fWindowCount == 0) {
|
|
|
|
|
BAutolock lock(this);
|
|
|
|
|
Quit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
StyledEditApp::RefsReceived(BMessage *message)
|
|
|
|
|
{
|
2002-09-23 23:01:55 +00:00
|
|
|
int32 refNum;
|
|
|
|
|
entry_ref ref;
|
|
|
|
|
status_t err;
|
|
|
|
|
|
2002-11-20 23:29:00 +00:00
|
|
|
refNum = 0;
|
2002-11-05 09:24:25 +00:00
|
|
|
do {
|
2002-11-20 23:29:00 +00:00
|
|
|
err = message->FindRef("refs", refNum, &ref);
|
|
|
|
|
if (err != B_OK)
|
2002-09-23 23:01:55 +00:00
|
|
|
return;
|
2002-11-05 09:24:25 +00:00
|
|
|
OpenDocument(&ref);
|
2002-09-23 23:01:55 +00:00
|
|
|
refNum++;
|
2002-11-20 23:29:00 +00:00
|
|
|
} while (true);
|
2002-09-23 23:01:55 +00:00
|
|
|
} /***StyledEditApp::RefsReceived();***/
|
|
|
|
|
|
2002-11-20 23:29:00 +00:00
|
|
|
void
|
|
|
|
|
StyledEditApp::ArgvReceived(int32 argc, const char *argv[], const char * cwd)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 1 ; (i < argc) ; i++) {
|
|
|
|
|
BPath path;
|
|
|
|
|
if (argv[i][0] == '/') {
|
|
|
|
|
path.SetTo(argv[i]);
|
|
|
|
|
} else {
|
|
|
|
|
path.SetTo(cwd,argv[i]);
|
|
|
|
|
}
|
|
|
|
|
if (path.InitCheck() != B_OK) {
|
2003-08-01 01:09:50 +00:00
|
|
|
printf("path.InitCheck failed: \"");
|
|
|
|
|
if (argv[i][0] == '/') {
|
|
|
|
|
printf("%s",argv[i]);
|
|
|
|
|
} else {
|
|
|
|
|
printf("%s/%s",cwd,argv[i]);
|
|
|
|
|
}
|
|
|
|
|
printf("\".\n");
|
|
|
|
|
continue;
|
2002-11-20 23:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entry_ref ref;
|
|
|
|
|
if (get_ref_for_path(path.Path(), &ref) != B_OK) {
|
2003-08-01 01:09:50 +00:00
|
|
|
printf("get_ref_for_path failed: \"");
|
|
|
|
|
printf("%s",path.Path());
|
|
|
|
|
printf("\".\n");
|
|
|
|
|
continue;
|
2002-11-20 23:29:00 +00:00
|
|
|
}
|
|
|
|
|
OpenDocument(&ref);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-05 09:24:25 +00:00
|
|
|
void
|
|
|
|
|
StyledEditApp::ReadyToRun()
|
|
|
|
|
{
|
|
|
|
|
if (fWindowCount == 0) {
|
|
|
|
|
OpenDocument();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32
|
|
|
|
|
StyledEditApp::NumberOfWindows()
|
|
|
|
|
{
|
2002-09-23 23:01:55 +00:00
|
|
|
|
|
|
|
|
return fWindowCount;
|
|
|
|
|
|
|
|
|
|
}/***StyledEditApp::NumberOfWindows()***/
|
|
|
|
|
|
2002-11-05 09:24:25 +00:00
|
|
|
int
|
|
|
|
|
main()
|
|
|
|
|
{
|
|
|
|
|
StyledEditApp styledEdit;
|
|
|
|
|
styledEdit.Run();
|
2002-09-23 23:01:55 +00:00
|
|
|
return 0;
|
2002-11-05 09:24:25 +00:00
|
|
|
}
|
2002-09-27 04:47:23 +00:00
|
|
|
|