Use class PrintTransport to access transport add-on.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6370 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -64,7 +64,7 @@ public:
|
||||
// Quit() is called by child class with result code
|
||||
void Quit(status_t result);
|
||||
// Show window and wait for it to quit, returns result code
|
||||
status_t Go();
|
||||
virtual status_t Go();
|
||||
// Or quit window e.g. something went wrong in constructor
|
||||
void Quit();
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@ Addon Preview : print :
|
||||
Driver.cpp
|
||||
PrinterDriver.cpp
|
||||
Preview.cpp
|
||||
PreviewDriver.cpp
|
||||
;
|
||||
|
||||
LinkSharedOSLibs Preview : be root libprint.a ;
|
||||
LinkSharedOSLibs Preview : be root libprint.a ;
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
|
||||
float width, height;
|
||||
int32 orient;
|
||||
BRect page;
|
||||
BRect margin(0,0,0,0);
|
||||
BRect margin(0, 0, 0, 0);
|
||||
int32 units = MarginView::UNIT_INCH;
|
||||
BString setting_value;
|
||||
|
||||
@@ -117,10 +117,15 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
|
||||
// (new BAlert("", "orientation not in msg", "Shit"))->Go();
|
||||
|
||||
// load page rect
|
||||
fSetupMsg->FindRect("paper_rect", &r);
|
||||
width = r.Width();
|
||||
height = r.Height();
|
||||
page = r;
|
||||
if (fSetupMsg->FindRect("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);
|
||||
}
|
||||
|
||||
// Load units
|
||||
fSetupMsg->FindInt32("units", &units);
|
||||
@@ -135,12 +140,14 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
|
||||
|
||||
// re-calculate the margin from the printable rect in points
|
||||
margin = page;
|
||||
fSetupMsg->FindRect("printable_rect", &margin);
|
||||
|
||||
margin.top -= page.top;
|
||||
margin.left -= page.left;
|
||||
margin.right = page.right - margin.right;
|
||||
margin.bottom = page.bottom - margin.bottom;
|
||||
if (fSetupMsg->FindRect("printable_rect", &margin) == B_OK) {
|
||||
margin.top -= page.top;
|
||||
margin.left -= page.left;
|
||||
margin.right = page.right - margin.right;
|
||||
margin.bottom = page.bottom - margin.bottom;
|
||||
} else {
|
||||
margin.Set(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
fMarginView = new MarginView(BRect(20,20,200,160), width, height,
|
||||
margin, units);
|
||||
|
||||
@@ -369,32 +369,12 @@ void PreviewWindow::MessageReceived(BMessage* m) {
|
||||
UpdateControls();
|
||||
}
|
||||
|
||||
status_t PreviewDriver::PrintJob(BFile *jobFile, BMessage *jobMsg) {
|
||||
PreviewWindow* w;
|
||||
status_t st;
|
||||
w = new PreviewWindow(jobFile);
|
||||
st = w->InitCheck();
|
||||
status_t PreviewWindow::Go() {
|
||||
status_t st = InitCheck();
|
||||
if (st == B_OK) {
|
||||
w->Go();
|
||||
return inherited::Go();
|
||||
} else {
|
||||
w->Quit();
|
||||
Quit();
|
||||
}
|
||||
return st;
|
||||
}
|
||||
|
||||
PrinterDriver* instanciate_driver(BNode *spoolDir)
|
||||
{
|
||||
return new PreviewDriver(spoolDir);
|
||||
}
|
||||
|
||||
// About dialog text:
|
||||
const char*
|
||||
kAbout =
|
||||
"Preview for BeOS\n"
|
||||
"© 2003 OpenBeOS\n"
|
||||
"by Michael Pfeiffer\n"
|
||||
"\n"
|
||||
"Based on PDF Writer by\nPhilippe Houdoin, Simon Gauvin, Michael Pfeiffer\n"
|
||||
;
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ THE SOFTWARE.
|
||||
|
||||
#include <InterfaceKit.h>
|
||||
#include "PrintJobReader.h"
|
||||
#include "PrinterDriver.h"
|
||||
#include "InterfaceUtils.h"
|
||||
|
||||
class PreviewPage {
|
||||
@@ -109,11 +108,6 @@ public:
|
||||
PreviewWindow(BFile* jobFile);
|
||||
status_t InitCheck() const { return fPreview->InitCheck(); }
|
||||
void MessageReceived(BMessage* m);
|
||||
status_t Go();
|
||||
};
|
||||
|
||||
class PreviewDriver : public PrinterDriver {
|
||||
public:
|
||||
PreviewDriver(BNode* spoolDir) : PrinterDriver(spoolDir) {};
|
||||
~PreviewDriver() {};
|
||||
virtual status_t PrintJob(BFile *jobFile, BMessage *jobMsg);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
|
||||
PreviewDriver
|
||||
|
||||
Copyright (c) 2003 OpenBeOS.
|
||||
|
||||
Author:
|
||||
Michael Pfeiffer
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include "PreviewDriver.h"
|
||||
|
||||
status_t PreviewDriver::PrintJob(BFile *jobFile, BMessage *jobMsg) {
|
||||
PreviewWindow* w;
|
||||
w = new PreviewWindow(jobFile);
|
||||
return w->Go();
|
||||
}
|
||||
|
||||
PrinterDriver* instanciate_driver(BNode *spoolDir)
|
||||
{
|
||||
return new PreviewDriver(spoolDir);
|
||||
}
|
||||
|
||||
// About dialog text:
|
||||
const char*
|
||||
kAbout =
|
||||
"Preview for BeOS\n"
|
||||
"© 2003 OpenBeOS\n"
|
||||
"by Michael Pfeiffer\n"
|
||||
"\n"
|
||||
"Based on PDF Writer by\nPhilippe Houdoin, Simon Gauvin, Michael Pfeiffer\n"
|
||||
;
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
|
||||
Preview
|
||||
|
||||
Copyright (c) 2002, 2003 OpenBeOS.
|
||||
|
||||
Author:
|
||||
Michael Pfeiffer
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include "Preview.h"
|
||||
#include "PrinterDriver.h"
|
||||
|
||||
class PreviewDriver : public PrinterDriver {
|
||||
public:
|
||||
PreviewDriver(BNode* spoolDir) : PrinterDriver(spoolDir) {};
|
||||
~PreviewDriver() {};
|
||||
virtual status_t PrintJob(BFile *jobFile, BMessage *jobMsg);
|
||||
};
|
||||
@@ -55,12 +55,7 @@ THE SOFTWARE.
|
||||
PrinterDriver::PrinterDriver(BNode* printerNode)
|
||||
: fJobFile(NULL),
|
||||
fPrinterNode(printerNode),
|
||||
fJobMsg(NULL),
|
||||
|
||||
fTransport(NULL),
|
||||
fTransportAddOn(-1),
|
||||
fTransportInitProc(NULL),
|
||||
fTransportExitProc(NULL)
|
||||
fJobMsg(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -110,11 +105,10 @@ PrinterDriver::PrintJob
|
||||
if (!fJobFile || !fPrinterNode)
|
||||
return B_ERROR;
|
||||
|
||||
// open transport
|
||||
if (OpenTransport() != B_OK) {
|
||||
if (fPrintTransport.Open(fPrinterNode) != B_OK) {
|
||||
return B_ERROR;
|
||||
}
|
||||
if (PrintToFileCanceled()) {
|
||||
if (fPrintTransport.IsPrintToFileCanceled()) {
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -151,8 +145,6 @@ PrinterDriver::PrintJob
|
||||
status_t s = EndJob();
|
||||
if (status == B_OK) status = s;
|
||||
|
||||
CloseTransport();
|
||||
|
||||
delete fJobMsg;
|
||||
|
||||
return status;
|
||||
@@ -287,112 +279,6 @@ PrinterDriver::GetDefaultSettings()
|
||||
return msg;
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
status_t
|
||||
PrinterDriver::OpenTransport()
|
||||
{
|
||||
char buffer[512];
|
||||
BPath *path;
|
||||
|
||||
|
||||
if (!fPrinterNode)
|
||||
return B_ERROR;
|
||||
|
||||
// first, find & load transport add-on
|
||||
path = new BPath();
|
||||
|
||||
// find name of this printer transport add-on
|
||||
fPrinterNode->ReadAttr("transport", B_STRING_TYPE, 0, buffer, sizeof(buffer));
|
||||
|
||||
// try first on user add-ons directory
|
||||
find_directory(B_USER_ADDONS_DIRECTORY, path);
|
||||
path->Append("Print/transport");
|
||||
path->Append(buffer);
|
||||
fTransportAddOn = load_add_on(path->Path());
|
||||
|
||||
if (fTransportAddOn < 0) {
|
||||
// add-on not in user add-ons directory. try system one
|
||||
find_directory(B_BEOS_ADDONS_DIRECTORY, path);
|
||||
path->Append("Print/transport");
|
||||
path->Append(buffer);
|
||||
fTransportAddOn = load_add_on(path->Path());
|
||||
}
|
||||
|
||||
if (fTransportAddOn < 0) {
|
||||
BAlert * alert = new BAlert("Uh oh!", "Couldn't find transport add-on.", "OK");
|
||||
alert->Go();
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
// get init & exit proc
|
||||
get_image_symbol(fTransportAddOn, "init_transport", B_SYMBOL_TYPE_TEXT, (void **) &fTransportInitProc);
|
||||
get_image_symbol(fTransportAddOn, "exit_transport", B_SYMBOL_TYPE_TEXT, (void **) &fTransportExitProc);
|
||||
|
||||
if (!fTransportInitProc || !fTransportExitProc) {
|
||||
BAlert * alert = new BAlert("Uh oh!", "Couldn't resolve transport symbols.", "OK");
|
||||
alert->Go();
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
delete path;
|
||||
|
||||
// now, init transport add-on
|
||||
node_ref ref;
|
||||
BDirectory dir;
|
||||
|
||||
fPrinterNode->GetNodeRef(&ref);
|
||||
dir.SetTo(&ref);
|
||||
|
||||
path = new BPath(&dir, NULL);
|
||||
strcpy(buffer, path->Path());
|
||||
|
||||
// create BMessage for init_transport()
|
||||
BMessage *msg = new BMessage('TRIN');
|
||||
msg->AddString("printer_file", buffer);
|
||||
|
||||
fTransport = (*fTransportInitProc)(msg);
|
||||
|
||||
delete msg;
|
||||
delete path;
|
||||
|
||||
if (fTransport == 0) {
|
||||
BAlert *alert = new BAlert("Uh oh!", "Couldn't open transport.", "OK");
|
||||
alert->Go();
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
bool
|
||||
PrinterDriver::PrintToFileCanceled()
|
||||
{
|
||||
// The BeOS "Print To File" transport returns a non-NULL BDataIO *
|
||||
// even after user filepanel cancellation!
|
||||
BFile* file = dynamic_cast<BFile*>(fTransport);
|
||||
return file && file->InitCheck() != B_OK;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
status_t
|
||||
PrinterDriver::CloseTransport()
|
||||
{
|
||||
if (!fTransportAddOn)
|
||||
return B_ERROR;
|
||||
|
||||
if (fTransportExitProc)
|
||||
(*fTransportExitProc)();
|
||||
|
||||
unload_add_on(fTransportAddOn);
|
||||
fTransportAddOn = 0;
|
||||
fTransport = NULL;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
#ifdef CODEWARRIOR
|
||||
#pragma mark [Privates routines]
|
||||
#endif
|
||||
|
||||
@@ -34,6 +34,7 @@ THE SOFTWARE.
|
||||
|
||||
#include <AppKit.h>
|
||||
#include <InterfaceKit.h>
|
||||
#include "PrintTransport.h"
|
||||
#include "InterfaceUtils.h"
|
||||
|
||||
#ifndef ROUND_UP
|
||||
@@ -68,12 +69,6 @@ THE SOFTWARE.
|
||||
#define p11x17_width (float) 792.0
|
||||
#define p11x17_height (float) 1224.0
|
||||
|
||||
// transport add-on calls definition
|
||||
extern "C" {
|
||||
typedef BDataIO *(*init_transport_proc)(BMessage *);
|
||||
typedef void (*exit_transport_proc)(void);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Class PrinterDriver
|
||||
@@ -103,16 +98,11 @@ public:
|
||||
virtual status_t JobSetup(BMessage *msg, const char *printerName = NULL);
|
||||
virtual BMessage* GetDefaultSettings();
|
||||
|
||||
// transport-related methods
|
||||
status_t OpenTransport();
|
||||
status_t CloseTransport();
|
||||
bool PrintToFileCanceled();
|
||||
|
||||
// accessors
|
||||
inline BFile *JobFile() { return fJobFile; }
|
||||
inline BNode *PrinterNode() { return fPrinterNode; }
|
||||
inline BMessage *JobMsg() { return fJobMsg; }
|
||||
inline BDataIO *Transport() { return fTransport; }
|
||||
inline BDataIO *Transport() { return fPrintTransport.GetDataIO(); }
|
||||
inline int32 Pass() const { return fPass; }
|
||||
|
||||
// publics status code
|
||||
@@ -135,10 +125,7 @@ private:
|
||||
int32 fPass;
|
||||
|
||||
// transport-related
|
||||
BDataIO *fTransport;
|
||||
image_id fTransportAddOn;
|
||||
init_transport_proc fTransportInitProc;
|
||||
exit_transport_proc fTransportExitProc;
|
||||
PrintTransport fPrintTransport;
|
||||
};
|
||||
|
||||
#endif // #ifndef PRINTERDRIVER_H
|
||||
|
||||
Reference in New Issue
Block a user