Do the same for the JobSetupWindow and PrinterSetupWindow's Go()

methods too.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38846 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin
2010-09-29 09:54:22 +00:00
parent fd7d3a7d40
commit 4cc17e8c78
2 changed files with 80 additions and 68 deletions
@@ -2,13 +2,13 @@
PDF Writer printer driver. PDF Writer printer driver.
Copyright (c) 2001-2003 OpenBeOS. Copyright (c) 2001-2003 OpenBeOS.
Authors: Authors:
Philippe Houdoin Philippe Houdoin
Simon Gauvin Simon Gauvin
Michael Pfeiffer Michael Pfeiffer
Permission is hereby granted, free of charge, to any person obtaining a copy of 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 this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to the Software without restriction, including without limitation the rights to
@@ -40,9 +40,9 @@ THE SOFTWARE.
#include "DocInfoWindow.h" #include "DocInfoWindow.h"
static const char* includeKeys[] = { static const char* includeKeys[] = {
"doc_info", "doc_info",
#if HAVE_FULLVERSION_PDF_LIB #if HAVE_FULLVERSION_PDF_LIB
"master_password", "user_password", "permissions", "master_password", "user_password", "permissions",
#endif #endif
NULL NULL
}; };
@@ -56,14 +56,14 @@ JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName)
fSetupMsg = msg; fSetupMsg = msg;
fExitSem = create_sem(0, "JobSetup"); fExitSem = create_sem(0, "JobSetup");
fResult = B_ERROR; fResult = B_ERROR;
if (printerName) { if (printerName) {
BString title; BString title;
title << printerName << " Job Setup"; title << printerName << " Job Setup";
SetTitle(title.String()); SetTitle(title.String());
fPrinterName = printerName; fPrinterName = printerName;
} }
// ---- Ok, build a default job setup user interface // ---- Ok, build a default job setup user interface
BRect r; BRect r;
BBox *panel; BBox *panel;
@@ -78,7 +78,7 @@ JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName)
int32 lastPage; int32 lastPage;
bool allPages; bool allPages;
char buffer[80]; char buffer[80];
// PrinterDriver ensures that property exists // PrinterDriver ensures that property exists
fSetupMsg->FindInt32("copies", &copies); fSetupMsg->FindInt32("copies", &copies);
fSetupMsg->FindInt32("first_page", &firstPage); fSetupMsg->FindInt32("first_page", &firstPage);
@@ -92,13 +92,13 @@ JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName)
fSetupMsg->AddMessage("doc_info", &doc_info); fSetupMsg->AddMessage("doc_info", &doc_info);
} }
AddFields(&fDocInfo, fSetupMsg, NULL, includeKeys); AddFields(&fDocInfo, fSetupMsg, NULL, includeKeys);
allPages = firstPage == 1 && lastPage == MAX_INT32; allPages = firstPage == 1 && lastPage == MAX_INT32;
r = Bounds(); r = Bounds();
// add a *dialog* background // add a *dialog* background
panel = new BBox(r, "top_panel", B_FOLLOW_ALL, panel = new BBox(r, "top_panel", B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
B_PLAIN_BORDER); B_PLAIN_BORDER);
@@ -118,8 +118,8 @@ JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName)
x = r.left + kMargin; x = r.left + kMargin;
y = r.top + kMargin; y = r.top + kMargin;
// add a "copies" input field // add a "copies" input field
/* Simon: temporarily removed this code /* Simon: temporarily removed this code
@@ -130,7 +130,7 @@ JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName)
fCopies->ResizeToPreferred(); fCopies->ResizeToPreferred();
fCopies->GetPreferredSize(&w, &h); fCopies->GetPreferredSize(&w, &h);
panel->AddChild(fCopies); panel->AddChild(fCopies);
y += h + kMargin; // "new line" y += h + kMargin; // "new line"
*/ */
// add a "pages" label // add a "pages" label
@@ -167,9 +167,9 @@ JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName)
panel->AddChild(fRange); panel->AddChild(fRange);
x += w + kMargin; x += w + kMargin;
// add a "from" field // add a "from" field
if (allPages) { if (allPages) {
buffer[0] = 0; buffer[0] = 0;
} else { } else {
sprintf(buffer, "%d", (int)firstPage); sprintf(buffer, "%d", (int)firstPage);
@@ -183,13 +183,13 @@ JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName)
panel->AddChild(fFrom); panel->AddChild(fFrom);
x += w + kMargin; x += w + kMargin;
// add a "to" field // add a "to" field
if (allPages) { if (allPages) {
buffer[0] = 0; buffer[0] = 0;
} else { } else {
sprintf(buffer, "%d", (int)lastPage); sprintf(buffer, "%d", (int)lastPage);
} }
fTo = new BTextControl(BRect(x, y, x+100, y+20), "to_field", kToLabel, buffer, fTo = new BTextControl(BRect(x, y, x+100, y+20), "to_field", kToLabel, buffer,
new BMessage(RANGE_TO_MSG)); new BMessage(RANGE_TO_MSG));
fTo->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT); fTo->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT);
@@ -217,15 +217,15 @@ JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName)
ok->MoveTo(x, ok->Frame().top); // put the ok bottom at bottom right corner ok->MoveTo(x, ok->Frame().top); // put the ok bottom at bottom right corner
panel->AddChild(ok); panel->AddChild(ok);
// add a "Cancel" button // add a "Cancel" button
cancel = new BButton(BRect(x, y, x + 100, y + 20), NULL, "Cancel", new BMessage(CANCEL_MSG), B_FOLLOW_RIGHT | B_FOLLOW_TOP); cancel = new BButton(BRect(x, y, x + 100, y + 20), NULL, "Cancel", new BMessage(CANCEL_MSG), B_FOLLOW_RIGHT | B_FOLLOW_TOP);
cancel->ResizeToPreferred(); cancel->ResizeToPreferred();
cancel->GetPreferredSize(&w, &h); cancel->GetPreferredSize(&w, &h);
cancel->MoveTo(x - w - kMargin, y); // put cancel button left next the ok button cancel->MoveTo(x - w - kMargin, y); // put cancel button left next the ok button
panel->AddChild(cancel); panel->AddChild(cancel);
// add a "DocInfo" button // add a "DocInfo" button
BButton *button = new BButton(r, NULL, "Doc Info", new BMessage(DOC_INFO_MSG), BButton *button = new BButton(r, NULL, "Doc Info", new BMessage(DOC_INFO_MSG),
B_FOLLOW_RIGHT | B_FOLLOW_TOP); B_FOLLOW_RIGHT | B_FOLLOW_TOP);
button->GetPreferredSize(&w, &h); button->GetPreferredSize(&w, &h);
button->ResizeToPreferred(); button->ResizeToPreferred();
@@ -234,15 +234,15 @@ JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName)
// Finally, add our panel to window // Finally, add our panel to window
AddChild(panel); AddChild(panel);
// Auto resize window // Auto resize window
ResizeTo(ok->Frame().right + kMargin, ok->Frame().bottom + kMargin); ResizeTo(ok->Frame().right + kMargin, ok->Frame().bottom + kMargin);
} }
// -------------------------------------------------- // --------------------------------------------------
void void
JobSetupWindow::UpdateJobMessage() JobSetupWindow::UpdateJobMessage()
{ {
int32 copies = 1; int32 copies = 1;
@@ -272,7 +272,7 @@ JobSetupWindow::~JobSetupWindow()
// -------------------------------------------------- // --------------------------------------------------
bool bool
JobSetupWindow::QuitRequested() JobSetupWindow::QuitRequested()
{ {
release_sem(fExitSem); release_sem(fExitSem);
@@ -281,7 +281,7 @@ JobSetupWindow::QuitRequested()
// -------------------------------------------------- // --------------------------------------------------
void void
JobSetupWindow::MessageReceived(BMessage *msg) JobSetupWindow::MessageReceived(BMessage *msg)
{ {
switch (msg->what) { switch (msg->what) {
@@ -290,7 +290,7 @@ JobSetupWindow::MessageReceived(BMessage *msg)
fResult = B_OK; fResult = B_OK;
release_sem(fExitSem); release_sem(fExitSem);
break; break;
case CANCEL_MSG: case CANCEL_MSG:
release_sem(fExitSem); release_sem(fExitSem);
break; break;
@@ -309,17 +309,24 @@ JobSetupWindow::MessageReceived(BMessage *msg)
break; break;
} }
} }
// -------------------------------------------------- // --------------------------------------------------
status_t status_t
JobSetupWindow::Go() JobSetupWindow::Go()
{ {
MoveTo(300,300); MoveTo(300,300);
Show(); Show();
acquire_sem(fExitSem);
if (Lock()) Quit(); while (acquire_sem(fExitSem) == B_INTERRUPTED) {
return fResult; }
// Cache the value as after Quit() this object is deleted.
status_t result = fResult;
if (Lock())
Quit();
return result;
} }
@@ -2,13 +2,13 @@
PDF Writer printer driver. PDF Writer printer driver.
Copyright (c) 2001 OpenBeOS. Copyright (c) 2001 OpenBeOS.
Authors: Authors:
Philippe Houdoin Philippe Houdoin
Simon Gauvin Simon Gauvin
Michael Pfeiffer Michael Pfeiffer
Permission is hereby granted, free of charge, to any person obtaining a copy of 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 this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to the Software without restriction, including without limitation the rights to
@@ -50,17 +50,17 @@ PrinterSetupWindow::PrinterSetupWindow(char *printerName)
SetTitle(title.String()); SetTitle(title.String());
} else } else
SetTitle("Printer Setup"); SetTitle("Printer Setup");
// ---- Ok, build a default job setup user interface // ---- Ok, build a default job setup user interface
BRect r; BRect r;
BButton *button; BButton *button;
float x, y, w, h; float x, y, w, h;
font_height fh; font_height fh;
r = Bounds(); r = Bounds();
// add a *dialog* background // add a *dialog* background
BBox *panel = new BBox(r, "top_panel", B_FOLLOW_ALL, BBox *panel = new BBox(r, "top_panel", B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
B_PLAIN_BORDER); B_PLAIN_BORDER);
@@ -80,22 +80,22 @@ PrinterSetupWindow::PrinterSetupWindow(char *printerName)
w = Bounds().Width(); w = Bounds().Width();
w -= 2 * kHorzMargin; w -= 2 * kHorzMargin;
h = 150; h = 150;
BBox * model_group = new BBox(BRect(x, y, x+w, y+h), "model_group", B_FOLLOW_ALL_SIDES); BBox * model_group = new BBox(BRect(x, y, x+w, y+h), "model_group", B_FOLLOW_ALL_SIDES);
model_group->SetLabel(kModelLabel); model_group->SetLabel(kModelLabel);
BRect rlv = model_group->Bounds(); BRect rlv = model_group->Bounds();
rlv.InsetBy(kHorzMargin, kVertMargin); rlv.InsetBy(kHorzMargin, kVertMargin);
rlv.top += fh.ascent + fh.descent + fh.leading; rlv.top += fh.ascent + fh.descent + fh.leading;
rlv.right -= B_V_SCROLL_BAR_WIDTH; rlv.right -= B_V_SCROLL_BAR_WIDTH;
fModelList = new BListView(rlv, "model_list", fModelList = new BListView(rlv, "model_list",
B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL_SIDES ); B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL_SIDES );
BScrollView * sv = new BScrollView( "model_list_scrollview", fModelList, BScrollView * sv = new BScrollView( "model_list_scrollview", fModelList,
B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS, false, true ); B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS, false, true );
model_group->AddChild(sv); model_group->AddChild(sv);
panel->AddChild(model_group); panel->AddChild(model_group);
y += (h + kInterSpace); y += (h + kInterSpace);
@@ -115,7 +115,7 @@ PrinterSetupWindow::PrinterSetupWindow(char *printerName)
x -= kInterSpace; x -= kInterSpace;
// add a "Cancel" button // add a "Cancel" button
button = new BButton(BRect(x, y, x + 400, y), NULL, "Cancel", new BMessage(CANCEL_MSG), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); button = new BButton(BRect(x, y, x + 400, y), NULL, "Cancel", new BMessage(CANCEL_MSG), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
button->ResizeToPreferred(); button->ResizeToPreferred();
button->GetPreferredSize(&w, &h); button->GetPreferredSize(&w, &h);
@@ -127,7 +127,7 @@ PrinterSetupWindow::PrinterSetupWindow(char *printerName)
panel->ResizeTo(Bounds().Width(), y); panel->ResizeTo(Bounds().Width(), y);
ResizeTo(Bounds().Width(), y); ResizeTo(Bounds().Width(), y);
float minWidth, maxWidth, minHeight, maxHeight; float minWidth, maxWidth, minHeight, maxHeight;
GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight); GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight);
@@ -139,11 +139,11 @@ PrinterSetupWindow::PrinterSetupWindow(char *printerName)
BDirectory Folder; BDirectory Folder;
BEntry entry; BEntry entry;
Folder.SetTo ("/boot/beos/etc/bubblejet"); Folder.SetTo ("/boot/beos/etc/bubblejet");
if (Folder.InitCheck() != B_OK) if (Folder.InitCheck() != B_OK)
return; return;
while (Folder.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) { while (Folder.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) {
char name[B_FILE_NAME_LENGTH]; char name[B_FILE_NAME_LENGTH];
if (entry.GetName(name) == B_NO_ERROR) if (entry.GetName(name) == B_NO_ERROR)
@@ -163,7 +163,7 @@ PrinterSetupWindow::~PrinterSetupWindow()
// -------------------------------------------------- // --------------------------------------------------
bool bool
PrinterSetupWindow::QuitRequested() PrinterSetupWindow::QuitRequested()
{ {
release_sem(fExitSem); release_sem(fExitSem);
@@ -172,7 +172,7 @@ PrinterSetupWindow::QuitRequested()
// -------------------------------------------------- // --------------------------------------------------
void void
PrinterSetupWindow::MessageReceived(BMessage *msg) PrinterSetupWindow::MessageReceived(BMessage *msg)
{ {
switch (msg->what) { switch (msg->what) {
@@ -181,48 +181,48 @@ PrinterSetupWindow::MessageReceived(BMessage *msg)
// Test model selection (if any), save it in printerName node and return // Test model selection (if any), save it in printerName node and return
BNode spoolDir; BNode spoolDir;
BPath * path; BPath * path;
if (fModelList->CurrentSelection() < 0) if (fModelList->CurrentSelection() < 0)
break; break;
BStringItem * item = dynamic_cast<BStringItem*> BStringItem * item = dynamic_cast<BStringItem*>
(fModelList->ItemAt(fModelList->CurrentSelection())); (fModelList->ItemAt(fModelList->CurrentSelection()));
if (!item) if (!item)
break; break;
path = new BPath(); path = new BPath();
find_directory(B_USER_SETTINGS_DIRECTORY, path); find_directory(B_USER_SETTINGS_DIRECTORY, path);
path->Append("printers"); path->Append("printers");
path->Append(fPrinterName); path->Append(fPrinterName);
spoolDir.SetTo(path->Path()); spoolDir.SetTo(path->Path());
delete path; delete path;
if (spoolDir.InitCheck() != B_OK) { if (spoolDir.InitCheck() != B_OK) {
BAlert * alert = new BAlert("Uh oh!", BAlert * alert = new BAlert("Uh oh!",
"Couldn't find printer spool directory.", "OK"); "Couldn't find printer spool directory.", "OK");
alert->Go(); alert->Go();
} else { } else {
spoolDir.WriteAttr("printer_model", B_STRING_TYPE, 0, item->Text(), spoolDir.WriteAttr("printer_model", B_STRING_TYPE, 0, item->Text(),
strlen(item->Text())); strlen(item->Text()));
fResult = B_OK; fResult = B_OK;
} }
release_sem(fExitSem); release_sem(fExitSem);
break; break;
} }
case CANCEL_MSG: case CANCEL_MSG:
fResult = B_ERROR; fResult = B_ERROR;
release_sem(fExitSem); release_sem(fExitSem);
break; break;
case MODEL_MSG: case MODEL_MSG:
fOkButton->SetEnabled((fModelList->CurrentSelection() >= 0)); fOkButton->SetEnabled((fModelList->CurrentSelection() >= 0));
break; break;
default: default:
inherited::MessageReceived(msg); inherited::MessageReceived(msg);
break; break;
@@ -231,14 +231,19 @@ PrinterSetupWindow::MessageReceived(BMessage *msg)
// -------------------------------------------------- // --------------------------------------------------
status_t status_t
PrinterSetupWindow::Go() PrinterSetupWindow::Go()
{ {
MoveTo(300, 300); MoveTo(300, 300);
Show(); Show();
acquire_sem(fExitSem);
Lock();
Quit();
return fResult; while (acquire_sem(fExitSem) == B_INTERRUPTED) {
}
// cache the value as after Quit() this object is deleted
status_t result = fResult;
if (Lock())
Quit();
return result;
} }