summaryrefslogtreecommitdiff
path: root/win/cadbar.cpp
blob: a6093f3dce6b264cd77c0e952b34378961f9c968 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// CADBar.cpp: implementation of the CCADStatusBar class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "leocad.h"
#include "CADBar.h"
#include "StepPop.h"
#include "project.h"
#include "lc_application.h"
#include "bmpmenu.h"

#ifdef _DEBUG
#undef THIS_FILE
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()

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

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))
	{
		ClientToScreen(rect);
		m_pPopup = new CStepPopup(CPoint(rect.left, rect.top), this);
	}

	GetItemRect(CommandToIndex(ID_INDICATOR_SNAP), rect);
	if (rect.PtInRect(point))
	{
		ClientToScreen(&point);
		CMenu menuPopups;
		menuPopups.LoadMenu(IDR_POPUPS);
		CTitleMenu TitleMenu;
		TitleMenu.Attach(menuPopups.GetSubMenu(7)->Detach());

		int SXY, SZ;
		lcGetActiveProject()->GetSnapIndex(&SXY, &SZ);

		TitleMenu.SetMenuTitle(ID_SNAP_XY, "XY Snap");
		TitleMenu.SetMenuTitle(ID_SNAP_Z, "Z Snap");

		TitleMenu.CheckMenuRadioItem(2, 11, SXY + 2, MF_BYPOSITION);
		TitleMenu.CheckMenuRadioItem(14, 23, SZ + 14, MF_BYPOSITION);

		TitleMenu.TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, AfxGetMainWnd());
	}

	CStatusBar::OnLButtonDown(nFlags, point);
}

void CCADStatusBar::OnRButtonDown(UINT nFlags, CPoint point) 
{
	CRect rect;
	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);
}