CProgressBar Class Reference

Progres bar display window for "busy" operations. More...

#include <progbar.h>

List of all members.

Public Member Functions

 CProgressBar ()
virtual ~CProgressBar ()
 Destroys the object, as one might expect. Notes: IMPORTANT - After calling the destructor (delete ProgressBar) it is VITAL that you then call RecalcLayout() for the main frame window in which the Progress Bar is appearing (the one you passed in to PB::Create(). If you don't do this, the bar won't disappear until the next time the main window is resized or a tool is chosen.
BOOL Create (CFrameWnd *pParentWnd, String_64 *JobDescrip=NULL, DWORD dwStyle=CBRS_BOTTOM, UINT32 nID=_R(AFX_IDW_STATUS_BAR))
 Creates a window and associates it with this CProgressBar object. The window appears immediately over the status bar. Notes: This currently assumes that it'll only ever be opened at the bottom of the Main Frame window.
void OnUpdateCmdUI (CFrameWnd *pTarget, BOOL bDisableIfNoHndler)
INT32 GetPercent (void) const
 Reads the currently displayed percentage of the progress bar.
BOOL SetPercent (INT32 Percent, BOOL RedrawBackground=FALSE, String_64 *JobDescrip=NULL)
 Sets the currently displayed percentage of the progress bar. The bar will be immediately redrawn to reflect the new value. Values outside the range 0..99 (inclusive) are clipped to 0 or 99. No redraw will be done if NewPercent equals the currently displayed value.

Protected Member Functions

virtual void DoPaint (CDC *pDC)
afx_msg void OnSize (UINT32, INT32, INT32)
afx_msg LRESULT OnSizeParent (WPARAM, LPARAM lParam)
afx_msg LRESULT OnSetFont (WPARAM wParam, LPARAM lParam)
afx_msg LRESULT OnGetFont (WPARAM wParam, LPARAM lParam)

Protected Attributes

INT32 CurrentPercent
String_64JobDescription
HFONT m_hFont
INT32 m_FontDescent
BOOL FontIsSystemFont


Detailed Description

Progres bar display window for "busy" operations.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/02/93 (-ish)

Definition at line 121 of file progbar.h.


Constructor & Destructor Documentation

CProgressBar::CProgressBar  ) 
 

Definition at line 206 of file progbar.cpp.

00207 {
00208     m_hFont = FontFactory::GetFont(STOCKFONT_STATUSBAR);
00209     CurrentPercent = -1;
00210 }

CProgressBar::~CProgressBar  )  [virtual]
 

Destroys the object, as one might expect. Notes: IMPORTANT - After calling the destructor (delete ProgressBar) it is VITAL that you then call RecalcLayout() for the main frame window in which the Progress Bar is appearing (the one you passed in to PB::Create(). If you don't do this, the bar won't disappear until the next time the main window is resized or a tool is chosen.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/02/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Definition at line 230 of file progbar.cpp.

00231 {
00232     if (JobDescription != NULL)
00233         delete JobDescription;
00234 
00235 //  ParentWindow->RecalcLayout();               // Cause ourself to be hidden
00236         // The above does not work, as it appears to be called before the window
00237         // has actually been deleted, and therefore has no effect. Thus, the 
00238         // responsibility for doing this is passed on to the entity calling 'delete'
00239 }


Member Function Documentation

BOOL CProgressBar::Create CFrameWnd *  pParentWnd,
String_64 JobDescrip = NULL,
DWORD  dwStyle = CBRS_BOTTOM,
UINT32  nID = _R(AFX_IDW_STATUS_BAR)
 

Creates a window and associates it with this CProgressBar object. The window appears immediately over the status bar. Notes: This currently assumes that it'll only ever be opened at the bottom of the Main Frame window.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/02/94
Parameters:
ParentWnd - The parent frame window (in Camelot, there can be only one) [INPUTS] JobDescription - A BRIEF string describing the job currently being undertaken. This will be displayed on the progress bar if possible dwstyle, nID - you shouldn't have to mess with these (cf CStatusBar)
- [OUTPUTS]
Returns:
TRUE if the initialisation of the progress bar was successful.
See also:
CProgressBar::SetPercent; CProgressBar::GetPercent

Definition at line 262 of file progbar.cpp.

00264 {
00265     ASSERT_VALID(pParentWnd);   // must have a parent
00266 
00267     CurrentPercent = -1;
00268     if (JobDescrip == NULL)
00269         JobDescription = NULL;
00270     else
00271         JobDescription = new String_64(*JobDescrip);
00272 #if WIN32
00273     // this element of CControlBar does not exist in MFC 2.5 16-bit
00274     m_dwStyle = dwStyle;
00275 #endif
00276 
00277 #if _MFC_VER == 0x400
00278     // MFC 4 defers registering of window classes, so make sure the window class
00279     // is registered before we use it.
00280     // (code taken from mfc/src/bardock.cpp, in MFC 4)
00281     if (!AfxDeferRegisterClass(AFX_WNDCONTROLBAR_REG))
00282         return FALSE;
00283 #endif
00284 
00285 
00286     // Work out the position of the bar.
00287     CRect rect;
00288     rect.SetRectEmpty();
00289 
00290     // create the window
00291     if (!CWnd::Create(_afxWndControlBar, NULL, dwStyle, rect, pParentWnd, nID))
00292         return FALSE;
00293         // NOTE: Parent must resize itself for control bar to be resized
00294 
00295     // set initial font and calculate bar height
00296     OnSetFont((WPARAM)m_hFont, 0);              // initialize font height etc
00297 
00298 
00299     pParentWnd->RecalcLayout();                 // Cause ourself to be shown
00300     SetPercent(0, TRUE);        // Force redraw of window _including background_
00301 
00302     return TRUE;
00303 }

void CProgressBar::DoPaint CDC pDC  )  [protected, virtual]
 

