1 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
3 // Copyright (c) 2003-2004, OpenBeOS
5 // This software is part of the OpenBeOS distribution and is covered
9 // File: ResourceUsageWindow.cpp
10 // Author: Sikosis, Jérôme Duval
11 // Description: Devices Preferences
12 // Created : July 19, 2003
14 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
17 // Includes ------------------------------------------------------------------
21 #include <ScrollView.h>
26 #include "DevicesInfo.h"
27 #include "DevicesWindows.h"
29 #undef B_TRANSLATION_CONTEXT
30 #define B_TRANSLATION_CONTEXT "ResourceUsageWindow"
32 class IRQDMAItem
: public BListItem
35 IRQDMAItem(int32 number
, const char* name
);
37 virtual void DrawItem(BView
*, BRect
, bool = false);
44 IRQDMAItem::IRQDMAItem(int32 number
, const char* name
)
51 IRQDMAItem::~IRQDMAItem()
56 /***********************************************************
58 ***********************************************************/
60 IRQDMAItem::DrawItem(BView
*owner
, BRect itemRect
, bool complete
)
62 rgb_color kBlack
= { 0,0,0,0 };
63 rgb_color kHighlight
= { 156,154,156,0 };
65 if (IsSelected() || complete
) {
70 color
= owner
->ViewColor();
72 owner
->SetHighColor(color
);
73 owner
->SetLowColor(color
);
74 owner
->FillRect(itemRect
);
75 owner
->SetHighColor(kBlack
);
78 owner
->SetLowColor(owner
->ViewColor());
81 BFont font
= be_plain_font
;
83 font
.GetHeight(&finfo
);
85 BPoint point
= BPoint(itemRect
.left
+ 5, itemRect
.bottom
- finfo
.descent
+ 1);
87 owner
->SetHighColor(kBlack
);
88 owner
->SetFont(be_plain_font
);
89 owner
->MovePenTo(point
);
92 sprintf(string
, "%ld", fNumber
);
93 owner
->DrawString(string
);
95 point
+= BPoint(28, 0);
96 owner
->MovePenTo(point
);
97 owner
->DrawString(fName
);
100 class RangeItem
: public BListItem
103 RangeItem(uint32 lowAddress
, uint32 highAddress
, const char* name
);
105 virtual void DrawItem(BView
*, BRect
, bool = false);
106 static int Compare(const void *firstArg
, const void *secondArg
);
109 uint32 fLowAddress
, fHighAddress
;
113 RangeItem::RangeItem(uint32 lowAddress
, uint32 highAddress
, const char* name
)
115 fLowAddress(lowAddress
),
116 fHighAddress(highAddress
)
118 fName
= strdup(name
);
121 RangeItem::~RangeItem()
126 /***********************************************************
128 ***********************************************************/
130 RangeItem::DrawItem(BView
*owner
, BRect itemRect
, bool complete
)
132 rgb_color kBlack
= { 0,0,0,0 };
133 rgb_color kHighlight
= { 156,154,156,0 };
135 if (IsSelected() || complete
) {
140 color
= owner
->ViewColor();
142 owner
->SetHighColor(color
);
143 owner
->SetLowColor(color
);
144 owner
->FillRect(itemRect
);
145 owner
->SetHighColor(kBlack
);
148 owner
->SetLowColor(owner
->ViewColor());
151 BFont font
= be_plain_font
;
153 font
.GetHeight(&finfo
);
155 BPoint point
= BPoint(itemRect
.left
+ 17, itemRect
.bottom
- finfo
.descent
+ 1);
156 owner
->SetFont(be_fixed_font
);
157 owner
->SetHighColor(kBlack
);
158 owner
->MovePenTo(point
);
160 if (fLowAddress
>= 0) {
162 sprintf(string
, "0x%04lx - 0x%04lx", fLowAddress
, fHighAddress
);
163 owner
->DrawString(string
);
165 point
+= BPoint(174, 0);
166 owner
->SetFont(be_plain_font
);
167 owner
->MovePenTo(point
);
168 owner
->DrawString(fName
);
172 RangeItem::Compare(const void *firstArg
, const void *secondArg
)
174 const RangeItem
*item1
= *static_cast<const RangeItem
* const *>(firstArg
);
175 const RangeItem
*item2
= *static_cast<const RangeItem
* const *>(secondArg
);
177 if (item1
->fLowAddress
< item2
->fLowAddress
) {
179 } else if (item1
->fLowAddress
> item2
->fLowAddress
) {
187 // ----------------------------------------------------------------------------
190 // ResourceUsageWindow - Constructor
191 ResourceUsageWindow::ResourceUsageWindow(BRect frame
, BList
&list
)
192 : BWindow (frame
, B_TRANSLATE("Resource Usage"), B_TITLED_WINDOW_LOOK
,
193 B_NORMAL_WINDOW_FEEL
, B_NOT_ZOOMABLE
|B_NOT_RESIZABLE
)
199 // ----------------------------------------------------------------------------
202 // ResourceUsageWindow - Destructor
203 ResourceUsageWindow::~ResourceUsageWindow()
207 // ----------------------------------------------------------------------------
210 // ResourceUsageWindow::InitWindow -- Initialization Commands here
211 void ResourceUsageWindow::InitWindow(BList
&list
)
213 BRect rtab
= Bounds();
214 BRect rlist
= Bounds();
218 rlist
.right
-= 15 + B_V_SCROLL_BAR_WIDTH
;
221 // Create the TabView and Tabs
222 BTabView
*tabView
= new BTabView(rtab
,"resource_usage_tabview");
223 tabView
->SetViewUIColor(B_PANEL_BACKGROUND_COLOR
);
225 rtab
= tabView
->Bounds();
228 // Create the ListViews
229 BListView
*IRQListView
= new BListView(rlist
, "IRQListView",
230 B_SINGLE_SELECTION_LIST
, B_FOLLOW_LEFT
| B_FOLLOW_TOP
,
231 B_WILL_DRAW
| B_NAVIGABLE
);
232 BListView
*DMAListView
= new BListView(rlist
, "DMAListView",
233 B_SINGLE_SELECTION_LIST
, B_FOLLOW_LEFT
| B_FOLLOW_TOP
,
234 B_WILL_DRAW
| B_NAVIGABLE
);
235 BListView
*IORangeListView
= new BListView(rlist
, "IORangeListView",
236 B_SINGLE_SELECTION_LIST
, B_FOLLOW_LEFT
| B_FOLLOW_TOP
,
237 B_WILL_DRAW
| B_NAVIGABLE
);
238 BListView
*memoryListView
= new BListView(rlist
, "memoryListView",
239 B_SINGLE_SELECTION_LIST
, B_FOLLOW_LEFT
| B_FOLLOW_TOP
,
240 B_WILL_DRAW
| B_NAVIGABLE
);
242 BScrollView
*IRQScrollView
= new BScrollView("scroll_list1", IRQListView
,
243 B_FOLLOW_LEFT
|B_FOLLOW_TOP
, 0, false, true, B_FANCY_BORDER
);
244 BScrollView
*DMAScrollView
= new BScrollView("scroll_list2", DMAListView
,
245 B_FOLLOW_LEFT
|B_FOLLOW_TOP
, 0, false, true, B_FANCY_BORDER
);
246 BScrollView
*IORangeScrollView
= new BScrollView("scroll_list3",
247 IORangeListView
, B_FOLLOW_LEFT
|B_FOLLOW_TOP
, 0, false, true,
249 BScrollView
*memoryScrollView
= new BScrollView("scroll_list4",
250 memoryListView
, B_FOLLOW_LEFT
|B_FOLLOW_TOP
, 0, false, true,
253 BTab
*tab
= new BTab();
254 tabView
->AddTab(IRQScrollView
, tab
);
255 tab
->SetLabel(B_TRANSLATE("IRQ"));
257 tabView
->AddTab(DMAScrollView
, tab
);
258 tab
->SetLabel(B_TRANSLATE("DMA"));
260 tabView
->AddTab(IORangeScrollView
, tab
);
261 tab
->SetLabel(B_TRANSLATE("IO Range"));
263 tabView
->AddTab(memoryScrollView
, tab
);
264 tab
->SetLabel(B_TRANSLATE("Memory Range"));
269 for (int i
=0;i
<16;mask
<<=1,i
++) {
272 for (int32 j
=0; j
<list
.CountItems(); j
++) {
273 DevicesInfo
*deviceInfo
= (DevicesInfo
*)list
.ItemAt(j
);
274 struct device_configuration
*current
= deviceInfo
->GetCurrent();
275 resource_descriptor r
;
277 int32 num
= count_resource_descriptors_of_type(current
,
280 for (int32 k
=0;k
<num
;k
++) {
281 get_nth_resource_descriptor_of_type(current
, k
, B_IRQ_RESOURCE
,
282 &r
, sizeof(resource_descriptor
));
284 if (mask
& r
.d
.m
.mask
) {
285 IRQListView
->AddItem(new IRQDMAItem(first
? i
: -1,
286 deviceInfo
->GetCardName()));
293 IRQListView
->AddItem(new IRQDMAItem(i
, ""));
301 for (int i
=0;i
<8;mask
<<=1,i
++) {
304 for (int32 j
=0; j
<list
.CountItems(); j
++) {
305 DevicesInfo
*deviceInfo
= (DevicesInfo
*)list
.ItemAt(j
);
306 struct device_configuration
*current
= deviceInfo
->GetCurrent();
307 resource_descriptor r
;
309 int32 num
= count_resource_descriptors_of_type(current
,
312 for (int32 k
=0;k
<num
;k
++) {
313 get_nth_resource_descriptor_of_type(current
, k
,
314 B_DMA_RESOURCE
, &r
, sizeof(resource_descriptor
));
316 if (mask
& r
.d
.m
.mask
) {
317 DMAListView
->AddItem(new IRQDMAItem(first
? i
: -1,
318 deviceInfo
->GetCardName()));
325 DMAListView
->AddItem(new IRQDMAItem(i
, ""));
331 for (int32 j
=0; j
<list
.CountItems(); j
++) {
332 DevicesInfo
*deviceInfo
= (DevicesInfo
*)list
.ItemAt(j
);
333 struct device_configuration
*current
= deviceInfo
->GetCurrent();
334 resource_descriptor r
;
336 int32 num
= count_resource_descriptors_of_type(current
,
339 for (int32 k
=0;k
<num
;k
++) {
340 get_nth_resource_descriptor_of_type(current
, k
,
341 B_IO_PORT_RESOURCE
, &r
, sizeof(resource_descriptor
));
343 IORangeListView
->AddItem(new RangeItem(r
.d
.r
.minbase
,
344 r
.d
.r
.minbase
+ r
.d
.r
.len
- 1, deviceInfo
->GetCardName()));
348 IORangeListView
->SortItems(&RangeItem::Compare
);
352 for (int32 j
=0; j
<list
.CountItems(); j
++) {
353 DevicesInfo
*deviceInfo
= (DevicesInfo
*)list
.ItemAt(j
);
354 struct device_configuration
*current
= deviceInfo
->GetCurrent();
355 resource_descriptor r
;
357 int32 num
= count_resource_descriptors_of_type(current
,
360 for (int32 k
=0;k
<num
;k
++) {
361 get_nth_resource_descriptor_of_type(current
, k
, B_MEMORY_RESOURCE
,
362 &r
, sizeof(resource_descriptor
));
364 memoryListView
->AddItem(new RangeItem(r
.d
.r
.minbase
,
365 r
.d
.r
.minbase
+ r
.d
.r
.len
- 1, deviceInfo
->GetCardName()));
369 memoryListView
->SortItems(&RangeItem::Compare
);
373 BBox
*background
= new BBox(Bounds(), "background");
374 background
->SetBorder(B_NO_BORDER
);
375 AddChild(background
);
376 background
->AddChild(tabView
);
378 // ----------------------------------------------------------------------------
381 // ResourceUsageWindow::MessageReceived -- receives messages
383 ResourceUsageWindow::MessageReceived (BMessage
*message
)
385 switch(message
->what
)
388 BWindow::MessageReceived(message
);
392 // ----------------------------------------------------------------------------