
/***************************************************************************
**
**    $Header:   D:/PICSLDV/SRC/LOG/VARPANE.CPP   1.14   09 Jan 1997 14:26:40   ZJRD  $
**
**    $Log:   D:/PICSLDV/SRC/LOG/VARPANE.CPP  $
** 
**    Rev 1.14   09 Jan 1997 14:26:40   ZJRD
** No change.
** 
**    Rev 1.13   13 Dec 1996 11:21:30   ZJRD
** No change.
** 
**    Rev 1.12   22 Nov 1996 11:02:32   ZJRD
** No change.
** 
**    Rev 1.11   11 Nov 1996 12:49:46   ZJRD
** No change.
** 
**    Rev 1.10   06 Nov 1996 13:01:46   ZJRD
** No change.
** 
**    Rev 1.9   02 Nov 1996 09:46:40   ZJRD
** No change.
** 
**    Rev 1.8   30 Oct 1996 12:48:56   ZJRD
** No change.
** 
**    Rev 1.7   28 Oct 1996 09:41:50   ZJRD
** No change.
** 
**    Rev 1.6   21 Oct 1996 09:16:10   ZJRD
** No change.
** 
**    Rev 1.5   09 Oct 1996 13:45:46   ZJRD
** No change.
** 
**    Rev 1.4   23 Sep 1996 10:32:46   ZJRD
** No change.
** 
**    Rev 1.3   06 Sep 1996 13:46:42   ZJRD
** No change.
** 
**    Rev 1.2   02 Sep 1996 11:27:46   ZJRD
** No change.
** 
**    Rev 1.1   15 Aug 1996 10:06:06   ZJRD
** No change.
** 
**    Rev 1.0   13 Aug 1996 09:18:24   ZJRD
** Initial revision.
** 
****************************************************************************/

/////////////////////////////////////////////////////////////////////////////
//
//  File name: VARPANE.CPP
//
//  Description: The implementation file for the class: CVarPane.
//
//  Author: Chen Jun
//
//  Date: 07/03/95
//
//  Modification:
//      1. 07/03/95, Initial version of the class: CVarPane.
//
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////
// Include files.
#include "stdafx.h"
#include "resource.h"

#include "symblsvr.h"
#include "stkexp.h"
#include "varexp.h"

#include "varpane.h"
#include "vartype.h"

#include "colors.h"


/////////////////////////////////////////////////////////////////////////////
// Debug flags.
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif


/////////////////////////////////////////////////////////////////////////////
// CVarPane

// Create Bottom pane in the Variable window.
BOOL CVarPane::Create(CWnd* pParent)
{
    // Assertion of the input parameters.
    
    // Register a custom WndClass and create a window.
    LPCSTR pszBottomClass =
        AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS,
            LoadCursor(NULL, IDC_ARROW),
            (HBRUSH)(GetStockObject(LTGRAY_BRUSH)));
            
    LPCSTR pszTitle = "";            
            
    DWORD dwStyle = WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER;
    
    const CRect rect(0,0,0,0);

    // Create a new sub-window.
    return CWnd::Create(pszBottomClass, pszTitle, dwStyle, rect, 
        pParent, IDW_VAR_BOTTOM);
}

// Initialize the class member.
void CVarPane::InitialMember(void)
{
    // Initialization.
    m_strAddress = "";
    m_strType = "";
}

// Construction.
CVarPane::CVarPane()
{
    // Initial class members.
    InitialMember();
}

// Destruction.
CVarPane::~CVarPane()
{
}


/////////////////////////////////////////////////////////////////////////////
// Common function.

// Draw the 3-D frame. Refer to UICOM.CPP written by Roger.
void CVarPane::DrawFrame(CDC * pDC, CRect &rect)
{        
    CPen pen1(PS_SOLID, 1, PALETTEINDEX(COLOR_DKGRAY));    
    CPen pen2(PS_SOLID, 1, PALETTEINDEX(COLOR_WHITE));    
    CPen * penOld;
    
    pDC->MoveTo(rect.left, rect.bottom);

    penOld = pDC->SelectObject(&pen1);

    pDC->LineTo(rect.left, rect.top);
    pDC->LineTo(rect.right, rect.top);

    pDC->SelectObject(&pen2);

    pDC->LineTo(rect.right, rect.bottom);
    pDC->LineTo(rect.left, rect.bottom);

    pDC->SelectObject(penOld);
}             

