Files
ayanova7/archive/ayanova 1.9.4 CE final release db schema 171/sp/gzRightsButton.cpp

231 lines
4.5 KiB
C++

// gzRightsButton.cpp : implementation file
//
#include "stdafx.h"
#include "sp.h"
#include "gzRightsButton.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CgzRightsButton
CgzRightsButton::CgzRightsButton()
{
m_nState=0;
m_bCanReadOnly=true;//by default
m_bModified=false;
m_nInitialState=-1;
//get the current default font
::GetObject((HFONT)GetStockObject(DEFAULT_GUI_FONT),sizeof(m_lf),&m_lf);
//make it funky
m_lf.lfWeight = FW_BOLD ;
m_font.DeleteObject();
BOOL bCreated = m_font.CreateFontIndirect(&m_lf);
ASSERT(bCreated);
}
CgzRightsButton::~CgzRightsButton()
{
}
BEGIN_MESSAGE_MAP(CgzRightsButton, CButton)
//{{AFX_MSG_MAP(CgzRightsButton)
ON_CONTROL_REFLECT(BN_CLICKED, OnClicked)
ON_CONTROL_REFLECT(BN_DOUBLECLICKED, OnDoubleclicked)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CgzRightsButton message handlers
void CgzRightsButton::OnClicked()
{
//toggle state
if(m_nState==0)//no access
{
m_nState++;
Set(m_nState,false);
return;
}
if(m_nState==2)//read only
{
m_nState=0;
Set(m_nState,false);
return;
}
if(m_bCanReadOnly)
{
m_nState=2;
Set(m_nState,false);
return;
}
else
{
m_nState=0;
Set(m_nState,false);
return;
}
return;
}
//***************************************
void CgzRightsButton::Set(CString state, bool initialize)
{
int x=atoi(state);
Set(x,initialize);
}
//**************************************
void CgzRightsButton::Set(int state, bool initialize)
{
ASSERT(state <3 && state > -1);
//ASSERT(state!=2 && m_bCanReadOnly==false);
m_nState = state;
//the control is being initialized
//so flag as unmodified
//and capture the initial state;
if(initialize)
{
m_bModified=false;
m_nInitialState=state;
}
else
{
//not initializing, so user click
//brought us here
//check to see if user clicked back
//to original value in which case
//it's not modified
if(m_nInitialState==m_nState)//no longer modified
m_bModified=false;
else
m_bModified=true;
}
//force a redraw
Invalidate();
}
//*****************************************
void CgzRightsButton::Get(CString *str)
{
int x=Get();
str->Format("%d",x);
}
//***************************************
int CgzRightsButton::Get()
{
return m_nState;
}
void CgzRightsButton::DoesReadOnly(bool ro)
{
m_bCanReadOnly=ro;
}
void CgzRightsButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rect = lpDrawItemStruct->rcItem;
UINT state = lpDrawItemStruct->itemState;
pDC->SelectObject(&m_font);
CString strText;
switch(m_nState)
{
case 0:
strText="None";
pDC->SetTextColor(RGB(255,0,0));
break;
case 1:
strText="Full";
pDC->SetTextColor(RGB(0,150,0));
break;
case 2:
strText="View";
pDC->SetTextColor(RGB(200,100,0));
break;
}
// draw the control edges (DrawFrameControl is handy!)
if (state & ODS_SELECTED)
pDC->DrawFrameControl(rect, DFC_BUTTON, DFCS_BUTTONPUSH );//| DFCS_PUSHED
else
pDC->DrawFrameControl(rect, DFC_BUTTON, DFCS_BUTTONPUSH);
//DFCS_BUTTONPUSH| DFCS_PUSHED
// Deflate the drawing rect by the size of the button's edges
rect.DeflateRect( CSize(GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE)));
//pDC->FillSolidRect(rect, RGB(0, 0, 0));
// Draw the text
if (!strText.IsEmpty())
{
CSize Extent = pDC->GetTextExtent(strText);
CPoint pt( rect.CenterPoint().x - Extent.cx/2,
rect.CenterPoint().y - Extent.cy/2 );
if (state & ODS_SELECTED)
pt.Offset(1,1);
int nMode = pDC->SetBkMode(TRANSPARENT);
if (state & ODS_DISABLED)
pDC->DrawState(pt, Extent, strText, DSS_DISABLED, TRUE, 0, (HBRUSH)NULL);
else
pDC->TextOut(pt.x, pt.y, strText);
pDC->SetBkMode(nMode);
}
}
void CgzRightsButton::PreSubclassWindow()
{
CButton::PreSubclassWindow();
ModifyStyle(0, BS_OWNERDRAW);
}
bool CgzRightsButton::IsChanged()
{
return m_bModified;
}
void CgzRightsButton::OnDoubleclicked()
{
//this should make it easier to quickly click multiple changes
OnClicked();
}