Definition at line 447 of file progbar.cpp.

00453 {
00454     ASSERT_VALID(this);
00455     ASSERT_VALID(pDC);
00456 
00457     CControlBar::DoPaint(pDC);      // draw border
00458 
00459     CRect rect;
00460     GetClientRect(rect);
00461     CalcInsideRect(rect);
00462 
00463     ASSERT(m_hFont != NULL);
00464     CFont *OurFont = CHECKFONT(CFont::FromHandle(m_hFont));     // Get a CFont* for this HFONT
00465     CFont *OldFont = CHECKFONT(pDC->SelectObject(OurFont));
00466 
00467     rect.InflateRect(-CX_BORDER, -CY_BORDER);
00468 
00469     CString PercentText("00%");                         // Generate %age string
00470     if (CurrentPercent > 0 && CurrentPercent < 100)
00471     {
00472         if (CurrentPercent > 9)
00473             PercentText.SetAt(0, (CurrentPercent / 10) + '0');
00474         PercentText.SetAt(1, (CurrentPercent % 10) + '0');
00475     }
00476 
00477     pDC->SetTextColor(GetSysColor(COLOR_BTNTEXT));      // Draw %age string
00478     pDC->SetBkColor(GetSysColor(COLOR_BTNFACE));
00479     pDC->SetBkMode(OPAQUE);
00480     SetTextAlign(pDC->m_hDC, TA_LEFT | TA_BOTTOM);
00481     pDC->TextOut(rect.left, rect.bottom, PercentText);
00482 
00483     CSize TextSize = pDC->GetTextExtent(PercentText, 3);
00484 
00485     INT32 BarStart = rect.left + TextSize.cx + 4;           // Calc bar position, size
00486     INT32 WindowEnd = rect.right - 4;
00487     INT32 BarWidth = WindowEnd - BarStart;
00488     
00489     if (BarWidth < 10) return;      // Not enough room to do a bar!
00490 
00491     if (BarWidth > MAXBARWIDTH) BarWidth = MAXBARWIDTH;
00492 
00493     if (JobDescription != NULL && WindowEnd - BarStart > MAXBARWIDTH + 64)
00494     {   // If enough room for some text, add the job description
00495         CString OutText = TEXT(*JobDescription);
00496 
00497         rect.left = BarStart + BarWidth + 4;
00498         rect.right = WindowEnd;
00499         pDC->TextOut(rect.left, rect.bottom, OutText);
00500     }
00501 
00502     CHECKFONT(pDC->SelectObject(OldFont));  // Restore previous font 
00503 
00504     rect.left = BarStart;               // Finally, calc and paint the bar,,,
00505     rect.right = BarStart+BarWidth;
00506     rect.bottom -= m_FontDescent - 2;   // Line up bar bottom with text baseline
00507     Paint3dPlinth(pDC, &rect, FALSE);
00508     
00509     BarWidth -= 4;                      // Bar is 2 pixels inside plinth rectangle
00510     rect.left = BarStart + 2;
00511     rect.top += 2;
00512     rect.bottom -= 2;
00513     rect.right = rect.left + (INT32) (((WORD)BarWidth * (WORD)CurrentPercent) / 100);
00514 
00515     CBrush BlueBrush(RGB(0,0,255));
00516     pDC->FillRect(rect, &BlueBrush);
00517 }

INT32 CProgressBar::GetPercent void   )  const
 

Reads the currently displayed percentage of the progress bar.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/02/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
The current percentage setting displayed in the progressbar window.
See also:
CProgressBar::SetPercent; CProgressBar::Create

Definition at line 340 of file progbar.cpp.

00341 {
00342     return(CurrentPercent);
00343 }

