Пример #1
0
// Handle some appstuff
BOOL buttons_app_message(Buttons *buttons,DOpusAppMessage *msg)
{
	short col,row;
	Cfg_Button *button;
	Cfg_Function *function;
	struct ArgArray *arg_array;
	IPCData *ipc;

	// Lock process list
	lock_listlock(&GUI->process_list,FALSE);

	// See if button editor is running
	ipc=IPC_FindProc(&GUI->process_list,NAME_BUTTON_EDITOR_RUN,FALSE,0);

	// Unlock process list
	unlock_listlock(&GUI->process_list);

	// Editor running?
	if (ipc)
	{
		// Send button
		if (buttons_edit_bank(buttons,-1,-1,0,(struct AppMessage *)msg,0))
		{
			// Message was swallowed
			return 1;
		}
	}

	// Lock bank
	GetSemaphore(&buttons->bank->lock,SEMF_SHARED,0);

	// Get button and function we dropped on
	col=msg->da_Msg.am_MouseX;
	row=msg->da_Msg.am_MouseY;
	if (!(button=button_from_point(buttons,&col,&row)) ||
		!(function=button_valid(button,button->current)))
	{
		FreeSemaphore(&buttons->bank->lock);
		return 0;
	}

	// Get arg array
	if ((arg_array=AppArgArray(msg,AAF_ALLOW_DIRS)))
	{
		BPTR lock;
		char pathname[256];

		// Get pathname of first file
		DevNameFromLockDopus(msg->da_Msg.am_ArgList[0].wa_Lock,pathname,256);

		// Need source directory; if no name, get parent
		if ((!msg->da_Msg.am_ArgList[0].wa_Name ||
			!*msg->da_Msg.am_ArgList[0].wa_Name) &&
			(lock=ParentDir(msg->da_Msg.am_ArgList[0].wa_Lock)))
		{
			// Get pathname of parent
			DevNameFromLockDopus(lock,pathname,256);
			UnLock(lock);
		}

		// Launch function
		function_launch(
			FUNCTION_RUN_FUNCTION_EXTERNAL,
			function,
			0,
			0,
			0,0,
			pathname,0,
			arg_array,0,
			buttons);
	}

	// Unlock button lock
	FreeSemaphore(&buttons->bank->lock);

	return 0;
}
Пример #2
0
// Stop dragging a button
void buttons_stop_drag(Buttons *buttons,short x,short y)
{
	struct Layer *layer;
	struct Window *window;
	ULONG id=0;
	BOOL swap_local=0;
	IPCData *ipc=0;
	BOOL ok=0;

	// Free drag info
	FreeDragInfo(buttons->drag_info);
	buttons->drag_info=0;

	// Nothing selected now
	buttons->editor_sel_col=-1;
	buttons->editor_sel_row=-1;
	buttons->button_sel_button=0;
	IPC_Command(
		buttons->editor,
		BUTTONEDIT_SELECT_BUTTON,
		-1,
		(APTR)-1,
		0,
		0);

	// Invalid coordinates?
	if (x==-1 || y==-1) return;

	// Lock layer
	LockScreenLayer(buttons->window->WScreen);

	// Find which layer we dropped it on
	if (layer=WhichLayer(
		&buttons->window->WScreen->LayerInfo,
		x+buttons->window->LeftEdge,
		y+buttons->window->TopEdge))
	{
		// Does layer have a window?
		if ((window=layer->Window))
		{
			// Is it our own window?
			if (window==buttons->window)
			{
				// Set flag to swap with local button
				swap_local=1;
			}
			else
			{
				// Get window ID
				id=GetWindowID(window);

				// Forbid to get IPC
				Forbid();
				if (!(ipc=(IPCData *)GetWindowAppPort(window)))
					Permit();
			}
		}
	}

	// Unlock layer
	UnlockScreenLayer(buttons->window->WScreen);

	// Got an IPC port?
	if (ipc)
	{
		// Button editor or another button bank?
		if (id==WINDOW_BUTTON_CONFIG || id==WINDOW_BUTTONS || id==WINDOW_FUNCTION_EDITOR)
		{
			Cfg_Button *button;
			Point *pos;

			// Store position (screen relative)
			if (pos=AllocVec(sizeof(Point),0))
			{
				pos->x=x+buttons->window->LeftEdge;
				pos->y=y+buttons->window->TopEdge;
			}

			// Copy current button
			if (button=CopyButton(buttons->button_drag_button,0,-1))
			{
				// Send button
				IPC_Command(ipc,BUTTONEDIT_CLIP_BUTTON,0,button,pos,0);
				ok=1;
			}
		}

		// Permit now we've sent the message
		Permit();
	}

	// Swapping local buttons?
	else
	if (swap_local)
	{
		Cfg_Button *swap;

		// Lock bank
		GetSemaphore(&buttons->bank->lock,SEMF_SHARED,0);

		// Get swap button
		if (swap=button_from_point(buttons,&x,&y))
		{
			// Different button?
			if (swap!=buttons->button_drag_button)
			{
				// Swap buttons
				SwapListNodes(
					&buttons->bank->buttons,
					(struct Node *)buttons->button_drag_button,
					(struct Node *)swap);

				// Redraw buttons
				buttons_show_button(
					buttons,
					swap,
					buttons->drag_col,
					buttons->drag_row,
					swap->current,0);
				buttons_show_button(
					buttons,
					buttons->button_drag_button,
					x,
					y,
					buttons->button_drag_button->current,0);
				buttons->flags|=BUTTONF_CHANGED;
			}
		}

		// Unlock bank
		FreeSemaphore(&buttons->bank->lock);
		ok=1;
	}

	// Failed?
	if (!ok) DisplayBeep(buttons->window->WScreen);
}