Implemented get_window_list(), and used it in count_windows() and window_at(). That simplified the code a lot. Removed some unused headers.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10389 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2004-12-11 10:12:59 +00:00
parent c387247ebe
commit a8fc5954c0
+35 -53
View File
@@ -30,7 +30,6 @@
#include <new> #include <new>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h>
// System Includes ------------------------------------------------------------- // System Includes -------------------------------------------------------------
#include <Alert.h> #include <Alert.h>
@@ -38,9 +37,9 @@
#include <Application.h> #include <Application.h>
#include <AppMisc.h> #include <AppMisc.h>
#include <Cursor.h> #include <Cursor.h>
#include <Debug.h>
#include <Entry.h> #include <Entry.h>
#include <File.h> #include <File.h>
#include <InterfaceDefs.h>
#include <Locker.h> #include <Locker.h>
#include <Path.h> #include <Path.h>
#include <PropertyInfo.h> #include <PropertyInfo.h>
@@ -1067,70 +1066,53 @@ uint32 BApplication::InitialWorkspace()
return fInitialWorkspace; return fInitialWorkspace;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int32 BApplication::count_windows(bool incl_menus) const int32
BApplication::count_windows(bool includeMenus) const
{ {
using namespace BPrivate;
// Windows are BLoopers, so we can just check each BLooper to see if it's
// a BWindow (or BMenuWindow)
int32 count = 0; int32 count = 0;
BObjectLocker<BLooperList> ListLock(gLooperList); BList windowList;
if (ListLock.IsLocked()) if (get_window_list(&windowList, includeMenus) == B_OK)
{ count = windowList.CountItems();
BLooper* Looper = NULL;
for (int32 i = 0; i < gLooperList.CountLoopers(); ++i)
{
Looper = gLooperList.LooperAt(i);
if (dynamic_cast<BWindow*>(Looper))
{
if (incl_menus || dynamic_cast<BMenuWindow*>(Looper) == NULL)
{
++count;
}
}
}
}
return count; return count;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BWindow* BApplication::window_at(uint32 index, bool incl_menus) const BWindow *
BApplication::window_at(uint32 index, bool includeMenus) const
{
BList windowList;
BWindow *window = NULL;
if (get_window_list(&windowList, includeMenus) == B_OK) {
if ((int32)index < windowList.CountItems())
window = static_cast<BWindow *>(windowList.ItemAt(index));
}
return window;
}
//------------------------------------------------------------------------------
status_t
BApplication::get_window_list(BList *list, bool includeMenus) const
{ {
using namespace BPrivate; using namespace BPrivate;
ASSERT(list);
// Windows are BLoopers, so we can just check each BLooper to see if it's // Windows are BLoopers, so we can just check each BLooper to see if it's
// a BWindow (or BMenuWindow) // a BWindow (or BMenuWindow)
uint32 count = 0; BObjectLocker<BLooperList> listLock(gLooperList);
BWindow* Window = NULL; if (listLock.IsLocked()) {
BObjectLocker<BLooperList> ListLock(gLooperList); BLooper *looper = NULL;
if (ListLock.IsLocked()) for (int32 i = 0; i < gLooperList.CountLoopers(); i++) {
{ looper = gLooperList.LooperAt(i);
BLooper* Looper = NULL; if (dynamic_cast<BWindow *>(looper)) {
for (int32 i = 0; i < gLooperList.CountLoopers() && !Window; ++i) if (includeMenus || dynamic_cast<BMenuWindow *>(looper) == NULL)
{ list->AddItem(looper);
Looper = gLooperList.LooperAt(i);
if (dynamic_cast<BWindow*>(Looper))
{
if (incl_menus || dynamic_cast<BMenuWindow*>(Looper) == NULL)
{
if (count == index)
{
Window = dynamic_cast<BWindow*>(Looper);
}
else
{
++count;
}
}
} }
} }
return B_OK;
} }
return Window;
}
//------------------------------------------------------------------------------
status_t BApplication::get_window_list(BList* list, bool incl_menus) const
{
return B_ERROR; return B_ERROR;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------