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
This commit is contained in:
ejakowatz
2002-08-03 23:18:14 +00:00
parent 79f45f7f8f
commit ebbcbbca01
3 changed files with 188 additions and 97 deletions
+2
View File
@@ -60,6 +60,8 @@ class BLooperList
bool IsLooperValid(const BLooper* l); bool IsLooperValid(const BLooper* l);
bool RemoveLooper(BLooper* l); bool RemoveLooper(BLooper* l);
void GetLooperList(BList* list); void GetLooperList(BList* list);
int32 CountLoopers();
BLooper* LooperAt(int32 index);
BLooper* LooperForThread(thread_id tid); BLooper* LooperForThread(thread_id tid);
BLooper* LooperForName(const char* name); BLooper* LooperForName(const char* name);
BLooper* LooperForPort(port_id port); BLooper* LooperForPort(port_id port);
+165 -97
View File
@@ -44,8 +44,11 @@
#include <PropertyInfo.h> #include <PropertyInfo.h>
#include <RegistrarDefs.h> #include <RegistrarDefs.h>
#include <Roster.h> #include <Roster.h>
#include <Window.h>
// Project Includes ------------------------------------------------------------ // Project Includes ------------------------------------------------------------
#include <LooperList.h>
#include <ObjectLocker.h>
// Local Includes -------------------------------------------------------------- // Local Includes --------------------------------------------------------------
@@ -60,97 +63,97 @@ BLocker BApplication::_app_resources_lock("_app_resources_lock");
property_info gApplicationPropInfo[] = property_info gApplicationPropInfo[] =
{ {
{ {
"Window", "Window",
{}, {},
{B_INDEX_SPECIFIER, B_REVERSE_INDEX_SPECIFIER}, {B_INDEX_SPECIFIER, B_REVERSE_INDEX_SPECIFIER},
NULL, 0, NULL, 0,
{}, {},
{}, {},
{} {}
}, },
{ {
"Window", "Window",
{}, {},
{B_NAME_SPECIFIER}, {B_NAME_SPECIFIER},
NULL, 1, NULL, 1,
{}, {},
{}, {},
{} {}
}, },
{ {
"Looper", "Looper",
{}, {},
{B_INDEX_SPECIFIER, B_REVERSE_INDEX_SPECIFIER}, {B_INDEX_SPECIFIER, B_REVERSE_INDEX_SPECIFIER},
NULL, 2, NULL, 2,
{}, {},
{}, {},
{} {}
}, },
{ {
"Looper", "Looper",
{}, {},
{B_ID_SPECIFIER}, {B_ID_SPECIFIER},
NULL, 3, NULL, 3,
{}, {},
{}, {},
{} {}
}, },
{ {
"Looper", "Looper",
{}, {},
{B_NAME_SPECIFIER}, {B_NAME_SPECIFIER},
NULL, 4, NULL, 4,
{}, {},
{}, {},
{} {}
}, },
{ {
"Name", "Name",
{B_GET_PROPERTY}, {B_GET_PROPERTY},
{B_DIRECT_SPECIFIER}, {B_DIRECT_SPECIFIER},
NULL, 5, NULL, 5,
{B_STRING_TYPE}, {B_STRING_TYPE},
{}, {},
{} {}
}, },
{ {
"Window", "Window",
{B_COUNT_PROPERTIES}, {B_COUNT_PROPERTIES},
{B_DIRECT_SPECIFIER}, {B_DIRECT_SPECIFIER},
NULL, 5, NULL, 5,
{B_INT32_TYPE}, {B_INT32_TYPE},
{}, {},
{} {}
}, },
{ {
"Loopers", "Loopers",
{B_GET_PROPERTY}, {B_GET_PROPERTY},
{B_DIRECT_SPECIFIER}, {B_DIRECT_SPECIFIER},
NULL, 5, NULL, 5,
{B_MESSENGER_TYPE}, {B_MESSENGER_TYPE},
{}, {},
{} {}
}, },
{ {
"Windows", "Windows",
{B_GET_PROPERTY}, {B_GET_PROPERTY},
{B_DIRECT_SPECIFIER}, {B_DIRECT_SPECIFIER},
NULL, 5, NULL, 5,
{B_MESSENGER_TYPE}, {B_MESSENGER_TYPE},
{}, {},
{} {}
}, },
{ {
"Looper", "Looper",
{B_COUNT_PROPERTIES}, {B_COUNT_PROPERTIES},
{B_DIRECT_SPECIFIER}, {B_DIRECT_SPECIFIER},
NULL, 5, NULL, 5,
{B_INT32_TYPE}, {B_INT32_TYPE},
{}, {},
{} {}
}, },
{} {}
}; };
// argc/argv // argc/argv
@@ -398,14 +401,27 @@ BWindow* BApplication::WindowAt(int32 index) const
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int32 BApplication::CountLoopers() const int32 BApplication::CountLoopers() const
{ {
// Tough nut to crack; not documented *anywhere*. Dug down into BLooper and using namespace BPrivate;
// found its private sLooperCount var BObjectLocker<BLooperList> ListLock(gLooperList);
return 0; // not implemented if (ListLock.IsLocked())
{
return gLooperList.CountLoopers();
}
return B_ERROR; // Some bad, non-specific thing has happened
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BLooper* BApplication::LooperAt(int32 index) const BLooper* BApplication::LooperAt(int32 index) const
{ {
return NULL; // not implemented using namespace BPrivate;
BLooper* Looper = NULL;
BObjectLocker<BLooperList> ListLock(gLooperList);
if (ListLock.IsLocked())
{
Looper = gLooperList.LooperAt(index);
}
return Looper;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool BApplication::IsLaunching() const bool BApplication::IsLaunching() const
@@ -767,12 +783,64 @@ uint32 BApplication::InitialWorkspace()
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int32 BApplication::count_windows(bool incl_menus) const 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<BLooperList> ListLock(gLooperList);
if (ListLock.IsLocked())
{
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;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BWindow* BApplication::window_at(uint32 index, bool incl_menus) const 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<BLooperList> ListLock(gLooperList);
if (ListLock.IsLocked())
{
BLooper* Looper = NULL;
for (int32 i = 0; i < gLooperList.CountLoopers() && !Window; ++i)
{
Looper = gLooperList.LooperAt(i);
if (dynamic_cast<BWindow*>(Looper))
{
if (incl_menus || dynamic_cast<BMenuWindow*>(Looper) == NULL)
{
if (count == index)
{
Window = Looper;
}
else
{
++count;
}
}
}
}
}
return Window;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
status_t BApplication::get_window_list(BList* list, bool incl_menus) const status_t BApplication::get_window_list(BList* list, bool incl_menus) const
+21
View File
@@ -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) BLooper* BLooperList::LooperForThread(thread_id tid)
{ {
BAutolock Listlock(fLock); BAutolock Listlock(fLock);