Debian Codegraph @

CodeLite/wxCodeCompletionBoxEntry.hpp

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // Copyright : (C) 2015 Eran Ifrah
5 // File name : wxCodeCompletionBoxEntry.h
6 //
7 // -------------------------------------------------------------------------
8 // A
9 // _____ _ _ _ _
10 // / __ \ | | | | (_) |
11 // | / \/ ___ __| | ___| | _| |_ ___
12 // | | / _ \ / _ |/ _ \ | | | __/ _ )
13 // | \__/\ (_) | (_| | __/ |___| | || __/
14 // \____/\___/ \__,_|\___\_____/_|\__\___|
15 //
16 // F i l e
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 //////////////////////////////////////////////////////////////////////////////
24 //////////////////////////////////////////////////////////////////////////////
25
26 #ifndef WXCODECOMPLETIONBOXENTRY_H
27 #define WXCODECOMPLETIONBOXENTRY_H
28
29 #include <wx/clntdata.h>
30 #include <wx/sharedptr.h>
31 #include <vector>
32 #include "codelite_exports.h"
33 #include <wx/gdicmn.h>
34 #include <wx/string.h>
35 #include "entry.h" // TagEntryPtr
36 #include <wx/bitmap.h>
37 #include "LSP/basic_types.h"
38
39 class wxStyledTextCtrl;
40 class WXDLLIMPEXP_CL wxCodeCompletionBoxEntry
41 {
42 public:
43 enum eFlags {
44 kIsFunction = (1 << 0),
45 kIsTemplate = (1 << 1),
46 kIsSnippet = (1 << 2),
47 kIsTemplateFunction = (1 << 3),
48 kTriggerInclude = (1 << 4),
49 };
50
51 protected:
52 wxString m_text;
53 wxString m_comment;
54 wxString m_insertText;
55 LSP::Range m_insertRage;
56 int m_imgIndex;
57 wxClientData* m_clientData;
58 wxRect m_itemRect;
59 friend class wxCodeCompletionBox;
60 TagEntryPtr m_tag; // Internal
61 int m_weight;
62 wxBitmap m_alternateBitmap;
63 wxString m_signature; // when IsFunction() is true
64 size_t m_flags = 0;
65
66 protected:
67 void EnableFlag(bool b, eFlags f)
68 {
69 if(b) {
70 this->m_flags |= f;
71 } else {
72 this->m_flags &= ~f;
73 }
74 }
75
76 bool HasFlag(eFlags f) const { return this->m_flags & f; }
77
78 public:
79 typedef wxSharedPtr<wxCodeCompletionBoxEntry> Ptr_t;
80 typedef std::vector<wxCodeCompletionBoxEntry::Ptr_t> Vec_t;
81
82 public:
83 wxCodeCompletionBoxEntry(const wxString& text, int imgId = wxNOT_FOUND, wxClientData* userData = NULL)
84 : m_text(text)
85 , m_insertText(text)
86 , m_imgIndex(imgId)
87 , m_clientData(userData)
88 , m_weight(0)
89 {
90 }
91
92 wxCodeCompletionBoxEntry(const wxString& text, const wxBitmap& bmp, wxClientData* userData = NULL)
93 : m_text(text)
94 , m_insertText(text)
95 , m_imgIndex(wxNOT_FOUND)
96 , m_clientData(userData)
97 , m_weight(0)
98 , m_alternateBitmap(bmp)
99 {
100 }
101
102 wxCodeCompletionBoxEntry(const wxString& text, const wxBitmap& bmp, const wxString& helpText,
103 wxClientData* userData = NULL)
104 : m_text(text)
105 , m_comment(helpText)
106 , m_insertText(text)
107 , m_imgIndex(wxNOT_FOUND)
108 , m_clientData(userData)
109 , m_weight(0)
110 , m_alternateBitmap(bmp)
111 {
112 }
113
114 virtual ~wxCodeCompletionBoxEntry()
115 {
116 wxDELETE(m_clientData);
117 m_imgIndex = wxNOT_FOUND;
118 m_text.Clear();
119 }
120
121 void SetInsertRange(const LSP::Range& insertRage) { this->m_insertRage = insertRage; }
122 void SetInsertText(const wxString& insertText) { this->m_insertText = insertText; }
123 const LSP::Range& GetInsertRange() const { return m_insertRage; }
124 const wxString& GetInsertText() const { return m_insertText; }
125
126 void SetIsFunction(bool isFunction) { EnableFlag(isFunction, kIsFunction); }
127 bool IsFunction() const { return HasFlag(kIsFunction); }
128
129 void SetIsTemplateFunction(bool isTemplateFunction) { EnableFlag(isTemplateFunction, kIsTemplateFunction); }
130 bool IsTemplateFunction() const { return HasFlag(kIsTemplateFunction); }
131
132 void SetIsSnippet(bool isSnippet) { EnableFlag(isSnippet, kIsSnippet); }
133 bool IsSnippet() const { return HasFlag(kIsSnippet); }
134
135 void SetSignature(const wxString& signature) { this->m_signature = signature; }
136 const wxString& GetSignature() const { return m_signature; }
137
138 void SetTriggerInclude(bool isTriggerInclude) { EnableFlag(isTriggerInclude, kTriggerInclude); }
139 bool IsTriggerInclude() const { return HasFlag(kTriggerInclude); }
140
141 /**
142 * @brief return the associated tag (might be null)
143 */
144 TagEntryPtr GetTag() const { return m_tag; }
145
146 /**
147 * @brief helper method for allocating wxCodeCompletionBoxEntry::Ptr
148 */
149 static wxCodeCompletionBoxEntry::Ptr_t New(const wxString& text, int imgId = wxNOT_FOUND,
150 wxClientData* userData = NULL)
151 {
152 wxCodeCompletionBoxEntry::Ptr_t pEntry(new wxCodeCompletionBoxEntry(text, imgId, userData));
153 return pEntry;
154 }
155
156 /**
157 * @brief helper method for allocating wxCodeCompletionBoxEntry::Ptr
158 */
159 static wxCodeCompletionBoxEntry::Ptr_t New(const wxString& text, const wxBitmap& bmp, wxClientData* userData = NULL)
160 {
161 wxCodeCompletionBoxEntry::Ptr_t pEntry(new wxCodeCompletionBoxEntry(text, bmp, userData));
162 return pEntry;
163 }
164
165 /**
166 * @brief helper method for allocating wxCodeCompletionBoxEntry::Ptr
167 */
168 static wxCodeCompletionBoxEntry::Ptr_t New(const wxString& text, const wxString& helpText, const wxBitmap& bmp,
169 wxClientData* userData = NULL)
170 {
171 wxCodeCompletionBoxEntry::Ptr_t pEntry(new wxCodeCompletionBoxEntry(text, bmp, helpText, userData));
172 return pEntry;
173 }
174
175 void SetWeight(int weight) { this->m_weight = weight; }
176 int GetWeight() const { return m_weight; }
177 void SetImgIndex(int imgIndex) { this->m_imgIndex = imgIndex; }
178 void SetText(const wxString& text) { this->m_text = text; }
179 int GetImgIndex() const { return m_imgIndex; }
180 const wxString& GetText() const { return m_text; }
181 /**
182 * @brief set client data, deleting the old client data
183 * @param clientData
184 */
185 void SetClientData(wxClientData* clientData)
186 {
187 wxDELETE(this->m_clientData);
188 this->m_clientData = clientData;
189 }
190 wxClientData* GetClientData() { return m_clientData; }
191 void SetComment(const wxString& comment) { this->m_comment = comment; }
192 const wxString& GetComment() const { return m_comment; }
193 void SetAlternateBitmap(const wxBitmap& alternateBitmap) { this->m_alternateBitmap = alternateBitmap; }
194 const wxBitmap& GetAlternateBitmap() const { return m_alternateBitmap; }
195 };
196
197 #endif // WXCODECOMPLETIONBOXENTRY_H