File: inputline.h

package info (click to toggle)
fityk 1.3.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,772 kB
  • sloc: cpp: 34,595; ansic: 4,676; python: 963; makefile: 384; sh: 119; xml: 91; java: 31; ruby: 27; perl: 25
file content (48 lines) | stat: -rw-r--r-- 1,507 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Purpose: input line with history (wxTextCtrl+wxSpinButton)
// Copyright: (c) 2007 Marcin Wojdyr
// Licence: wxWidgets licence, or (at your option) GPL ver. 2+

#ifndef FITYK_WX_INPUTLINE_H_
#define FITYK_WX_INPUTLINE_H_

#include <wx/spinctrl.h>

class InputLineObserver
{
public:
    virtual ~InputLineObserver() {}
    virtual void ProcessInputLine(const wxString& line) = 0;
};

class InputLine : public wxPanel
{
public:
    /// receiver will be called when Enter is pressed
    InputLine(wxWindow *parent, wxWindowID winid,
              InputLineObserver* observer, wxString const& hist_file_);
    ~InputLine();
    /// intended for use in EVT_KEY_DOWN handlers of other controls,
    /// to change focus and redirect keyboard input to text input
    void RedirectKeyPress(wxKeyEvent& event);
    void SetValue(const wxString& value) { m_text->SetValue(value); }
protected:
    wxTextCtrl *m_text;
#ifndef __WXGTK3__
    wxSpinButton *m_button;
#endif
    wxArrayString m_history;
    int m_hpos; // current item in m_history
    InputLineObserver* m_observer;
    wxString const hist_file;

    void OnSpinButton(wxSpinEvent &event)
        { HistoryMove(m_history.GetCount() - 1 - event.GetPosition(), false); }
    void OnInputLine(const wxString& line);
    void HistoryMove(int n, bool relative);
    void GoToHistoryEnd();
    void OnKeyDownAtText (wxKeyEvent& event);
    void OnKeyDownAtSpinButton (wxKeyEvent& event);
    wxSize DoGetBestSize() const;
};

#endif // FITYK_WX_INPUTLINE_H_