Patch by Hamish Morrison in bluetooth server: simplify code in the bluetooth console 'Output' class.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40237 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Alex Wilson
2011-01-15 06:36:18 +00:00
parent c5b852f95f
commit 6420e23bca
2 changed files with 28 additions and 35 deletions
+24 -31
View File
@@ -21,15 +21,16 @@
*/ */
OutputView::OutputView() OutputView::OutputView(const char* name)
: :
BGroupView("OutputView", B_VERTICAL, B_WILL_DRAW) BGroupView(name, B_VERTICAL, B_WILL_DRAW)
{ {
rgb_color textColor = {255, 255, 255}; rgb_color textColor = {255, 255, 255};
fTextView = new BTextView("Output", NULL, &textColor, B_WILL_DRAW); fTextView = new BTextView("Output", NULL, &textColor, B_WILL_DRAW);
fTextView->SetViewColor(0, 0, 100); fTextView->SetViewColor(0, 0, 100);
fTextView->MakeEditable(false); fTextView->MakeEditable(false);
BScrollView* scrollView = new BScrollView("ScrollView", fTextView, 0, false, true); BScrollView* scrollView = new BScrollView("ScrollView", fTextView,
0, false, true);
BLayoutBuilder::Group<>(this).Add(scrollView); BLayoutBuilder::Group<>(this).Add(scrollView);
} }
@@ -41,10 +42,10 @@ Output* Output::sInstance = 0;
Output::Output() Output::Output()
: :
BWindow(BRect(200, 200, 800, 800), "Output", B_TITLED_WINDOW, B_NOT_ZOOMABLE) BWindow(BRect(200, 200, 800, 800), "Output",
B_TITLED_WINDOW, B_NOT_ZOOMABLE)
{ {
fTabsList = new BList(20); fOutputViewsList = new BList();
fOutputViewsList = new BList(20);
fReset = new BButton("reset all", "Clear", fReset = new BButton("reset all", "Clear",
new BMessage(kMsgOutputReset), B_WILL_DRAW); new BMessage(kMsgOutputReset), B_WILL_DRAW);
@@ -54,8 +55,7 @@ Output::Output()
fTabView = new BTabView("tab_view", B_WIDTH_FROM_LABEL, fTabView = new BTabView("tab_view", B_WIDTH_FROM_LABEL,
B_FULL_UPDATE_ON_RESIZE | B_WILL_DRAW | B_NAVIGABLE_JUMP); B_FULL_UPDATE_ON_RESIZE | B_WILL_DRAW | B_NAVIGABLE_JUMP);
fTabView->AddTab(fAll = new OutputView(), fAllTab = new BTab()); fTabView->AddTab(fAll = new OutputView("All"));
fAllTab->SetLabel("All");
BLayoutBuilder::Group<>(this, B_VERTICAL, 5) BLayoutBuilder::Group<>(this, B_VERTICAL, 5)
.Add(fTabView) .Add(fTabView)
@@ -74,18 +74,15 @@ Output::Output()
void void
Output::AddTab(const char* text, int32 index) Output::AddTab(const char* text, uint32 index)
{ {
OutputView* customOutput; OutputView* customOutput;
BTab* customTab;
Lock(); Lock();
fTabView->AddTab(customOutput = new OutputView(), customTab = new BTab()); fTabView->AddTab(customOutput = new OutputView(text));
customTab->SetLabel(text);
fTabView->Invalidate(); fTabView->Invalidate();
Unlock(); Unlock();
fTabsList->AddItem(customTab, index);
fOutputViewsList->AddItem(customOutput, index); fOutputViewsList->AddItem(customOutput, index);
} }
@@ -93,8 +90,6 @@ Output::AddTab(const char* text, int32 index)
Output::~Output() Output::~Output()
{ {
/* BWindow::~BWindow();*/ /* BWindow::~BWindow();*/
delete fTabsList;
delete fOutputViewsList; delete fOutputViewsList;
} }
@@ -116,26 +111,24 @@ Output::QuitRequested()
} }
OutputView*
Output::_OutputViewForTab(int32 index)
{
return (OutputView*)fTabView->TabAt(index)->View();
}
void void
Output::MessageReceived(BMessage* msg) Output::MessageReceived(BMessage* msg)
{ {
switch(msg->what) { switch(msg->what) {
case kMsgOutputReset: case kMsgOutputReset:
for (int32 index = 0; index<fTabsList->CountItems(); index++) { _OutputViewForTab(fTabView->Selection())->Clear();
if (fTabsList->ItemAt(index) != NULL && ((BTab*)fTabsList
->ItemAt(index))->IsSelected())
((OutputView*)fOutputViewsList->ItemAt(index))->Clear();
}
break; break;
case kMsgOutputResetAll: case kMsgOutputResetAll:
{ for (int32 index = 0; index < fTabView->CountTabs(); ++index)
fAll->Clear(); _OutputViewForTab(index)->Clear();
for (int32 index = 0; index<fTabsList->CountItems(); index++) {
if (fTabsList->ItemAt(index) != NULL )
((OutputView*)fOutputViewsList->ItemAt(index))->Clear();
}
break; break;
}
default: default:
BWindow::MessageReceived(msg); BWindow::MessageReceived(msg);
break; break;
@@ -173,21 +166,21 @@ void
Output::Post(const char* text, uint32 index) Output::Post(const char* text, uint32 index)
{ {
Lock(); Lock();
OutputView* view = (OutputView*) fOutputViewsList->ItemAt(index); OutputView* view = (OutputView*)fOutputViewsList->ItemAt(index);
if (view != NULL) if (view != NULL)
Add(text, view); _Add(text, view);
else else
// Note that the view should be added before this! // Note that the view should be added before this!
// Dropping twice to the main // Dropping twice to the main
Add(text, fAll); _Add(text, fAll);
Unlock(); Unlock();
} }
void void
Output::Add(const char* text, OutputView* view) Output::_Add(const char* text, OutputView* view)
{ {
view->Add(text); view->Add(text);
fAll->Add(text); fAll->Add(text);
+4 -4
View File
@@ -22,7 +22,7 @@ const uint32 kMsgOutputResetAll = 'opra';
class OutputView : public BGroupView class OutputView : public BGroupView
{ {
public: public:
OutputView(); OutputView(const char* name);
void Add(const char* text) {fTextView->Insert(text);} void Add(const char* text) {fTextView->Insert(text);}
void Clear() {fTextView->Delete(0, fTextView->TextLength());} void Clear() {fTextView->Delete(0, fTextView->TextLength());}
@@ -43,7 +43,7 @@ public:
virtual void MessageReceived(BMessage* msg); virtual void MessageReceived(BMessage* msg);
virtual void FrameMoved(BPoint point); virtual void FrameMoved(BPoint point);
void AddTab(const char* text, int32 index); void AddTab(const char* text, uint32 index);
void Post(const char* text, uint32 index); void Post(const char* text, uint32 index);
int Postf(uint32 index, const char* format, ...); int Postf(uint32 index, const char* format, ...);
@@ -51,7 +51,8 @@ public:
private: private:
// functions // functions
Output(); Output();
void Add(const char* text, OutputView* view); void _Add(const char* text, OutputView* view);
OutputView* _OutputViewForTab(int32 index);
private: private:
// data // data
@@ -65,7 +66,6 @@ private:
BTabView* fTabView; BTabView* fTabView;
BList* fTabsList;
BList* fOutputViewsList; BList* fOutputViewsList;
}; };