// Display the error message.
void CVarPane::DisplayErrorMessage(void) const
{
    // Assertion of the input parameters.
    ASSERT( m_nErrorID > noError && m_nErrorID < maxError );
    
    // Create the error message table.
    char* pszErrorMessage[] = {
        "",
        "Insufficient memory."
    };
    
    // Show the error message.
    AfxMessageBox(pszErrorMessage[m_nErrorID]);
}


/////////////////////////////////////////////////////////////////////////////
// Message map

BEGIN_MESSAGE_MAP(CVarPane, CWnd)
    //{{AFX_MSG_MAP(CVarPane)
    ON_WM_CREATE()
    ON_WM_PAINT()
    ON_WM_LBUTTONDBLCLK()
    ON_WM_SETCURSOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CVarPane message handlers

int CVarPane::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CWnd::OnCreate(lpCreateStruct) == -1)
        return -1;
    
    // TODO: Add your specialized creation code here

    // Set standard font & Get the font size.
    CDC* pDC = GetDC();
    pDC->SelectStockObject(ANSI_FIXED_FONT);
    TEXTMETRIC tm;
    pDC->GetTextMetrics(&tm);
    m_nFontWidth = tm.tmAveCharWidth;
    m_nFontHeight = tm.tmHeight + tm.tmExternalLeading;
    ReleaseDC(pDC);

    // Set the pane position.
    m_nTop = (bottomHeight - m_nFontHeight) / 2;
    m_nFirst = m_nFontWidth*11;
    m_nSecond = m_nFontWidth*27;
         
    return 0;
}

void CVarPane::OnPaint()
{
    CPaintDC dc(this); // device context for painting
    
    // TODO: Add your message handler code here

    // Set font & color.
    dc.SelectStockObject(ANSI_FIXED_FONT);
    dc.SetBkColor(PALETTEINDEX(COLOR_LTGRAY));
    dc.SetTextColor(PALETTEINDEX(COLOR_BLACK));

    // Draw the frame.
    CRect rectPane;
    GetClientRect(rectPane);
    int nLeft = m_nFontWidth*10;
    int nRight = m_nFontWidth*18;
    DrawFrame(&dc, CRect(nLeft,1,nRight,rectPane.bottom-1));

    nLeft = m_nFontWidth*26;
    nRight = rectPane.right-1;
    DrawFrame(&dc, CRect(nLeft,1,nRight,rectPane.bottom-1));

    // Write the item name.
    dc.TextOut(m_nFontWidth*1, m_nTop, CString("Address:"));
    dc.TextOut(m_nFontWidth*20, m_nTop, CString("Type:"));
        
    // Output the Address.
    dc.TextOut(m_nFirst, m_nTop, m_strAddress);
    
    // Output the Type.
    dc.TextOut(m_nSecond, m_nTop, m_strType);
    
    // Do not call CWnd::OnPaint() for painting messages
}

void CVarPane::OnLButtonDblClk(UINT nFlags, CPoint point)
{
    // TODO: Add your message handler code here and/or call default
    
    // Open the dialog to show the detail definition for the complex type.
    if ( point.x >= m_nFontWidth*20 ) {
//        CVarTypeDialog dlg;
//        dlg.DoModal();
    }
    
    CWnd::OnLButtonDblClk(nFlags, point);
}

