Exemplo n.º 1
0
/*
================
rvPropertyGrid::ReflectMessage

Handle messages sent to the parent window
================
*/
bool rvPropertyGrid::ReflectMessage ( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
	switch ( msg )
	{					
		case WM_COMMAND:
		{
			if ( (HWND)lParam == mWindow )
			{
				switch ( HIWORD(wParam) )
				{
					case LBN_SELCHANGE:
						mSelectedItem = SendMessage ( mWindow, LB_GETCURSEL, 0, 0 );
						break;
				}
			}
			break;
		}
	
		case WM_DRAWITEM:
			HandleDrawItem ( wParam, lParam );
			return true;
	
		case WM_MEASUREITEM:
		{
			MEASUREITEMSTRUCT* mis = (MEASUREITEMSTRUCT*) lParam;
			mis->itemHeight = 18;
			return true;
		}
	}
	
	return false;
}
// This Really just Draws the menu bar items since it assumes 
//  that the background has already been drawn using DoDrawFrame
void cef_dark_window::DoDrawMenuBar(HDC hdc)
{
    HMENU menu = GetMenu();
    int items = ::GetMenuItemCount(menu);

    RECT menuBarRect;
    ComputeMenuBarRect(menuBarRect);

    for (int i = 0; i < items; i++) {
        // Determine the menu item state and ID
        MENUITEMINFO mmi = {0};
        mmi.cbSize = sizeof (mmi);
        mmi.fMask = MIIM_STATE|MIIM_ID;
        ::GetMenuItemInfo (menu, i, TRUE, &mmi);
        
        // Drawitem only works on ID
        MEASUREITEMSTRUCT mis = {0};
        mis.CtlType = ODT_MENU;
        mis.itemID = mmi.wID;

        RECT itemRect;
        ::SetRectEmpty(&itemRect);

        if (::GetMenuItemRect(mWnd, menu, (UINT)i, &itemRect)) {
            ScreenToNonClient(&itemRect);
            
            // Check to make sure it's actually in the 
            //  the correct location (fixes aero drawing issue)
            POINT pt = {itemRect.left, itemRect.top};
            if (!CanUseAeroGlass() || ::PtInRect(&menuBarRect, pt)) {
            
                // Draw the menu item
                DRAWITEMSTRUCT dis = {0};
                dis.CtlType = ODT_MENU;
                dis.itemID = mmi.wID;
                dis.hwndItem = (HWND)menu;
                dis.itemAction = ODA_DRAWENTIRE;
                dis.hDC = hdc;
                ::CopyRect(&dis.rcItem, &itemRect);

                if (mmi.fState & MFS_HILITE) {
                    dis.itemState |= ODS_SELECTED;
                } 
                if (mmi.fState & MFS_GRAYED) {
                    dis.itemState |= ODS_GRAYED;
                } 

                dis.itemState |= ODS_NOACCEL;

                HandleDrawItem(&dis);
            }
        }
    }
}
// This Really just Draws the menu bar items since it assumes 
//  that the background has already been drawn using DoDrawFrame
void cef_dark_window::DoDrawMenuBar(HDC hdc)
{
    HMENU menu = GetMenu();
    int items = ::GetMenuItemCount(menu);

    for (int i = 0; i < items; i++) {
        // Determine the menu item state and ID
        MENUITEMINFO mmi = {0};
        mmi.cbSize = sizeof (mmi);
        mmi.fMask = MIIM_STATE|MIIM_ID;
        ::GetMenuItemInfo (menu, i, TRUE, &mmi);
        
        // Drawitem only works on ID
        MEASUREITEMSTRUCT mis = {0};
        mis.CtlType = ODT_MENU;
        mis.itemID = mmi.wID;

        RECT itemRect;
        ::SetRectEmpty(&itemRect);
        if (::GetMenuItemRect(mWnd, menu, (UINT)i, &itemRect)) {
            ScreenToNonClient(&itemRect);
            
            // Draw the menu item
            DRAWITEMSTRUCT dis = {0};
            dis.CtlType = ODT_MENU;
            dis.itemID = mmi.wID;
            dis.hwndItem = (HWND)menu;
            dis.itemAction = ODA_DRAWENTIRE;
            dis.hDC = hdc;
            ::CopyRect(&dis.rcItem, &itemRect);

            if (mmi.fState & MFS_HILITE) {
                dis.itemState |= ODS_SELECTED;
            } 
            if (mmi.fState & MFS_GRAYED) {
                dis.itemState |= ODS_GRAYED;
            } 

            dis.itemState |= ODS_NOACCEL;

            HandleDrawItem(&dis);
        }
    }
}
// WindowProc handles dispatching of messages and routing back to the base class or to Windows
LRESULT cef_dark_aero_window::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
    bool callDefWindowProc = true;

    switch (message) 
    {
    case WM_MEASUREITEM:
        if (HandleMeasureItem((LPMEASUREITEMSTRUCT)lParam))
            return 0L;
        break;
    case WM_DRAWITEM:
        if (HandleDrawItem((LPDRAWITEMSTRUCT)lParam))
            return 0L;
        break;
    case WM_SETICON:
        mWindowIcon = 0;
        {
            RECT rectIcon;
            ComputeWindowIconRect(rectIcon);
            InvalidateRect(&rectIcon);
        }
        break;
    }

    // First let the DesktopWindowManager handle the message and tell us if 
    //  we should pass the message to the default window proc
    LRESULT lr = DwpCustomFrameProc(message, wParam, lParam, &callDefWindowProc);

    switch(message) {
    case WM_SETTINGCHANGE:
        HandleSettingChange((UINT)wParam, (LPCWSTR)lParam);
        break;

    case WM_NCACTIVATE:
    case WM_ACTIVATE:
        if (mReady) {
            UpdateNonClientArea();
        }
        break;
    case WM_NCMOUSELEAVE:
        // NOTE: We want anyone else interested in this message
        //          to be notified. Otherwise the default implementation 
        //          may be in the wrong state
        HandleNcMouseLeave();
        break;
    case WM_NCMOUSEMOVE:
        {
            POINT pt;
            POINTSTOPOINT(pt, lParam);

            if (HandleNcMouseMove((UINT)wParam, &pt))
                return 0L;
        }
        break;
    case WM_NCLBUTTONDOWN:
        {
            POINT pt;
            POINTSTOPOINT(pt, lParam);
            if (HandleNcLeftButtonDown((UINT)wParam, &pt))
                return 0L;
        }
        break;
    case WM_NCLBUTTONUP:
        {
            POINT pt;
            POINTSTOPOINT(pt, lParam);
            if (HandleNcLeftButtonUp((UINT)wParam, &pt))
                return 0L;
        }
        break;
    }

    // call DefWindowProc?
    if (!callDefWindowProc) {
        return lr;
    }


    lr = cef_window::WindowProc(message, wParam, lParam);

    if (!mReady)
        return lr;

    switch (message)
    {
    case WM_GETMINMAXINFO:
        HandleGetMinMaxInfo((LPMINMAXINFO) lParam);
        break;
    case WM_SETTEXT:
    case WM_WINDOWPOSCHANGING:
    case WM_WINDOWPOSCHANGED:
    case WM_MOVE:
    case WM_SIZE:
    case WM_SIZING:
    case WM_EXITSIZEMOVE:
        UpdateNonClientArea();
        if (message == WM_WINDOWPOSCHANGED) 
        {
            RECT rect;
            ComputeMenuBarRect(rect);
            InvalidateRect(&rect, TRUE);
        }
        break;
    case WM_EXITMENULOOP:
        mMenuActiveIndex = -1;
        break;   
    case WM_ACTIVATEAPP:
        mIsActive = (BOOL)wParam;
        UpdateNonClientArea();
        break;
    }

    return lr;
}
// The Aero version doesn't send us WM_DRAWITEM messages
//  to draw the item when hovering so we have to do that
// Pass NULL for pt to remove the highlight from any menu item
void cef_dark_aero_window::HiliteMenuItemAt(LPPOINT pt)
{
    HDC hdc = GetDC();
    HMENU menu = GetMenu();
    int items = ::GetMenuItemCount(menu);
    int oldMenuHilite = mMenuHiliteIndex;
    
    // reset this in case we don't get a hit below
    mMenuHiliteIndex = -1;

    for (int i = 0; i < items; i++) {
        // Determine the menu item state and ID
        MENUITEMINFO mmi = {0};
        mmi.cbSize = sizeof (mmi);
        mmi.fMask = MIIM_STATE|MIIM_ID;
        ::GetMenuItemInfo (menu, i, TRUE, &mmi);
        
        // Drawitem only works on ID
        MEASUREITEMSTRUCT mis = {0};
        mis.CtlType = ODT_MENU;
        mis.itemID = mmi.wID;

        RECT itemRect;
        ::SetRectEmpty(&itemRect);
        if (::GetMenuItemRect(mWnd, menu, (UINT)i, &itemRect)) {
            bool needsUpdate = false;

            if ((pt) && (::PtInRect(&itemRect, *pt))) {
                mmi.fState |= MFS_HILITE;
                mMenuHiliteIndex = i;
                needsUpdate = true;
            } else if (i == oldMenuHilite) {
                mmi.fState &= ~MFS_HILITE;
                needsUpdate = true;
            }

            if (needsUpdate) {
                // Draw the menu item
                DRAWITEMSTRUCT dis = {0};
                dis.CtlType = ODT_MENU;
                dis.itemID = mmi.wID;
                dis.hwndItem = (HWND)menu;
                dis.itemAction = ODA_DRAWENTIRE;
                dis.hDC = hdc;

                AdjustMenuItemRect(itemRect);

                ::CopyRect(&dis.rcItem, &itemRect);

                if (mmi.fState & MFS_HILITE) {
                    dis.itemState |= ODS_SELECTED;
                } 
                if (mmi.fState & MFS_GRAYED) {
                    dis.itemState |= ODS_GRAYED;
                } 

                dis.itemState |= ODS_NOACCEL;

                HandleDrawItem(&dis);
            }
        }
    }

    ReleaseDC(hdc);

}
// WindowProc handles dispatching of messages and routing back to the base class or to Windows
LRESULT cef_dark_window::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message) 
    {
    case WM_SETTINGCHANGE:
        // NOTE: We want anyone else interested in this message
        //          to be notified of a setting change even if we handle 
        //          the message.  Otherwise the default implementation 
        //          may be in the wrong state
        HandleSettingChange((UINT)wParam, (LPCWSTR)lParam);
        break;
    case WM_NCMOUSELEAVE:
        // NOTE: We want anyone else interested in this message
        //          to be notified. Otherwise the default implementation 
        //          may be in the wrong state
        HandleNcMouseLeave();
        break;
    case WM_NCMOUSEMOVE:
        if (HandleNcMouseMove((UINT)wParam))
            return 0L;
        break;

    case WM_NCLBUTTONDOWN:
        if (HandleNcLeftButtonDown((UINT)wParam))
            return 0L;
        break;
    case WM_NCLBUTTONUP:
        {
            POINT pt;
            POINTSTOPOINT(pt, lParam);
            if (HandleNcLeftButtonUp((UINT)wParam, &pt))
                return 0L;
        }
        break;
    case WM_NCCREATE:
        if (HandleNcCreate())
            return 0L;
        break;  
    case WM_NCPAINT:
        if (HandleNcPaint((HRGN)wParam)) 
            return 0L;
        break;
    case WM_NCDESTROY:
        if (HandleNcDestroy())
            return 0L;
        break;
    case WM_NCHITTEST:
        {
            POINT pt;
            POINTSTOPOINT(pt, lParam);
            return HandleNcHitTest(&pt);
        }            
        break;
    case WM_MEASUREITEM:
        if (HandleMeasureItem((LPMEASUREITEMSTRUCT)lParam))
            return TRUE;
        break;
    case WM_DRAWITEM:
        if (HandleDrawItem((LPDRAWITEMSTRUCT)lParam))
            return TRUE;
        break;
    case WM_SETICON:
        mWindowIcon = 0;
        break;
    case WM_SETTEXT:
    case WM_ACTIVATE:
    case WM_NCACTIVATE:
        // Turn off redraw because the 
        //  DefaultWindowProc will paint over top of 
        //  our frame and cause the title bar to flicker 
        if (!IsIconic()){
            SetRedraw(FALSE); 
        }
        break;
    }
    LRESULT lr = cef_window::WindowProc(message, wParam, lParam);
    // post default message processing
    switch (message)
    {
    case WM_WINDOWPOSCHANGING:
    case WM_WINDOWPOSCHANGED:
    case WM_MOVE:
    case WM_SIZE:
    case WM_SIZING:
    case WM_EXITSIZEMOVE:
        UpdateNonClientArea();
        break;
    }

    // special case -- since we turned off redraw for these 
    //  messages to reduce flicker, we need to turn redraw 
    //  on now and force updating the non-client area
    switch (message) 
    {
    case WM_SETTEXT:
    case WM_ACTIVATE:
    case WM_NCACTIVATE:
        if (!IsIconic()){
            SetRedraw(TRUE);
            UpdateNonClientArea();
            if (message != WM_SETTEXT) {
                DoRepaintClientArea();
            }
        }
        break;
    }
    return lr;
}