WIP: add a print test page button.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40216 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -21,5 +21,6 @@ const uint32 kMsgPrinterSelected = 'PSel';
|
|||||||
const uint32 kMsgCancelJob = 'CncJ';
|
const uint32 kMsgCancelJob = 'CncJ';
|
||||||
const uint32 kMsgRestartJob = 'RstJ';
|
const uint32 kMsgRestartJob = 'RstJ';
|
||||||
const uint32 kMsgJobSelected = 'JSel';
|
const uint32 kMsgJobSelected = 'JSel';
|
||||||
|
const uint32 kMsgPrintTestPage = 'PtPg';
|
||||||
|
|
||||||
#endif // _MESSAGES_H
|
#endif // _MESSAGES_H
|
||||||
|
|||||||
@@ -42,26 +42,26 @@ public:
|
|||||||
bool QuitRequested();
|
bool QuitRequested();
|
||||||
|
|
||||||
void BuildPrinterList();
|
void BuildPrinterList();
|
||||||
PrinterItem *SelectedItem() const;
|
PrinterItem* SelectedItem() const;
|
||||||
void UpdateItem(PrinterItem *item);
|
void UpdateItem(PrinterItem* item);
|
||||||
|
|
||||||
PrinterItem *ActivePrinter() const;
|
PrinterItem* ActivePrinter() const;
|
||||||
void SetActivePrinter(PrinterItem* item);
|
void SetActivePrinter(PrinterItem* item);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef BListView Inherited;
|
typedef BListView Inherited;
|
||||||
|
|
||||||
void _AddPrinter(BDirectory &printer, bool calculateLayout);
|
void _AddPrinter(BDirectory& printer, bool calculateLayout);
|
||||||
void _LayoutPrinterItems();
|
void _LayoutPrinterItems();
|
||||||
PrinterItem *_FindItem(node_ref* node) const;
|
PrinterItem* _FindItem(node_ref* node) const;
|
||||||
|
|
||||||
void EntryCreated(node_ref *node,
|
void EntryCreated(node_ref* node,
|
||||||
entry_ref *entry);
|
entry_ref* entry);
|
||||||
void EntryRemoved(node_ref *node);
|
void EntryRemoved(node_ref* node);
|
||||||
void AttributeChanged(node_ref *node);
|
void AttributeChanged(node_ref* node);
|
||||||
|
|
||||||
FolderWatcher *fFolder;
|
FolderWatcher* fFolder;
|
||||||
PrinterItem *fActivePrinter;
|
PrinterItem* fActivePrinter;
|
||||||
PrinterListLayoutData fLayoutData;
|
PrinterListLayoutData fLayoutData;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -76,25 +76,29 @@ public:
|
|||||||
void GetColumnWidth(BView* view, float& leftColumn,
|
void GetColumnWidth(BView* view, float& leftColumn,
|
||||||
float& rightColumn);
|
float& rightColumn);
|
||||||
|
|
||||||
void DrawItem(BView *owner, BRect bounds,
|
void DrawItem(BView* owner, BRect bounds,
|
||||||
bool complete);
|
bool complete);
|
||||||
void Update(BView *owner, const BFont *font);
|
void Update(BView* owner, const BFont* font);
|
||||||
|
|
||||||
bool Remove(BListView *view);
|
bool Remove(BListView* view);
|
||||||
bool IsActivePrinter() const;
|
bool IsActivePrinter() const;
|
||||||
bool HasPendingJobs() const;
|
bool HasPendingJobs() const;
|
||||||
|
|
||||||
const char *Name() const { return fName.String(); }
|
const char* Name() const { return fName.String(); }
|
||||||
|
const char* Driver() const { return fDriverName.String(); }
|
||||||
|
const char* Transport() const { return fTransport.String(); }
|
||||||
|
const char* TransportAddress() const
|
||||||
|
{ return fTransportAddress.String(); }
|
||||||
|
|
||||||
SpoolFolder *Folder() const;
|
SpoolFolder* Folder() const;
|
||||||
BDirectory *Node();
|
BDirectory* Node();
|
||||||
void UpdatePendingJobs();
|
void UpdatePendingJobs();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _GetStringProperty(const char *propName,
|
void _GetStringProperty(const char* propName,
|
||||||
BString &outString);
|
BString& outString);
|
||||||
|
|
||||||
SpoolFolder *fFolder;
|
SpoolFolder* fFolder;
|
||||||
BDirectory fNode;
|
BDirectory fNode;
|
||||||
BString fComments;
|
BString fComments;
|
||||||
BString fTransport;
|
BString fTransport;
|
||||||
@@ -104,8 +108,8 @@ private:
|
|||||||
BString fPendingJobs;
|
BString fPendingJobs;
|
||||||
PrinterListLayoutData& fLayoutData;
|
PrinterListLayoutData& fLayoutData;
|
||||||
|
|
||||||
static BBitmap *sIcon;
|
static BBitmap* sIcon;
|
||||||
static BBitmap *sSelectedIcon;
|
static BBitmap* sSelectedIcon;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _PRINTERS_LISTVIEW_H
|
#endif // _PRINTERS_LISTVIEW_H
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2010, Haiku.
|
* Copyright 2001-2011, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Michael Pfeiffer
|
* Michael Pfeiffer
|
||||||
|
* Philippe Houdoin
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "PrintersWindow.h"
|
#include "PrintersWindow.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
// BeOS API
|
// BeOS API
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
@@ -16,6 +19,7 @@
|
|||||||
#include <FindDirectory.h>
|
#include <FindDirectory.h>
|
||||||
#include <ListView.h>
|
#include <ListView.h>
|
||||||
#include <Locale.h>
|
#include <Locale.h>
|
||||||
|
#include <PrintJob.h>
|
||||||
#include <ScrollView.h>
|
#include <ScrollView.h>
|
||||||
|
|
||||||
#include "pr_server.h"
|
#include "pr_server.h"
|
||||||
@@ -38,7 +42,7 @@ PrintersWindow::PrintersWindow(BRect frame)
|
|||||||
fSelectedPrinter(NULL),
|
fSelectedPrinter(NULL),
|
||||||
fAddingPrinter(false)
|
fAddingPrinter(false)
|
||||||
{
|
{
|
||||||
BuildGUI();
|
_BuildGUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -74,8 +78,8 @@ PrintersWindow::MessageReceived(BMessage* msg)
|
|||||||
fSelectedPrinter = NULL;
|
fSelectedPrinter = NULL;
|
||||||
fJobListView->SetSpoolFolder(NULL);
|
fJobListView->SetSpoolFolder(NULL);
|
||||||
}
|
}
|
||||||
UpdateJobButtons();
|
_UpdateJobButtons();
|
||||||
UpdatePrinterButtons();
|
_UpdatePrinterButtons();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,11 +113,19 @@ PrintersWindow::MessageReceived(BMessage* msg)
|
|||||||
setActivePrinter.AddSpecifier("ActivePrinter");
|
setActivePrinter.AddSpecifier("ActivePrinter");
|
||||||
setActivePrinter.AddString("data", printer->Name());
|
setActivePrinter.AddString("data", printer->Name());
|
||||||
msgr.SendMessage(&setActivePrinter);
|
msgr.SendMessage(&setActivePrinter);
|
||||||
UpdatePrinterButtons();
|
_UpdatePrinterButtons();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case kMsgPrintTestPage:
|
||||||
|
{
|
||||||
|
fSelectedPrinter = fPrinterListView->SelectedItem();
|
||||||
|
if (fSelectedPrinter)
|
||||||
|
PrintTestPage(fSelectedPrinter);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case kMsgCancelJob:
|
case kMsgCancelJob:
|
||||||
fJobListView->CancelJob();
|
fJobListView->CancelJob();
|
||||||
break;
|
break;
|
||||||
@@ -123,7 +135,7 @@ PrintersWindow::MessageReceived(BMessage* msg)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case kMsgJobSelected:
|
case kMsgJobSelected:
|
||||||
UpdateJobButtons();
|
_UpdateJobButtons();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_PRINTER_CHANGED:
|
case B_PRINTER_CHANGED:
|
||||||
@@ -151,7 +163,66 @@ PrintersWindow::MessageReceived(BMessage* msg)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PrintersWindow::BuildGUI()
|
PrintersWindow::PrintTestPage(PrinterItem* printer)
|
||||||
|
{
|
||||||
|
BPrintJob job("TestPage");
|
||||||
|
job.ConfigPage();
|
||||||
|
BMessage* settings = job.Settings();
|
||||||
|
|
||||||
|
printf("print job settings:\n");
|
||||||
|
settings->PrintToStream();
|
||||||
|
|
||||||
|
BRect pageRect = job.PrintableRect();
|
||||||
|
|
||||||
|
job.BeginJob();
|
||||||
|
|
||||||
|
// TestPageView testPage(pageRect, printer);
|
||||||
|
// job.DrawView(testPage, pageRect, BPoint(0.0, 0.0));
|
||||||
|
job.SpoolPage();
|
||||||
|
if (!job.CanContinue())
|
||||||
|
return;
|
||||||
|
|
||||||
|
job.CommitJob();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PrintersWindow::AddJob(SpoolFolder* folder, Job* job)
|
||||||
|
{
|
||||||
|
if (_IsSelected(folder->Item()))
|
||||||
|
fJobListView->AddJob(job);
|
||||||
|
fPrinterListView->UpdateItem(folder->Item());
|
||||||
|
_UpdatePrinterButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PrintersWindow::RemoveJob(SpoolFolder* folder, Job* job)
|
||||||
|
{
|
||||||
|
if (_IsSelected(folder->Item()))
|
||||||
|
fJobListView->RemoveJob(job);
|
||||||
|
fPrinterListView->UpdateItem(folder->Item());
|
||||||
|
_UpdatePrinterButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PrintersWindow::UpdateJob(SpoolFolder* folder, Job* job)
|
||||||
|
{
|
||||||
|
if (_IsSelected(folder->Item())) {
|
||||||
|
fJobListView->UpdateJob(job);
|
||||||
|
_UpdateJobButtons();
|
||||||
|
}
|
||||||
|
fPrinterListView->UpdateItem(folder->Item());
|
||||||
|
_UpdatePrinterButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PrintersWindow::_BuildGUI()
|
||||||
{
|
{
|
||||||
const float boxInset = 10.0;
|
const float boxInset = 10.0;
|
||||||
BRect r(Bounds());
|
BRect r(Bounds());
|
||||||
@@ -201,6 +272,17 @@ PrintersWindow::BuildGUI()
|
|||||||
if (fMakeDefault->Bounds().Width() > maxWidth)
|
if (fMakeDefault->Bounds().Width() > maxWidth)
|
||||||
maxWidth = fMakeDefault->Bounds().Width();
|
maxWidth = fMakeDefault->Bounds().Width();
|
||||||
|
|
||||||
|
// Print Test Page button
|
||||||
|
fPrintTestPage = new BButton(BRect(5,60,5,60), "print_test_page",
|
||||||
|
B_TRANSLATE("Print test page"), new BMessage(kMsgPrintTestPage),
|
||||||
|
B_FOLLOW_RIGHT);
|
||||||
|
printersBox->AddChild(fPrintTestPage);
|
||||||
|
fPrintTestPage->ResizeToPreferred();
|
||||||
|
|
||||||
|
if (fPrintTestPage->Bounds().Width() > maxWidth)
|
||||||
|
maxWidth = fPrintTestPage->Bounds().Width();
|
||||||
|
|
||||||
|
|
||||||
// Resize all buttons to maximum width and align them to the right
|
// Resize all buttons to maximum width and align them to the right
|
||||||
float xPos = printersBox->Bounds().Width() - boxInset - maxWidth;
|
float xPos = printersBox->Bounds().Width() - boxInset - maxWidth;
|
||||||
addButton->MoveTo(xPos, boxInset + 8);
|
addButton->MoveTo(xPos, boxInset + 8);
|
||||||
@@ -214,9 +296,16 @@ PrintersWindow::BuildGUI()
|
|||||||
boxInset + fRemove->Bounds().Height() + boxInset + 8);
|
boxInset + fRemove->Bounds().Height() + boxInset + 8);
|
||||||
fMakeDefault->ResizeTo(maxWidth, fMakeDefault->Bounds().Height());
|
fMakeDefault->ResizeTo(maxWidth, fMakeDefault->Bounds().Height());
|
||||||
|
|
||||||
|
fPrintTestPage->MoveTo(xPos, boxInset + addButton->Bounds().Height() +
|
||||||
|
boxInset + fRemove->Bounds().Height() +
|
||||||
|
boxInset + fMakeDefault->Bounds().Height() + boxInset + 8);
|
||||||
|
fPrintTestPage->ResizeTo(maxWidth, fPrintTestPage->Bounds().Height());
|
||||||
|
|
||||||
|
|
||||||
// Disable all selection-based buttons
|
// Disable all selection-based buttons
|
||||||
fRemove->SetEnabled(false);
|
fRemove->SetEnabled(false);
|
||||||
fMakeDefault->SetEnabled(false);
|
fMakeDefault->SetEnabled(false);
|
||||||
|
fPrintTestPage->SetEnabled(false);
|
||||||
|
|
||||||
// Create listview with scroller
|
// Create listview with scroller
|
||||||
BRect listBounds(boxInset, boxInset + 8,
|
BRect listBounds(boxInset, boxInset + 8,
|
||||||
@@ -289,55 +378,24 @@ PrintersWindow::BuildGUI()
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PrintersWindow::IsSelected(PrinterItem* printer)
|
PrintersWindow::_IsSelected(PrinterItem* printer)
|
||||||
{
|
{
|
||||||
return fSelectedPrinter && fSelectedPrinter == printer;
|
return fSelectedPrinter && fSelectedPrinter == printer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PrintersWindow::AddJob(SpoolFolder* folder, Job* job)
|
PrintersWindow::_UpdatePrinterButtons()
|
||||||
{
|
|
||||||
if (IsSelected(folder->Item()))
|
|
||||||
fJobListView->AddJob(job);
|
|
||||||
fPrinterListView->UpdateItem(folder->Item());
|
|
||||||
UpdatePrinterButtons();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
PrintersWindow::RemoveJob(SpoolFolder* folder, Job* job)
|
|
||||||
{
|
|
||||||
if (IsSelected(folder->Item()))
|
|
||||||
fJobListView->RemoveJob(job);
|
|
||||||
fPrinterListView->UpdateItem(folder->Item());
|
|
||||||
UpdatePrinterButtons();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
PrintersWindow::UpdateJob(SpoolFolder* folder, Job* job)
|
|
||||||
{
|
|
||||||
if (IsSelected(folder->Item())) {
|
|
||||||
fJobListView->UpdateJob(job);
|
|
||||||
UpdateJobButtons();
|
|
||||||
}
|
|
||||||
fPrinterListView->UpdateItem(folder->Item());
|
|
||||||
UpdatePrinterButtons();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
PrintersWindow::UpdatePrinterButtons()
|
|
||||||
{
|
{
|
||||||
PrinterItem* item = fPrinterListView->SelectedItem();
|
PrinterItem* item = fPrinterListView->SelectedItem();
|
||||||
fRemove->SetEnabled(item && !item->HasPendingJobs());
|
fRemove->SetEnabled(item && !item->HasPendingJobs());
|
||||||
fMakeDefault->SetEnabled(item && !item->IsActivePrinter());
|
fMakeDefault->SetEnabled(item && !item->IsActivePrinter());
|
||||||
|
fPrintTestPage->SetEnabled(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PrintersWindow::UpdateJobButtons()
|
PrintersWindow::_UpdateJobButtons()
|
||||||
{
|
{
|
||||||
JobItem* item = fJobListView->SelectedItem();
|
JobItem* item = fJobListView->SelectedItem();
|
||||||
if (item != NULL) {
|
if (item != NULL) {
|
||||||
@@ -349,3 +407,5 @@ PrintersWindow::UpdateJobButtons()
|
|||||||
fRestart->SetEnabled(false);
|
fRestart->SetEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -28,21 +28,24 @@ public:
|
|||||||
void MessageReceived(BMessage* msg);
|
void MessageReceived(BMessage* msg);
|
||||||
bool QuitRequested();
|
bool QuitRequested();
|
||||||
|
|
||||||
|
void PrintTestPage(PrinterItem* printer);
|
||||||
|
|
||||||
void AddJob(SpoolFolder* folder, Job* job);
|
void AddJob(SpoolFolder* folder, Job* job);
|
||||||
void RemoveJob(SpoolFolder* folder, Job* job);
|
void RemoveJob(SpoolFolder* folder, Job* job);
|
||||||
void UpdateJob(SpoolFolder* folder, Job* job);
|
void UpdateJob(SpoolFolder* folder, Job* job);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void BuildGUI();
|
void _BuildGUI();
|
||||||
bool IsSelected(PrinterItem* printer);
|
bool _IsSelected(PrinterItem* printer);
|
||||||
void UpdatePrinterButtons();
|
void _UpdatePrinterButtons();
|
||||||
void UpdateJobButtons();
|
void _UpdateJobButtons();
|
||||||
|
|
||||||
typedef BWindow Inherited;
|
typedef BWindow Inherited;
|
||||||
|
|
||||||
PrinterListView* fPrinterListView;
|
PrinterListView* fPrinterListView;
|
||||||
BButton* fMakeDefault;
|
BButton* fMakeDefault;
|
||||||
BButton* fRemove;
|
BButton* fRemove;
|
||||||
|
BButton* fPrintTestPage;
|
||||||
|
|
||||||
JobListView* fJobListView;
|
JobListView* fJobListView;
|
||||||
BButton* fRestart;
|
BButton* fRestart;
|
||||||
|
|||||||
Reference in New Issue
Block a user