// **************************************************************************** // // Function Name: RWindowView::InvalidateVectorRect( ) // // Description: Invalidates the given vector rect in this view // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RWindowView::InvalidateVectorRect( const RRealVectorRect& rect, BOOLEAN fErase ) { // // Only invalidate if we have a CWnd if( !GetCWnd() ) return; // Get the bounding rect... RRealRect temp = rect.m_TransformedBoundingRect; // Get our transformation... R2dTransform transform; ApplyTransform( transform, FALSE, FALSE ); // Apply it to our bounds... temp *= transform; // Convert the bounds to device units ::LogicalUnitsToDeviceUnits( temp, *this ); // guard for roundoff... const YRealDimension kRoundOffGuard = 2.0; temp.Inflate( RRealSize( kRoundOffGuard, kRoundOffGuard ) ); // Put it in a CRect and do the invalidate CRect crect( ::Round(temp.m_Left), ::Round(temp.m_Top), ::Round(temp.m_Right), ::Round(temp.m_Bottom) ); GetCWnd( ).InvalidateRect( crect, fErase ); }
// **************************************************************************** // // Function Name: RWindowView::ValidateVectorRect( ) // // Description: Validates the given vector rect in this view // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RWindowView::ValidateVectorRect( const RRealVectorRect& rect ) { // // Only validate if we have a CWnd if( !GetCWnd() ) return; // Get the bounding rect... RRealVectorRect temp = rect; // Get our transformation... R2dTransform transform; ApplyTransform( transform, FALSE, FALSE ); // Apply it to our bounds... temp *= transform; // Convert the bounds to device units ::LogicalUnitsToDeviceUnits( temp, *this ); // Get the polygon points RRealPoint realPolygon[ 4 ]; temp.GetPolygonPoints( realPolygon ); // Create a polygon region RIntPoint polygon[4]; polygon[0] = realPolygon[0]; polygon[1] = realPolygon[1]; polygon[2] = realPolygon[2]; polygon[3] = realPolygon[3]; CRgn validateArea; validateArea.CreatePolygonRgn( reinterpret_cast<POINT*>( &polygon ), 4, ALTERNATE ); // Validate the region GetCWnd( ).ValidateRgn( &validateArea ); }
void CRichEditNcBorder::NcDrawBorder() { Default(); if (m_bThemedBorder) { CThemed th(GetCWnd(), WC_EDIT); CWindowDC dc(GetCWnd()); CRect rBorder, rClient; GetWindowRect(rBorder); th.GetThemeBackgroundContentRect(&dc, EP_EDITTEXT, ETS_NORMAL, rBorder, rClient); // convert to window coordinates rClient.OffsetRect(-rBorder.left, -rBorder.top); rBorder.OffsetRect(-rBorder.left, -rBorder.top); dc.ExcludeClipRect(rClient); // determine the current border state int nState; if (!IsWindowEnabled()) nState = ETS_DISABLED; else if (HasStyle(ES_READONLY) || SendMessage(EM_GETOPTIONS, NULL, NULL) & ECO_READONLY) nState = ETS_READONLY; else nState = ETS_NORMAL; th.DrawBackground(&dc, EP_EDITTEXT, nState, rBorder); } }
// **************************************************************************** // // Function Name: RWindowView::Invalidate( ) // // Description: Invalidates the entire view // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RWindowView::Invalidate( BOOLEAN fErase ) { // // Only invalidate if we have a CWnd if( GetCWnd() ) GetCWnd( ).Invalidate( fErase ); }
// **************************************************************************** // // Function Name: RWindowView::ActivateView( ) // // Description: Activate the view // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RWindowView::ActivateView( ) { GetCWnd( ).SetForegroundWindow( ); CFrameWnd* pParentFrame = GetCWnd( ).GetParentFrame(); if( pParentFrame->GetParentFrame( ) ) if ( pParentFrame->GetParentFrame( )->GetActiveFrame() != pParentFrame ) pParentFrame->ActivateFrame( ); }
// **************************************************************************** // // Function Name: RWindowView::IsKeyEventPending( ) // // Description: Check if there are any pending key events in the Queue. // // Returns: TRUE if the next system event is a key event // // Exceptions: None // // **************************************************************************** // BOOLEAN RWindowView::IsKeyEventPending( ) const { MSG msg; while (PeekMessage( &msg, GetCWnd().GetSafeHwnd(), 0, 0, PM_NOYIELD|PM_NOREMOVE )) { if (msg.message == WM_KEYUP) // we want to flush this message PeekMessage( &msg, GetCWnd().GetSafeHwnd(), WM_KEYUP, WM_KEYUP, PM_NOYIELD|PM_REMOVE ); else if ((msg.message == WM_CHAR) || (msg.message == WM_KEYDOWN)) return TRUE; else return FALSE; } return FALSE; }
void CToolbarHelper::InitTooltips() { if (!m_tt.Create(GetCWnd(), TTS_ALWAYSTIP)) return; // hook the toolbar for mouse messages VERIFY(ScHookWindow(m_pToolbar->GetSafeHwnd())); // turn off default tooltips m_pToolbar->SetBarStyle(m_pToolbar->GetBarStyle() & ~CBRS_TOOLTIPS); // and activate it m_tt.Activate(TRUE); // set up tools for each of the toolar buttons int nBtnCount = m_pToolbar->GetToolBarCtrl().GetButtonCount(); for (int nBtn = 0; nBtn < nBtnCount; nBtn++) { if (m_pToolbar->GetItemID(nBtn) != ID_SEPARATOR) { CRect rBtn; m_pToolbar->GetItemRect(nBtn, rBtn); m_tt.AddTool(m_pToolbar, LPSTR_TEXTCALLBACK, rBtn, m_pToolbar->GetItemID(nBtn)); } } }
// **************************************************************************** // // Function Name: RWindowView::OnAutoScrollTimer( ) // // Description: Called by the autoscroll timer when its timer elapses // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RWindowView::OnAutoScrollTimer( ) { // Get the modifier key state YModifierKey modifierKeys = GetModifierKeyState( ); // Get the current mouse position in both device coordinates and local coordinates #ifdef _WINDOWS POINT pt; ::GetCursorPos( &pt ); GetCWnd( ).ScreenToClient( &pt ); RRealPoint devicePoint = RRealPoint( pt.x, pt.y ); RRealPoint localPoint = devicePoint; ::DeviceUnitsToLogicalUnits( localPoint, *this ); localPoint = ConvertPointToLocalCoordinateSystem( localPoint ); #endif // Get the direction to autoscroll EDirection autoScrollDirection = GetAutoScrollDirection( localPoint ); // If the left button is no longer down, or we are not moving in the same direction, // kill the timer. if( !( IsMouseCaptured() /*modifierKeys & kModifierLeftButton*/ ) || !( autoScrollDirection & m_AutoScrollDirection ) ) { delete m_pAutoScrollTimer; m_pAutoScrollTimer = 0; } // Otherwise, we are good to autoscroll. Simulate a mouse move event else OnXMouseMessage( kMouseMove, devicePoint, modifierKeys ); }
// **************************************************************************** // // Function Name: RWindowView::ScrollWindow( ) // // Description: Scrolls this window // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RWindowView::ScrollWindow( const RRealSize& scrollAmount ) { // Convert to device units RRealSize tempSize = scrollAmount; ::LogicalUnitsToDeviceUnits( tempSize, *this ); // Round RIntSize deviceSize( tempSize ); GetCWnd( ).ScrollWindow( deviceSize.m_dx, deviceSize.m_dy, NULL, NULL ); }
//************************************************************************************************** void LTVirtualButtonOwner::TrackLeave() { if (b_LeaveTracking) return; TRACKMOUSEEVENT tTrkMouse; tTrkMouse.cbSize = sizeof(TRACKMOUSEEVENT); tTrkMouse.dwFlags = TME_LEAVE; tTrkMouse.hwndTrack = GetCWnd()->m_hWnd; TrackMouseEvent(&tTrkMouse); b_LeaveTracking = true; }
// **************************************************************************** // // Function Name: RWindowView::GetSize( ) // // Description: Accessor // // Returns: The view size // // Exceptions: None // // **************************************************************************** // RRealSize RWindowView::GetSize( ) const { // Get the client rect CRect rcClient; GetCWnd( ).GetClientRect( &rcClient ); // Make a size out of it RRealSize size( rcClient.Width( ), rcClient.Height( ) ); // Convert it to logical units ::DeviceUnitsToLogicalUnits( size, *this ); return size; }
void CDockManager::OnMaximize() { ASSERT (IsMaximized()); BOOL bDockVisible = ::IsWindowVisible(ScGetHwnd()); CRect rMain = GetWorkArea(); if (bDockVisible && IsDocked()) { CRect rDock; ::GetWindowRect(ScGetHwnd(), rDock); switch (m_nDockPos) { case DMP_LEFT: if (m_nWidthDockedMax == -1) rMain.left += min(rDock.Width(), rMain.Width() / 2); else rMain.left += m_nWidthDockedMax; break; case DMP_RIGHT: if (m_nWidthDockedMax == -1) rMain.right -= min(rDock.Width(), rMain.Width() / 2); else rMain.right -= m_nWidthDockedMax; break; case DMP_BELOW: if (m_nHeightDockedMax == -1) rMain.bottom -= min(rDock.Height(), rMain.Height() / 2); else rMain.bottom -= m_nHeightDockedMax; break; default: ASSERT(0); return; } } MoveWindow(GetCWnd(), rMain); if (bDockVisible && IsDocked()) UpdateDockWindowPos(); }
BOOL CToolbarHelper::DisplayDropMenu(UINT nCmdID, BOOL bPressBtn) { // see if we have a menu for it THButton dm; if (m_mapTHButtons.Lookup(nCmdID, dm) && dm.nMenuID) { CMenu menu, *pSubMenu; if (menu.LoadMenu(dm.nMenuID)) { pSubMenu = menu.GetSubMenu(dm.nSubMenu); if (pSubMenu) { PrepareMenuItems(pSubMenu, GetCWnd()); pSubMenu->SetDefaultItem(dm.nDefCmdID); CRect rItem; int nIndex = m_pToolbar->CommandToIndex(nCmdID); m_pToolbar->GetItemRect(nIndex, rItem); m_pToolbar->ClientToScreen(rItem); if (bPressBtn) { m_pToolbar->GetToolBarCtrl().PressButton(nCmdID, TRUE); } pSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, rItem.left, rItem.bottom, GetCWnd()); if (bPressBtn) { m_pToolbar->GetToolBarCtrl().PressButton(nCmdID, FALSE); } return TRUE; // we handled it } } } return FALSE; }
// **************************************************************************** // // Function Name: RWindowView::GetViewableArea( ) // // Description: Accessor // // Returns: The rectangle into this view that is currently visible // due to scrolling. // // Exceptions: None // // **************************************************************************** // RRealRect RWindowView::GetViewableArea( ) const { // Get the client rect from MFC RECT clientRect; GetCWnd( ).GetClientRect( &clientRect ); // Convert to a Renaissance rect in logical units RRealRect viewableRect( clientRect ); ::DeviceUnitsToLogicalUnits( viewableRect, *this ); // Offset to take into account scrolling if( m_pHorizontalScrollBar && m_pVerticalScrollBar ) { RRealSize offset( m_pHorizontalScrollBar->GetPosition( ), m_pVerticalScrollBar->GetPosition( ) ); ::DeviceUnitsToLogicalUnits( offset, *this ); viewableRect.Offset( offset ); } return viewableRect; }
// **************************************************************************** // // Function Name: RWindowView::GetCursorPosition( ) // // Description: Gets the current cursor position within this view // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // RRealPoint RWindowView::GetCursorPosition( ) const { // Get the absolute cursor position POINT pt; ::GetCursorPos( &pt ); // Convert to client coordinates GetCWnd( ).ScreenToClient( &pt ); RRealPoint cursorPosition( pt.x, pt.y ); // Convert to logical units ::DeviceUnitsToLogicalUnits( cursorPosition, *this ); // Get our transform R2dTransform transform; ApplyTransform( transform, FALSE, FALSE ); // Invert the transform and convert the point to our coordinate system transform.Invert( ); return cursorPosition * transform; }
LRESULT CDockManager::ScWindowProc(HWND hRealWnd, UINT msg, WPARAM wp, LPARAM lp) { switch (msg) { case WM_MOVE: if (IsDocked()) { LRESULT lr = ScDefault(hRealWnd); if (m_bResizeUpdate) UpdateMainWindowPos(); return lr; } break; case WM_SIZE: if (IsDocked()) { LRESULT lr = ScDefault(hRealWnd); if (m_bResizeUpdate) UpdateMainWindowPos(); // save dock width if (m_bSizeUpdate && ::IsWindowVisible(ScGetHwnd())) { CRect rDock; ::GetWindowRect(ScGetHwnd(), rDock); if (IsMaximized()) { if (m_nDockPos == DMP_BELOW) m_nHeightDockedMax = rDock.Height(); else m_nWidthDockedMax = rDock.Width(); } else { if (m_nDockPos == DMP_BELOW) m_nHeightDocked = rDock.Height(); else m_nWidthDocked = rDock.Width(); } } return lr; } break; case WM_SYSCOMMAND: if (IsDocked()) { switch (wp) { // hide system menu case SC_KEYMENU: case SC_MOUSEMENU: return 0; // don't allow docked window to be minimized or maximized directly // instead, send the message to the main window case SC_MAXIMIZE: case SC_MINIMIZE: return SendMessage(msg, wp, lp); // if the dock window is being closed and the main window is maximized // then readjust the main window rect case SC_CLOSE: if (IsMaximized()) { LRESULT lr = ScDefault(hRealWnd); OnMaximize(); return lr; } break; } } break; case WM_NCRBUTTONDOWN: // if this is in the caption then eat it if (IsDocked() && wp == HTCAPTION) { // activate the window first ScSendMessage(WM_ACTIVATE, WA_CLICKACTIVE, NULL); return 0; } break; case WM_NCLBUTTONDOWN: // if this is in the caption and the main window in maxed // then eat if (IsDocked() && wp == HTCAPTION && IsMaximized()) { // activate the window first ScSendMessage(WM_ACTIVATE, WA_CLICKACTIVE, NULL); return 0; } break; case WM_NCLBUTTONDBLCLK: if (wp == HTCAPTION) { // toggle the docked state if (IsDocked()) UnDock(); else Dock(m_nLastDockPos); // and eat the message return 0; } break; case WM_NCHITTEST: if (IsDocked()) { UINT nHitTest = ScDefault(hRealWnd); // if the main window is _not_ unmaximized then don't let the // docked window be resized on it's docked edge // because its not intuitive and causes no end of trouble :) if (!IsMaximized()) { switch (m_nDockPos) { case DMP_LEFT: if (nHitTest == HTRIGHT || nHitTest == HTTOPRIGHT || nHitTest == HTBOTTOMRIGHT) nHitTest = HTCLIENT; break; case DMP_RIGHT: if (nHitTest == HTLEFT || nHitTest == HTTOPLEFT || nHitTest == HTBOTTOMLEFT) nHitTest = HTCLIENT; break; case DMP_BELOW: if (nHitTest == HTTOP || nHitTest == HTTOPLEFT || nHitTest == HTTOPRIGHT) nHitTest = HTCLIENT; break; default: ASSERT(0); break; } } // else main window is maximized so _only_ let it be resized on its // docked edge and resize the main window afterwards else { switch (m_nDockPos) { case DMP_LEFT: if (nHitTest == HTTOPRIGHT || nHitTest == HTBOTTOMRIGHT || nHitTest == HTLEFT || nHitTest == HTTOPLEFT || nHitTest == HTBOTTOMLEFT || nHitTest == HTTOP || nHitTest == HTBOTTOM) { nHitTest = HTCLIENT; } break; case DMP_RIGHT: if (nHitTest == HTTOPRIGHT || nHitTest == HTBOTTOMRIGHT || nHitTest == HTRIGHT || nHitTest == HTTOPLEFT || nHitTest == HTBOTTOMLEFT || nHitTest == HTTOP || nHitTest == HTBOTTOM) { nHitTest = HTCLIENT; } break; case DMP_BELOW: if (nHitTest == HTTOPRIGHT || nHitTest == HTBOTTOMRIGHT || nHitTest == HTRIGHT || nHitTest == HTTOPLEFT || nHitTest == HTBOTTOMLEFT || nHitTest == HTLEFT || nHitTest == HTBOTTOM) { nHitTest = HTCLIENT; } break; default: ASSERT(0); break; } } return nHitTest; } break; case WM_GETMINMAXINFO: if (IsDocked()) { LRESULT lr = ScDefault(hRealWnd); // save off our last min size LPMINMAXINFO pMMI = (LPMINMAXINFO)lp; m_sizeDockMin = pMMI->ptMinTrackSize; OnMinMaxInfo(pMMI, FALSE); return lr; } case WM_WINDOWPOSCHANGED: // if the dock window is being shown/hidden and the main window is maximized // then adjust the main window rect if (IsDocked() && IsMaximized()) { LPWINDOWPOS lpwp = (LPWINDOWPOS)lp; BOOL bVisible = ::IsWindowVisible(hRealWnd); BOOL bWantHide = (lpwp->flags & SWP_HIDEWINDOW); //BOOL bWantShow = (lpwp->flags & SWP_SHOWWINDOW); if (bVisible && bWantHide) // special case { CAutoFlag af(m_bResizeUpdate, FALSE); LRESULT lr = ScDefault(hRealWnd); CRect rMain = GetWorkArea(); MoveWindow(GetCWnd(), rMain); return lr; } else //if (!bVisible && bWantShow) { LRESULT lr = ScDefault(hRealWnd); OnMaximize(); return lr; } } break; } return ScDefault(hRealWnd); }
// **************************************************************************** // // Function Name: RWindowView::IsEventPending( ) // // Description: Check if there are any pending events in the Queue. // This query can be made during idle processing to check // if control should return to the framework. // // Returns: TRUE if the are system events pending // // Exceptions: None // // **************************************************************************** // BOOLEAN RWindowView::IsEventPending( ) const { MSG msg; return (BOOLEAN)PeekMessage( &msg, GetCWnd().GetSafeHwnd(), 0, 0, PM_NOYIELD|PM_NOREMOVE ); }
// **************************************************************************** // // Function Name: RWindowView::SetKeyFocus( ) // // Description: Set the Windows key focus to be this view. // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RWindowView::SetKeyFocus( ) { GetCWnd().SetFocus( ); }
void CDockManager::FitDockWindowToWorkArea() { // make sure the dock window is fully visible CRect rDock, rMain, rWorkArea = GetWorkArea(); ::GetWindowRect(ScGetHwnd(), rDock); GetWindowRect(rMain); CRect rIntersect; // if it is then we're done if (rIntersect.IntersectRect(rWorkArea, rDock) && rIntersect == rDock) return; // else adjust the edges to be within the work area // try adjust the size until we hit m_sizeDockMin switch (m_nDockPos) { case DMP_LEFT: rDock.left = max(rDock.left, rWorkArea.left); rDock.right = max(rDock.left + m_sizeDockMin.cx, rDock.right); ScGetCWnd()->MoveWindow(rDock); // check we've not pushed the main window over if (rDock.right > rMain.left) { rMain.OffsetRect(rDock.right - rMain.left, 0); // and stop the right edge of the main window spilling out rMain.right = min(rMain.right, rWorkArea.right); GetCWnd()->MoveWindow(rMain); } break; case DMP_RIGHT: rDock.right = min(rDock.right, rWorkArea.right); rDock.left = min(rDock.right - m_sizeDockMin.cx, rDock.left); ScGetCWnd()->MoveWindow(rDock); // check we've not pushed the main window over if (rDock.left < rMain.right) { rMain.OffsetRect(rDock.left - rMain.right, 0); // and stop the left edge of the main window spilling out rMain.left = max(rMain.left, rWorkArea.left); GetCWnd()->MoveWindow(rMain); } break; case DMP_BELOW: rDock.bottom = min(rDock.bottom, rWorkArea.bottom); rDock.top = min(rDock.bottom - m_sizeDockMin.cy, rDock.top); ScGetCWnd()->MoveWindow(rDock); // check we've not pushed the main window over if (rDock.top < rMain.bottom) { rMain.OffsetRect(0, rDock.top - rMain.bottom); // and stop the top edge of the main window spilling out rMain.top = max(rMain.top, rWorkArea.top); GetCWnd()->MoveWindow(rMain); } break; case DMP_UNDOCKED: // just centre the window on the desktop ScGetCWnd()->CenterWindow(); break; } }
void CDockManager::UpdateMainWindowPos() { ASSERT (IsDocked()); if (!IsDocked()) return; CRect rMain, rDock; GetWindowRect(rMain); ::GetWindowRect(ScGetHwnd(), rDock); // if the main window is maximized then shrink/enlarge // the window if (IsMaximized()) { rMain = GetWorkArea(); switch (m_nDockPos) { case DMP_LEFT: rMain.left = rDock.right; break; case DMP_RIGHT: rMain.right = rDock.left; break; case DMP_BELOW: rMain.bottom = rDock.top; break; default: ASSERT(0); return; } } // else just move the main window else { switch (m_nDockPos) { case DMP_LEFT: rMain.top = rDock.top; rMain.bottom = rDock.bottom; rMain.right = rDock.right + rMain.Width(); rMain.left = rDock.right; break; case DMP_RIGHT: rMain.top = rDock.top; rMain.bottom = rDock.bottom; rMain.left = rDock.left - rMain.Width(); rMain.right = rDock.left; break; case DMP_BELOW: rMain.left = rDock.left; rMain.right = rDock.right; rMain.top = rDock.top - rMain.Height(); rMain.bottom = rDock.top; break; default: ASSERT(0); return; } } MoveWindow(GetCWnd(), rMain); }
UINT CShortcutManager::ProcessMessage(const MSG* pMsg, DWORD* pShortcut) const { // 只处理可用的快捷键 if (!IsWindowEnabled() || !IsWindowVisible()) { return FALSE; } // 只处理键盘消息 if (pMsg->message != WM_KEYDOWN && pMsg->message != WM_SYSKEYDOWN) { return FALSE; } CWnd* pWnd = CWnd::FromHandle(pMsg->hwnd); CWnd* pMainWnd = GetCWnd(); CWnd* pTopParent = pWnd->GetParentOwner(); if (pTopParent != pMainWnd) { return FALSE; } switch (pMsg->wParam) { case VK_CONTROL: case VK_SHIFT: case VK_MENU: case VK_NUMLOCK: case VK_SCROLL: case VK_CAPITAL: return FALSE; // 不去处理 return/cancel 键 case VK_RETURN: case VK_CANCEL: return FALSE; case VK_MBUTTON: break; // 快捷键 default: { //不去处理发往hotkey控件的消息 if (IsClass(pMsg->hwnd, WC_HOTKEY)) { return FALSE; } // get 获取快捷方式DWORD值 BOOL bExtKey = (pMsg->lParam & 0x01000000); DWORD dwShortcut = GetShortcut((WORD)pMsg->wParam, bExtKey); // 查找相应的命令ID UINT nCmdID = 0; if (!m_mapShortcut2ID.Lookup(dwShortcut, nCmdID) || !nCmdID) { return FALSE; } if (m_wInvalidComb & HKCOMB_EDITCTRLS) { if (IsEditControl(pMsg->hwnd)) { if (IsEditShortcut(dwShortcut)) { return FALSE; } WORD wModifiers = HIWORD(dwShortcut); if (pMsg->wParam >= VK_F1 && pMsg->wParam <= VK_F24) { // ok } // 3. else must have <ctrl> or <alt> else { if (!(wModifiers & (HOTKEYF_ALT | HOTKEYF_CONTROL))) { return FALSE; } } } } // 返回 command ID if (m_bAutoSendCmds) { SendMessage(NULL, WM_COMMAND, nCmdID, 0); } if (pShortcut) { *pShortcut = dwShortcut; } return nCmdID; } } return FALSE; }
// **************************************************************************** // // Function Name: RWindowView::SetMouseCapture( ) // // Description: Captures the mouse to this view. // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RWindowView::SetMouseCapture( ) { WinCode( GetCWnd( ).SetCapture( ) ); RView::SetMouseCapture( ); }