wxMaxima
Loading...
Searching...
No Matches
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
36#ifndef AUTOCOMPLETEPOPUP_H
37#define AUTOCOMPLETEPOPUP_H
38
39#include "precomp.h"
40#include "Autocomplete.h"
41#include "cells/EditorCell.h"
42#include <wx/combo.h>
43#include <wx/listctrl.h>
44#include <vector>
45
46class AutocompletePopup final : public wxListView, public wxComboPopup
47{
48 // Return pointer to the created control
49 wxWindow *GetControl() override { return this; }
50
51 // Translate string into a list selection
52 void SetStringValue(const wxString& s) override
53 {
54 int n = wxListView::FindItem(-1, s);
55 if (n >= 0 && n < wxListView::GetItemCount() )
56 wxListView::Select(n);
57 }
58 // Get list selection as a string
59 wxString GetStringValue() const override
60 { return (m_value >= 0) ? wxListView::GetItemText(m_value) : wxString(); }
61
62private:
63 struct DonePtr { AutocompletePopup*& observer; ~DonePtr() { observer = nullptr; } };
64 int m_value = -1; // current item index
66 wxString m_partial;
67
68 wxWindow *m_parent = {};
69 const DonePtr m_doneptr;
70 std::vector<wxString> m_completions;
71 AutoComplete *m_autocomplete = {};
72 EditorCell *m_editor = {};
74
76 wxPoint m_position;
78 wxRect m_screenRect;
79
80public:
82 void SetPosition(wxPoint pos){m_position = pos;}
84 bool Create(wxWindow* parent) override;
85 virtual ~AutocompletePopup();
87 void OnChar(wxKeyEvent &event);
89 void OnKeyDown(wxKeyEvent &event);
90
99 AutocompletePopup(wxWindow *parent, EditorCell *editor, AutoComplete *autocomplete,
101
102 void UpdateResults();
103
104 void OnClick(wxMouseEvent &event);
105};
106
107#endif // AUTOCOMPLETEPOPUP_H
This file declares the class AutoComplete.
This file contains the definition of the class EditorCell.
Definition: Autocomplete.h:60
autoCompletionType
All types of things we can autocomplete.
Definition: Autocomplete.h:67
Definition: AutocompletePopup.h:47
void OnChar(wxKeyEvent &event)
Gets the info which keycode the current keypress results in.
Definition: AutocompletePopup.cpp:297
void SetPosition(wxPoint pos)
Define where the popup will appear on Create()
Definition: AutocompletePopup.h:82
bool Create(wxWindow *parent) override
Create popup control.
Definition: AutocompletePopup.cpp:227
void OnKeyDown(wxKeyEvent &event)
Gets the info which key has been pressed with which modifier.
Definition: AutocompletePopup.cpp:86
This class defines what the user sees as input cell.
Definition: EditorCell.h:59