LRESULT CProgressBar::OnGetFont WPARAM  wParam,
LPARAM  lParam
[protected]
 

Definition at line 665 of file progbar.cpp.

00666 {
00667     return (LRESULT)(UINT32)m_hFont;
00668 }

LRESULT CProgressBar::OnSetFont WPARAM  wParam,
LPARAM  lParam
[protected]
 

Definition at line 627 of file progbar.cpp.

00629 {
00630     m_hFont = (HFONT)wParam;
00631 
00632     ASSERT(m_hFont != NULL);
00633 
00634     // recalculate based on font height + borders
00635     TEXTMETRIC tm;
00636     // get text metrics of font
00637     {
00638         CClientDC dcScreen(NULL);
00639 
00640         CFont *OurFont = CHECKFONT(CFont::FromHandle(m_hFont));
00641         CFont *OldFont = CHECKFONT(dcScreen.SelectObject(OurFont));
00642 
00643         VERIFY(dcScreen.GetTextMetrics(&tm));
00644         CHECKFONT(dcScreen.SelectObject(OldFont));
00645     }
00646     CRect rectSize;
00647     rectSize.SetRectEmpty();
00648     CalcInsideRect(rectSize);       // will be negative size
00649 
00650 #if _MFC_VER < 0x300
00651     m_sizeFixedLayout.cy = (tm.tmHeight - tm.tmInternalLeading) + 
00652             CY_BORDER*3 /* 1 extra on top, 2 on bottom */ - rectSize.Height();
00653     ASSERT(m_sizeFixedLayout.cx == 32767);  // max size
00654 #else
00655     BarHeight = (tm.tmHeight - tm.tmInternalLeading) + 
00656             CY_BORDER*3 /* 1 extra on top, 2 on bottom */ - rectSize.Height();
00657 #endif
00658 
00659     m_FontDescent = tm.tmDescent;   // Cache descent size
00660 
00661     return 0L;      // does not re-draw or invalidate - resize parent instead
00662 }

void CProgressBar::OnSize UINT32  ,
INT32  ,
INT32 
[protected]
 

Definition at line 532 of file progbar.cpp.

00533 {
00534     // force repaint on resize
00535     Invalidate();
00536 }

LRESULT CProgressBar::OnSizeParent WPARAM  ,
LPARAM  lParam
[protected]
 

Definition at line 539 of file progbar.cpp.

00552 {
00553     AFX_SIZEPARENTPARAMS FAR* lpLayout = (AFX_SIZEPARENTPARAMS FAR*)lParam;
00554     CRect StatusRect;
00555 
00556     ((CMainFrame *) AfxGetApp()->m_pMainWnd)->GetStatusBarWindowRect(&StatusRect);
00557 
00558     if (!StatusRect.IsRectEmpty())                  // Cover status bar (if open)
00559     {
00560         // JustinF says: this is a quick bodge so that the progress-bar respects any
00561         // overriding prefix displayed in the status line by StatusLine::SetPrefix.
00562         StatusRect.left = StatusLine::GetPrefixWidth();
00563 
00564         // We just move our window so it is covering the status bar, using the
00565         // HWDP supplied in the AFX_SIZEPARENTPARAMS structure.
00566         lpLayout->hDWP = ::DeferWindowPos(lpLayout->hDWP, m_hWnd, HWND_TOP,
00567                                           StatusRect.left, StatusRect.top,  
00568                                           StatusRect.right - StatusRect.left,
00569                                           StatusRect.bottom - StatusRect.top,
00570                                           SWP_NOACTIVATE);
00571     }
00572     else
00573     {
00574 
00575     #if _MFC_VER < 0x300
00576         // No status bar - just plonk the progress bar where we can...
00577         return (CControlBar::OnSizeParent((WPARAM)0, lParam));
00578     #else
00579         // resize and reposition this control bar based on styles
00580         DWORD dwStyle = (m_dwStyle & (CBRS_ALIGN_ANY|CBRS_BORDER_ANY)) |
00581             (GetStyle() & WS_VISIBLE);
00582 
00583         if ((dwStyle & WS_VISIBLE) && (dwStyle & CBRS_ALIGN_ANY) != 0)
00584         {
00585             // align the control bar
00586             CRect rect;
00587 
00588             if (StatusRect.IsRectEmpty())
00589             {
00590                 // Status bar is not open - just fit in where we can.
00591                 // (This code copied from barcore.cpp in MFC 3)
00592                 rect.CopyRect(&lpLayout->rect);
00593 
00594                 CSize sizeAvail = rect.Size();  // maximum size available
00595 
00596                 // get maximum requested size
00597                 CSize size = CalcFixedLayout(lpLayout->bStretch, 
00598                     (dwStyle & CBRS_ORIENT_HORZ) ? TRUE : FALSE);
00599 
00600                 size.cx = min(size.cx, sizeAvail.cx);
00601                 size.cy = BarHeight;
00602 
00603                 lpLayout->sizeTotal.cy += size.cy;
00604                 lpLayout->sizeTotal.cx = max(lpLayout->sizeTotal.cx, size.cx);
00605                 rect.top = rect.bottom - size.cy;
00606                 lpLayout->rect.bottom -= size.cy;
00607 
00608                 rect.right = rect.left + size.cx;
00609                 rect.bottom = rect.top + size.cy;
00610 
00611                 // only resize the window if doing layout and not just rect query
00612                 if (lpLayout->hDWP != NULL)
00613                 {
00614                     AfxRepositionWindow(lpLayout, m_hWnd, &rect);
00615                 }
00616             }
00617         }
00618     #endif
00619     }
00620 
00621     return 0;
00622 
00623 }

