1 /*
2 * This file is part of HexEditor plugin for Code::Blocks Studio
3 * Copyright (C) 2008-2009 Bartlomiej Swiecki
4 *
5 * HexEditor plugin is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * HexEditor pluging is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with HexEditor. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * $Revision: 10288 $
19 * $Id: SelectStoredExpressionDlg.h 10288 2015-05-15 10:58:29Z jenslody $
20 * $HeadURL: svn://svn.code.sf.net/p/codeblocks/code/branches/release-20.xx/src/plugins/contrib/HexEditor/SelectStoredExpressionDlg.h $
21 */
22 
23 #ifndef SELECTSTOREDEXPRESSIONDLG_H
24 #define SELECTSTOREDEXPRESSIONDLG_H
25 
26 #include <map>
27 
28 //(*Headers(SelectStoredExpressionDlg)
29 #include <wx/sizer.h>
30 #include <wx/button.h>
31 #include "scrollingdialog.h"
32 #include <wx/stattext.h>
33 #include <wx/textctrl.h>
34 #include <wx/timer.h>
35 #include <wx/listbox.h>
36 //*)
37 
38 
39 class SelectStoredExpressionDlg: public wxScrollingDialog
40 {
41 	public:
42 
43 		SelectStoredExpressionDlg( wxWindow* parent, const wxString& startingExpresion = wxEmptyString );
44 		virtual ~SelectStoredExpressionDlg();
45 
GetExpression()46 		wxString GetExpression() { return m_Expression; }
47 
48 	private:
49 
50         wxString m_Expression;
51 
52 		//(*Declarations(SelectStoredExpressionDlg)
53 		wxButton* Button4;
54 		wxButton* Button1;
55 		wxButton* Button2;
56 		wxButton* Button3;
57 		wxStaticText* StaticText1;
58 		wxTimer Timer1;
59 		wxListBox* m_Expressions;
60 		wxTextCtrl* m_Filter;
61 		//*)
62 
63 		//(*Identifiers(SelectStoredExpressionDlg)
64 		static const long ID_LISTBOX1;
65 		static const long ID_STATICTEXT1;
66 		static const long ID_TEXTCTRL1;
67 		static const long ID_BUTTON1;
68 		static const long ID_BUTTON2;
69 		static const long ID_BUTTON3;
70 		static const long ID_BUTTON4;
71 		static const long ID_TIMER1;
72 		//*)
73 
74 		//(*Handlers(SelectStoredExpressionDlg)
75 		void OnOkClick(wxCommandEvent& event);
76 		void OnCancelClick(wxCommandEvent& event);
77 		void OnButton1Click(wxCommandEvent& event);
78 		void Onm_ExpressionsSelect(wxCommandEvent& event);
79 		void OnButton2Click(wxCommandEvent& event);
80 		void OnButton3Click(wxCommandEvent& event);
81 		void Onm_FilterText(wxCommandEvent& event);
82 		void Onm_FilterTextEnter(wxCommandEvent& event);
83 		void OnTimer1Trigger(wxTimerEvent& event);
84 		void OnButton4Click(wxCommandEvent& event);
85 		void Onm_ExpressionsDClick(wxCommandEvent& event);
86 		//*)
87 
88 		void BuildContent(wxWindow* parent);
89 		void ReadExpressions();
90 		void StoreExpressions();
91 		void RecreateExpressionsList( const wxString& selectionHint = wxEmptyString );
92 
93         typedef std::map< wxString, wxString > CacheT;
94         CacheT m_Cache;
95         bool m_CacheChanged;
96 
97         /** \brief Helper class to identify items on expression list */
98         class ListData: public wxClientData
99         {
100             public:
101 
102                 /** \brief Ctor */
ListData(const CacheT::iterator & i)103                 inline ListData( const CacheT::iterator& i ): m_Iterator( i )
104                 {}
105 
106                 /** \brief Fetch iterator */
GetIterator()107                 inline const CacheT::iterator& GetIterator()
108                 {
109                     return m_Iterator;
110                 }
111 
112                 /** \brief Fetch key */
GetKey()113                 inline const wxString& GetKey()
114                 {
115                     return m_Iterator->first;
116                 }
117 
118                 /** \brief Fetch value */
GetValue()119                 inline const wxString& GetValue()
120                 {
121                     return m_Iterator->second;
122                 }
123 
124             private:
125 
126                 CacheT::iterator m_Iterator;        ///< \brief Item's iterator
127         };
128 
129         ListData* GetSelection();
130 
131         void AddingExpression( const wxString& defaultName, const wxString& defaultValue );
132 
133         void FilterUpdated();
134 
135         void StoreExpressionsQuery();
136 
137         static wxString GetListName( const wxString& name, const wxString& expr );
138 
139 
140 		DECLARE_EVENT_TABLE()
141 };
142 
143 #endif
144