Example #1
0
void ObservableHandler::_handleAddObserver(
	BMessage*								message) {

#if DEBUG
	BLooper* l = Looper();
	ASSERT(l);
	ASSERT(l->IsLocked());
#endif
	BMessage reply;

	BMessenger observer;
	status_t err = message->FindMessenger(
		"observer", &observer);
	if(err < B_OK) {
		PRINT((
			"* ObservableHandler::_handleAddObserver(): no observer specified!\n"));
		// send reply? +++++
		return;
	}

	if(m_released) {
		// already quitting
		reply.what = M_BAD_TARGET;
		reply.AddMessenger("target", BMessenger(this));
		reply.AddMessenger("observer", observer);
		message->SendReply(&reply);
		
		return;
	}
	else if(IndexOfTarget(observer.Target(0)) != -1) {
		// observer already added
		reply.what = M_BAD_OBSERVER;
		reply.AddMessenger("target", BMessenger(this));
		reply.AddMessenger("observer", observer);
		message->SendReply(&reply);
		
		return;
	}	

	// valid observer given

	// add it
	err = AddTarget(observer.Target(0));
	ASSERT(err == B_OK);

	// call hook
	observerAdded(observer);
}
Example #2
0
// Include the following version of SetTargetForItems() to eliminate
// hidden polymorphism warning. Should be correct, but is unused and untested.
status_t QueryMenu::SetTargetForItems(BMessenger messenger)
{
	if (messenger.IsTargetLocal()) {
		BLooper* ignore; // don't care what value this gets
		fTargetHandler = messenger.Target(&ignore);
		return BMenu::SetTargetForItems(messenger);
	} else {
		return B_ERROR;
	}
}
Example #3
0
/*!	\brief Subscribes a target to node and/or mount watching, or unsubscribes
		   it from node watching.

	Depending of \a flags the action performed by this function varies:
	- \a flags is \c 0: The target is unsubscribed from watching the node.
	  \a node must not be \c NULL in this case.
	- \a flags contains \c B_WATCH_MOUNT: The target is subscribed to mount
	  watching.
	- \a flags contains at least one of \c B_WATCH_NAME, \c B_WATCH_STAT,
	  \c B_WATCH_ATTR, or \c B_WATCH_DIRECTORY: The target is subscribed to
	  watching the specified aspects of the node. \a node must not be \c NULL
	  in this case.

	Note, that the latter two cases are not mutual exlusive, i.e. mount and
	node watching can be requested with a single call.

	\param node node_ref referring to the node to be watched. May be \c NULL,
		   if only mount watching is requested.
	\param flags Flags indicating the actions to be performed.
	\param target Messenger referring to the target. Must be valid.
	\return \c B_OK, if everything went fine, another error code otherwise.
*/
status_t
watch_node(const node_ref *node, uint32 flags, BMessenger target)
{
	status_t error = (target.IsValid() ? B_OK : B_BAD_VALUE);
	if (error == B_OK) {
		BLooper *looper = NULL;
		BHandler *handler = target.Target(&looper);
		error = watch_node(node, flags, handler, looper);
	}
	return error;
}
Example #4
0
/*!	\brief Unsubscribes a target from node and mount monitoring.
	\param target Messenger referring to the target. Must be valid.
	\return \c B_OK, if everything went fine, another error code otherwise.
*/
status_t
stop_watching(BMessenger target)
{
	status_t error = (target.IsValid() ? B_OK : B_BAD_VALUE);
	if (error == B_OK) {
		BLooper *looper = NULL;
		BHandler *handler = target.Target(&looper);
		error = stop_watching(handler, looper);
	}
	return error;
}
Example #5
0
int32 MouseWatcher(void* data)
{
	BMessenger* TheMessenger = (BMessenger*)data;
	BPoint PreviousPos;
	uint32 PreviousButtons;
	bool FirstCheck = true;
	BMessage MessageToSend;
	MessageToSend.AddPoint("where",BPoint(0,0));
	MessageToSend.AddInt32("buttons",0);
	MessageToSend.AddInt32("modifiers",0);
	while(true)
	{
		if (!TheMessenger->LockTarget())
		{
			delete TheMessenger;
			return 0;			// window is dead so exit
		}
		BLooper *TheLooper;
		BView* TheView = (BView*)TheMessenger->Target(&TheLooper);
		BPoint Where;
		uint32 Buttons;
		TheView->GetMouse(&Where,&Buttons,false);
		if(FirstCheck)
		{
			PreviousPos = Where;
			PreviousButtons = Buttons;
			FirstCheck = false;
		}
		bool Send = false;
		if(Buttons != PreviousButtons || Buttons == 0 || Where != PreviousPos)
		{
			if(Buttons == 0)
				MessageToSend.what = MW_MOUSE_UP;
			else if(Buttons != PreviousButtons)
				MessageToSend.what = MW_MOUSE_DOWN;
			else
				MessageToSend.what = MW_MOUSE_MOVED;
			MessageToSend.ReplacePoint("where",Where);
			MessageToSend.ReplaceInt32("buttons",Buttons);
			MessageToSend.ReplaceInt32("modifiers",modifiers());
			Send = true;
		}
		TheLooper->Unlock();
		if(Send)
			TheMessenger->SendMessage(&MessageToSend);
		if(Buttons == 0)
		{
			//Button was released
			delete TheMessenger;
			return 0;
		}
		snooze(50000);
	}
}
Example #6
0
void ObservableLooper::_handleAddObserver(
    BMessage*								message) {

    BMessage reply;

    BMessenger observer;
    status_t err = message->FindMessenger(
                       "observer", &observer);
    if(err < B_OK) {
        PRINT((
                  "* ObservableLooper::_handleAddObserver(): no observer specified!\n"));
        // send reply? +++++
        return;
    }

    // at this point, a reply of some sort will be sent
    reply.AddMessenger("target", BMessenger(this));
    reply.AddMessenger("observer", observer);

    if(m_quitting) {
        // already quitting
        reply.what = M_BAD_TARGET;
    }
    else if(IndexOfTarget(observer.Target(0)) != -1) {
        // observer already added
        reply.what = M_BAD_OBSERVER;
    }
    else {
        // add it
        err = AddTarget(observer.Target(0));
        ASSERT(err == B_OK);
        reply.what = M_OBSERVER_ADDED;
    }

    // send reply
    message->SendReply(&reply);

    // call hook
    observerAdded(observer);
}
Example #7
0
static BRect CallerFrame(BMessenger& caller)
{
	BRect rect;
	if (caller.LockTarget())
	{
		BLooper* looper;
		caller.Target(&looper);
		BWindow* window = dynamic_cast<BWindow*>(looper);
		if (window)
			rect = window->Frame();
		looper->Unlock();
	}
	return rect;
}
Example #8
0
void DCCConnect::UpdateBar(const BMessenger& msgr, int readSize, int cps, uint32 size, bool update)
{
	BMessage msg(B_UPDATE_STATUS_BAR);

	if (update) {
		char text[128];

		sprintf(text, "%.1f", size / 1024.0);
		msg.AddString("trailing_text", text);

		sprintf(text, "%d", cps);
		msg.AddString("text", text);
	}

	msg.AddFloat("delta", readSize);
	BLooper* looper(NULL);
	DCCConnect* transferView((DCCConnect*)msgr.Target(&looper));
	if ((looper != NULL) && (transferView != NULL)) looper->PostMessage(&msg, transferView->fBar);
}
Example #9
0
void ObservableLooper::_handleRemoveObserver(
    BMessage*								message) {

//	PRINT(("ObservableLooper::_handleRemoveObserver():\n"
//		"  %ld targets\n", CountTargets()));
    BMessage reply;

    BMessenger observer;
    status_t err = message->FindMessenger(
                       "observer", &observer);
    if(err < B_OK) {
        PRINT((
                  "* ObservableLooper::_handleRemoveObserver(): no observer specified!\n"));
        // send reply? +++++
        return;
    }

    // at this point, a reply of some sort will be sent
    reply.AddMessenger("target", BMessenger(this));
    reply.AddMessenger("observer", observer);

    int32 index = IndexOfTarget(observer.Target(0));
    if(index == -1) {
        reply.what = M_BAD_OBSERVER;
    }
    else {
        RemoveTarget(index);
        reply.what = M_OBSERVER_REMOVED;
    }

    message->SendReply(&reply);

    // call hook
    observerRemoved(observer);

    // time to shut down?
    if(m_quitting && !CountTargets()) {
        releaseComplete();
        BLooper::Quit();
    }
}
Example #10
0
void ObservableHandler::_handleRemoveObserver(
	BMessage*								message) {

#if DEBUG
	BLooper* l = Looper();
	ASSERT(l);
	ASSERT(l->IsLocked());
#endif
	BMessage reply;

	BMessenger observer;
	status_t err = message->FindMessenger(
		"observer", &observer);
	if(err < B_OK) {
		PRINT((
			"* ObservableHandler::_handleRemoveObserver(): no observer specified!\n"));
		// send reply? +++++
		return;
	}

	int32 index = IndexOfTarget(observer.Target(0));
	if(index == -1) {
		reply.what = M_BAD_OBSERVER;
		
		reply.AddMessenger("target", BMessenger(this));
		reply.AddMessenger("observer", observer);
		message->SendReply(&reply);
		return;
	}
	
	// valid observer given; remove it & call notification hook
	RemoveTarget(index);
	observerRemoved(observer);
	
	// time to shut down?
	if(m_released && !CountTargets()) {
		releaseComplete();
		delete this; // BOOM!
	}
}
Example #11
0
void _OwqList::OpenAddWindow(BMessage* row)
{
	if( !mAddWin.IsValid() ) {
		_OwqWindow*	win = new _OwqWindow( BMessenger(this), row );
		if( win ) {
			mAddWin = BMessenger(win);
			win->Show();
		}
	} else {
		BHandler*		target;
		BLooper*		looper;
		if( (target = mAddWin.Target(&looper)) != 0 ) {
			_OwqWindow*	win = dynamic_cast<_OwqWindow*>( target );
			if( win ) {
				if( row && win->Lock() ) {
					win->MessageReceived( row );
					win->Unlock();
				}
				win->Activate( true );
			}
		}
	}
}
int32 MouseDragOrPopupWatcher(void* data)
{
	BMessenger* TheMessenger = (BMessenger*)data;
	BPoint StartPos;
	uint32 StartButtons = 0;
	bigtime_t StartTime = 0;
	bool FirstCheck = true;
	BMessage MessageToSend;
	MessageToSend.AddPoint("where",BPoint(0,0));
	MessageToSend.AddInt32("buttons",0);
	MessageToSend.AddInt32("modifiers",0);
	bigtime_t PopupTime;
	if(get_click_speed(&PopupTime) != B_OK)
		return 0;
	PopupTime *= 2;
	while(true)
	{
		if (!TheMessenger->LockTarget())
		{
			delete TheMessenger;
			return 0;			// window is dead so exit
		}
		BLooper *TheLooper;
		BView* TheView = (BView*)TheMessenger->Target(&TheLooper);
		BPoint Where;
		uint32 Buttons;
		bigtime_t Time = system_time();
		TheView->GetMouse(&Where,&Buttons,false);
		if(FirstCheck)
		{
			StartPos = Where;
			StartButtons = Buttons;
			StartTime = Time;
			FirstCheck = false;
		}
		bool Send = false;
		if(Buttons == 0 || Buttons != StartButtons)
		{
			//Changed or released
			MessageToSend.what = MW_MOUSE_CLICK;
			Send = true;
		}
		else if(Where.x < StartPos.x-1.0 || Where.x > StartPos.x+1.0 ||
			Where.y < StartPos.y-1.0 || Where.y > StartPos.y+1.0)
		{
			MessageToSend.what = MW_MOUSE_DRAG;
			Send = true;
		}
		else if(Time >= StartTime + PopupTime)
		{
			MessageToSend.what = MW_MOUSE_POPUP;
			Send = true;
		}
		TheLooper->Unlock();
		if(Send)
		{
			MessageToSend.ReplacePoint("where",StartPos);
			MessageToSend.ReplaceInt32("buttons",Buttons);
			MessageToSend.ReplaceInt32("modifiers",modifiers());
			TheMessenger->SendMessage(&MessageToSend);
			delete TheMessenger;
			return 0;
		}
		snooze(50000);
	}
}
Example #13
0
/*
	BHandler *Target(BLooper **looper) const
	@case 1			this is uninitialized, looper is NULL
	@results		should return NULL.
 */
