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

View File

@ -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);

View File

@ -44,8 +44,11 @@
#include <PropertyInfo.h>
#include <RegistrarDefs.h>
#include <Roster.h>
#include <Window.h>
// Project Includes ------------------------------------------------------------
#include <LooperList.h>
#include <ObjectLocker.h>
// 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<BLooperList> 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<BLooperList> 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<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
{
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

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)
{
BAutolock Listlock(fLock);