summaryrefslogtreecommitdiff
path: root/win
diff options
context:
space:
mode:
authorleo2003-09-18 16:50:52 +0000
committerleo2003-09-18 16:50:52 +0000
commit4bd07328df37f1bc8a16cdd77decf49467b6c4be (patch)
tree31c714fab1ece4cd75a3df66e10821a2a9394caf /win
parent3df8b99fe7e3961006ab4cd4a3bdc33c7c2b7e51 (diff)
Added a progress bar for long operations.
git-svn-id: http://svn.leocad.org/trunk@349 c7d43263-9d01-0410-8a33-9dba5d9f93d6
Diffstat (limited to 'win')
-rw-r--r--win/Mainfrm.cpp45
-rw-r--r--win/Mainfrm.h5
-rw-r--r--win/System.cpp35
-rw-r--r--win/cadbar.cpp64
-rw-r--r--win/cadbar.h29
5 files changed, 176 insertions, 2 deletions
diff --git a/win/Mainfrm.cpp b/win/Mainfrm.cpp
index 7c88533..3f30de8 100644
--- a/win/Mainfrm.cpp
+++ b/win/Mainfrm.cpp
@@ -3,6 +3,7 @@
#include "stdafx.h"
#include <afxrich.h>
+#include <afxpriv.h>
#include "LeoCAD.h"
#include "MainFrm.h"
#include "Camera.h"
@@ -102,6 +103,7 @@ BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_COMMAND(ID_FILE_PRINTPIECELIST, OnFilePrintPieceList)
ON_WM_ACTIVATEAPP()
ON_COMMAND(ID_VIEW_NEWVIEW, OnViewNewView)
+ ON_MESSAGE(WM_SETMESSAGESTRING, OnSetMessageString)
//}}AFX_MSG_MAP
ON_COMMAND_RANGE(ID_PIECEBAR_ZOOMPREVIEW, ID_PIECEBAR_SUBPARTS, OnPieceBar)
ON_UPDATE_COMMAND_UI_RANGE(ID_PIECEBAR_ZOOMPREVIEW, ID_PIECEBAR_SUBPARTS, OnUpdatePieceBar)
@@ -987,6 +989,49 @@ void CMainFrame::OnActivateApp(BOOL bActive, HTASK hTask)
project->HandleNotify(LC_ACTIVATE, bActive ? 1 : 0);
}
+LRESULT CMainFrame::OnSetMessageString(WPARAM wParam, LPARAM lParam)
+{
+ UINT nIDLast = m_nIDLastMessage;
+ m_nFlags &= ~WF_NOPOPMSG;
+
+ CWnd* pMessageBar = GetMessageBar();
+ if (pMessageBar != NULL)
+ {
+ LPCTSTR lpsz = NULL;
+ CString strMessage;
+
+ // set the message bar text
+ if (!m_strStatusBar.IsEmpty())
+ {
+ lpsz = m_strStatusBar;
+ }
+ else if (lParam != 0)
+ {
+ ASSERT(wParam == 0); // can't have both an ID and a string
+ lpsz = (LPCTSTR)lParam; // set an explicit string
+ }
+ else if (wParam != 0)
+ {
+ // map SC_CLOSE to PREVIEW_CLOSE when in print preview mode
+ if (wParam == AFX_IDS_SCCLOSE && m_lpfnCloseProc != NULL)
+ wParam = AFX_IDS_PREVIEW_CLOSE;
+
+ // get message associated with the ID indicated by wParam
+ GetMessageString(wParam, strMessage);
+ lpsz = strMessage;
+ }
+ pMessageBar->SetWindowText(lpsz);
+
+ // update owner of the bar in terms of last message selected
+ m_nIDLastMessage = (UINT)wParam;
+ m_nIDTracking = (UINT)wParam;
+ }
+
+ m_nIDLastMessage = (UINT)wParam; // new ID (or 0)
+ m_nIDTracking = (UINT)wParam; // so F1 on toolbar buttons work
+ return nIDLast;
+}
+
#include "view.h"
LRESULT CALLBACK GLWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
diff --git a/win/Mainfrm.h b/win/Mainfrm.h
index e2c268d..ca6db37 100644
--- a/win/Mainfrm.h
+++ b/win/Mainfrm.h
@@ -56,6 +56,9 @@ public:
CPiecesBar m_wndPiecesBar;
CSplitterWnd m_wndSplitter;
+ void SetStatusBarMessage(const char* Message)
+ { m_strStatusBar = Message; }
+
protected:
CModifyDialog m_wndModifyDlg;
@@ -63,6 +66,7 @@ protected:
WINDOWPLACEMENT m_wpPrev;
CToolBar* m_pwndFullScrnBar;
CRect m_FullScreenWindowRect;
+ CString m_strStatusBar;
// Generated message map functions
protected:
@@ -78,6 +82,7 @@ protected:
afx_msg void OnFilePrintPieceList();
afx_msg void OnActivateApp(BOOL bActive, HTASK hTask);
afx_msg void OnViewNewView();
+ afx_msg LRESULT OnSetMessageString(WPARAM wParam, LPARAM lParam);
//}}AFX_MSG
// Status bar
diff --git a/win/System.cpp b/win/System.cpp
index f928673..e5e72c8 100644
--- a/win/System.cpp
+++ b/win/System.cpp
@@ -27,6 +27,8 @@
#include "LibDlg.h"
#include "EdGrpDlg.h"
#include "AboutDlg.h"
+#include "cadbar.h"
+#include "mainfrm.h"
static CMenu menuPopups;
static CStepDlg* StepModeless = NULL;
@@ -1690,3 +1692,36 @@ void SystemSetGroup(int group)
{
AfxGetMainWnd()->PostMessage (WM_LC_UPDATE_LIST, group+2, 0);
}
+
+void SystemStartProgressBar(int nLower, int nUpper, int nStep, const char* Text)
+{
+ CFrameWnd* pFrame = (CFrameWnd*)AfxGetMainWnd();
+ CCADStatusBar* pStatusBar = (CCADStatusBar*)pFrame->GetControlBar(AFX_IDW_STATUS_BAR);
+
+ pStatusBar->ShowProgressBar(TRUE);
+ pStatusBar->SetProgressBarRange(nLower, nUpper);
+ pStatusBar->SetProgressBarStep(nStep);
+ pStatusBar->SetProgressBarPos(0);
+
+ ((CMainFrame*)AfxGetMainWnd())->SetStatusBarMessage(Text);
+ ((CMainFrame*)AfxGetMainWnd())->SetMessageText(Text);
+}
+
+void SytemEndProgressBar()
+{
+ CFrameWnd* pFrame = (CFrameWnd*)AfxGetMainWnd();
+ CCADStatusBar* pStatusBar = (CCADStatusBar*)pFrame->GetControlBar(AFX_IDW_STATUS_BAR);
+
+ pStatusBar->ShowProgressBar(FALSE);
+
+ ((CMainFrame*)AfxGetMainWnd())->SetStatusBarMessage("");
+ ((CMainFrame*)AfxGetMainWnd())->SetMessageText(AFX_IDS_IDLEMESSAGE);
+}
+
+void SytemStepProgressBar()
+{
+ CFrameWnd* pFrame = (CFrameWnd*)AfxGetMainWnd();
+ CCADStatusBar* pStatusBar = (CCADStatusBar*)pFrame->GetControlBar(AFX_IDW_STATUS_BAR);
+
+ pStatusBar->StepProgressBar();
+}
diff --git a/win/cadbar.cpp b/win/cadbar.cpp
index d40466d..80a1df3 100644
--- a/win/cadbar.cpp
+++ b/win/cadbar.cpp
@@ -13,10 +13,13 @@ static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
+#define ID_STATUS_PROGRESS 17234
+
BEGIN_MESSAGE_MAP(CCADStatusBar, CStatusBar)
//{{AFX_MSG_MAP(CCADStatusBar)
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
+ ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
@@ -27,16 +30,32 @@ END_MESSAGE_MAP()
CCADStatusBar::CCADStatusBar()
{
m_pPopup = NULL;
+ m_nProgressWidth = 150;
+ m_bProgressVisible = FALSE;
}
CCADStatusBar::~CCADStatusBar()
{
+}
+
+BOOL CCADStatusBar::Create(CWnd *pParentWnd, DWORD dwStyle, UINT nID)
+{
+ // Default creation
+ BOOL bCreatedOK = CStatusBar::Create(pParentWnd,dwStyle,nID);
+
+ if (bCreatedOK)
+ {
+ // Also create the progress bar
+ m_Progress.Create(WS_CHILD | WS_EX_STATICEDGE | PBS_SMOOTH, CRect(0,0,m_nProgressWidth,10), this, ID_STATUS_PROGRESS);
+ }
+ return bCreatedOK;
}
void CCADStatusBar::OnLButtonDown(UINT nFlags, CPoint point)
{
CRect rect;
+
GetItemRect(CommandToIndex(ID_INDICATOR_STEP), rect);
if (rect.PtInRect(point))
{
@@ -63,6 +82,49 @@ void CCADStatusBar::OnRButtonDown(UINT nFlags, CPoint point)
GetItemRect(CommandToIndex(ID_INDICATOR_STEP), rect);
if (rect.PtInRect(point))
AfxGetMainWnd()->PostMessage(WM_COMMAND, ID_VIEW_STEP_CHOOSE);
-
+
CStatusBar::OnRButtonDown(nFlags, point);
}
+
+void CCADStatusBar::OnSize(UINT nType, int cx, int cy)
+{
+ CStatusBar::OnSize(nType, cx, cy);
+
+ if (m_bProgressVisible)
+ AdjustProgressBarPosition();
+}
+
+BOOL CCADStatusBar::ShowProgressBar(BOOL bShow)
+{
+ // Save old visible status
+ BOOL bOldVisible = m_bProgressVisible;
+
+ if ((bOldVisible != bShow) && ::IsWindow(m_Progress.m_hWnd))
+ {
+ // Show/hide
+ m_Progress.ShowWindow(bShow ? SW_SHOWNA : SW_HIDE);
+ m_bProgressVisible = bShow;
+
+ // If just shown, make sure it's in the right position
+ if (bShow)
+ {
+ AdjustProgressBarPosition();
+ RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
+ }
+ }
+
+ return bOldVisible;
+}
+
+void CCADStatusBar::AdjustProgressBarPosition()
+{
+ // Make sure the progress bar is created
+ if(!::IsWindow(m_Progress.m_hWnd))
+ return;
+
+ CRect Rect;
+ GetItemRect(0, Rect);
+ m_Progress.SetWindowPos(NULL, Rect.right - m_nProgressWidth, Rect.top,
+ m_nProgressWidth, Rect.Height(), SWP_NOZORDER | SWP_NOACTIVATE);
+}
+
diff --git a/win/cadbar.h b/win/cadbar.h
index 0af4856..6026258 100644
--- a/win/cadbar.h
+++ b/win/cadbar.h
@@ -12,15 +12,42 @@
class CCADStatusBar : public CStatusBar
{
public:
- CWnd* m_pPopup;
CCADStatusBar();
virtual ~CCADStatusBar();
+ virtual BOOL Create(CWnd *pParentWnd, DWORD dwStyle = WS_CHILD | WS_VISIBLE | CBRS_BOTTOM, UINT nID = AFX_IDW_STATUS_BAR);
+
+ BOOL IsProgressBarVisible() const
+ { return m_bProgressVisible; }
+ void SetProgressBarWidth(int nWidth)
+ { m_nProgressWidth = nWidth; }
+ BOOL ShowProgressBar(BOOL bShow = TRUE);
+
+ void SetProgressBarRange(int nLower, int nUpper)
+ { m_Progress.SetRange(nLower,nUpper); }
+ int SetProgressBarPos(int nPos)
+ { return m_Progress.SetPos(nPos); }
+ int SetProgressBarStep(int nStep)
+ { return m_Progress.SetStep(nStep); }
+ int StepProgressBar()
+ { return m_Progress.StepIt(); }
+
+protected:
+ void AdjustProgressBarPosition();
+public:
+ CWnd* m_pPopup;
+
+protected:
+ // Progress Bar variables.
+ CProgressCtrl m_Progress;
+ int m_nProgressWidth;
+ BOOL m_bProgressVisible;
protected:
//{{AFX_MSG(CCADStatusBar)
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
+ afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()