* Cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34445 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-12-02 13:27:04 +00:00
parent 969279e36c
commit e90df81946
+78 -74
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2001-2008, Haiku.
* Copyright 2001-2009, Haiku.
* Distributed under the terms of the MIT license.
*
* Authors:
@@ -9,6 +9,13 @@
* julun <[email protected]>
*/
#include <PrintJob.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Alert.h>
#include <Application.h>
#include <Button.h>
@@ -20,68 +27,58 @@
#include <NodeInfo.h>
#include <OS.h>
#include <Path.h>
#include <PrintJob.h>
#include <Region.h>
#include <Roster.h>
#include <View.h>
#include <pr_server.h>
#include <ViewPrivate.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*! Summary of spool file:
|-----------------------------------|
| print_file_header |
|-----------------------------------|
| BMessage print_job_settings |
|-----------------------------------|
| |
| ********** (first page) ********* |
| * * |
| * _page_header_ * |
| * ----------------------------- * |
| * |---------------------------| * |
| * | BPoint where | * |
| * | BRect bounds | * |
| * | BPicture pic | * |
| * |---------------------------| * |
| * |---------------------------| * |
| * | BPoint where | * |
| * | BRect bounds | * |
| * | BPicture pic | * |
| * |---------------------------| * |
| ********************************* |
| |
| ********* (second page) ********* |
| * * |
| * _page_header_ * |
| * ----------------------------- * |
| * |---------------------------| * |
| * | BPoint where | * |
| * | BRect bounds | * |
| * | BPicture pic | * |
| * |---------------------------| * |
| ********************************* |
|-----------------------------------|
/* !
*
* Summery of R5 spool file:
*
* |-----------------------------------|
* | print_file_header |
* |-----------------------------------|
* | BMessage print_job_settings |
* |-----------------------------------|
* | |
* | ********** (first page) ********* |
* | * * |
* | * _page_header_ * |
* | * ----------------------------- * |
* | * |---------------------------| * |
* | * | BPoint where | * |
* | * | BRect bounds | * |
* | * | BPicture pic | * |
* | * |---------------------------| * |
* | * |---------------------------| * |
* | * | BPoint where | * |
* | * | BRect bounds | * |
* | * | BPicture pic | * |
* | * |---------------------------| * |
* | ********************************* |
* | |
* | ********* (second page) ********* |
* | * * |
* | * _page_header_ * |
* | * ----------------------------- * |
* | * |---------------------------| * |
* | * | BPoint where | * |
* | * | BRect bounds | * |
* | * | BPicture pic | * |
* | * |---------------------------| * |
* | ********************************* |
* |-----------------------------------|
*
* BeOS R5 print_file_header.version is 1 << 16
* BeOS R5 print_file_header.first_page is -1
*
* each page can consist of a collection of picture structures
* remaining pages start at _page_header_.next_page of previous _page_header_
*
* See also: "How to Write a BeOS R5 Printer Driver" for description of spool
* file format: http://haiku-os.org/documents/dev/how_to_write_a_printer_driver
*
BeOS R5 print_file_header.version is 1 << 16
BeOS R5 print_file_header.first_page is -1
each page can consist of a collection of picture structures
remaining pages start at _page_header_.next_page of previous _page_header_
See also: "How to Write a BeOS R5 Printer Driver" for description of spool
file format: http://haiku-os.org/documents/dev/how_to_write_a_printer_driver
*/
@@ -117,7 +114,7 @@ namespace BPrivate {
void SetResult(BMessage* result);
BMessage* Result() const { return fResult; }
static status_t GetPrintServerMessenger(BMessenger& msngr);
static status_t GetPrintServerMessenger(BMessenger& messenger);
private:
void RejectUserInput();
@@ -135,14 +132,17 @@ namespace BPrivate {
} // namespace BPrivate
using namespace BPrivate;
// #pragma mark -- BPrintJob
BPrintJob::BPrintJob(const char *job_name)
: fPrintJobName(NULL),
BPrintJob::BPrintJob(const char* jobName)
:
fPrintJobName(NULL),
fSpoolFile(NULL),
fError(B_ERROR),
fSetupMessage(NULL),
@@ -151,8 +151,8 @@ BPrintJob::BPrintJob(const char *job_name)
{
memset(&fSpoolFileHeader, 0, sizeof(print_file_header));
if (job_name != NULL)
fPrintJobName = strdup(job_name);
if (jobName != NULL && jobName[0])
fPrintJobName = strdup(jobName);
fCurrentPageHeader = new _page_header_;
if (fCurrentPageHeader != NULL)
@@ -235,7 +235,8 @@ BPrintJob::BeginJob()
if (path.InitCheck() != B_OK)
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));
fSpoolFile = new BFile(fSpoolFileName, B_READ_WRITE | B_CREATE_FILE);
@@ -302,8 +303,8 @@ BPrintJob::CommitJob()
&fSpoolFileHeader.page_count, sizeof(int32));
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_MIMETYPE, B_STRING_TYPE, 0,
@@ -326,6 +327,7 @@ BPrintJob::CommitJob()
printServer.SendMessage(&request, &reply);
}
void
BPrintJob::CancelJob()
{
@@ -496,8 +498,7 @@ BPrintJob::PrinterType(void *) const
}
// #pragma mark ----- PRIVATE -----
// #pragma mark - private
void
@@ -533,14 +534,15 @@ BPrintJob::_RecurseView(BView *view, BPoint origin, BPicture *picture,
while (child != NULL) {
if ((child->Flags() & B_WILL_DRAW) && !child->IsHidden()) {
BPoint leftTop(view->Bounds().LeftTop() + child->Frame().LeftTop());
BRect printRect(rect.OffsetToCopy(rect.LeftTop() - leftTop) & child->Bounds());
BRect printRect(rect.OffsetToCopy(rect.LeftTop() - leftTop)
& child->Bounds());
if (printRect.IsValid())
_RecurseView(child, origin + leftTop, picture, printRect);
}
child = child->NextSibling();
}
if (view->Flags() & B_DRAW_ON_CHILDREN) {
if ((view->Flags() & B_DRAW_ON_CHILDREN) != 0) {
view->AppendToPicture(picture);
view->PushState();
view->SetOrigin(origin);
@@ -557,7 +559,8 @@ BPrintJob::_RecurseView(BView *view, BPoint origin, BPicture *picture,
void
BPrintJob::_GetMangledName(char* buffer, size_t bufferSize) const
{
snprintf(buffer, bufferSize, "%s@%lld", fPrintJobName, system_time() / 1000);
snprintf(buffer, bufferSize, "%s@%lld", fPrintJobName,
system_time() / 1000);
}
@@ -642,11 +645,10 @@ BPrintJob::_AddPicture(BPicture &picture, BRect &rect, BPoint &where)
picture.Flatten(fSpoolFile);
}
/* !
*
* Returns a copy of the applications default printer name or NULL if it
* could not be obtained. Caller is responsible to free the string using free().
*
/*! Returns a copy of the applications default printer name or NULL if it
could not be obtained. Caller is responsible to free the string using
free().
*/
char*
BPrintJob::_GetCurrentPrinterName() const
@@ -703,7 +705,8 @@ namespace BPrivate {
PrintServerMessenger::PrintServerMessenger(uint32 what, BMessage *input)
: fWhat(what),
:
fWhat(what),
fInput(input),
fRequest(NULL),
fResult(NULL),
@@ -766,8 +769,9 @@ namespace BPrivate {
return B_ERROR;
// Get the originating window, if it exists
BWindow* window = dynamic_cast<BWindow*>(BLooper::LooperForThread(find_thread(NULL)));
if (window) {
BWindow* window = dynamic_cast<BWindow*>(
BLooper::LooperForThread(find_thread(NULL)));
if (window != NULL) {
status_t err;
while (true) {
do {