diff --git a/src/preferences/print/PrinterListView.cpp b/src/preferences/print/PrinterListView.cpp index 7342a539df..2ed962c12c 100644 --- a/src/preferences/print/PrinterListView.cpp +++ b/src/preferences/print/PrinterListView.cpp @@ -70,7 +70,7 @@ PrinterListView::BuildPrinterList() BDirectory printer(&entry); _AddPrinter(printer, false); } - + _LayoutPrinterItems(); } @@ -151,6 +151,40 @@ PrinterListView::SelectedItem() const } +// FolderListener interface + +void +PrinterListView::EntryCreated(node_ref* node, entry_ref* entry) +{ + BDirectory printer(node); + _AddPrinter(printer, true); +} + + +void +PrinterListView::EntryRemoved(node_ref* node) +{ + PrinterItem* item = _FindItem(node); + if (item) { + if (item == fActivePrinter) + fActivePrinter = NULL; + + RemoveItem(item); + delete item; + } +} + + +void +PrinterListView::AttributeChanged(node_ref* node) +{ + BDirectory printer(node); + _AddPrinter(printer, true); +} + + +// private methods + void PrinterListView::_AddPrinter(BDirectory& printer, bool calculateLayout) { @@ -169,7 +203,7 @@ PrinterListView::_AddPrinter(BDirectory& printer, bool calculateLayout) if (info.GetType(buffer) == B_OK && strcmp(buffer, PSRV_PRINTER_FILETYPE) == 0) { // Yes, it is a printer definition node - AddItem(new PrinterItem(dynamic_cast(Window()), + AddItem(new PrinterItem(dynamic_cast(Window()), printer, fLayoutData)); if (calculateLayout) _LayoutPrinterItems(); @@ -183,20 +217,20 @@ PrinterListView::_LayoutPrinterItems() { float& leftColumnMaximumWidth = fLayoutData.fLeftColumnMaximumWidth; float& rightColumnMaximumWidth = fLayoutData.fRightColumnMaximumWidth; - - for (int32 i = 0; i < CountItems(); i ++) { + + for (int32 i = 0; i < CountItems(); i ++) { PrinterItem* item = dynamic_cast(ItemAt(i)); float leftColumnWidth = 0; float rightColumnWidth = 0; item->GetColumnWidth(this, leftColumnWidth, rightColumnWidth); - - leftColumnMaximumWidth = MAX(leftColumnMaximumWidth, + + leftColumnMaximumWidth = MAX(leftColumnMaximumWidth, leftColumnWidth); - rightColumnMaximumWidth = MAX(rightColumnMaximumWidth, + rightColumnMaximumWidth = MAX(rightColumnMaximumWidth, rightColumnWidth); } - + Invalidate(); } @@ -214,37 +248,6 @@ PrinterListView::_FindItem(node_ref* node) const } -void -PrinterListView::_EntryCreated(node_ref* node, entry_ref* entry) -{ - BDirectory printer(node); - _AddPrinter(printer, true); -} - - -void -PrinterListView::_EntryRemoved(node_ref* node) -{ - PrinterItem* item = _FindItem(node); - if (item) { - if (item == fActivePrinter) - fActivePrinter = NULL; - - RemoveItem(item); - delete item; - } -} - - -void -PrinterListView::_AttributeChanged(node_ref* node) -{ - BDirectory printer(node); - _AddPrinter(printer, true); -} - - - // #pragma mark -- PrinterItem @@ -325,10 +328,10 @@ PrinterItem::GetColumnWidth(BView* view, float& leftColumn, float& rightColumn) { BFont font; view->GetFont(&font); - + leftColumn = font.StringWidth(fName.String()); leftColumn = MAX(leftColumn, font.StringWidth(fDriverName.String())); - + rightColumn = font.StringWidth(fPendingJobs.String()); rightColumn = MAX(rightColumn, font.StringWidth(fTransport.String())); rightColumn = MAX(rightColumn, font.StringWidth(fComments.String())); @@ -413,7 +416,7 @@ PrinterItem::DrawItem(BView *owner, BRect /*bounds*/, bool complete) } else { width = fLayoutData.fRightColumnMaximumWidth; } - + BPoint pendingPt(bounds.right - width - 8.0, namePt.y); BPoint transportPt(bounds.right - width - 8.0, driverPt.y); BPoint commentPt(bounds.right - width - 8.0, defaultPt.y); diff --git a/src/preferences/print/PrinterListView.h b/src/preferences/print/PrinterListView.h index 9ad77864b0..d7fa7374f1 100644 --- a/src/preferences/print/PrinterListView.h +++ b/src/preferences/print/PrinterListView.h @@ -47,7 +47,7 @@ public: PrinterItem *ActivePrinter() const; void SetActivePrinter(PrinterItem* item); - + private: typedef BListView Inherited; @@ -55,10 +55,10 @@ private: void _LayoutPrinterItems(); PrinterItem *_FindItem(node_ref* node) const; - void _EntryCreated(node_ref *node, + void EntryCreated(node_ref *node, entry_ref *entry); - void _EntryRemoved(node_ref *node); - void _AttributeChanged(node_ref *node); + void EntryRemoved(node_ref *node); + void AttributeChanged(node_ref *node); FolderWatcher *fFolder; PrinterItem *fActivePrinter; @@ -73,9 +73,9 @@ public: PrinterListLayoutData& layoutData); ~PrinterItem(); - void GetColumnWidth(BView* view, float& leftColumn, + void GetColumnWidth(BView* view, float& leftColumn, float& rightColumn); - + void DrawItem(BView *owner, BRect bounds, bool complete); void Update(BView *owner, const BFont *font);