/*
void CVarPane::OnRButtonDown(UINT nFlags, CPoint point)
{
    // TODO: Add your message handler code here and/or call default

    // Create the popup menu.
    CMenu* pPopupMenu = new CMenu;
    ASSERT( NULL != pPopupMenu );
    if ( !pPopupMenu ) {
        m_nErrorID = insufficientMemory;
        DisplayErrorMessage();
        return;
    }
    pPopupMenu->CreatePopupMenu();
    
    // Define the local menu.
    pPopupMenu->AppendMenu(MF_STRING, ID_VIEW_FORMAT_ADDRESS, "char* as &Address");
    pPopupMenu->AppendMenu(MF_STRING, ID_VIEW_FORMAT_STRING, "char* as &String");
    pPopupMenu->AppendMenu(MF_SEPARATOR);
    
    pPopupMenu->AppendMenu(MF_STRING, ID_VIEW_FORMAT_BYTE, "&Byte");
    pPopupMenu->AppendMenu(MF_STRING, ID_VIEW_FORMAT_WORD, "&Word");
    pPopupMenu->AppendMenu(MF_STRING, ID_VIEW_FORMAT_LONG, "&Long");
    pPopupMenu->AppendMenu(MF_STRING, ID_VIEW_FORMAT_FLOAT, "&Float");
    pPopupMenu->AppendMenu(MF_STRING, ID_VIEW_FORMAT_DOUBLE, "&Double");
    pPopupMenu->AppendMenu(MF_SEPARATOR);
    
    pPopupMenu->AppendMenu(MF_STRING, ID_VIEW_FORMAT_SIGNED, "S&igned Decimal");
    pPopupMenu->AppendMenu(MF_STRING, ID_VIEW_FORMAT_UNSIGNED, "&Unsigned Decimal");
    pPopupMenu->AppendMenu(MF_STRING, ID_VIEW_FORMAT_HEXADECIMAL, "Hexadecimal");
    
    // Create the local menu.
    CMenu* pLocalMenu = new CMenu;
    ASSERT( NULL != pLocalMenu );
    if ( !pLocalMenu ) {
        m_nErrorID = insufficientMemory;
        DisplayErrorMessage();
        return;
    }
    pLocalMenu->CreatePopupMenu();

    // Define the local menu.
    pLocalMenu->AppendMenu(MF_STRING, ID_VARIABLE_ADD, "&Add...");
    pLocalMenu->AppendMenu(MF_STRING, ID_VARIABLE_EDIT, "&Edit...");
    pLocalMenu->AppendMenu(MF_STRING, ID_VARIABLE_DELETE, "&Delete");
    pLocalMenu->AppendMenu(MF_STRING, ID_VARIABLE_DELETEALL, "De&lete All");
    pLocalMenu->AppendMenu(MF_STRING, ID_VARIABLE_UNDELETE, "&Undelete");
    pLocalMenu->AppendMenu(MF_SEPARATOR);

    pLocalMenu->AppendMenu(MF_STRING, ID_EDIT_MODIFYVALUES, "&Modify Value...");
    pLocalMenu->AppendMenu(MF_SEPARATOR);

    pLocalMenu->AppendMenu(MF_POPUP, (UINT)(pPopupMenu->GetSafeHmenu()), "&Format");

    pLocalMenu->AppendMenu(MF_STRING, ID_VIEW_TYPECAST, "Type &Cast...");
    pLocalMenu->AppendMenu(MF_SEPARATOR);
    
    pLocalMenu->AppendMenu(MF_STRING, ID_VIEW_DISPLAYHORIZONTALLY, "Display &Horizontally");
    pLocalMenu->AppendMenu(MF_STRING, ID_VIEW_DISPLAYVERTICALLY, "Display &Vertically");
    pLocalMenu->AppendMenu(MF_SEPARATOR);
    
    pLocalMenu->AppendMenu(MF_STRING, ID_VIEW_SORTBYHISTORY, "Sort By H&istory");
    pLocalMenu->AppendMenu(MF_STRING, ID_VIEW_SORTBYNAME, "Sort By &Name");
    pLocalMenu->AppendMenu(MF_SEPARATOR);
    
    pLocalMenu->AppendMenu(MF_STRING, ID_EDIT_SEARCH, "&Search...");
    pLocalMenu->AppendMenu(MF_STRING, ID_EDIT_SEARCHNEXT, "Search &Next");
    
    // Adjust the cursor location.
    if ( 0 == point.x && 0 == point.y ) {
        CRect rect;
        GetClientRect(&rect);
        point = CPoint(rect.left+rect.Width()/2, rect.top+rect.Height()/2);
    }

    // Display the local menu.
    ClientToScreen(&point);

    // Active the local menu.
    pLocalMenu->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, GetParent());

    // Release the allocated buffer.
//    delete pPopupMenu;
    delete pLocalMenu;
    
    CWnd::OnRButtonDown(nFlags, point);
}
*/


BOOL CVarPane::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
    // TODO: Add your message handler code here and/or call default

    // Disable parent window from pre-handling the WM_RBUTTONDOWN message.
    // MAINFRM latch WM_RBUTTONDOWN to implement local menu.
    if( message == WM_RBUTTONDOWN ) {
        return FALSE;
    }
    
    return CWnd::OnSetCursor(pWnd, nHitTest, message);
}
