//***************************************************************************************** void CBCGMenuPage::OnBcgbarresResetFrameMenu() { UpdateData (); if (m_pMenuBar == NULL) { ASSERT (FALSE); return; } int iIndex = m_wndMenuesList.GetCurSel (); if (iIndex == CB_ERR) { ASSERT (FALSE); return; } { CBCGLocalResource locaRes; CString strPrompt; strPrompt.Format (IDS_BCGBARRES_RESET_MENU_FMT, m_strMenuName); if (AfxMessageBox (strPrompt, MB_YESNO | MB_ICONQUESTION) != IDYES) { return; } } HMENU hOldMenu = NULL; CBCGMultiDocTemplate* pTemplate = (CBCGMultiDocTemplate*) m_wndMenuesList.GetItemData (iIndex); if (pTemplate != NULL) // Document's menu { ASSERT_VALID (pTemplate); HINSTANCE hInst = AfxFindResourceHandle ( MAKEINTRESOURCE (pTemplate->GetResId ()), RT_MENU); BOOL bIsCurrent = (pTemplate->m_hMenuShared == m_hmenuCurr); hOldMenu = pTemplate->m_hMenuShared; pTemplate->m_hMenuShared = ::LoadMenu (hInst, MAKEINTRESOURCE (pTemplate->GetResId ())); m_pMenuBar->CreateFromMenu (pTemplate->m_hMenuShared, FALSE); CBCGMenuBar::UpdateMDIChildrenMenus (pTemplate); if (m_pParentFrame != NULL) { if (m_pParentFrame->SendMessage (BCGM_RESETMENU, pTemplate->GetResId ())) { m_pMenuBar->AdjustLayout(); }; } g_menuHash.SaveMenuBar (pTemplate->m_hMenuShared, m_pMenuBar); if (bIsCurrent) { ASSERT (!m_bIsDefaultMDIMenu); m_hmenuCurr = pTemplate->m_hMenuShared; } } else // Frame's default menu { UINT uiDefMenuResId = m_pMenuBar->GetDefaultMenuResId (); if (uiDefMenuResId != 0) { HINSTANCE hInst = AfxFindResourceHandle ( MAKEINTRESOURCE (uiDefMenuResId), RT_MENU); hOldMenu = m_pMenuBar->m_hDefaultMenu; HMENU hDefaultMenu = ::LoadMenu (hInst, MAKEINTRESOURCE (uiDefMenuResId)); m_pMenuBar->OnDefaultMenuLoaded (hDefaultMenu); m_pMenuBar->CreateFromMenu (hDefaultMenu, TRUE); if (m_pParentFrame != NULL) { if (m_pParentFrame->SendMessage (BCGM_RESETMENU, uiDefMenuResId)) { m_pMenuBar->AdjustLayout(); }; m_pParentFrame->m_hMenuDefault = hDefaultMenu; } g_menuHash.SaveMenuBar (hDefaultMenu, m_pMenuBar); if (m_bIsDefaultMDIMenu) { m_hmenuCurr = hDefaultMenu; } } } if (m_pParentFrame != NULL) { m_pParentFrame->OnUpdateFrameMenu (m_hmenuCurr); } if (hOldMenu != NULL) { ASSERT (::IsMenu (hOldMenu)); g_menuHash.RemoveMenu (hOldMenu); ::DestroyMenu (hOldMenu); } m_pMenuBar->Invalidate (); m_pMenuBar->UpdateWindow (); }
//******************************************************************************** BOOL CBCGPRibbonSlider::OnProcessKey (UINT nChar) { ASSERT_VALID (this); const int nPrevPos = m_nPos; int nPos = m_nPos; switch (nChar) { case VK_LEFT: if (!IsVert ()) { nPos--; } else { return FALSE; } break; case VK_UP: if (IsVert ()) { nPos++; } else { return FALSE; } break; case VK_SUBTRACT: if (!m_bZoomButtons) { return FALSE; } case VK_PRIOR: if (IsVert ()) { nPos += m_nPageSize; } else { nPos -= m_nPageSize; } break; case VK_ADD: if (!m_bZoomButtons) { return FALSE; } case VK_NEXT: if (IsVert ()) { nPos -= m_nPageSize; } else { nPos += m_nPageSize; } break; case VK_RIGHT: if (!IsVert ()) { nPos++; } else { return FALSE; } break; case VK_DOWN: if (IsVert ()) { nPos--; } else { return FALSE; } break; case VK_HOME: nPos = IsVert () ? m_nMax : m_nMin; break; case VK_END: nPos = IsVert () ? m_nMin : m_nMax; break; default: return FALSE; } nPos = min (max (m_nMin, nPos), m_nMax); if (nPrevPos != nPos) { SetPos (nPos); NotifyCommand (); } return TRUE; }
HFONT CToolBoxCtrl::SetCurrFont(CDC* pDC) { ASSERT_VALID(pDC); return(HFONT) ::SelectObject(pDC->GetSafeHdc(), m_hFont != NULL ? m_hFont : ::GetStockObject(DEFAULT_GUI_FONT)); }
//***************************************************************************** void CBCGPRibbonSlider::SetZoomButtons (BOOL bSet) { ASSERT_VALID (this); m_bZoomButtons = bSet; }
//*************************************************************************** BOOL CBCGPRibbonSlider::IsAutoRepeatMode (int& /*nDelay*/) const { ASSERT_VALID (this); return m_nPressed == nZoomInIndex || m_nPressed == nZoomOutIndex; }
void MyGraph::DrawLegend(CDC& dc) { VALIDATE; ASSERT_VALID(&dc); // Create the legend font. CFont fontLegend; int pointFontHeight = max(m_rcGraph.Height() / LEGEND_DIVISOR, MIN_FONT_SIZE); VERIFY(fontLegend.CreatePointFont(pointFontHeight, _T("Arial"), &dc)); // Get the height of each label. LOGFONT lf; ::SecureZeroMemory(&lf, sizeof(lf)); VERIFY(fontLegend.GetLogFont(&lf)); int nLabelHeight(abs(lf.lfHeight)); // Get number of legend entries int nLegendEntries = max(1, GetMaxSeriesSize()); // Calculate optimal label height = AvailableLegendHeight/AllAuthors // Use a buffer of (GAP_PIXELS / 2) on each side inside the legend, and in addition the same // gab above and below the legend frame, so in total 2*GAP_PIXELS double optimalLabelHeight = double(m_rcGraph.Height() - 2*GAP_PIXELS)/nLegendEntries; // Now relate the LabelHeight to the PointFontHeight int optimalPointFontHeight = int(pointFontHeight*optimalLabelHeight/nLabelHeight); // Limit the optimal PointFontHeight to the available range optimalPointFontHeight = min( max(optimalPointFontHeight, MIN_FONT_SIZE), pointFontHeight); // If the optimalPointFontHeight is different from the initial one, create a new legend font if (optimalPointFontHeight != pointFontHeight) { fontLegend.DeleteObject(); VERIFY(fontLegend.CreatePointFont(optimalPointFontHeight, _T("Arial"), &dc)); VERIFY(fontLegend.GetLogFont(&lf)); nLabelHeight = abs(lf.lfHeight); } // Calculate maximum number of authors that can be shown with the current label height int nShownAuthors = (m_rcGraph.Height() - 2*GAP_PIXELS)/nLabelHeight - 1; // Fix rounding errors. if (nShownAuthors+1 == GetMaxSeriesSize()) ++nShownAuthors; // Get number of authors to be shown. nShownAuthors = min(nShownAuthors, GetMaxSeriesSize()); // nShownAuthors contains now the number of authors CFont* pFontOld = dc.SelectObject(&fontLegend); ASSERT_VALID(pFontOld); // Determine actual size of legend. A buffer of (GAP_PIXELS / 2) on each side, // plus the height of each label based on the pint size of the font. int nLegendHeight = (GAP_PIXELS / 2) + (nShownAuthors * nLabelHeight) + (GAP_PIXELS / 2); // Draw the legend border. Allow LEGEND_COLOR_BAR_PIXELS pixels for // display of label bars. m_rcLegend.top = (m_rcGraph.Height() - nLegendHeight) / 2; m_rcLegend.bottom = m_rcLegend.top + nLegendHeight; m_rcLegend.right = m_rcGraph.Width() - GAP_PIXELS; m_rcLegend.left = m_rcLegend.right - GetMaxLegendLabelLength(dc) - LEGEND_COLOR_BAR_WIDTH_PIXELS; VERIFY(dc.Rectangle(m_rcLegend)); int skipped_row = -1; // if != -1, this is the row that we show the ... in if (nShownAuthors < GetMaxSeriesSize()) skipped_row = nShownAuthors-2; // Draw each group's label and bar. for (int nGroup = 0; nGroup < nShownAuthors; ++nGroup) { int nLabelTop(m_rcLegend.top + (nGroup * nLabelHeight) + (GAP_PIXELS / 2)); int nShownGroup = nGroup; // introduce helper variable to avoid code duplication // Do we have a skipped row? if (skipped_row != -1) { if (nGroup == skipped_row) { // draw the dots VERIFY(dc.TextOut(m_rcLegend.left + GAP_PIXELS, nLabelTop, _T("...") )); continue; } if (nGroup == nShownAuthors-1) { // we show the last group instead of the scheduled group nShownGroup = GetMaxSeriesSize()-1; } } // Draw the label. VERIFY(dc.TextOut(m_rcLegend.left + GAP_PIXELS, nLabelTop, m_saLegendLabels.GetAt(nShownGroup))); // Determine the bar. CRect rcBar; rcBar.left = m_rcLegend.left + GAP_PIXELS + GetMaxLegendLabelLength(dc) + GAP_PIXELS; rcBar.top = nLabelTop + LEGEND_COLOR_BAR_GAP_PIXELS; rcBar.right = m_rcLegend.right - GAP_PIXELS; rcBar.bottom = rcBar.top + nLabelHeight - LEGEND_COLOR_BAR_GAP_PIXELS; VERIFY(dc.Rectangle(rcBar)); // Draw bar for group. COLORREF crBar(m_dwaColors.GetAt(nShownGroup)); CBrush br(crBar); CBrush* pBrushOld = dc.SelectObject(&br); ASSERT_VALID(pBrushOld); rcBar.DeflateRect(LEGEND_COLOR_BAR_GAP_PIXELS, LEGEND_COLOR_BAR_GAP_PIXELS); dc.FillRect(rcBar, &br); dc.SelectObject(pBrushOld); br.DeleteObject(); } VERIFY(dc.SelectObject(pFontOld)); fontLegend.DeleteObject(); }
void CDijshowView::OnDraw(CDC* pDC) { CDijshowDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); CRect client,rect; CPoint point; CDC dc,*pDrawDC; CBitmap bitmap, *pOldBitmap; pDC->GetClipBox(client); point=client.TopLeft(); // draw to offscreen bitmap for fast looking repaints if (dc.CreateCompatibleDC(pDC)) { if (bitmap.CreateCompatibleBitmap(pDC, client.Width(),client.Height())) { OnPrepareDC(&dc, NULL);//用途? pDrawDC = &dc; // offset origin more because bitmap is just piece of the whole drawing pOldBitmap = dc.SelectObject(&bitmap); dc.OffsetViewportOrg(-client.left, -client.top); // dc.OffsetViewportOrg(client.left, client.top); dc.SetBrushOrg(client.left % 8, client.top % 8); // might as well clip to the same rectangle dc.IntersectClipRect(client); //用途 } } CBrush br; // CBrush * old_br; br.CreateSolidBrush(RGB(255,255,255)); pDrawDC->SelectObject(br); CRect rect1(client.left-5,client.top-5,client.right+5,client.bottom+5); pDrawDC->Rectangle(rect1); POSITION pos = NodeList.GetHeadPosition(); for (int i=0;i < NodeList.GetCount();i++) { CNodeObject * node=NodeList.GetNext(pos); node->Draw(pDrawDC); } pos = PathList.GetHeadPosition(); for ( i=0;i < PathList.GetCount();i++) { CPathObject * path=PathList.GetNext(pos); path->Draw(pDrawDC); } if (pDrawDC != pDC) { pDC->SetViewportOrg(0, 0); pDC->SetWindowOrg(0,0); pDC->SetMapMode(MM_TEXT); dc.SetViewportOrg(0, 0); dc.SetWindowOrg(0,0); dc.SetMapMode(MM_TEXT); pDC->BitBlt(client.left,client.top, client.Width(),client.Height(), &dc, 0,0, SRCCOPY); dc.SelectObject(pOldBitmap); } // TODO: add draw code for native data here }
void CDocument::UpdateFrameCounts() // assumes 1 doc per frame { // walk all frames of views (mark and sweep approach) POSITION pos = GetFirstViewPosition(); while (pos != NULL) { CView* pView = GetNextView(pos); ASSERT_VALID(pView); ASSERT(::IsWindow(pView->m_hWnd)); if (pView->IsWindowVisible()) // Do not count invisible windows. { CFrameWnd* pFrame = pView->GetParentFrame(); if (pFrame != NULL) pFrame->m_nWindow = -1; // unknown } } // now do it again counting the unique ones int nFrames = 0; pos = GetFirstViewPosition(); while (pos != NULL) { CView* pView = GetNextView(pos); ASSERT_VALID(pView); ASSERT(::IsWindow(pView->m_hWnd)); if (pView->IsWindowVisible()) // Do not count invisible windows. { CFrameWnd* pFrame = pView->GetParentFrame(); if (pFrame != NULL && pFrame->m_nWindow == -1) { ASSERT_VALID(pFrame); // not yet counted (give it a 1 based number) pFrame->m_nWindow = ++nFrames; } } } // lastly walk the frames and update titles (assume same order) // go through frames updating the appropriate one int iFrame = 1; pos = GetFirstViewPosition(); while (pos != NULL) { CView* pView = GetNextView(pos); ASSERT_VALID(pView); ASSERT(::IsWindow(pView->m_hWnd)); if (pView->IsWindowVisible()) // Do not count invisible windows. { CFrameWnd* pFrame = pView->GetParentFrame(); if (pFrame != NULL && pFrame->m_nWindow == iFrame) { ASSERT_VALID(pFrame); if (nFrames == 1) pFrame->m_nWindow = 0; // the only one of its kind pFrame->OnUpdateFrameTitle(TRUE); iFrame++; } } } ASSERT(iFrame == nFrames + 1); }
void CDocument::OnFinalRelease() { ASSERT_VALID(this); OnCloseDocument(); // may 'delete this' }
void COXItemTipWnd::Display(CRect& rect, CString sText, int nOffset, int nAlignment, CFont* pFont, COLORREF clrText, COLORREF clrBackground) { ASSERT_VALID(m_pParentWnd); ASSERT(::IsWindow(m_pParentWnd->GetSafeHwnd())); ASSERT(::IsWindow(m_hWnd)); CWnd* pWnd=GetActiveWindow(); if(pWnd==NULL || (!IsDescendant(pWnd,m_pParentWnd) && (m_pParentWnd->GetExStyle()&WS_EX_TOPMOST)!=WS_EX_TOPMOST)) { return; } CClientDC dc(this); // device context for drawing CFont* pOldFont=NULL; if(pFont) { pOldFont=dc.SelectObject(pFont); } COLORREF clrOld=ID_OX_COLOR_NONE; if(clrText!=ID_OX_COLOR_NONE) { clrOld=dc.SetTextColor(clrText); } int nOldBkMode=dc.SetBkMode(TRANSPARENT); CRect rectDraw=rect; dc.DrawText(sText,&rectDraw,DT_CALCRECT|DT_LEFT|DT_SINGLELINE|DT_NOPREFIX); rectDraw.right+=2*nOffset; if(rectDraw.Width()>rect.Width()) { rect.right=rect.left+rectDraw.Width(); } if(rectDraw.Height()>rect.Height()) { rect.bottom=rect.top+rectDraw.Height(); } // it's show time! m_pParentWnd->ClientToScreen(&rect); // adjust rectangle to fit the screen // CWnd* pParentWnd=m_pParentWnd; BOOL bTopMostParent=FALSE; while(pParentWnd!=NULL) { if(pParentWnd->GetExStyle() & WS_EX_TOPMOST) { bTopMostParent=TRUE; break; } pParentWnd=pParentWnd->GetParent(); } DWORD dwMessagePos=::GetMessagePos(); CPoint point(GET_X_LPARAM(dwMessagePos),GET_Y_LPARAM(dwMessagePos)); CRect rectDisplay=GetMonitorRectFromPoint(point,!bTopMostParent); if(rect.right>rectDisplay.right) { rect.OffsetRect(rectDisplay.right-rect.right,0); } if(rect.left<rectDisplay.left) { rect.OffsetRect(rectDisplay.left-rect.left,0); } // ///////////////////////////////////////////////////////////// if(bTopMostParent) { SetWindowPos(&wndTopMost,rect.left,rect.top,rect.Width(), rect.Height(),SWP_NOACTIVATE); } else { SetWindowPos(NULL,rect.left,rect.top,rect.Width(), rect.Height(),SWP_NOZORDER|SWP_NOACTIVATE); } ShowWindow(SW_SHOWNA); if(clrBackground!=ID_OX_COLOR_NONE) { CBrush brush; brush.CreateSolidBrush(clrBackground); CRect rectClient; GetClientRect(rectClient); dc.FillRect(&rectClient,&brush); } else { SendMessage(WM_ERASEBKGND,(WPARAM)(HDC)dc); } rectDraw=rect; rectDraw.DeflateRect(nOffset,0); ScreenToClient(&rectDraw); dc.DrawText(sText,&rectDraw,nAlignment|DT_SINGLELINE|DT_VCENTER|DT_NOPREFIX); if(pOldFont) { dc.SelectObject(pOldFont); } if(clrOld!=ID_OX_COLOR_NONE) { dc.SetTextColor(clrOld); } dc.SetBkMode(nOldBkMode); m_nTimerID=SetTimer(ID_OXITEMTIP_TIMER,ID_OXITEMTIP_TIMER_DELAY,NULL); if(m_nTimerID==0) { TRACE(_T("COXItemTipWnd::Display: failed to set timer to check item tip state\n")); } }
CDocument* CMyDocManager::OpenDocumentFile(LPCTSTR lpszFileName) { // From MFC: CDocManager::OpenDocumentFile CString strFileName = lpszFileName; strFileName.TrimLeft(); strFileName.TrimRight(); if (strFileName[0] == '\"') strFileName.Delete(0); int nPos = strFileName.ReverseFind('\"'); if (nPos != -1) strFileName.Delete(nPos); CString strQuery, strPage; nPos = strFileName.Find('?'); if (nPos != -1) { strQuery = strFileName.Mid(nPos + 1); strFileName = strFileName.Left(nPos); } bool bPathTooLong = false; TCHAR szPath[_MAX_PATH]; if (!AfxFullPath(szPath, strFileName)) bPathTooLong = true; if (bPathTooLong || !PathFileExists(szPath)) { // Try extracting page number nPos = strFileName.ReverseFind('#'); if (nPos != -1) { strPage = strFileName.Mid(nPos + 1); strFileName = strFileName.Left(nPos); if (!AfxFullPath(szPath, strFileName)) bPathTooLong = true; } } if (bPathTooLong) { AfxMessageBox(FormatString(IDS_PATH_TOO_LONG, szPath), MB_ICONEXCLAMATION | MB_OK); return NULL; } TCHAR szLinkName[_MAX_PATH]; if (AfxResolveShortcut(GetMainWnd(), szPath, szLinkName, _MAX_PATH)) lstrcpy(szPath, szLinkName); // find the highest confidence CDocTemplate::Confidence bestMatch = CDocTemplate::noAttempt; CDocTemplate* pBestTemplate = NULL; CDocument* pOpenDocument = NULL; CMainFrame* pOldMainFrm = (CMainFrame*) theApp.m_pMainWnd; POSITION pos = m_templateList.GetHeadPosition(); while (pos != NULL) { CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetNext(pos); ASSERT_KINDOF(CDocTemplate, pTemplate); CDocTemplate::Confidence match; ASSERT(pOpenDocument == NULL); match = pTemplate->MatchDocType(szPath, pOpenDocument); if (match > bestMatch) { bestMatch = match; pBestTemplate = pTemplate; } if (match == CDocTemplate::yesAlreadyOpen) break; } if (pOpenDocument != NULL) { POSITION pos = pOpenDocument->GetFirstViewPosition(); if (pos != NULL) { CView* pView = pOpenDocument->GetNextView(pos); ASSERT_VALID(pView); CMainFrame* pMainFrm = (CMainFrame*) pView->GetTopLevelFrame(); pMainFrm->ActivateDocument(pOpenDocument); } else TRACE(_T("Error: Can not find a view for document to activate.\n")); } if (pOpenDocument == NULL) { if (pBestTemplate == NULL) { AfxMessageBox(AFX_IDP_FAILED_TO_OPEN_DOC); return NULL; } pOpenDocument = pBestTemplate->OpenDocumentFile(szPath); } if (pOpenDocument != NULL) { CDjVuDoc* pDoc = (CDjVuDoc*) pOpenDocument; CDjVuView* pView = pDoc->GetDjVuView(); CMainFrame* pMainFrm = pView->GetMainFrame(); // CDocManager::OnDDECommand shows the previous main window. // If it was in the fullscreen mode, hide it back. if (pOldMainFrm != NULL && pOldMainFrm != pMainFrm && pOldMainFrm->IsFullscreenMode()) pOldMainFrm->ShowWindow(SW_HIDE); if (!strPage.IsEmpty()) pView->GoToURL(MakeUTF8String(_T("#") + strPage)); } return pOpenDocument; }
BOOL COXItemTipWnd::PreTranslateMessage(MSG* pMsg) { ASSERT_VALID(m_pParentWnd); ASSERT(::IsWindow(m_pParentWnd->GetSafeHwnd())); ASSERT(::IsWindow(m_hWnd)); CWnd *pWnd=NULL; int nHitTest; pWnd=m_pParentWnd; while(pWnd!=NULL && (pWnd->GetStyle()&WS_CHILD)!=0) { pWnd=pWnd->GetParent(); } ASSERT(pWnd!=NULL); if(pMsg->message==WM_MOUSEMOVE || (pMsg->message==WM_TIMER && pMsg->wParam==(WPARAM)m_nTimerID)) { CPoint point; ::GetCursorPos(&point); CRect rect; GetWindowRect(rect); pWnd=WindowFromPoint(point); ASSERT(pWnd!=NULL); if(pWnd->GetSafeHwnd()==GetSafeHwnd()) { return CWnd::PreTranslateMessage(pMsg); } else { if(pMsg->message!=WM_MOUSEMOVE) { Hide(); return TRUE; } } } switch(pMsg->message) { case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: case WM_MBUTTONDOWN: case WM_LBUTTONUP: case WM_RBUTTONUP: case WM_MBUTTONUP: case WM_MOUSEMOVE: case WM_LBUTTONDBLCLK: case WM_RBUTTONDBLCLK: case WM_MBUTTONDBLCLK: { POINTS points=MAKEPOINTS(pMsg->lParam); CPoint point(points.x,points.y); ClientToScreen(&point); pWnd=WindowFromPoint(point); ASSERT(pWnd); if(pWnd==this) { pWnd=m_pParentWnd; } nHitTest=(int)pWnd->SendMessage(WM_NCHITTEST,0, MAKELONG(point.x,point.y)); if(nHitTest==HTCLIENT) { pWnd->ScreenToClient(&point); } else { switch(pMsg->message) { case WM_LBUTTONDOWN: { pMsg->message=WM_NCLBUTTONDOWN; break; } case WM_RBUTTONDOWN: { pMsg->message=WM_NCRBUTTONDOWN; break; } case WM_MBUTTONDOWN: { pMsg->message=WM_NCMBUTTONDOWN; break; } case WM_LBUTTONUP: { pMsg->message=WM_NCLBUTTONUP; break; } case WM_RBUTTONUP: { pMsg->message=WM_NCRBUTTONUP; break; } case WM_MBUTTONUP: { pMsg->message=WM_NCMBUTTONUP; break; } case WM_LBUTTONDBLCLK: { pMsg->message=WM_NCLBUTTONDBLCLK; break; } case WM_RBUTTONDBLCLK: { pMsg->message=WM_NCRBUTTONDBLCLK; break; } case WM_MBUTTONDBLCLK: { pMsg->message=WM_NCMBUTTONDBLCLK; break; } case WM_MOUSEMOVE: { pMsg->message=WM_NCMOUSEMOVE; break; } } pMsg->wParam=nHitTest; } pMsg->lParam=MAKELONG(point.x,point.y); ASSERT(pWnd!=this); } case WM_KEYDOWN: case WM_SYSKEYDOWN: { ASSERT(pWnd!=NULL); Hide(pMsg,pWnd); return TRUE; } } BOOL bResult=CWnd::PreTranslateMessage(pMsg); return bResult; }
CDocument* CSingleDocTemplate::OpenDocumentFile(LPCTSTR lpszPathName, BOOL bMakeVisible) // if lpszPathName == NULL => create new file of this type { CDocument* pDocument = NULL; CFrameWnd* pFrame = NULL; BOOL bCreated = FALSE; // => doc and frame created BOOL bWasModified = FALSE; if (m_pOnlyDoc != NULL) { // already have a document - reinit it pDocument = m_pOnlyDoc; if (!pDocument->SaveModified()) return NULL; // leave the original one pFrame = (CFrameWnd*)AfxGetMainWnd(); ASSERT(pFrame != NULL); ASSERT_KINDOF(CFrameWnd, pFrame); ASSERT_VALID(pFrame); } else { // create a new document pDocument = CreateNewDocument(); ASSERT(pFrame == NULL); // will be created below bCreated = TRUE; } if (pDocument == NULL) { AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC); return NULL; } ASSERT(pDocument == m_pOnlyDoc); if (pFrame == NULL) { ASSERT(bCreated); // create frame - set as main document frame BOOL bAutoDelete = pDocument->m_bAutoDelete; pDocument->m_bAutoDelete = FALSE; // don't destroy if something goes wrong pFrame = CreateNewFrame(pDocument, NULL); pDocument->m_bAutoDelete = bAutoDelete; if (pFrame == NULL) { AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC); delete pDocument; // explicit delete on error return NULL; } } if (lpszPathName == NULL) { // create a new document SetDefaultTitle(pDocument); // avoid creating temporary compound file when starting up invisible if (!bMakeVisible) pDocument->m_bEmbedded = TRUE; if (!pDocument->OnNewDocument()) { // user has been alerted to what failed in OnNewDocument TRACE(traceAppMsg, 0, "CDocument::OnNewDocument returned FALSE.\n"); if (bCreated) pFrame->DestroyWindow(); // will destroy document return NULL; } } else { CWaitCursor wait; // open an existing document bWasModified = pDocument->IsModified(); pDocument->SetModifiedFlag(FALSE); // not dirty for open if (!pDocument->OnOpenDocument(lpszPathName)) { // user has been alerted to what failed in OnOpenDocument TRACE(traceAppMsg, 0, "CDocument::OnOpenDocument returned FALSE.\n"); if (bCreated) { pFrame->DestroyWindow(); // will destroy document } else if (!pDocument->IsModified()) { // original document is untouched pDocument->SetModifiedFlag(bWasModified); } else { // we corrupted the original document SetDefaultTitle(pDocument); if (!pDocument->OnNewDocument()) { TRACE(traceAppMsg, 0, "Error: OnNewDocument failed after trying " "to open a document - trying to continue.\n"); // assume we can continue } } return NULL; // open failed } pDocument->SetPathName(lpszPathName); } CWinThread* pThread = AfxGetThread(); ASSERT(pThread); if (bCreated && pThread->m_pMainWnd == NULL) { // set as main frame (InitialUpdateFrame will show the window) pThread->m_pMainWnd = pFrame; } InitialUpdateFrame(pFrame, pDocument, bMakeVisible); return pDocument; }
void CSingleDocTemplate::AssertValid() const { CDocTemplate::AssertValid(); if (m_pOnlyDoc) ASSERT_VALID(m_pOnlyDoc); }
void MyGraph::DrawSeriesPie(CDC& dc) const { VALIDATE; ASSERT_VALID(&dc); // Determine width of pie display area (pie and space). int nSeriesSpace(0); int seriesCount = GetNonZeroSeriesCount(); int horizontalSpace(0); if (m_saLegendLabels.GetSize()) { // With legend box. horizontalSpace = m_nXAxisWidth - m_rcLegend.Width() - (GAP_PIXELS * 2); int nPieAndSpaceWidth(horizontalSpace / (seriesCount ? seriesCount : 1)); // Height is limiting factor. if (nPieAndSpaceWidth > m_nYAxisHeight - (GAP_PIXELS * 2)) { nSeriesSpace = (m_nYAxisHeight - (GAP_PIXELS * 2)); } else { // Width is limiting factor. nSeriesSpace = nPieAndSpaceWidth; } } else { // No legend box. horizontalSpace = m_nXAxisWidth; // Height is limiting factor. if (m_nXAxisWidth > m_nYAxisHeight * (seriesCount ? seriesCount : 1)) { nSeriesSpace = m_nYAxisHeight; } else { // Width is limiting factor. nSeriesSpace = m_nXAxisWidth / (seriesCount ? seriesCount : 1); } } // Make pies be centered horizontally int xOrigin = m_ptOrigin.x + GAP_PIXELS + (horizontalSpace - nSeriesSpace * seriesCount) / 2; // Create font for labels. CFont fontLabels; int pointFontHeight = max(m_rcGraph.Height() / Y_AXIS_LABEL_DIVISOR, MIN_FONT_SIZE); VERIFY(fontLabels.CreatePointFont(pointFontHeight, _T("Arial"), &dc)); CFont* pFontOld = dc.SelectObject(&fontLabels); ASSERT_VALID(pFontOld); // Draw each pie. int nPie(0); int nRadius((int) (nSeriesSpace * INTERSERIES_PERCENT_USED / 2.0)); POSITION pos(m_olMyGraphSeries.GetHeadPosition()); while (pos) { MyGraphSeries* pSeries = m_olMyGraphSeries.GetNext(pos); ASSERT_VALID(pSeries); // Don't leave a space for empty pies. if (0 < pSeries->GetNonZeroElementCount()) { // Locate this pie. CPoint ptCenter; ptCenter.x = xOrigin + (nSeriesSpace * nPie) + nSeriesSpace / 2; ptCenter.y = m_ptOrigin.y - m_nYAxisHeight / 2; CRect rcPie; rcPie.left = ptCenter.x - nRadius; rcPie.right = ptCenter.x + nRadius; rcPie.top = ptCenter.y - nRadius; rcPie.bottom = ptCenter.y + nRadius; // Draw series label. CSize sizPieLabel(dc.GetTextExtent(pSeries->GetLabel())); VERIFY(dc.TextOut(ptCenter.x - (sizPieLabel.cx / 2), ptCenter.y + nRadius + GAP_PIXELS, pSeries->GetLabel())); // How much do the wedges total to? double dPieTotal(pSeries->GetDataTotal()); // Draw each wedge in this pie. CPoint ptStart(rcPie.left, ptCenter.y); double dRunningWedgeTotal(0.0); for (int nGroup = 0; nGroup < m_saLegendLabels.GetSize(); ++nGroup) { // Ignore empty wedges. if (0 < pSeries->GetData(nGroup)) { // Get the degrees of this wedge. dRunningWedgeTotal += pSeries->GetData(nGroup); double dPercent(dRunningWedgeTotal * 100.0 / dPieTotal); double degrees(360.0 * dPercent / 100.0); // Find the location of the wedge's endpoint. CPoint ptEnd(WedgeEndFromDegrees(degrees, ptCenter, nRadius)); // Special case: a wedge that takes up the whole pie would // otherwise be confused with an empty wedge. bool drawEmptyWedges = false; if (1 == pSeries->GetNonZeroElementCount()) { _ASSERTE(360 == (int)degrees && ptStart == ptEnd && "This is the problem we're correcting"); --ptEnd.y; drawEmptyWedges = true; } // If the wedge is zero size or very narrow, don't paint it. // If pie is small, and wedge data is small, we might get a wedges // where center and both endpoints lie on the same coordinate, // and endpoints differ only in one pixel. GDI draws such pie as whole pie, // so we just skip them instead. int distance = abs(ptStart.x-ptEnd.x) + abs(ptStart.y-ptEnd.y); if (drawEmptyWedges || distance > 1) { // Draw wedge. COLORREF crWedge(m_dwaColors.GetAt(nGroup)); CBrush br(crWedge); CBrush* pBrushOld = dc.SelectObject(&br); ASSERT_VALID(pBrushOld); VERIFY(dc.Pie(rcPie, ptStart, ptEnd)); // Create a region from the path we create. VERIFY(dc.BeginPath()); VERIFY(dc.Pie(rcPie, ptStart, ptEnd)); VERIFY(dc.EndPath()); CRgn * prgnWedge = new CRgn; VERIFY(prgnWedge->CreateFromPath(&dc)); pSeries->SetTipRegion(nGroup, prgnWedge); // Cleanup. dc.SelectObject(pBrushOld); br.DeleteObject(); ptStart = ptEnd; } } } ++nPie; } } // Draw X axis title CSize sizXLabel(dc.GetTextExtent(m_sXAxisLabel)); VERIFY(dc.TextOut(xOrigin + (nSeriesSpace * nPie - sizXLabel.cx)/2, m_ptOrigin.y - m_nYAxisHeight/2 + nRadius + GAP_PIXELS*2 + sizXLabel.cy, m_sXAxisLabel)); VERIFY(dc.SelectObject(pFontOld)); fontLabels.DeleteObject(); }
void CSettingPropSheetFrame::OnSetFocus(CWnd* /*pOldWnd*/) { // Forward focus to the embedded property sheet ASSERT_VALID(m_pModelessSettingPropSheet); m_pModelessSettingPropSheet->SetFocus(); }
void MyGraph::DrawGraph(CDC& dc) { VALIDATE; ASSERT_VALID(&dc); if (GetMaxSeriesSize()) { dc.SetBkMode(TRANSPARENT); // Populate the colors as a group of evenly spaced colors of maximum // saturation. int nColorsDelta(240 / GetMaxSeriesSize()); int baseColorL = 120; int diffColorL = 60; DWORD backgroundColor = ::GetSysColor(COLOR_WINDOW); // If graph is a non-stacked line graph, use darker colors if system window color is light. #if 0 if (m_eGraphType == MyGraph::Line && !m_bStackedGraph) { int backgroundLuma = (GetRValue(backgroundColor) + GetGValue(backgroundColor) + GetBValue(backgroundColor)) / 3; if (backgroundLuma > 128) { baseColorL = 70; diffColorL = 50; } } #endif for (WORD nGroup = 0; nGroup < GetMaxSeriesSize(); ++nGroup) { WORD colorH = (WORD)(nColorsDelta * nGroup); WORD colorL = (WORD)(baseColorL+(diffColorL*(nGroup%2))); WORD colorS = (WORD)(180)+(30*((1-nGroup%2)*(nGroup%3))); COLORREF cr(MyGraph::HLStoRGB(colorH, colorL, colorS)); // Populate colors cleverly m_dwaColors.SetAtGrow(nGroup, cr); } // Reduce the graphable area by the frame window and status bar. We will // leave GAP_PIXELS pixels blank on all sides of the graph. So top-left // side of graph is at GAP_PIXELS,GAP_PIXELS and the bottom-right side // of graph is at (m_rcGraph.Height() - GAP_PIXELS), (m_rcGraph.Width() - // GAP_PIXELS). These settings are altered by axis labels and legends. CRect rcWnd; GetClientRect(&rcWnd); m_rcGraph.left = GAP_PIXELS; m_rcGraph.top = GAP_PIXELS; m_rcGraph.right = rcWnd.Width() - GAP_PIXELS; m_rcGraph.bottom = rcWnd.Height() - GAP_PIXELS; CBrush br; VERIFY(br.CreateSolidBrush(backgroundColor)); dc.FillRect(rcWnd, &br); br.DeleteObject(); // Draw graph title. DrawTitle(dc); // Set the axes and origin values. SetupAxes(dc); // Draw legend if there is one and there's enough space. if (m_saLegendLabels.GetSize() && m_rcGraph.right-m_rcGraph.left > LEGEND_VISIBILITY_THRESHOLD) { DrawLegend(dc); } else{ m_rcLegend.SetRectEmpty(); } // Draw axes unless it's a pie. if (m_eGraphType != MyGraph::PieChart) { DrawAxes(dc); } // Draw series data and labels. switch (m_eGraphType) { case MyGraph::Bar: DrawSeriesBar(dc); break; case MyGraph::Line: if (m_bStackedGraph) DrawSeriesLineStacked(dc); else DrawSeriesLine(dc); break; case MyGraph::PieChart: DrawSeriesPie(dc); break; default: _ASSERTE(! "Bad default case"); break; } } }
CUniformResourceLocator& CUniformResourceLocator::operator = ( const CUniversalNamingConvention& source ) { ASSERT_VALID( this ); Copy( source ); return( *this ); }
void MyGraph::DrawAxes(CDC& dc) const { VALIDATE; ASSERT_VALID(&dc); _ASSERTE(MyGraph::PieChart != m_eGraphType); dc.SetTextColor(::GetSysColor(COLOR_WINDOWTEXT)); // Draw y axis. dc.MoveTo(m_ptOrigin); VERIFY(dc.LineTo(m_ptOrigin.x, m_ptOrigin.y - m_nYAxisHeight)); // Draw x axis. dc.MoveTo(m_ptOrigin); if (m_saLegendLabels.GetSize()) { VERIFY(dc.LineTo(m_ptOrigin.x + (m_nXAxisWidth - m_rcLegend.Width() - (GAP_PIXELS * 2)), m_ptOrigin.y)); } else { VERIFY(dc.LineTo(m_ptOrigin.x + m_nXAxisWidth, m_ptOrigin.y)); } // Note: m_nAxisLabelHeight and m_nAxisTickLabelHeight have been calculated in SetupAxis() // Create the x-axis label font. CFont fontXAxis; VERIFY(fontXAxis.CreatePointFont(m_nAxisLabelHeight, _T("Arial"), &dc)); // Obtain the height of the font in device coordinates. LOGFONT pLF; VERIFY(fontXAxis.GetLogFont(&pLF)); int fontHeightDC = pLF.lfHeight; // Create the y-axis label font. CFont fontYAxis; VERIFY(fontYAxis.CreateFont( /* nHeight */ fontHeightDC, /* nWidth */ 0, /* nEscapement */ 90 * 10, /* nOrientation */ 0, /* nWeight */ FW_DONTCARE, /* bItalic */ false, /* bUnderline */ false, /* cStrikeOut */ 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, VARIABLE_PITCH | FF_DONTCARE, _T("Arial")) ); // Set the y-axis label font and draw the label. CFont* pFontOld = dc.SelectObject(&fontYAxis); ASSERT_VALID(pFontOld); CSize sizYLabel(dc.GetTextExtent(m_sYAxisLabel)); VERIFY(dc.TextOut(GAP_PIXELS, (m_rcGraph.Height() + sizYLabel.cx) / 2, m_sYAxisLabel)); // Set the x-axis label font and draw the label. VERIFY(dc.SelectObject(&fontXAxis)); CSize sizXLabel(dc.GetTextExtent(m_sXAxisLabel)); VERIFY(dc.TextOut(m_ptOrigin.x + (m_nXAxisWidth - sizXLabel.cx) / 2, m_rcGraph.bottom - GAP_PIXELS - sizXLabel.cy, m_sXAxisLabel)); // chose suitable tick step (1, 2, 5, 10, 20, 50, etc.) int nMaxDataValue(GetMaxDataValue()); nMaxDataValue = max(nMaxDataValue, 1); int nTickStep = 1; while (10 * nTickStep * Y_AXIS_TICK_COUNT_TARGET <= nMaxDataValue) nTickStep *= 10; if (5 * nTickStep * Y_AXIS_TICK_COUNT_TARGET <= nMaxDataValue) nTickStep *= 5; if (2 * nTickStep * Y_AXIS_TICK_COUNT_TARGET <= nMaxDataValue) nTickStep *= 2; // We hardwire TITLE_DIVISOR y-axis ticks here for simplicity. int nTickCount(nMaxDataValue / nTickStep); double tickSpace = (double)m_nYAxisHeight * nTickStep / (double)nMaxDataValue; // create tick label font and set it in the device context CFont fontTickLabels; VERIFY(fontTickLabels.CreatePointFont(m_nAxisTickLabelHeight, _T("Arial"), &dc)); VERIFY(dc.SelectObject(&fontTickLabels)); for (int nTick = 0; nTick < nTickCount; ++nTick) { int nTickYLocation = static_cast<int>(m_ptOrigin.y - tickSpace * (nTick + 1) + 0.5); dc.MoveTo(m_ptOrigin.x - TICK_PIXELS, nTickYLocation); VERIFY(dc.LineTo(m_ptOrigin.x + TICK_PIXELS, nTickYLocation)); // Draw tick label. CString sTickLabel; sTickLabel.Format(_T("%d"), nTickStep * (nTick+1)); CSize sizTickLabel(dc.GetTextExtent(sTickLabel)); VERIFY(dc.TextOut(m_ptOrigin.x - GAP_PIXELS - sizTickLabel.cx - TICK_PIXELS, nTickYLocation - sizTickLabel.cy/2, sTickLabel)); } // Draw X axis tick marks. POSITION pos(m_olMyGraphSeries.GetHeadPosition()); int nSeries(0); while (pos) { MyGraphSeries* pSeries = m_olMyGraphSeries.GetNext(pos); ASSERT_VALID(pSeries); // Ignore unpopulated series if bar chart. if (m_eGraphType != MyGraph::Bar || 0 < pSeries->GetNonZeroElementCount()) { // Get the spacing of the series. int nSeriesSpace(0); if (m_saLegendLabels.GetSize()) { nSeriesSpace = (m_nXAxisWidth - m_rcLegend.Width() - (GAP_PIXELS * 2)) / (m_eGraphType == MyGraph::Bar ? GetNonZeroSeriesCount() : (int)m_olMyGraphSeries.GetCount()); } else { nSeriesSpace = m_nXAxisWidth / (m_eGraphType == MyGraph::Bar ? GetNonZeroSeriesCount() : (int)m_olMyGraphSeries.GetCount()); } int nTickXLocation(m_ptOrigin.x + ((nSeries + 1) * nSeriesSpace) - (nSeriesSpace / 2)); dc.MoveTo(nTickXLocation, m_ptOrigin.y - TICK_PIXELS); VERIFY(dc.LineTo(nTickXLocation, m_ptOrigin.y + TICK_PIXELS)); // Draw x-axis tick label. CString sTickLabel(pSeries->GetLabel()); CSize sizTickLabel(dc.GetTextExtent(sTickLabel)); VERIFY(dc.TextOut(nTickXLocation - (sizTickLabel.cx / 2), m_ptOrigin.y + TICK_PIXELS + GAP_PIXELS, sTickLabel)); ++nSeries; } } VERIFY(dc.SelectObject(pFontOld)); fontXAxis.DeleteObject(); fontYAxis.DeleteObject(); fontTickLabels.DeleteObject(); }
CUniformResourceLocator& CUniformResourceLocator::operator = ( LPCTSTR source ) { ASSERT_VALID( this ); Copy( source ); return( *this ); }
//***************************************************************************** void CBCGPRibbonSlider::SetPageSize (int nPageSize) { ASSERT_VALID (this); m_nPageSize = nPageSize; }
int CUniformResourceLocator::Compare( const CUniformResourceLocator& source ) { ASSERT_VALID( this ); return( URL.CompareNoCase( source.URL ) ); }
//***************************************************************************** void CBCGPRibbonSlider::OnAfterChangeRect (CDC* pDC) { ASSERT_VALID (this); CBCGPBaseRibbonElement::OnAfterChangeRect (pDC); m_rectZoomOut.SetRectEmpty (); m_rectZoomIn.SetRectEmpty (); m_rectThumb.SetRectEmpty (); m_rectLabel.SetRectEmpty (); m_rectSlider = m_rect; if (m_rect.IsRectEmpty ()) { return; } if (IsVert () && !m_strText.IsEmpty ()) { m_rectLabel = m_rectSlider; m_rectSlider.bottom -= globalData.GetTextHeight (); m_rectLabel.top = m_rectSlider.bottom; } double dblScale = globalData.GetRibbonImageScale (); if (m_bZoomButtons) { m_rectZoomOut = m_rectSlider; if (IsVert ()) { m_rectZoomOut.bottom = m_rectZoomOut.top + (int)(.5 + cySliderHeight * dblScale); } else { m_rectZoomOut.right = m_rectZoomOut.left + m_rectZoomOut.Height (); } m_rectZoomIn = m_rectSlider; if (IsVert ()) { m_rectZoomIn.top = m_rectZoomIn.bottom - (int)(.5 + cySliderHeight * dblScale); m_rectSlider.top = m_rectZoomOut.bottom; m_rectSlider.bottom = m_rectZoomIn.top; } else { m_rectZoomIn.left = m_rectZoomIn.right - m_rectZoomIn.Height (); m_rectSlider.left = m_rectZoomOut.right; m_rectSlider.right = m_rectZoomIn.left; } } int nThumbSize = IsVert () ? cyThumbHeight : cxThumbWidth; if (dblScale > 1.) { nThumbSize = (int)(.5 + dblScale * nThumbSize); } if (IsVert ()) { m_rectSlider.DeflateRect (0, nThumbSize / 2); } else { m_rectSlider.DeflateRect (nThumbSize / 2, 0); } SetThumbRect (); }
void MyGraph::DrawSeriesBar(CDC& dc) const { VALIDATE; ASSERT_VALID(&dc); // How much space does each series get (includes inter series space)? // We ignore series whose members are all zero. double availableSpace = m_saLegendLabels.GetSize() ? m_nXAxisWidth - m_rcLegend.Width() - (GAP_PIXELS * 2) : m_nXAxisWidth; double seriesSpace = availableSpace / (double)GetNonZeroSeriesCount(); // Determine width of bars. Data points with a value of zero are assumed // to be empty. This is a bad assumption. double barWidth(0.0); // This is the width of the largest series (no inter series space). double maxSeriesPlotSize(0.0); if(!m_bStackedGraph){ int seriessize = GetMaxNonZeroSeriesSize(); barWidth = seriessize ? seriesSpace / seriessize : 0; if (1 < GetNonZeroSeriesCount()) { barWidth *= INTERSERIES_PERCENT_USED; } maxSeriesPlotSize = GetMaxNonZeroSeriesSize() * barWidth; } else{ barWidth = seriesSpace * INTERSERIES_PERCENT_USED; maxSeriesPlotSize = barWidth; } // Iterate the series. POSITION pos(m_olMyGraphSeries.GetHeadPosition()); int nSeries(0); while (pos) { MyGraphSeries* pSeries = m_olMyGraphSeries.GetNext(pos); ASSERT_VALID(pSeries); // Ignore unpopulated series. if (0 < pSeries->GetNonZeroElementCount()) { // Draw each bar; empty bars are not drawn. double runningLeft(m_ptOrigin.x + (nSeries + 1) * seriesSpace - maxSeriesPlotSize); double stackAccumulator(0.0); for (int nGroup = 0; nGroup < GetMaxSeriesSize(); ++nGroup) { if (pSeries->GetData(nGroup)) { int nMaxDataValue(GetMaxDataValue()); nMaxDataValue = max(nMaxDataValue, 1); double barTop = m_ptOrigin.y - (double)m_nYAxisHeight * pSeries->GetData(nGroup) / (double)nMaxDataValue - stackAccumulator; CRect rcBar; rcBar.left = (int)runningLeft; rcBar.top = (int)barTop; // Make adjacent bar borders overlap, so there's only one pixel border line between them. rcBar.right = (int)(runningLeft + barWidth) + 1; rcBar.bottom = (int)((double)m_ptOrigin.y - stackAccumulator) + 1; if(m_bStackedGraph){ stackAccumulator = (double)m_ptOrigin.y - barTop; } pSeries->SetTipRegion(nGroup, rcBar); COLORREF crBar(m_dwaColors.GetAt(nGroup)); CBrush br(crBar); CBrush* pBrushOld = dc.SelectObject(&br); ASSERT_VALID(pBrushOld); VERIFY(dc.Rectangle(rcBar)); dc.SelectObject(pBrushOld); br.DeleteObject(); if(!m_bStackedGraph){ runningLeft += barWidth; } } } ++nSeries; } } if (!m_bStackedGraph) { int nMaxDataValue = max(GetMaxDataValue(), 1); double barTop = m_ptOrigin.y - (double)m_nYAxisHeight * (GetAverageDataValue() / (double)nMaxDataValue); dc.MoveTo(m_ptOrigin.x, barTop); VERIFY(dc.LineTo(m_ptOrigin.x + (m_nXAxisWidth - m_rcLegend.Width() - (GAP_PIXELS * 2)), barTop)); } }
//******************************************************************************** void CBCGPRibbonSlider::OnDrawOnList (CDC* pDC, CString strText, int nTextOffset, CRect rect, BOOL /*bIsSelected*/, BOOL /*bHighlighted*/) { ASSERT_VALID (this); ASSERT_VALID (pDC); const int nSliderWidth = IsVert () ? (cxSliderWidth + 2) : (rect.Height () * 2); BOOL bIsDisabled = m_bIsDisabled; m_bIsDisabled = FALSE; CRect rectText = rect; rectText.left += nTextOffset; rectText.right -= nSliderWidth; const int xMargin = 3; rectText.DeflateRect (xMargin, 0); pDC->DrawText (strText, rectText, DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX); // Draw channel: CRect rectChannel = rect; rectChannel.left = rectChannel.right - nSliderWidth; if (IsVert ()) { rectChannel.left = rectChannel.CenterPoint ().x - 1; rectChannel.right = rectChannel.left + 2; } else { rectChannel.top = rectChannel.CenterPoint ().y - 1; rectChannel.bottom = rectChannel.top + 2; } CBCGPVisualManager::GetInstance ()->OnDrawRibbonSliderChannel ( pDC, this, rectChannel); // Draw thumb: CRect rectThumb = rect; rectThumb.left = rectThumb.right - nSliderWidth; if (IsVert ()) { rectThumb.top = rectThumb.CenterPoint ().y - 2; rectThumb.bottom = rectThumb.CenterPoint ().y + 3; rectThumb.DeflateRect (1, 0); } else { rectThumb.left = rectThumb.CenterPoint ().x - 2; rectThumb.right = rectThumb.CenterPoint ().x + 2; rectThumb.DeflateRect (0, 1); } CBCGPVisualManager::GetInstance ()->OnDrawRibbonSliderThumb ( pDC, this, rectThumb, FALSE, FALSE, FALSE); m_bIsDisabled = bIsDisabled; }
void MyGraph::DrawSeriesLine(CDC& dc) const { VALIDATE; ASSERT_VALID(&dc); _ASSERTE(!m_bStackedGraph); // Iterate the groups. CPoint ptLastLoc(0,0); int dataLastLoc(0); for (int nGroup = 0; nGroup < GetMaxSeriesSize(); nGroup++) { // How much space does each series get (includes inter series space)? int nSeriesSpace(0); if (m_saLegendLabels.GetSize()) { nSeriesSpace = (m_nXAxisWidth - m_rcLegend.Width() - (GAP_PIXELS * 2)) / (int)m_olMyGraphSeries.GetCount(); } else { nSeriesSpace = m_nXAxisWidth / (int)m_olMyGraphSeries.GetCount(); } // Determine width of bars. int nMaxSeriesSize(GetMaxSeriesSize()); nMaxSeriesSize = max(nMaxSeriesSize, 1); int nBarWidth(nSeriesSpace / nMaxSeriesSize); if (1 < m_olMyGraphSeries.GetCount()) { nBarWidth = (int) ((double) nBarWidth * INTERSERIES_PERCENT_USED); } // This is the width of the largest series (no inter series space). //int nMaxSeriesPlotSize(GetMaxSeriesSize() * nBarWidth); // Iterate the series. POSITION pos(m_olMyGraphSeries.GetHeadPosition()); // Build objects. COLORREF crLine(m_dwaColors.GetAt(nGroup)); CBrush br(crLine); CBrush* pBrushOld = dc.SelectObject(&br); ASSERT_VALID(pBrushOld); CPen penLine(PS_SOLID, 1, crLine); CPen* pPenOld = dc.SelectObject(&penLine); ASSERT_VALID(pPenOld); for (int nSeries = 0; nSeries < m_olMyGraphSeries.GetCount(); ++nSeries) { MyGraphSeries* pSeries = m_olMyGraphSeries.GetNext(pos); ASSERT_VALID(pSeries); // Get x and y location of center of ellipse. CPoint ptLoc(0,0); ptLoc.x = m_ptOrigin.x + (((nSeries + 1) * nSeriesSpace) - (nSeriesSpace / 2)); int nMaxDataValue(GetMaxDataValue()); nMaxDataValue = max(nMaxDataValue, 1); double dLineHeight(pSeries->GetData(nGroup) * m_nYAxisHeight / double(nMaxDataValue)); ptLoc.y = (int) ((double) m_ptOrigin.y - dLineHeight); // Draw line back to last data member. if (nSeries > 0 && (pSeries->GetData(nGroup)!=0 || dataLastLoc != 0)) { dc.MoveTo(ptLastLoc.x, ptLastLoc.y - 1); VERIFY(dc.LineTo(ptLoc.x - 1, ptLoc.y - 1)); } // Now draw ellipse. CRect rcEllipse(ptLoc.x - 3, ptLoc.y - 3, ptLoc.x + 3, ptLoc.y + 3); if(pSeries->GetData(nGroup)!=0){ VERIFY(dc.Ellipse(rcEllipse)); } if (m_olMyGraphSeries.GetCount() < 40) { pSeries->SetTipRegion(nGroup, rcEllipse); } // Save last pt and data ptLastLoc = ptLoc; dataLastLoc = pSeries->GetData(nGroup); } VERIFY(dc.SelectObject(pPenOld)); penLine.DeleteObject(); VERIFY(dc.SelectObject(pBrushOld)); br.DeleteObject(); } int nMaxDataValue = max(GetMaxDataValue(), 1); double barTop = m_ptOrigin.y - (double)m_nYAxisHeight * (GetAverageDataValue() / (double)nMaxDataValue); dc.MoveTo(m_ptOrigin.x, barTop); VERIFY(dc.LineTo(m_ptOrigin.x + (m_nXAxisWidth - m_rcLegend.Width() - (GAP_PIXELS * 2)), barTop)); }
BOOL CToolBoxCtrl::OnDrawTool(CDC* pDC, CToolElement* pTool) const { ASSERT_VALID(this); ASSERT_VALID(pDC); ASSERT_VALID(pTool); if (!pTool->m_Rect.IsRectEmpty()) { if (pTool->m_Rect.top >= m_rectList.bottom) { return FALSE; } CRect rectName = pTool->m_Rect; BOOL bFlag=FALSE; if(pTool->IsSelected()) { bFlag=TRUE; CBrush bsh(m_clrSelected); CBrush* oldBsh=pDC->SelectObject(&bsh); CPen pen(PS_SOLID,1,m_clrSelectedBorder); CPen* oldPen=pDC->SelectObject(&pen); pDC->Rectangle(&rectName); pDC->SelectObject(oldBsh); pDC->SelectObject(oldPen); } if(!bFlag&&pTool->IsHovered()) { bFlag=TRUE; CBrush bsh(m_clrHover); CBrush* oldBsh=pDC->SelectObject(&bsh); CPen pen(PS_SOLID,1,m_clrSelectedBorder); CPen* oldPen=pDC->SelectObject(&pen); pDC->Rectangle(&rectName); pDC->SelectObject(oldBsh); pDC->SelectObject(oldPen); } int nHeight=m_nToolHeight; if (pTool->IsToolTab()) { CRect rectExpand = rectName; nHeight=m_nTabHeight; rectExpand.right = nHeight; if(!bFlag) { CRect rectFill=rectName; rectFill.DeflateRect(1,1); CBrush bsh(m_clrToolTab); pDC->FillRect(rectName, &bsh); } CRgn rgnClipExpand; CRect rectExpandClip = rectExpand; rectExpandClip.bottom = min(rectExpandClip.bottom, m_rectList.bottom); rgnClipExpand.CreateRectRgnIndirect(&rectExpandClip); pDC->SelectClipRgn(&rgnClipExpand); pTool->OnDrawExpandBox(pDC, rectExpand); } COLORREF clrTextOld = (COLORREF)-1; if (!pTool->IsEnabled()) { clrTextOld = pDC->SetTextColor(afxGlobalData.clrGrayedText); } CRect rectIcon = pTool->m_Rect; rectIcon.right = rectIcon.left + nHeight; CRgn rgnClipIcon; CRect rectIconClip = rectIcon; rectIconClip.bottom = min(rectIconClip.bottom, m_rectList.bottom); rgnClipIcon.CreateRectRgnIndirect(&rectIconClip); pDC->SelectClipRgn(&rgnClipIcon); pTool->OnDrawIcon(pDC, rectIcon); CRgn rgnClipName; rectName.left += rectIcon.right; CRect rectNameClip = rectName; rectNameClip.bottom = min(rectNameClip.bottom, m_rectList.bottom); rgnClipName.CreateRectRgnIndirect(&rectNameClip); pDC->SelectClipRgn(&rgnClipName); HFONT hOldFont = NULL; if (pTool->IsToolTab()) { hOldFont = (HFONT) ::SelectObject(pDC->GetSafeHdc(), m_fontToolTab.GetSafeHandle()); } pTool->OnDrawName(pDC, rectName); if (hOldFont != NULL) { ::SelectObject(pDC->GetSafeHdc(), hOldFont); } pDC->SelectClipRgn(NULL); if (clrTextOld != (COLORREF)-1) { pDC->SetTextColor(clrTextOld); } } if (pTool->IsExpanded()) { for (POSITION pos = pTool->m_lstSubTools.GetHeadPosition(); pos != NULL;) { if (!OnDrawTool(pDC, pTool->m_lstSubTools.GetNext(pos))) { return FALSE; } } } return TRUE; }
void MyGraph::DrawSeriesLineStacked(CDC& dc) const { VALIDATE; ASSERT_VALID(&dc); _ASSERTE(m_bStackedGraph); int nSeriesCount = (int)m_olMyGraphSeries.GetCount(); CArray<int> stackAccumulator; stackAccumulator.SetSize(nSeriesCount); CArray<CPoint> polygon; // Special case: if we only have single series, make polygon // a bar instead of one pixel line. polygon.SetSize(nSeriesCount==1 ? 4 : nSeriesCount * 2); // How much space does each series get? int nSeriesSpace(0); if (m_saLegendLabels.GetSize()) { nSeriesSpace = (m_nXAxisWidth - m_rcLegend.Width() - (GAP_PIXELS * 2)) / nSeriesCount; } else { nSeriesSpace = m_nXAxisWidth / nSeriesCount; } int nMaxDataValue(GetMaxDataValue()); nMaxDataValue = max(nMaxDataValue, 1); double dYScaling = double(m_nYAxisHeight) / nMaxDataValue; // Iterate the groups. for (int nGroup = 0; nGroup < GetMaxSeriesSize(); nGroup++) { // Build objects. COLORREF crGroup(m_dwaColors.GetAt(nGroup)); CBrush br(crGroup); CBrush* pBrushOld = dc.SelectObject(&br); ASSERT_VALID(pBrushOld); // For polygon outline, use average of this and previous color, and darken it. COLORREF crPrevGroup(nGroup > 0 ? m_dwaColors.GetAt(nGroup-1) : crGroup); COLORREF crOutline = RGB( (GetRValue(crGroup)+GetRValue(crPrevGroup))/3, (GetGValue(crGroup)+GetGValue(crPrevGroup))/3, (GetBValue(crGroup)+GetBValue(crPrevGroup))/3); CPen penLine(PS_SOLID, 1, crOutline); CPen* pPenOld = dc.SelectObject(&penLine); ASSERT_VALID(pPenOld); // Construct bottom part of polygon from current stack accumulator for (int nPolyBottom = 0; nPolyBottom < nSeriesCount; ++nPolyBottom) { CPoint ptLoc; ptLoc.x = m_ptOrigin.x + (((nPolyBottom + 1) * nSeriesSpace) - (nSeriesSpace / 2)); double dLineHeight((stackAccumulator[nPolyBottom]) * dYScaling); ptLoc.y = (int) ((double) m_ptOrigin.y - dLineHeight); if (nSeriesCount > 1) { polygon[nSeriesCount-nPolyBottom-1] = ptLoc; } else { // special case: when there's one series, make polygon a bar polygon[0] = CPoint(ptLoc.x-GAP_PIXELS/2, ptLoc.y); polygon[1] = CPoint(ptLoc.x+GAP_PIXELS/2, ptLoc.y); } } // Iterate the series, construct upper part of polygon and upadte stack accumulator POSITION pos(m_olMyGraphSeries.GetHeadPosition()); for (int nSeries = 0; nSeries < nSeriesCount; ++nSeries) { MyGraphSeries* pSeries = m_olMyGraphSeries.GetNext(pos); ASSERT_VALID(pSeries); CPoint ptLoc; ptLoc.x = m_ptOrigin.x + (((nSeries + 1) * nSeriesSpace) - (nSeriesSpace / 2)); double dLineHeight((pSeries->GetData(nGroup) + stackAccumulator[nSeries]) * dYScaling); ptLoc.y = (int) ((double) m_ptOrigin.y - dLineHeight); if (nSeriesCount > 1) { polygon[nSeriesCount+nSeries] = ptLoc; } else { // special case: when there's one series, make polygon a bar polygon[2] = CPoint(ptLoc.x+GAP_PIXELS/2, ptLoc.y); polygon[3] = CPoint(ptLoc.x-GAP_PIXELS/2, ptLoc.y); } stackAccumulator[nSeries] += pSeries->GetData(nGroup); } // Draw polygon VERIFY(dc.Polygon(polygon.GetData(), (int)polygon.GetSize())); VERIFY(dc.SelectObject(pPenOld)); penLine.DeleteObject(); VERIFY(dc.SelectObject(pBrushOld)); br.DeleteObject(); } }
void CNPainterView::OnDraw(CDC* pDC) { CNPainterDoc* pdoc = GetDocument(); ASSERT_VALID(pdoc); if (!pdoc) return; CRect client, rect; CDC dc; CDC *pdrawdc = pDC; CBitmap bitmap; CBitmap* poldbmp = nullptr; pDC->GetClipBox(client); rect = client; docToClient(rect); CString str; str.Format(_T("CNPainterView::OnDraw clipRect:<%d,%d,%d,%d %d,%d>"), rect.left, rect.top, rect.right, rect.bottom, rect.Width(), rect.Height()); AfxGetMainWnd()->SetWindowText(str); if(!pDC->IsPrinting()) { if(dc.CreateCompatibleDC(pDC)) { if(bitmap.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height())) { OnPrepareDC(&dc, NULL); pdrawdc = &dc; dc.OffsetViewportOrg(-rect.left, -rect.top); poldbmp = dc.SelectObject(&bitmap); dc.SetBrushOrg(rect.left % 8, rect.top % 8); // might as well clip to the same rectangle //dc.SelectClipRgn(NULL); dc.IntersectClipRect(client); } } } //// 更新背景 //if(!pdrawdc->IsPrinting()) // DoDrawBackground(pdrawdc); //// 背景图片 //pdoc->m_adminObjs.DrawPaperBack(pdrawdc); ////// 画网格 VSP3.1 网格线已经集成到itobjPage::Draw() ////if(!pdrawdc->IsPrinting() && pdoc->m_adminObjs.IsVisibleGrid()) //// DoDrawGrid(pdrawdc); //pdoc->m_adminObjs.DrawObjects(pdrawdc); //// 绘制选中标识 //DoDrawSelectItems(pdrawdc); // pdoc->getAdminer().drawBackground(pdrawdc, m_szWorker); //// 画对象 pdoc->getAdminer().draw(pdrawdc, this); pdoc->draw(pdrawdc); // 刷新客户区 //if(pdrawdc != pDC) //{ // pDC->BitBlt(client.left, client.top, client.Width(), client.Height(), pdrawdc, client.left, client.top, SRCCOPY); // if(poldbmp) // pdrawdc->SelectObject(poldbmp); //} if (pdrawdc != pDC) { pDC->SetViewportOrg(0, 0); pDC->SetWindowOrg(0,0); pDC->SetMapMode(MM_TEXT); dc.SetViewportOrg(0, 0); dc.SetWindowOrg(0,0); dc.SetMapMode(MM_TEXT); pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(), &dc, 0, 0, SRCCOPY); dc.SelectObject(poldbmp); } }
//******************************************************************************************** void CBCGMenuPage::OnSelchangeMenuList() { UpdateData (); if (m_pMenuBar == NULL) { ASSERT (FALSE); return; } if (m_hmenuSelected != NULL) { m_pMenuBar->OnChangeHot (-1); g_menuHash.SaveMenuBar (m_hmenuSelected, m_pMenuBar); } int iIndex = m_wndMenuesList.GetCurSel (); if (iIndex == CB_ERR) { m_strMenuDescr = _T(""); m_wndIcon.SetIcon (NULL); UpdateData (FALSE); m_hmenuSelected = NULL; return; } HICON hicon = NULL; HMENU hmenu = NULL; CBCGMultiDocTemplate* pTemplate = (CBCGMultiDocTemplate*) m_wndMenuesList.GetItemData (iIndex); if (pTemplate != NULL) { ASSERT_VALID (pTemplate); pTemplate->GetDocString (m_strMenuDescr, CDocTemplate::regFileTypeName); hicon = AfxGetApp ()->LoadIcon (pTemplate->GetResId ()); if (hicon == NULL) { hicon = ::LoadIcon(NULL, IDI_APPLICATION); } hmenu = pTemplate->m_hMenuShared; } else { { CBCGLocalResource locaRes; m_strMenuDescr.LoadString (IDS_BCGBARRES_DEFAULT_MENU_DESCR); } CWnd* pWndMain = AfxGetMainWnd (); if (pWndMain != NULL) { hicon = (HICON) (LONG_PTR) GetClassLongPtr (*pWndMain, GCLP_HICON); } hmenu = m_pMenuBar->GetDefaultMenu (); } ASSERT (hmenu != NULL); m_pMenuBar->CreateFromMenu (hmenu); m_wndIcon.SetIcon (hicon); m_hmenuSelected = hmenu; UpdateData (FALSE); }