Moved the static stuff into a singleton.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34376 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -98,11 +98,6 @@ private:
|
|||||||
void _BuildDefaultPopUp();
|
void _BuildDefaultPopUp();
|
||||||
void _ShowPopUp(BView* target, BPoint where);
|
void _ShowPopUp(BView* target, BPoint where);
|
||||||
|
|
||||||
static bool sVisible;
|
|
||||||
static bool sVisibleInitialized;
|
|
||||||
static BLocker sLock;
|
|
||||||
static BList sList;
|
|
||||||
|
|
||||||
enum relation {
|
enum relation {
|
||||||
TARGET_UNKNOWN,
|
TARGET_UNKNOWN,
|
||||||
TARGET_IS_CHILD,
|
TARGET_IS_CHILD,
|
||||||
|
|||||||
@@ -11,11 +11,11 @@
|
|||||||
//! BDragger represents a replicant "handle".
|
//! BDragger represents a replicant "handle".
|
||||||
|
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <Autolock.h>
|
|
||||||
#include <Beep.h>
|
#include <Beep.h>
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
#include <Dragger.h>
|
#include <Dragger.h>
|
||||||
@@ -25,6 +25,8 @@
|
|||||||
#include <Shelf.h>
|
#include <Shelf.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
|
#include <AutoLocker.h>
|
||||||
|
|
||||||
#include <AppServerLink.h>
|
#include <AppServerLink.h>
|
||||||
#include <DragTrackingFilter.h>
|
#include <DragTrackingFilter.h>
|
||||||
#include <binary_compatibility/Interface.h>
|
#include <binary_compatibility/Interface.h>
|
||||||
@@ -34,11 +36,6 @@
|
|||||||
#include "ZombieReplicantView.h"
|
#include "ZombieReplicantView.h"
|
||||||
|
|
||||||
|
|
||||||
bool BDragger::sVisible;
|
|
||||||
bool BDragger::sVisibleInitialized;
|
|
||||||
BLocker BDragger::sLock("BDragger static");
|
|
||||||
BList BDragger::sList;
|
|
||||||
|
|
||||||
const uint32 kMsgDragStarted = 'Drgs';
|
const uint32 kMsgDragStarted = 'Drgs';
|
||||||
|
|
||||||
const unsigned char
|
const unsigned char
|
||||||
@@ -54,6 +51,58 @@ kHandBitmap[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
struct DraggerManager {
|
||||||
|
bool visible;
|
||||||
|
bool visibleInitialized;
|
||||||
|
BList list;
|
||||||
|
|
||||||
|
DraggerManager()
|
||||||
|
:
|
||||||
|
visible(false),
|
||||||
|
visibleInitialized(false),
|
||||||
|
fLock("BDragger static")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Lock()
|
||||||
|
{
|
||||||
|
return fLock.Lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Unlock()
|
||||||
|
{
|
||||||
|
fLock.Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
static DraggerManager* Default()
|
||||||
|
{
|
||||||
|
if (sDefaultInstance == NULL)
|
||||||
|
pthread_once(&sDefaultInitOnce, &_InitSingleton);
|
||||||
|
|
||||||
|
return sDefaultInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static void _InitSingleton()
|
||||||
|
{
|
||||||
|
sDefaultInstance = new DraggerManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
BLocker fLock;
|
||||||
|
|
||||||
|
static pthread_once_t sDefaultInitOnce;
|
||||||
|
static DraggerManager* sDefaultInstance;
|
||||||
|
};
|
||||||
|
|
||||||
|
pthread_once_t DraggerManager::sDefaultInitOnce = PTHREAD_ONCE_INIT;
|
||||||
|
DraggerManager* DraggerManager::sDefaultInstance = NULL;
|
||||||
|
|
||||||
|
} // unnamed namespace
|
||||||
|
|
||||||
|
|
||||||
BDragger::BDragger(BRect bounds, BView *target, uint32 rmask, uint32 flags)
|
BDragger::BDragger(BRect bounds, BView *target, uint32 rmask, uint32 flags)
|
||||||
: BView(bounds, "_dragger_", rmask, flags),
|
: BView(bounds, "_dragger_", rmask, flags),
|
||||||
fTarget(target),
|
fTarget(target),
|
||||||
@@ -329,8 +378,10 @@ BDragger::ShowAllDraggers()
|
|||||||
|
|
||||||
status_t status = link.Flush();
|
status_t status = link.Flush();
|
||||||
if (status == B_OK) {
|
if (status == B_OK) {
|
||||||
sVisible = true;
|
DraggerManager* manager = DraggerManager::Default();
|
||||||
sVisibleInitialized = true;
|
AutoLocker<DraggerManager> locker(manager);
|
||||||
|
manager->visible = true;
|
||||||
|
manager->visibleInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@@ -346,8 +397,10 @@ BDragger::HideAllDraggers()
|
|||||||
|
|
||||||
status_t status = link.Flush();
|
status_t status = link.Flush();
|
||||||
if (status == B_OK) {
|
if (status == B_OK) {
|
||||||
sVisible = false;
|
DraggerManager* manager = DraggerManager::Default();
|
||||||
sVisibleInitialized = true;
|
AutoLocker<DraggerManager> locker(manager);
|
||||||
|
manager->visible = false;
|
||||||
|
manager->visibleInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@@ -357,21 +410,22 @@ BDragger::HideAllDraggers()
|
|||||||
bool
|
bool
|
||||||
BDragger::AreDraggersDrawn()
|
BDragger::AreDraggersDrawn()
|
||||||
{
|
{
|
||||||
BAutolock _(sLock);
|
DraggerManager* manager = DraggerManager::Default();
|
||||||
|
AutoLocker<DraggerManager> locker(manager);
|
||||||
|
|
||||||
if (!sVisibleInitialized) {
|
if (!manager->visibleInitialized) {
|
||||||
BPrivate::AppServerLink link;
|
BPrivate::AppServerLink link;
|
||||||
link.StartMessage(AS_GET_SHOW_ALL_DRAGGERS);
|
link.StartMessage(AS_GET_SHOW_ALL_DRAGGERS);
|
||||||
|
|
||||||
status_t status;
|
status_t status;
|
||||||
if (link.FlushWithReply(status) == B_OK && status == B_OK) {
|
if (link.FlushWithReply(status) == B_OK && status == B_OK) {
|
||||||
link.Read<bool>(&sVisible);
|
link.Read<bool>(&manager->visible);
|
||||||
sVisibleInitialized = true;
|
manager->visibleInitialized = true;
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sVisible;
|
return manager->visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -547,13 +601,14 @@ BDragger::operator=(const BDragger &)
|
|||||||
/*static*/ void
|
/*static*/ void
|
||||||
BDragger::_UpdateShowAllDraggers(bool visible)
|
BDragger::_UpdateShowAllDraggers(bool visible)
|
||||||
{
|
{
|
||||||
BAutolock _(sLock);
|
DraggerManager* manager = DraggerManager::Default();
|
||||||
|
AutoLocker<DraggerManager> locker(manager);
|
||||||
|
|
||||||
sVisibleInitialized = true;
|
manager->visibleInitialized = true;
|
||||||
sVisible = visible;
|
manager->visible = visible;
|
||||||
|
|
||||||
for (int32 i = sList.CountItems(); i-- > 0;) {
|
for (int32 i = manager->list.CountItems(); i-- > 0;) {
|
||||||
BDragger* dragger = (BDragger*)sList.ItemAt(i);
|
BDragger* dragger = (BDragger*)manager->list.ItemAt(i);
|
||||||
BMessenger target(dragger);
|
BMessenger target(dragger);
|
||||||
target.SendMessage(_SHOW_DRAG_HANDLES_);
|
target.SendMessage(_SHOW_DRAG_HANDLES_);
|
||||||
}
|
}
|
||||||
@@ -563,8 +618,9 @@ BDragger::_UpdateShowAllDraggers(bool visible)
|
|||||||
void
|
void
|
||||||
BDragger::_AddToList()
|
BDragger::_AddToList()
|
||||||
{
|
{
|
||||||
BAutolock _(sLock);
|
DraggerManager* manager = DraggerManager::Default();
|
||||||
sList.AddItem(this);
|
AutoLocker<DraggerManager> locker(manager);
|
||||||
|
manager->list.AddItem(this);
|
||||||
|
|
||||||
bool allowsDragging = true;
|
bool allowsDragging = true;
|
||||||
if (fShelf)
|
if (fShelf)
|
||||||
@@ -583,8 +639,9 @@ BDragger::_AddToList()
|
|||||||
void
|
void
|
||||||
BDragger::_RemoveFromList()
|
BDragger::_RemoveFromList()
|
||||||
{
|
{
|
||||||
BAutolock _(sLock);
|
DraggerManager* manager = DraggerManager::Default();
|
||||||
sList.RemoveItem(this);
|
AutoLocker<DraggerManager> locker(manager);
|
||||||
|
manager->list.RemoveItem(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user