//*****************************************************************************
BOOL CALLBACK SnapEnumProc(HWND hwnd, LPARAM lParam)
{
	struct snap_info *si = (struct snap_info *)lParam;
	if (hwnd != si->self && IsWindowVisible(hwnd))
	{
		HWND pw = GetParent(hwnd);
		if (pw == si->parent)
		{
			RECT r;
			GetWindowRect(hwnd, &r);
			r.right -= r.left;
			r.bottom -= r.top;
			if (pw) ScreenToClient(pw, (POINT*)&r.left);
			if (false == si->same_level)
			{
				r.left += si->h->from1;
				r.top  += si->v->from1;
			}
			si->h->to2 = (si->h->to1 = r.left) + r.right;
			si->v->to2 = (si->v->to1 = r.top)  + r.bottom;
			snap_to_edge(si->h, si->v, si->sizing, si->same_level, si->pad);
		}
	}
	return TRUE;
}
Exemple #2
0
int snap_enum_proc(struct button *bp, void *param)
{
    struct snap_info *si = (struct snap_info *)param;
    if (bp != si->self && 0 == (bp->f & BN_HID))// && bp->typ == BN_BTN)
    {
        int x, y, w, h;
        x = bp->x0;
        y = bp->y0;
        w = bp->w0;
        h = bp->h0;
        if (false == si->same_level) {
            x += si->h->from1;
            y += si->v->from1;
        }
        si->h->to1 = x;
        si->h->to2 = x+w;
        si->v->to1 = y;
        si->v->to2 = y+h;
        snap_to_edge(si->h, si->v, si->sizing, si->same_level, si->pad);
    }
    return TRUE;
}   
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//snap_windows
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void snap_windows(WINDOWPOS *wp, bool sizing, int *content)
{
	int snapdist    = plugin_snap_dist;
	//int grid        = plugin_snap_usegrid ? plugin_snap_gridsize : 0;
	int padding     = plugin_snap_padding;

	if (snapdist < 1) return;
	// ------------------------------------------------------

	HWND self   = wp->hwnd;
	HWND parent = GetParent(self);

	struct edges h;
	struct edges v;
	struct snap_info si = { &h, &v, sizing, true, padding, self, parent };

	h.dmin = v.dmin = h.def = v.def = snapdist;

	h.from1 = wp->x;
	h.from2 = h.from1 + wp->cx;
	v.from1 = wp->y;
	v.from2 = v.from1 + wp->cy;


	// ------------------------------------------------------
	// snap to grid
	/*
	if (grid > 1 && (parent || sizing))
	{
		snap_to_grid(&h, &v, sizing, grid, padding);
	}
	//else
	*/
	{
		// -----------------------------------------
		if (parent)
		{
			// snap to siblings
			EnumChildWindows(parent, SnapEnumProc, (LPARAM)&si);

			// snap to frame edges
			RECT r;
			GetClientRect(parent, &r);
			h.to1 = r.left;
			h.to2 = r.right;
			v.to1 = r.top;
			v.to2 = r.bottom;
			snap_to_edge(&h, &v, sizing, false, padding);
		}
		else
		{
			// snap to top level windows
			EnumThreadWindows(GetCurrentThreadId(), SnapEnumProc, (LPARAM)&si);

			// snap to screen edges
			RECT r;
			get_mon_rect(get_monitor(self), &r);
			h.to1 = r.left;
			h.to2 = r.right;
			v.to1 = r.top;
			v.to2 = r.bottom;
			snap_to_edge(&h, &v, sizing, false, 0);
		}

		// -----------------------------------------
		if (sizing)
		{
			// snap to button icons
			if (content)
			{
				// images have to be double padded, since they are centered
				h.to2 = (h.to1 = h.from1) + content[0];
				v.to2 = (v.to1 = v.from1) + content[1];
				snap_to_edge(&h, &v, sizing, false, -2*padding);
			}

			// snap frame to childs
			si.same_level = false;
			si.pad = -padding;
			si.self = NULL;
			si.parent = self;
			EnumChildWindows(self, SnapEnumProc, (LPARAM)&si);
		}
	}

	// -----------------------------------------
	// adjust the window-pos

	if (h.dmin < snapdist)
		if (sizing) wp->cx += h.omin;
		else wp->x += h.omin;

	if (v.dmin < snapdist)
		if (sizing) wp->cy += v.omin;
		else wp->y += v.omin;
}
Exemple #4
0
void snap_button(struct dlg *dlg, struct button *bp, bool sizing, int *content)
{
    struct edges h;
    struct edges v;
    void *parent = NULL;

    int snapdist = g_snap_dist;
    int grid     = g_snap_usegrid ? g_snap_gridsize : 0;
    int padding  = g_snap_padding;

    if (snapdist < 1)
        return;

    h.dmin = v.dmin = h.def = v.def = snapdist;
    h.from2 = (h.from1 = bp->x0) + bp->w0;
    v.from2 = (v.from1 = bp->y0) + bp->h0;

    // ------------------------------------------------------
    // snap to grid
    if (grid > 1)// && (parent || sizing))
    {
        snap_to_grid(&h, &v, sizing, grid, padding);
    }
    else
    {
        struct snap_info si;

        si.h = &h;
        si.v = &v;
        si.sizing = sizing;
        si.same_level = true;
        si.pad = padding;
        si.self = bp;
        si.parent = parent;

        enum_buttons(dlg, snap_enum_proc, &si);

        h.to1 = 0;
        h.to2 = dlg->w;
        v.to1 = 0;
        v.to2 = dlg->h;
        snap_to_edge(&h, &v, sizing, false, padding);

        // -----------------------------------------
        if (sizing)
        {
            // snap to button icons
            if (content)
            {
                // images have to be double padded, since they are centered
                h.to2 = (h.to1 = h.from1) + content[0];
                v.to2 = (v.to1 = v.from1) + content[1];
                snap_to_edge(&h, &v, sizing, false, -2*padding);
            }

        /*
            // snap frame to childs
            si.same_level = false;
            si.pad = -padding;
            si.self = NULL;
            si.parent = self;
            enum_buttons(dlg, snap_enum_proc, &si);
        */
        }
    }

    // -----------------------------------------
    // adjust the window-pos

    if (h.dmin < snapdist) {
        if (sizing)
            bp->w0 += h.omin;
        else
            bp->x0 += h.omin;
    }
    if (v.dmin < snapdist) {
        if (sizing)
            bp->h0 += v.omin;
        else
            bp->y0 += v.omin;
    }
}