//////////////////////////////////////////////////////////////////////
// This file was auto-generated by codelite's wxCrafter Plugin
// wxCrafter project file: memoryviewbase.wxcp
// Do not modify this file by hand!
//////////////////////////////////////////////////////////////////////

#include "memoryviewbase.h"

// Declare the bitmap loading function
extern void wxC5C75InitBitmapResources();

namespace
{
// return the wxBORDER_SIMPLE that matches the current application theme
wxBorder get_border_simple_theme_aware_bit()
{
#if wxVERSION_NUMBER >= 3300 && defined(__WXMSW__)
    return wxSystemSettings::GetAppearance().IsDark() ? wxBORDER_SIMPLE : wxBORDER_DEFAULT;
#else
    return wxBORDER_DEFAULT;
#endif
} // DoGetBorderSimpleBit
bool bBitmapLoaded = false;
} // namespace

MemoryViewBase::MemoryViewBase(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
    : wxPanel(parent, id, pos, size, style)
{
    if (!bBitmapLoaded) {
        // We need to initialise the default bitmap handler
        wxXmlResource::Get()->AddHandler(new wxBitmapXmlHandler);
        wxC5C75InitBitmapResources();
        bBitmapLoaded = true;
    }

    wxBoxSizer* bSizer1 = new wxBoxSizer(wxVERTICAL);
    this->SetSizer(bSizer1);

    wxFlexGridSizer* flexGridSizer6 = new wxFlexGridSizer(0, 6, 0, 0);
    flexGridSizer6->SetFlexibleDirection(wxBOTH);
    flexGridSizer6->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
    flexGridSizer6->AddGrowableCol(1);

    bSizer1->Add(flexGridSizer6, 0, wxALL | wxEXPAND, WXC_FROM_DIP(5));

    m_staticText2 =
        new wxStaticText(this, wxID_ANY, _("Address:"), wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, -1)), 0);

    flexGridSizer6->Add(m_staticText2, 0, wxLEFT | wxTOP | wxBOTTOM | wxALIGN_CENTER_VERTICAL, WXC_FROM_DIP(5));

    m_textCtrlExpression = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, -1)),
                                          wxTE_PROCESS_ENTER);
    m_textCtrlExpression->SetToolTip(_("Address or pointer to watch"));
    m_textCtrlExpression->SetFocus();
#if wxVERSION_NUMBER >= 3000
    m_textCtrlExpression->SetHint(wxT(""));
#endif

    flexGridSizer6->Add(m_textCtrlExpression, 1, wxALL | wxEXPAND, WXC_FROM_DIP(5));

    m_staticText1 =
        new wxStaticText(this, wxID_ANY, _("Size:"), wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, -1)), 0);
    m_staticText1->SetToolTip(_("Memory size to view"));

    flexGridSizer6->Add(m_staticText1, 0, wxLEFT | wxTOP | wxBOTTOM | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL,
                        WXC_FROM_DIP(5));

    wxArrayString m_choiceSizeArr;
    m_choiceSizeArr.Add(_("32"));
    m_choiceSizeArr.Add(_("64"));
    m_choiceSizeArr.Add(_("128"));
    m_choiceSizeArr.Add(_("256"));
    m_choiceSizeArr.Add(_("512"));
    m_choiceSizeArr.Add(_("1024"));
    m_choiceSizeArr.Add(_("2048"));
    m_choiceSizeArr.Add(_("4096"));
    m_choiceSize =
        new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, -1)), m_choiceSizeArr, 0);
    m_choiceSize->SetToolTip(_("Memory size to view"));
    m_choiceSize->SetSelection(0);

    flexGridSizer6->Add(m_choiceSize, 0, wxALL | wxEXPAND | wxALIGN_CENTER_VERTICAL, WXC_FROM_DIP(5));

    m_staticText8 = new wxStaticText(this, wxID_ANY, _("Number of columns:"), wxDefaultPosition,
                                     wxDLG_UNIT(this, wxSize(-1, -1)), 0);

    flexGridSizer6->Add(m_staticText8, 0, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, WXC_FROM_DIP(5));

    wxArrayString m_choiceColsArr;
    m_choiceColsArr.Add(_("4"));
    m_choiceColsArr.Add(_("8"));
    m_choiceColsArr.Add(_("16"));
    m_choiceColsArr.Add(_("32"));
    m_choiceCols =
        new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, -1)), m_choiceColsArr, 0);
    m_choiceCols->SetToolTip(_("Number of columns to use per row"));
    m_choiceCols->SetSelection(2);

    flexGridSizer6->Add(m_choiceCols, 0, wxALL, WXC_FROM_DIP(5));

    wxBoxSizer* bSizer3 = new wxBoxSizer(wxHORIZONTAL);

    bSizer1->Add(bSizer3, 1, wxEXPAND, WXC_FROM_DIP(5));

    m_textCtrlMemory = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, -1)),
                                      wxTE_RICH2 | wxTE_MULTILINE | wxTE_DONTWRAP);
