* 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:
Karsten Heimrich
2008-07-13 11:11:43 +00:00
parent 3be7d0090c
commit a80e05e225
9 changed files with 799 additions and 913 deletions
+15 -5
View File
@@ -3,7 +3,7 @@
PDF Writer printer driver. PDF Writer printer driver.
Copyright (c) 2001, 2002 OpenBeOS. Copyright (c) 2001, 2002 OpenBeOS.
Copyright (c) 2005 Haiku. Copyright (c) 2005 - 2008 Haiku.
Authors: Authors:
Philippe Houdoin Philippe Houdoin
@@ -33,17 +33,27 @@ THE SOFTWARE.
#ifndef _UTILS_H #ifndef _UTILS_H
#define _UTILS_H #define _UTILS_H
#include <Window.h>
#include <Message.h> #include <List.h>
#include <MessageFilter.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 // 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 SetFloat(BMessage* msg, const char* name, float value);
void SetInt32(BMessage* msg, const char* name, int32 value); void SetInt32(BMessage* msg, const char* name, int32 value);
void SetString(BMessage* msg, const char* name, const char* value);
void SetRect(BMessage* msg, const char* name, const BRect& rect);
void SetString(BMessage* msg, const char* name, const BString& value);
class EscapeMessageFilter : public BMessageFilter class EscapeMessageFilter : public BMessageFilter
{ {
@@ -27,15 +27,21 @@ THE SOFTWARE.
*/ */
#include <InterfaceKit.h>
#include <SupportKit.h>
#include <StorageKit.h>
#include "AdvancedSettingsWindow.h" #include "AdvancedSettingsWindow.h"
#include "Utils.h"
#define SETTINGS_PATH "/boot/home/config/settings/PDF Writer/" #include <Box.h>
#define BOOKMARKS_PATH SETTINGS_PATH "bookmarks/" #include <Button.h>
#define XREFS_PATH SETTINGS_PATH "xrefs/" #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) static BMessage* BorderWidthMessage(uint32 what, float width)
{ {
@@ -44,310 +50,273 @@ static BMessage* BorderWidthMessage(uint32 what, float width)
return m; return m;
} }
// --------------------------------------------------
AdvancedSettingsWindow::AdvancedSettingsWindow(BMessage *settings) AdvancedSettingsWindow::AdvancedSettingsWindow(BMessage *settings)
: HWindow(BRect(0, 0, 400, 180), "Advanced Settings", B_TITLED_WINDOW_LOOK, : HWindow(BRect(0, 0, 400, 180), "Advanced Settings", B_TITLED_WINDOW_LOOK,
B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE |
B_NOT_ZOOMABLE) 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)); 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);
x = 5; y = 5; w = r.Width(); h = r.Height();
// PDFlib license key
#if 0
BString licenseKey; BString licenseKey;
if (settings->FindString("pdflib_license_key", &licenseKey) != B_OK) licenseKey = ""; if (settings->FindString("pdflib_license_key", &licenseKey) != B_OK)
fLicenseKey = new BTextControl(BRect(x, y, x+2-10, y+14), "pdflib_license_key", "PDFlib License Key", "", NULL); licenseKey = "Not supported.";
fLicenseKey->TextView()->HideTyping(true);
fLicenseKey->TextView()->SetText(licenseKey.String());
panel->AddChild(fLicenseKey);
fLicenseKey->ResizeToPreferred();
y += fLicenseKey->Bounds().Height()+5;
#endif
// web links if (settings->FindBool("create_web_links", &fCreateLinks) != B_OK)
if (settings->FindBool("create_web_links", &fCreateLinks) != B_OK) fCreateLinks = false; 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; 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))); m->AddItem(item = new BMenuItem("None", new BMessage(CREATE_LINKS_MSG)));
item->SetMarked(!fCreateLinks); item->SetMarked(!fCreateLinks);
m->AddSeparatorItem(); m->AddSeparatorItem();
m->AddItem(item = new BMenuItem("No Border", BorderWidthMessage(LINK_BORDER_MSG, 0.0))); m->AddItem(item = new BMenuItem("No Border", BorderWidthMessage(LINK_BORDER_MSG, 0.0)));
if (fCreateLinks && fLinkBorderWidth == 0) item->SetMarked(true); if (fCreateLinks && fLinkBorderWidth == 0)
m->AddItem(item = new BMenuItem("Normal Border", BorderWidthMessage(LINK_BORDER_MSG, 1.0))); item->SetMarked(true);
if (fCreateLinks && fLinkBorderWidth == 1) item->SetMarked(true);
m->AddItem(item = new BMenuItem("Bold Border", BorderWidthMessage(LINK_BORDER_MSG, 2.0))); m->AddItem(item = new BMenuItem("Normal Border", BorderWidthMessage(LINK_BORDER_MSG, 1.0)));
if (fCreateLinks && fLinkBorderWidth == 2) item->SetMarked(true); 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;
// bookmarks // bookmarks
if (settings->FindBool("create_bookmarks", &fCreateBookmarks) != B_OK) fCreateBookmarks = false; m = new BPopUpMenu("Bookmark Definition File");
m = new BPopUpMenu("definition");
m->SetRadioMode(true); 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))); m->AddItem(item = new BMenuItem("None", new BMessage(CREATE_BOOKMARKS_MSG)));
item->SetMarked(!fCreateBookmarks); item->SetMarked(!fCreateBookmarks);
m->AddSeparatorItem(); m->AddSeparatorItem();
BDirectory folder; BDirectory bookmarks(_SetupDirectory("bookmarks"));
if (bookmarks.InitCheck() == B_OK) {
BEntry entry; BEntry entry;
while (bookmarks.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) {
// XXX: B_USER_SETTINGS_DIRECTORY
folder.SetTo (BOOKMARKS_PATH);
if (folder.InitCheck() == B_OK) {
while (folder.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) {
char name[B_FILE_NAME_LENGTH]; 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(DEFINITION_MSG))); m->AddItem(item = new BMenuItem(name, new BMessage(DEFINITION_MSG)));
if (fCreateBookmarks && strcmp(name, fBookmarkDefinition.String()) == 0) item->SetMarked(true); if (fCreateBookmarks && strcmp(name, fBookmarkDefinition.String()) == 0)
item->SetMarked(true);
}
} }
} }
// cross references // 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); 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))); m->AddItem(item = new BMenuItem("None", new BMessage(CREATE_XREFS_MSG)));
item->SetMarked(!fCreateXRefs); item->SetMarked(!fCreateXRefs);
m->AddSeparatorItem(); m->AddSeparatorItem();
// XXX: B_USER_SETTINGS_DIRECTORY BDirectory xrefs(_SetupDirectory("xrefs"));
folder.SetTo (XREFS_PATH); if (xrefs.InitCheck() == B_OK) {
if (folder.InitCheck() == B_OK) { BEntry entry;
while (folder.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) { while (xrefs.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) {
char name[B_FILE_NAME_LENGTH]; 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))); 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 m = new BPopUpMenu("Close status window when done");
// - Never
// - No Errors
// - No Errors and Warnings
// - Always
m = new BPopUpMenu("close option");
m->SetRadioMode(true); 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); panel->AddChild(mf);
mf->ResizeToPreferred();
mf->SetDivider(divider);
mf->Menu()->SetLabelFromMarked(true);
int32 closeOption; _AddMenuItem(m, "Never", kNever);
if (settings->FindInt32("close_option", &closeOption) != B_OK) closeOption = kNever; _AddMenuItem(m, "No Errors", kNoErrors);
fCloseOption = (CloseOption)closeOption; _AddMenuItem(m, "No Errors or Warnings", kNoErrorsOrWarnings);
AddMenuItem(m, "Never", kNever); _AddMenuItem(m, "No Errors, Warnings or Info", kNoErrorsWarningsOrInfo);
AddMenuItem(m, "No Errors", kNoErrors); _AddMenuItem(m, "Always", kAlways);
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 bounds = Bounds();
button = new BButton(r, NULL, "OK", new BMessage(OK_MSG), bounds.InsetBy(5.0, 0.0);
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); bounds.top = mf->Frame().bottom + 10.0;
button->ResizeToPreferred(); BBox *line = new BBox(BRect(bounds.left, bounds.top, bounds.right,
button->GetPreferredSize(&w, &h); bounds.top + 1.0), NULL, B_FOLLOW_LEFT_RIGHT);
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 );
panel->AddChild(line); panel->AddChild(line);
// Finally, add our panel to window bounds.InsetBy(5.0, 0.0);
AddChild(panel); bounds.OffsetBy(0.0, 11.0);
BButton *cancel = new BButton(bounds, NULL, "Cancel", new BMessage(CANCEL_MSG));
panel->AddChild(cancel);
cancel->ResizeToPreferred();
MoveTo(320, 320); BButton *ok = new BButton(bounds, NULL, "OK", new BMessage(OK_MSG));
} panel->AddChild(ok, cancel);
ok->ResizeToPreferred();
void bounds.right = fLicenseKey->Frame().right;
AdvancedSettingsWindow::UpdateSettings() ok->MoveTo(bounds.right - ok->Bounds().Width(), ok->Frame().top);
{
#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")) { bounds = ok->Frame();
fSettings->ReplaceBool("create_web_links", fCreateLinks); cancel->MoveTo(bounds.left - cancel->Bounds().Width() - 10.0, bounds.top);
} else {
fSettings->AddBool("create_web_links", fCreateLinks);
}
if (fSettings->HasFloat("link_border_width")) { ok->MakeDefault(true);
fSettings->ReplaceFloat("link_border_width", fLinkBorderWidth); ResizeTo(bounds.right + 10.0, bounds.bottom + 10.0);
} else {
fSettings->AddFloat("link_border_width", fLinkBorderWidth);
}
if (fSettings->HasBool("create_bookmarks")) { BButton *button = new BButton(bounds, NULL, "Open Settings Folder" B_UTF8_ELLIPSIS,
fSettings->ReplaceBool("create_bookmarks", fCreateBookmarks); new BMessage(OPEN_SETTINGS_FOLDER_MSG));
} else { panel->AddChild(button);
fSettings->AddBool("create_bookmarks", fCreateBookmarks); button->ResizeToPreferred();
} button->MoveTo(fLicenseKey->Frame().left, bounds.top);
if (fSettings->HasString("bookmark_definition_file")) { BRect winFrame(Frame());
fSettings->ReplaceString("bookmark_definition_file", fBookmarkDefinition.String()); BRect screenFrame(BScreen().Frame());
} else { MoveTo((screenFrame.right - winFrame.right) / 2,
fSettings->AddString("bookmark_definition_file", fBookmarkDefinition.String()); (screenFrame.bottom - winFrame.bottom) / 2);
}
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 void
AdvancedSettingsWindow::MessageReceived(BMessage *msg) AdvancedSettingsWindow::MessageReceived(BMessage *msg)
{ {
float w;
void *source; void *source;
int32 closeOption; BMenuItem *item = NULL;
if (msg->FindPointer("source", &source) == B_OK)
if (msg->FindPointer("source", &source) != B_OK) source = NULL; item = static_cast<BMenuItem*> (source);
switch (msg->what){ switch (msg->what){
case OK_MSG: UpdateSettings(); Quit(); case OK_MSG: {
break; _UpdateSettings();
Quit();
} break;
case CANCEL_MSG: Quit(); case CANCEL_MSG: {
break; Quit();
} break;
case CREATE_LINKS_MSG: case CREATE_LINKS_MSG: {
fCreateLinks = false; fCreateLinks = false;
break; } break;
case LINK_BORDER_MSG: case LINK_BORDER_MSG: {
float w;
if (msg->FindFloat("width", &w) == B_OK) { if (msg->FindFloat("width", &w) == B_OK) {
fLinkBorderWidth = w; fLinkBorderWidth = w;
fCreateLinks = true; fCreateLinks = true;
} }
break; } break;
case CREATE_BOOKMARKS_MSG: case CREATE_BOOKMARKS_MSG: {
fCreateBookmarks = false; fCreateBookmarks = false;
break; } break;
case DEFINITION_MSG: case DEFINITION_MSG: {
if (source) { if (item) {
BMenuItem* item = (BMenuItem*)source;
fBookmarkDefinition = item->Label(); fBookmarkDefinition = item->Label();
fCreateBookmarks = true; fCreateBookmarks = true;
} }
break; } break;
case CREATE_XREFS_MSG: case CREATE_XREFS_MSG: {
fCreateXRefs = false; fCreateXRefs = false;
break; } break;
case XREFS_MSG: case XREFS_MSG: {
if (source) { if (item) {
BMenuItem* item = (BMenuItem*)source;
fXRefs = item->Label(); fXRefs = item->Label();
fCreateXRefs = true; fCreateXRefs = true;
} }
break; } break;
case AUTO_CLOSE_MSG: case AUTO_CLOSE_MSG: {
if (msg->FindInt32("close_option", &closeOption) == B_OK) { int32 closeOption;
if (msg->FindInt32("close_option", &closeOption) == B_OK)
fCloseOption = (CloseOption)closeOption; fCloseOption = (CloseOption)closeOption;
} } break;
break;
case OPEN_SETTINGS_FOLDER_MSG: case OPEN_SETTINGS_FOLDER_MSG: {
{ BPath path;
char* argv[] = { SETTINGS_PATH }; find_directory(B_USER_SETTINGS_DIRECTORY, &path, false);
be_roster->Launch("application/x-vnd.Be-TRAK", 1, argv); 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; } break;
default: default:
inherited::MessageReceived(msg); inherited::MessageReceived(msg);
@@ -355,3 +324,58 @@ AdvancedSettingsWindow::MessageReceived(BMessage *msg)
} }
} }
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);
}
@@ -32,27 +32,30 @@ THE SOFTWARE.
#ifndef ADVANCED_SETTINGS_WINDOW_H #ifndef ADVANCED_SETTINGS_WINDOW_H
#define 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 "InterfaceUtils.h"
#include "Utils.h"
#include "PrinterDriver.h" #include "PrinterDriver.h"
#include <Directory.h>
#include <String.h>
class BMessage;
class BPopUpMenu;
class BTextControl;
class AdvancedSettingsWindow : public HWindow class AdvancedSettingsWindow : public HWindow
{ {
typedef HWindow inherited;
public: public:
// Constructors, destructors, operators... // Constructors, destructors, operators...
AdvancedSettingsWindow(BMessage *doc_info); AdvancedSettingsWindow(BMessage *doc_info);
typedef HWindow inherited; virtual void MessageReceived(BMessage *msg);
// public constantes
enum { enum {
OK_MSG = 'ok__', OK_MSG = 'ok__',
CANCEL_MSG = 'cncl', CANCEL_MSG = 'cncl',
@@ -66,14 +69,13 @@ public:
OPEN_SETTINGS_FOLDER_MSG = 'opsf', OPEN_SETTINGS_FOLDER_MSG = 'opsf',
}; };
// Virtual function overrides private:
public: void _UpdateSettings();
virtual void MessageReceived(BMessage *msg); BDirectory _SetupDirectory(const char* dirName);
void _AddMenuItem(BPopUpMenu* menu, const char* label, CloseOption option);
private: private:
BMessage* fSettings; BMessage* fSettings;
BTextControl* fLicenseKey; BTextControl* fLicenseKey;
bool fCreateLinks; bool fCreateLinks;
float fLinkBorderWidth; float fLinkBorderWidth;
@@ -82,9 +84,6 @@ private:
bool fCreateXRefs; bool fCreateXRefs;
BString fXRefs; BString fXRefs;
CloseOption fCloseOption; CloseOption fCloseOption;
void UpdateSettings();
void AddMenuItem(BPopUpMenu* menu, const char* label, CloseOption option);
}; };
#endif #endif
+24 -48
View File
@@ -37,8 +37,10 @@ THE SOFTWARE.
#include "Driver.h" #include "Driver.h"
#include "PDFWriter.h" #include "PDFWriter.h"
#include "PrinterDriver.h"
#include "PrinterSettings.h" #include "PrinterSettings.h"
static PrinterDriver *instanciate_driver(BNode *spoolDir); static PrinterDriver *instanciate_driver(BNode *spoolDir);
// ======== For testing only ================== // ======== For testing only ==================
@@ -46,88 +48,64 @@ static PrinterDriver *instanciate_driver(BNode *spoolDir);
BMessage* BMessage*
take_job(BFile *spoolFile, BNode *spoolDir, BMessage *msg) take_job(BFile *spoolFile, BNode *spoolDir, BMessage *msg)
{ {
PrinterDriver *driver; PrinterDriver *driver = instanciate_driver(spoolDir);
status_t status = driver->PrintJob(spoolFile, spoolDir, msg);
driver = instanciate_driver(spoolDir);
if (driver->PrintJob(spoolFile, spoolDir, msg) == B_OK) {
msg = new BMessage('okok');
} else {
msg = new BMessage('baad');
}
delete driver; delete driver;
msg = new BMessage('okok');
if (status != B_OK)
msg->what = 'baad';
return msg; return msg;
} }
// --------------------------------------------------
BMessage* BMessage*
config_page(BNode *spoolDir, BMessage *msg) config_page(BNode *spoolDir, BMessage *msg)
{ {
BMessage *pagesetupMsg; BMessage *pagesetupMsg = new BMessage(*msg);
PrinterDriver *driver;
const char *printerName;
char buffer[B_ATTR_NAME_LENGTH+1];
pagesetupMsg = new BMessage(*msg);
PrinterSettings::Read(spoolDir, pagesetupMsg, PrinterSettings::kPageSettings); PrinterSettings::Read(spoolDir, pagesetupMsg, PrinterSettings::kPageSettings);
// retrieve the printer (spool) name. BString printerName;
printerName = NULL; spoolDir->ReadAttrString("Printer Name", &printerName);
if (spoolDir->ReadAttr("Printer Name", B_STRING_TYPE, 1, buffer, B_ATTR_NAME_LENGTH+1) > 0) {
printerName = buffer;
}
driver = instanciate_driver(spoolDir); PrinterDriver *driver = instanciate_driver(spoolDir);
if (driver->PageSetup(pagesetupMsg, printerName) == B_OK) { if (driver->PageSetup(pagesetupMsg, printerName.String()) == B_OK) {
pagesetupMsg->what = 'okok'; pagesetupMsg->what = 'okok';
PrinterSettings::Update(spoolDir, pagesetupMsg, PrinterSettings::kPageSettings); PrinterSettings::Update(spoolDir, pagesetupMsg,
PrinterSettings::kPageSettings);
} else { } else {
delete pagesetupMsg; delete pagesetupMsg;
pagesetupMsg = NULL; pagesetupMsg = NULL;
} }
delete driver; delete driver;
return pagesetupMsg; return pagesetupMsg;
} }
// --------------------------------------------------
BMessage* BMessage*
config_job(BNode *spoolDir, BMessage *msg) config_job(BNode *spoolDir, BMessage *msg)
{ {
BMessage *jobsetupMsg; BMessage *jobsetupMsg = new BMessage(*msg);
PrinterDriver *driver;
const char *printerName;
char buffer[B_ATTR_NAME_LENGTH+1];
jobsetupMsg = new BMessage(*msg);
PrinterSettings::Read(spoolDir, jobsetupMsg, PrinterSettings::kJobSettings); PrinterSettings::Read(spoolDir, jobsetupMsg, PrinterSettings::kJobSettings);
// retrieve the printer (spool) name. BString printerName;
printerName = NULL; spoolDir->ReadAttrString("Printer Name", &printerName);
if (spoolDir->ReadAttr("Printer Name", B_STRING_TYPE, 1, buffer, B_ATTR_NAME_LENGTH+1) > 0) {
printerName = buffer; PrinterDriver *driver = instanciate_driver(spoolDir);
} if (driver->JobSetup(jobsetupMsg, printerName.String()) == B_OK) {
driver = instanciate_driver(spoolDir);
if (driver->JobSetup(jobsetupMsg, printerName) == B_OK) {
jobsetupMsg->what = 'okok'; jobsetupMsg->what = 'okok';
PrinterSettings::Update(spoolDir, jobsetupMsg, PrinterSettings::kJobSettings); PrinterSettings::Update(spoolDir, jobsetupMsg,
PrinterSettings::kJobSettings);
} else { } else {
delete jobsetupMsg; delete jobsetupMsg;
jobsetupMsg = NULL; jobsetupMsg = NULL;
} }
delete driver; delete driver;
return jobsetupMsg; return jobsetupMsg;
} }
// --------------------------------------------------
char* char*
add_printer(char *printerName) add_printer(char *printerName)
{ {
@@ -135,13 +113,13 @@ add_printer(char *printerName)
} }
// --------------------------------------------------
static PrinterDriver* static PrinterDriver*
instanciate_driver(BNode *spoolDir) instanciate_driver(BNode *spoolDir)
{ {
return new PDFWriter(); return new PDFWriter();
} }
/** /**
* default_settings * default_settings
* *
@@ -152,9 +130,7 @@ BMessage*
default_settings(BNode* printer) default_settings(BNode* printer)
{ {
BMessage *msg = new BMessage(); BMessage *msg = new BMessage();
PrinterSettings::Read(printer, msg, PrinterSettings::kPageSettings); PrinterSettings::Read(printer, msg, PrinterSettings::kPageSettings);
return msg; return msg;
} }
@@ -33,11 +33,9 @@ THE SOFTWARE.
extern "C" extern "C"
{ {
__declspec(dllexport) BMessage * take_job(BFile * spool_file, BNode * spool_dir, BMessage * msg); BMessage * take_job(BFile * spool_file, BNode * spool_dir, BMessage * msg);
__declspec(dllexport) BMessage * config_page(BNode * spool_dir, BMessage * msg); BMessage * config_page(BNode * spool_dir, BMessage * msg);
__declspec(dllexport) BMessage * config_job(BNode * spool_dir, BMessage * msg); BMessage * config_job(BNode * spool_dir, BMessage * msg);
__declspec(dllexport) char * add_printer(char * printer_name); char * add_printer(char * printer_name);
__declspec(dllexport) BMessage * default_settings(BNode * printer); BMessage * default_settings(BNode * printer);
} }
@@ -31,15 +31,26 @@ THE SOFTWARE.
*/ */
#include <InterfaceKit.h>
#include <SupportKit.h>
#include "pdflib.h" // for pageFormat constants
#include "PrinterDriver.h"
#include "PageSetupWindow.h" #include "PageSetupWindow.h"
#include "MarginView.h"
#include "FontsWindow.h"
#include "AdvancedSettingsWindow.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 global variables
static struct static struct
@@ -79,272 +90,197 @@ static struct
// PDFLib 5.x does not support PDF 1.2 anymore! // 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) PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
: HWindow(BRect(0,0,400,220), "Page Setup", B_TITLED_WINDOW_LOOK, : HWindow(BRect(0,0,400,220), "Page Setup", B_TITLED_WINDOW_LOOK,
B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE |
B_NOT_ZOOMABLE) B_NOT_ZOOMABLE),
fResult(B_ERROR),
fSetupMsg(msg),
fAdvancedSettings(*msg),
fPrinterDirName(printerName)
{ {
fSetupMsg = msg;
fExitSem = create_sem(0, "PageSetup"); fExitSem = create_sem(0, "PageSetup");
fResult = B_ERROR;
fAdvancedSettings = *msg;
if ( printerName ) { if (printerName)
BString title; SetTitle(BString(printerName).Append(" Page Setup").String());
title << printerName << " Page Setup"; if (fSetupMsg->FindInt32("orientation", &fCurrentOrientation) != B_OK)
SetTitle( title.String() ); fCurrentOrientation = PrinterDriver::PORTRAIT_ORIENTATION;
// save the printer name BRect page;
fPrinterDirName = printerName; 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 BString label;
BRect r; if (fSetupMsg->FindString("pdf_paper_size", &label) != B_OK)
BBox *panel; label = "Letter";
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; int32 compression;
BString setting_value;
// 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
fSetupMsg->FindInt32("pdf_compression", &compression); fSetupMsg->FindInt32("pdf_compression", &compression);
// Load units int32 units;
fSetupMsg->FindInt32("units", &units); if (fSetupMsg->FindInt32("units", &units) != B_OK)
units = kUnitInch;
// Load printable rect // re-calculate the margin from the printable rect in points
fSetupMsg->FindRect("printable_rect", &margin); 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 BString setting_value;
fSetupMsg->FindString("pdf_compatibility", &setting_value); if (fSetupMsg->FindString("pdf_compatibility", &setting_value) != B_OK)
setting_value = "1.3";
// Load font settings // Load font settings
fFonts = new Fonts(); fFonts = new Fonts();
fFonts->CollectFonts(); fFonts->CollectFonts();
BMessage fonts; BMessage fonts;
if (fSetupMsg->FindMessage("fonts", &fonts) == B_OK) { if (fSetupMsg->FindMessage("fonts", &fonts) == B_OK)
fFonts->SetTo(&fonts); fFonts->SetTo(&fonts);
}
// add a *dialog* background // add a *dialog* background
r = Bounds(); BRect bounds(Bounds());
panel = new BBox(r, "top_panel", B_FOLLOW_ALL, BBox *panel = new BBox(bounds, "background", B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER);
B_PLAIN_BORDER); AddChild(panel);
////////////// Create the margin view ////////////////////// bounds.InsetBy(10.0, 10.0);
bounds.right = 230.0;
// re-calculate the margin from the printable rect in points bounds.bottom = 160.0;
margin.top -= page.top; fMarginView = new MarginView(bounds, int32(width), int32(height), margin,
margin.left -= page.left; MarginUnit(units));
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);
panel->AddChild(fMarginView); panel->AddChild(fMarginView);
fMarginView->SetResizingMode(B_FOLLOW_NONE);
// add page format menu BPopUpMenu* m = new BPopUpMenu("Page Size");
// Simon Changed to OFFSET popups
x = r.left + kMargin * 2 + kOffset; y = r.top + kMargin * 2;
BPopUpMenu* m = new BPopUpMenu("page_size");
m->SetRadioMode(true); m->SetRadioMode(true);
// Simon changed width 200->140 bounds.OffsetBy(bounds.Width() + 10.0, 5.0);
BMenuField *mf = new BMenuField(BRect(x, y, x + 140, y + 20), "page_size", float divider = be_plain_font->StringWidth("PDF Compatibility: ");
"Page Size:", m); fPageSizeMenu = new BMenuField(bounds, "page_size", "Page Size:", m);
fPageSizeMenu = mf; panel->AddChild(fPageSizeMenu);
mf->ResizeToPreferred(); fPageSizeMenu->ResizeToPreferred();
mf->GetPreferredSize(&w, &h); fPageSizeMenu->SetDivider(divider);
fPageSizeMenu->Menu()->SetLabelFromMarked(true);
// Simon added: SetDivider for (int32 i = 0; pageFormat[i].label != NULL; i++) {
mf->SetDivider(be_plain_font->StringWidth("Page Size#")); 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); if (label.Compare(pageFormat[i].label) == 0)
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;
}
}
mf->Menu()->SetLabelFromMarked(true);
if (!item) {
item = m->ItemAt(0);
}
item->SetMarked(true); item->SetMarked(true);
mf->MenuItem()->SetLabel(item->Label()); }
// add orientation menu m = new BPopUpMenu("Orientation");
y += h + kMargin;
m = new BPopUpMenu("orientation");
m->SetRadioMode(true); m->SetRadioMode(true);
// Simon changed 200->140 bounds.OffsetBy(0.0, fPageSizeMenu->Bounds().Height() + 10.0);
mf = new BMenuField(BRect(x, y, x + 140, y + 20), "orientation", "Orientation:", m); fOrientationMenu = new BMenuField(bounds, "orientation", "Orientation:", m);
panel->AddChild(fOrientationMenu);
fOrientationMenu->ResizeToPreferred();
fOrientationMenu->SetDivider(divider);
fOrientationMenu->Menu()->SetLabelFromMarked(true);
// Simon added: SetDivider for (int32 i = 0; orientation[i].label != NULL; i++) {
mf->SetDivider(be_plain_font->StringWidth("Orientation#")); 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; if (fCurrentOrientation == orientation[i].orientation)
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;
}
}
mf->Menu()->SetLabelFromMarked(true);
// SHOULD BE REMOVED
if (!item) {
item = m->ItemAt(0);
}
///////////////////
item->SetMarked(true); item->SetMarked(true);
mf->MenuItem()->SetLabel(item->Label()); }
// add PDF comptibility menu m = new BPopUpMenu("PDF Compatibility");
y += h + kMargin;
m = new BPopUpMenu("pdf_compatibility");
m->SetRadioMode(true); 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; bounds.OffsetBy(0.0, fOrientationMenu->Bounds().Height() + 10.0);
for (int i = 0; pdf_compatibility[i] != NULL; i++) fPDFCompatibilityMenu = new BMenuField(bounds, "pdf_compatibility",
{ "PDF Compatibility:", m);
BMenuItem* mi = new BMenuItem(pdf_compatibility[i], NULL); panel->AddChild(fPDFCompatibilityMenu);
m->AddItem(mi); fPDFCompatibilityMenu->ResizeToPreferred();
fPDFCompatibilityMenu->SetDivider(divider);
//(new BAlert("", setting_value.String(), pdf_compatibility[i]))->Go(); fPDFCompatibilityMenu->Menu()->SetLabelFromMarked(true);
if (setting_value == pdf_compatibility[i]) {
item = mi;
}
}
mf->Menu()->SetLabelFromMarked(true);
/// SHOULD BE REMOVED
if (!item) {
item = m->ItemAt(0);
}
////////////////////
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); item->SetMarked(true);
mf->MenuItem()->SetLabel(item->Label()); }
// add PDF compression slider bounds.OffsetBy(0.0, fPDFCompatibilityMenu->Bounds().Height() + 10.0);
y += h + kMargin; 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();
BSlider * slider = new BSlider(BRect(x, y, panel->Bounds().right - kMargin, y + 20), "pdf_compression", bounds = Bounds();
"Compression:", bounds.InsetBy(5.0, 0.0);
NULL, 0, 9); bounds.top = MAX(fPDFCompressionSlider->Frame().bottom,
fPDFCompressionSlider = slider; fMarginView->Frame().bottom) + 10.0;
BBox *line = new BBox(BRect(bounds.left, bounds.top, bounds.right,
panel->AddChild(slider); bounds.top + 1.0), NULL, B_FOLLOW_LEFT_RIGHT);
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 );
panel->AddChild(line); panel->AddChild(line);
// Finally, add our panel to window bounds.InsetBy(5.0, 0.0);
AddChild(panel); 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() PageSetupWindow::~PageSetupWindow()
{ {
delete_sem(fExitSem); 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 void
PageSetupWindow::MessageReceived(BMessage *msg) PageSetupWindow::MessageReceived(BMessage *msg)
{ {
switch (msg->what) { switch (msg->what) {
case OK_MSG: case OK_MSG: {
UpdateSetupMessage(); _UpdateSetupMessage();
fResult = B_OK; fResult = B_OK;
release_sem(fExitSem); release_sem(fExitSem);
break; } break;
case CANCEL_MSG: case CANCEL_MSG: {
fResult = B_ERROR; fResult = B_ERROR;
release_sem(fExitSem); release_sem(fExitSem);
break; } break;
// Simon added case PAGE_SIZE_CHANGED: {
case 'pgsz':
{
float w, h; float w, h;
msg->FindFloat("width", &w); msg->FindFloat("width", &w);
msg->FindFloat("height", &h); msg->FindFloat("height", &h);
BMenuItem *item = fOrientationMenu->Menu()->FindMarked(); if (fCurrentOrientation == PrinterDriver::PORTRAIT_ORIENTATION) {
if (item) {
int32 orientation = 0;
BMessage *m = item->Message();
m->FindInt32("orientation", &orientation);
if (orientation == PrinterDriver::PORTRAIT_ORIENTATION) {
fMarginView->SetPageSize(w, h); fMarginView->SetPageSize(w, h);
} else { } else {
fMarginView->SetPageSize(h, w); fMarginView->SetPageSize(h, w);
} }
fMarginView->UpdateView(MARGIN_CHANGED); fMarginView->UpdateView(MARGIN_CHANGED);
} } break;
}
break;
// Simon added case ORIENTATION_CHANGED: {
case 'ornt':
{
BPoint p = fMarginView->PageSize();
int32 orientation; int32 orientation;
msg->FindInt32("orientation", &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);
}
}
break;
case FONTS_MSG: if (fCurrentOrientation != orientation) {
fCurrentOrientation = orientation;
BPoint p = fMarginView->PageSize();
fMarginView->SetPageSize(p.y, p.x);
fMarginView->UpdateView(MARGIN_CHANGED);
}
} break;
case FONTS_MSG: {
(new FontsWindow(fFonts))->Show(); (new FontsWindow(fFonts))->Show();
break; } break;
case ADVANCED_MSG: case ADVANCED_MSG: {
(new AdvancedSettingsWindow(&fAdvancedSettings))->Show(); (new AdvancedSettingsWindow(&fAdvancedSettings))->Show();
break; } break;
default: default:
inherited::MessageReceived(msg); inherited::MessageReceived(msg);
@@ -575,7 +342,14 @@ PageSetupWindow::MessageReceived(BMessage *msg)
} }
// -------------------------------------------------- bool
PageSetupWindow::QuitRequested()
{
release_sem(fExitSem);
return true;
}
status_t status_t
PageSetupWindow::Go() 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);
}
@@ -32,44 +32,45 @@ THE SOFTWARE.
#ifndef PAGESETUPWINDOW_H #ifndef PAGESETUPWINDOW_H
#define 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 MarginView;
class PageSetupWindow : public HWindow class PageSetupWindow : public HWindow
{ {
typedef HWindow inherited;
public: public:
// Constructors, destructors, operators... // Constructors, destructors, operators...
PageSetupWindow(BMessage *msg, const char *printerName = NULL); PageSetupWindow(BMessage *msg, const char *printerName = NULL);
~PageSetupWindow(); ~PageSetupWindow();
typedef HWindow inherited; virtual void MessageReceived(BMessage *msg);
virtual bool QuitRequested();
status_t Go();
// public constantes
enum { enum {
OK_MSG = 'ok__', OK_MSG = 'ok__',
CANCEL_MSG = 'cncl', CANCEL_MSG = 'cncl',
FONTS_MSG = 'font', FONTS_MSG = 'font',
ADVANCED_MSG = 'advc' ADVANCED_MSG = 'advc',
PAGE_SIZE_CHANGED = 'pgsz',
ORIENTATION_CHANGED = 'ornt'
}; };
// Virtual function overrides private:
public: void _UpdateSetupMessage();
virtual void MessageReceived(BMessage *msg);
virtual bool QuitRequested();
status_t Go();
// From here, it's none of your business! ;-)
private: private:
long fExitSem; long fExitSem;
status_t fResult; status_t fResult;
@@ -80,17 +81,11 @@ private:
BSlider* fPDFCompressionSlider; BSlider* fPDFCompressionSlider;
Fonts* fFonts; Fonts* fFonts;
BMessage fAdvancedSettings; BMessage fAdvancedSettings;
void UpdateSetupMessage();
MarginView * fMarginView; MarginView * fMarginView;
// used for saving settings // used for saving settings
BString fPrinterDirName; BString fPrinterDirName;
int32 fCurrentOrientation;
//private class constants
static const int kMargin = 10;
static const int kOffset = 200;
}; };
#endif #endif
@@ -273,7 +273,7 @@ PageSetupWindow::UpdateSetupMessage()
SetRect(fSetupMsg, "preview:paper_rect", r); SetRect(fSetupMsg, "preview:paper_rect", r);
SetRect(fSetupMsg, "paper_rect", ScaleRect(r, scaleR)); 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 // Save the printable_rect
BRect margin = fMarginView->Margin(); BRect margin = fMarginView->Margin();
@@ -3,7 +3,7 @@
Preview printer driver. Preview printer driver.
Copyright (c) 2001, 2002 OpenBeOS. Copyright (c) 2001, 2002 OpenBeOS.
Copyright (c) 2005 Haiku. Copyright (c) 2005 - 2008 Haiku.
Authors: Authors:
Philippe Houdoin Philippe Houdoin
@@ -32,7 +32,76 @@ THE SOFTWARE.
#include "Utils.h" #include "Utils.h"
// --------------------------------------------------
#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);
}
}
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) EscapeMessageFilter::EscapeMessageFilter(BWindow *window, int32 what)
: BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, '_KYD') : BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, '_KYD')
, fWindow(window), , fWindow(window),
@@ -41,7 +110,6 @@ EscapeMessageFilter::EscapeMessageFilter(BWindow *window, int32 what)
} }
// --------------------------------------------------
filter_result filter_result
EscapeMessageFilter::Filter(BMessage *msg, BHandler **target) EscapeMessageFilter::Filter(BMessage *msg, BHandler **target)
{ {
@@ -53,35 +121,3 @@ EscapeMessageFilter::Filter(BMessage *msg, BHandler **target)
} }
return B_DISPATCH_MESSAGE; 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);
}
}