From 42f07f3fead9c9b79fab5695e37f08c8a6c897c6 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 17 Jun 2009 14:18:55 +0000 Subject: [PATCH] * Added ImageListView showing the list of images. It will probably eventually become a tree view, showing the source files as subitems of the images. * Added the image list to the team window and changed the layout more towards what it's intended to look like. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31087 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/debugger/Jamfile | 1 + .../gui/team_window/ImageListView.cpp | 244 ++++++++++++++++++ .../debugger/gui/team_window/ImageListView.h | 47 ++++ .../debugger/gui/team_window/TeamWindow.cpp | 24 +- .../debugger/gui/team_window/TeamWindow.h | 2 + 5 files changed, 313 insertions(+), 5 deletions(-) create mode 100644 src/apps/debugger/gui/team_window/ImageListView.cpp create mode 100644 src/apps/debugger/gui/team_window/ImageListView.h diff --git a/src/apps/debugger/Jamfile b/src/apps/debugger/Jamfile index 0aad8445f9..569ed2803d 100644 --- a/src/apps/debugger/Jamfile +++ b/src/apps/debugger/Jamfile @@ -28,6 +28,7 @@ Application Debugger : Variant.cpp # gui/team_window + ImageListView.cpp TeamWindow.cpp ThreadListView.cpp diff --git a/src/apps/debugger/gui/team_window/ImageListView.cpp b/src/apps/debugger/gui/team_window/ImageListView.cpp new file mode 100644 index 0000000000..7ccd1a8af7 --- /dev/null +++ b/src/apps/debugger/gui/team_window/ImageListView.cpp @@ -0,0 +1,244 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + +#include "ImageListView.h" + +#include + +#include + +#include +#include + +#include +#include + +#include "table/TableColumns.h" + + +enum { + MSG_SYNC_IMAGE_LIST = 'sytl' +}; + + +// #pragma mark - ImagesTableModel + + +class ImageListView::ImagesTableModel : public TableModel { +public: + ImagesTableModel(Team* team) + : + fTeam(team) + { + Update(); + } + + ~ImagesTableModel() + { + fTeam = NULL; + Update(); + } + + bool Update() + { + if (fTeam == NULL) { + for (int32 i = 0; Image* image = fImages.ItemAt(i); i++) + image->RemoveReference(); + fImages.MakeEmpty(); + + return true; + } + + AutoLocker locker(fTeam); + + ImageList::ConstIterator it = fTeam->Images().GetIterator(); + Image* newImage = it.Next(); + int32 index = 0; + + // remove no longer existing images + while (Image* oldImage = fImages.ItemAt(index)) { + if (oldImage == newImage) { + index++; + newImage = it.Next(); + } else { + // TODO: Not particularly efficient! + fImages.RemoveItemAt(index); + oldImage->RemoveReference(); + NotifyRowsRemoved(index, 1); + } + } + + // add new images + int32 countBefore = fImages.CountItems(); + while (newImage != NULL) { + if (!fImages.AddItem(newImage)) + return false; + + newImage->AddReference(); + newImage = it.Next(); + } + + int32 count = fImages.CountItems(); + if (count > countBefore) + NotifyRowsAdded(countBefore, count - countBefore); + + return true; + } + + virtual int32 CountColumns() const + { + return 2; + } + + virtual int32 CountRows() const + { + return fImages.CountItems(); + } + + virtual bool GetValueAt(int32 rowIndex, int32 columnIndex, Variant& value) + { + Image* image = fImages.ItemAt(rowIndex); + if (image == NULL) + return false; + + switch (columnIndex) { + case 0: + value.SetTo(image->ID()); + return true; + case 1: + value.SetTo(image->Name(), VARIANT_DONT_COPY_DATA); + return true; + default: + return false; + } + } + + Image* ImageAt(int32 index) const + { + return fImages.ItemAt(index); + } + +private: + Team* fTeam; + BObjectList fImages; +}; + + +// #pragma mark - ImageListView + + +ImageListView::ImageListView() + : + BGroupView(B_VERTICAL), + fTeam(NULL), + fImagesTable(NULL), + fImagesTableModel(NULL) +{ + SetName("Images"); +} + + +ImageListView::~ImageListView() +{ + SetTeam(NULL); + fImagesTable->SetTableModel(NULL); + delete fImagesTableModel; +} + + +/*static*/ ImageListView* +ImageListView::Create() +{ + ImageListView* self = new ImageListView; + + try { + self->_Init(); + } catch (...) { + delete self; + throw; + } + + return self; +} + + +void +ImageListView::SetTeam(Team* team) +{ + if (team == fTeam) + return; + + if (fTeam != NULL) { + fTeam->RemoveListener(this); + fImagesTable->SetTableModel(NULL); + delete fImagesTableModel; + fImagesTableModel = NULL; + } + + fTeam = team; + + if (fTeam != NULL) { + fImagesTableModel = new(std::nothrow) ImagesTableModel(fTeam); + fImagesTable->SetTableModel(fImagesTableModel); + fImagesTable->ResizeAllColumnsToPreferred(); + fTeam->AddListener(this); + } +} + + +void +ImageListView::MessageReceived(BMessage* message) +{ + switch (message->what) { + case MSG_SYNC_IMAGE_LIST: + if (fImagesTableModel != NULL) + fImagesTableModel->Update(); + break; + default: + BGroupView::MessageReceived(message); + break; + } +} + + +void +ImageListView::ImageAdded(Team* team, Image* image) +{ + Looper()->PostMessage(MSG_SYNC_IMAGE_LIST, this); +} + + +void +ImageListView::ImageRemoved(Team* team, Image* image) +{ + Looper()->PostMessage(MSG_SYNC_IMAGE_LIST, this); +} + + +void +ImageListView::TableRowInvoked(Table* table, int32 rowIndex) +{ +// if (fImagesTableModel != NULL) { +// Image* image = fImagesTableModel->ImageAt(rowIndex); +// if (image != NULL) +// fParent->OpenImageWindow(image); +// } +} + + +void +ImageListView::_Init() +{ + fImagesTable = new Table("images list", 0); + AddChild(fImagesTable->ToView()); + + // columns + fImagesTable->AddColumn(new Int32TableColumn(0, "ID", 40, 20, 1000, + B_TRUNCATE_MIDDLE, B_ALIGN_RIGHT)); + fImagesTable->AddColumn(new StringTableColumn(1, "Name", 80, 40, 1000, + B_TRUNCATE_END, B_ALIGN_LEFT)); + + fImagesTable->AddTableListener(this); +} diff --git a/src/apps/debugger/gui/team_window/ImageListView.h b/src/apps/debugger/gui/team_window/ImageListView.h new file mode 100644 index 0000000000..5b24d2a34c --- /dev/null +++ b/src/apps/debugger/gui/team_window/ImageListView.h @@ -0,0 +1,47 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef IMAGE_LIST_VIEW_H +#define IMAGE_LIST_VIEW_H + +#include + +#include "table/Table.h" +#include "Team.h" + + +class ImageListView : public BGroupView, private Team::Listener, + private TableListener { +public: + ImageListView(); + ~ImageListView(); + + static ImageListView* Create(); + // throws + + void SetTeam(Team* team); + + virtual void MessageReceived(BMessage* message); + +private: + class ImagesTableModel; + +private: + // Team::Listener + virtual void ImageAdded(Team* team, Image* image); + virtual void ImageRemoved(Team* team, Image* image); + + // TableListener + virtual void TableRowInvoked(Table* table, int32 rowIndex); + + void _Init(); + +private: + Team* fTeam; + Table* fImagesTable; + ImagesTableModel* fImagesTableModel; +}; + + +#endif // IMAGE_LIST_VIEW_H diff --git a/src/apps/debugger/gui/team_window/TeamWindow.cpp b/src/apps/debugger/gui/team_window/TeamWindow.cpp index 17491e90f8..313daf1ada 100644 --- a/src/apps/debugger/gui/team_window/TeamWindow.cpp +++ b/src/apps/debugger/gui/team_window/TeamWindow.cpp @@ -8,7 +8,10 @@ #include #include #include +#include +#include +#include "ImageListView.h" #include "Team.h" #include "ThreadListView.h" @@ -18,12 +21,13 @@ TeamWindow::TeamWindow(::Team* team, Listener* listener) : - BWindow(BRect(100, 100, 399, 299), _GetWindowTitle(team).String(), + BWindow(BRect(100, 100, 699, 499), _GetWindowTitle(team).String(), B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS), fTeam(team), fListener(listener), fTabView(NULL), - fThreadListView(NULL) + fThreadListView(NULL), + fImageListView(NULL) { } @@ -83,16 +87,26 @@ TeamWindow::_Init() BGroupLayout* rootLayout = new BGroupLayout(B_VERTICAL); SetLayout(rootLayout); - fTabView = new BTabView("tab view"); - + BSplitView* mainSplitView = new BSplitView(B_VERTICAL, 3.0f); BGroupLayoutBuilder(rootLayout) - .Add(fTabView); + .Add(mainSplitView); + + fTabView = new BTabView("tab view"); + mainSplitView->AddChild(fTabView, 0.4f); fTabView->AddTab(fThreadListView = ThreadListView::Create()); // fTabView->AddTab(fTeamsPage = new TeamsPage(this)); // fTabView->AddTab(fThreadsPage = new ThreadsPage(this)); + BSplitView* imageAndSourceSplitView = new BSplitView(B_HORIZONTAL, 3.0f); + mainSplitView->AddChild(imageAndSourceSplitView); + + fImageListView = ImageListView::Create(); + imageAndSourceSplitView->AddChild(fImageListView); + imageAndSourceSplitView->AddChild(new BTextView("source view"), 2.0f); + fThreadListView->SetTeam(fTeam); + fImageListView->SetTeam(fTeam); } diff --git a/src/apps/debugger/gui/team_window/TeamWindow.h b/src/apps/debugger/gui/team_window/TeamWindow.h index 670cc42dcf..ac19bcd8a3 100644 --- a/src/apps/debugger/gui/team_window/TeamWindow.h +++ b/src/apps/debugger/gui/team_window/TeamWindow.h @@ -10,6 +10,7 @@ class BTabView; +class ImageListView; class Team; class ThreadListView; @@ -37,6 +38,7 @@ private: Listener* fListener; BTabView* fTabView; ThreadListView* fThreadListView; + ImageListView* fImageListView; };