Exemplo n.º 1
0
// Someone pressed the help key
void help_get_help(short x,short y,unsigned short qual)
{
    struct Window *window=0;
    struct Layer *layer;
    IPCData *ipc=0;

    // Lock screen layer
    LockLayerInfo(&GUI->screen_pointer->LayerInfo);

    // Find which layer the mouse is over
    if ((layer=WhichLayer(&GUI->screen_pointer->LayerInfo,x,y)))
    {
        // Get window pointer
        window=layer->Window;

        // Get window ID
        if (GetWindowID(window)!=WINDOW_UNKNOWN)
        {
            // Forbid to get port
            Forbid();

            // Get port
            if (!(ipc=(IPCData *)GetWindowAppPort(window)))
                Permit();
        }
    }

    // Unlock layer
    UnlockLayerInfo(&GUI->screen_pointer->LayerInfo);

    // Got a port?
    if (ipc)
    {
        ULONG coords;

        // Convert coordinates to window-relative
        x-=window->LeftEdge;
        y-=window->TopEdge;

        // Pack into longword
        coords=((unsigned short)x<<16)|(unsigned short)y;

        // Send help command
        IPC_Command(ipc,IPC_HELP,qual,(APTR)coords,0,0);

        // Enable multitasking now that message has been sent
        Permit();
    }

    // Otherwise, show generic help
    else help_show_help(HELP_MAIN,0);
}
Exemplo n.º 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);
}