From 025e2c7bfef150810d7fa2bc0a1eab4fa8672483 Mon Sep 17 00:00:00 2001 From: Oliver Ruiz Dorantes Date: Thu, 26 Feb 2009 20:56:27 +0000 Subject: [PATCH] Separate stolen ListItem subclass to work on a new one for bluetooth devices git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29325 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/preferences/bluetooth/DeviceListItem.cpp | 87 +++++++++++++++++++ src/preferences/bluetooth/DeviceListItem.h | 28 ++++++ src/preferences/bluetooth/InquiryPanel.cpp | 90 +------------------- 3 files changed, 118 insertions(+), 87 deletions(-) create mode 100644 src/preferences/bluetooth/DeviceListItem.cpp create mode 100644 src/preferences/bluetooth/DeviceListItem.h diff --git a/src/preferences/bluetooth/DeviceListItem.cpp b/src/preferences/bluetooth/DeviceListItem.cpp new file mode 100644 index 0000000000..ade5904733 --- /dev/null +++ b/src/preferences/bluetooth/DeviceListItem.cpp @@ -0,0 +1,87 @@ +/* + * Copyright 2009, Oliver Ruiz Dorantes, + * All rights reserved. Distributed under the terms of the MIT License. + */ +#include "DeviceListItem.h" +#include + + +#include +#include + +namespace bluetooth { + +RangeItem::RangeItem(uint32 lowAddress, uint32 highAddress, const char* name) + : BListItem(), + fLowAddress(lowAddress), + fHighAddress(highAddress) +{ + fName = strdup(name); +} + +RangeItem::~RangeItem() +{ + delete fName; +} + +/*********************************************************** + * DrawItem + ***********************************************************/ +void +RangeItem::DrawItem(BView *owner, BRect itemRect, bool complete) +{ + rgb_color kBlack = { 0,0,0,0 }; + rgb_color kHighlight = { 156,154,156,0 }; + + if (IsSelected() || complete) { + rgb_color color; + if (IsSelected()) + color = kHighlight; + else + color = owner->ViewColor(); + + owner->SetHighColor(color); + owner->SetLowColor(color); + owner->FillRect(itemRect); + owner->SetHighColor(kBlack); + + } else { + owner->SetLowColor(owner->ViewColor()); + } + + BFont font = be_plain_font; + font_height finfo; + font.GetHeight(&finfo); + + BPoint point = BPoint(itemRect.left + 17, itemRect.bottom - finfo.descent + 1); + owner->SetFont(be_fixed_font); + owner->SetHighColor(kBlack); + owner->MovePenTo(point); + +/* if (fLowAddress >= 0) { + char string[255]; + sprintf(string, "0x%04lx - 0x%04lx", fLowAddress, fHighAddress); + owner->DrawString(string); + } + point += BPoint(174, 0);*/ + owner->SetFont(be_plain_font); + owner->MovePenTo(point); + owner->DrawString(fName); +} + +int +RangeItem::Compare(const void *firstArg, const void *secondArg) +{ + const RangeItem *item1 = *static_cast(firstArg); + const RangeItem *item2 = *static_cast(secondArg); + + if (item1->fLowAddress < item2->fLowAddress) { + return -1; + } else if (item1->fLowAddress > item2->fLowAddress) { + return 1; + } else + return 0; + +} + +} diff --git a/src/preferences/bluetooth/DeviceListItem.h b/src/preferences/bluetooth/DeviceListItem.h new file mode 100644 index 0000000000..404e473db9 --- /dev/null +++ b/src/preferences/bluetooth/DeviceListItem.h @@ -0,0 +1,28 @@ +/* + * Copyright 2009, Oliver Ruiz Dorantes, + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef DEVICELISTITEM_H_ +#define DEVICELISTITEM_H_ + +#include + +namespace bluetooth { + +// TODO: Implement a BluetoothDeviceListItem class, this one is stolen from somewhere ..... +class RangeItem : public BListItem +{ + public: + RangeItem(uint32 lowAddress, uint32 highAddress, const char* name); + ~RangeItem(); + virtual void DrawItem(BView *, BRect, bool = false); + static int Compare(const void *firstArg, const void *secondArg); + private: + char* fName; + uint32 fLowAddress, fHighAddress; +}; + +} + + +#endif diff --git a/src/preferences/bluetooth/InquiryPanel.cpp b/src/preferences/bluetooth/InquiryPanel.cpp index 4066b39d55..b291f16bd5 100644 --- a/src/preferences/bluetooth/InquiryPanel.cpp +++ b/src/preferences/bluetooth/InquiryPanel.cpp @@ -20,6 +20,9 @@ #include #include "InquiryPanel.h" +#include "DeviceListItem.h" + +using namespace bluetooth; // private funcionaility provided by kit extern uint8 GetInquiryTime(); @@ -34,93 +37,6 @@ static const uint32 kMsgAddListDevice = 'aDdv'; static const uint32 kMsgAddToRemoteList = 'aDdL'; static const uint32 kMsgSecond = 'sCMs'; -// TODO: Implement a BluetoothDeviceListItem class, this one is stolen from somewhere ..... -class RangeItem : public BListItem -{ - public: - RangeItem(uint32 lowAddress, uint32 highAddress, const char* name); - ~RangeItem(); - virtual void DrawItem(BView *, BRect, bool = false); - static int Compare(const void *firstArg, const void *secondArg); - private: - char* fName; - uint32 fLowAddress, fHighAddress; -}; - -RangeItem::RangeItem(uint32 lowAddress, uint32 highAddress, const char* name) - : BListItem(), - fLowAddress(lowAddress), - fHighAddress(highAddress) -{ - fName = strdup(name); -} - -RangeItem::~RangeItem() -{ - delete fName; -} - -/*********************************************************** - * DrawItem - ***********************************************************/ -void -RangeItem::DrawItem(BView *owner, BRect itemRect, bool complete) -{ - rgb_color kBlack = { 0,0,0,0 }; - rgb_color kHighlight = { 156,154,156,0 }; - - if (IsSelected() || complete) { - rgb_color color; - if (IsSelected()) - color = kHighlight; - else - color = owner->ViewColor(); - - owner->SetHighColor(color); - owner->SetLowColor(color); - owner->FillRect(itemRect); - owner->SetHighColor(kBlack); - - } else { - owner->SetLowColor(owner->ViewColor()); - } - - BFont font = be_plain_font; - font_height finfo; - font.GetHeight(&finfo); - - BPoint point = BPoint(itemRect.left + 17, itemRect.bottom - finfo.descent + 1); - owner->SetFont(be_fixed_font); - owner->SetHighColor(kBlack); - owner->MovePenTo(point); - -/* if (fLowAddress >= 0) { - char string[255]; - sprintf(string, "0x%04lx - 0x%04lx", fLowAddress, fHighAddress); - owner->DrawString(string); - } - point += BPoint(174, 0);*/ - owner->SetFont(be_plain_font); - owner->MovePenTo(point); - owner->DrawString(fName); -} - -int -RangeItem::Compare(const void *firstArg, const void *secondArg) -{ - const RangeItem *item1 = *static_cast(firstArg); - const RangeItem *item2 = *static_cast(secondArg); - - if (item1->fLowAddress < item2->fLowAddress) { - return -1; - } else if (item1->fLowAddress > item2->fLowAddress) { - return 1; - } else - return 0; - -} - - class PanelDiscoveryListener : public DiscoveryListener {