void CProgressBar::OnUpdateCmdUI CFrameWnd *  pTarget,
BOOL  bDisableIfNoHndler
 

Definition at line 307 of file progbar.cpp.

00310 {
00311     CCmdUI state;
00312     state.m_pOther = this;
00313     state.m_nIndexMax = (UINT32)m_nCount;
00314 
00315     for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
00316       state.m_nIndex++)
00317     {
00318         state.m_nID = 0;
00319         state.DoUpdate(pTarget, bDisableIfNoHndler);
00320     }
00321 
00322     // update the dialog controls added to the status bar (of which there are none)
00323     UpdateDialogControls(pTarget, bDisableIfNoHndler);
00324 }

BOOL CProgressBar::SetPercent INT32  NewPercent,
BOOL  ClearBackground = FALSE,
String_64 JobDescrip = NULL
 

Sets the currently displayed percentage of the progress bar. The bar will be immediately redrawn to reflect the new value. Values outside the range 0..99 (inclusive) are clipped to 0 or 99. No redraw will be done if NewPercent equals the currently displayed value.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/02/94
Parameters:
NewPercent - the new percentage value to be displayed by the progress bar [INPUTS]
ClearBackground - Clears the entire bar background and redraws everything, rather than doing a (far more efficient) update of the bar/percentage alone. Use the default of FALSE unless absolutely necessary!

JobDescrip - NULL, or a pointer to a new job description - pass NULL if this hasn't changed, as it makes a copy of the new string every time it is changed. If this is non-NULL, then the ClearBackground flag will be forced to TRUE to draw the new text.

Parameters:
- [OUTPUTS]
Returns:
TRUE if it successfully makes the change.
See also:
CProgressBar::GetPercent; CProgressBar::Create

Definition at line 371 of file progbar.cpp.

00376 {
00377     if (NewPercent < 0) NewPercent = 0;
00378     if (NewPercent > 99) NewPercent = 99;
00379 
00380     // If there's no change, don't bother updating
00381     if (JobDescrip == NULL && NewPercent == CurrentPercent)
00382         return(TRUE);
00383 
00384     CurrentPercent = NewPercent;
00385 
00386     // If there is a new Job Description, change to use it
00387     if (JobDescrip != NULL)
00388     {
00389         delete JobDescription;
00390         JobDescription = new String_64(*JobDescrip);
00391 
00392         ClearBackground = TRUE;     // Ensure that the new text is drawn
00393     }
00394 
00395 
00396 #if FALSE
00397 /*
00398     CDC *DC = GetDC();
00399 
00400     if (ClearBackground)
00401     {
00402         CRect   Rect;
00403         CBrush  FillBrush(GetSysColor(COLOR_BTNFACE));
00404 
00405         GetClientRect(&Rect);                   // Get window position/area...
00406         DC->FillRect(Rect, &FillBrush);         // [...& fill backgnd with grey]
00407     }
00408 
00409     DoPaint(DC);                                // Force immediate redraw
00410     ReleaseDC(DC);
00411 */
00412 #else
00413     Invalidate(ClearBackground);                // Invalidate the window
00414     UpdateWindow();                             // And redraw it immediately
00415 #endif
00416 
00417     return(TRUE);
00418 }


Member Data Documentation

INT32 CProgressBar::CurrentPercent [protected]
 

Definition at line 139 of file progbar.h.

BOOL CProgressBar::FontIsSystemFont [protected]
 

Definition at line 143 of file progbar.h.

String_64* CProgressBar::JobDescription [protected]
 

Definition at line 140 of file progbar.h.

INT32 CProgressBar::m_FontDescent [protected]
 

Definition at line 142 of file progbar.h.

HFONT CProgressBar::m_hFont [protected]
 

Definition at line 141 of file progbar.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:53:14 2007 for Camelot by  doxygen 1.4.4