-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetListView.cpp
More file actions
60 lines (54 loc) · 1.78 KB
/
NetListView.cpp
File metadata and controls
60 lines (54 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*****************************************************************
* Copyright (c) 2005 Simon Taylor, Tim de Jong *
* *
* All rights reserved. *
* Distributed under the terms of the MIT License. *
*****************************************************************/
#include "NetListView.h"
#include "NetListItem.h"
#include <Region.h>
#include <cstdio>
bool NetListView::UpdateItem(BListItem* item, void* data)
{
//NetListView* curView = (NetListView*)data;
//BFont curFont;
//curView->GetFont(&curFont);
//item->SetWidth(curView->Bounds().Width());
//float wrapWidth = (curView->Bounds().Width() - 6)/curFont.Size();
((NetListItem*)item)->CalcWordWrap(20);
return false;
}
NetListView::NetListView(BRect frame, const char *name, list_view_type type = B_SINGLE_SELECTION_LIST, uint32 resizeMask = B_FOLLOW_LEFT, uint32 flags = B_WILL_DRAW)
: BListView(frame, name, type, resizeMask, flags)
{
oldWidth = frame.Width();
}
void NetListView::FrameResized(float width, float height)
{
BListView::FrameResized(width, height);
//Ensure the bevel on the right is drawn properly
if(width < oldWidth)
oldWidth = width;
PushState();
BRect invalRect(oldWidth, 0, oldWidth, height);
ConvertFromParent(&invalRect);
BRegion lineRegion(invalRect);
ConstrainClippingRegion(&lineRegion);
Draw(invalRect);
oldWidth = width;
PopState();
//Do word wrapping
BFont curFont;
GetFont(&curFont);
float itemWidth = Bounds().Width();
float wrapWidth = (itemWidth - 6)/curFont.Size();
for(int itemNum = 0; itemNum < CountItems(); itemNum++)
{
NetListItem* item = (NetListItem*)(Items()[itemNum]);
item->SetWidth(itemWidth);
item->CalcWordWrap(wrapWidth);
}
//DoForEach(UpdateItem, (void*)this);
Invalidate();
BListView::FrameResized(width, height);
}