From ebbcbbca0179ddc89aa0337547709ef4ead335ba Mon Sep 17 00:00:00 2001 From: ejakowatz Date: Sat, 3 Aug 2002 23:18:14 +0000 Subject: [PATCH] Implemented count_loopers()/windows() and looper/window_at(). Minor changes to BLooperList to accomodate. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@568 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/app/LooperList.h | 2 + src/kits/app/Application.cpp | 262 +++++++++++++++++++------------ src/kits/app/LooperList.cpp | 21 +++ 3 files changed, 188 insertions(+), 97 deletions(-) diff --git a/headers/private/app/LooperList.h b/headers/private/app/LooperList.h index 7358639d55..45b30de04f 100644 --- a/headers/private/app/LooperList.h +++ b/headers/private/app/LooperList.h @@ -60,6 +60,8 @@ class BLooperList bool IsLooperValid(const BLooper* l); bool RemoveLooper(BLooper* l); void GetLooperList(BList* list); + int32 CountLoopers(); + BLooper* LooperAt(int32 index); BLooper* LooperForThread(thread_id tid); BLooper* LooperForName(const char* name); BLooper* LooperForPort(port_id port); diff --git a/src/kits/app/Application.cpp b/src/kits/app/Application.cpp index b60482d6ae..3c8f060581 100644 --- a/src/kits/app/Application.cpp +++ b/src/kits/app/Application.cpp @@ -44,8 +44,11 @@ #include #include #include +#include // Project Includes ------------------------------------------------------------ +#include +#include // Local Includes -------------------------------------------------------------- @@ -60,97 +63,97 @@ BLocker BApplication::_app_resources_lock("_app_resources_lock"); property_info gApplicationPropInfo[] = { - { - "Window", - {}, - {B_INDEX_SPECIFIER, B_REVERSE_INDEX_SPECIFIER}, - NULL, 0, - {}, - {}, - {} - }, - { - "Window", - {}, - {B_NAME_SPECIFIER}, - NULL, 1, - {}, - {}, - {} - }, - { - "Looper", - {}, - {B_INDEX_SPECIFIER, B_REVERSE_INDEX_SPECIFIER}, - NULL, 2, - {}, - {}, - {} - }, - { - "Looper", - {}, - {B_ID_SPECIFIER}, - NULL, 3, - {}, - {}, - {} - }, - { - "Looper", - {}, - {B_NAME_SPECIFIER}, - NULL, 4, - {}, - {}, - {} - }, - { - "Name", - {B_GET_PROPERTY}, - {B_DIRECT_SPECIFIER}, - NULL, 5, - {B_STRING_TYPE}, - {}, - {} - }, - { - "Window", - {B_COUNT_PROPERTIES}, - {B_DIRECT_SPECIFIER}, - NULL, 5, - {B_INT32_TYPE}, - {}, - {} - }, - { - "Loopers", - {B_GET_PROPERTY}, - {B_DIRECT_SPECIFIER}, - NULL, 5, - {B_MESSENGER_TYPE}, - {}, - {} - }, - { - "Windows", - {B_GET_PROPERTY}, - {B_DIRECT_SPECIFIER}, - NULL, 5, - {B_MESSENGER_TYPE}, - {}, - {} - }, - { - "Looper", - {B_COUNT_PROPERTIES}, - {B_DIRECT_SPECIFIER}, - NULL, 5, - {B_INT32_TYPE}, - {}, - {} - }, - {} + { + "Window", + {}, + {B_INDEX_SPECIFIER, B_REVERSE_INDEX_SPECIFIER}, + NULL, 0, + {}, + {}, + {} + }, + { + "Window", + {}, + {B_NAME_SPECIFIER}, + NULL, 1, + {}, + {}, + {} + }, + { + "Looper", + {}, + {B_INDEX_SPECIFIER, B_REVERSE_INDEX_SPECIFIER}, + NULL, 2, + {}, + {}, + {} + }, + { + "Looper", + {}, + {B_ID_SPECIFIER}, + NULL, 3, + {}, + {}, + {} + }, + { + "Looper", + {}, + {B_NAME_SPECIFIER}, + NULL, 4, + {}, + {}, + {} + }, + { + "Name", + {B_GET_PROPERTY}, + {B_DIRECT_SPECIFIER}, + NULL, 5, + {B_STRING_TYPE}, + {}, + {} + }, + { + "Window", + {B_COUNT_PROPERTIES}, + {B_DIRECT_SPECIFIER}, + NULL, 5, + {B_INT32_TYPE}, + {}, + {} + }, + { + "Loopers", + {B_GET_PROPERTY}, + {B_DIRECT_SPECIFIER}, + NULL, 5, + {B_MESSENGER_TYPE}, + {}, + {} + }, + { + "Windows", + {B_GET_PROPERTY}, + {B_DIRECT_SPECIFIER}, + NULL, 5, + {B_MESSENGER_TYPE}, + {}, + {} + }, + { + "Looper", + {B_COUNT_PROPERTIES}, + {B_DIRECT_SPECIFIER}, + NULL, 5, + {B_INT32_TYPE}, + {}, + {} + }, + {} }; // argc/argv @@ -398,14 +401,27 @@ BWindow* BApplication::WindowAt(int32 index) const //------------------------------------------------------------------------------ int32 BApplication::CountLoopers() const { - // Tough nut to crack; not documented *anywhere*. Dug down into BLooper and - // found its private sLooperCount var - return 0; // not implemented + using namespace BPrivate; + BObjectLocker ListLock(gLooperList); + if (ListLock.IsLocked()) + { + return gLooperList.CountLoopers(); + } + + return B_ERROR; // Some bad, non-specific thing has happened } //------------------------------------------------------------------------------ BLooper* BApplication::LooperAt(int32 index) const { - return NULL; // not implemented + using namespace BPrivate; + BLooper* Looper = NULL; + BObjectLocker ListLock(gLooperList); + if (ListLock.IsLocked()) + { + Looper = gLooperList.LooperAt(index); + } + + return Looper; } //------------------------------------------------------------------------------ bool BApplication::IsLaunching() const @@ -767,12 +783,64 @@ uint32 BApplication::InitialWorkspace() //------------------------------------------------------------------------------ int32 BApplication::count_windows(bool incl_menus) const { - return 0; // not implemented + 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; + BObjectLocker ListLock(gLooperList); + if (ListLock.IsLocked()) + { + BLooper* Looper = NULL; + for (int32 i = 0; i < gLooperList.CountLoopers(); ++i) + { + Looper = gLooperList.LooperAt(i); + if (dynamic_cast(Looper)) + { + if (incl_menus || dynamic_cast(Looper) == NULL) + { + ++count; + } + } + } + } + + return count; } //------------------------------------------------------------------------------ BWindow* BApplication::window_at(uint32 index, bool incl_menus) const { - return NULL; // not implemented + using namespace BPrivate; + + // Windows are BLoopers, so we can just check each BLooper to see if it's + // a BWindow (or BMenuWindow) + uint32 count = 0; + BWindow* Window = NULL; + BObjectLocker ListLock(gLooperList); + if (ListLock.IsLocked()) + { + BLooper* Looper = NULL; + for (int32 i = 0; i < gLooperList.CountLoopers() && !Window; ++i) + { + Looper = gLooperList.LooperAt(i); + if (dynamic_cast(Looper)) + { + if (incl_menus || dynamic_cast(Looper) == NULL) + { + if (count == index) + { + Window = Looper; + } + else + { + ++count; + } + } + } + } + } + + return Window; } //------------------------------------------------------------------------------ status_t BApplication::get_window_list(BList* list, bool incl_menus) const diff --git a/src/kits/app/LooperList.cpp b/src/kits/app/LooperList.cpp index 052edfaa09..06cfe8548b 100644 --- a/src/kits/app/LooperList.cpp +++ b/src/kits/app/LooperList.cpp @@ -125,6 +125,27 @@ void BLooperList::GetLooperList(BList* list) } } //------------------------------------------------------------------------------ +int32 BLooperList::CountLoopers() +{ + BAutolock Listlock(fLock); + AssertLocked(); + return (int32)fData.size(); +} +//------------------------------------------------------------------------------ +BLooper* BLooperList::LooperAt(int32 index) +{ + BAutolock Listlock(fLock); + AssertLocked(); + + BLooper* Looper = NULL; + if (index < (int32)fData.size()) + { + Looper = fData[(uint32)index].looper; + } + + return Looper; +} +//------------------------------------------------------------------------------ BLooper* BLooperList::LooperForThread(thread_id tid) { BAutolock Listlock(fLock);