#ifdef __WXMSW__
    // To get the newer version of the font on MSW, we use font wxSYS_DEFAULT_GUI_FONT with family set to
    // wxFONTFAMILY_TELETYPE
    wxFont m_textCtrlMemoryFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
    m_textCtrlMemoryFont.SetFamily(wxFONTFAMILY_TELETYPE);
#else
    wxFont m_textCtrlMemoryFont = wxSystemSettings::GetFont(wxSYS_ANSI_FIXED_FONT);
    m_textCtrlMemoryFont.SetFamily(wxFONTFAMILY_TELETYPE);
#endif
    m_textCtrlMemory->SetFont(m_textCtrlMemoryFont);

    bSizer3->Add(m_textCtrlMemory, 1, wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND, WXC_FROM_DIP(5));

    wxBoxSizer* bSizer4 = new wxBoxSizer(wxVERTICAL);

    bSizer3->Add(bSizer4, 0, 0, WXC_FROM_DIP(5));

    m_buttonEvaluate =
        new wxButton(this, wxID_ANY, _("Evaluate"), wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, -1)), 0);
    m_buttonEvaluate->SetDefault();
    m_buttonEvaluate->SetToolTip(_("Evaluate the expression in the \"Address\" field"));

    bSizer4->Add(m_buttonEvaluate, 0, wxALL | wxEXPAND, WXC_FROM_DIP(5));

    m_buttonUpdate = new wxButton(this, wxID_ANY, _("Update"), wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, -1)), 0);
    m_buttonUpdate->SetToolTip(_("Update the memory in the main display area to apply your changes"));

    bSizer4->Add(m_buttonUpdate, 0, wxALL | wxEXPAND, WXC_FROM_DIP(5));

    SetName(wxT("MemoryViewBase"));
    SetSize(wxDLG_UNIT(this, wxSize(-1, -1)));
    if (GetSizer()) {
        GetSizer()->Fit(this);
    }
    // Connect events
    m_textCtrlExpression->Bind(wxEVT_COMMAND_TEXT_ENTER, &MemoryViewBase::OnTextEntered, this);
    m_choiceSize->Bind(wxEVT_COMMAND_CHOICE_SELECTED, &MemoryViewBase::OnMemorySize, this);
    m_choiceCols->Bind(wxEVT_COMMAND_CHOICE_SELECTED, &MemoryViewBase::OnNumberOfRows, this);
    m_textCtrlMemory->Bind(wxEVT_LEFT_DCLICK, &MemoryViewBase::OnTextDClick, this);
    m_buttonEvaluate->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &MemoryViewBase::OnEvaluate, this);
    m_buttonEvaluate->Bind(wxEVT_UPDATE_UI, &MemoryViewBase::OnEvaluateUI, this);
    m_buttonUpdate->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &MemoryViewBase::OnUpdate, this);
}

MemoryViewBase::~MemoryViewBase()
{
    m_textCtrlExpression->Unbind(wxEVT_COMMAND_TEXT_ENTER, &MemoryViewBase::OnTextEntered, this);
    m_choiceSize->Unbind(wxEVT_COMMAND_CHOICE_SELECTED, &MemoryViewBase::OnMemorySize, this);
    m_choiceCols->Unbind(wxEVT_COMMAND_CHOICE_SELECTED, &MemoryViewBase::OnNumberOfRows, this);
    m_textCtrlMemory->Unbind(wxEVT_LEFT_DCLICK, &MemoryViewBase::OnTextDClick, this);
    m_buttonEvaluate->Unbind(wxEVT_COMMAND_BUTTON_CLICKED, &MemoryViewBase::OnEvaluate, this);
    m_buttonEvaluate->Unbind(wxEVT_UPDATE_UI, &MemoryViewBase::OnEvaluateUI, this);
    m_buttonUpdate->Unbind(wxEVT_COMMAND_BUTTON_CLICKED, &MemoryViewBase::OnUpdate, this);
}
