* invalidate only the items in question, should fix ticket #1803
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25107 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -33,14 +33,34 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
status_t GetPrinterServerMessenger(BMessenger& msgr)
|
BString
|
||||||
|
ActivePrinterName()
|
||||||
{
|
{
|
||||||
// If print server is not yet running, start it
|
BMessenger msgr;
|
||||||
if (!be_roster->IsRunning(PSRV_SIGNATURE_TYPE)) {
|
if (GetPrinterServerMessenger(msgr) != B_OK)
|
||||||
|
return BString();
|
||||||
|
|
||||||
|
BMessage getNameOfActivePrinter(B_GET_PROPERTY);
|
||||||
|
getNameOfActivePrinter.AddSpecifier("ActivePrinter");
|
||||||
|
|
||||||
|
BMessage reply;
|
||||||
|
msgr.SendMessage(&getNameOfActivePrinter, &reply);
|
||||||
|
|
||||||
|
BString activePrinterName;
|
||||||
|
reply.FindString("result", &activePrinterName);
|
||||||
|
|
||||||
|
return activePrinterName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
GetPrinterServerMessenger(BMessenger& msgr)
|
||||||
|
{
|
||||||
|
// If print server is not yet running, start it
|
||||||
|
if (!be_roster->IsRunning(PSRV_SIGNATURE_TYPE))
|
||||||
be_roster->Launch(PSRV_SIGNATURE_TYPE);
|
be_roster->Launch(PSRV_SIGNATURE_TYPE);
|
||||||
}
|
|
||||||
|
|
||||||
msgr = BMessenger(PSRV_SIGNATURE_TYPE);
|
msgr = BMessenger(PSRV_SIGNATURE_TYPE);
|
||||||
|
|
||||||
return msgr.IsValid() ? B_OK : B_ERROR;
|
return msgr.IsValid() ? B_OK : B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,10 @@
|
|||||||
#define GLOBALS_H
|
#define GLOBALS_H
|
||||||
|
|
||||||
#include <Messenger.h>
|
#include <Messenger.h>
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
BString ActivePrinterName();
|
||||||
status_t GetPrinterServerMessenger(BMessenger& msgr);
|
status_t GetPrinterServerMessenger(BMessenger& msgr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,8 @@
|
|||||||
|
|
||||||
PrinterListView::PrinterListView(BRect frame)
|
PrinterListView::PrinterListView(BRect frame)
|
||||||
: Inherited(frame, "printers_list", B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL),
|
: Inherited(frame, "printers_list", B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL),
|
||||||
fFolder(NULL)
|
fFolder(NULL),
|
||||||
|
fActivePrinter(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,10 +100,13 @@ PrinterListView::AttachedToWindow()
|
|||||||
BuildPrinterList();
|
BuildPrinterList();
|
||||||
|
|
||||||
// Select active printer
|
// Select active printer
|
||||||
|
BString activePrinterName(ActivePrinterName());
|
||||||
for (int32 i = 0; i < CountItems(); i ++) {
|
for (int32 i = 0; i < CountItems(); i ++) {
|
||||||
PrinterItem* item = dynamic_cast<PrinterItem*>(ItemAt(i));
|
PrinterItem* item = dynamic_cast<PrinterItem*>(ItemAt(i));
|
||||||
if (item != NULL && item->IsActivePrinter()) {
|
if (item != NULL && item->Name() == activePrinterName) {
|
||||||
Select(i); break;
|
Select(i);
|
||||||
|
fActivePrinter = item;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,6 +177,9 @@ void PrinterListView::EntryRemoved(node_ref* node)
|
|||||||
{
|
{
|
||||||
PrinterItem* item = FindItem(node);
|
PrinterItem* item = FindItem(node);
|
||||||
if (item) {
|
if (item) {
|
||||||
|
if (item == fActivePrinter)
|
||||||
|
fActivePrinter = NULL;
|
||||||
|
|
||||||
RemoveItem(item);
|
RemoveItem(item);
|
||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
@@ -199,6 +206,20 @@ PrinterItem* PrinterListView::SelectedItem()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PrinterItem*
|
||||||
|
PrinterListView::ActivePrinter() const
|
||||||
|
{
|
||||||
|
return fActivePrinter;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PrinterListView::SetActivePrinter(PrinterItem* item)
|
||||||
|
{
|
||||||
|
fActivePrinter = item;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BBitmap* PrinterItem::sIcon = NULL;
|
BBitmap* PrinterItem::sIcon = NULL;
|
||||||
BBitmap* PrinterItem::sSelectedIcon = NULL;
|
BBitmap* PrinterItem::sSelectedIcon = NULL;
|
||||||
|
|
||||||
@@ -368,18 +389,7 @@ void PrinterItem::DrawItem(BView *owner, BRect /*bounds*/, bool complete)
|
|||||||
bool
|
bool
|
||||||
PrinterItem::IsActivePrinter()
|
PrinterItem::IsActivePrinter()
|
||||||
{
|
{
|
||||||
BMessenger msgr;
|
return fName == ActivePrinterName();
|
||||||
if (::GetPrinterServerMessenger(msgr) != B_OK)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
BMessage getNameOfActivePrinter(B_GET_PROPERTY);
|
|
||||||
getNameOfActivePrinter.AddSpecifier("ActivePrinter");
|
|
||||||
|
|
||||||
BString activePrinterName;
|
|
||||||
BMessage reply;
|
|
||||||
return msgr.SendMessage(&getNameOfActivePrinter, &reply) == B_OK
|
|
||||||
&& reply.FindString("result", &activePrinterName) == B_OK
|
|
||||||
&& fName == activePrinterName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -61,12 +61,15 @@ class PrinterListView : public BListView, public FolderListener {
|
|||||||
|
|
||||||
void BuildPrinterList();
|
void BuildPrinterList();
|
||||||
PrinterItem *SelectedItem();
|
PrinterItem *SelectedItem();
|
||||||
|
|
||||||
void UpdateItem(PrinterItem *item);
|
void UpdateItem(PrinterItem *item);
|
||||||
|
|
||||||
|
PrinterItem* ActivePrinter() const;
|
||||||
|
void SetActivePrinter(PrinterItem* item);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BDirectory fNode;
|
BDirectory fNode;
|
||||||
FolderWatcher *fFolder;
|
FolderWatcher *fFolder;
|
||||||
|
PrinterItem *fActivePrinter;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BBitmap;
|
class BBitmap;
|
||||||
|
|||||||
@@ -107,27 +107,21 @@ void PrintersWindow::MessageReceived(BMessage* msg)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kMsgMakeDefaultPrinter:
|
case kMsgMakeDefaultPrinter:
|
||||||
{
|
{
|
||||||
int32 prIndex = fPrinterListView->CurrentSelection();
|
PrinterItem* printer = fPrinterListView->SelectedItem();
|
||||||
if (prIndex >= 0)
|
if (printer && printer == fPrinterListView->ActivePrinter())
|
||||||
{
|
break;
|
||||||
PrinterItem* printer = dynamic_cast<PrinterItem*>(fPrinterListView->ItemAt(prIndex));
|
|
||||||
BMessenger msgr;
|
|
||||||
if (printer != NULL && ::GetPrinterServerMessenger(msgr) == B_OK)
|
|
||||||
{
|
|
||||||
BMessage setActivePrinter(B_SET_PROPERTY);
|
|
||||||
setActivePrinter.AddSpecifier("ActivePrinter");
|
|
||||||
setActivePrinter.AddString("data", printer->Name());
|
|
||||||
msgr.SendMessage(&setActivePrinter);
|
|
||||||
|
|
||||||
fPrinterListView->Invalidate();
|
|
||||||
UpdatePrinterButtons();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
BMessenger msgr;
|
||||||
|
if (printer && GetPrinterServerMessenger(msgr) == B_OK) {
|
||||||
|
BMessage setActivePrinter(B_SET_PROPERTY);
|
||||||
|
setActivePrinter.AddSpecifier("ActivePrinter");
|
||||||
|
setActivePrinter.AddString("data", printer->Name());
|
||||||
|
msgr.SendMessage(&setActivePrinter);
|
||||||
|
UpdatePrinterButtons();
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
case kMsgCancelJob: fJobListView->CancelJob();
|
case kMsgCancelJob: fJobListView->CancelJob();
|
||||||
break;
|
break;
|
||||||
@@ -139,10 +133,23 @@ void PrintersWindow::MessageReceived(BMessage* msg)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case B_PRINTER_CHANGED:
|
case B_PRINTER_CHANGED:
|
||||||
// active printer could have been changed
|
{
|
||||||
fPrinterListView->Invalidate();
|
// active printer could have been changed, even outside of prefs
|
||||||
break;
|
BString activePrinterName(ActivePrinterName());
|
||||||
|
PrinterItem* item = fPrinterListView->ActivePrinter();
|
||||||
|
if (item && item->Name() != activePrinterName)
|
||||||
|
fPrinterListView->UpdateItem(item);
|
||||||
|
|
||||||
|
for (int32 i = 0; i < fPrinterListView->CountItems(); ++i) {
|
||||||
|
item = dynamic_cast<PrinterItem*>(fPrinterListView->ItemAt(i));
|
||||||
|
if (item && item->Name() == activePrinterName) {
|
||||||
|
fPrinterListView->UpdateItem(item);
|
||||||
|
fPrinterListView->SetActivePrinter(item);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Inherited::MessageReceived(msg);
|
Inherited::MessageReceived(msg);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user