* some code cleanup

* adjusted copyright header
* remove PrinterSetupWindow, simply return the printer name
* some better interface layout, center windows on screen, etc...



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24551 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Karsten Heimrich
2008-03-24 11:30:20 +00:00
parent f9bcddd700
commit 1879dc35bf
13 changed files with 582 additions and 1090 deletions
+27 -64
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2007, Haiku. All rights reserved. * Copyright 2001-2008, Haiku. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -8,119 +8,82 @@
* Michael Pfeiffer * Michael Pfeiffer
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <StorageKit.h> #include <StorageKit.h>
#include "Driver.h" #include "Driver.h"
#include "PrinterDriver.h" #include "PrinterDriver.h"
// --------------------------------------------------
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, msg);
driver = instanciate_driver(spoolDir);
if (driver->PrintJob(spoolFile, 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 = new BMessage(*msg); BString printerName;
PrinterDriver *driver; spoolDir->ReadAttrString("Printer Name", &printerName);
const char *printerName;
char buffer[B_ATTR_NAME_LENGTH+1];
// retrieve the printer (spool) name. BMessage *pagesetupMsg = new BMessage(*msg);
printerName = NULL; pagesetupMsg->what = 'okok';
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';
} 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 = new BMessage(*msg); BString printerName;
PrinterDriver *driver; spoolDir->ReadAttrString("Printer Name", &printerName);
const char *printerName;
char buffer[B_ATTR_NAME_LENGTH+1];
// retrieve the printer (spool) name. BMessage *jobsetupMsg = new BMessage(*msg);
printerName = NULL; jobsetupMsg->what = 'okok';
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';
} 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)
{ {
status_t st; return printerName;
PrinterDriver* driver;
driver = instanciate_driver(NULL);
st = driver->PrinterSetup(printerName);
delete driver;
if (st == B_OK) {
return printerName;
} else {
return NULL;
}
} }
/**
* default_settings
*
* @param BNode* printer spool directory
* @return BMessage* the settings
*/
BMessage* BMessage*
default_settings(BNode* spoolDir) default_settings(BNode* spoolDir)
{ {
PrinterDriver* driver; PrinterDriver *driver = instanciate_driver(spoolDir);
BMessage* settings; BMessage *settings = driver->GetDefaultSettings();
driver = instanciate_driver(spoolDir);
settings = driver->GetDefaultSettings();
delete driver; delete driver;
return settings; return settings;
} }
+6 -7
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007, Haiku. All rights reserved. * Copyright 2002-2008, Haiku. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -12,15 +12,14 @@
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);
} }
class PrinterDriver; class PrinterDriver;
// instanciate_driver has to be implemented by the printer driver // instanciate_driver has to be implemented by the printer driver
PrinterDriver *instanciate_driver(BNode *spoolDir); PrinterDriver *instanciate_driver(BNode *spoolDir);
@@ -10,7 +10,6 @@ UsePrivateHeaders interface ;
AddResources Preview : Preview.rsrc ; AddResources Preview : Preview.rsrc ;
Addon Preview : Addon Preview :
PrinterSetupWindow.cpp
PageSetupWindow.cpp PageSetupWindow.cpp
JobSetupWindow.cpp JobSetupWindow.cpp
Driver.cpp Driver.cpp
@@ -1,255 +1,180 @@
/* /*
* Copyright 2003-2007, Haiku. All rights reserved. * Copyright 2003-2008, Haiku. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Philippe Houdoin * Philippe Houdoin
* Simon Gauvin * Simon Gauvin
* Michael Pfeiffer * Michael Pfeiffer
* julun <[email protected]>
*/ */
#include <InterfaceKit.h> #include "JobSetupWindow.h"
#include <SupportKit.h> #include "PrinterDriver.h"
#include <stdlib.h> #include <stdlib.h>
#include "PrinterDriver.h"
#include "JobSetupWindow.h"
// -------------------------------------------------- #include <Box.h>
#include <Button.h>
#include <RadioButton.h>
#include <Screen.h>
#include <TextControl.h>
JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName) JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName)
: BlockingWindow(BRect(0, 0, 320, 160), "Job Setup", B_TITLED_WINDOW_LOOK, : BlockingWindow(BRect(0, 0, 300, 200), "Job 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),
fPrinterName(printerName),
fSetupMsg(msg)
{ {
MoveTo(300, 300); if (printerName)
SetTitle(BString(printerName).Append(" Job Setup").String());
fSetupMsg = msg; int32 firstPage;
if (printerName) {
BString title;
title << printerName << " Job Setup";
SetTitle(title.String());
fPrinterName = printerName;
}
// ---- Ok, build a default job setup user interface
BRect r;
BBox *panel;
BBox *line;
BButton *ok;
BButton *cancel;
BStringView *sv;
float x, y, w, h;
float indent;
int32 copies;
int32 firstPage;
int32 lastPage;
bool allPages;
char buffer[80];
// PrinterDriver ensures that property exists
fSetupMsg->FindInt32("copies", &copies);
fSetupMsg->FindInt32("first_page", &firstPage); fSetupMsg->FindInt32("first_page", &firstPage);
fSetupMsg->FindInt32("last_page", &lastPage);
allPages = firstPage == 1 && lastPage == MAX_INT32; int32 lastPage;
fSetupMsg->FindInt32("last_page", &lastPage);
bool allPages = firstPage == 1 && lastPage == LONG_MAX;
r = Bounds(); BRect bounds(Bounds());
BBox *panel = new BBox(bounds, "background", B_FOLLOW_ALL,
// add a *dialog* background B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER);
panel = new BBox(r, "top_panel", B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
B_PLAIN_BORDER);
const int kMargin = 6;
//const char *kCopiesLabel = "Copies:";
const char *kCopiesLabelExtraSpace = "Copies:##";
const char *kPagesRangeLabel = "Pages:";
const char *kAllPagesLabel = "All";
const char *kPagesRangeSelectionLabel = "";
const char *kFromLabel = "From:";
const char *kFromLabelExtraSpace = "From:##";
const char *kToLabel = "To:";
const char *kToLabelExtraSpace = "To:##";
r = panel->Bounds();
x = r.left + kMargin;
y = r.top + kMargin;
// add a "copies" input field
/* Simon: temporarily removed this code
sprintf(buffer, "%d", (int)copies);
fCopies = new BTextControl(BRect(x, y, x+100, y+20), "copies", kCopiesLabel,
buffer, new BMessage(NB_COPIES_MSG));
fCopies->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT);
fCopies->ResizeToPreferred();
fCopies->GetPreferredSize(&w, &h);
panel->AddChild(fCopies);
y += h + kMargin; // "new line"
*/
// add a "pages" label
sv = new BStringView(BRect(x, y, x+100, y+20), "pages_range", kPagesRangeLabel);
panel->AddChild(sv);
sv->ResizeToPreferred();
sv->GetPreferredSize(&w, &h);
// align "copies" textcontrol field on the "allPages" radiobutton bellow...
indent = be_plain_font->StringWidth(kCopiesLabelExtraSpace);
w += kMargin;
if ( w > indent )
indent = w;
// fCopies->SetDivider(indent);
x += indent;
// add a "all" radiobutton
fAll = new BRadioButton(BRect(x, y, x+100, y+20), "all_pages", kAllPagesLabel,
new BMessage(ALL_PAGES_MGS));
fAll->ResizeToPreferred();
fAll->GetPreferredSize(&w, &h);
fAll->SetValue(allPages);
panel->AddChild(fAll);
y += h + kMargin; // "new line"
// add a range selection raddiobutton
fRange = new BRadioButton(BRect(x, y, x+100, y+20), "pages_range_selection", kPagesRangeSelectionLabel,
new BMessage(RANGE_SELECTION_MSG));
fRange->ResizeToPreferred();
fRange->GetPreferredSize(&w, &h);
fRange->SetValue(!allPages);
panel->AddChild(fRange);
x += w + kMargin;
// add a "from" field
if (allPages) {
buffer[0] = 0;
} else {
sprintf(buffer, "%d", (int)firstPage);
}
fFrom = new BTextControl(BRect(x, y, x+100, y+20), "from_field", kFromLabel, buffer,
new BMessage(RANGE_FROM_MSG));
fFrom->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT);
fFrom->SetDivider(be_plain_font->StringWidth(kFromLabelExtraSpace));
fFrom->ResizeToPreferred();
fFrom->GetPreferredSize(&w, &h);
panel->AddChild(fFrom);
x += w + kMargin;
// add a "to" field
if (allPages) {
buffer[0] = 0;
} else {
sprintf(buffer, "%d", (int)lastPage);
}
fTo = new BTextControl(BRect(x, y, x+100, y+20), "to_field", kToLabel, buffer,
new BMessage(RANGE_TO_MSG));
fTo->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT);
fTo->SetDivider(be_plain_font->StringWidth(kToLabelExtraSpace));
fTo->ResizeToPreferred();
fTo->GetPreferredSize(&w, &h);
panel->AddChild(fTo);
y += h + kMargin + kMargin; // "new line"
x = r.left + kMargin;
// add a separator line...
line = new BBox(BRect(r.left, y - 1, r.right, y), NULL,
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP );
panel->AddChild(line);
y += 2 + kMargin + kMargin; // "new line"
// add a "OK" button, and make it default
ok = new BButton(BRect(x, y, x+100, y+20), NULL, "OK", new BMessage(OK_MSG), B_FOLLOW_RIGHT | B_FOLLOW_TOP);
ok->MakeDefault(true);
ok->ResizeToPreferred();
ok->GetPreferredSize(&w, &h);
x = r.right - w - kMargin;
ok->MoveTo(x, ok->Frame().top); // put the ok bottom at bottom right corner
panel->AddChild(ok);
// add a "Cancel" button
cancel = new BButton(BRect(x, y, x + 100, y + 20), NULL, "Cancel", new BMessage(CANCEL_MSG), B_FOLLOW_RIGHT | B_FOLLOW_TOP);
cancel->ResizeToPreferred();
cancel->GetPreferredSize(&w, &h);
cancel->MoveTo(x - w - kMargin, y); // put cancel button left next the ok button
panel->AddChild(cancel);
// Finally, add our panel to window
AddChild(panel); AddChild(panel);
// Auto resize window bounds.InsetBy(10.0, 10.0);
ResizeTo(ok->Frame().right + kMargin, ok->Frame().bottom + kMargin);
fAll = new BRadioButton(bounds, "allPages", "Print all pages",
new BMessage(ALL_PAGES_MGS));
panel->AddChild(fAll);
fAll->ResizeToPreferred();
fAll->SetValue(allPages);
bounds.OffsetBy(0.0, fAll->Bounds().Height() + 10.0);
fRange = new BRadioButton(bounds, "pagesRange", "Print pages:",
new BMessage(RANGE_SELECTION_MSG));
panel->AddChild(fRange);
fRange->ResizeToPreferred();
fRange->SetValue(!allPages);
bounds.OffsetBy(0.0, fRange->Bounds().Height() + 5.0);
BRect rect(bounds);
rect.right = be_plain_font->StringWidth("From: SomeSpaceHere");
fFrom = new BTextControl(rect, "from", "From:", "SomeSpaceHere", NULL);
panel->AddChild(fFrom);
fFrom->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT);
fFrom->ResizeToPreferred();
fFrom->SetDivider(be_plain_font->StringWidth("From: "));
fFrom->SetEnabled(!allPages);
fTo = new BTextControl(rect, "to", "To:", "SomeSpaceHere", NULL);
panel->AddChild(fTo);
fTo->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT);
fTo->ResizeToPreferred();
fTo->SetDivider(be_plain_font->StringWidth("To: "));
fTo->MoveTo(fFrom->Frame().right + 10.0, fTo->Frame().top);
fTo->SetEnabled(!allPages);
BString buffer;
buffer << firstPage;
fFrom->SetText(buffer.String());
buffer = "";
buffer << lastPage;
fTo->SetText(buffer.String());
for (uint32 i = 0; i < '0'; i++) {
fTo->TextView()->DisallowChar(i);
fFrom->TextView()->DisallowChar(i);
}
for (uint32 i = '9' + 1; i < 255; i++) {
fTo->TextView()->DisallowChar(i);
fFrom->TextView()->DisallowChar(i);
}
bounds.OffsetBy(0.0, fTo->Bounds().Height() + 10.0);
BBox *line = new BBox(BRect(bounds.left - 5.0, bounds.top, bounds.right + 5.0,
bounds.top + 1.0), NULL, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP );
panel->AddChild(line);
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 = fTo->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);
BRect winFrame(Frame());
BRect screenFrame(BScreen().Frame());
MoveTo((screenFrame.right - winFrame.right) / 2,
(screenFrame.bottom - winFrame.bottom) / 2);
} }
// --------------------------------------------------
void void
JobSetupWindow::UpdateJobMessage() JobSetupWindow::UpdateJobMessage()
{ {
int32 copies = 1; int32 from = 1;
int32 to = LONG_MAX;
int32 from; if (fAll->Value() == B_CONTROL_OFF) {
int32 to;
if (fAll->Value() == B_CONTROL_ON) {
from = 1; to = MAX_INT32;
} else {
from = atoi(fFrom->Text()); from = atoi(fFrom->Text());
to = atoi(fTo->Text()); to = atoi(fTo->Text());
if (from <= 0) from = 1; if (from <= 0) from = 1;
if (to < from) to = from; if (to < from) to = from;
} }
if (fSetupMsg->HasInt32("copies")) { int32 copies = 1;
fSetupMsg->ReplaceInt32("copies", copies); fSetupMsg->RemoveName("copies");
} else { fSetupMsg->AddInt32("copies", copies);
fSetupMsg->AddInt32("copies", copies);
} fSetupMsg->RemoveName("first_page");
if (fSetupMsg->HasInt32("first_page")) { fSetupMsg->AddInt32("first_page", from);
fSetupMsg->ReplaceInt32("first_page", from);
} else { fSetupMsg->RemoveName("last_page");
fSetupMsg->AddInt32("first_page", from); fSetupMsg->AddInt32("last_page", to);
}
if (fSetupMsg->HasInt32("last_page")) {
fSetupMsg->ReplaceInt32("last_page", to);
} else {
fSetupMsg->AddInt32("last_page", to);
}
} }
// --------------------------------------------------
void void
JobSetupWindow::MessageReceived(BMessage *msg) JobSetupWindow::MessageReceived(BMessage *msg)
{ {
switch (msg->what) { switch (msg->what) {
case OK_MSG: case OK_MSG: {
UpdateJobMessage(); UpdateJobMessage();
Quit(B_OK); Quit(B_OK);
break; } break;
case CANCEL_MSG: case CANCEL_MSG: {
Quit(B_ERROR); Quit(B_ERROR);
break; } break;
case RANGE_FROM_MSG: case ALL_PAGES_MGS : {
case RANGE_TO_MSG: fTo->SetEnabled(false);
fRange->SetValue(B_CONTROL_ON); fFrom->SetEnabled(false);
break; } break;
default: case RANGE_SELECTION_MSG : {
inherited::MessageReceived(msg); fTo->SetEnabled(true);
break; fFrom->SetEnabled(true);
} break;
default: {
BlockingWindow::MessageReceived(msg);
} break;
} }
} }
@@ -1,55 +1,53 @@
/* /*
* Copyright 2003-2007, Haiku. All rights reserved. * Copyright 2003-2008, Haiku. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Philippe Houdoin * Philippe Houdoin
* Simon Gauvin * Simon Gauvin
* Michael Pfeiffer * Michael Pfeiffer
* julun <[email protected]>
*/ */
#ifndef JOBSETUPWINDOW_H #ifndef JOBSETUPWINDOW_H
#define JOBSETUPWINDOW_H #define JOBSETUPWINDOW_H
#include <InterfaceKit.h>
#include "InterfaceUtils.h" #include "InterfaceUtils.h"
#include "Utils.h" #include "Utils.h"
#include <String.h>
class BMessage;
class BRadioButton;
class BTextControl;
class JobSetupWindow : public BlockingWindow class JobSetupWindow : public BlockingWindow
{ {
public: public:
// Constructors, destructors, operators... JobSetupWindow(BMessage *msg, const char *printer_name = NULL);
virtual void MessageReceived(BMessage *msg);
JobSetupWindow(BMessage *msg, const char *printer_name = NULL); enum {
ALL_PAGES_MGS = 'all_',
RANGE_SELECTION_MSG = 'rnge',
OK_MSG = 'ok__',
CANCEL_MSG = 'cncl',
};
typedef BlockingWindow inherited;
// public constantes
enum {
NB_COPIES_MSG = 'copy',
ALL_PAGES_MGS = 'all_',
RANGE_SELECTION_MSG = 'rnge',
RANGE_FROM_MSG = 'from',
RANGE_TO_MSG = 'to__',
OK_MSG = 'ok__',
CANCEL_MSG = 'cncl',
};
// Virtual function overrides
public:
virtual void MessageReceived(BMessage *msg);
// From here, it's none of your business! ;-)
private: private:
BString fPrinterName; void UpdateJobMessage();
BMessage *fSetupMsg;
BRadioButton *fAll;
BRadioButton *fRange;
BTextControl *fFrom;
BTextControl *fTo;
void UpdateJobMessage(); private:
BString fPrinterName;
BMessage *fSetupMsg;
BRadioButton *fAll;
BRadioButton *fRange;
BTextControl *fFrom;
BTextControl *fTo;
}; };
#endif #endif
@@ -1,25 +1,60 @@
/* /*
* Copyright 2003-2007, Haiku. All rights reserved. * Copyright 2003-2008, Haiku. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Philippe Houdoin * Philippe Houdoin
* Simon Gauvin * Simon Gauvin
* Michael Pfeiffer * Michael Pfeiffer
* Hartmut Reh * Dr. Hartmut Reh
* julun <[email protected]>
*/ */
#include <stdlib.h>
#include <InterfaceKit.h>
#include <SupportKit.h>
#include "PrinterDriver.h"
#include "PageSetupWindow.h"
#include "BeUtils.h" #include "BeUtils.h"
#include "MarginView.h" #include "MarginView.h"
#include "PrinterDriver.h"
#include "PageSetupWindow.h"
#include <stdlib.h>
#include <Box.h>
#include <Button.h>
#include <MenuField.h>
#include <Message.h>
#include <PopUpMenu.h>
#include <Screen.h>
#include <TextControl.h>
/* copied from PDFlib.h: */
#define a0_width (float) 2380.0
#define a0_height (float) 3368.0
#define a1_width (float) 1684.0
#define a1_height (float) 2380.0
#define a2_width (float) 1190.0
#define a2_height (float) 1684.0
#define a3_width (float) 842.0
#define a3_height (float) 1190.0
#define a4_width (float) 595.0
#define a4_height (float) 842.0
#define a5_width (float) 421.0
#define a5_height (float) 595.0
#define a6_width (float) 297.0
#define a6_height (float) 421.0
#define b5_width (float) 501.0
#define b5_height (float) 709.0
#define letter_width (float) 612.0
#define letter_height (float) 792.0
#define legal_width (float) 612.0
#define legal_height (float) 1008.0
#define ledger_width (float) 1224.0
#define ledger_height (float) 792.0
#define p11x17_width (float) 792.0
#define p11x17_height (float) 1224.0
// static global variables
static struct static struct
{ {
char *label; char *label;
@@ -55,75 +90,39 @@ static struct
}; };
/**
* Constuctor
*
* @param
* @return
*/
PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName) PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
: BlockingWindow(BRect(0,0,400,220), "Page Setup", B_TITLED_WINDOW_LOOK, : BlockingWindow(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),
fSetupMsg(msg),
fPrinterDirName(printerName)
{ {
MoveTo(300, 300); if (printerName)
SetTitle(BString(printerName).Append(" Page Setup").String());
fSetupMsg = msg;
if ( printerName ) {
BString title;
title << printerName << " Page Setup";
SetTitle( title.String() );
// save the printer name
fPrinterDirName = printerName;
}
// ---- Ok, build a default page setup user interface
BRect r(0, 0, letter_width, letter_height);
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);
MarginUnit units = kUnitInch;
BString setting_value;
// load orientation // load orientation
int32 orient = 0;
fSetupMsg->FindInt32("orientation", &orient); fSetupMsg->FindInt32("orientation", &orient);
// load page rect // load page rect
if (fSetupMsg->FindRect("preview:paper_rect", &r) == B_OK) { float width = letter_width;
width = r.Width(); float height = letter_height;
height = r.Height(); BRect page(0, 0, width, height);
page = r; if (fSetupMsg->FindRect("preview:paper_rect", &page) == B_OK) {
} else { width = page.Width();
width = letter_width; height = page.Height();
height = letter_height;
page.Set(0, 0, width, height);
} }
BString label("Letter");
fSetupMsg->FindString("preview:paper_size", &label);
// Load units // Load units
int32 unitsValue; int32 units;
if (fSetupMsg->FindInt32("units", &unitsValue) == B_OK) { if (fSetupMsg->FindInt32("units", &units) != B_OK)
units = (MarginUnit)unitsValue; units = kUnitInch;
}
// 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);
////////////// Create the margin view //////////////////////
// re-calculate the margin from the printable rect in points // re-calculate the margin from the printable rect in points
margin = page; BRect margin = page;
if (fSetupMsg->FindRect("preview:printable_rect", &margin) == B_OK) { if (fSetupMsg->FindRect("preview:printable_rect", &margin) == B_OK) {
margin.top -= page.top; margin.top -= page.top;
margin.left -= page.left; margin.left -= page.left;
@@ -133,148 +132,123 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
margin.Set(28.34, 28.34, 28.34, 28.34); // 28.34 dots = 1cm margin.Set(28.34, 28.34, 28.34, 28.34); // 28.34 dots = 1cm
} }
fMarginView = new MarginView(BRect(20,20,200,160), (int32)width, (int32)height, BRect bounds(Bounds());
margin, units); 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);
bounds.right = 230.0;
bounds.bottom = 160.0;
fMarginView = new MarginView(bounds, 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("Orientation: ");
"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->SetMarked(true);
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);
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 (orient == orientation[i].orientation)
mf->ResizeToPreferred(); item->SetMarked(true);
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);
mf->MenuItem()->SetLabel(item->Label());
// add scale text control
y += h + kMargin;
BString scale;
float scale0; float scale0;
if (fSetupMsg->FindFloat("scale", &scale0) == B_OK) { BString scale;
if (fSetupMsg->FindFloat("scale", &scale0) == B_OK)
scale << (int)scale0; scale << (int)scale0;
} else { else
scale = "100"; scale = "100";
}
fScaleControl = new BTextControl(BRect(x, y, x + 100, y + 20), "scale", "Scale [%]:", bounds.OffsetBy(0.0, fOrientationMenu->Bounds().Height() + 10.0);
scale.String(), bounds.right -= 30.0;
NULL, B_FOLLOW_RIGHT); fScaleControl = new BTextControl(bounds, "scale", "Scale [%]:",
int num; scale.String(), NULL);
for (num = 0; num <= 255; num++) { panel->AddChild(fScaleControl);
fScaleControl->TextView()->DisallowChar(num); fScaleControl->ResizeToPreferred();
} fScaleControl->SetDivider(divider);
for (num = 0; num <= 9; num++) {
fScaleControl->TextView()->AllowChar('0' + num); for (uint32 i = 0; i < '0'; i++)
} fScaleControl->TextView()->DisallowChar(i);
for (uint32 i = '9' + 1; i < 255; i++)
fScaleControl->TextView()->DisallowChar(i);
fScaleControl->TextView()->SetMaxBytes(3); fScaleControl->TextView()->SetMaxBytes(3);
panel->AddChild(fScaleControl); bounds = Bounds();
bounds.InsetBy(5.0, 0.0);
// add a "OK" button, and make it default bounds.top =
button = new BButton(r, NULL, "OK", new BMessage(OK_MSG), MAX(fScaleControl->Frame().bottom, fMarginView->Frame().bottom) + 10.0;
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); BBox *line = new BBox(BRect(bounds.left, bounds.top, bounds.right,
button->ResizeToPreferred(); bounds.top + 1.0), NULL, B_FOLLOW_LEFT_RIGHT);
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 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 = fScaleControl->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);
BRect winFrame(Frame());
BRect screenFrame(BScreen().Frame());
MoveTo((screenFrame.right - winFrame.right) / 2,
(screenFrame.bottom - winFrame.bottom) / 2);
} }
// --------------------------------------------------
void void
PageSetupWindow::UpdateSetupMessage() PageSetupWindow::UpdateSetupMessage()
{ {
BMenuItem *item;
int32 orientation = 0; int32 orientation = 0;
BMenuItem *item = fOrientationMenu->Menu()->FindMarked();
item = fOrientationMenu->Menu()->FindMarked();
if (item) { if (item) {
BMessage *msg = item->Message(); BMessage *msg = item->Message();
msg->FindInt32("orientation", &orientation); msg->FindInt32("orientation", &orientation);
@@ -283,30 +257,24 @@ PageSetupWindow::UpdateSetupMessage()
// Save scaling factor // Save scaling factor
float scale = atoi(fScaleControl->Text()); float scale = atoi(fScaleControl->Text());
if (scale <= 0.0) { // sanity check if (scale <= 0.0) scale = 100.0;
scale = 100.0; if (scale > 1000.0) scale = 1000.0;
}
if (scale > 1000.0) {
scale = 1000.0;
}
SetFloat(fSetupMsg, "scale", scale); SetFloat(fSetupMsg, "scale", scale);
float scaleR = 100.0 / scale; float scaleR = 100.0 / scale;
item = fPageSizeMenu->Menu()->FindMarked(); item = fPageSizeMenu->Menu()->FindMarked();
if (item) { if (item) {
float w, h; float w, h;
BMessage *msg = item->Message(); BMessage *msg = item->Message();
msg->FindFloat("width", &w); msg->FindFloat("width", &w);
msg->FindFloat("height", &h); msg->FindFloat("height", &h);
BRect r; BRect r(0, 0, w, h);
if (orientation == 0) { if (orientation != 0)
r.Set(0, 0, w, h);
} else {
r.Set(0, 0, h, w); r.Set(0, 0, h, w);
}
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());
// Save the printable_rect // Save the printable_rect
BRect margin = fMarginView->GetMargin(); BRect margin = fMarginView->GetMargin();
@@ -320,72 +288,59 @@ PageSetupWindow::UpdateSetupMessage()
SetRect(fSetupMsg, "preview:printable_rect", margin); SetRect(fSetupMsg, "preview:printable_rect", margin);
SetRect(fSetupMsg, "printable_rect", ScaleRect(margin, scaleR)); SetRect(fSetupMsg, "printable_rect", ScaleRect(margin, scaleR));
// save the units used SetInt32(fSetupMsg, "units", fMarginView->GetMarginUnit());
int32 units = fMarginView->GetMarginUnit();
SetInt32(fSetupMsg, "units", units);
} }
} }
// --------------------------------------------------
void void
PageSetupWindow::MessageReceived(BMessage *msg) PageSetupWindow::MessageReceived(BMessage *msg)
{ {
switch (msg->what){ switch (msg->what) {
case OK_MSG: case OK_MSG: {
UpdateSetupMessage(); UpdateSetupMessage();
Quit(B_OK); Quit(B_OK);
break; } break;
case CANCEL_MSG: case CANCEL_MSG: {
Quit(B_ERROR); Quit(B_ERROR);
break; } break;
// Simon added case PAGE_SIZE_CHANGED: {
case 'pgsz': float w, h;
{ msg->FindFloat("width", &w);
float w, h; msg->FindFloat("height", &h);
msg->FindFloat("width", &w); BMenuItem *item = fOrientationMenu->Menu()->FindMarked();
msg->FindFloat("height", &h); if (item) {
BMenuItem *item = fOrientationMenu->Menu()->FindMarked(); int32 orientation = 0;
if (item) { item->Message()->FindInt32("orientation", &orientation);
int32 orientation = 0; if (orientation == PrinterDriver::PORTRAIT_ORIENTATION) {
BMessage *m = item->Message(); fMarginView->SetPageSize(w, h);
m->FindInt32("orientation", &orientation); } else {
if (orientation == PrinterDriver::PORTRAIT_ORIENTATION) { fMarginView->SetPageSize(h, w);
fMarginView->SetPageSize(w, h);
} else {
fMarginView->SetPageSize(h, w);
}
fMarginView->UpdateView(MARGIN_CHANGED);
} }
fMarginView->UpdateView(MARGIN_CHANGED);
} }
break; } break;
// Simon added case ORIENTATION_CHANGED: {
case 'ornt': int32 orientation;
{ msg->FindInt32("orientation", &orientation);
BPoint p = fMarginView->GetPageSize();
int32 orientation; BPoint p = fMarginView->GetPageSize();
msg->FindInt32("orientation", &orientation); if (orientation == PrinterDriver::LANDSCAPE_ORIENTATION) {
if (orientation == PrinterDriver::LANDSCAPE_ORIENTATION fMarginView->SetPageSize(p.y, p.x);
&& p.y > p.x) { fMarginView->UpdateView(MARGIN_CHANGED);
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;
if (orientation == PrinterDriver::PORTRAIT_ORIENTATION) {
fMarginView->SetPageSize(p.y, p.x);
fMarginView->UpdateView(MARGIN_CHANGED);
}
} break;
default: default:
inherited::MessageReceived(msg); BlockingWindow::MessageReceived(msg);
break; break;
} }
} }
@@ -1,65 +1,54 @@
/* /*
* Copyright 2003-2007, Haiku. All rights reserved. * Copyright 2003-2008, Haiku. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Philippe Houdoin * Philippe Houdoin
* Simon Gauvin * Simon Gauvin
* Michael Pfeiffer * Michael Pfeiffer
* Hartmut Reh * Dr. Hartmut Reh
* julun <[email protected]>
*/ */
#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 "InterfaceUtils.h"
#include "Utils.h" #include "Utils.h"
#include <String.h>
class BMessage;
class BMenuField;
class BTextControl;
class MarginView; class MarginView;
class PageSetupWindow : public BlockingWindow class PageSetupWindow : public BlockingWindow
{ {
public: public:
// Constructors, destructors, operators... PageSetupWindow(BMessage *msg, const char *printerName = NULL);
virtual void MessageReceived(BMessage *msg);
PageSetupWindow(BMessage *msg, const char *printerName = NULL); enum {
OK_MSG = 'ok__',
typedef BlockingWindow inherited; CANCEL_MSG = 'cncl',
PAGE_SIZE_CHANGED = 'pgsz',
// public constantes ORIENTATION_CHANGED = 'ornt'
enum { };
OK_MSG = 'ok__',
CANCEL_MSG = 'cncl',
};
// Virtual function overrides
public:
virtual void MessageReceived(BMessage *msg);
// From here, it's none of your business! ;-)
private: private:
BMessage * fSetupMsg; void UpdateSetupMessage();
BMenuField * fPageSizeMenu;
BMenuField * fOrientationMenu;
BTextControl * fScaleControl;
void UpdateSetupMessage(); private:
BMessage * fSetupMsg;
MarginView * fMarginView; BMenuField * fPageSizeMenu;
BMenuField * fOrientationMenu;
// used for saving settings BTextControl * fScaleControl;
BString fPrinterDirName; MarginView * fMarginView;
BString fPrinterDirName;
//private class constants
static const int kMargin = 10;
static const int kOffset = 200;
}; };
#endif #endif
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2007, Haiku. All rights reserved. * Copyright 2003-2008, Haiku. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -8,25 +8,35 @@
#include "PreviewDriver.h" #include "PreviewDriver.h"
status_t PreviewDriver::PrintJob(BFile *jobFile, BMessage *jobMsg) {
PreviewWindow* w; #define PREVIEW_DRIVER_DEBUG 0
w = new PreviewWindow(jobFile);
return w->Go();
PreviewDriver::PreviewDriver(BNode* spoolDir)
: PrinterDriver(spoolDir)
{
};
PreviewDriver::~PreviewDriver()
{
} }
PrinterDriver* instanciate_driver(BNode *spoolDir)
status_t
PreviewDriver::PrintJob(BFile *jobFile, BMessage *jobMsg)
{
#if PREVIEW_DRIVER_DEBUG
return PrinterDriver::PrintJob(jobFile, jobMessage)
#else
PreviewWindow* w = new PreviewWindow(jobFile);
return w->Go();
#endif
}
PrinterDriver*
instanciate_driver(BNode *spoolDir)
{ {
return new PreviewDriver(spoolDir); return new PreviewDriver(spoolDir);
} }
// About dialog text:
const char*
kAbout =
"Preview for Haiku\n"
"© 2003-2007 Haiku\n"
"by Michael Pfeiffer\n"
"\n"
"Based on PDF Writer by\nPhilippe Houdoin, Simon Gauvin, Michael Pfeiffer\n"
;
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007, Haiku. All rights reserved. * Copyright 2002-2008, Haiku. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -11,7 +11,8 @@
class PreviewDriver : public PrinterDriver { class PreviewDriver : public PrinterDriver {
public: public:
PreviewDriver(BNode* spoolDir) : PrinterDriver(spoolDir) {}; PreviewDriver(BNode* spoolDir);
~PreviewDriver() {}; ~PreviewDriver();
virtual status_t PrintJob(BFile *jobFile, BMessage *jobMsg);
virtual status_t PrintJob(BFile *jobFile, BMessage *jobMsg);
}; };
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2007, Haiku. All rights reserved. * Copyright 2003-2008, Haiku. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -9,44 +9,34 @@
* Dr. Hartmut Reh * Dr. Hartmut Reh
*/ */
#include <stdio.h>
#include <string.h> // for memset()
#include <StorageKit.h>
#include "PrinterDriver.h" #include "PrinterDriver.h"
#include "PrintJobReader.h"
#include "PrinterSetupWindow.h"
#include "PageSetupWindow.h"
#include "JobSetupWindow.h" #include "JobSetupWindow.h"
#include "PageSetupWindow.h"
// Private prototypes
// ------------------
#ifdef CODEWARRIOR #include <File.h>
#pragma mark [Constructor & destructor] #include <Node.h>
#endif #include <Message.h>
#include <stdio.h>
// Constructor & destructor
// ------------------------
// --------------------------------------------------
PrinterDriver::PrinterDriver(BNode* printerNode) PrinterDriver::PrinterDriver(BNode* printerNode)
: fJobFile(NULL), : fPrinting(false)
fPrinterNode(printerNode), , fJobFile(NULL)
fJobMsg(NULL) , fPrinterNode(printerNode)
{ {
} }
// --------------------------------------------------
PrinterDriver::~PrinterDriver() PrinterDriver::~PrinterDriver()
{ {
} }
#ifdef CODEWARRIOR
#pragma mark [Public methods]
#endif
#ifdef B_BEOS_VERSION_DANO #ifdef B_BEOS_VERSION_DANO
struct print_file_header { struct print_file_header {
@@ -60,74 +50,60 @@ struct print_file_header {
#endif #endif
// Public methods
// --------------
status_t status_t
PrinterDriver::PrintJob PrinterDriver::PrintJob(BFile *spoolFile, BMessage *jobMsg)
(
BFile *jobFile, // spool file
BMessage *jobMsg // job message
)
{ {
print_file_header pfh; if (!spoolFile || !fPrinterNode)
status_t status;
BMessage *msg;
int32 page;
uint32 copy;
uint32 copies;
const int32 passes = 2;
fJobFile = jobFile;
fJobMsg = jobMsg;
if (!fJobFile || !fPrinterNode)
return B_ERROR; return B_ERROR;
fJobFile = spoolFile;
print_file_header pfh;
// read print file header // read print file header
fJobFile->Seek(0, SEEK_SET); fJobFile->Seek(0, SEEK_SET);
fJobFile->Read(&pfh, sizeof(pfh)); fJobFile->Read(&pfh, sizeof(pfh));
// read job message // read job message
fJobMsg = msg = new BMessage(); BMessage msg;
msg->Unflatten(fJobFile); msg.Unflatten(fJobFile);
if (msg->HasInt32("copies")) {
copies = msg->FindInt32("copies");
} else {
copies = 1;
}
status = BeginJob();
BeginJob();
fPrinting = true; fPrinting = true;
for (fPass = 0; fPass < passes && status == B_OK && fPrinting; fPass++) {
for (copy = 0; copy < copies && status == B_OK && fPrinting; copy++)
{
for (page = 1; page <= pfh.page_count && status == B_OK && fPrinting; page++) {
status = PrintPage(page, pfh.page_count);
}
// re-read job message for next page for (int32 page = 1; page <= pfh.page_count; ++page) {
fJobFile->Seek(sizeof(pfh), SEEK_SET); printf("PrinterDriver::PrintPage(): Faking print of page %ld/ %ld",
msg->Unflatten(fJobFile); page, pfh.page_count);
}
} }
status_t s = EndJob(); fJobFile->Seek(0, SEEK_SET);
if (status == B_OK) status = s; PrintJobReader reader(fJobFile);
delete fJobMsg; status_t status = reader.InitCheck();
printf("PrintJobReader::InitCheck(): %s\n", status == B_OK ? "B_OK" : "B_ERROR");
printf("PrintJobReader::NumberOfPages(): %ld\n", reader.NumberOfPages());
printf("PrintJobReader::FirstPage(): %ld\n", reader.FirstPage());
printf("PrintJobReader::LastPage(): %ld\n", reader.LastPage());
BRect rect = reader.PaperRect();
printf("PrintJobReader::PaperRect(): BRect(l:%.1f, t:%.1f, r:%.1f, b:%.1f)\n",
rect.left, rect.top, rect.right, rect.bottom);
rect = reader.PrintableRect();
printf("PrintJobReader::PrintableRect(): BRect(l:%.1f, t:%.1f, r:%.1f, b:%.1f)\n",
rect.left, rect.top, rect.right, rect.bottom);
int32 xdpi, ydpi;
reader.GetResolution(&xdpi, &ydpi);
printf("PrintJobReader::GetResolution(): xdpi:%ld, ydpi:%ld\n", xdpi, ydpi);
printf("PrintJobReader::GetScale(): %.1f\n", reader.GetScale());
fPrinting = false;
EndJob();
return status; return status;
} }
/**
* This will stop the printing loop
*
* @param none
* @return void
*/
void void
PrinterDriver::StopPrinting() PrinterDriver::StopPrinting()
{ {
@@ -135,7 +111,6 @@ PrinterDriver::StopPrinting()
} }
// --------------------------------------------------
status_t status_t
PrinterDriver::BeginJob() PrinterDriver::BeginJob()
{ {
@@ -143,20 +118,13 @@ PrinterDriver::BeginJob()
} }
// --------------------------------------------------
status_t status_t
PrinterDriver::PrintPage(int32 pageNumber, int32 pageCount) PrinterDriver::PrintPage(int32 pageNumber, int32 pageCount)
{ {
char text[128];
sprintf(text, "Faking print of page %ld/%ld...", pageNumber, pageCount);
BAlert *alert = new BAlert("PrinterDriver::PrintPage()", text, "Hmm?");
alert->Go();
return B_OK; return B_OK;
} }
// --------------------------------------------------
status_t status_t
PrinterDriver::EndJob() PrinterDriver::EndJob()
{ {
@@ -164,61 +132,28 @@ PrinterDriver::EndJob()
} }
BlockingWindow* PrinterDriver::NewPrinterSetupWindow(char* printerName) { BlockingWindow*
return NULL; PrinterDriver::NewPageSetupWindow(BMessage *setupMsg, const char *printerName)
} {
BlockingWindow* PrinterDriver::NewPageSetupWindow(BMessage *setupMsg, const char *printerName) {
return new PageSetupWindow(setupMsg, printerName); return new PageSetupWindow(setupMsg, printerName);
} }
BlockingWindow* PrinterDriver::NewJobSetupWindow(BMessage *jobMsg, const char *printerName) {
BlockingWindow*
PrinterDriver::NewJobSetupWindow(BMessage *jobMsg, const char *printerName)
{
return new JobSetupWindow(jobMsg, printerName); return new JobSetupWindow(jobMsg, printerName);
} }
status_t PrinterDriver::Go(BlockingWindow* w) {
if (w) {
return w->Go();
} else {
return B_OK;
}
}
// --------------------------------------------------
status_t
PrinterDriver::PrinterSetup(char *printerName)
// name of printer, to attach printer settings
{
return Go(NewPrinterSetupWindow(printerName));
}
// --------------------------------------------------
status_t status_t
PrinterDriver::PageSetup(BMessage *setupMsg, const char *printerName) PrinterDriver::PageSetup(BMessage *setupMsg, const char *printerName)
{ {
// check to see if the messag is built correctly... BlockingWindow* w = NewPageSetupWindow(setupMsg, printerName);
if (setupMsg->HasFloat("scaling") != B_OK) { return w->Go();
#if HAS_PRINTER_SETTINGS
PrinterSettings *ps = new PrinterSettings(printerName);
if (ps->InitCheck() == B_OK) {
// first read the settings from the spool dir
if (ps->ReadSettings(setupMsg) != B_OK) {
// if there were none, then create a default set...
ps->GetDefaults(setupMsg);
// ...and save them
ps->WriteSettings(setupMsg);
}
}
#endif
}
return Go(NewPageSetupWindow(setupMsg, printerName));
} }
// --------------------------------------------------
status_t status_t
PrinterDriver::JobSetup(BMessage *jobMsg, const char *printerName) PrinterDriver::JobSetup(BMessage *jobMsg, const char *printerName)
{ {
@@ -230,12 +165,18 @@ PrinterDriver::JobSetup(BMessage *jobMsg, const char *printerName)
jobMsg->AddInt32("first_page", 1); jobMsg->AddInt32("first_page", 1);
if (!jobMsg->HasInt32("last_page")) if (!jobMsg->HasInt32("last_page"))
jobMsg->AddInt32("last_page", MAX_INT32); jobMsg->AddInt32("last_page", LONG_MAX);
return Go(NewJobSetupWindow(jobMsg, printerName)); BlockingWindow* w = NewJobSetupWindow(jobMsg, printerName);
return w->Go();
} }
// --------------------------------------------------
/* copied from PDFlib.h: */
#define letter_width (float) 612.0
#define letter_height (float) 792.0
BMessage* BMessage*
PrinterDriver::GetDefaultSettings() PrinterDriver::GetDefaultSettings()
{ {
@@ -250,10 +191,3 @@ PrinterDriver::GetDefaultSettings()
msg->AddInt32("yres", 300); msg->AddInt32("yres", 300);
return msg; return msg;
} }
#ifdef CODEWARRIOR
#pragma mark [Privates routines]
#endif
// Private routines
// ----------------
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2007, Haiku. All rights reserved. * Copyright 2001-2008, Haiku. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -12,48 +12,15 @@
#ifndef PRINTERDRIVER_H #ifndef PRINTERDRIVER_H
#define PRINTERDRIVER_H #define PRINTERDRIVER_H
#include <AppKit.h>
#include <InterfaceKit.h>
#include "InterfaceUtils.h" #include "InterfaceUtils.h"
class BFile;
class BNode; class BNode;
class BMessage;
#ifndef ROUND_UP
#define ROUND_UP(x, y) (((x) + (y) - 1) & ~((y) - 1))
#endif
#define MAX_INT32 ((int32)0x7fffffffL)
/* copied from PDFlib.h: */
#define a0_width (float) 2380.0
#define a0_height (float) 3368.0
#define a1_width (float) 1684.0
#define a1_height (float) 2380.0
#define a2_width (float) 1190.0
#define a2_height (float) 1684.0
#define a3_width (float) 842.0
#define a3_height (float) 1190.0
#define a4_width (float) 595.0
#define a4_height (float) 842.0
#define a5_width (float) 421.0
#define a5_height (float) 595.0
#define a6_width (float) 297.0
#define a6_height (float) 421.0
#define b5_width (float) 501.0
#define b5_height (float) 709.0
#define letter_width (float) 612.0
#define letter_height (float) 792.0
#define legal_width (float) 612.0
#define legal_height (float) 1008.0
#define ledger_width (float) 1224.0
#define ledger_height (float) 792.0
#define p11x17_width (float) 792.0
#define p11x17_height (float) 1224.0
/**
* Class PrinterDriver
*/
class PrinterDriver class PrinterDriver
{ {
public: public:
@@ -69,12 +36,10 @@ public:
virtual status_t EndJob(); virtual status_t EndJob();
// configuration window getters // configuration window getters
virtual BlockingWindow* NewPrinterSetupWindow(char* printerName);
virtual BlockingWindow* NewPageSetupWindow(BMessage *setupMsg, const char *printerName); virtual BlockingWindow* NewPageSetupWindow(BMessage *setupMsg, const char *printerName);
virtual BlockingWindow* NewJobSetupWindow(BMessage *setupMsg, const char *printerName); virtual BlockingWindow* NewJobSetupWindow(BMessage *setupMsg, const char *printerName);
// configuration default methods // configuration default methods
virtual status_t PrinterSetup(char *printerName);
virtual status_t PageSetup(BMessage *msg, const char *printerName = NULL); virtual status_t PageSetup(BMessage *msg, const char *printerName = NULL);
virtual status_t JobSetup(BMessage *msg, const char *printerName = NULL); virtual status_t JobSetup(BMessage *msg, const char *printerName = NULL);
virtual BMessage* GetDefaultSettings(); virtual BMessage* GetDefaultSettings();
@@ -82,8 +47,6 @@ public:
// accessors // accessors
inline BFile *JobFile() { return fJobFile; } inline BFile *JobFile() { return fJobFile; }
inline BNode *PrinterNode() { return fPrinterNode; } inline BNode *PrinterNode() { return fPrinterNode; }
inline BMessage *JobMsg() { return fJobMsg; }
inline int32 Pass() const { return fPass; }
// publics status code // publics status code
typedef enum { typedef enum {
@@ -93,17 +56,12 @@ public:
private: private:
status_t Go(BlockingWindow* w); bool fPrinting;
BFile *fJobFile; BFile *fJobFile;
BNode *fPrinterNode; BNode *fPrinterNode;
BMessage *fJobMsg;
volatile Orientation fOrientation; volatile Orientation fOrientation;
bool fPrinting;
int32 fPass;
}; };
#endif // #ifndef PRINTERDRIVER_H #endif
@@ -1,194 +0,0 @@
/*
* Copyright 2003-2007, Haiku. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Philippe Houdoin
* Simon Gauvin
* Michael Pfeiffer
*/
#include <InterfaceKit.h>
#include <StorageKit.h>
#include <SupportKit.h>
#include "PrinterSetupWindow.h"
// --------------------------------------------------
PrinterSetupWindow::PrinterSetupWindow(char *printerName)
: BlockingWindow(BRect(0,0,300,300), printerName, B_TITLED_WINDOW_LOOK,
B_MODAL_APP_WINDOW_FEEL, B_NOT_ZOOMABLE)
{
MoveTo(300, 300);
fPrinterName = printerName;
if (printerName) {
BString title;
title << printerName << " Printer Setup";
SetTitle(title.String());
} else
SetTitle("Printer Setup");
// ---- Ok, build a default job setup user interface
BRect r;
BButton *button;
float x, y, w, h;
font_height fh;
r = Bounds();
// add a *dialog* background
BBox *panel = new BBox(r, "top_panel", B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
B_PLAIN_BORDER);
const int kInterSpace = 8;
const int kHorzMargin = 10;
const int kVertMargin = 10;
x = kHorzMargin;
y = kVertMargin;
// add a label before the list
const char *kModelLabel = "Printer model";
be_plain_font->GetHeight(&fh);
w = Bounds().Width();
w -= 2 * kHorzMargin;
h = 150;
BBox * model_group = new BBox(BRect(x, y, x+w, y+h), "model_group", B_FOLLOW_ALL_SIDES);
model_group->SetLabel(kModelLabel);
BRect rlv = model_group->Bounds();
rlv.InsetBy(kHorzMargin, kVertMargin);
rlv.top += fh.ascent + fh.descent + fh.leading;
rlv.right -= B_V_SCROLL_BAR_WIDTH;
fModelList = new BListView(rlv, "model_list",
B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL_SIDES );
BScrollView * sv = new BScrollView( "model_list_scrollview", fModelList,
B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS, false, true );
model_group->AddChild(sv);
panel->AddChild(model_group);
y += (h + kInterSpace);
x = r.right - kHorzMargin;
// add a "OK" button, and make it default
fOkButton = new BButton(BRect(x, y, x + 400, y), NULL, "OK", new BMessage(OK_MSG), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
fOkButton->ResizeToPreferred();
fOkButton->GetPreferredSize(&w, &h);
x -= w;
fOkButton->MoveTo(x, y);
fOkButton->MakeDefault(true);
fOkButton->SetEnabled(false);
panel->AddChild(fOkButton);
x -= kInterSpace;
// add a "Cancel" button
button = new BButton(BRect(x, y, x + 400, y), NULL, "Cancel", new BMessage(CANCEL_MSG), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
button->ResizeToPreferred();
button->GetPreferredSize(&w, &h);
x -= w;
button->MoveTo(x, y);
panel->AddChild(button);
y += (h + kInterSpace);
panel->ResizeTo(Bounds().Width(), y);
ResizeTo(Bounds().Width(), y);
float minWidth, maxWidth, minHeight, maxHeight;
GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight);
SetSizeLimits(panel->Frame().Width(), panel->Frame().Width(),
panel->Frame().Height(), maxHeight);
// Finally, add our panel to window
AddChild(panel);
BDirectory Folder;
BEntry entry;
Folder.SetTo ("/boot/beos/etc/bubblejet");
if (Folder.InitCheck() != B_OK)
return;
while (Folder.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) {
char name[B_FILE_NAME_LENGTH];
if (entry.GetName(name) == B_NO_ERROR)
fModelList->AddItem (new BStringItem(name));
}
fModelList->SetSelectionMessage(new BMessage(MODEL_MSG));
fModelList->SetInvocationMessage(new BMessage(OK_MSG));
}
// --------------------------------------------------
void
PrinterSetupWindow::MessageReceived(BMessage *msg)
{
switch (msg->what) {
case OK_MSG:
{
// Test model selection (if any), save it in printerName node and return
BNode spoolDir;
BPath * path;
status_t result = B_ERROR;
if (fModelList->CurrentSelection() < 0)
break;
BStringItem * item = dynamic_cast<BStringItem*>
(fModelList->ItemAt(fModelList->CurrentSelection()));
if (!item)
break;
path = new BPath();
find_directory(B_USER_SETTINGS_DIRECTORY, path);
path->Append("printers");
path->Append(fPrinterName);
spoolDir.SetTo(path->Path());
delete path;
if (spoolDir.InitCheck() != B_OK) {
BAlert * alert = new BAlert("Uh oh!",
"Couldn't find printer spool directory.", "OK");
alert->Go();
} else {
spoolDir.WriteAttr("printer_model", B_STRING_TYPE, 0, item->Text(),
strlen(item->Text()));
result = B_OK;
}
Quit(result);
break;
}
case CANCEL_MSG:
Quit(B_ERROR);
break;
case MODEL_MSG:
fOkButton->SetEnabled((fModelList->CurrentSelection() >= 0));
break;
default:
inherited::MessageReceived(msg);
break;
};
}
@@ -1,45 +0,0 @@
/*
* Copyright 2003-2007, Haiku. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Philippe Houdoin
* Simon Gauvin
* Michael Pfeiffer
*/
#ifndef PRINTERSETUPWINDOW_H
#define PRINTERSETUPWINDOW_H
#include <InterfaceKit.h>
#include "InterfaceUtils.h"
class PrinterSetupWindow : public BlockingWindow
{
public:
// Constructors, destructors, operators...
PrinterSetupWindow(char *printerName);
typedef BlockingWindow inherited;
// public constantes
enum {
OK_MSG = 'ok__',
CANCEL_MSG = 'cncl',
MODEL_MSG = 'modl'
};
// Virtual function overrides
public:
virtual void MessageReceived(BMessage *msg);
// From here, it's none of your business! ;-)
private:
BButton *fOkButton;
BListView *fModelList;
char *fPrinterName;
};
#endif