* Right align right column.
"Transport" or "comment" text does not get truncated anymore, when it is longer than "pending jobs" text. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36896 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
d1dd67cbbf
commit
0514b0cad2
@ -36,6 +36,8 @@ PrinterListView::PrinterListView(BRect frame)
|
||||
fFolder(NULL),
|
||||
fActivePrinter(NULL)
|
||||
{
|
||||
fLayoutData.fLeftColumnMaximumWidth = 100;
|
||||
fLayoutData.fRightColumnMaximumWidth = 100;
|
||||
}
|
||||
|
||||
|
||||
@ -65,8 +67,10 @@ PrinterListView::BuildPrinterList()
|
||||
BEntry entry;
|
||||
while(dir.GetNextEntry(&entry) == B_OK) {
|
||||
BDirectory printer(&entry);
|
||||
_AddPrinter(printer);
|
||||
_AddPrinter(printer, false);
|
||||
}
|
||||
|
||||
_LayoutPrinterItems();
|
||||
}
|
||||
|
||||
|
||||
@ -147,7 +151,7 @@ PrinterListView::SelectedItem() const
|
||||
|
||||
|
||||
void
|
||||
PrinterListView::_AddPrinter(BDirectory& printer)
|
||||
PrinterListView::_AddPrinter(BDirectory& printer, bool calculateLayout)
|
||||
{
|
||||
BString state;
|
||||
node_ref node;
|
||||
@ -164,12 +168,38 @@ PrinterListView::_AddPrinter(BDirectory& printer)
|
||||
if (info.GetType(buffer) == B_OK
|
||||
&& strcmp(buffer, PSRV_PRINTER_FILETYPE) == 0) {
|
||||
// Yes, it is a printer definition node
|
||||
AddItem(new PrinterItem(dynamic_cast<PrintersWindow*>(Window()), printer));
|
||||
AddItem(new PrinterItem(dynamic_cast<PrintersWindow*>(Window()),
|
||||
printer, fLayoutData));
|
||||
if (calculateLayout)
|
||||
_LayoutPrinterItems();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PrinterListView::_LayoutPrinterItems()
|
||||
{
|
||||
float& leftColumnMaximumWidth = fLayoutData.fLeftColumnMaximumWidth;
|
||||
float& rightColumnMaximumWidth = fLayoutData.fRightColumnMaximumWidth;
|
||||
|
||||
for (int32 i = 0; i < CountItems(); i ++) {
|
||||
PrinterItem* item = dynamic_cast<PrinterItem*>(ItemAt(i));
|
||||
|
||||
float leftColumnWidth = 0;
|
||||
float rightColumnWidth = 0;
|
||||
item->GetColumnWidth(this, leftColumnWidth, rightColumnWidth);
|
||||
|
||||
leftColumnMaximumWidth = MAX(leftColumnMaximumWidth,
|
||||
leftColumnWidth);
|
||||
rightColumnMaximumWidth = MAX(rightColumnMaximumWidth,
|
||||
rightColumnWidth);
|
||||
}
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
|
||||
PrinterItem*
|
||||
PrinterListView::_FindItem(node_ref* node) const
|
||||
{
|
||||
@ -187,7 +217,7 @@ void
|
||||
PrinterListView::_EntryCreated(node_ref* node, entry_ref* entry)
|
||||
{
|
||||
BDirectory printer(node);
|
||||
_AddPrinter(printer);
|
||||
_AddPrinter(printer, true);
|
||||
}
|
||||
|
||||
|
||||
@ -209,7 +239,7 @@ void
|
||||
PrinterListView::_AttributeChanged(node_ref* node)
|
||||
{
|
||||
BDirectory printer(node);
|
||||
_AddPrinter(printer);
|
||||
_AddPrinter(printer, true);
|
||||
}
|
||||
|
||||
|
||||
@ -222,10 +252,12 @@ BBitmap* PrinterItem::sIcon = NULL;
|
||||
BBitmap* PrinterItem::sSelectedIcon = NULL;
|
||||
|
||||
|
||||
PrinterItem::PrinterItem(PrintersWindow* window, const BDirectory& node)
|
||||
PrinterItem::PrinterItem(PrintersWindow* window, const BDirectory& node,
|
||||
PrinterListLayoutData& layoutData)
|
||||
: BListItem(0, false),
|
||||
fFolder(NULL),
|
||||
fNode(node)
|
||||
fNode(node),
|
||||
fLayoutData(layoutData)
|
||||
{
|
||||
BRect rect(0, 0, B_LARGE_ICON - 1, B_LARGE_ICON - 1);
|
||||
if (sIcon == NULL) {
|
||||
@ -287,6 +319,21 @@ PrinterItem::~PrinterItem()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
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()));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PrinterItem::Update(BView *owner, const BFont *font)
|
||||
{
|
||||
@ -348,13 +395,24 @@ PrinterItem::DrawItem(BView *owner, BRect /*bounds*/, bool complete)
|
||||
owner->SetLowColor(oldLowColor);
|
||||
owner->SetHighColor(oldHighColor);
|
||||
|
||||
float x = B_LARGE_ICON + 8.0;
|
||||
float iconColumnWidth = B_LARGE_ICON + 8.0;
|
||||
float x = iconColumnWidth;
|
||||
BPoint iconPt(bounds.LeftTop() + BPoint(2.0, 2.0));
|
||||
BPoint namePt(iconPt + BPoint(x, fntheight));
|
||||
BPoint driverPt(iconPt + BPoint(x, fntheight * 2.0));
|
||||
BPoint defaultPt(iconPt + BPoint(x, fntheight * 3.0));
|
||||
|
||||
float width = owner->StringWidth(B_TRANSLATE("No pending jobs."));
|
||||
float totalWidth = bounds.Width() - iconColumnWidth;
|
||||
float maximumWidth = fLayoutData.fLeftColumnMaximumWidth +
|
||||
fLayoutData.fRightColumnMaximumWidth;
|
||||
float width;
|
||||
if (totalWidth < maximumWidth) {
|
||||
width = fLayoutData.fRightColumnMaximumWidth * totalWidth /
|
||||
maximumWidth;
|
||||
} 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);
|
||||
|
@ -25,6 +25,14 @@ class BBitmap;
|
||||
class PrintersWindow;
|
||||
|
||||
|
||||
struct PrinterListLayoutData
|
||||
{
|
||||
float fLeftColumnMaximumWidth;
|
||||
float fRightColumnMaximumWidth;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class PrinterListView : public BListView, public FolderListener {
|
||||
public:
|
||||
PrinterListView(BRect frame);
|
||||
@ -39,11 +47,12 @@ public:
|
||||
|
||||
PrinterItem *ActivePrinter() const;
|
||||
void SetActivePrinter(PrinterItem* item);
|
||||
|
||||
|
||||
private:
|
||||
typedef BListView Inherited;
|
||||
|
||||
void _AddPrinter(BDirectory &printer);
|
||||
void _AddPrinter(BDirectory &printer, bool calculateLayout);
|
||||
void _LayoutPrinterItems();
|
||||
PrinterItem *_FindItem(node_ref* node) const;
|
||||
|
||||
void _EntryCreated(node_ref *node,
|
||||
@ -53,15 +62,20 @@ private:
|
||||
|
||||
FolderWatcher *fFolder;
|
||||
PrinterItem *fActivePrinter;
|
||||
PrinterListLayoutData fLayoutData;
|
||||
};
|
||||
|
||||
|
||||
class PrinterItem : public BListItem {
|
||||
public:
|
||||
PrinterItem(PrintersWindow *window,
|
||||
const BDirectory &node);
|
||||
PrinterItem(PrintersWindow* window,
|
||||
const BDirectory& node,
|
||||
PrinterListLayoutData& layoutData);
|
||||
~PrinterItem();
|
||||
|
||||
void GetColumnWidth(BView* view, float& leftColumn,
|
||||
float& rightColumn);
|
||||
|
||||
void DrawItem(BView *owner, BRect bounds,
|
||||
bool complete);
|
||||
void Update(BView *owner, const BFont *font);
|
||||
@ -87,6 +101,7 @@ private:
|
||||
BString fDriverName;
|
||||
BString fName;
|
||||
BString fPendingJobs;
|
||||
PrinterListLayoutData& fLayoutData;
|
||||
|
||||
static BBitmap *sIcon;
|
||||
static BBitmap *sSelectedIcon;
|
||||
|
Loading…
Reference in New Issue
Block a user