void TargetTester::TargetTest1()
{
	BMessenger messenger;
	CHK(messenger.Target(NULL) == NULL);
}
/*!
	\brief Tracker add-on entry
*/
extern "C" void
process_refs(entry_ref dir, BMessage* refs, void* /*reserved*/)
{
	status_t status;
	BAlert *alert;
	BMessenger msgr;
	BPoseView *view = NULL;
	BMessage poseViewBackup;
	BMessage poseViewColumnBackup;
	uint32 poseViewModeBackup;
	BString windowTitleBackup;

	refs->PrintToStream();
	
	status = refs->FindMessenger("TrackerViewToken", &msgr);
	if (status < B_OK) {
		Error(view, status);
		return;
	}

	status = B_ERROR;
	if (!msgr.LockTarget()) {
		Error(view, status);
		return;
	}

	status = B_BAD_HANDLER;
	view = dynamic_cast<BPoseView *>(msgr.Target(NULL));
	if (!view) {
		Error(view, status);
		return;
	}
	if (dynamic_cast<BWindow *>(view->Looper()) == NULL) {
		Error(view, status, true);
		return;
	}

	windowTitleBackup = view->Window()->Title();

	view->SaveColumnState(poseViewColumnBackup);
	view->SaveState(poseViewBackup);
	view->SetDragEnabled(false);
	view->SetSelectionRectEnabled(false);
	view->SetPoseEditing(false);
	poseViewModeBackup = view->ViewMode();
	

	view->SetViewMode(kIconMode);

	view->ShowBarberPole();


	view->UnlockLooper();



	alert = new BAlert("Error", "IconVader:\nClick on the icons to get points."
		"\nAvoid symlinks!", "OK");
	alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
	alert->Go();


	int32 score = 0;
	int32 count = 300;
	while (count--) {
		status = B_ERROR;
		if (!msgr.LockTarget()) {
			Error(view, status);
			return;
		}

		BPose *pose;
		for (int32 i = 0; (pose = view->PoseAtIndex(i)); i++) {
			if (pose->IsSelected()) {
				if (pose->TargetModel()->IsFile())
					score++;
				if (pose->TargetModel()->IsDirectory())
					score+=2;
				if (pose->TargetModel()->IsSymLink())
					score-=10;
				pose->Select(false);
			}
#ifdef __HAIKU__
			BPoint location = pose->Location(view);
#else
			BPoint location = pose->Location();
#endif
			location.x += ((rand() % 20) - 10);
			location.y += ((rand() % 20) - 10);
#ifdef __HAIKU__
			pose->SetLocation(location, view);
#else
			pose->SetLocation(location);
#endif
		}

		view->CheckPoseVisibility();

		view->Invalidate();

		BString str("Score: ");
		str << score;
		view->Window()->SetTitle(str.String());
		
		view->UnlockLooper();
		snooze(100000);
	}

	BString scoreStr("You scored ");
	scoreStr << score << " points!";
	alert = new BAlert("Error", scoreStr.String(), "Cool!");
	alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
	alert->Go();


	status = B_ERROR;
	if (!msgr.LockTarget()) {
		Error(view, status);
		return;
	}

	/*
	status = B_BAD_HANDLER;
	view = dynamic_cast<BPoseView *>(msgr.Target(NULL));
	if (!view)
		goto err1;
	*/

	view->HideBarberPole();
	view->SetViewMode(poseViewModeBackup);
	view->RestoreState(poseViewBackup);
	view->RestoreColumnState(poseViewColumnBackup);

	view->Window()->SetTitle(windowTitleBackup.String());
	
/*
	BMessage('_RRC') {
        TrackerViewToken = BMessenger(port=32004, team=591, target=direct:0x131)
} */


	//be_roster->Launch("application/x-vnd.haiku-filetypes", refs);
	
	view->UnlockLooper();
	return;

}