示例#1
0
文件: monslctl.c 项目: GYGit/reactos
static VOID
MonSelUpdateMonitorsInfo(IN OUT PMONITORSELWND infoPtr,
                         IN BOOL bRepaint)
{
    RECT rcExtSurface, rcExtDisplay;
    DWORD Index;

    /* Recalculate rcExtent */
    MonSelUpdateExtent(infoPtr);

    infoPtr-> CanDisplay = infoPtr->MonitorsCount != 0 &&
                           (infoPtr->ClientSize.cx > (2 * (infoPtr->Margin.cx + infoPtr->SelectionFrame.cx))) &&
                           (infoPtr->ClientSize.cy > (2 * (infoPtr->Margin.cy + infoPtr->SelectionFrame.cy)));

    if (infoPtr->CanDisplay)
    {
        /* Calculate the rectangle on the control in which may be painted */
        rcExtSurface.left = infoPtr->Margin.cx;
        rcExtSurface.top = infoPtr->Margin.cy;
        rcExtSurface.right = rcExtSurface.left + infoPtr->ClientSize.cx - (2 * infoPtr->Margin.cx);
        rcExtSurface.bottom = rcExtSurface.top + infoPtr->ClientSize.cy - (2 * infoPtr->Margin.cy);

        /* Calculate the rectangle on the control that is actually painted on */
        rcExtDisplay.left = rcExtDisplay.top = 0;
        rcExtDisplay.right = infoPtr->rcExtent.right - infoPtr->rcExtent.left;
        rcExtDisplay.bottom = infoPtr->rcExtent.bottom - infoPtr->rcExtent.top;

        ScaleRectSizeFit(&rcExtSurface,
                         &rcExtDisplay);

        infoPtr->rcOldMonitors = infoPtr->rcMonitors;
        infoPtr->rcMonitors = rcExtDisplay;

        /* Now that we know in which area all monitors are located,
           calculate the monitors selection rectangles on the screen */

        for (Index = 0; Index < infoPtr->MonitorsCount; Index++)
        {
            MonSelMonInfoToRect(&infoPtr->MonitorInfo[Index],
                                &rcExtDisplay);

            MonSelScaleRectRelative(&infoPtr->rcExtent,
                                    &rcExtDisplay,
                                    &infoPtr->rcMonitors,
                                    &infoPtr->Monitors[Index].rc);
        }

        MonSelResetMonitors(infoPtr);

        if (bRepaint)
            MonSelRepaint(infoPtr);
    }
    else if (bRepaint)
    {
        InvalidateRect(infoPtr->hSelf,
                       NULL,
                       TRUE);
    }
}
示例#2
0
static BOOL
MonSelSetMonitorsInfo(IN OUT PMONITORSELWND infoPtr,
                      IN DWORD dwMonitors,
                      IN const MONSL_MONINFO *MonitorsInfo)
{
    DWORD Index;
    BOOL Ret = TRUE;

    if (infoPtr->DraggingMonitor >= 0)
        return FALSE;

    if (infoPtr->MonitorInfo != NULL)
    {
        LocalFree((HLOCAL)infoPtr->MonitorInfo);
        infoPtr->MonitorInfo = NULL;

        MonSelResetMonitors(infoPtr);

        LocalFree((HLOCAL)infoPtr->Monitors);
        infoPtr->Monitors = NULL;

        infoPtr->MonitorsCount = 0;
    }

    if (dwMonitors != 0)
    {
        infoPtr->MonitorInfo = (PMONSL_MONINFO)LocalAlloc(LMEM_FIXED,
                               dwMonitors * sizeof(MONSL_MONINFO));
        if (infoPtr->MonitorInfo != NULL)
        {
            infoPtr->Monitors = (PMONSL_MON)LocalAlloc(LMEM_FIXED,
                                dwMonitors * sizeof(MONSL_MON));
            if (infoPtr->Monitors != NULL)
            {
                CopyMemory(infoPtr->MonitorInfo,
                           MonitorsInfo,
                           dwMonitors * sizeof(MONSL_MONINFO));
                ZeroMemory(infoPtr->Monitors,
                           dwMonitors * sizeof(MONSL_MON));

                for (Index = 0; Index < dwMonitors; Index++)
                {
                    _stprintf(infoPtr->Monitors[Index].szCaption,
                              _T("%u"),
                              Index + 1);
                }

                infoPtr->MonitorsCount = dwMonitors;

                if (infoPtr->SelectedMonitor >= (INT)infoPtr->MonitorsCount)
                    infoPtr->SelectedMonitor = -1;

                if (!(infoPtr->ControlExStyle & MSLM_EX_ALLOWSELECTNONE) && infoPtr->SelectedMonitor < 0)
                    infoPtr->SelectedMonitor = 0;

                MonSelUpdateMonitorsInfo(infoPtr,
                                         TRUE);
            }
            else
            {
                LocalFree((HLOCAL)infoPtr->MonitorInfo);
                infoPtr->MonitorInfo = NULL;

                Ret = FALSE;
            }
        }
        else
            Ret = FALSE;
    }

    if (!Ret)
        infoPtr->SelectedMonitor = -1;

    if (!Ret || dwMonitors == 0)
    {
        InvalidateRect(infoPtr->hSelf,
                       NULL,
                       TRUE);
    }

    return Ret;
}