Exemplo n.º 1
0
void NumValidatorTestCase::TransferFloat()
{
    // We need a locale with point as decimal separator.
    wxLocale loc(wxLANGUAGE_ENGLISH_UK, wxLOCALE_DONT_LOAD_DEFAULT);

    float value = 0;
    wxFloatingPointValidator<float> valFloat(3, &value);
    valFloat.SetWindow(m_text);

    CPPUNIT_ASSERT( valFloat.TransferToWindow() );
    CPPUNIT_ASSERT_EQUAL( "0.000", m_text->GetValue() );

    value = 1.234f;
    CPPUNIT_ASSERT( valFloat.TransferToWindow() );
    CPPUNIT_ASSERT_EQUAL( "1.234", m_text->GetValue() );

    value = 1.2345678f;
    CPPUNIT_ASSERT( valFloat.TransferToWindow() );
    CPPUNIT_ASSERT_EQUAL( "1.235", m_text->GetValue() );


    m_text->ChangeValue("foobar");
    CPPUNIT_ASSERT( !valFloat.TransferFromWindow() );

    m_text->ChangeValue("-234.567");
    CPPUNIT_ASSERT( valFloat.TransferFromWindow() );
    CPPUNIT_ASSERT_EQUAL( -234.567f, value );

    m_text->Clear();
    CPPUNIT_ASSERT( !valFloat.TransferFromWindow() );
}
Exemplo n.º 2
0
void NumValidatorTestCase::TransferInt()
{
    int value = 0;
    wxIntegerValidator<int> valInt(&value);
    valInt.SetWindow(m_text);

    CPPUNIT_ASSERT( valInt.TransferToWindow() );
    CPPUNIT_ASSERT_EQUAL( "0", m_text->GetValue() );

    value = 17;
    CPPUNIT_ASSERT( valInt.TransferToWindow() );
    CPPUNIT_ASSERT_EQUAL( "17", m_text->GetValue() );


    m_text->ChangeValue("foobar");
    CPPUNIT_ASSERT( !valInt.TransferFromWindow() );

    m_text->ChangeValue("-234");
    CPPUNIT_ASSERT( valInt.TransferFromWindow() );
    CPPUNIT_ASSERT_EQUAL( -234, value );

    m_text->ChangeValue("9223372036854775808"); // == LLONG_MAX + 1
    CPPUNIT_ASSERT( !valInt.TransferFromWindow() );

    m_text->Clear();
    CPPUNIT_ASSERT( !valInt.TransferFromWindow() );
}
Exemplo n.º 3
0
void NumValidatorTestCase::TransferUnsigned()
{
    unsigned value = 0;
    wxIntegerValidator<unsigned> valUnsigned(&value);
    valUnsigned.SetWindow(m_text);

    CPPUNIT_ASSERT( valUnsigned.TransferToWindow() );
    CPPUNIT_ASSERT_EQUAL( "0", m_text->GetValue() );

    value = 17;
    CPPUNIT_ASSERT( valUnsigned.TransferToWindow() );
    CPPUNIT_ASSERT_EQUAL( "17", m_text->GetValue() );


    m_text->ChangeValue("foobar");
    CPPUNIT_ASSERT( !valUnsigned.TransferFromWindow() );

    m_text->ChangeValue("-234");
    CPPUNIT_ASSERT( !valUnsigned.TransferFromWindow() );

    m_text->ChangeValue("234");
    CPPUNIT_ASSERT( valUnsigned.TransferFromWindow() );
    CPPUNIT_ASSERT_EQUAL( 234, value );

    m_text->ChangeValue("18446744073709551616"); // == ULLONG_MAX + 1
    CPPUNIT_ASSERT( !valUnsigned.TransferFromWindow() );

    m_text->Clear();
    CPPUNIT_ASSERT( !valUnsigned.TransferFromWindow() );
}
Exemplo n.º 4
0
void MyFrame::OnRun(wxCommandEvent &event) {
    ostringstream stream;

    text->Clear();

    unique_ptr<eph::nominate_abstract> nsl;

    switch (methods->GetCurrentSelection()) {
        case 0:
            nsl = make_unique<eph::nominate_pal>(stream, lines);
            break;
        case 1:
            nsl = make_unique<eph::nominate_sdv_lpe>(stream, lines);
            break;
        case 2:
            nsl = make_unique<eph::nominate_sdv_lpe>(stream, lines, eph::ENABLE_SL::YES);
            break;
    }

    auto result = nsl->nominate(finalists->GetCurrentSelection()+1, noms_per_ballot->GetCurrentSelection()+1);

    if (verbose->GetValue()) {
        text->AppendText(stream.str());
    }
    text->AppendText(result);
}
Exemplo n.º 5
0
    MainFrame(const wxString& title) {
        wxXmlResource::Get()->LoadFrame(this, NULL, "Frame1");

        m_buttonFindAll = XRCCTRL(*this, "m_buttonFindAll", wxButton);
        m_textCtrlRegex = XRCCTRL(*this, "m_textCtrlRegex", wxTextCtrl);
        m_textCtrlString = XRCCTRL(*this, "m_textCtrlString", wxTextCtrl);
        m_textCtrlFindAll = XRCCTRL(*this, "m_textCtrlFindAll", wxTextCtrl);
        m_textCtrlRegex->Bind(wxEVT_TEXT, [=](wxCommandEvent &event){
            std::wstring a = m_textCtrlRegex->GetValue();
            auto R = re::compile(a);
            if (R){
                m_textCtrlRegex->SetBackgroundColour(wxColor(0,255,0));
                m_textCtrlRegex->Refresh();
                m_textCtrlFindAll->Clear();
                m_textCtrlFindAll->Refresh();
            }
            else{
                m_textCtrlRegex->SetBackgroundColour(wxColor(255, 0, 0));
                m_textCtrlRegex->Refresh();
                m_textCtrlFindAll->Clear();
                m_textCtrlFindAll->AppendText(std::to_string(re::getlasterror()));
                m_textCtrlFindAll->AppendText("\n");
                m_textCtrlFindAll->AppendText(re::getlasterrorstr());
                m_textCtrlFindAll->Refresh();
            }
        }
        );
        //------------------------------------------------------------------------------
        m_buttonFindAll->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [=](wxCommandEvent &event){
            m_textCtrlFindAll->Clear();
            std::wstring a = m_textCtrlRegex->GetValue();
            auto R = re::compile(a);
            if (R){
                std::wstring s = m_textCtrlString->GetValue();
                auto v = R->findall(s);
                for (auto i = v.begin(); i < v.end(); i++){
                    m_textCtrlFindAll->AppendText(*i);
                    m_textCtrlFindAll->AppendText("\n");
                }
            }
            m_textCtrlFindAll->Refresh();

        });
        //------------------------------------------------------------------------------

    }
