* fixes for ticket #2378
* adjust ui code to be more font sensitive * add/ rename some of the utils message manipulation functions * use ReadAttrString instead of ReadAttr to get the printer name git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26398 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -2,14 +2,14 @@
|
||||
|
||||
PDF Writer printer driver.
|
||||
|
||||
Copyright (c) 2001, 2002 OpenBeOS.
|
||||
Copyright (c) 2005 Haiku.
|
||||
Copyright (c) 2001, 2002 OpenBeOS.
|
||||
Copyright (c) 2005 - 2008 Haiku.
|
||||
|
||||
Authors:
|
||||
Authors:
|
||||
Philippe Houdoin
|
||||
Simon Gauvin
|
||||
Simon Gauvin
|
||||
Michael Pfeiffer
|
||||
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
@@ -33,24 +33,34 @@ THE SOFTWARE.
|
||||
#ifndef _UTILS_H
|
||||
#define _UTILS_H
|
||||
|
||||
#include <Window.h>
|
||||
#include <Message.h>
|
||||
|
||||
#include <List.h>
|
||||
#include <MessageFilter.h>
|
||||
#include <String.h>
|
||||
#include <Rect.h>
|
||||
|
||||
|
||||
void AddString(BMessage* m, const char* name, const char* value);
|
||||
class BHandler;
|
||||
class BMessage;
|
||||
class BWindow;
|
||||
|
||||
|
||||
// set or replace a value in a BMessage
|
||||
void SetRect(BMessage* msg, const char* name, BRect rect);
|
||||
void SetBool(BMessage* msg, const char* name, bool value);
|
||||
void SetFloat(BMessage* msg, const char* name, float value);
|
||||
void SetInt32(BMessage* msg, const char* name, int32 value);
|
||||
void SetString(BMessage* msg, const char* name, const char* value);
|
||||
|
||||
class EscapeMessageFilter : public BMessageFilter
|
||||
void SetRect(BMessage* msg, const char* name, const BRect& rect);
|
||||
void SetString(BMessage* msg, const char* name, const BString& value);
|
||||
|
||||
|
||||
class EscapeMessageFilter : public BMessageFilter
|
||||
{
|
||||
private:
|
||||
BWindow *fWindow;
|
||||
int32 fWhat;
|
||||
|
||||
|
||||
public:
|
||||
EscapeMessageFilter(BWindow *window, int32 what);
|
||||
filter_result Filter(BMessage *msg, BHandler **target);
|
||||
@@ -65,7 +75,7 @@ class TList {
|
||||
private:
|
||||
BList fList;
|
||||
typedef int (*sort_func)(const void*, const void*);
|
||||
|
||||
|
||||
public:
|
||||
virtual ~TList();
|
||||
void MakeEmpty();
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
AdvancedSettingsWindow.cpp
|
||||
|
||||
Copyright (c) 2002 OpenBeOS.
|
||||
Copyright (c) 2002 OpenBeOS.
|
||||
|
||||
Author:
|
||||
Author:
|
||||
Michael Pfeiffer
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
@@ -27,15 +27,21 @@ THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <InterfaceKit.h>
|
||||
#include <SupportKit.h>
|
||||
#include <StorageKit.h>
|
||||
#include "AdvancedSettingsWindow.h"
|
||||
#include "Utils.h"
|
||||
|
||||
|
||||
#define SETTINGS_PATH "/boot/home/config/settings/PDF Writer/"
|
||||
#define BOOKMARKS_PATH SETTINGS_PATH "bookmarks/"
|
||||
#define XREFS_PATH SETTINGS_PATH "xrefs/"
|
||||
#include <Box.h>
|
||||
#include <Button.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <MenuField.h>
|
||||
#include <Message.h>
|
||||
#include <Messenger.h>
|
||||
#include <Path.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <Screen.h>
|
||||
#include <TextControl.h>
|
||||
|
||||
|
||||
static BMessage* BorderWidthMessage(uint32 what, float width)
|
||||
{
|
||||
@@ -44,314 +50,332 @@ static BMessage* BorderWidthMessage(uint32 what, float width)
|
||||
return m;
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
|
||||
AdvancedSettingsWindow::AdvancedSettingsWindow(BMessage *settings)
|
||||
: HWindow(BRect(0,0,400,180), "Advanced Settings", B_TITLED_WINDOW_LOOK,
|
||||
B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE |
|
||||
B_NOT_ZOOMABLE)
|
||||
: HWindow(BRect(0, 0, 400, 180), "Advanced Settings", B_TITLED_WINDOW_LOOK,
|
||||
B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE |
|
||||
B_NOT_ZOOMABLE),
|
||||
fSettings(settings)
|
||||
{
|
||||
// ---- Ok, build a default page setup user interface
|
||||
BRect r;
|
||||
BBox *panel;
|
||||
BButton *button;
|
||||
// BCheckBox *cb;
|
||||
BMenuField *mf;
|
||||
float x, y, w, h;
|
||||
fSettings = settings;
|
||||
|
||||
AddShortcut('W',B_COMMAND_KEY,new BMessage(B_QUIT_REQUESTED));
|
||||
|
||||
// add a *dialog* background
|
||||
r = Bounds();
|
||||
panel = new BBox(r, "top_panel", B_FOLLOW_ALL,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
|
||||
B_PLAIN_BORDER);
|
||||
AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
|
||||
|
||||
x = 5; y = 5; w = r.Width(); h = r.Height();
|
||||
|
||||
// PDFlib license key
|
||||
#if 0
|
||||
BString licenseKey;
|
||||
if (settings->FindString("pdflib_license_key", &licenseKey) != B_OK) licenseKey = "";
|
||||
fLicenseKey = new BTextControl(BRect(x, y, x+2-10, y+14), "pdflib_license_key", "PDFlib License Key", "", NULL);
|
||||
fLicenseKey->TextView()->HideTyping(true);
|
||||
fLicenseKey->TextView()->SetText(licenseKey.String());
|
||||
panel->AddChild(fLicenseKey);
|
||||
fLicenseKey->ResizeToPreferred();
|
||||
y += fLicenseKey->Bounds().Height()+5;
|
||||
#endif
|
||||
if (settings->FindString("pdflib_license_key", &licenseKey) != B_OK)
|
||||
licenseKey = "Not supported.";
|
||||
|
||||
// web links
|
||||
if (settings->FindBool("create_web_links", &fCreateLinks) != B_OK) fCreateLinks = false;
|
||||
if (settings->FindBool("create_web_links", &fCreateLinks) != B_OK)
|
||||
fCreateLinks = false;
|
||||
|
||||
if (settings->FindFloat("link_border_width", &fLinkBorderWidth))
|
||||
fLinkBorderWidth = 1;
|
||||
|
||||
if (settings->FindBool("create_bookmarks", &fCreateBookmarks) != B_OK)
|
||||
fCreateBookmarks = false;
|
||||
|
||||
if (settings->FindString("xrefs_file", &fXRefs) != B_OK)
|
||||
fXRefs = "";
|
||||
|
||||
if (settings->FindString("bookmark_definition_file", &fBookmarkDefinition) != B_OK)
|
||||
fBookmarkDefinition = "";
|
||||
|
||||
if (settings->FindBool("create_xrefs", &fCreateXRefs) != B_OK)
|
||||
fCreateXRefs = false;
|
||||
|
||||
if (settings->FindInt32("close_option", (int32)&fCloseOption) != B_OK)
|
||||
fCloseOption = kNever;
|
||||
|
||||
BRect bounds(Bounds());
|
||||
BBox *panel = new BBox(bounds, "background", B_FOLLOW_ALL,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER);
|
||||
AddChild(panel);
|
||||
|
||||
bounds.InsetBy(10.0, 10.0);
|
||||
float divider = be_plain_font->StringWidth("Close status window when done: ");
|
||||
fLicenseKey = new BTextControl(bounds, "pdflib_license_key",
|
||||
"PDFlib License Key: ", "", NULL);
|
||||
panel->AddChild(fLicenseKey);
|
||||
fLicenseKey->SetEnabled(false);
|
||||
fLicenseKey->ResizeToPreferred();
|
||||
fLicenseKey->SetDivider(divider);
|
||||
//fLicenseKey->TextView()->HideTyping(true);
|
||||
fLicenseKey->TextView()->SetText(licenseKey.String());
|
||||
|
||||
// border link
|
||||
|
||||
bounds.OffsetBy(0.0, fLicenseKey->Bounds().Height() + 10.0);
|
||||
BPopUpMenu* m = new BPopUpMenu("Link Border");
|
||||
m->SetRadioMode(true);
|
||||
|
||||
BMenuField *mf = new BMenuField(bounds, "link_border_width_menu",
|
||||
"Link Border: ", m);
|
||||
panel->AddChild(mf);
|
||||
mf->ResizeToPreferred();
|
||||
mf->SetDivider(divider);
|
||||
mf->Menu()->SetLabelFromMarked(true);
|
||||
|
||||
BMenuItem* item;
|
||||
if (settings->FindFloat("link_border_width", &fLinkBorderWidth)) fLinkBorderWidth = 1;
|
||||
BPopUpMenu* m = new BPopUpMenu("link_border_width");
|
||||
m->SetRadioMode(true);
|
||||
m->AddItem(item = new BMenuItem("None", new BMessage(CREATE_LINKS_MSG)));
|
||||
item->SetMarked(!fCreateLinks);
|
||||
m->AddSeparatorItem();
|
||||
|
||||
m->AddItem(item = new BMenuItem("No Border", BorderWidthMessage(LINK_BORDER_MSG, 0.0)));
|
||||
if (fCreateLinks && fLinkBorderWidth == 0) item->SetMarked(true);
|
||||
m->AddItem(item = new BMenuItem("Normal Border", BorderWidthMessage(LINK_BORDER_MSG, 1.0)));
|
||||
if (fCreateLinks && fLinkBorderWidth == 1) item->SetMarked(true);
|
||||
m->AddItem(item = new BMenuItem("Bold Border", BorderWidthMessage(LINK_BORDER_MSG, 2.0)));
|
||||
if (fCreateLinks && fLinkBorderWidth == 2) item->SetMarked(true);
|
||||
|
||||
mf = new BMenuField(BRect(x, y, x+w-10, y+14), "link_border_width_menu", "Link:", m);
|
||||
mf->ResizeToPreferred();
|
||||
panel->AddChild(mf);
|
||||
y += mf->Bounds().Height() + 15;
|
||||
|
||||
m->AddItem(item = new BMenuItem("No Border", BorderWidthMessage(LINK_BORDER_MSG, 0.0)));
|
||||
if (fCreateLinks && fLinkBorderWidth == 0)
|
||||
item->SetMarked(true);
|
||||
|
||||
m->AddItem(item = new BMenuItem("Normal Border", BorderWidthMessage(LINK_BORDER_MSG, 1.0)));
|
||||
if (fCreateLinks && fLinkBorderWidth == 1)
|
||||
item->SetMarked(true);
|
||||
|
||||
m->AddItem(item = new BMenuItem("Bold Border", BorderWidthMessage(LINK_BORDER_MSG, 2.0)));
|
||||
if (fCreateLinks && fLinkBorderWidth == 2)
|
||||
item->SetMarked(true);
|
||||
|
||||
|
||||
// bookmarks
|
||||
|
||||
if (settings->FindBool("create_bookmarks", &fCreateBookmarks) != B_OK) fCreateBookmarks = false;
|
||||
|
||||
m = new BPopUpMenu("definition");
|
||||
m = new BPopUpMenu("Bookmark Definition File");
|
||||
m->SetRadioMode(true);
|
||||
mf = new BMenuField(BRect(x, y, x+w-10, y+14), "definition_menu", "Bookmark Definition File:", m);
|
||||
panel->AddChild(mf);
|
||||
y += mf->Bounds().Height() + 15;
|
||||
|
||||
if (settings->FindString("bookmark_definition_file", &fBookmarkDefinition) != B_OK) fBookmarkDefinition = "";
|
||||
bounds.OffsetBy(0.0, mf->Bounds().Height() + 10.0);
|
||||
mf = new BMenuField(bounds, "definition_menu", "Bookmark Definition File: ", m);
|
||||
panel->AddChild(mf);
|
||||
mf->ResizeToPreferred();
|
||||
mf->SetDivider(divider);
|
||||
mf->Menu()->SetLabelFromMarked(true);
|
||||
|
||||
m->AddItem(item = new BMenuItem("None", new BMessage(CREATE_BOOKMARKS_MSG)));
|
||||
item->SetMarked(!fCreateBookmarks);
|
||||
m->AddSeparatorItem();
|
||||
|
||||
BDirectory folder;
|
||||
BEntry entry;
|
||||
|
||||
// XXX: B_USER_SETTINGS_DIRECTORY
|
||||
folder.SetTo (BOOKMARKS_PATH);
|
||||
if (folder.InitCheck() == B_OK) {
|
||||
while (folder.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) {
|
||||
BDirectory bookmarks(_SetupDirectory("bookmarks"));
|
||||
if (bookmarks.InitCheck() == B_OK) {
|
||||
BEntry entry;
|
||||
while (bookmarks.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) {
|
||||
char name[B_FILE_NAME_LENGTH];
|
||||
if (entry.GetName(name) == B_NO_ERROR)
|
||||
m->AddItem (item = new BMenuItem(name, new BMessage(DEFINITION_MSG)));
|
||||
if (fCreateBookmarks && strcmp(name, fBookmarkDefinition.String()) == 0) item->SetMarked(true);
|
||||
if (entry.GetName(name) == B_OK) {
|
||||
m->AddItem(item = new BMenuItem(name, new BMessage(DEFINITION_MSG)));
|
||||
if (fCreateBookmarks && strcmp(name, fBookmarkDefinition.String()) == 0)
|
||||
item->SetMarked(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cross references
|
||||
if (settings->FindBool("create_xrefs", &fCreateXRefs) != B_OK) fCreateXRefs = false;
|
||||
|
||||
m = new BPopUpMenu("cross references");
|
||||
m = new BPopUpMenu("Cross References File");
|
||||
m->SetRadioMode(true);
|
||||
mf = new BMenuField(BRect(x, y, x+w-10, y+14), "xrefs_menu", "Cross References File:", m);
|
||||
panel->AddChild(mf);
|
||||
y += mf->Bounds().Height() + 15;
|
||||
|
||||
if (settings->FindString("xrefs_file", &fXRefs) != B_OK) fXRefs = "";
|
||||
bounds.OffsetBy(0.0, mf->Bounds().Height() + 10.0);
|
||||
mf = new BMenuField(bounds, "xrefs_menu", "Cross References File: ", m);
|
||||
panel->AddChild(mf);
|
||||
mf->ResizeToPreferred();
|
||||
mf->SetDivider(divider);
|
||||
mf->Menu()->SetLabelFromMarked(true);
|
||||
|
||||
m->AddItem(item = new BMenuItem("None", new BMessage(CREATE_XREFS_MSG)));
|
||||
item->SetMarked(!fCreateXRefs);
|
||||
m->AddSeparatorItem();
|
||||
|
||||
// XXX: B_USER_SETTINGS_DIRECTORY
|
||||
folder.SetTo (XREFS_PATH);
|
||||
if (folder.InitCheck() == B_OK) {
|
||||
while (folder.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) {
|
||||
|
||||
BDirectory xrefs(_SetupDirectory("xrefs"));
|
||||
if (xrefs.InitCheck() == B_OK) {
|
||||
BEntry entry;
|
||||
while (xrefs.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) {
|
||||
char name[B_FILE_NAME_LENGTH];
|
||||
if (entry.GetName(name) == B_NO_ERROR)
|
||||
if (entry.GetName(name) == B_OK) {
|
||||
m->AddItem (item = new BMenuItem(name, new BMessage(XREFS_MSG)));
|
||||
if (fCreateXRefs && strcmp(name, fXRefs.String()) == 0) item->SetMarked(true);
|
||||
if (fCreateXRefs && strcmp(name, fXRefs.String()) == 0)
|
||||
item->SetMarked(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// close automatically status window after pdf generation
|
||||
// - Never
|
||||
// - No Errors
|
||||
// - No Errors and Warnings
|
||||
// - Always
|
||||
m = new BPopUpMenu("close option");
|
||||
m = new BPopUpMenu("Close status window when done");
|
||||
m->SetRadioMode(true);
|
||||
mf = new BMenuField(BRect(x, y, x+w-10, y+14), "close_option_menu", "Close status window when done:", m);
|
||||
|
||||
bounds.OffsetBy(0.0, mf->Bounds().Height() + 10.0);
|
||||
mf = new BMenuField(bounds, "close_option_menu", "Close status window when done: ", m);
|
||||
panel->AddChild(mf);
|
||||
mf->ResizeToPreferred();
|
||||
mf->SetDivider(divider);
|
||||
mf->Menu()->SetLabelFromMarked(true);
|
||||
|
||||
int32 closeOption;
|
||||
if (settings->FindInt32("close_option", &closeOption) != B_OK) closeOption = kNever;
|
||||
fCloseOption = (CloseOption)closeOption;
|
||||
AddMenuItem(m, "Never", kNever);
|
||||
AddMenuItem(m, "No Errors", kNoErrors);
|
||||
AddMenuItem(m, "No Errors or Warnings", kNoErrorsOrWarnings);
|
||||
AddMenuItem(m, "No Errors, Warnings or Info", kNoErrorsWarningsOrInfo);
|
||||
AddMenuItem(m, "Always", kAlways);
|
||||
_AddMenuItem(m, "Never", kNever);
|
||||
_AddMenuItem(m, "No Errors", kNoErrors);
|
||||
_AddMenuItem(m, "No Errors or Warnings", kNoErrorsOrWarnings);
|
||||
_AddMenuItem(m, "No Errors, Warnings or Info", kNoErrorsWarningsOrInfo);
|
||||
_AddMenuItem(m, "Always", kAlways);
|
||||
|
||||
// add a "OK" button, and make it default
|
||||
button = new BButton(r, NULL, "OK", new BMessage(OK_MSG),
|
||||
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
||||
button->ResizeToPreferred();
|
||||
button->GetPreferredSize(&w, &h);
|
||||
button->MakeDefault(true);
|
||||
x = r.right - w - 8;
|
||||
y = r.bottom - h - 8;
|
||||
button->MoveTo(x, y);
|
||||
panel->AddChild(button);
|
||||
|
||||
// add a "Cancel button
|
||||
button = new BButton(r, NULL, "Cancel", new BMessage(CANCEL_MSG),
|
||||
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
||||
button->GetPreferredSize(&w, &h);
|
||||
button->ResizeToPreferred();
|
||||
x -= w + 8;
|
||||
button->MoveTo(x, y);
|
||||
panel->AddChild(button);
|
||||
|
||||
// add a "Open Settings Folder" button
|
||||
button = new BButton(r, NULL, "Open Settings Folder…", new BMessage(OPEN_SETTINGS_FOLDER_MSG),
|
||||
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
||||
button->GetPreferredSize(&w, &h);
|
||||
button->ResizeToPreferred();
|
||||
x = r.left + 8;
|
||||
button->MoveTo(x, y);
|
||||
panel->AddChild(button);
|
||||
|
||||
|
||||
// add a separator line...
|
||||
BBox * line = new BBox(BRect(r.left, y - 9, r.right, y - 8), NULL,
|
||||
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM );
|
||||
bounds = Bounds();
|
||||
bounds.InsetBy(5.0, 0.0);
|
||||
bounds.top = mf->Frame().bottom + 10.0;
|
||||
BBox *line = new BBox(BRect(bounds.left, bounds.top, bounds.right,
|
||||
bounds.top + 1.0), NULL, B_FOLLOW_LEFT_RIGHT);
|
||||
panel->AddChild(line);
|
||||
|
||||
// Finally, add our panel to window
|
||||
AddChild(panel);
|
||||
|
||||
MoveTo(320, 320);
|
||||
bounds.InsetBy(5.0, 0.0);
|
||||
bounds.OffsetBy(0.0, 11.0);
|
||||
BButton *cancel = new BButton(bounds, NULL, "Cancel", new BMessage(CANCEL_MSG));
|
||||
panel->AddChild(cancel);
|
||||
cancel->ResizeToPreferred();
|
||||
|
||||
BButton *ok = new BButton(bounds, NULL, "OK", new BMessage(OK_MSG));
|
||||
panel->AddChild(ok, cancel);
|
||||
ok->ResizeToPreferred();
|
||||
|
||||
bounds.right = fLicenseKey->Frame().right;
|
||||
ok->MoveTo(bounds.right - ok->Bounds().Width(), ok->Frame().top);
|
||||
|
||||
bounds = ok->Frame();
|
||||
cancel->MoveTo(bounds.left - cancel->Bounds().Width() - 10.0, bounds.top);
|
||||
|
||||
ok->MakeDefault(true);
|
||||
ResizeTo(bounds.right + 10.0, bounds.bottom + 10.0);
|
||||
|
||||
BButton *button = new BButton(bounds, NULL, "Open Settings Folder" B_UTF8_ELLIPSIS,
|
||||
new BMessage(OPEN_SETTINGS_FOLDER_MSG));
|
||||
panel->AddChild(button);
|
||||
button->ResizeToPreferred();
|
||||
button->MoveTo(fLicenseKey->Frame().left, bounds.top);
|
||||
|
||||
BRect winFrame(Frame());
|
||||
BRect screenFrame(BScreen().Frame());
|
||||
MoveTo((screenFrame.right - winFrame.right) / 2,
|
||||
(screenFrame.bottom - winFrame.bottom) / 2);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AdvancedSettingsWindow::UpdateSettings()
|
||||
{
|
||||
#if 0
|
||||
if (fSettings->HasString("pdflib_license_key")) {
|
||||
fSettings->ReplaceString("pdflib_license_key", fLicenseKey->Text());
|
||||
} else {
|
||||
fSettings->AddString("pdflib_license_key", fLicenseKey->Text());
|
||||
}
|
||||
#endif
|
||||
|
||||
if (fSettings->HasBool("create_web_links")) {
|
||||
fSettings->ReplaceBool("create_web_links", fCreateLinks);
|
||||
} else {
|
||||
fSettings->AddBool("create_web_links", fCreateLinks);
|
||||
}
|
||||
|
||||
if (fSettings->HasFloat("link_border_width")) {
|
||||
fSettings->ReplaceFloat("link_border_width", fLinkBorderWidth);
|
||||
} else {
|
||||
fSettings->AddFloat("link_border_width", fLinkBorderWidth);
|
||||
}
|
||||
|
||||
if (fSettings->HasBool("create_bookmarks")) {
|
||||
fSettings->ReplaceBool("create_bookmarks", fCreateBookmarks);
|
||||
} else {
|
||||
fSettings->AddBool("create_bookmarks", fCreateBookmarks);
|
||||
}
|
||||
|
||||
if (fSettings->HasString("bookmark_definition_file")) {
|
||||
fSettings->ReplaceString("bookmark_definition_file", fBookmarkDefinition.String());
|
||||
} else {
|
||||
fSettings->AddString("bookmark_definition_file", fBookmarkDefinition.String());
|
||||
}
|
||||
|
||||
if (fSettings->HasBool("create_xrefs")) {
|
||||
fSettings->ReplaceBool("create_xrefs", fCreateXRefs);
|
||||
} else {
|
||||
fSettings->AddBool("create_xrefs", fCreateXRefs);
|
||||
}
|
||||
|
||||
if (fSettings->HasString("xrefs_file")) {
|
||||
fSettings->ReplaceString("xrefs_file", fXRefs.String());
|
||||
} else {
|
||||
fSettings->AddString("xrefs_file", fXRefs.String());
|
||||
}
|
||||
|
||||
if (fSettings->HasInt32("close_option")) {
|
||||
fSettings->ReplaceInt32("close_option", fCloseOption);
|
||||
} else {
|
||||
fSettings->AddInt32("close_option", fCloseOption);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
void AdvancedSettingsWindow::AddMenuItem(BPopUpMenu* menu, const char* label, CloseOption option) {
|
||||
BMessage* msg = new BMessage(AUTO_CLOSE_MSG);
|
||||
msg->AddInt32("close_option", option);
|
||||
BMenuItem* item = new BMenuItem(label, msg);
|
||||
menu->AddItem(item);
|
||||
if (fCloseOption == option) item->SetMarked(true);
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
void
|
||||
AdvancedSettingsWindow::MessageReceived(BMessage *msg)
|
||||
{
|
||||
float w;
|
||||
void *source;
|
||||
int32 closeOption;
|
||||
BMenuItem *item = NULL;
|
||||
if (msg->FindPointer("source", &source) == B_OK)
|
||||
item = static_cast<BMenuItem*> (source);
|
||||
|
||||
if (msg->FindPointer("source", &source) != B_OK) source = NULL;
|
||||
|
||||
switch (msg->what){
|
||||
case OK_MSG: UpdateSettings(); Quit();
|
||||
break;
|
||||
|
||||
case CANCEL_MSG: Quit();
|
||||
break;
|
||||
case OK_MSG: {
|
||||
_UpdateSettings();
|
||||
Quit();
|
||||
} break;
|
||||
|
||||
case CREATE_LINKS_MSG:
|
||||
case CANCEL_MSG: {
|
||||
Quit();
|
||||
} break;
|
||||
|
||||
case CREATE_LINKS_MSG: {
|
||||
fCreateLinks = false;
|
||||
break;
|
||||
|
||||
case LINK_BORDER_MSG:
|
||||
} break;
|
||||
|
||||
case LINK_BORDER_MSG: {
|
||||
float w;
|
||||
if (msg->FindFloat("width", &w) == B_OK) {
|
||||
fLinkBorderWidth = w;
|
||||
fCreateLinks = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case CREATE_BOOKMARKS_MSG:
|
||||
} break;
|
||||
|
||||
case CREATE_BOOKMARKS_MSG: {
|
||||
fCreateBookmarks = false;
|
||||
break;
|
||||
|
||||
case DEFINITION_MSG:
|
||||
if (source) {
|
||||
BMenuItem* item = (BMenuItem*)source;
|
||||
} break;
|
||||
|
||||
case DEFINITION_MSG: {
|
||||
if (item) {
|
||||
fBookmarkDefinition = item->Label();
|
||||
fCreateBookmarks = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case CREATE_XREFS_MSG:
|
||||
} break;
|
||||
|
||||
case CREATE_XREFS_MSG: {
|
||||
fCreateXRefs = false;
|
||||
break;
|
||||
|
||||
case XREFS_MSG:
|
||||
if (source) {
|
||||
BMenuItem* item = (BMenuItem*)source;
|
||||
} break;
|
||||
|
||||
case XREFS_MSG: {
|
||||
if (item) {
|
||||
fXRefs = item->Label();
|
||||
fCreateXRefs = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case AUTO_CLOSE_MSG:
|
||||
if (msg->FindInt32("close_option", &closeOption) == B_OK) {
|
||||
} break;
|
||||
|
||||
case AUTO_CLOSE_MSG: {
|
||||
int32 closeOption;
|
||||
if (msg->FindInt32("close_option", &closeOption) == B_OK)
|
||||
fCloseOption = (CloseOption)closeOption;
|
||||
} break;
|
||||
|
||||
case OPEN_SETTINGS_FOLDER_MSG: {
|
||||
BPath path;
|
||||
find_directory(B_USER_SETTINGS_DIRECTORY, &path, false);
|
||||
path.Append("PDF Writer");
|
||||
|
||||
entry_ref ref;
|
||||
get_ref_for_path(path.Path(), &ref);
|
||||
|
||||
BMessenger tracker("application/x-vnd.Be-TRAK");
|
||||
if (tracker.IsValid()) {
|
||||
BMessage message(B_REFS_RECEIVED);
|
||||
message.AddRef("refs", &ref);
|
||||
tracker.SendMessage(&message);
|
||||
}
|
||||
break;
|
||||
|
||||
case OPEN_SETTINGS_FOLDER_MSG:
|
||||
{
|
||||
char* argv[] = { SETTINGS_PATH };
|
||||
be_roster->Launch("application/x-vnd.Be-TRAK", 1, argv);
|
||||
}
|
||||
break;
|
||||
|
||||
} break;
|
||||
|
||||
default:
|
||||
inherited::MessageReceived(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AdvancedSettingsWindow::_UpdateSettings()
|
||||
{
|
||||
#if 0
|
||||
AddString(fSettings, "pdflib_license_key", fLicenseKey);
|
||||
#endif
|
||||
|
||||
SetInt32(fSettings, "close_option", fCloseOption);
|
||||
|
||||
SetBool(fSettings, "create_web_links", fCreateLinks);
|
||||
SetFloat(fSettings, "link_border_width", fLinkBorderWidth);
|
||||
|
||||
SetString(fSettings, "xrefs_file", fXRefs);
|
||||
SetBool(fSettings, "create_xrefs", fCreateXRefs);
|
||||
|
||||
SetBool(fSettings, "create_bookmarks", fCreateBookmarks);
|
||||
SetString(fSettings, "bookmark_definition_file", fBookmarkDefinition);
|
||||
}
|
||||
|
||||
|
||||
BDirectory
|
||||
AdvancedSettingsWindow::_SetupDirectory(const char* dirName)
|
||||
{
|
||||
BPath path;
|
||||
find_directory(B_USER_SETTINGS_DIRECTORY, &path, true);
|
||||
|
||||
BDirectory dir(path.Path());
|
||||
if (dir.Contains("PDF Writer")) {
|
||||
path.Append("PDF Writer");
|
||||
dir.SetTo(path.Path());
|
||||
} else {
|
||||
dir.CreateDirectory("PDF Writer", &dir);
|
||||
}
|
||||
|
||||
if (dir.Contains(dirName)) {
|
||||
path.Append(dirName);
|
||||
dir.SetTo(path.Path());
|
||||
} else {
|
||||
dir.CreateDirectory(dirName, &dir);
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
||||
void AdvancedSettingsWindow::_AddMenuItem(BPopUpMenu* menu, const char* label,
|
||||
CloseOption option)
|
||||
{
|
||||
BMessage* msg = new BMessage(AUTO_CLOSE_MSG);
|
||||
msg->AddInt32("close_option", option);
|
||||
BMenuItem* item = new BMenuItem(label, msg);
|
||||
menu->AddItem(item);
|
||||
if (fCloseOption == option)
|
||||
item->SetMarked(true);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
PDF Writer printer driver.
|
||||
|
||||
Copyright (c) 2002 OpenBeOS.
|
||||
Copyright (c) 2002 OpenBeOS.
|
||||
|
||||
Authors:
|
||||
Authors:
|
||||
Philippe Houdoin
|
||||
Simon Gauvin
|
||||
Michael Pfeiffer
|
||||
@@ -32,59 +32,58 @@ THE SOFTWARE.
|
||||
#ifndef ADVANCED_SETTINGS_WINDOW_H
|
||||
#define ADVANCED_SETTINGS_WINDOW_H
|
||||
|
||||
#include <InterfaceKit.h>
|
||||
#include <Message.h>
|
||||
#include <Messenger.h>
|
||||
#include <File.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Path.h>
|
||||
#include <String.h>
|
||||
|
||||
#include "InterfaceUtils.h"
|
||||
#include "Utils.h"
|
||||
#include "PrinterDriver.h"
|
||||
|
||||
class AdvancedSettingsWindow : public HWindow
|
||||
|
||||
#include <Directory.h>
|
||||
#include <String.h>
|
||||
|
||||
|
||||
class BMessage;
|
||||
class BPopUpMenu;
|
||||
class BTextControl;
|
||||
|
||||
|
||||
class AdvancedSettingsWindow : public HWindow
|
||||
{
|
||||
typedef HWindow inherited;
|
||||
public:
|
||||
// Constructors, destructors, operators...
|
||||
|
||||
AdvancedSettingsWindow(BMessage *doc_info);
|
||||
AdvancedSettingsWindow(BMessage *doc_info);
|
||||
|
||||
typedef HWindow inherited;
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
|
||||
// public constantes
|
||||
enum {
|
||||
OK_MSG = 'ok__',
|
||||
CANCEL_MSG = 'cncl',
|
||||
CREATE_LINKS_MSG = 'clnk',
|
||||
LINK_BORDER_MSG = 'lnkb',
|
||||
CREATE_BOOKMARKS_MSG = 'cbmk',
|
||||
DEFINITION_MSG = 'defi',
|
||||
CREATE_XREFS_MSG = 'cxrf',
|
||||
XREFS_MSG = 'xref',
|
||||
AUTO_CLOSE_MSG = 'acls',
|
||||
OPEN_SETTINGS_FOLDER_MSG = 'opsf',
|
||||
OK_MSG = 'ok__',
|
||||
CANCEL_MSG = 'cncl',
|
||||
CREATE_LINKS_MSG = 'clnk',
|
||||
LINK_BORDER_MSG = 'lnkb',
|
||||
CREATE_BOOKMARKS_MSG = 'cbmk',
|
||||
DEFINITION_MSG = 'defi',
|
||||
CREATE_XREFS_MSG = 'cxrf',
|
||||
XREFS_MSG = 'xref',
|
||||
AUTO_CLOSE_MSG = 'acls',
|
||||
OPEN_SETTINGS_FOLDER_MSG = 'opsf',
|
||||
};
|
||||
|
||||
// Virtual function overrides
|
||||
public:
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
|
||||
private:
|
||||
void _UpdateSettings();
|
||||
BDirectory _SetupDirectory(const char* dirName);
|
||||
void _AddMenuItem(BPopUpMenu* menu, const char* label, CloseOption option);
|
||||
|
||||
BMessage* fSettings;
|
||||
|
||||
BTextControl* fLicenseKey;
|
||||
bool fCreateLinks;
|
||||
float fLinkBorderWidth;
|
||||
bool fCreateBookmarks;
|
||||
BString fBookmarkDefinition;
|
||||
bool fCreateXRefs;
|
||||
BString fXRefs;
|
||||
CloseOption fCloseOption;
|
||||
|
||||
void UpdateSettings();
|
||||
void AddMenuItem(BPopUpMenu* menu, const char* label, CloseOption option);
|
||||
private:
|
||||
BMessage* fSettings;
|
||||
BTextControl* fLicenseKey;
|
||||
bool fCreateLinks;
|
||||
float fLinkBorderWidth;
|
||||
bool fCreateBookmarks;
|
||||
BString fBookmarkDefinition;
|
||||
bool fCreateXRefs;
|
||||
BString fXRefs;
|
||||
CloseOption fCloseOption;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
PDF Writer printer driver.
|
||||
|
||||
Copyright (c) 2001 OpenBeOS.
|
||||
Copyright (c) 2001 OpenBeOS.
|
||||
|
||||
Authors:
|
||||
Authors:
|
||||
Philippe Houdoin
|
||||
Simon Gauvin
|
||||
Simon Gauvin
|
||||
Michael Pfeiffer
|
||||
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
@@ -37,124 +37,100 @@ THE SOFTWARE.
|
||||
|
||||
#include "Driver.h"
|
||||
#include "PDFWriter.h"
|
||||
#include "PrinterDriver.h"
|
||||
#include "PrinterSettings.h"
|
||||
|
||||
|
||||
static PrinterDriver *instanciate_driver(BNode *spoolDir);
|
||||
|
||||
// ======== For testing only ==================
|
||||
|
||||
BMessage*
|
||||
take_job(BFile *spoolFile, BNode *spoolDir, BMessage *msg)
|
||||
BMessage*
|
||||
take_job(BFile *spoolFile, BNode *spoolDir, BMessage *msg)
|
||||
{
|
||||
PrinterDriver *driver;
|
||||
|
||||
driver = instanciate_driver(spoolDir);
|
||||
if (driver->PrintJob(spoolFile, spoolDir, msg) == B_OK) {
|
||||
msg = new BMessage('okok');
|
||||
} else {
|
||||
msg = new BMessage('baad');
|
||||
}
|
||||
PrinterDriver *driver = instanciate_driver(spoolDir);
|
||||
status_t status = driver->PrintJob(spoolFile, spoolDir, msg);
|
||||
delete driver;
|
||||
|
||||
|
||||
msg = new BMessage('okok');
|
||||
if (status != B_OK)
|
||||
msg->what = 'baad';
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
BMessage*
|
||||
config_page(BNode *spoolDir, BMessage *msg)
|
||||
BMessage*
|
||||
config_page(BNode *spoolDir, BMessage *msg)
|
||||
{
|
||||
BMessage *pagesetupMsg;
|
||||
PrinterDriver *driver;
|
||||
const char *printerName;
|
||||
char buffer[B_ATTR_NAME_LENGTH+1];
|
||||
|
||||
pagesetupMsg = new BMessage(*msg);
|
||||
|
||||
BMessage *pagesetupMsg = new BMessage(*msg);
|
||||
PrinterSettings::Read(spoolDir, pagesetupMsg, PrinterSettings::kPageSettings);
|
||||
|
||||
// retrieve the printer (spool) name.
|
||||
printerName = NULL;
|
||||
if (spoolDir->ReadAttr("Printer Name", B_STRING_TYPE, 1, buffer, B_ATTR_NAME_LENGTH+1) > 0) {
|
||||
printerName = buffer;
|
||||
}
|
||||
BString printerName;
|
||||
spoolDir->ReadAttrString("Printer Name", &printerName);
|
||||
|
||||
driver = instanciate_driver(spoolDir);
|
||||
if (driver->PageSetup(pagesetupMsg, printerName) == B_OK) {
|
||||
PrinterDriver *driver = instanciate_driver(spoolDir);
|
||||
if (driver->PageSetup(pagesetupMsg, printerName.String()) == B_OK) {
|
||||
pagesetupMsg->what = 'okok';
|
||||
PrinterSettings::Update(spoolDir, pagesetupMsg, PrinterSettings::kPageSettings);
|
||||
PrinterSettings::Update(spoolDir, pagesetupMsg,
|
||||
PrinterSettings::kPageSettings);
|
||||
} else {
|
||||
delete pagesetupMsg;
|
||||
pagesetupMsg = NULL;
|
||||
}
|
||||
|
||||
delete driver;
|
||||
|
||||
return pagesetupMsg;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
BMessage*
|
||||
BMessage*
|
||||
config_job(BNode *spoolDir, BMessage *msg)
|
||||
{
|
||||
BMessage *jobsetupMsg;
|
||||
PrinterDriver *driver;
|
||||
const char *printerName;
|
||||
char buffer[B_ATTR_NAME_LENGTH+1];
|
||||
|
||||
jobsetupMsg = new BMessage(*msg);
|
||||
|
||||
BMessage *jobsetupMsg = new BMessage(*msg);
|
||||
PrinterSettings::Read(spoolDir, jobsetupMsg, PrinterSettings::kJobSettings);
|
||||
|
||||
// retrieve the printer (spool) name.
|
||||
printerName = NULL;
|
||||
if (spoolDir->ReadAttr("Printer Name", B_STRING_TYPE, 1, buffer, B_ATTR_NAME_LENGTH+1) > 0) {
|
||||
printerName = buffer;
|
||||
}
|
||||
driver = instanciate_driver(spoolDir);
|
||||
if (driver->JobSetup(jobsetupMsg, printerName) == B_OK) {
|
||||
BString printerName;
|
||||
spoolDir->ReadAttrString("Printer Name", &printerName);
|
||||
|
||||
PrinterDriver *driver = instanciate_driver(spoolDir);
|
||||
if (driver->JobSetup(jobsetupMsg, printerName.String()) == B_OK) {
|
||||
jobsetupMsg->what = 'okok';
|
||||
PrinterSettings::Update(spoolDir, jobsetupMsg, PrinterSettings::kJobSettings);
|
||||
PrinterSettings::Update(spoolDir, jobsetupMsg,
|
||||
PrinterSettings::kJobSettings);
|
||||
} else {
|
||||
delete jobsetupMsg;
|
||||
jobsetupMsg = NULL;
|
||||
}
|
||||
|
||||
delete driver;
|
||||
|
||||
return jobsetupMsg;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
char*
|
||||
char*
|
||||
add_printer(char *printerName)
|
||||
{
|
||||
return printerName;
|
||||
return printerName;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
static PrinterDriver*
|
||||
static PrinterDriver*
|
||||
instanciate_driver(BNode *spoolDir)
|
||||
{
|
||||
return new PDFWriter();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* default_settings
|
||||
* default_settings
|
||||
*
|
||||
* @param BNode* printer spool directory
|
||||
* @return BMessage* the settings
|
||||
*/
|
||||
BMessage*
|
||||
BMessage*
|
||||
default_settings(BNode* printer)
|
||||
{
|
||||
BMessage *msg = new BMessage();
|
||||
|
||||
PrinterSettings::Read(printer, msg, PrinterSettings::kPageSettings);
|
||||
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
PDF Writer printer driver.
|
||||
|
||||
Copyright (c) 2002 OpenBeOS.
|
||||
Copyright (c) 2002 OpenBeOS.
|
||||
|
||||
Authors:
|
||||
Authors:
|
||||
Philippe Houdoin
|
||||
Simon Gauvin
|
||||
Simon Gauvin
|
||||
Michael Pfeiffer
|
||||
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
@@ -33,11 +33,9 @@ THE SOFTWARE.
|
||||
|
||||
extern "C"
|
||||
{
|
||||
__declspec(dllexport) BMessage * take_job(BFile * spool_file, BNode * spool_dir, BMessage * msg);
|
||||
__declspec(dllexport) BMessage * config_page(BNode * spool_dir, BMessage * msg);
|
||||
__declspec(dllexport) BMessage * config_job(BNode * spool_dir, BMessage * msg);
|
||||
__declspec(dllexport) char * add_printer(char * printer_name);
|
||||
__declspec(dllexport) BMessage * default_settings(BNode * printer);
|
||||
BMessage * take_job(BFile * spool_file, BNode * spool_dir, BMessage * msg);
|
||||
BMessage * config_page(BNode * spool_dir, BMessage * msg);
|
||||
BMessage * config_job(BNode * spool_dir, BMessage * msg);
|
||||
char * add_printer(char * printer_name);
|
||||
BMessage * default_settings(BNode * printer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,320 +31,256 @@ THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <InterfaceKit.h>
|
||||
#include <SupportKit.h>
|
||||
#include "pdflib.h" // for pageFormat constants
|
||||
#include "PrinterDriver.h"
|
||||
#include "PageSetupWindow.h"
|
||||
|
||||
#include "MarginView.h"
|
||||
#include "FontsWindow.h"
|
||||
#include "AdvancedSettingsWindow.h"
|
||||
#include "Fonts.h"
|
||||
#include "FontsWindow.h"
|
||||
#include "InterfaceUtils.h"
|
||||
#include "MarginView.h"
|
||||
#include "PrinterDriver.h"
|
||||
#include "pdflib.h" // for pageFormat constants
|
||||
#include "Utils.h"
|
||||
|
||||
|
||||
#include <Box.h>
|
||||
#include <Button.h>
|
||||
#include <MenuField.h>
|
||||
#include <Message.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <Screen.h>
|
||||
#include <TextControl.h>
|
||||
|
||||
|
||||
// static global variables
|
||||
static struct
|
||||
{
|
||||
char *label;
|
||||
char *label;
|
||||
float width;
|
||||
float height;
|
||||
} pageFormat[] =
|
||||
{
|
||||
{"Letter", letter_width, letter_height },
|
||||
{"Legal", legal_width, legal_height },
|
||||
{"Ledger", ledger_width, ledger_height },
|
||||
{"p11x17", p11x17_width, p11x17_height },
|
||||
{"A0", a0_width, a0_height },
|
||||
{"A1", a1_width, a1_height },
|
||||
{"A2", a2_width, a2_height },
|
||||
{"A3", a3_width, a3_height },
|
||||
{"A4", a4_width, a4_height },
|
||||
{"A5", a5_width, a5_height },
|
||||
{"A6", a6_width, a6_height },
|
||||
{"B5", b5_width, b5_height },
|
||||
{NULL, 0.0, 0.0 }
|
||||
{ "Letter", letter_width, letter_height },
|
||||
{ "Legal", legal_width, legal_height },
|
||||
{ "Ledger", ledger_width, ledger_height },
|
||||
{ "p11x17", p11x17_width, p11x17_height },
|
||||
{ "A0", a0_width, a0_height },
|
||||
{ "A1", a1_width, a1_height },
|
||||
{ "A2", a2_width, a2_height },
|
||||
{ "A3", a3_width, a3_height },
|
||||
{ "A4", a4_width, a4_height },
|
||||
{ "A5", a5_width, a5_height },
|
||||
{ "A6", a6_width, a6_height },
|
||||
{ "B5", b5_width, b5_height },
|
||||
{ NULL, 0.0, 0.0 }
|
||||
};
|
||||
|
||||
|
||||
static struct
|
||||
{
|
||||
char *label;
|
||||
char *label;
|
||||
int32 orientation;
|
||||
} orientation[] =
|
||||
{
|
||||
{"Portrait", PrinterDriver::PORTRAIT_ORIENTATION},
|
||||
{"Landscape", PrinterDriver::LANDSCAPE_ORIENTATION},
|
||||
{NULL, 0}
|
||||
{ "Portrait", PrinterDriver::PORTRAIT_ORIENTATION },
|
||||
{ "Landscape", PrinterDriver::LANDSCAPE_ORIENTATION },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
// PDFLib 5.x does not support PDF 1.2 anymore!
|
||||
static const char *pdf_compatibility[] = {"1.3", "1.4", NULL};
|
||||
static const char *pdf_compatibility[] = { "1.3", "1.4", NULL };
|
||||
|
||||
|
||||
/**
|
||||
* Constuctor
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
|
||||
: HWindow(BRect(0,0,400,220), "Page Setup", B_TITLED_WINDOW_LOOK,
|
||||
B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE |
|
||||
B_NOT_ZOOMABLE)
|
||||
: HWindow(BRect(0,0,400,220), "Page Setup", B_TITLED_WINDOW_LOOK,
|
||||
B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE |
|
||||
B_NOT_ZOOMABLE),
|
||||
fResult(B_ERROR),
|
||||
fSetupMsg(msg),
|
||||
fAdvancedSettings(*msg),
|
||||
fPrinterDirName(printerName)
|
||||
{
|
||||
fSetupMsg = msg;
|
||||
fExitSem = create_sem(0, "PageSetup");
|
||||
fResult = B_ERROR;
|
||||
fAdvancedSettings = *msg;
|
||||
|
||||
if ( printerName ) {
|
||||
BString title;
|
||||
if (printerName)
|
||||
SetTitle(BString(printerName).Append(" Page Setup").String());
|
||||
|
||||
title << printerName << " Page Setup";
|
||||
SetTitle( title.String() );
|
||||
if (fSetupMsg->FindInt32("orientation", &fCurrentOrientation) != B_OK)
|
||||
fCurrentOrientation = PrinterDriver::PORTRAIT_ORIENTATION;
|
||||
|
||||
// save the printer name
|
||||
fPrinterDirName = printerName;
|
||||
BRect page;
|
||||
float width = letter_width;
|
||||
float height = letter_height;
|
||||
if (fSetupMsg->FindRect("paper_rect", &page) == B_OK) {
|
||||
width = page.Width();
|
||||
height = page.Height();
|
||||
} else {
|
||||
page.Set(0, 0, width, height);
|
||||
}
|
||||
|
||||
// ---- Ok, build a default page setup user interface
|
||||
BRect r;
|
||||
BBox *panel;
|
||||
BButton *button;
|
||||
float x, y, w, h;
|
||||
int i;
|
||||
BMenuItem *item;
|
||||
float width, height;
|
||||
int32 orient;
|
||||
BRect page;
|
||||
BRect margin(0,0,0,0);
|
||||
int32 units;
|
||||
int32 compression;
|
||||
BString setting_value;
|
||||
BString label;
|
||||
if (fSetupMsg->FindString("pdf_paper_size", &label) != B_OK)
|
||||
label = "Letter";
|
||||
|
||||
// load orientation
|
||||
fSetupMsg->FindInt32("orientation", &orient);
|
||||
// (new BAlert("", "orientation not in msg", "Shit"))->Go();
|
||||
|
||||
// load page rect
|
||||
fSetupMsg->FindRect("paper_rect", &r);
|
||||
width = r.Width();
|
||||
height = r.Height();
|
||||
page = r;
|
||||
|
||||
// Load compression
|
||||
int32 compression;
|
||||
fSetupMsg->FindInt32("pdf_compression", &compression);
|
||||
|
||||
// Load units
|
||||
fSetupMsg->FindInt32("units", &units);
|
||||
int32 units;
|
||||
if (fSetupMsg->FindInt32("units", &units) != B_OK)
|
||||
units = kUnitInch;
|
||||
|
||||
// Load printable rect
|
||||
fSetupMsg->FindRect("printable_rect", &margin);
|
||||
// re-calculate the margin from the printable rect in points
|
||||
BRect margin = page;
|
||||
if (fSetupMsg->FindRect("printable_rect", &margin) == B_OK) {
|
||||
margin.top -= page.top;
|
||||
margin.left -= page.left;
|
||||
margin.right = page.right - margin.right;
|
||||
margin.bottom = page.bottom - margin.bottom;
|
||||
} else {
|
||||
margin.Set(28.34, 28.34, 28.34, 28.34); // 28.34 dots = 1cm
|
||||
}
|
||||
|
||||
// Load pdf compatability
|
||||
fSetupMsg->FindString("pdf_compatibility", &setting_value);
|
||||
BString setting_value;
|
||||
if (fSetupMsg->FindString("pdf_compatibility", &setting_value) != B_OK)
|
||||
setting_value = "1.3";
|
||||
|
||||
// Load font settings
|
||||
fFonts = new Fonts();
|
||||
fFonts->CollectFonts();
|
||||
BMessage fonts;
|
||||
if (fSetupMsg->FindMessage("fonts", &fonts) == B_OK) {
|
||||
if (fSetupMsg->FindMessage("fonts", &fonts) == B_OK)
|
||||
fFonts->SetTo(&fonts);
|
||||
}
|
||||
|
||||
// add a *dialog* background
|
||||
r = Bounds();
|
||||
panel = new BBox(r, "top_panel", B_FOLLOW_ALL,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
|
||||
B_PLAIN_BORDER);
|
||||
BRect bounds(Bounds());
|
||||
BBox *panel = new BBox(bounds, "background", B_FOLLOW_ALL,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER);
|
||||
AddChild(panel);
|
||||
|
||||
////////////// Create the margin view //////////////////////
|
||||
|
||||
// re-calculate the margin from the printable rect in points
|
||||
margin.top -= page.top;
|
||||
margin.left -= page.left;
|
||||
margin.right = page.right - margin.right;
|
||||
margin.bottom = page.bottom - margin.bottom;
|
||||
|
||||
fMarginView = new MarginView(BRect(20,20,200,160), (int32)width, (int32)height,
|
||||
margin, (MarginUnit)units);
|
||||
bounds.InsetBy(10.0, 10.0);
|
||||
bounds.right = 230.0;
|
||||
bounds.bottom = 160.0;
|
||||
fMarginView = new MarginView(bounds, int32(width), int32(height), margin,
|
||||
MarginUnit(units));
|
||||
panel->AddChild(fMarginView);
|
||||
fMarginView->SetResizingMode(B_FOLLOW_NONE);
|
||||
|
||||
// add page format menu
|
||||
// Simon Changed to OFFSET popups
|
||||
x = r.left + kMargin * 2 + kOffset; y = r.top + kMargin * 2;
|
||||
|
||||
BPopUpMenu* m = new BPopUpMenu("page_size");
|
||||
BPopUpMenu* m = new BPopUpMenu("Page Size");
|
||||
m->SetRadioMode(true);
|
||||
|
||||
// Simon changed width 200->140
|
||||
BMenuField *mf = new BMenuField(BRect(x, y, x + 140, y + 20), "page_size",
|
||||
"Page Size:", m);
|
||||
fPageSizeMenu = mf;
|
||||
mf->ResizeToPreferred();
|
||||
mf->GetPreferredSize(&w, &h);
|
||||
bounds.OffsetBy(bounds.Width() + 10.0, 5.0);
|
||||
float divider = be_plain_font->StringWidth("PDF Compatibility: ");
|
||||
fPageSizeMenu = new BMenuField(bounds, "page_size", "Page Size:", m);
|
||||
panel->AddChild(fPageSizeMenu);
|
||||
fPageSizeMenu->ResizeToPreferred();
|
||||
fPageSizeMenu->SetDivider(divider);
|
||||
fPageSizeMenu->Menu()->SetLabelFromMarked(true);
|
||||
|
||||
// Simon added: SetDivider
|
||||
mf->SetDivider(be_plain_font->StringWidth("Page Size#"));
|
||||
for (int32 i = 0; pageFormat[i].label != NULL; i++) {
|
||||
BMessage* message = new BMessage(PAGE_SIZE_CHANGED);
|
||||
message->AddFloat("width", pageFormat[i].width);
|
||||
message->AddFloat("height", pageFormat[i].height);
|
||||
BMenuItem* item = new BMenuItem(pageFormat[i].label, message);
|
||||
m->AddItem(item);
|
||||
|
||||
panel->AddChild(mf);
|
||||
|
||||
item = NULL;
|
||||
for (i = 0; pageFormat[i].label != NULL; i++)
|
||||
{
|
||||
BMessage* msg = new BMessage('pgsz');
|
||||
msg->AddFloat("width", pageFormat[i].width);
|
||||
msg->AddFloat("height", pageFormat[i].height);
|
||||
BMenuItem* mi = new BMenuItem(pageFormat[i].label, msg);
|
||||
m->AddItem(mi);
|
||||
|
||||
if (width == pageFormat[i].width && height == pageFormat[i].height) {
|
||||
item = mi;
|
||||
}
|
||||
if (height == pageFormat[i].width && width == pageFormat[i].height) {
|
||||
item = mi;
|
||||
}
|
||||
if (label.Compare(pageFormat[i].label) == 0)
|
||||
item->SetMarked(true);
|
||||
}
|
||||
mf->Menu()->SetLabelFromMarked(true);
|
||||
if (!item) {
|
||||
item = m->ItemAt(0);
|
||||
}
|
||||
item->SetMarked(true);
|
||||
mf->MenuItem()->SetLabel(item->Label());
|
||||
|
||||
// add orientation menu
|
||||
y += h + kMargin;
|
||||
|
||||
m = new BPopUpMenu("orientation");
|
||||
m = new BPopUpMenu("Orientation");
|
||||
m->SetRadioMode(true);
|
||||
|
||||
// Simon changed 200->140
|
||||
mf = new BMenuField(BRect(x, y, x + 140, y + 20), "orientation", "Orientation:", m);
|
||||
bounds.OffsetBy(0.0, fPageSizeMenu->Bounds().Height() + 10.0);
|
||||
fOrientationMenu = new BMenuField(bounds, "orientation", "Orientation:", m);
|
||||
panel->AddChild(fOrientationMenu);
|
||||
fOrientationMenu->ResizeToPreferred();
|
||||
fOrientationMenu->SetDivider(divider);
|
||||
fOrientationMenu->Menu()->SetLabelFromMarked(true);
|
||||
|
||||
// Simon added: SetDivider
|
||||
mf->SetDivider(be_plain_font->StringWidth("Orientation#"));
|
||||
for (int32 i = 0; orientation[i].label != NULL; i++) {
|
||||
BMessage* message = new BMessage(ORIENTATION_CHANGED);
|
||||
message->AddInt32("orientation", orientation[i].orientation);
|
||||
BMenuItem* item = new BMenuItem(orientation[i].label, message);
|
||||
m->AddItem(item);
|
||||
|
||||
fOrientationMenu = mf;
|
||||
mf->ResizeToPreferred();
|
||||
panel->AddChild(mf);
|
||||
r.top += h;
|
||||
item = NULL;
|
||||
for (int i = 0; orientation[i].label != NULL; i++)
|
||||
{
|
||||
BMessage* msg = new BMessage('ornt');
|
||||
msg->AddInt32("orientation", orientation[i].orientation);
|
||||
BMenuItem* mi = new BMenuItem(orientation[i].label, msg);
|
||||
m->AddItem(mi);
|
||||
|
||||
if (orient == orientation[i].orientation) {
|
||||
item = mi;
|
||||
}
|
||||
if (fCurrentOrientation == orientation[i].orientation)
|
||||
item->SetMarked(true);
|
||||
}
|
||||
mf->Menu()->SetLabelFromMarked(true);
|
||||
// SHOULD BE REMOVED
|
||||
if (!item) {
|
||||
item = m->ItemAt(0);
|
||||
}
|
||||
///////////////////
|
||||
item->SetMarked(true);
|
||||
mf->MenuItem()->SetLabel(item->Label());
|
||||
|
||||
// add PDF comptibility menu
|
||||
y += h + kMargin;
|
||||
|
||||
m = new BPopUpMenu("pdf_compatibility");
|
||||
m = new BPopUpMenu("PDF Compatibility");
|
||||
m->SetRadioMode(true);
|
||||
mf = new BMenuField(BRect(x, y, x + 200, y + 20), "pdf_compatibility", "PDF Compatibility:", m);
|
||||
fPDFCompatibilityMenu = mf;
|
||||
mf->ResizeToPreferred();
|
||||
panel->AddChild(mf);
|
||||
r.top += h;
|
||||
|
||||
item = NULL;
|
||||
for (int i = 0; pdf_compatibility[i] != NULL; i++)
|
||||
{
|
||||
BMenuItem* mi = new BMenuItem(pdf_compatibility[i], NULL);
|
||||
m->AddItem(mi);
|
||||
bounds.OffsetBy(0.0, fOrientationMenu->Bounds().Height() + 10.0);
|
||||
fPDFCompatibilityMenu = new BMenuField(bounds, "pdf_compatibility",
|
||||
"PDF Compatibility:", m);
|
||||
panel->AddChild(fPDFCompatibilityMenu);
|
||||
fPDFCompatibilityMenu->ResizeToPreferred();
|
||||
fPDFCompatibilityMenu->SetDivider(divider);
|
||||
fPDFCompatibilityMenu->Menu()->SetLabelFromMarked(true);
|
||||
|
||||
//(new BAlert("", setting_value.String(), pdf_compatibility[i]))->Go();
|
||||
if (setting_value == pdf_compatibility[i]) {
|
||||
item = mi;
|
||||
}
|
||||
for (int32 i = 0; pdf_compatibility[i] != NULL; i++) {
|
||||
BMenuItem* item = new BMenuItem(pdf_compatibility[i], NULL);
|
||||
m->AddItem(item);
|
||||
if (setting_value == pdf_compatibility[i])
|
||||
item->SetMarked(true);
|
||||
}
|
||||
|
||||
mf->Menu()->SetLabelFromMarked(true);
|
||||
bounds.OffsetBy(0.0, fPDFCompatibilityMenu->Bounds().Height() + 10.0);
|
||||
fPDFCompressionSlider = new BSlider(bounds, "pdf_compression",
|
||||
"Compression:", NULL, 0, 9);
|
||||
panel->AddChild(fPDFCompressionSlider);
|
||||
fPDFCompressionSlider->SetLimitLabels("None", "Best");
|
||||
fPDFCompressionSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
|
||||
fPDFCompressionSlider->SetValue(compression);
|
||||
fPDFCompressionSlider->ResizeToPreferred();
|
||||
|
||||
/// SHOULD BE REMOVED
|
||||
if (!item) {
|
||||
item = m->ItemAt(0);
|
||||
}
|
||||
////////////////////
|
||||
|
||||
item->SetMarked(true);
|
||||
mf->MenuItem()->SetLabel(item->Label());
|
||||
|
||||
// add PDF compression slider
|
||||
y += h + kMargin;
|
||||
|
||||
BSlider * slider = new BSlider(BRect(x, y, panel->Bounds().right - kMargin, y + 20), "pdf_compression",
|
||||
"Compression:",
|
||||
NULL, 0, 9);
|
||||
fPDFCompressionSlider = slider;
|
||||
|
||||
panel->AddChild(slider);
|
||||
|
||||
slider->SetLimitLabels("None", "Best");
|
||||
slider->SetHashMarks(B_HASH_MARKS_BOTTOM);
|
||||
slider->ResizeToPreferred();
|
||||
slider->GetPreferredSize(&w, &h);
|
||||
|
||||
slider->SetValue(compression);
|
||||
|
||||
// add a "OK" button, and make it default
|
||||
button = new BButton(r, NULL, "OK", new BMessage(OK_MSG),
|
||||
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
||||
button->ResizeToPreferred();
|
||||
button->GetPreferredSize(&w, &h);
|
||||
x = r.right - w - 8;
|
||||
y = r.bottom - h - 8;
|
||||
button->MoveTo(x, y);
|
||||
panel->AddChild(button);
|
||||
button->MakeDefault(true);
|
||||
|
||||
// add a "Cancel button
|
||||
button = new BButton(r, NULL, "Cancel", new BMessage(CANCEL_MSG),
|
||||
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
||||
button->GetPreferredSize(&w, &h);
|
||||
button->ResizeToPreferred();
|
||||
button->MoveTo(x - w - 8, y);
|
||||
panel->AddChild(button);
|
||||
|
||||
// add a "Fonts" button
|
||||
button = new BButton(r, NULL, "Fonts" B_UTF8_ELLIPSIS, new BMessage(FONTS_MSG),
|
||||
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
||||
button->GetPreferredSize(&w, &h);
|
||||
button->ResizeToPreferred();
|
||||
button->MoveTo(r.left + 8, y);
|
||||
panel->AddChild(button);
|
||||
|
||||
// add a "Fonts" button
|
||||
BButton* font = button;
|
||||
button = new BButton(r, NULL, "Advanced" B_UTF8_ELLIPSIS, new BMessage(ADVANCED_MSG),
|
||||
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
||||
button->GetPreferredSize(&w, &h);
|
||||
button->ResizeToPreferred();
|
||||
button->MoveTo(font->Frame().right + 8, y);
|
||||
panel->AddChild(button);
|
||||
|
||||
// add a separator line...
|
||||
BBox * line = new BBox(BRect(r.left, y - 9, r.right, y - 8), NULL,
|
||||
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM );
|
||||
bounds = Bounds();
|
||||
bounds.InsetBy(5.0, 0.0);
|
||||
bounds.top = MAX(fPDFCompressionSlider->Frame().bottom,
|
||||
fMarginView->Frame().bottom) + 10.0;
|
||||
BBox *line = new BBox(BRect(bounds.left, bounds.top, bounds.right,
|
||||
bounds.top + 1.0), NULL, B_FOLLOW_LEFT_RIGHT);
|
||||
panel->AddChild(line);
|
||||
|
||||
// Finally, add our panel to window
|
||||
AddChild(panel);
|
||||
bounds.InsetBy(5.0, 0.0);
|
||||
bounds.OffsetBy(0.0, 11.0);
|
||||
BButton *cancel = new BButton(bounds, NULL, "Cancel", new BMessage(CANCEL_MSG));
|
||||
panel->AddChild(cancel);
|
||||
cancel->ResizeToPreferred();
|
||||
|
||||
BButton *ok = new BButton(bounds, NULL, "OK", new BMessage(OK_MSG));
|
||||
panel->AddChild(ok, cancel);
|
||||
ok->ResizeToPreferred();
|
||||
|
||||
bounds.right = fPDFCompressionSlider->Frame().right;
|
||||
ok->MoveTo(bounds.right - ok->Bounds().Width(), ok->Frame().top);
|
||||
|
||||
bounds = ok->Frame();
|
||||
cancel->MoveTo(bounds.left - cancel->Bounds().Width() - 10.0, bounds.top);
|
||||
|
||||
ok->MakeDefault(true);
|
||||
ResizeTo(bounds.right + 10.0, bounds.bottom + 10.0);
|
||||
|
||||
BButton *button = new BButton(bounds, NULL, "Fonts" B_UTF8_ELLIPSIS,
|
||||
new BMessage(FONTS_MSG));
|
||||
panel->AddChild(button);
|
||||
button->ResizeToPreferred();
|
||||
button->MoveTo(fMarginView->Frame().left, bounds.top);
|
||||
|
||||
bounds = button->Frame();
|
||||
button = new BButton(bounds, NULL, "Advanced" B_UTF8_ELLIPSIS,
|
||||
new BMessage(ADVANCED_MSG));
|
||||
panel->AddChild(button);
|
||||
button->ResizeToPreferred();
|
||||
button->MoveTo(bounds.right + 10, bounds.top);
|
||||
|
||||
BRect winFrame(Frame());
|
||||
BRect screenFrame(BScreen().Frame());
|
||||
MoveTo((screenFrame.right - winFrame.right) / 2,
|
||||
(screenFrame.bottom - winFrame.bottom) / 2);
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
PageSetupWindow::~PageSetupWindow()
|
||||
{
|
||||
delete_sem(fExitSem);
|
||||
@@ -352,221 +288,52 @@ PageSetupWindow::~PageSetupWindow()
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
bool
|
||||
PageSetupWindow::QuitRequested()
|
||||
{
|
||||
release_sem(fExitSem);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
void
|
||||
PageSetupWindow::UpdateSetupMessage()
|
||||
{
|
||||
BMenuItem *item;
|
||||
int32 orientation = 0;
|
||||
|
||||
item = fOrientationMenu->Menu()->FindMarked();
|
||||
if (item) {
|
||||
BMessage *msg = item->Message();
|
||||
msg->FindInt32("orientation", &orientation);
|
||||
fSetupMsg->ReplaceInt32("orientation", orientation);
|
||||
}
|
||||
|
||||
item = fPDFCompatibilityMenu->Menu()->FindMarked();
|
||||
if (item) {
|
||||
if (fSetupMsg->HasString("pdf_compatibility"))
|
||||
fSetupMsg->ReplaceString("pdf_compatibility", item->Label());
|
||||
else
|
||||
fSetupMsg->AddString("pdf_compatibility", item->Label());
|
||||
}
|
||||
|
||||
if (fSetupMsg->HasInt32("pdf_compression")) {
|
||||
fSetupMsg->ReplaceInt32("pdf_compression", fPDFCompressionSlider->Value());
|
||||
} else {
|
||||
fSetupMsg->AddInt32("pdf_compression", fPDFCompressionSlider->Value());
|
||||
}
|
||||
|
||||
item = fPageSizeMenu->Menu()->FindMarked();
|
||||
if (item) {
|
||||
float w, h;
|
||||
BMessage *msg = item->Message();
|
||||
msg->FindFloat("width", &w);
|
||||
msg->FindFloat("height", &h);
|
||||
BRect r;
|
||||
if (orientation == 0)
|
||||
r.Set(0, 0, w, h);
|
||||
else
|
||||
r.Set(0, 0, h, w);
|
||||
fSetupMsg->ReplaceRect("paper_rect", r);
|
||||
|
||||
// Save the printable_rect
|
||||
BRect margin = fMarginView->Margin();
|
||||
if (orientation == 0) {
|
||||
margin.right = w - margin.right;
|
||||
margin.bottom = h - margin.bottom;
|
||||
} else {
|
||||
margin.right = h - margin.right;
|
||||
margin.bottom = w - margin.bottom;
|
||||
}
|
||||
fSetupMsg->ReplaceRect("printable_rect", margin);
|
||||
|
||||
// save the units used
|
||||
int32 units = fMarginView->Unit();
|
||||
if (fSetupMsg->HasInt32("units")) {
|
||||
fSetupMsg->ReplaceInt32("units", units);
|
||||
} else {
|
||||
fSetupMsg->AddInt32("units", units);
|
||||
}
|
||||
}
|
||||
|
||||
BMessage fonts;
|
||||
if (B_OK == fFonts->Archive(&fonts)) {
|
||||
if (fSetupMsg->HasMessage("fonts")) {
|
||||
fSetupMsg->ReplaceMessage("fonts", &fonts);
|
||||
} else {
|
||||
fSetupMsg->AddMessage("fonts", &fonts);
|
||||
}
|
||||
}
|
||||
|
||||
// advanced settings
|
||||
bool b;
|
||||
float f;
|
||||
BString s;
|
||||
int32 i;
|
||||
|
||||
|
||||
if (fAdvancedSettings.FindString("pdflib_license_key", &s) == B_OK) {
|
||||
if (fSetupMsg->HasString("pdflib_license_key")) {
|
||||
fSetupMsg->ReplaceString("pdflib_license_key", s.String());
|
||||
} else {
|
||||
fSetupMsg->AddString("pdflib_license_key", s.String());
|
||||
}
|
||||
}
|
||||
|
||||
if (fAdvancedSettings.FindBool("create_web_links", &b) == B_OK) {
|
||||
if (fSetupMsg->HasBool("create_web_links")) {
|
||||
fSetupMsg->ReplaceBool("create_web_links", b);
|
||||
} else {
|
||||
fSetupMsg->AddBool("create_web_links", b);
|
||||
}
|
||||
}
|
||||
|
||||
if (fAdvancedSettings.FindFloat("link_border_width", &f) == B_OK) {
|
||||
if (fSetupMsg->HasFloat("link_border_width")) {
|
||||
fSetupMsg->ReplaceFloat("link_border_width", f);
|
||||
} else {
|
||||
fSetupMsg->AddFloat("link_border_width", f);
|
||||
}
|
||||
}
|
||||
|
||||
if (fAdvancedSettings.FindBool("create_bookmarks", &b) == B_OK) {
|
||||
if (fSetupMsg->HasBool("create_bookmarks")) {
|
||||
fSetupMsg->ReplaceBool("create_bookmarks", b);
|
||||
} else {
|
||||
fSetupMsg->AddBool("create_bookmarks", b);
|
||||
}
|
||||
}
|
||||
|
||||
if (fAdvancedSettings.FindString("bookmark_definition_file", &s) == B_OK) {
|
||||
if (fSetupMsg->HasString("bookmark_definition_file")) {
|
||||
fSetupMsg->ReplaceString("bookmark_definition_file", s.String());
|
||||
} else {
|
||||
fSetupMsg->AddString("bookmark_definition_file", s.String());
|
||||
}
|
||||
}
|
||||
|
||||
if (fAdvancedSettings.FindBool("create_xrefs", &b) == B_OK) {
|
||||
if (fSetupMsg->HasBool("create_xrefs")) {
|
||||
fSetupMsg->ReplaceBool("create_xrefs", b);
|
||||
} else {
|
||||
fSetupMsg->AddBool("create_xrefs", b);
|
||||
}
|
||||
}
|
||||
|
||||
if (fAdvancedSettings.FindString("xrefs_file", &s) == B_OK) {
|
||||
if (fSetupMsg->HasString("xrefs_file")) {
|
||||
fSetupMsg->ReplaceString("xrefs_file", s.String());
|
||||
} else {
|
||||
fSetupMsg->AddString("xrefs_file", s.String());
|
||||
}
|
||||
}
|
||||
|
||||
if (fAdvancedSettings.FindInt32("close_option", &i) == B_OK) {
|
||||
if (fSetupMsg->HasInt32("close_option")) {
|
||||
fSetupMsg->ReplaceInt32("close_option", i);
|
||||
} else {
|
||||
fSetupMsg->AddInt32("close_option", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
void
|
||||
PageSetupWindow::MessageReceived(BMessage *msg)
|
||||
{
|
||||
switch (msg->what){
|
||||
case OK_MSG:
|
||||
UpdateSetupMessage();
|
||||
switch (msg->what) {
|
||||
case OK_MSG: {
|
||||
_UpdateSetupMessage();
|
||||
fResult = B_OK;
|
||||
release_sem(fExitSem);
|
||||
break;
|
||||
} break;
|
||||
|
||||
case CANCEL_MSG:
|
||||
case CANCEL_MSG: {
|
||||
fResult = B_ERROR;
|
||||
release_sem(fExitSem);
|
||||
break;
|
||||
} break;
|
||||
|
||||
// Simon added
|
||||
case 'pgsz':
|
||||
{
|
||||
float w, h;
|
||||
msg->FindFloat("width", &w);
|
||||
msg->FindFloat("height", &h);
|
||||
BMenuItem *item = fOrientationMenu->Menu()->FindMarked();
|
||||
if (item) {
|
||||
int32 orientation = 0;
|
||||
BMessage *m = item->Message();
|
||||
m->FindInt32("orientation", &orientation);
|
||||
if (orientation == PrinterDriver::PORTRAIT_ORIENTATION) {
|
||||
fMarginView->SetPageSize(w, h);
|
||||
} else {
|
||||
fMarginView->SetPageSize(h, w);
|
||||
}
|
||||
fMarginView->UpdateView(MARGIN_CHANGED);
|
||||
}
|
||||
case PAGE_SIZE_CHANGED: {
|
||||
float w, h;
|
||||
msg->FindFloat("width", &w);
|
||||
msg->FindFloat("height", &h);
|
||||
if (fCurrentOrientation == PrinterDriver::PORTRAIT_ORIENTATION) {
|
||||
fMarginView->SetPageSize(w, h);
|
||||
} else {
|
||||
fMarginView->SetPageSize(h, w);
|
||||
}
|
||||
break;
|
||||
fMarginView->UpdateView(MARGIN_CHANGED);
|
||||
} break;
|
||||
|
||||
// Simon added
|
||||
case 'ornt':
|
||||
{
|
||||
case ORIENTATION_CHANGED: {
|
||||
int32 orientation;
|
||||
msg->FindInt32("orientation", &orientation);
|
||||
|
||||
if (fCurrentOrientation != orientation) {
|
||||
fCurrentOrientation = orientation;
|
||||
BPoint p = fMarginView->PageSize();
|
||||
int32 orientation;
|
||||
msg->FindInt32("orientation", &orientation);
|
||||
if (orientation == PrinterDriver::LANDSCAPE_ORIENTATION
|
||||
&& p.y > p.x) {
|
||||
fMarginView->SetPageSize(p.y, p.x);
|
||||
fMarginView->UpdateView(MARGIN_CHANGED);
|
||||
}
|
||||
if (orientation == PrinterDriver::PORTRAIT_ORIENTATION
|
||||
&& p.x > p.y) {
|
||||
fMarginView->SetPageSize(p.y, p.x);
|
||||
fMarginView->UpdateView(MARGIN_CHANGED);
|
||||
}
|
||||
fMarginView->SetPageSize(p.y, p.x);
|
||||
fMarginView->UpdateView(MARGIN_CHANGED);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case FONTS_MSG:
|
||||
case FONTS_MSG: {
|
||||
(new FontsWindow(fFonts))->Show();
|
||||
break;
|
||||
} break;
|
||||
|
||||
case ADVANCED_MSG:
|
||||
case ADVANCED_MSG: {
|
||||
(new AdvancedSettingsWindow(&fAdvancedSettings))->Show();
|
||||
break;
|
||||
} break;
|
||||
|
||||
default:
|
||||
inherited::MessageReceived(msg);
|
||||
@@ -575,7 +342,14 @@ PageSetupWindow::MessageReceived(BMessage *msg)
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
bool
|
||||
PageSetupWindow::QuitRequested()
|
||||
{
|
||||
release_sem(fExitSem);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PageSetupWindow::Go()
|
||||
{
|
||||
@@ -589,3 +363,77 @@ PageSetupWindow::Go()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PageSetupWindow::_UpdateSetupMessage()
|
||||
{
|
||||
SetInt32(fSetupMsg, "orientation", fCurrentOrientation);
|
||||
|
||||
BMenuItem *item = fPDFCompatibilityMenu->Menu()->FindMarked();
|
||||
if (item)
|
||||
SetString(fSetupMsg, "pdf_compatibility", item->Label());
|
||||
|
||||
SetInt32(fSetupMsg, "pdf_compression", fPDFCompressionSlider->Value());
|
||||
|
||||
item = fPageSizeMenu->Menu()->FindMarked();
|
||||
if (item) {
|
||||
float w, h;
|
||||
BMessage *msg = item->Message();
|
||||
msg->FindFloat("width", &w);
|
||||
msg->FindFloat("height", &h);
|
||||
BRect r(0, 0, w, h);
|
||||
if (fCurrentOrientation == PrinterDriver::LANDSCAPE_ORIENTATION)
|
||||
r.Set(0, 0, h, w);
|
||||
|
||||
// Save the printable_rect
|
||||
BRect margin = fMarginView->Margin();
|
||||
if (fCurrentOrientation == PrinterDriver::PORTRAIT_ORIENTATION) {
|
||||
margin.right = w - margin.right;
|
||||
margin.bottom = h - margin.bottom;
|
||||
} else {
|
||||
margin.right = h - margin.right;
|
||||
margin.bottom = w - margin.bottom;
|
||||
}
|
||||
|
||||
SetRect(fSetupMsg, "paper_rect", r);
|
||||
SetRect(fSetupMsg, "printable_rect", margin);
|
||||
SetInt32(fSetupMsg, "units", fMarginView->Unit());
|
||||
SetString(fSetupMsg, "pdf_paper_size", item->Label());
|
||||
}
|
||||
|
||||
BMessage fonts;
|
||||
if (fFonts->Archive(&fonts) == B_OK) {
|
||||
fSetupMsg->RemoveName("fonts");
|
||||
fSetupMsg->AddMessage("fonts", &fonts);
|
||||
}
|
||||
|
||||
// advanced settings
|
||||
BString value;
|
||||
if (fAdvancedSettings.FindString("pdflib_license_key", &value) == B_OK)
|
||||
SetString(fSetupMsg, "pdflib_license_key", value);
|
||||
|
||||
bool webLinks;
|
||||
if (fAdvancedSettings.FindBool("create_web_links", &webLinks) == B_OK)
|
||||
SetBool(fSetupMsg, "create_web_links", webLinks);
|
||||
|
||||
float linkBorder;
|
||||
if (fAdvancedSettings.FindFloat("link_border_width", &linkBorder) == B_OK)
|
||||
SetFloat(fSetupMsg, "link_border_width", linkBorder);
|
||||
|
||||
bool createBookmarks;
|
||||
if (fAdvancedSettings.FindBool("create_bookmarks", &createBookmarks) == B_OK)
|
||||
SetBool(fSetupMsg, "create_bookmarks", createBookmarks);
|
||||
|
||||
if (fAdvancedSettings.FindString("bookmark_definition_file", &value) == B_OK)
|
||||
SetString(fSetupMsg, "bookmark_definition_file", value);
|
||||
|
||||
bool createXrefs;
|
||||
if (fAdvancedSettings.FindBool("create_xrefs", &createXrefs) == B_OK)
|
||||
SetBool(fSetupMsg, "create_xrefs", createXrefs);
|
||||
|
||||
if (fAdvancedSettings.FindString("xrefs_file", &value) == B_OK)
|
||||
SetString(fSetupMsg, "xrefs_file", value.String());
|
||||
|
||||
int32 closeOption;
|
||||
if (fAdvancedSettings.FindInt32("close_option", &closeOption) == B_OK)
|
||||
SetInt32(fSetupMsg, "close_option", closeOption);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
PDF Writer printer driver.
|
||||
|
||||
Copyright (c) 2001 OpenBeOS.
|
||||
Copyright (c) 2001 OpenBeOS.
|
||||
|
||||
Authors:
|
||||
Authors:
|
||||
Philippe Houdoin
|
||||
Simon Gauvin
|
||||
Michael Pfeiffer
|
||||
@@ -32,65 +32,60 @@ THE SOFTWARE.
|
||||
#ifndef PAGESETUPWINDOW_H
|
||||
#define PAGESETUPWINDOW_H
|
||||
|
||||
#include <InterfaceKit.h>
|
||||
#include <Message.h>
|
||||
#include <Messenger.h>
|
||||
#include <File.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Path.h>
|
||||
#include <String.h>
|
||||
#include "InterfaceUtils.h"
|
||||
#include "Utils.h"
|
||||
#include "Fonts.h"
|
||||
|
||||
#include "InterfaceUtils.h"
|
||||
|
||||
|
||||
#include <Message.h>
|
||||
#include <String.h>
|
||||
|
||||
|
||||
class BMenuField;
|
||||
class BSlider;
|
||||
class Fonts;
|
||||
class MarginView;
|
||||
|
||||
class PageSetupWindow : public HWindow
|
||||
|
||||
class PageSetupWindow : public HWindow
|
||||
{
|
||||
typedef HWindow inherited;
|
||||
public:
|
||||
// Constructors, destructors, operators...
|
||||
|
||||
PageSetupWindow(BMessage *msg, const char *printerName = NULL);
|
||||
~PageSetupWindow();
|
||||
PageSetupWindow(BMessage *msg, const char *printerName = NULL);
|
||||
~PageSetupWindow();
|
||||
|
||||
typedef HWindow inherited;
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
virtual bool QuitRequested();
|
||||
|
||||
status_t Go();
|
||||
|
||||
// public constantes
|
||||
enum {
|
||||
OK_MSG = 'ok__',
|
||||
CANCEL_MSG = 'cncl',
|
||||
FONTS_MSG = 'font',
|
||||
ADVANCED_MSG = 'advc'
|
||||
OK_MSG = 'ok__',
|
||||
CANCEL_MSG = 'cncl',
|
||||
FONTS_MSG = 'font',
|
||||
ADVANCED_MSG = 'advc',
|
||||
PAGE_SIZE_CHANGED = 'pgsz',
|
||||
ORIENTATION_CHANGED = 'ornt'
|
||||
};
|
||||
|
||||
// Virtual function overrides
|
||||
public:
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
virtual bool QuitRequested();
|
||||
status_t Go();
|
||||
|
||||
// From here, it's none of your business! ;-)
|
||||
private:
|
||||
long fExitSem;
|
||||
status_t fResult;
|
||||
BMessage * fSetupMsg;
|
||||
BMenuField * fPageSizeMenu;
|
||||
BMenuField * fOrientationMenu;
|
||||
BMenuField * fPDFCompatibilityMenu;
|
||||
BSlider * fPDFCompressionSlider;
|
||||
Fonts * fFonts;
|
||||
BMessage fAdvancedSettings;
|
||||
|
||||
void UpdateSetupMessage();
|
||||
void _UpdateSetupMessage();
|
||||
private:
|
||||
long fExitSem;
|
||||
status_t fResult;
|
||||
BMessage* fSetupMsg;
|
||||
BMenuField* fPageSizeMenu;
|
||||
BMenuField* fOrientationMenu;
|
||||
BMenuField* fPDFCompatibilityMenu;
|
||||
BSlider* fPDFCompressionSlider;
|
||||
Fonts* fFonts;
|
||||
BMessage fAdvancedSettings;
|
||||
MarginView * fMarginView;
|
||||
|
||||
MarginView * fMarginView;
|
||||
|
||||
// used for saving settings
|
||||
BString fPrinterDirName;
|
||||
|
||||
//private class constants
|
||||
static const int kMargin = 10;
|
||||
static const int kOffset = 200;
|
||||
// used for saving settings
|
||||
BString fPrinterDirName;
|
||||
int32 fCurrentOrientation;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -273,7 +273,7 @@ PageSetupWindow::UpdateSetupMessage()
|
||||
|
||||
SetRect(fSetupMsg, "preview:paper_rect", r);
|
||||
SetRect(fSetupMsg, "paper_rect", ScaleRect(r, scaleR));
|
||||
AddString(fSetupMsg, "preview:paper_size", item->Label());
|
||||
SetString(fSetupMsg, "preview:paper_size", item->Label());
|
||||
|
||||
// Save the printable_rect
|
||||
BRect margin = fMarginView->Margin();
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
Preview printer driver.
|
||||
|
||||
Copyright (c) 2001, 2002 OpenBeOS.
|
||||
Copyright (c) 2005 Haiku.
|
||||
Copyright (c) 2001, 2002 OpenBeOS.
|
||||
Copyright (c) 2005 - 2008 Haiku.
|
||||
|
||||
Authors:
|
||||
Authors:
|
||||
Philippe Houdoin
|
||||
Simon Gauvin
|
||||
Simon Gauvin
|
||||
Michael Pfeiffer
|
||||
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
@@ -32,18 +32,86 @@ THE SOFTWARE.
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
// --------------------------------------------------
|
||||
EscapeMessageFilter::EscapeMessageFilter(BWindow *window, int32 what)
|
||||
: BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, '_KYD')
|
||||
, fWindow(window),
|
||||
fWhat(what)
|
||||
{
|
||||
|
||||
#include <Message.h>
|
||||
#include <Window.h>
|
||||
|
||||
|
||||
void
|
||||
SetBool(BMessage* msg, const char* name, bool value)
|
||||
{
|
||||
if (msg->HasBool(name)) {
|
||||
msg->ReplaceBool(name, value);
|
||||
} else {
|
||||
msg->AddBool(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
filter_result
|
||||
EscapeMessageFilter::Filter(BMessage *msg, BHandler **target)
|
||||
void
|
||||
SetFloat(BMessage* msg, const char* name, float value)
|
||||
{
|
||||
if (msg->HasFloat(name)) {
|
||||
msg->ReplaceFloat(name, value);
|
||||
} else {
|
||||
msg->AddFloat(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SetInt32(BMessage* msg, const char* name, int32 value)
|
||||
{
|
||||
if (msg->HasInt32(name)) {
|
||||
msg->ReplaceInt32(name, value);
|
||||
} else {
|
||||
msg->AddInt32(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SetString(BMessage* msg, const char* name, const char* value)
|
||||
{
|
||||
if (msg->HasString(name, 0)) {
|
||||
msg->ReplaceString(name, value);
|
||||
} else {
|
||||
msg->AddString(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SetRect(BMessage* msg, const char* name, const BRect& rect)
|
||||
{
|
||||
if (msg->HasRect(name)) {
|
||||
msg->ReplaceRect(name, rect);
|
||||
} else {
|
||||
msg->AddRect(name, rect);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SetString(BMessage* msg, const char* name, const BString& value)
|
||||
{
|
||||
SetString(msg, name, value.String());
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -- EscapeMessageFilter
|
||||
|
||||
|
||||
EscapeMessageFilter::EscapeMessageFilter(BWindow *window, int32 what)
|
||||
: BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, '_KYD')
|
||||
, fWindow(window),
|
||||
fWhat(what)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
filter_result
|
||||
EscapeMessageFilter::Filter(BMessage *msg, BHandler **target)
|
||||
{
|
||||
int32 key;
|
||||
// notify window with message fWhat if Escape key is hit
|
||||
@@ -53,35 +121,3 @@ EscapeMessageFilter::Filter(BMessage *msg, BHandler **target)
|
||||
}
|
||||
return B_DISPATCH_MESSAGE;
|
||||
}
|
||||
|
||||
void AddString(BMessage* m, const char* name, const char* value) {
|
||||
if (m->HasString(name, 0)) {
|
||||
m->ReplaceString(name, value);
|
||||
} else {
|
||||
m->AddString(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
void SetRect(BMessage* msg, const char* name, BRect rect) {
|
||||
if (msg->HasRect(name)) {
|
||||
msg->ReplaceRect(name, rect);
|
||||
} else {
|
||||
msg->AddRect(name, rect);
|
||||
}
|
||||
}
|
||||
|
||||
void SetFloat(BMessage* msg, const char* name, float value) {
|
||||
if (msg->HasFloat(name)) {
|
||||
msg->ReplaceFloat(name, value);
|
||||
} else {
|
||||
msg->AddFloat(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
void SetInt32(BMessage* msg, const char* name, int32 value) {
|
||||
if (msg->HasInt32(name)) {
|
||||
msg->ReplaceInt32(name, value);
|
||||
} else {
|
||||
msg->AddInt32(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user