home *** CD-ROM | disk | FTP | other *** search
- // -------------------------------------------------------------------------
- // Copyright @ 1997 TCK Software, Incorporated
- // All Rights Reserved
- // -------------------------------------------------------------------------
- #include "stdafx.h"
- #include "VHexStatic.h"
- #include "VForm.h"
-
- // -------------------------------------------------------------------------
- // VHexStatic Class
- // -------------------------------------------------------------------------
- VHexStatic::VHexStatic()
- {
- m_text.Format("Ctl %d", m_nId);
- SetBorder(TRUE);
- VertCenterText(TRUE);
- SetTransparent(FALSE);
- m_nLeftMargin = 1;
- m_nLineHeight = 18;
- m_bHexOn = FALSE;
- }
-
- // -------------------------------------------------------------------------
- // VHexStatic Constructor with arguments
- // -------------------------------------------------------------------------
- VHexStatic::VHexStatic(VRow *pRow, int nId, LPCSTR szText,
- int x, int y, int cx, int cy) :
- VCtl(pRow, nId, szText, x, y, cx, cy)
- {
- SetBorder(TRUE);
- VertCenterText(TRUE);
- SetTransparent(FALSE);
- m_nLeftMargin = 1;
- m_nLineHeight = 18;
- m_bHexOn = FALSE;
- }
-
- // -------------------------------------------------------------------------
- // VHexStatic Assignment Operator (=)
- // -------------------------------------------------------------------------
- VHexStatic& VHexStatic::operator =(VHexStatic& x)
- {
- (VCtl&)*this = (VCtl&)x;
- m_bHexOn = x.m_bHexOn;
- m_nLineHeight = x.m_nLineHeight;
-
- return *this;
- }
-
- // -------------------------------------------------------------------------
- // VHexStatic Init
- // -------------------------------------------------------------------------
- void VHexStatic::Init(VRow *pRow, int nId, LPCSTR szText, int x, int y, int cx, int cy)
- {
- VCtl::Init(pRow, nId, szText, x, y, cx, cy);
- }
-
- // -------------------------------------------------------------------------
- // VHexStatic SetHexText
- // -------------------------------------------------------------------------
- void VHexStatic::SetHexText(LPCSTR szBuf, int nLength)
- {
- char c;
- char *pAscii = m_text.GetBuffer(nLength+1);
- char *pHex1 = m_hex1.GetBuffer(nLength+1);
- char *pHex2 = m_hex2.GetBuffer(nLength+1);
-
- // Logic to cdisplay hex information
- for(int i=0; i < nLength; i++)
- {
- c = szBuf[i];
- pAscii[i] = (c == 0) ? '.' : c; // Convert nulls to periods
- pHex1[i] = HexHi(c);
- pHex2[i] = HexLo(c);
- }
-
- pAscii[nLength] = 0; // Null Terminate
- pHex1[nLength] = 0; // Null Terminate
- pHex2[nLength] = 0; // Null Terminate
-
- m_text.ReleaseBuffer();
- m_hex1.ReleaseBuffer();
- m_hex2.ReleaseBuffer();
- }
-
- // -------------------------------------------------------------------------
- // Returns Hex Char for byte
- // -------------------------------------------------------------------------
- char VHexStatic::HexLo(char c)
- {
- char x = c & 0x0F; // Mask off the high bits
- static char hexArray[] = "0123456789ABCDEFXXXX";
-
- return hexArray[x];
- }
-
- #define HIHALFBYTE(b) ((BYTE)(((BYTE)(b) >> 4) & 0x0F))
- char VHexStatic::HexHi(char c)
- {
- char x = HIHALFBYTE(c); // Shift off low bits and mask
- static char hexArray[] = "0123456789ABCDEFXXXX";
-
- return hexArray[x];
- }
-
- // -------------------------------------------------------------------------
- // VHexStatic OnDraw Routine
- // -------------------------------------------------------------------------
- void VHexStatic::OnDraw(CDC *pDC, LPRECT pRect, BOOL bGridMode)
- {
- CRect rcOrig = pRect ? *pRect : m_rectWin;
- CRect rect = rcOrig;
- CRect rectText;
- BOOL bSkipBkgrnd = FALSE;
- int nLineStart = rcOrig.top;
- VClipObj myClipObj;
-
- if(bGridMode)
- {
- myClipObj.Set(pDC, rcOrig);
- // DrawTextEx(pDC, rect, TRUE, bGridMode); // Background already drawn
- // return;
- }
-
- rect.bottom = rect.top + m_nLineHeight; // First do ascii text
- if(rect.bottom > rcOrig.bottom)
- rect.bottom = rcOrig.bottom;
- rectText = rect;
-
- if(HasBorder())
- {
- if(NoInactiveBorder() && !HasFocus())
- bSkipBkgrnd = TRUE;
- else
- DrawEffect(pDC, &rect, m_nEffect, m_nEffectDepth);
-
- rectText = EffectInterior(&rect, m_nEffect, m_nEffectDepth);
- }
-
- if(!IsTransparent() && !bSkipBkgrnd)
- {
- CBrush brBack(m_vclrBack.GetRGB());
- pDC->FillRect(&rectText, &brBack);
- }
-
- rectText.left += m_nLeftMargin;
- // DrawCtlText(pDC, m_text, rectText, DT_EDITCONTROL | DT_WORDBREAK);
-
- // --------------------------
- // Draw the Text
- // --------------------------
- CFont* pOldFont=0;
- COLORREF clrOldText, clrOldBk;
- int nOldBkMode, nOldTextAlign;
- BOOL bVal;
-
- // --- Setup Text Attributes ---
- if(m_pFont) pOldFont = pDC->SelectObject(m_pFont); // Set Custom Font
- clrOldText = pDC->SetTextColor(ForeColor());
- clrOldBk = pDC->SetBkColor(BackColor());
- nOldBkMode = pDC->SetBkMode(TRANSPARENT);
- nOldTextAlign = pDC->SetTextAlign(m_nTextAlign);
-
- bVal = pDC->ExtTextOut(rectText.left, rectText.top, ETO_CLIPPED,
- rectText, m_text, NULL );
-
- // Showing extra 2 rows
- if(HexOn())
- {
- nLineStart += m_nLineHeight + 4;
- rectText.top = nLineStart;
- rectText.bottom = rectText.top + m_nLineHeight;
- if(rectText.bottom > rcOrig.bottom)
- rectText.bottom = rcOrig.bottom;
-
- if(rectText.bottom > rectText.top) // Only draw if room
- bVal = pDC->ExtTextOut(rectText.left, rectText.top, ETO_CLIPPED,
- rectText, m_hex1, NULL );
-
- // Since we arent using borders, we will cheat a little...
- nLineStart += m_nLineHeight - 3;
- rectText.top = nLineStart;
- rectText.bottom = rectText.top + m_nLineHeight;
- if(rectText.bottom > rcOrig.bottom)
- rectText.bottom = rcOrig.bottom;
-
- if(rectText.bottom > rectText.top) // Only draw if room
- bVal = pDC->ExtTextOut(rectText.left, rectText.top, ETO_CLIPPED,
- rectText, m_hex2, NULL );
- }
-
- // --- Reset Text Attributes back to originals ---
- pDC->SetTextColor(clrOldText);
- pDC->SetBkColor(clrOldBk);
- pDC->SetBkMode(nOldBkMode);
- pDC->SetTextAlign(nOldTextAlign);
- if(pOldFont) pDC->SelectObject(pOldFont); // Reset orig Font
- }
-
-