[haiku-commits] r40237 - haiku/trunk/src/servers/bluetooth

  • From: yourpalal2@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 15 Jan 2011 07:36:18 +0100 (CET)

Author: yourpalal
Date: 2011-01-15 07:36:18 +0100 (Sat, 15 Jan 2011)
New Revision: 40237
Changeset: http://dev.haiku-os.org/changeset/40237

Modified:
   haiku/trunk/src/servers/bluetooth/Output.cpp
   haiku/trunk/src/servers/bluetooth/Output.h
Log:
Patch by Hamish Morrison in bluetooth server: simplify code in the bluetooth 
console 'Output' class.


Modified: haiku/trunk/src/servers/bluetooth/Output.cpp
===================================================================
--- haiku/trunk/src/servers/bluetooth/Output.cpp        2011-01-14 14:06:08 UTC 
(rev 40236)
+++ haiku/trunk/src/servers/bluetooth/Output.cpp        2011-01-15 06:36:18 UTC 
(rev 40237)
@@ -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};
        fTextView = new BTextView("Output", NULL, &textColor, B_WILL_DRAW);
        fTextView->SetViewColor(0, 0, 100);
        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);
 }
@@ -41,10 +42,10 @@
 
 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(20);
+       fOutputViewsList = new BList();
 
        fReset = new BButton("reset all", "Clear", 
                new BMessage(kMsgOutputReset), B_WILL_DRAW);
@@ -54,8 +55,7 @@
        fTabView = new BTabView("tab_view", B_WIDTH_FROM_LABEL,
                B_FULL_UPDATE_ON_RESIZE | B_WILL_DRAW | B_NAVIGABLE_JUMP);
 
-       fTabView->AddTab(fAll = new OutputView(), fAllTab = new BTab()); 
-       fAllTab->SetLabel("All");
+       fTabView->AddTab(fAll = new OutputView("All"));
        
        BLayoutBuilder::Group<>(this, B_VERTICAL, 5)
                .Add(fTabView)
@@ -74,18 +74,15 @@
 
 
 void
-Output::AddTab(const char* text, int32 index) 
+Output::AddTab(const char* text, uint32 index)
 {
        OutputView* customOutput;
-       BTab*           customTab;
 
        Lock();
-       fTabView->AddTab(customOutput = new OutputView(), customTab = new 
BTab());
-       customTab->SetLabel(text);
+       fTabView->AddTab(customOutput = new OutputView(text));
        fTabView->Invalidate();
        Unlock();
 
-       fTabsList->AddItem(customTab, index);
        fOutputViewsList->AddItem(customOutput, index);
 }
 
@@ -93,8 +90,6 @@
 Output::~Output()
 {
 /*     BWindow::~BWindow();*/
-       
-       delete fTabsList;
        delete fOutputViewsList;
 }
 
@@ -116,26 +111,24 @@
 }
 
 
+OutputView*
+Output::_OutputViewForTab(int32 index)
+{
+       return (OutputView*)fTabView->TabAt(index)->View();
+}
+
+
 void
 Output::MessageReceived(BMessage* msg)
 {
        switch(msg->what) {
                case kMsgOutputReset:
-                       for (int32 index = 0; index<fTabsList->CountItems(); 
index++) {
-                               if (fTabsList->ItemAt(index) != NULL && 
((BTab*)fTabsList
-                                       ->ItemAt(index))->IsSelected())
-                                       
((OutputView*)fOutputViewsList->ItemAt(index))->Clear();
-                       }
+                       _OutputViewForTab(fTabView->Selection())->Clear();
                        break;
                case kMsgOutputResetAll:
-               {
-                       fAll->Clear();
-                       for (int32 index = 0; index<fTabsList->CountItems(); 
index++) {
-                               if (fTabsList->ItemAt(index) != NULL )  
-                                       
((OutputView*)fOutputViewsList->ItemAt(index))->Clear();        
-                       }
+                       for (int32 index = 0; index < fTabView->CountTabs(); 
++index)
+                               _OutputViewForTab(index)->Clear();
                        break;
-               }
                default:
                        BWindow::MessageReceived(msg);
                        break;
@@ -173,21 +166,21 @@
 Output::Post(const char* text, uint32 index)
 {
        Lock();
-       OutputView* view = (OutputView*) fOutputViewsList->ItemAt(index);
+       OutputView* view = (OutputView*)fOutputViewsList->ItemAt(index);
 
        if (view != NULL)
-               Add(text, view);
+               _Add(text, view);
        else
                // Note that the view should be added before this!
                // Dropping twice to the main
-               Add(text, fAll);
+               _Add(text, fAll);
        
        Unlock();
 }
 
 
 void
-Output::Add(const char* text, OutputView* view)
+Output::_Add(const char* text, OutputView* view)
 {      
        view->Add(text);
        fAll->Add(text);

Modified: haiku/trunk/src/servers/bluetooth/Output.h
===================================================================
--- haiku/trunk/src/servers/bluetooth/Output.h  2011-01-14 14:06:08 UTC (rev 
40236)
+++ haiku/trunk/src/servers/bluetooth/Output.h  2011-01-15 06:36:18 UTC (rev 
40237)
@@ -22,7 +22,7 @@
 class OutputView : public BGroupView
 {
 public:
-       OutputView();
+       OutputView(const char* name);
 
        void                    Add(const char* text)   
{fTextView->Insert(text);}
        void                    Clear()                                 
{fTextView->Delete(0, fTextView->TextLength());}
@@ -43,7 +43,7 @@
        virtual void    MessageReceived(BMessage* msg);
        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);
        int                             Postf(uint32 index, const char* format, 
...);
@@ -51,7 +51,8 @@
 private: 
        // functions
        Output();
-       void                    Add(const char* text, OutputView* view);
+       void                    _Add(const char* text, OutputView* view);
+       OutputView*             _OutputViewForTab(int32 index);
 
 private: 
        // data
@@ -65,7 +66,6 @@
        
        BTabView*               fTabView;
        
-       BList*                  fTabsList;
        BList*                  fOutputViewsList;
 };
 


Other related posts:

  • » [haiku-commits] r40237 - haiku/trunk/src/servers/bluetooth - yourpalal2