"Fossies" - the Fresh Open Source Software Archive

Member "filezilla-3.48.1/src/interface/inputdialog.cpp" (18 May 2020, 1785 Bytes) of package /linux/misc/FileZilla_3.48.1_src.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "inputdialog.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 3.48.0_vs_3.48.1.

    1 #include <filezilla.h>
    2 #include "inputdialog.h"
    3 #include "textctrlex.h"
    4 
    5 bool CInputDialog::Create(wxWindow* parent, wxString const& title, wxString const& text, int max_len, bool password)
    6 {
    7     SetParent(parent);
    8 
    9     if (!wxDialogEx::Create(parent, -1, title)) {
   10         return false;
   11     }
   12 
   13     auto& lay = layout();
   14     auto * main = lay.createMain(this, 1);
   15 
   16     main->Add(new wxStaticText(this, -1, text));
   17 
   18     textCtrl_ = new wxTextCtrlEx(this, -1, wxString(), wxDefaultPosition, wxDefaultSize, password ? wxTE_PASSWORD : 0);
   19 
   20     main->Add(textCtrl_, lay.grow)->SetMinSize(lay.dlgUnits(150), -1);
   21     if (max_len != -1) {
   22         textCtrl_->SetMaxLength(max_len);
   23     }
   24 
   25     auto * buttons = lay.createButtonSizer(this, main, true);
   26 
   27     auto ok = new wxButton(this, wxID_OK, _("&OK"));
   28     ok->SetDefault();
   29     buttons->AddButton(ok);
   30 
   31     auto cancel = new wxButton(this, wxID_CANCEL, _("Cancel"));
   32     buttons->AddButton(cancel);
   33     buttons->Realize();
   34 
   35     auto onButton = [this](wxEvent& evt) {EndModal(evt.GetId()); };
   36     ok->Bind(wxEVT_BUTTON, onButton);
   37     cancel->Bind(wxEVT_BUTTON, onButton);
   38 
   39     GetSizer()->Fit(this);
   40 
   41     WrapRecursive(this, 2.0);
   42 
   43     textCtrl_->SetFocus();
   44     ok->Disable();
   45 
   46     textCtrl_->Bind(wxEVT_TEXT, [this, ok](wxEvent const&){
   47         ok->Enable(allowEmpty_ || !textCtrl_->GetValue().empty());
   48     });
   49 
   50     return true;
   51 }
   52 
   53 void CInputDialog::AllowEmpty(bool allowEmpty)
   54 {
   55     allowEmpty_ = allowEmpty;
   56     XRCCTRL(*this, "wxID_OK", wxButton)->Enable(allowEmpty_ ? true : (!textCtrl_->GetValue().empty()));
   57 }
   58 
   59 void CInputDialog::SetValue(wxString const& value)
   60 {
   61     textCtrl_->SetValue(value);
   62 }
   63 
   64 wxString CInputDialog::GetValue() const
   65 {
   66     return textCtrl_->GetValue();
   67 }
   68 
   69 bool CInputDialog::SelectText(int start, int end)
   70 {
   71 #ifdef __WXGTK__
   72     Show();
   73 #endif
   74     textCtrl_->SetFocus();
   75     textCtrl_->SetSelection(start, end);
   76     return true;
   77 }