* naive implementation for DrawAfterChildren()
* resolved TODO in _RecurseView(), no need to call Draw() on views that are hidden or miss the B_WILL_DRAW flag, as there Draw() function would never be called according to the BeBook documentation git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24686 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+136
-126
@@ -3,9 +3,9 @@
|
|||||||
* Distributed under the terms of the MIT license.
|
* Distributed under the terms of the MIT license.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
I.R. Adema
|
* I.R. Adema
|
||||||
Stefano Ceccherini ([email protected])
|
* Stefano Ceccherini ([email protected])
|
||||||
Michael Pfeiffer
|
* Michael Pfeiffer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// TODO refactor (avoid code duplications, decrease method sizes)
|
// TODO refactor (avoid code duplications, decrease method sizes)
|
||||||
@@ -38,11 +38,11 @@ static const char *kNoPagesToPrintText = "No Pages to print!";
|
|||||||
|
|
||||||
// Summery of spool file format:
|
// Summery of spool file format:
|
||||||
// See articel "How to Write a BeOS R5 Printer Driver" for description
|
// See articel "How to Write a BeOS R5 Printer Driver" for description
|
||||||
// of spool file format:
|
// of spool file format:
|
||||||
// http://haiku-os.org/documents/dev/how_to_write_a_printer_driver
|
// http://haiku-os.org/documents/dev/how_to_write_a_printer_driver
|
||||||
|
|
||||||
// print_file_header header
|
// print_file_header header
|
||||||
// On BeOS R5 header.version is 1 << 16 and
|
// On BeOS R5 header.version is 1 << 16 and
|
||||||
// header.first_page is -1.
|
// header.first_page is -1.
|
||||||
// BMessage job_settings
|
// BMessage job_settings
|
||||||
// _page_header_ page_header
|
// _page_header_ page_header
|
||||||
@@ -59,7 +59,7 @@ struct _page_header_ {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
GetPrinterServerMessenger(BMessenger& messenger)
|
GetPrinterServerMessenger(BMessenger& messenger)
|
||||||
{
|
{
|
||||||
messenger = BMessenger(PSRV_SIGNATURE_TYPE);
|
messenger = BMessenger(PSRV_SIGNATURE_TYPE);
|
||||||
@@ -67,44 +67,44 @@ GetPrinterServerMessenger(BMessenger& messenger)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ShowError(const char *message)
|
ShowError(const char *message)
|
||||||
{
|
{
|
||||||
BAlert* alert = new BAlert("Error", message, "OK");
|
BAlert* alert = new BAlert("Error", message, "OK");
|
||||||
alert->Go();
|
alert->Go();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace BPrivate {
|
namespace BPrivate {
|
||||||
|
|
||||||
class Configuration {
|
class Configuration {
|
||||||
public:
|
public:
|
||||||
Configuration(uint32 what, BMessage *input);
|
Configuration(uint32 what, BMessage *input);
|
||||||
~Configuration();
|
~Configuration();
|
||||||
|
|
||||||
status_t SendRequest(thread_func function);
|
status_t SendRequest(thread_func function);
|
||||||
|
|
||||||
BMessage* Request();
|
BMessage* Request();
|
||||||
|
|
||||||
void SetResult(BMessage* result);
|
void SetResult(BMessage* result);
|
||||||
BMessage* Result() const { return fResult; }
|
BMessage* Result() const { return fResult; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void RejectUserInput();
|
void RejectUserInput();
|
||||||
void AllowUserInput();
|
void AllowUserInput();
|
||||||
void DeleteSemaphore();
|
void DeleteSemaphore();
|
||||||
|
|
||||||
uint32 fWhat;
|
uint32 fWhat;
|
||||||
BMessage *fInput;
|
BMessage *fInput;
|
||||||
BMessage *fRequest;
|
BMessage *fRequest;
|
||||||
BMessage *fResult;
|
BMessage *fResult;
|
||||||
sem_id fThreadCompleted;
|
sem_id fThreadCompleted;
|
||||||
BAlert *fHiddenApplicationModalWindow;
|
BAlert *fHiddenApplicationModalWindow;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Configuration::Configuration(uint32 what, BMessage *input)
|
Configuration::Configuration(uint32 what, BMessage *input)
|
||||||
: fWhat(what),
|
: fWhat(what),
|
||||||
fInput(input),
|
fInput(input),
|
||||||
fRequest(NULL),
|
fRequest(NULL),
|
||||||
fResult(NULL),
|
fResult(NULL),
|
||||||
@@ -113,8 +113,8 @@ namespace BPrivate {
|
|||||||
{
|
{
|
||||||
RejectUserInput();
|
RejectUserInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Configuration::~Configuration()
|
Configuration::~Configuration()
|
||||||
{
|
{
|
||||||
DeleteSemaphore();
|
DeleteSemaphore();
|
||||||
@@ -122,9 +122,9 @@ namespace BPrivate {
|
|||||||
delete fRequest; fRequest = NULL;
|
delete fRequest; fRequest = NULL;
|
||||||
AllowUserInput();
|
AllowUserInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Configuration::RejectUserInput()
|
Configuration::RejectUserInput()
|
||||||
{
|
{
|
||||||
BAlert* alert = new BAlert("bogus", "app_modal_dialog", "OK");
|
BAlert* alert = new BAlert("bogus", "app_modal_dialog", "OK");
|
||||||
@@ -134,16 +134,16 @@ namespace BPrivate {
|
|||||||
alert->MoveTo(-65000, -65000);
|
alert->MoveTo(-65000, -65000);
|
||||||
alert->Go(NULL);
|
alert->Go(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Configuration::AllowUserInput()
|
Configuration::AllowUserInput()
|
||||||
{
|
{
|
||||||
fHiddenApplicationModalWindow->Lock();
|
fHiddenApplicationModalWindow->Lock();
|
||||||
fHiddenApplicationModalWindow->Quit();
|
fHiddenApplicationModalWindow->Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Configuration::DeleteSemaphore()
|
Configuration::DeleteSemaphore()
|
||||||
{
|
{
|
||||||
@@ -153,25 +153,25 @@ namespace BPrivate {
|
|||||||
delete_sem(id);
|
delete_sem(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
Configuration::SendRequest(thread_func function)
|
Configuration::SendRequest(thread_func function)
|
||||||
{
|
{
|
||||||
fThreadCompleted = create_sem(0, "Configuration");
|
fThreadCompleted = create_sem(0, "Configuration");
|
||||||
if (fThreadCompleted < B_OK) {
|
if (fThreadCompleted < B_OK) {
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_id id = spawn_thread(function, "async_request", B_NORMAL_PRIORITY, this);
|
thread_id id = spawn_thread(function, "async_request", B_NORMAL_PRIORITY, this);
|
||||||
if (id <= 0 || resume_thread(id) != B_OK) {
|
if (id <= 0 || resume_thread(id) != B_OK) {
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Code copied from BAlert::Go()
|
// Code copied from BAlert::Go()
|
||||||
BWindow* window = dynamic_cast<BWindow*>(BLooper::LooperForThread(find_thread(NULL)));
|
BWindow* window = dynamic_cast<BWindow*>(BLooper::LooperForThread(find_thread(NULL)));
|
||||||
// Get the originating window, if it exists
|
// Get the originating window, if it exists
|
||||||
|
|
||||||
// Heavily modified from TextEntryAlert code; the original didn't let the
|
// Heavily modified from TextEntryAlert code; the original didn't let the
|
||||||
// blocked window ever draw.
|
// blocked window ever draw.
|
||||||
if (window != NULL) {
|
if (window != NULL) {
|
||||||
@@ -182,7 +182,7 @@ namespace BPrivate {
|
|||||||
kSemTimeOut);
|
kSemTimeOut);
|
||||||
// We've (probably) had our time slice taken away from us
|
// We've (probably) had our time slice taken away from us
|
||||||
} while (err == B_INTERRUPTED);
|
} while (err == B_INTERRUPTED);
|
||||||
|
|
||||||
if (err == B_BAD_SEM_ID) {
|
if (err == B_BAD_SEM_ID) {
|
||||||
// Semaphore was finally nuked in SetResult(BMessage *)
|
// Semaphore was finally nuked in SetResult(BMessage *)
|
||||||
break;
|
break;
|
||||||
@@ -193,20 +193,20 @@ namespace BPrivate {
|
|||||||
// No window to update, so just hang out until we're done.
|
// No window to update, so just hang out until we're done.
|
||||||
while (acquire_sem(fThreadCompleted) == B_INTERRUPTED);
|
while (acquire_sem(fThreadCompleted) == B_INTERRUPTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t status;
|
status_t status;
|
||||||
wait_for_thread(id, &status);
|
wait_for_thread(id, &status);
|
||||||
|
|
||||||
return Result() != NULL ? B_OK : B_ERROR;
|
return Result() != NULL ? B_OK : B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BMessage *
|
BMessage *
|
||||||
Configuration::Request()
|
Configuration::Request()
|
||||||
{
|
{
|
||||||
if (fRequest != NULL)
|
if (fRequest != NULL)
|
||||||
return fRequest;
|
return fRequest;
|
||||||
|
|
||||||
if (fInput != NULL) {
|
if (fInput != NULL) {
|
||||||
fRequest = new BMessage(*fInput);
|
fRequest = new BMessage(*fInput);
|
||||||
fRequest->what = fWhat;
|
fRequest->what = fWhat;
|
||||||
@@ -214,8 +214,8 @@ namespace BPrivate {
|
|||||||
fRequest = new BMessage(fWhat);
|
fRequest = new BMessage(fWhat);
|
||||||
return fRequest;
|
return fRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Configuration::SetResult(BMessage *result)
|
Configuration::SetResult(BMessage *result)
|
||||||
{
|
{
|
||||||
@@ -238,11 +238,11 @@ BPrintJob::BPrintJob(const char *job_name)
|
|||||||
fCurrentPageHeader(NULL)
|
fCurrentPageHeader(NULL)
|
||||||
{
|
{
|
||||||
memset(&fCurrentHeader, 0, sizeof(fCurrentHeader));
|
memset(&fCurrentHeader, 0, sizeof(fCurrentHeader));
|
||||||
|
|
||||||
if (job_name != NULL) {
|
if (job_name != NULL) {
|
||||||
fPrintJobName = strdup(job_name);
|
fPrintJobName = strdup(job_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
fCurrentPageHeader = new _page_header_;
|
fCurrentPageHeader = new _page_header_;
|
||||||
if (fCurrentPageHeader != NULL) {
|
if (fCurrentPageHeader != NULL) {
|
||||||
memset(fCurrentPageHeader, 0, sizeof(*fCurrentPageHeader));
|
memset(fCurrentPageHeader, 0, sizeof(*fCurrentPageHeader));
|
||||||
@@ -253,7 +253,7 @@ BPrintJob::BPrintJob(const char *job_name)
|
|||||||
BPrintJob::~BPrintJob()
|
BPrintJob::~BPrintJob()
|
||||||
{
|
{
|
||||||
CancelJob();
|
CancelJob();
|
||||||
|
|
||||||
free(fPrintJobName);
|
free(fPrintJobName);
|
||||||
delete fSetupMessage;
|
delete fSetupMessage;
|
||||||
delete fDefaultSetupMessage;
|
delete fDefaultSetupMessage;
|
||||||
@@ -265,7 +265,7 @@ static status_t
|
|||||||
ConfigPageThread(void *data)
|
ConfigPageThread(void *data)
|
||||||
{
|
{
|
||||||
BPrivate::Configuration* configuration = static_cast<BPrivate::Configuration*>(data);
|
BPrivate::Configuration* configuration = static_cast<BPrivate::Configuration*>(data);
|
||||||
|
|
||||||
BMessenger printServer;
|
BMessenger printServer;
|
||||||
if (GetPrinterServerMessenger(printServer) != B_OK) {
|
if (GetPrinterServerMessenger(printServer) != B_OK) {
|
||||||
ShowError(kPrintServerNotRespondingText);
|
ShowError(kPrintServerNotRespondingText);
|
||||||
@@ -279,14 +279,14 @@ ConfigPageThread(void *data)
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BMessage reply;
|
BMessage reply;
|
||||||
if (printServer.SendMessage(request, &reply) != B_OK
|
if (printServer.SendMessage(request, &reply) != B_OK
|
||||||
|| reply.what != 'okok') {
|
|| reply.what != 'okok') {
|
||||||
configuration->SetResult(NULL);
|
configuration->SetResult(NULL);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
configuration->SetResult(new BMessage(reply));
|
configuration->SetResult(new BMessage(reply));
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -294,7 +294,7 @@ ConfigPageThread(void *data)
|
|||||||
|
|
||||||
status_t
|
status_t
|
||||||
BPrintJob::ConfigPage()
|
BPrintJob::ConfigPage()
|
||||||
{
|
{
|
||||||
BPrivate::Configuration configuration(PSRV_SHOW_PAGE_SETUP, fSetupMessage);
|
BPrivate::Configuration configuration(PSRV_SHOW_PAGE_SETUP, fSetupMessage);
|
||||||
status_t status = configuration.SendRequest(ConfigPageThread);
|
status_t status = configuration.SendRequest(ConfigPageThread);
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
@@ -310,7 +310,7 @@ static status_t
|
|||||||
ConfigJobThread(void *data)
|
ConfigJobThread(void *data)
|
||||||
{
|
{
|
||||||
BPrivate::Configuration* configuration = static_cast<BPrivate::Configuration*>(data);
|
BPrivate::Configuration* configuration = static_cast<BPrivate::Configuration*>(data);
|
||||||
|
|
||||||
BMessenger printServer;
|
BMessenger printServer;
|
||||||
if (GetPrinterServerMessenger(printServer) != B_OK) {
|
if (GetPrinterServerMessenger(printServer) != B_OK) {
|
||||||
ShowError(kPrintServerNotRespondingText);
|
ShowError(kPrintServerNotRespondingText);
|
||||||
@@ -324,14 +324,14 @@ ConfigJobThread(void *data)
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BMessage reply;
|
BMessage reply;
|
||||||
if (printServer.SendMessage(request, &reply) != B_OK
|
if (printServer.SendMessage(request, &reply) != B_OK
|
||||||
|| reply.what != 'okok') {
|
|| reply.what != 'okok') {
|
||||||
configuration->SetResult(NULL);
|
configuration->SetResult(NULL);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
configuration->SetResult(new BMessage(reply));
|
configuration->SetResult(new BMessage(reply));
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -344,7 +344,7 @@ BPrintJob::ConfigJob()
|
|||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
delete fSetupMessage;
|
delete fSetupMessage;
|
||||||
fSetupMessage = configuration.Result();
|
fSetupMessage = configuration.Result();
|
||||||
_HandlePrintSetup(fSetupMessage);
|
_HandlePrintSetup(fSetupMessage);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -360,33 +360,33 @@ BPrintJob::BeginJob()
|
|||||||
if (fCurrentPageHeader == NULL) {
|
if (fCurrentPageHeader == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fSetupMessage == NULL) {
|
if (fSetupMessage == NULL) {
|
||||||
// TODO show alert, setup message is required
|
// TODO show alert, setup message is required
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create spool file
|
// create spool file
|
||||||
BPath path;
|
BPath path;
|
||||||
status_t status = find_directory(B_USER_PRINTERS_DIRECTORY, &path);
|
status_t status = find_directory(B_USER_PRINTERS_DIRECTORY, &path);
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
char *printer = _GetCurrentPrinterName();
|
char *printer = _GetCurrentPrinterName();
|
||||||
if (printer == NULL)
|
if (printer == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
path.Append(printer);
|
path.Append(printer);
|
||||||
free(printer);
|
free(printer);
|
||||||
|
|
||||||
char mangledName[B_FILE_NAME_LENGTH];
|
char mangledName[B_FILE_NAME_LENGTH];
|
||||||
_GetMangledName(mangledName, B_FILE_NAME_LENGTH);
|
_GetMangledName(mangledName, B_FILE_NAME_LENGTH);
|
||||||
|
|
||||||
path.Append(mangledName);
|
path.Append(mangledName);
|
||||||
|
|
||||||
if (path.InitCheck() != B_OK)
|
if (path.InitCheck() != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// TODO fSpoolFileName should store the name only (not path which can be 1024 bytes long)
|
// TODO fSpoolFileName should store the name only (not path which can be 1024 bytes long)
|
||||||
strncpy(fSpoolFileName, path.Path(), sizeof(fSpoolFileName));
|
strncpy(fSpoolFileName, path.Path(), sizeof(fSpoolFileName));
|
||||||
fSpoolFile = new BFile(fSpoolFileName, B_READ_WRITE | B_CREATE_FILE);
|
fSpoolFile = new BFile(fSpoolFileName, B_READ_WRITE | B_CREATE_FILE);
|
||||||
@@ -394,32 +394,32 @@ BPrintJob::BeginJob()
|
|||||||
if (fSpoolFile->InitCheck() != B_OK) {
|
if (fSpoolFile->InitCheck() != B_OK) {
|
||||||
CancelJob();
|
CancelJob();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add print_file_header
|
// add print_file_header
|
||||||
// page_count is updated in CommitJob()
|
// page_count is updated in CommitJob()
|
||||||
fCurrentHeader.version = 1 << 16;
|
fCurrentHeader.version = 1 << 16;
|
||||||
fCurrentHeader.page_count = 0;
|
fCurrentHeader.page_count = 0;
|
||||||
// on BeOS R5 the offset to the first page
|
// on BeOS R5 the offset to the first page
|
||||||
// was always -1.
|
// was always -1.
|
||||||
fCurrentHeader.first_page = (off_t)-1;
|
fCurrentHeader.first_page = (off_t)-1;
|
||||||
|
|
||||||
if (fSpoolFile->Write(&fCurrentHeader, sizeof(fCurrentHeader)) != sizeof(fCurrentHeader)) {
|
if (fSpoolFile->Write(&fCurrentHeader, sizeof(fCurrentHeader)) != sizeof(fCurrentHeader)) {
|
||||||
CancelJob();
|
CancelJob();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add printer settings message
|
// add printer settings message
|
||||||
if (!fSetupMessage->HasString(PSRV_FIELD_CURRENT_PRINTER))
|
if (!fSetupMessage->HasString(PSRV_FIELD_CURRENT_PRINTER))
|
||||||
fSetupMessage->AddString(PSRV_FIELD_CURRENT_PRINTER, printer);
|
fSetupMessage->AddString(PSRV_FIELD_CURRENT_PRINTER, printer);
|
||||||
_AddSetupSpec();
|
_AddSetupSpec();
|
||||||
|
|
||||||
// prepare page header
|
// prepare page header
|
||||||
// number_of_pictures is updated in DrawView()
|
// number_of_pictures is updated in DrawView()
|
||||||
// next_page is updated in SpoolPage()
|
// next_page is updated in SpoolPage()
|
||||||
fCurrentPageHeaderOffset = fSpoolFile->Position();
|
fCurrentPageHeaderOffset = fSpoolFile->Position();
|
||||||
fCurrentPageHeader->number_of_pictures = 0;
|
fCurrentPageHeader->number_of_pictures = 0;
|
||||||
|
|
||||||
// state variables
|
// state variables
|
||||||
fAbort = 0;
|
fAbort = 0;
|
||||||
fPageNumber = 0;
|
fPageNumber = 0;
|
||||||
@@ -434,18 +434,18 @@ BPrintJob::CommitJob()
|
|||||||
if (fSpoolFile == NULL) {
|
if (fSpoolFile == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fPageNumber <= 0) {
|
if (fPageNumber <= 0) {
|
||||||
ShowError(kNoPagesToPrintText);
|
ShowError(kNoPagesToPrintText);
|
||||||
CancelJob();
|
CancelJob();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fCurrentPageHeader->number_of_pictures > 0) {
|
if (fCurrentPageHeader->number_of_pictures > 0) {
|
||||||
SpoolPage();
|
SpoolPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
// update spool file
|
// update spool file
|
||||||
_EndLastPage();
|
_EndLastPage();
|
||||||
|
|
||||||
// set file attributes
|
// set file attributes
|
||||||
@@ -453,14 +453,14 @@ BPrintJob::CommitJob()
|
|||||||
be_app->GetAppInfo(&appInfo);
|
be_app->GetAppInfo(&appInfo);
|
||||||
const char* printerName = "";
|
const char* printerName = "";
|
||||||
fSetupMessage->FindString(PSRV_FIELD_CURRENT_PRINTER, &printerName);
|
fSetupMessage->FindString(PSRV_FIELD_CURRENT_PRINTER, &printerName);
|
||||||
|
|
||||||
BNodeInfo info(fSpoolFile);
|
BNodeInfo info(fSpoolFile);
|
||||||
info.SetType(PSRV_SPOOL_FILETYPE);
|
info.SetType(PSRV_SPOOL_FILETYPE);
|
||||||
|
|
||||||
fSpoolFile->WriteAttr(PSRV_SPOOL_ATTR_PAGECOUNT, B_INT32_TYPE, 0, &fPageNumber, sizeof(int32));
|
fSpoolFile->WriteAttr(PSRV_SPOOL_ATTR_PAGECOUNT, B_INT32_TYPE, 0, &fPageNumber, sizeof(int32));
|
||||||
fSpoolFile->WriteAttr(PSRV_SPOOL_ATTR_DESCRIPTION, B_STRING_TYPE, 0, fPrintJobName, strlen(fPrintJobName) + 1);
|
fSpoolFile->WriteAttr(PSRV_SPOOL_ATTR_DESCRIPTION, B_STRING_TYPE, 0, fPrintJobName, strlen(fPrintJobName) + 1);
|
||||||
fSpoolFile->WriteAttr(PSRV_SPOOL_ATTR_PRINTER, B_STRING_TYPE, 0, printerName, strlen(printerName) + 1);
|
fSpoolFile->WriteAttr(PSRV_SPOOL_ATTR_PRINTER, B_STRING_TYPE, 0, printerName, strlen(printerName) + 1);
|
||||||
fSpoolFile->WriteAttr(PSRV_SPOOL_ATTR_STATUS, B_STRING_TYPE, 0, PSRV_JOB_STATUS_WAITING, strlen(PSRV_JOB_STATUS_WAITING) + 1);
|
fSpoolFile->WriteAttr(PSRV_SPOOL_ATTR_STATUS, B_STRING_TYPE, 0, PSRV_JOB_STATUS_WAITING, strlen(PSRV_JOB_STATUS_WAITING) + 1);
|
||||||
fSpoolFile->WriteAttr(PSRV_SPOOL_ATTR_MIMETYPE, B_STRING_TYPE, 0, appInfo.signature, strlen(appInfo.signature) + 1);
|
fSpoolFile->WriteAttr(PSRV_SPOOL_ATTR_MIMETYPE, B_STRING_TYPE, 0, appInfo.signature, strlen(appInfo.signature) + 1);
|
||||||
|
|
||||||
delete fSpoolFile;
|
delete fSpoolFile;
|
||||||
@@ -471,11 +471,11 @@ BPrintJob::CommitJob()
|
|||||||
BMessenger printServer;
|
BMessenger printServer;
|
||||||
if (GetPrinterServerMessenger(printServer) != B_OK) {
|
if (GetPrinterServerMessenger(printServer) != B_OK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BMessage request(PSRV_PRINT_SPOOLED_JOB);
|
BMessage request(PSRV_PRINT_SPOOLED_JOB);
|
||||||
BMessage reply;
|
BMessage reply;
|
||||||
|
|
||||||
request.AddString("JobName", fPrintJobName);
|
request.AddString("JobName", fPrintJobName);
|
||||||
request.AddString("Spool File", fSpoolFileName);
|
request.AddString("Spool File", fSpoolFileName);
|
||||||
printServer.SendMessage(&request, &reply);
|
printServer.SendMessage(&request, &reply);
|
||||||
@@ -487,7 +487,7 @@ BPrintJob::CancelJob()
|
|||||||
if (fSpoolFile == NULL) {
|
if (fSpoolFile == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fAbort = 1;
|
fAbort = 1;
|
||||||
BEntry(fSpoolFileName).Remove();
|
BEntry(fSpoolFileName).Remove();
|
||||||
delete fSpoolFile;
|
delete fSpoolFile;
|
||||||
@@ -501,13 +501,13 @@ BPrintJob::SpoolPage()
|
|||||||
if (fSpoolFile == NULL) {
|
if (fSpoolFile == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update page header
|
// update page header
|
||||||
fCurrentPageHeader->next_page = fSpoolFile->Position();
|
fCurrentPageHeader->next_page = fSpoolFile->Position();
|
||||||
fSpoolFile->Seek(fCurrentPageHeaderOffset, SEEK_SET);
|
fSpoolFile->Seek(fCurrentPageHeaderOffset, SEEK_SET);
|
||||||
fSpoolFile->Write(fCurrentPageHeader, sizeof(*fCurrentPageHeader));
|
fSpoolFile->Write(fCurrentPageHeader, sizeof(*fCurrentPageHeader));
|
||||||
fSpoolFile->Seek(0, SEEK_END);
|
fSpoolFile->Seek(0, SEEK_END);
|
||||||
|
|
||||||
fCurrentPageHeader->number_of_pictures = 0;
|
fCurrentPageHeader->number_of_pictures = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -528,11 +528,11 @@ BPrintJob::DrawView(BView *view, BRect rect, BPoint where)
|
|||||||
|
|
||||||
if (view == NULL)
|
if (view == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (view->LockLooper()) {
|
if (view->LockLooper()) {
|
||||||
BPicture picture;
|
BPicture picture;
|
||||||
_RecurseView(view, B_ORIGIN - rect.LeftTop(), &picture, rect);
|
_RecurseView(view, B_ORIGIN - rect.LeftTop(), &picture, rect);
|
||||||
_AddPicture(picture, rect, where);
|
_AddPicture(picture, rect, where);
|
||||||
view->UnlockLooper();
|
view->UnlockLooper();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -553,8 +553,8 @@ void
|
|||||||
BPrintJob::SetSettings(BMessage *message)
|
BPrintJob::SetSettings(BMessage *message)
|
||||||
{
|
{
|
||||||
if (message != NULL) {
|
if (message != NULL) {
|
||||||
_HandlePrintSetup(message);
|
_HandlePrintSetup(message);
|
||||||
}
|
}
|
||||||
delete fSetupMessage;
|
delete fSetupMessage;
|
||||||
fSetupMessage = message;
|
fSetupMessage = message;
|
||||||
}
|
}
|
||||||
@@ -567,15 +567,15 @@ BPrintJob::IsSettingsMessageValid(BMessage *message) const
|
|||||||
if (printerName == NULL) {
|
if (printerName == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
// The passed message is valid if it contains the right printer name.
|
// The passed message is valid if it contains the right printer name.
|
||||||
bool valid = message != NULL
|
bool valid = message != NULL
|
||||||
&& message->FindString("printer_name", &name) == B_OK
|
&& message->FindString("printer_name", &name) == B_OK
|
||||||
&& strcmp(printerName, name) == 0;
|
&& strcmp(printerName, name) == 0;
|
||||||
|
|
||||||
free(printerName);
|
free(printerName);
|
||||||
|
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -633,13 +633,13 @@ BPrintJob::PrinterType(void *) const
|
|||||||
BMessenger printServer;
|
BMessenger printServer;
|
||||||
if (GetPrinterServerMessenger(printServer) != B_OK) {
|
if (GetPrinterServerMessenger(printServer) != B_OK) {
|
||||||
return B_COLOR_PRINTER; // default
|
return B_COLOR_PRINTER; // default
|
||||||
}
|
}
|
||||||
|
|
||||||
BMessage message(PSRV_GET_ACTIVE_PRINTER);
|
BMessage message(PSRV_GET_ACTIVE_PRINTER);
|
||||||
BMessage reply;
|
BMessage reply;
|
||||||
|
|
||||||
printServer.SendMessage(&message, &reply);
|
printServer.SendMessage(&message, &reply);
|
||||||
|
|
||||||
int32 type;
|
int32 type;
|
||||||
if (reply.FindInt32("color", &type) != B_OK) {
|
if (reply.FindInt32("color", &type) != B_OK) {
|
||||||
return B_COLOR_PRINTER; // default
|
return B_COLOR_PRINTER; // default
|
||||||
@@ -648,18 +648,15 @@ BPrintJob::PrinterType(void *) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
#pragma mark ----- PRIVATE -----
|
// #pragma mark ----- PRIVATE -----
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BPrintJob::_RecurseView(BView *view, BPoint origin,
|
BPrintJob::_RecurseView(BView *view, BPoint origin, BPicture *picture,
|
||||||
BPicture *picture, BRect rect)
|
BRect rect)
|
||||||
{
|
{
|
||||||
ASSERT(picture != NULL);
|
ASSERT(picture != NULL);
|
||||||
// TODO: test what happens if views don't have
|
|
||||||
// the B_WILL_DRAW flag or have B_DRAW_ON_CHILDREN
|
|
||||||
|
|
||||||
view->AppendToPicture(picture);
|
view->AppendToPicture(picture);
|
||||||
view->f_is_printing = true;
|
view->f_is_printing = true;
|
||||||
@@ -669,13 +666,26 @@ BPrintJob::_RecurseView(BView *view, BPoint origin,
|
|||||||
view->PopState();
|
view->PopState();
|
||||||
view->f_is_printing = false;
|
view->f_is_printing = false;
|
||||||
view->EndPicture();
|
view->EndPicture();
|
||||||
|
|
||||||
BView *child = view->ChildAt(0);
|
BView *child = view->ChildAt(0);
|
||||||
while (child != NULL) {
|
while (child != NULL) {
|
||||||
// TODO: origin and rect should probably
|
if ((child->Flags() & B_WILL_DRAW) && !child->IsHidden()) {
|
||||||
// be converted for children views in some way
|
// TODO: origin and rect should probably
|
||||||
_RecurseView(child, origin, picture, rect);
|
// be converted for children views in some way
|
||||||
child = child->NextSibling();
|
_RecurseView(child, origin, picture, rect);
|
||||||
|
child = child->NextSibling();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (view->Flags() & B_DRAW_ON_CHILDREN) {
|
||||||
|
view->AppendToPicture(picture);
|
||||||
|
view->f_is_printing = true;
|
||||||
|
view->PushState();
|
||||||
|
view->SetOrigin(origin);
|
||||||
|
view->DrawAfterChildren(rect);
|
||||||
|
view->PopState();
|
||||||
|
view->f_is_printing = false;
|
||||||
|
view->EndPicture();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -692,7 +702,7 @@ BPrintJob::_HandlePageSetup(BMessage *setup)
|
|||||||
{
|
{
|
||||||
setup->FindRect(PSRV_FIELD_PRINTABLE_RECT, &fUsableSize);
|
setup->FindRect(PSRV_FIELD_PRINTABLE_RECT, &fUsableSize);
|
||||||
setup->FindRect(PSRV_FIELD_PAPER_RECT, &fPaperSize);
|
setup->FindRect(PSRV_FIELD_PAPER_RECT, &fPaperSize);
|
||||||
|
|
||||||
// TODO verify data type (taken from libprint)
|
// TODO verify data type (taken from libprint)
|
||||||
int64 valueInt64;
|
int64 valueInt64;
|
||||||
if (setup->FindInt64(PSRV_FIELD_XRES, &valueInt64) == B_OK) {
|
if (setup->FindInt64(PSRV_FIELD_XRES, &valueInt64) == B_OK) {
|
||||||
@@ -716,7 +726,7 @@ BPrintJob::_HandlePrintSetup(BMessage *message)
|
|||||||
if (message->FindInt32(PSRV_FIELD_LAST_PAGE, &fLastPage) != B_OK) {
|
if (message->FindInt32(PSRV_FIELD_LAST_PAGE, &fLastPage) != B_OK) {
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -731,7 +741,7 @@ BPrintJob::_NewPage()
|
|||||||
if (fPageNumber == 1)
|
if (fPageNumber == 1)
|
||||||
fCurrentHeader.first_page = fCurrentPageHeaderOffset;
|
fCurrentHeader.first_page = fCurrentPageHeaderOffset;
|
||||||
|
|
||||||
fPageNumber ++;
|
fPageNumber ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -756,7 +766,7 @@ BPrintJob::_AddPicture(BPicture &picture, BRect &rect, BPoint &where)
|
|||||||
ASSERT(fSpoolFile != NULL);
|
ASSERT(fSpoolFile != NULL);
|
||||||
|
|
||||||
if (fCurrentPageHeader->number_of_pictures == 0) {
|
if (fCurrentPageHeader->number_of_pictures == 0) {
|
||||||
_NewPage();
|
_NewPage();
|
||||||
}
|
}
|
||||||
fCurrentPageHeader->number_of_pictures ++;
|
fCurrentPageHeader->number_of_pictures ++;
|
||||||
|
|
||||||
@@ -771,17 +781,17 @@ BPrintJob::_AddPicture(BPicture &picture, BRect &rect, BPoint &where)
|
|||||||
// Caller is responsible to free the string using free().
|
// Caller is responsible to free the string using free().
|
||||||
char *
|
char *
|
||||||
BPrintJob::_GetCurrentPrinterName() const
|
BPrintJob::_GetCurrentPrinterName() const
|
||||||
{
|
{
|
||||||
BMessenger printServer;
|
BMessenger printServer;
|
||||||
if (GetPrinterServerMessenger(printServer)) {
|
if (GetPrinterServerMessenger(printServer)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
BMessage message(PSRV_GET_ACTIVE_PRINTER);
|
BMessage message(PSRV_GET_ACTIVE_PRINTER);
|
||||||
BMessage reply;
|
BMessage reply;
|
||||||
|
|
||||||
const char *printerName = NULL;
|
const char *printerName = NULL;
|
||||||
|
|
||||||
if (printServer.SendMessage(&message, &reply) == B_OK) {
|
if (printServer.SendMessage(&message, &reply) == B_OK) {
|
||||||
reply.FindString("printer_name", &printerName);
|
reply.FindString("printer_name", &printerName);
|
||||||
}
|
}
|
||||||
@@ -799,17 +809,17 @@ BPrintJob::_LoadDefaultSettings()
|
|||||||
if (GetPrinterServerMessenger(printServer) != B_OK) {
|
if (GetPrinterServerMessenger(printServer) != B_OK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BMessage message(PSRV_GET_DEFAULT_SETTINGS);
|
BMessage message(PSRV_GET_DEFAULT_SETTINGS);
|
||||||
BMessage *reply = new BMessage;
|
BMessage *reply = new BMessage;
|
||||||
|
|
||||||
printServer.SendMessage(&message, reply);
|
printServer.SendMessage(&message, reply);
|
||||||
|
|
||||||
// Only override our settings if we don't have any settings yet
|
// Only override our settings if we don't have any settings yet
|
||||||
if (fSetupMessage == NULL)
|
if (fSetupMessage == NULL)
|
||||||
_HandlePrintSetup(reply);
|
_HandlePrintSetup(reply);
|
||||||
|
|
||||||
delete fDefaultSetupMessage;
|
delete fDefaultSetupMessage;
|
||||||
fDefaultSetupMessage = reply;
|
fDefaultSetupMessage = reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user