From 6bb758a26fd2ca15fea6f2933894d56011c186ce Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Wed, 2 Mar 2005 11:15:41 +0000 Subject: [PATCH] Implemented some basic BPrintJob methods (hope I didn't screw anything, is there any print server guy around ?). Is there any reason why it is left out of the build (besides being incomplete) ? git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11530 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/PrintJob.cpp | 174 +++++++++++++++++++------------ src/kits/interface/interface.src | 1 + 2 files changed, 107 insertions(+), 68 deletions(-) diff --git a/src/kits/interface/PrintJob.cpp b/src/kits/interface/PrintJob.cpp index bf5775e32e..cbe1f47677 100644 --- a/src/kits/interface/PrintJob.cpp +++ b/src/kits/interface/PrintJob.cpp @@ -27,9 +27,29 @@ THE SOFTWARE. */ -#include "PrintJob.h" +#include +#include + +#include + +#include +#include + + +static BMessenger *sPrintServer = NULL; + + +static void +EnsureValidMessenger() +{ + if (sPrintServer == NULL) + sPrintServer = new BMessenger; + + if (!sPrintServer->IsValid()) + *sPrintServer = BMessenger(PSRV_SIGNATURE_TYPE); +} + -// ----------------------------------------------------------------------------- BPrintJob::BPrintJob(const char *job_name) : print_job_name(NULL), @@ -40,55 +60,54 @@ BPrintJob::BPrintJob(const char *job_name) default_setup_msg(NULL), m_curPageHeader(NULL) { - print_job_name = new char[strlen(job_name)+1]; - ::strcpy(print_job_name, job_name); + print_job_name = strdup(job_name); } -// ----------------------------------------------------------------------------- + BPrintJob::~BPrintJob() { - delete print_job_name; + free(print_job_name); } -// ----------------------------------------------------------------------------- + void BPrintJob::BeginJob() { } -// ----------------------------------------------------------------------------- + void BPrintJob::CommitJob() { } -// ----------------------------------------------------------------------------- + status_t BPrintJob::ConfigJob() { return B_OK; } -// ----------------------------------------------------------------------------- + void BPrintJob::CancelJob() { } -// ----------------------------------------------------------------------------- + status_t BPrintJob::ConfigPage() { return B_OK; } -// ----------------------------------------------------------------------------- + void BPrintJob::SpoolPage() { } -// ----------------------------------------------------------------------------- + bool BPrintJob::CanContinue() { @@ -97,7 +116,6 @@ BPrintJob::CanContinue() } -// ----------------------------------------------------------------------------- void BPrintJob::DrawView(BView *a_view, BRect a_rect, @@ -106,64 +124,84 @@ BPrintJob::DrawView(BView *a_view, } -// ----------------------------------------------------------------------------- BMessage * BPrintJob::Settings() { - return NULL; + BMessage *message = NULL; + + if (setup_msg != NULL) + message = new BMessage(*setup_msg); + + return message; } -// ----------------------------------------------------------------------------- + void BPrintJob::SetSettings(BMessage *a_msg) { } -// ----------------------------------------------------------------------------- + bool -BPrintJob::IsSettingsMessageValid(BMessage *a_msg) const +BPrintJob::IsSettingsMessageValid(BMessage *message) const { - return true; + const char *messageName = NULL; + char *printerName = GetCurrentPrinterName(); + + bool result = false; + + // The passed message is valid if it contains the right printer name. + if (message != NULL + && message->FindString("printer_name", &messageName) == B_OK + && strcmp(printerName, messageName) == 0) + result = true; + + free(printerName); + + return result; } -// ----------------------------------------------------------------------------- + BRect BPrintJob::PaperRect() { + if (!paper_size.IsValid()) + LoadDefaultSettings(); + return paper_size; } -// ----------------------------------------------------------------------------- + BRect BPrintJob::PrintableRect() { + if (!usable_size.IsValid()) + LoadDefaultSettings(); + return usable_size; } -// ----------------------------------------------------------------------------- void -BPrintJob::GetResolution(int32 *xdpi, - int32 *ydpi) +BPrintJob::GetResolution(int32 *xdpi, int32 *ydpi) { *xdpi = v_xres; *ydpi = v_yres; } -// ----------------------------------------------------------------------------- + int32 BPrintJob::FirstPage() { return first_page; } -// ----------------------------------------------------------------------------- int32 BPrintJob::LastPage() { return last_page; } -// ----------------------------------------------------------------------------- + int32 BPrintJob::PrinterType(void *) const { @@ -174,92 +212,92 @@ BPrintJob::PrinterType(void *) const #pragma mark ----- PRIVATE ----- #endif -// ----------------------------------------------------------------------------- + void -BPrintJob::RecurseView(BView *v, - BPoint origin, - BPicture *p, - BRect r) +BPrintJob::RecurseView(BView *view, BPoint origin, + BPicture *picture, BRect rect) { } -// ----------------------------------------------------------------------------- + void BPrintJob::MangleName(char *filename) { } -// ----------------------------------------------------------------------------- + void BPrintJob::HandlePageSetup(BMessage *setup) { } -// ----------------------------------------------------------------------------- + bool BPrintJob::HandlePrintSetup(BMessage *setup) { return true; } -// ----------------------------------------------------------------------------- + void BPrintJob::NewPage() { } -// ----------------------------------------------------------------------------- + void BPrintJob::EndLastPage() { } -// ----------------------------------------------------------------------------- + void BPrintJob::AddSetupSpec() { } -// ----------------------------------------------------------------------------- + void -BPrintJob::AddPicture(BPicture *picture, - BRect *rect, - BPoint where) +BPrintJob::AddPicture(BPicture *picture, BRect *rect, BPoint where) { } -// ----------------------------------------------------------------------------- + char * BPrintJob::GetCurrentPrinterName() const -{ - return NULL; +{ + EnsureValidMessenger(); + + BMessage message(PSRV_GET_ACTIVE_PRINTER); + BMessage reply; + + const char *printerName = NULL; + + if (sPrintServer->SendMessage(&message, &reply) == B_OK) + reply.FindString("printer_name", &printerName); + + return printerName != NULL ? strdup(printerName) : NULL; } -// ----------------------------------------------------------------------------- + void BPrintJob::LoadDefaultSettings() { + EnsureValidMessenger(); + + BMessage message(PSRV_GET_DEFAULT_SETTINGS); + BMessage reply; + + sPrintServer->SendMessage(&message, &reply); + + if (reply.HasRect("paper_rect")) + reply.FindRect("paper_rect", &paper_size); + if (reply.HasRect("printable_rect")) + reply.FindRect("printable_rect", &usable_size); } - -// ----------------------------------------------------------------------------- -void -BPrintJob::_ReservedPrintJob1() -{ -} - -void -BPrintJob::_ReservedPrintJob2() -{ -} - -void -BPrintJob::_ReservedPrintJob3() -{ -} - -void -BPrintJob::_ReservedPrintJob4() -{ -} +void BPrintJob::_ReservedPrintJob1() {} +void BPrintJob::_ReservedPrintJob2() {} +void BPrintJob::_ReservedPrintJob3() {} +void BPrintJob::_ReservedPrintJob4() {} diff --git a/src/kits/interface/interface.src b/src/kits/interface/interface.src index ead363798f..8ee4982a34 100644 --- a/src/kits/interface/interface.src +++ b/src/kits/interface/interface.src @@ -30,6 +30,7 @@ INTERFACE_KIT_SOURCE = Point.cpp Polygon.cpp PopUpMenu.cpp + #PrintJob.cpp PrivateScreen.cpp RadioButton.cpp Rect.cpp