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
|
// Quit() is called by child class with result code
|
||||||
void Quit(status_t result);
|
void Quit(status_t result);
|
||||||
// Show window and wait for it to quit, returns result code
|
// 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
|
// Or quit window e.g. something went wrong in constructor
|
||||||
void Quit();
|
void Quit();
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ Addon Preview : print :
|
|||||||
Driver.cpp
|
Driver.cpp
|
||||||
PrinterDriver.cpp
|
PrinterDriver.cpp
|
||||||
Preview.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;
|
float width, height;
|
||||||
int32 orient;
|
int32 orient;
|
||||||
BRect page;
|
BRect page;
|
||||||
BRect margin(0,0,0,0);
|
BRect margin(0, 0, 0, 0);
|
||||||
int32 units = MarginView::UNIT_INCH;
|
int32 units = MarginView::UNIT_INCH;
|
||||||
BString setting_value;
|
BString setting_value;
|
||||||
|
|
||||||
@@ -117,10 +117,15 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
|
|||||||
// (new BAlert("", "orientation not in msg", "Shit"))->Go();
|
// (new BAlert("", "orientation not in msg", "Shit"))->Go();
|
||||||
|
|
||||||
// load page rect
|
// load page rect
|
||||||
fSetupMsg->FindRect("paper_rect", &r);
|
if (fSetupMsg->FindRect("paper_rect", &r) == B_OK) {
|
||||||
width = r.Width();
|
width = r.Width();
|
||||||
height = r.Height();
|
height = r.Height();
|
||||||
page = r;
|
page = r;
|
||||||
|
} else {
|
||||||
|
width = letter_width;
|
||||||
|
height = letter_height;
|
||||||
|
page.Set(0, 0, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
// Load units
|
// Load units
|
||||||
fSetupMsg->FindInt32("units", &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
|
// re-calculate the margin from the printable rect in points
|
||||||
margin = page;
|
margin = page;
|
||||||
fSetupMsg->FindRect("printable_rect", &margin);
|
if (fSetupMsg->FindRect("printable_rect", &margin) == B_OK) {
|
||||||
|
margin.top -= page.top;
|
||||||
margin.top -= page.top;
|
margin.left -= page.left;
|
||||||
margin.left -= page.left;
|
margin.right = page.right - margin.right;
|
||||||
margin.right = page.right - margin.right;
|
margin.bottom = page.bottom - margin.bottom;
|
||||||
margin.bottom = page.bottom - margin.bottom;
|
} else {
|
||||||
|
margin.Set(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
fMarginView = new MarginView(BRect(20,20,200,160), width, height,
|
fMarginView = new MarginView(BRect(20,20,200,160), width, height,
|
||||||
margin, units);
|
margin, units);
|
||||||
|
|||||||
@@ -369,32 +369,12 @@ void PreviewWindow::MessageReceived(BMessage* m) {
|
|||||||
UpdateControls();
|
UpdateControls();
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t PreviewDriver::PrintJob(BFile *jobFile, BMessage *jobMsg) {
|
status_t PreviewWindow::Go() {
|
||||||
PreviewWindow* w;
|
status_t st = InitCheck();
|
||||||
status_t st;
|
|
||||||
w = new PreviewWindow(jobFile);
|
|
||||||
st = w->InitCheck();
|
|
||||||
if (st == B_OK) {
|
if (st == B_OK) {
|
||||||
w->Go();
|
return inherited::Go();
|
||||||
} else {
|
} else {
|
||||||
w->Quit();
|
Quit();
|
||||||
}
|
}
|
||||||
return st;
|
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 <InterfaceKit.h>
|
||||||
#include "PrintJobReader.h"
|
#include "PrintJobReader.h"
|
||||||
#include "PrinterDriver.h"
|
|
||||||
#include "InterfaceUtils.h"
|
#include "InterfaceUtils.h"
|
||||||
|
|
||||||
class PreviewPage {
|
class PreviewPage {
|
||||||
@@ -109,11 +108,6 @@ public:
|
|||||||
PreviewWindow(BFile* jobFile);
|
PreviewWindow(BFile* jobFile);
|
||||||
status_t InitCheck() const { return fPreview->InitCheck(); }
|
status_t InitCheck() const { return fPreview->InitCheck(); }
|
||||||
void MessageReceived(BMessage* m);
|
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)
|
PrinterDriver::PrinterDriver(BNode* printerNode)
|
||||||
: fJobFile(NULL),
|
: fJobFile(NULL),
|
||||||
fPrinterNode(printerNode),
|
fPrinterNode(printerNode),
|
||||||
fJobMsg(NULL),
|
fJobMsg(NULL)
|
||||||
|
|
||||||
fTransport(NULL),
|
|
||||||
fTransportAddOn(-1),
|
|
||||||
fTransportInitProc(NULL),
|
|
||||||
fTransportExitProc(NULL)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,11 +105,10 @@ PrinterDriver::PrintJob
|
|||||||
if (!fJobFile || !fPrinterNode)
|
if (!fJobFile || !fPrinterNode)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
// open transport
|
if (fPrintTransport.Open(fPrinterNode) != B_OK) {
|
||||||
if (OpenTransport() != B_OK) {
|
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
if (PrintToFileCanceled()) {
|
if (fPrintTransport.IsPrintToFileCanceled()) {
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,8 +145,6 @@ PrinterDriver::PrintJob
|
|||||||
status_t s = EndJob();
|
status_t s = EndJob();
|
||||||
if (status == B_OK) status = s;
|
if (status == B_OK) status = s;
|
||||||
|
|
||||||
CloseTransport();
|
|
||||||
|
|
||||||
delete fJobMsg;
|
delete fJobMsg;
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@@ -287,112 +279,6 @@ PrinterDriver::GetDefaultSettings()
|
|||||||
return msg;
|
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
|
#ifdef CODEWARRIOR
|
||||||
#pragma mark [Privates routines]
|
#pragma mark [Privates routines]
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ THE SOFTWARE.
|
|||||||
|
|
||||||
#include <AppKit.h>
|
#include <AppKit.h>
|
||||||
#include <InterfaceKit.h>
|
#include <InterfaceKit.h>
|
||||||
|
#include "PrintTransport.h"
|
||||||
#include "InterfaceUtils.h"
|
#include "InterfaceUtils.h"
|
||||||
|
|
||||||
#ifndef ROUND_UP
|
#ifndef ROUND_UP
|
||||||
@@ -68,12 +69,6 @@ THE SOFTWARE.
|
|||||||
#define p11x17_width (float) 792.0
|
#define p11x17_width (float) 792.0
|
||||||
#define p11x17_height (float) 1224.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
|
* Class PrinterDriver
|
||||||
@@ -103,16 +98,11 @@ public:
|
|||||||
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();
|
||||||
|
|
||||||
// transport-related methods
|
|
||||||
status_t OpenTransport();
|
|
||||||
status_t CloseTransport();
|
|
||||||
bool PrintToFileCanceled();
|
|
||||||
|
|
||||||
// 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 BMessage *JobMsg() { return fJobMsg; }
|
||||||
inline BDataIO *Transport() { return fTransport; }
|
inline BDataIO *Transport() { return fPrintTransport.GetDataIO(); }
|
||||||
inline int32 Pass() const { return fPass; }
|
inline int32 Pass() const { return fPass; }
|
||||||
|
|
||||||
// publics status code
|
// publics status code
|
||||||
@@ -135,10 +125,7 @@ private:
|
|||||||
int32 fPass;
|
int32 fPass;
|
||||||
|
|
||||||
// transport-related
|
// transport-related
|
||||||
BDataIO *fTransport;
|
PrintTransport fPrintTransport;
|
||||||
image_id fTransportAddOn;
|
|
||||||
init_transport_proc fTransportInitProc;
|
|
||||||
exit_transport_proc fTransportExitProc;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // #ifndef PRINTERDRIVER_H
|
#endif // #ifndef PRINTERDRIVER_H
|
||||||
|
|||||||
Reference in New Issue
Block a user