* 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
+36 -73
View File
@@ -1,126 +1,89 @@
/*
* Copyright 2001-2007, Haiku. All rights reserved.
* Copyright 2001-2008, Haiku. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Philippe Houdoin
* Simon Gauvin
* Simon Gauvin
* Michael Pfeiffer
*/
#include <stdio.h>
#include <string.h>
#include <StorageKit.h>
#include "Driver.h"
#include "PrinterDriver.h"
// --------------------------------------------------
BMessage*
take_job(BFile *spoolFile, BNode *spoolDir, BMessage *msg)
BMessage*
take_job(BFile *spoolFile, BNode *spoolDir, BMessage *msg)
{
PrinterDriver *driver;
driver = instanciate_driver(spoolDir);
if (driver->PrintJob(spoolFile, msg) == B_OK) {
msg = new BMessage('okok');
} else {
msg = new BMessage('baad');
}
PrinterDriver *driver = instanciate_driver(spoolDir);
status_t status = driver->PrintJob(spoolFile, msg);
delete driver;
msg = new BMessage('okok');
if (status != B_OK)
msg->what = 'baad';
return msg;
}
// --------------------------------------------------
BMessage*
config_page(BNode *spoolDir, BMessage *msg)
BMessage*
config_page(BNode *spoolDir, BMessage *msg)
{
BMessage *pagesetupMsg = new BMessage(*msg);
PrinterDriver *driver;
const char *printerName;
char buffer[B_ATTR_NAME_LENGTH+1];
BString printerName;
spoolDir->ReadAttrString("Printer Name", &printerName);
// retrieve the printer (spool) name.
printerName = NULL;
if (spoolDir->ReadAttr("Printer Name", B_STRING_TYPE, 1, buffer, B_ATTR_NAME_LENGTH+1) > 0) {
printerName = buffer;
}
BMessage *pagesetupMsg = new BMessage(*msg);
pagesetupMsg->what = 'okok';
driver = instanciate_driver(spoolDir);
if (driver->PageSetup(pagesetupMsg, printerName) == B_OK) {
pagesetupMsg->what = 'okok';
} else {
PrinterDriver *driver = instanciate_driver(spoolDir);
if (driver->PageSetup(pagesetupMsg, printerName.String()) != B_OK) {
delete pagesetupMsg;
pagesetupMsg = NULL;
}
delete driver;
return pagesetupMsg;
}
// --------------------------------------------------
BMessage*
BMessage*
config_job(BNode *spoolDir, BMessage *msg)
{
BMessage *jobsetupMsg = new BMessage(*msg);
PrinterDriver *driver;
const char *printerName;
char buffer[B_ATTR_NAME_LENGTH+1];
BString printerName;
spoolDir->ReadAttrString("Printer Name", &printerName);
// retrieve the printer (spool) name.
printerName = NULL;
if (spoolDir->ReadAttr("Printer Name", B_STRING_TYPE, 1, buffer, B_ATTR_NAME_LENGTH+1) > 0) {
printerName = buffer;
}
driver = instanciate_driver(spoolDir);
if (driver->JobSetup(jobsetupMsg, printerName) == B_OK) {
jobsetupMsg->what = 'okok';
} else {
BMessage *jobsetupMsg = new BMessage(*msg);
jobsetupMsg->what = 'okok';
PrinterDriver *driver = instanciate_driver(spoolDir);
if (driver->JobSetup(jobsetupMsg, printerName.String()) != B_OK) {
delete jobsetupMsg;
jobsetupMsg = NULL;
}
delete driver;
return jobsetupMsg;
}
// --------------------------------------------------
char*
char*
add_printer(char *printerName)
{
status_t st;
PrinterDriver* driver;
driver = instanciate_driver(NULL);
st = driver->PrinterSetup(printerName);
delete driver;
if (st == B_OK) {
return printerName;
} else {
return NULL;
}
return printerName;
}
/**
* default_settings
*
* @param BNode* printer spool directory
* @return BMessage* the settings
*/
BMessage*
BMessage*
default_settings(BNode* spoolDir)
{
PrinterDriver* driver;
BMessage* settings;
driver = instanciate_driver(spoolDir);
settings = driver->GetDefaultSettings();
PrinterDriver *driver = instanciate_driver(spoolDir);
BMessage *settings = driver->GetDefaultSettings();
delete driver;
return settings;
}
+7 -8
View File
@@ -1,10 +1,10 @@
/*
* Copyright 2002-2007, Haiku. All rights reserved.
* Copyright 2002-2008, Haiku. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Philippe Houdoin
* Simon Gauvin
* Simon Gauvin
* Michael Pfeiffer
*/
@@ -12,15 +12,14 @@
extern "C"
{
__declspec(dllexport) BMessage * take_job(BFile * spool_file, BNode * spool_dir, BMessage * msg);
__declspec(dllexport) BMessage * config_page(BNode * spool_dir, BMessage * msg);
__declspec(dllexport) BMessage * config_job(BNode * spool_dir, BMessage * msg);
__declspec(dllexport) char * add_printer(char * printer_name);
__declspec(dllexport) BMessage * default_settings(BNode * printer);
BMessage * take_job(BFile * spool_file, BNode * spool_dir, BMessage * msg);
BMessage * config_page(BNode * spool_dir, BMessage * msg);
BMessage * config_job(BNode * spool_dir, BMessage * msg);
char * add_printer(char * printer_name);
BMessage * default_settings(BNode * printer);
}
class PrinterDriver;
// instanciate_driver has to be implemented by the printer driver
PrinterDriver *instanciate_driver(BNode *spoolDir);
+4 -5
View File
@@ -2,15 +2,14 @@ SubDir HAIKU_TOP src add-ons print drivers preview ;
SetSubDirSupportedPlatformsBeOSCompatible ;
SubDirHdrs [ FDirName $(HAIKU_TOP) headers private print ] ;
SubDirHdrs [ FDirName $(HAIKU_TOP) headers private print utils ] ;
SubDirHdrs [ FDirName $(HAIKU_TOP) headers private print ] ;
SubDirHdrs [ FDirName $(HAIKU_TOP) headers private print utils ] ;
UsePrivateHeaders interface ;
AddResources Preview : Preview.rsrc ;
Addon Preview :
PrinterSetupWindow.cpp
PageSetupWindow.cpp
JobSetupWindow.cpp
Driver.cpp
@@ -18,8 +17,8 @@ Addon Preview :
PrinterDriver.cpp
PreviewDriver.cpp
:
be
root
be
root
libprintutils.a
;
@@ -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.
*
* Authors:
* Philippe Houdoin
* Simon Gauvin
* Simon Gauvin
* Michael Pfeiffer
* julun <[email protected]>
*/
#include <InterfaceKit.h>
#include <SupportKit.h>
#include "JobSetupWindow.h"
#include "PrinterDriver.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)
: 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_NOT_ZOOMABLE)
B_NOT_ZOOMABLE),
fPrinterName(printerName),
fSetupMsg(msg)
{
MoveTo(300, 300);
if (printerName)
SetTitle(BString(printerName).Append(" Job Setup").String());
fSetupMsg = msg;
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);
int32 firstPage;
fSetupMsg->FindInt32("first_page", &firstPage);
fSetupMsg->FindInt32("last_page", &lastPage);
allPages = firstPage == 1 && lastPage == MAX_INT32;
r = Bounds();
int32 lastPage;
fSetupMsg->FindInt32("last_page", &lastPage);
bool allPages = firstPage == 1 && lastPage == LONG_MAX;
// add a *dialog* background
panel = new BBox(r, "top_panel", B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
B_PLAIN_BORDER);
BRect bounds(Bounds());
BBox *panel = new BBox(bounds, "background", B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER);
AddChild(panel);
const int kMargin = 6;
bounds.InsetBy(10.0, 10.0);
//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);
fAll = new BRadioButton(bounds, "allPages", "Print all pages",
new BMessage(ALL_PAGES_MGS));
panel->AddChild(fAll);
fAll->ResizeToPreferred();
fAll->SetValue(allPages);
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);
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);
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);
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);
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);
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);
y += h + kMargin + kMargin; // "new line"
x = r.left + kMargin;
BString buffer;
buffer << firstPage;
fFrom->SetText(buffer.String());
// add a separator line...
line = new BBox(BRect(r.left, y - 1, r.right, y), NULL,
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP );
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);
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
bounds.OffsetBy(0.0, 11.0);
BButton *cancel = new BButton(bounds, NULL, "Cancel", new BMessage(CANCEL_MSG));
panel->AddChild(cancel);
cancel->ResizeToPreferred();
// Finally, add our panel to window
AddChild(panel);
// Auto resize window
ResizeTo(ok->Frame().right + kMargin, ok->Frame().bottom + kMargin);
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
JobSetupWindow::UpdateJobMessage()
void
JobSetupWindow::UpdateJobMessage()
{
int32 copies = 1;
int32 from;
int32 to;
if (fAll->Value() == B_CONTROL_ON) {
from = 1; to = MAX_INT32;
} else {
int32 from = 1;
int32 to = LONG_MAX;
if (fAll->Value() == B_CONTROL_OFF) {
from = atoi(fFrom->Text());
to = atoi(fTo->Text());
to = atoi(fTo->Text());
if (from <= 0) from = 1;
if (to < from) to = from;
}
if (fSetupMsg->HasInt32("copies")) {
fSetupMsg->ReplaceInt32("copies", copies);
} else {
fSetupMsg->AddInt32("copies", copies);
}
if (fSetupMsg->HasInt32("first_page")) {
fSetupMsg->ReplaceInt32("first_page", from);
} else {
fSetupMsg->AddInt32("first_page", from);
}
if (fSetupMsg->HasInt32("last_page")) {
fSetupMsg->ReplaceInt32("last_page", to);
} else {
fSetupMsg->AddInt32("last_page", to);
}
int32 copies = 1;
fSetupMsg->RemoveName("copies");
fSetupMsg->AddInt32("copies", copies);
fSetupMsg->RemoveName("first_page");
fSetupMsg->AddInt32("first_page", from);
fSetupMsg->RemoveName("last_page");
fSetupMsg->AddInt32("last_page", to);
}
// --------------------------------------------------
void
void
JobSetupWindow::MessageReceived(BMessage *msg)
{
switch (msg->what) {
case OK_MSG:
case OK_MSG: {
UpdateJobMessage();
Quit(B_OK);
break;
case CANCEL_MSG:
} break;
case CANCEL_MSG: {
Quit(B_ERROR);
break;
} break;
case RANGE_FROM_MSG:
case RANGE_TO_MSG:
fRange->SetValue(B_CONTROL_ON);
break;
case ALL_PAGES_MGS : {
fTo->SetEnabled(false);
fFrom->SetEnabled(false);
} break;
default:
inherited::MessageReceived(msg);
break;
case RANGE_SELECTION_MSG : {
fTo->SetEnabled(true);
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.
*
* Authors:
* Philippe Houdoin
* Simon Gauvin
* Simon Gauvin
* Michael Pfeiffer
* julun <[email protected]>
*/
#ifndef JOBSETUPWINDOW_H
#define JOBSETUPWINDOW_H
#include <InterfaceKit.h>
#include "InterfaceUtils.h"
#include "Utils.h"
class JobSetupWindow : public BlockingWindow
#include <String.h>
class BMessage;
class BRadioButton;
class BTextControl;
class JobSetupWindow : public BlockingWindow
{
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:
BString fPrinterName;
BMessage *fSetupMsg;
BRadioButton *fAll;
BRadioButton *fRange;
BTextControl *fFrom;
BTextControl *fTo;
void UpdateJobMessage();
void UpdateJobMessage();
private:
BString fPrinterName;
BMessage *fSetupMsg;
BRadioButton *fAll;
BRadioButton *fRange;
BTextControl *fFrom;
BTextControl *fTo;
};
#endif
@@ -1,31 +1,66 @@
/*
* Copyright 2003-2007, Haiku. All rights reserved.
* Copyright 2003-2008, Haiku. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Philippe Houdoin
* Simon Gauvin
* Simon Gauvin
* 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 "MarginView.h"
#include "PrinterDriver.h"
#include "PageSetupWindow.h"
// static global variables
static struct
#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 struct
{
char *label;
float width;
float height;
} pageFormat[] =
} pageFormat[] =
{
{"Letter", letter_width, letter_height },
{"Legal", legal_width, legal_height },
@@ -43,11 +78,11 @@ static struct
};
static struct
static struct
{
char *label;
int32 orientation;
} orientation[] =
} orientation[] =
{
{"Portrait", PrinterDriver::PORTRAIT_ORIENTATION},
{"Landscape", PrinterDriver::LANDSCAPE_ORIENTATION},
@@ -55,75 +90,39 @@ static struct
};
/**
* Constuctor
*
* @param
* @return
*/
PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
: BlockingWindow(BRect(0,0,400,220), "Page Setup", B_TITLED_WINDOW_LOOK,
B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE |
B_NOT_ZOOMABLE)
B_NOT_ZOOMABLE),
fSetupMsg(msg),
fPrinterDirName(printerName)
{
MoveTo(300, 300);
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;
if (printerName)
SetTitle(BString(printerName).Append(" Page Setup").String());
// load orientation
int32 orient = 0;
fSetupMsg->FindInt32("orientation", &orient);
// load page rect
if (fSetupMsg->FindRect("preview:paper_rect", &r) == B_OK) {
width = r.Width();
height = r.Height();
page = r;
} else {
width = letter_width;
height = letter_height;
page.Set(0, 0, width, height);
float width = letter_width;
float height = letter_height;
BRect page(0, 0, width, height);
if (fSetupMsg->FindRect("preview:paper_rect", &page) == B_OK) {
width = page.Width();
height = page.Height();
}
// Load units
int32 unitsValue;
if (fSetupMsg->FindInt32("units", &unitsValue) == B_OK) {
units = (MarginUnit)unitsValue;
}
// 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 //////////////////////
BString label("Letter");
fSetupMsg->FindString("preview:paper_size", &label);
// Load units
int32 units;
if (fSetupMsg->FindInt32("units", &units) != B_OK)
units = kUnitInch;
// re-calculate the margin from the printable rect in points
margin = page;
BRect margin = page;
if (fSetupMsg->FindRect("preview:printable_rect", &margin) == B_OK) {
margin.top -= page.top;
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
}
fMarginView = new MarginView(BRect(20,20,200,160), (int32)width, (int32)height,
margin, units);
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);
bounds.right = 230.0;
bounds.bottom = 160.0;
fMarginView = new MarginView(bounds, int32(width), int32(height), margin,
MarginUnit(units));
panel->AddChild(fMarginView);
// add page format menu
// Simon Changed to OFFSET popups
x = r.left + kMargin * 2 + kOffset; y = r.top + kMargin * 2;
fMarginView->SetResizingMode(B_FOLLOW_NONE);
BPopUpMenu* m = new BPopUpMenu("page_size");
BPopUpMenu* m = new BPopUpMenu("Page Size");
m->SetRadioMode(true);
// Simon changed width 200->140
BMenuField *mf = new BMenuField(BRect(x, y, x + 140, y + 20), "page_size",
"Page Size:", m);
fPageSizeMenu = mf;
mf->ResizeToPreferred();
mf->GetPreferredSize(&w, &h);
bounds.OffsetBy(bounds.Width() + 10.0, 5.0);
float divider = be_plain_font->StringWidth("Orientation: ");
fPageSizeMenu = new BMenuField(bounds, "page_size", "Page Size:", m);
panel->AddChild(fPageSizeMenu);
fPageSizeMenu->ResizeToPreferred();
fPageSizeMenu->SetDivider(divider);
fPageSizeMenu->Menu()->SetLabelFromMarked(true);
// Simon added: SetDivider
mf->SetDivider(be_plain_font->StringWidth("Page Size#"));
for (int32 i = 0; pageFormat[i].label != NULL; i++) {
BMessage* message = new BMessage(PAGE_SIZE_CHANGED);
message->AddFloat("width", pageFormat[i].width);
message->AddFloat("height", pageFormat[i].height);
BMenuItem* item = new BMenuItem(pageFormat[i].label, message);
m->AddItem(item);
panel->AddChild(mf);
item = NULL;
for (i = 0; pageFormat[i].label != NULL; i++)
{
BMessage* msg = new BMessage('pgsz');
msg->AddFloat("width", pageFormat[i].width);
msg->AddFloat("height", pageFormat[i].height);
BMenuItem* mi = new BMenuItem(pageFormat[i].label, msg);
m->AddItem(mi);
if (width == pageFormat[i].width && height == pageFormat[i].height) {
item = mi;
}
if (height == pageFormat[i].width && width == pageFormat[i].height) {
item = mi;
}
if (label.Compare(pageFormat[i].label) == 0)
item->SetMarked(true);
}
mf->Menu()->SetLabelFromMarked(true);
if (!item) {
item = m->ItemAt(0);
}
item->SetMarked(true);
mf->MenuItem()->SetLabel(item->Label());
// add orientation menu
y += h + kMargin;
m = new BPopUpMenu("orientation");
m = new BPopUpMenu("Orientation");
m->SetRadioMode(true);
// Simon changed 200->140
mf = new BMenuField(BRect(x, y, x + 140, y + 20), "orientation", "Orientation:", m);
// Simon added: SetDivider
mf->SetDivider(be_plain_font->StringWidth("Orientation#"));
fOrientationMenu = mf;
mf->ResizeToPreferred();
panel->AddChild(mf);
r.top += h;
item = NULL;
for (int i = 0; orientation[i].label != NULL; i++)
{
BMessage* msg = new BMessage('ornt');
msg->AddInt32("orientation", orientation[i].orientation);
BMenuItem* mi = new BMenuItem(orientation[i].label, msg);
m->AddItem(mi);
if (orient == orientation[i].orientation) {
item = mi;
}
bounds.OffsetBy(0.0, fPageSizeMenu->Bounds().Height() + 10.0);
fOrientationMenu = new BMenuField(bounds, "orientation", "Orientation:", m);
panel->AddChild(fOrientationMenu);
fOrientationMenu->ResizeToPreferred();
fOrientationMenu->SetDivider(divider);
fOrientationMenu->Menu()->SetLabelFromMarked(true);
for (int32 i = 0; orientation[i].label != NULL; i++) {
BMessage* message = new BMessage(ORIENTATION_CHANGED);
message->AddInt32("orientation", orientation[i].orientation);
BMenuItem* item = new BMenuItem(orientation[i].label, message);
m->AddItem(item);
if (orient == orientation[i].orientation)
item->SetMarked(true);
}
mf->Menu()->SetLabelFromMarked(true);
// SHOULD BE REMOVED
if (!item) {
item = m->ItemAt(0);
}
///////////////////
item->SetMarked(true);
mf->MenuItem()->SetLabel(item->Label());
// add scale text control
y += h + kMargin;
BString scale;
float scale0;
if (fSetupMsg->FindFloat("scale", &scale0) == B_OK) {
BString scale;
if (fSetupMsg->FindFloat("scale", &scale0) == B_OK)
scale << (int)scale0;
} else {
else
scale = "100";
}
fScaleControl = new BTextControl(BRect(x, y, x + 100, y + 20), "scale", "Scale [%]:",
scale.String(),
NULL, B_FOLLOW_RIGHT);
int num;
for (num = 0; num <= 255; num++) {
fScaleControl->TextView()->DisallowChar(num);
}
for (num = 0; num <= 9; num++) {
fScaleControl->TextView()->AllowChar('0' + num);
}
bounds.OffsetBy(0.0, fOrientationMenu->Bounds().Height() + 10.0);
bounds.right -= 30.0;
fScaleControl = new BTextControl(bounds, "scale", "Scale [%]:",
scale.String(), NULL);
panel->AddChild(fScaleControl);
fScaleControl->ResizeToPreferred();
fScaleControl->SetDivider(divider);
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);
panel->AddChild(fScaleControl);
// 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 separator line...
BBox * line = new BBox(BRect(r.left, y - 9, r.right, y - 8), NULL,
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM );
bounds = Bounds();
bounds.InsetBy(5.0, 0.0);
bounds.top =
MAX(fScaleControl->Frame().bottom, fMarginView->Frame().bottom) + 10.0;
BBox *line = new BBox(BRect(bounds.left, bounds.top, bounds.right,
bounds.top + 1.0), NULL, B_FOLLOW_LEFT_RIGHT);
panel->AddChild(line);
// Finally, add our panel to window
AddChild(panel);
bounds.InsetBy(5.0, 0.0);
bounds.OffsetBy(0.0, 11.0);
BButton *cancel = new BButton(bounds, NULL, "Cancel", new BMessage(CANCEL_MSG));
panel->AddChild(cancel);
cancel->ResizeToPreferred();
BButton *ok = new BButton(bounds, NULL, "OK", new BMessage(OK_MSG));
panel->AddChild(ok, cancel);
ok->ResizeToPreferred();
bounds.right = 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
PageSetupWindow::UpdateSetupMessage()
void
PageSetupWindow::UpdateSetupMessage()
{
BMenuItem *item;
int32 orientation = 0;
item = fOrientationMenu->Menu()->FindMarked();
BMenuItem *item = fOrientationMenu->Menu()->FindMarked();
if (item) {
BMessage *msg = item->Message();
msg->FindInt32("orientation", &orientation);
@@ -283,32 +257,26 @@ PageSetupWindow::UpdateSetupMessage()
// Save scaling factor
float scale = atoi(fScaleControl->Text());
if (scale <= 0.0) { // sanity check
scale = 100.0;
}
if (scale > 1000.0) {
scale = 1000.0;
}
if (scale <= 0.0) scale = 100.0;
if (scale > 1000.0) scale = 1000.0;
SetFloat(fSetupMsg, "scale", scale);
float scaleR = 100.0 / scale;
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 {
BRect r(0, 0, w, h);
if (orientation != 0)
r.Set(0, 0, h, w);
}
SetRect(fSetupMsg, "preview:paper_rect", r);
SetRect(fSetupMsg, "paper_rect", ScaleRect(r, scaleR));
// Save the printable_rect
AddString(fSetupMsg, "preview:paper_size", item->Label());
// Save the printable_rect
BRect margin = fMarginView->GetMargin();
if (orientation == 0) {
margin.right = w - margin.right;
@@ -320,72 +288,59 @@ PageSetupWindow::UpdateSetupMessage()
SetRect(fSetupMsg, "preview:printable_rect", margin);
SetRect(fSetupMsg, "printable_rect", ScaleRect(margin, scaleR));
// save the units used
int32 units = fMarginView->GetMarginUnit();
SetInt32(fSetupMsg, "units", units);
}
SetInt32(fSetupMsg, "units", fMarginView->GetMarginUnit());
}
}
// --------------------------------------------------
void
void
PageSetupWindow::MessageReceived(BMessage *msg)
{
switch (msg->what){
case OK_MSG:
switch (msg->what) {
case OK_MSG: {
UpdateSetupMessage();
Quit(B_OK);
break;
case CANCEL_MSG:
} break;
case CANCEL_MSG: {
Quit(B_ERROR);
break;
} break;
// Simon added
case 'pgsz':
{
float w, h;
msg->FindFloat("width", &w);
msg->FindFloat("height", &h);
BMenuItem *item = fOrientationMenu->Menu()->FindMarked();
if (item) {
int32 orientation = 0;
BMessage *m = item->Message();
m->FindInt32("orientation", &orientation);
if (orientation == PrinterDriver::PORTRAIT_ORIENTATION) {
fMarginView->SetPageSize(w, h);
} else {
fMarginView->SetPageSize(h, w);
}
fMarginView->UpdateView(MARGIN_CHANGED);
case PAGE_SIZE_CHANGED: {
float w, h;
msg->FindFloat("width", &w);
msg->FindFloat("height", &h);
BMenuItem *item = fOrientationMenu->Menu()->FindMarked();
if (item) {
int32 orientation = 0;
item->Message()->FindInt32("orientation", &orientation);
if (orientation == PrinterDriver::PORTRAIT_ORIENTATION) {
fMarginView->SetPageSize(w, h);
} else {
fMarginView->SetPageSize(h, w);
}
fMarginView->UpdateView(MARGIN_CHANGED);
}
break;
} break;
// Simon added
case 'ornt':
{
BPoint p = fMarginView->GetPageSize();
int32 orientation;
msg->FindInt32("orientation", &orientation);
if (orientation == PrinterDriver::LANDSCAPE_ORIENTATION
&& p.y > p.x) {
fMarginView->SetPageSize(p.y, p.x);
fMarginView->UpdateView(MARGIN_CHANGED);
}
if (orientation == PrinterDriver::PORTRAIT_ORIENTATION
&& p.x > p.y) {
fMarginView->SetPageSize(p.y, p.x);
fMarginView->UpdateView(MARGIN_CHANGED);
}
case ORIENTATION_CHANGED: {
int32 orientation;
msg->FindInt32("orientation", &orientation);
BPoint p = fMarginView->GetPageSize();
if (orientation == PrinterDriver::LANDSCAPE_ORIENTATION) {
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:
inherited::MessageReceived(msg);
BlockingWindow::MessageReceived(msg);
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.
*
* Authors:
* Philippe Houdoin
* Simon Gauvin
* Simon Gauvin
* Michael Pfeiffer
* Hartmut Reh
* Dr. Hartmut Reh
* julun <[email protected]>
*/
#ifndef PAGESETUPWINDOW_H
#define PAGESETUPWINDOW_H
#include <InterfaceKit.h>
#include <Message.h>
#include <Messenger.h>
#include <File.h>
#include <FindDirectory.h>
#include <Path.h>
#include <String.h>
#include "InterfaceUtils.h"
#include "Utils.h"
#include <String.h>
class BMessage;
class BMenuField;
class BTextControl;
class MarginView;
class PageSetupWindow : public BlockingWindow
class PageSetupWindow : public BlockingWindow
{
public:
// Constructors, destructors, operators...
PageSetupWindow(BMessage *msg, const char *printerName = NULL);
virtual void MessageReceived(BMessage *msg);
PageSetupWindow(BMessage *msg, const char *printerName = NULL);
typedef BlockingWindow inherited;
// public constantes
enum {
OK_MSG = 'ok__',
CANCEL_MSG = 'cncl',
};
// Virtual function overrides
public:
virtual void MessageReceived(BMessage *msg);
// From here, it's none of your business! ;-)
enum {
OK_MSG = 'ok__',
CANCEL_MSG = 'cncl',
PAGE_SIZE_CHANGED = 'pgsz',
ORIENTATION_CHANGED = 'ornt'
};
private:
BMessage * fSetupMsg;
BMenuField * fPageSizeMenu;
BMenuField * fOrientationMenu;
BTextControl * fScaleControl;
void UpdateSetupMessage();
void UpdateSetupMessage();
MarginView * fMarginView;
// used for saving settings
BString fPrinterDirName;
//private class constants
static const int kMargin = 10;
static const int kOffset = 200;
private:
BMessage * fSetupMsg;
BMenuField * fPageSizeMenu;
BMenuField * fOrientationMenu;
BTextControl * fScaleControl;
MarginView * fMarginView;
BString fPrinterDirName;
};
#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.
*
* Authors:
@@ -8,25 +8,35 @@
#include "PreviewDriver.h"
status_t PreviewDriver::PrintJob(BFile *jobFile, BMessage *jobMsg) {
PreviewWindow* w;
w = new PreviewWindow(jobFile);
return w->Go();
#define PREVIEW_DRIVER_DEBUG 0
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);
}
// 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.
*
* Authors:
@@ -11,7 +11,8 @@
class PreviewDriver : public PrinterDriver {
public:
PreviewDriver(BNode* spoolDir) : PrinterDriver(spoolDir) {};
~PreviewDriver() {};
virtual status_t PrintJob(BFile *jobFile, BMessage *jobMsg);
PreviewDriver(BNode* spoolDir);
~PreviewDriver();
virtual status_t PrintJob(BFile *jobFile, BMessage *jobMsg);
};
@@ -1,52 +1,42 @@
/*
* Copyright 2003-2007, Haiku. All rights reserved.
* Copyright 2003-2008, Haiku. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Philippe Houdoin
* Simon Gauvin
* Simon Gauvin
* Michael Pfeiffer
* Dr. Hartmut Reh
*/
#include <stdio.h>
#include <string.h> // for memset()
#include <StorageKit.h>
#include "PrinterDriver.h"
#include "PrintJobReader.h"
#include "PrinterSetupWindow.h"
#include "PageSetupWindow.h"
#include "JobSetupWindow.h"
#include "PageSetupWindow.h"
// Private prototypes
// ------------------
#ifdef CODEWARRIOR
#pragma mark [Constructor & destructor]
#endif
#include <File.h>
#include <Node.h>
#include <Message.h>
#include <stdio.h>
// Constructor & destructor
// ------------------------
// --------------------------------------------------
PrinterDriver::PrinterDriver(BNode* printerNode)
: fJobFile(NULL),
fPrinterNode(printerNode),
fJobMsg(NULL)
: fPrinting(false)
, fJobFile(NULL)
, fPrinterNode(printerNode)
{
}
// --------------------------------------------------
PrinterDriver::~PrinterDriver()
PrinterDriver::~PrinterDriver()
{
}
#ifdef CODEWARRIOR
#pragma mark [Public methods]
#endif
#ifdef B_BEOS_VERSION_DANO
struct print_file_header {
@@ -60,166 +50,111 @@ struct print_file_header {
#endif
// Public methods
// --------------
status_t
PrinterDriver::PrintJob
(
BFile *jobFile, // spool file
BMessage *jobMsg // job message
)
status_t
PrinterDriver::PrintJob(BFile *spoolFile, BMessage *jobMsg)
{
print_file_header pfh;
status_t status;
BMessage *msg;
int32 page;
uint32 copy;
uint32 copies;
const int32 passes = 2;
fJobFile = jobFile;
fJobMsg = jobMsg;
if (!fJobFile || !fPrinterNode)
if (!spoolFile || !fPrinterNode)
return B_ERROR;
// read print file header
fJobFile = spoolFile;
print_file_header pfh;
// read print file header
fJobFile->Seek(0, SEEK_SET);
fJobFile->Read(&pfh, sizeof(pfh));
// read job message
fJobMsg = msg = new BMessage();
msg->Unflatten(fJobFile);
if (msg->HasInt32("copies")) {
copies = msg->FindInt32("copies");
} else {
copies = 1;
}
status = BeginJob();
// read job message
BMessage msg;
msg.Unflatten(fJobFile);
BeginJob();
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
fJobFile->Seek(sizeof(pfh), SEEK_SET);
msg->Unflatten(fJobFile);
}
for (int32 page = 1; page <= pfh.page_count; ++page) {
printf("PrinterDriver::PrintPage(): Faking print of page %ld/ %ld",
page, pfh.page_count);
}
status_t s = EndJob();
if (status == B_OK) status = s;
delete fJobMsg;
fJobFile->Seek(0, SEEK_SET);
PrintJobReader reader(fJobFile);
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;
}
/**
* This will stop the printing loop
*
* @param none
* @return void
*/
void
void
PrinterDriver::StopPrinting()
{
fPrinting = false;
}
// --------------------------------------------------
status_t
PrinterDriver::BeginJob()
PrinterDriver::BeginJob()
{
return B_OK;
}
// --------------------------------------------------
status_t
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;
}
// --------------------------------------------------
status_t
PrinterDriver::EndJob()
PrinterDriver::PrintPage(int32 pageNumber, int32 pageCount)
{
return B_OK;
}
BlockingWindow* PrinterDriver::NewPrinterSetupWindow(char* printerName) {
return NULL;
status_t
PrinterDriver::EndJob()
{
return B_OK;
}
BlockingWindow* PrinterDriver::NewPageSetupWindow(BMessage *setupMsg, const char *printerName) {
BlockingWindow*
PrinterDriver::NewPageSetupWindow(BMessage *setupMsg, const char *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);
}
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)
{
// check to see if the messag is built correctly...
if (setupMsg->HasFloat("scaling") != B_OK) {
#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));
BlockingWindow* w = NewPageSetupWindow(setupMsg, printerName);
return w->Go();
}
// --------------------------------------------------
status_t
status_t
PrinterDriver::JobSetup(BMessage *jobMsg, const char *printerName)
{
// set default value if property not set
@@ -228,16 +163,22 @@ PrinterDriver::JobSetup(BMessage *jobMsg, const char *printerName)
if (!jobMsg->HasInt32("first_page"))
jobMsg->AddInt32("first_page", 1);
if (!jobMsg->HasInt32("last_page"))
jobMsg->AddInt32("last_page", MAX_INT32);
return Go(NewJobSetupWindow(jobMsg, printerName));
if (!jobMsg->HasInt32("last_page"))
jobMsg->AddInt32("last_page", LONG_MAX);
BlockingWindow* w = NewJobSetupWindow(jobMsg, printerName);
return w->Go();
}
// --------------------------------------------------
BMessage*
PrinterDriver::GetDefaultSettings()
/* copied from PDFlib.h: */
#define letter_width (float) 612.0
#define letter_height (float) 792.0
BMessage*
PrinterDriver::GetDefaultSettings()
{
BMessage* msg = new BMessage();
BRect paperRect(0, 0, letter_width, letter_height);
@@ -250,10 +191,3 @@ PrinterDriver::GetDefaultSettings()
msg->AddInt32("yres", 300);
return msg;
}
#ifdef CODEWARRIOR
#pragma mark [Privates routines]
#endif
// Private routines
// ----------------
@@ -1,10 +1,10 @@
/*
* Copyright 2001-2007, Haiku. All rights reserved.
* Copyright 2001-2008, Haiku. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Philippe Houdoin
* Simon Gauvin
* Simon Gauvin
* Michael Pfeiffer
* Dr. Hartmut Reh
*/
@@ -12,55 +12,22 @@
#ifndef PRINTERDRIVER_H
#define PRINTERDRIVER_H
#include <AppKit.h>
#include <InterfaceKit.h>
#include "InterfaceUtils.h"
class BFile;
class BNode;
#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 BMessage;
/**
* Class PrinterDriver
*/
class PrinterDriver
class PrinterDriver
{
public:
// constructors / destructor
PrinterDriver(BNode* printerNode);
virtual ~PrinterDriver();
void StopPrinting();
virtual status_t PrintJob(BFile *jobFile, BMessage *jobMsg);
@@ -69,22 +36,18 @@ public:
virtual status_t EndJob();
// configuration window getters
virtual BlockingWindow* NewPrinterSetupWindow(char* printerName);
virtual BlockingWindow* NewPageSetupWindow(BMessage *setupMsg, const char *printerName);
virtual BlockingWindow* NewJobSetupWindow(BMessage *setupMsg, const char *printerName);
// configuration default methods
virtual status_t PrinterSetup(char *printerName);
virtual status_t PageSetup(BMessage *msg, const char *printerName = NULL);
virtual status_t JobSetup(BMessage *msg, const char *printerName = NULL);
virtual BMessage* GetDefaultSettings();
// accessors
inline BFile *JobFile() { return fJobFile; }
inline BNode *PrinterNode() { return fPrinterNode; }
inline BMessage *JobMsg() { return fJobMsg; }
inline int32 Pass() const { return fPass; }
// publics status code
typedef enum {
PORTRAIT_ORIENTATION,
@@ -93,17 +56,12 @@ public:
private:
status_t Go(BlockingWindow* w);
bool fPrinting;
BFile *fJobFile;
BNode *fPrinterNode;
BMessage *fJobMsg;
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