wxMaxima
AutocompletePopup.h
Go to the documentation of this file.
1 // -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2 //
3 // Copyright (C) 2009-2015 Andrej Vodopivec <andrej.vodopivec@gmail.com>
4 // Copyright (C) 2015-2016 Gunter Königsmann <wxMaxima@physikbuch.de>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 //
21 // SPDX-License-Identifier: GPL-2.0+
22 
28 #define popid_complete_00 (wxID_HIGHEST + 1000)
29 
37 #ifndef AUTOCOMPLETEPOPUP_H
38 #define AUTOCOMPLETEPOPUP_H
39 
40 #include "precomp.h"
41 #include "Autocomplete.h"
42 #include "EditorCell.h"
43 #include <wx/combo.h>
44 #include <wx/listctrl.h>
46 #define AC_MENU_LENGTH 25
47 
48 class AutocompletePopup final : public wxListView, public wxComboPopup
49 {
50  // Return pointer to the created control
51  wxWindow *GetControl() override { return this; }
52 
53  // Translate string into a list selection
54  void SetStringValue(const wxString& s) override
55  {
56  int n = wxListView::FindItem(-1,s);
57  if (n >= 0 && n < wxListView::GetItemCount() )
58  wxListView::Select(n);
59  }
60  // Get list selection as a string
61  wxString GetStringValue() const override
62  { return (m_value >= 0) ? wxListView::GetItemText(m_value) : wxString(); }
63 
64 private:
65  struct DonePtr { AutocompletePopup*& observer; ~DonePtr() { observer = nullptr; } };
66  int m_value = -1; // current item index
68  wxString m_partial;
69 
70  wxWindow *m_parent = {};
71  const DonePtr m_doneptr;
72  wxArrayString m_completions;
73  AutoComplete *m_autocomplete = {};
74  EditorCell *m_editor = {};
76 
78  wxPoint m_position;
80  wxRect m_screenRect;
81 
82 public:
84  void SetPosition(wxPoint pos){m_position = pos;}
86  bool Create(wxWindow* parent) override;
89  void OnChar(wxKeyEvent &event);
91  void OnKeyDown(wxKeyEvent &event);
92 
101  AutocompletePopup(wxWindow *parent, EditorCell *editor, AutoComplete *autocomplete,
103 
104  void UpdateResults();
105 
106  void OnClick(wxMouseEvent &event);
107 };
108 
109 #endif // AUTOCOMPLETEPOPUP_H
Autocomplete.h
AutocompletePopup::OnChar
void OnChar(wxKeyEvent &event)
Gets the info which keycode the current keypress results in.
Definition: AutocompletePopup.cpp:336
AutocompletePopup::OnKeyDown
void OnKeyDown(wxKeyEvent &event)
Gets the info which key has been pressed with which modifier.
Definition: AutocompletePopup.cpp:90
AutocompletePopup::AutocompletePopup
AutocompletePopup(wxWindow *parent, EditorCell *editor, AutoComplete *autocomplete, AutoComplete::autoCompletionType type, AutocompletePopup **doneptr)
Definition: AutocompletePopup.cpp:316
EditorCell
Definition: EditorCell.h:57
AutocompletePopup::SetPosition
void SetPosition(wxPoint pos)
Define where the popup will appear on Create()
Definition: AutocompletePopup.h:84
AutocompletePopup::Create
bool Create(wxWindow *parent) override
Create popup control.
Definition: AutocompletePopup.cpp:254
AutoComplete
Definition: Autocomplete.h:53
AutoComplete::autoCompletionType
autoCompletionType
All types of things we can autocomplete.
Definition: Autocomplete.h:61
AutocompletePopup
Definition: AutocompletePopup.h:48
EditorCell.h