BPrintJob: PrintableRect(), PaperRect() and GetResolution() now call
_LoadDefaultSettings() if no settings were loaded already, in order to return valid values. Renamed private methods to fit our guidelines. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23204 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -84,19 +84,19 @@ virtual void _ReservedPrintJob4();
|
|||||||
BPrintJob(const BPrintJob &);
|
BPrintJob(const BPrintJob &);
|
||||||
BPrintJob &operator=(const BPrintJob &);
|
BPrintJob &operator=(const BPrintJob &);
|
||||||
|
|
||||||
void RecurseView(BView *v, BPoint origin, BPicture *p, BRect r);
|
void _RecurseView(BView *view, BPoint origin, BPicture *p, BRect r);
|
||||||
void MangleName(char *filename);
|
void _GetMangledName(char *buffer, size_t bufferSize) const;
|
||||||
void HandlePageSetup(BMessage *setup);
|
void _HandlePageSetup(BMessage *setup);
|
||||||
bool HandlePrintSetup(BMessage *setup);
|
bool _HandlePrintSetup(BMessage *setup);
|
||||||
|
|
||||||
void NewPage();
|
void _NewPage();
|
||||||
void EndLastPage();
|
void _EndLastPage();
|
||||||
|
|
||||||
void AddSetupSpec();
|
void _AddSetupSpec();
|
||||||
void AddPicture(BPicture *picture, BRect *rect, BPoint where);
|
void _AddPicture(BPicture &picture, BRect &rect, BPoint &where);
|
||||||
|
|
||||||
char* GetCurrentPrinterName() const;
|
char* _GetCurrentPrinterName() const;
|
||||||
void LoadDefaultSettings();
|
void _LoadDefaultSettings();
|
||||||
|
|
||||||
char * fPrintJobName;
|
char * fPrintJobName;
|
||||||
int32 fPageNumber;
|
int32 fPageNumber;
|
||||||
|
|||||||
@@ -251,19 +251,10 @@ BPrintJob::~BPrintJob()
|
|||||||
{
|
{
|
||||||
CancelJob();
|
CancelJob();
|
||||||
|
|
||||||
if (fPrintJobName != NULL) {
|
free(fPrintJobName);
|
||||||
free(fPrintJobName);
|
|
||||||
fPrintJobName = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete fDefaultSetupMessage;
|
|
||||||
fDefaultSetupMessage = NULL;
|
|
||||||
|
|
||||||
delete fSetupMessage;
|
delete fSetupMessage;
|
||||||
fSetupMessage = NULL;
|
delete fDefaultSetupMessage;
|
||||||
|
|
||||||
delete fCurrentPageHeader;
|
delete fCurrentPageHeader;
|
||||||
fCurrentPageHeader = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -307,7 +298,7 @@ BPrintJob::ConfigPage()
|
|||||||
return status;
|
return status;
|
||||||
delete fSetupMessage;
|
delete fSetupMessage;
|
||||||
fSetupMessage = configuration.Result();
|
fSetupMessage = configuration.Result();
|
||||||
HandlePageSetup(fSetupMessage);
|
_HandlePageSetup(fSetupMessage);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,7 +342,7 @@ BPrintJob::ConfigJob()
|
|||||||
return status;
|
return status;
|
||||||
delete fSetupMessage;
|
delete fSetupMessage;
|
||||||
fSetupMessage = configuration.Result();
|
fSetupMessage = configuration.Result();
|
||||||
HandlePrintSetup(fSetupMessage);
|
_HandlePrintSetup(fSetupMessage);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -378,7 +369,7 @@ BPrintJob::BeginJob()
|
|||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
char *printer = GetCurrentPrinterName();
|
char *printer = _GetCurrentPrinterName();
|
||||||
if (printer == NULL)
|
if (printer == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -386,7 +377,7 @@ BPrintJob::BeginJob()
|
|||||||
free(printer);
|
free(printer);
|
||||||
|
|
||||||
char mangledName[B_FILE_NAME_LENGTH];
|
char mangledName[B_FILE_NAME_LENGTH];
|
||||||
MangleName(mangledName);
|
_GetMangledName(mangledName, B_FILE_NAME_LENGTH);
|
||||||
|
|
||||||
path.Append(mangledName);
|
path.Append(mangledName);
|
||||||
|
|
||||||
@@ -415,7 +406,7 @@ BPrintJob::BeginJob()
|
|||||||
// 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()
|
||||||
@@ -449,7 +440,7 @@ BPrintJob::CommitJob()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update spool file
|
// update spool file
|
||||||
EndLastPage();
|
_EndLastPage();
|
||||||
|
|
||||||
// set file attributes
|
// set file attributes
|
||||||
app_info appInfo;
|
app_info appInfo;
|
||||||
@@ -534,8 +525,8 @@ BPrintJob::DrawView(BView *view, BRect rect, BPoint where)
|
|||||||
|
|
||||||
if (view->LockLooper()) {
|
if (view->LockLooper()) {
|
||||||
BPicture picture;
|
BPicture picture;
|
||||||
RecurseView(view, where, &picture, rect);
|
_RecurseView(view, where, &picture, rect);
|
||||||
AddPicture(&picture, &rect, where);
|
_AddPicture(picture, rect, where);
|
||||||
view->UnlockLooper();
|
view->UnlockLooper();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -556,7 +547,7 @@ 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;
|
||||||
@@ -566,7 +557,7 @@ BPrintJob::SetSettings(BMessage *message)
|
|||||||
bool
|
bool
|
||||||
BPrintJob::IsSettingsMessageValid(BMessage *message) const
|
BPrintJob::IsSettingsMessageValid(BMessage *message) const
|
||||||
{
|
{
|
||||||
char *printerName = GetCurrentPrinterName();
|
char *printerName = _GetCurrentPrinterName();
|
||||||
if (printerName == NULL) {
|
if (printerName == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -588,6 +579,8 @@ BPrintJob::IsSettingsMessageValid(BMessage *message) const
|
|||||||
BRect
|
BRect
|
||||||
BPrintJob::PaperRect()
|
BPrintJob::PaperRect()
|
||||||
{
|
{
|
||||||
|
if (fDefaultSetupMessage == NULL)
|
||||||
|
_LoadDefaultSettings();
|
||||||
return fPaperSize;
|
return fPaperSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -595,6 +588,8 @@ BPrintJob::PaperRect()
|
|||||||
BRect
|
BRect
|
||||||
BPrintJob::PrintableRect()
|
BPrintJob::PrintableRect()
|
||||||
{
|
{
|
||||||
|
if (fDefaultSetupMessage == NULL)
|
||||||
|
_LoadDefaultSettings();
|
||||||
return fUsableSize;
|
return fUsableSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -602,12 +597,13 @@ BPrintJob::PrintableRect()
|
|||||||
void
|
void
|
||||||
BPrintJob::GetResolution(int32 *xdpi, int32 *ydpi)
|
BPrintJob::GetResolution(int32 *xdpi, int32 *ydpi)
|
||||||
{
|
{
|
||||||
if (xdpi != NULL) {
|
if (fDefaultSetupMessage == NULL)
|
||||||
|
_LoadDefaultSettings();
|
||||||
|
|
||||||
|
if (xdpi != NULL)
|
||||||
*xdpi = fXResolution;
|
*xdpi = fXResolution;
|
||||||
}
|
if (ydpi != NULL)
|
||||||
if (ydpi != NULL) {
|
|
||||||
*ydpi = fYResolution;
|
*ydpi = fYResolution;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -652,7 +648,7 @@ BPrintJob::PrinterType(void *) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BPrintJob::RecurseView(BView *view, BPoint origin,
|
BPrintJob::_RecurseView(BView *view, BPoint origin,
|
||||||
BPicture *picture, BRect rect)
|
BPicture *picture, BRect rect)
|
||||||
{
|
{
|
||||||
ASSERT(picture != NULL);
|
ASSERT(picture != NULL);
|
||||||
@@ -671,24 +667,21 @@ BPrintJob::RecurseView(BView *view, BPoint origin,
|
|||||||
while (child != NULL) {
|
while (child != NULL) {
|
||||||
// TODO: origin and rect should probably
|
// TODO: origin and rect should probably
|
||||||
// be converted for children views in some way
|
// be converted for children views in some way
|
||||||
RecurseView(child, origin, picture, rect);
|
_RecurseView(child, origin, picture, rect);
|
||||||
child = child->NextSibling();
|
child = child->NextSibling();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BPrintJob::MangleName(char *filename)
|
BPrintJob::_GetMangledName(char *buffer, size_t bufferSize) const
|
||||||
{
|
{
|
||||||
char sysTime[10];
|
snprintf(buffer, bufferSize, "%s@%lld", fPrintJobName, system_time() / 1000);
|
||||||
snprintf(sysTime, sizeof(sysTime), "@%lld", system_time() / 1000);
|
|
||||||
strncpy(filename, fPrintJobName, B_FILE_NAME_LENGTH - sizeof(sysTime));
|
|
||||||
strcat(filename, sysTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BPrintJob::HandlePageSetup(BMessage *setup)
|
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);
|
||||||
@@ -705,9 +698,9 @@ BPrintJob::HandlePageSetup(BMessage *setup)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BPrintJob::HandlePrintSetup(BMessage *message)
|
BPrintJob::_HandlePrintSetup(BMessage *message)
|
||||||
{
|
{
|
||||||
HandlePageSetup(message);
|
_HandlePageSetup(message);
|
||||||
|
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
if (message->FindInt32(PSRV_FIELD_FIRST_PAGE, &fFirstPage) != B_OK) {
|
if (message->FindInt32(PSRV_FIELD_FIRST_PAGE, &fFirstPage) != B_OK) {
|
||||||
@@ -722,7 +715,7 @@ BPrintJob::HandlePrintSetup(BMessage *message)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BPrintJob::NewPage()
|
BPrintJob::_NewPage()
|
||||||
{
|
{
|
||||||
// write page header
|
// write page header
|
||||||
fCurrentPageHeaderOffset = fSpoolFile->Position();
|
fCurrentPageHeaderOffset = fSpoolFile->Position();
|
||||||
@@ -736,7 +729,7 @@ BPrintJob::NewPage()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BPrintJob::EndLastPage()
|
BPrintJob::_EndLastPage()
|
||||||
{
|
{
|
||||||
fSpoolFile->Seek(0, SEEK_SET);
|
fSpoolFile->Seek(0, SEEK_SET);
|
||||||
fCurrentHeader.page_count = fPageNumber;
|
fCurrentHeader.page_count = fPageNumber;
|
||||||
@@ -744,27 +737,25 @@ BPrintJob::EndLastPage()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BPrintJob::AddSetupSpec()
|
BPrintJob::_AddSetupSpec()
|
||||||
{
|
{
|
||||||
fSetupMessage->Flatten(fSpoolFile);
|
fSetupMessage->Flatten(fSpoolFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BPrintJob::AddPicture(BPicture *picture, BRect *rect, BPoint where)
|
BPrintJob::_AddPicture(BPicture &picture, BRect &rect, BPoint &where)
|
||||||
{
|
{
|
||||||
ASSERT(picture != NULL);
|
|
||||||
ASSERT(fSpoolFile != NULL);
|
ASSERT(fSpoolFile != NULL);
|
||||||
ASSERT(rect != NULL);
|
|
||||||
|
|
||||||
if (fCurrentPageHeader->number_of_pictures == 0) {
|
if (fCurrentPageHeader->number_of_pictures == 0) {
|
||||||
NewPage();
|
_NewPage();
|
||||||
}
|
}
|
||||||
fCurrentPageHeader->number_of_pictures ++;
|
fCurrentPageHeader->number_of_pictures ++;
|
||||||
|
|
||||||
fSpoolFile->Write(&where, sizeof(where));
|
fSpoolFile->Write(&where, sizeof(where));
|
||||||
fSpoolFile->Write(rect, sizeof(*rect));
|
fSpoolFile->Write(&rect, sizeof(rect));
|
||||||
picture->Flatten(fSpoolFile);
|
picture.Flatten(fSpoolFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -772,7 +763,7 @@ BPrintJob::AddPicture(BPicture *picture, BRect *rect, BPoint where)
|
|||||||
// or NULL if it ccould not be obtained.
|
// or NULL if it ccould not be obtained.
|
||||||
// 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)) {
|
||||||
@@ -795,7 +786,7 @@ BPrintJob::GetCurrentPrinterName() const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BPrintJob::LoadDefaultSettings()
|
BPrintJob::_LoadDefaultSettings()
|
||||||
{
|
{
|
||||||
BMessenger printServer;
|
BMessenger printServer;
|
||||||
if (GetPrinterServerMessenger(printServer) != B_OK) {
|
if (GetPrinterServerMessenger(printServer) != B_OK) {
|
||||||
@@ -807,7 +798,7 @@ BPrintJob::LoadDefaultSettings()
|
|||||||
|
|
||||||
printServer.SendMessage(&message, reply);
|
printServer.SendMessage(&message, reply);
|
||||||
|
|
||||||
HandlePrintSetup(reply);
|
_HandlePrintSetup(reply);
|
||||||
|
|
||||||
delete fDefaultSetupMessage;
|
delete fDefaultSetupMessage;
|
||||||
fDefaultSetupMessage = reply;
|
fDefaultSetupMessage = reply;
|
||||||
|
|||||||
Reference in New Issue
Block a user