Exemplo n.º 6
0
void MyFrame::OnWriteClipboardContents(wxCommandEvent& WXUNUSED(event))
{
    if (wxTheClipboard->Open())
    {
        if (wxTheClipboard->IsSupported( wxDF_UNICODETEXT ))
        {
            wxTextDataObject data;
            wxTheClipboard->GetData( data );
            m_textctrl->Clear();
            m_textctrl->SetValue( data.GetText() );

        }
        wxTheClipboard->Close();
    }
}
Exemplo n.º 7
0
void MyFrame::OnOpen(wxCommandEvent & WXUNUSED(event)) {
    wxFileDialog dialog(this, wxEmptyString, wxEmptyString, wxEmptyString, wxEmptyString,
                        wxFD_OPEN | wxFD_FILE_MUST_EXIST);
    if (dialog.ShowModal() == wxID_OK) {
        wxString filename(dialog.GetPath());

        wxTextFile text_file(filename);
        if (!text_file.Open(wxConvUTF8)) {
            return;
        }

        grid->EnableEditing(false);
        if (text_file.GetLineCount() > grid->GetNumberRows()) {
            grid->AppendRows(text_file.GetLineCount() - grid->GetNumberRows());

        } else if (text_file.GetLineCount() < grid->GetNumberRows()) {
            grid->DeleteRows(text_file.GetLineCount(), grid->GetNumberRows() - text_file.GetLineCount());
        }

        grid->ClearGrid();

        for (int row = 0; row < text_file.GetLineCount(); ++row) {
            wxStringTokenizer tokenizer(text_file[row], L",");
            for (int col = 0; tokenizer.HasMoreTokens() && col < grid->GetNumberCols(); ++col) {
                wxString token = tokenizer.GetNextToken();

                grid->SetCellValue(row, col, token);
            }
        }
        grid->AutoSize();

        text->Clear();
        lines.clear();

        for (int row = 0; row < text_file.GetLineCount(); ++row) {
            lines.push_back(text_file[row]);
        }

        text_file.Close();

        topsizer->Layout();
        SetStatusText(wxFileName(filename).GetFullName());
    }
}
Exemplo n.º 8
0
void OutputWinConfDlg::show_preview()
{
    const wxColour& output = ow_->text_color_[UserInterface::kNormal];
    const wxColour& input = ow_->text_color_[UserInterface::kInput];
    const wxColour& quote = ow_->text_color_[UserInterface::kQuoted];
    const wxColour& warning = ow_->text_color_[UserInterface::kWarning];

    preview_->Clear();
    preview_->SetBackgroundColour(ow_->bg_color_);
    preview_->SetDefaultStyle(ow_->GetDefaultStyle());
    preview_->SetDefaultStyle(wxTextAttr(output));
    preview_->AppendText(wxT("\nsettings preview\n\n"));
    preview_->SetDefaultStyle(wxTextAttr(input));
    preview_->AppendText(wxT("=-> i pi\n"));
    preview_->SetDefaultStyle(wxTextAttr(output));
    preview_->AppendText(wxT("3.14159\n"));
    preview_->SetDefaultStyle(wxTextAttr(input));
    preview_->AppendText(wxT("=-> c < file.fit\n"));
    preview_->SetDefaultStyle(wxTextAttr(quote));
    preview_->AppendText(wxT("1> bleh in file\n"));
    preview_->SetDefaultStyle(wxTextAttr(warning));
    preview_->AppendText(wxT("Syntax error.\n"));
}
Exemplo n.º 9
0
void MyFrame::OnClear(wxCommandEvent& WXUNUSED(event))
{
    m_txtctrl->Clear();
}
Exemplo n.º 10
0
void MyFrame::OnClearLog( wxCommandEvent& WXUNUSED(event) )
{
    m_log->Clear();
}
Exemplo n.º 11
0
void MyFrame::OnQuery(wxCommandEvent& WXUNUSED(event))
{
    m_textCtrl->Clear();
    IAccessible* accessibleFrame = NULL;
    if (S_OK != AccessibleObjectFromWindow((HWND) GetHWND(), OBJID_CLIENT,
        IID_IAccessible, (void**) & accessibleFrame))
    {
        Log(wxT("Could not get object."));
        return;
    }
    if (accessibleFrame)
    {
        //Log(wxT("Got an IAccessible for the frame."));
        LogObject(0, accessibleFrame);
        Log(wxT("Checking children using AccessibleChildren()..."));

        // Now check the AccessibleChildren function works OK
        long childCount = 0;
        if (S_OK != accessibleFrame->get_accChildCount(& childCount))
        {
            Log(wxT("Could not get number of children."));
            accessibleFrame->Release();
            return;
        }
        else if (childCount == 0)
        {
            Log(wxT("No children."));
            accessibleFrame->Release();
            return;
        }


        long obtained = 0;
        VARIANT *var = new VARIANT[childCount];
        int i;
        for (i = 0; i < childCount; i++)
        {
            VariantInit(& (var[i]));
            var[i].vt = VT_DISPATCH;
        }

        if (S_OK == AccessibleChildren(accessibleFrame, 0, childCount, var, &obtained))
        {
            for (i = 0; i < childCount; i++)
            {
                IAccessible* childAccessible = NULL;
                if (var[i].pdispVal)
                {
                    if (var[i].pdispVal->QueryInterface(IID_IAccessible, (LPVOID*) & childAccessible) == S_OK)
                    {
                        var[i].pdispVal->Release();

                        wxString name, role;
                        GetInfo(childAccessible, 0, name, role);
                        wxString str;
                        str.Printf(wxT("Found child %s/%s"), name.c_str(), role.c_str());
                        Log(str);
                        childAccessible->Release();
                    }
                    else
                    {
                        var[i].pdispVal->Release();
                    }
                }
            }
        }
        else
        {
            Log(wxT("AccessibleChildren failed."));
        }
        delete[] var;


        accessibleFrame->Release();
    }
}