~efargaspro/+junk/codeblocks-16.01-release

« back to all changes in this revision

Viewing changes to src/plugins/contrib/codesnippets/codesnippets.h

  • Committer: damienlmoore at gmail
  • Date: 2016-02-02 02:43:22 UTC
  • Revision ID: damienlmoore@gmail.com-20160202024322-yql5qmtbwdyamdwd
Code::BlocksĀ 16.01

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        This file is part of Code Snippets, a plugin for Code::Blocks
 
3
        Copyright (C) 2006 Arto Jonsson
 
4
 
 
5
        This program is free software; you can redistribute it and/or
 
6
        modify it under the terms of the GNU General Public License
 
7
        as published by the Free Software Foundation; either version 2
 
8
        of the License, or (at your option) any later version.
 
9
 
 
10
        This program 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 this program; if not, write to the Free Software
 
17
        Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
18
*/
 
19
 
 
20
#ifndef CODESNIPPETS_H_INCLUDED
 
21
#define CODESNIPPETS_H_INCLUDED
 
22
 
 
23
#include <wx/dnd.h>
 
24
 
 
25
#include "cbplugin.h" // for "class cbPlugin"
 
26
//#include "wxaui/manager.h"
 
27
#include "snippetsconfig.h"
 
28
 
 
29
 
 
30
class CodeSnippetsWindow;
 
31
 
 
32
// ----------------------------------------------------------------------------
 
33
class CodeSnippets : public cbPlugin
 
34
// ----------------------------------------------------------------------------
 
35
{
 
36
    friend class wxMyFileDropTarget;
 
37
    friend class DropTargets;
 
38
 
 
39
        public:
 
40
                /** Constructor. */
 
41
                CodeSnippets();
 
42
                /** Destructor. */
 
43
                ~CodeSnippets();
 
44
 
 
45
                /** Invoke configuration dialog. */
 
46
                int Configure() { return 0; }
 
47
 
 
48
                /** Return the plugin's configuration priority.
 
49
                 * This is a number (default is 50) that is used to sort plugins
 
50
                 * in configuration dialogs. Lower numbers mean the plugin's
 
51
                 * configuration is put higher in the list.
 
52
                */
 
53
                int GetConfigurationPriority() const { return 50; }
 
54
 
 
55
                /** Return the configuration group for this plugin. Default is cgUnknown.
 
56
                 * Notice that you can logically AND more than one configuration groups,
 
57
                 * so you could set it, for example, as "cgCompiler | cgContribPlugin".
 
58
                */
 
59
                int GetConfigurationGroup() const { return cgContribPlugin; }
 
60
 
 
61
                /** Return plugin's configuration panel.
 
62
                  * @param parent The parent window.
 
63
                  * @return A pointer to the plugin's cbConfigurationPanel. It is deleted by the caller.
 
64
                  */
 
65
                cbConfigurationPanel* GetConfigurationPanel(wxWindow* parent){ return 0; }
 
66
 
 
67
                /** Return plugin's configuration panel for projects.
 
68
                 * The panel returned from this function will be added in the project's
 
69
                 * configuration dialog.
 
70
                 * @param parent The parent window.
 
71
                 * @param project The project that is being edited.
 
72
                 * @return A pointer to the plugin's cbConfigurationPanel. It is deleted by the caller.
 
73
                */
 
74
                cbConfigurationPanel* GetProjectConfigurationPanel(wxWindow* parent, cbProject* project){ return 0; }
 
75
 
 
76
                /** This method is called by Code::Blocks and is used by the plugin
 
77
                 * to add any menu items it needs on Code::Blocks's menu bar.\n
 
78
                 * It is a pure virtual method that needs to be implemented by all
 
79
                 * plugins. If the plugin does not need to add items on the menu,
 
80
                 * just do nothing ;)
 
81
                 * @param menuBar the wxMenuBar to create items in
 
82
                */
 
83
                void BuildMenu(wxMenuBar* menuBar);
 
84
 
 
85
                /** This method is called by Code::Blocks core modules (EditorManager,
 
86
                 * ProjectManager etc) and is used by the plugin to add any menu
 
87
                 * items it needs in the module's popup menu. For example, when
 
88
                 * the user right-clicks on a project file in the project tree,
 
89
                 * ProjectManager prepares a popup menu to display with context
 
90
                 * sensitive options for that file. Before it displays this popup
 
91
                 * menu, it asks all attached plugins (by asking PluginManager to call
 
92
                 * this method), if they need to add any entries
 
93
                 * in that menu. This method is called.\n
 
94
                 * If the plugin does not need to add items in the menu,
 
95
                 * just do nothing ;)
 
96
                 * @param type the module that's preparing a popup menu
 
97
                 * @param menu pointer to the popup menu
 
98
                 * @param data pointer to FileTreeData object (to access/modify the file tree)
 
99
                */
 
100
                void BuildModuleMenu(const ModuleType type, wxMenu* menu, const FileTreeData* data = 0){}
 
101
 
 
102
                /** This method is called by Code::Blocks and is used by the plugin
 
103
                 * to add any toolbar items it needs on Code::Blocks's toolbar.\n
 
104
                 * It is a pure virtual method that needs to be implemented by all
 
105
                 * plugins. If the plugin does not need to add items on the toolbar,
 
106
                 * just do nothing ;)
 
107
                 * @param toolBar the wxToolBar to create items on
 
108
                 * @return The plugin should return true if it needed the toolbar, false if not
 
109
                */
 
110
                bool BuildToolBar(wxToolBar* toolBar){ return false; }
 
111
        protected:
 
112
                /** Any descendent plugin should override this virtual method and
 
113
                 * perform any necessary initialization. This method is called by
 
114
                 * Code::Blocks (PluginManager actually) when the plugin has been
 
115
                 * loaded and should attach in Code::Blocks. When Code::Blocks
 
116
                 * starts up, it finds and <em>loads</em> all plugins but <em>does
 
117
                 * not</em> activate (attaches) them. It then activates all plugins
 
118
                 * that the user has selected to be activated on start-up.\n
 
119
                 * This means that a plugin might be loaded but <b>not</b> activated...\n
 
120
                 * Think of this method as the actual constructor...
 
121
                */
 
122
                void OnAttach();
 
123
 
 
124
                /** Any descendent plugin should override this virtual method and
 
125
                 * perform any necessary de-initialization. This method is called by
 
126
                 * Code::Blocks (PluginManager actually) when the plugin has been
 
127
                 * loaded, attached and should de-attach from Code::Blocks.\n
 
128
                 * Think of this method as the actual destructor...
 
129
                 * @param appShutDown If true, the application is shutting down. In this
 
130
                 *         case *don't* use Manager::Get()->Get...() functions or the
 
131
                 *         behaviour is undefined...
 
132
                */
 
133
                void OnRelease(bool appShutDown);
 
134
        void OnDisable(bool appShutDown);
 
135
 
 
136
                // ---
 
137
                void SetSnippetsWindow(CodeSnippetsWindow* p);
 
138
                CodeSnippetsWindow*  GetSnippetsWindow(){return GetConfig()->GetSnippetsWindow();}
 
139
        //-void OnTreeDragEvent(wxTreeEvent& event); 2011/01/9
 
140
        //-void OnPrjTreeDragEvent(wxMouseEvent& event);
 
141
 
 
142
        private:
 
143
 
 
144
        void CreateSnippetWindow();
 
145
        void SetTreeCtrlHandler(wxWindow *p, WXTYPE eventType);
 
146
        void RemoveTreeCtrlHandler(wxWindow *p, WXTYPE eventType);
 
147
        bool GetTreeSelectionData(const wxTreeCtrl* pTree, const wxTreeItemId itemID, wxString& selString);
 
148
        wxArrayString* TextToFilenames(const wxString& string);
 
149
        bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& files);
 
150
        wxString FindAppPath(const wxString& argv0, const wxString& cwd, const wxString& appVariableName);
 
151
        void CloseDockWindow();
 
152
        wxWindow* FindOpenFilesListWindow();
 
153
 
 
154
                void OnViewSnippets(wxCommandEvent& event);
 
155
                void OnUpdateUI(wxUpdateUIEvent& event);
 
156
                void OnActivate(wxActivateEvent& event);
 
157
        void OnWindowDestroy(wxEvent& event);
 
158
                void OnIdle(wxIdleEvent& event);
 
159
                void OnSwitchViewLayout(CodeBlocksLayoutEvent& event);
 
160
                void OnSwitchedViewLayout(CodeBlocksLayoutEvent& event);
 
161
                void OnDockWindowVisability(CodeBlocksDockEvent& event);
 
162
        void OnAppStartupDone(CodeBlocksEvent& event);
 
163
        void OnAppStartShutdown(CodeBlocksEvent& event);
 
164
 
 
165
        void OnPrjTreeMouseMotionEvent(wxMouseEvent& event);
 
166
        void OnPrjTreeMouseLeftDownEvent(wxMouseEvent& event);
 
167
        void OnPrjTreeMouseLeftUpEvent(wxMouseEvent& event);
 
168
        void DoPrjTreeExternalDrag(wxTreeCtrl* pTree);
 
169
        void OnPrjTreeMouseLeaveWindowEvent(wxMouseEvent& event);
 
170
        void SendMouseLeftUp(const wxWindow* pWin, const int mouseX, const int mouseY);
 
171
        void MSW_MouseMove(int x, int y );
 
172
 
 
173
                wxWindow*       m_pAppWin;
 
174
        ProjectManager* m_pProjectMgr;
 
175
        wxTreeCtrl*     m_pMgtTreeBeginDrag;
 
176
        //-wxPoint         m_TreeMousePosn;
 
177
        wxTreeItemId    m_TreeItemId;
 
178
        wxString        m_TreeText;
 
179
        int             m_nOnActivateBusy;
 
180
        wxFile          m_PidTmpFile;
 
181
 
 
182
        bool            m_bMouseCtrlKeyDown;
 
183
        bool            m_bMouseLeftKeyDown;
 
184
        bool            m_bMouseIsDragging;
 
185
        bool            m_bDragCursorOn;
 
186
        wxCursor*       m_pDragCursor;
 
187
        wxCursor        m_oldCursor;
 
188
        int             m_MouseDownX, m_MouseDownY;
 
189
        int             m_MouseUpX, m_MouseUpY;
 
190
        wxTreeItemId    m_prjTreeItemAtKeyUp, m_prjTreeItemAtKeyDown;
 
191
                bool            m_bMouseExitedWindow;
 
192
        bool            m_bBeginInternalDrag;
 
193
 
 
194
                DECLARE_EVENT_TABLE();
 
195
 
 
196
}; //class CodeSnippets
 
197
// ----------------------------------------------------------------------------
 
198
//  ::MainFrame Drop Target (taken from ../src/main.cpp)
 
199
// ----------------------------------------------------------------------------
 
200
class wxMyFileDropTarget : public wxFileDropTarget
 
201
// ----------------------------------------------------------------------------
 
202
{
 
203
    // This class declaration must mirror the one used in ::MainFrame
 
204
    // We pass our filename array off to MainFrame using this class
 
205
 
 
206
  public:
 
207
    wxMyFileDropTarget(CodeSnippets* frame):m_frame(frame){}
 
208
    virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames)
 
209
    {
 
210
        if(!m_frame) return false;
 
211
        return m_frame->OnDropFiles(x,y,filenames);
 
212
    }
 
213
  private:
 
214
    CodeSnippets* m_frame;
 
215
};
 
216
 
 
217
// ----------------------------------------------------------------------------
 
218
// Local drop targets
 
219
// ----------------------------------------------------------------------------
 
220
class DropTargets: public wxDropTarget
 
221
// ----------------------------------------------------------------------------
 
222
{
 
223
  public:
 
224
 
 
225
    // constructor
 
226
    DropTargets (CodeSnippets* pcbDndExtn);
 
227
 
 
228
    virtual wxDragResult OnData (wxCoord x, wxCoord y, wxDragResult def);
 
229
    bool OnDataText (wxCoord x, wxCoord y, const wxString& data);
 
230
    bool OnDataFiles (wxCoord x, wxCoord y, const wxArrayString& filenames);
 
231
 
 
232
    wxDragResult OnDragOver (wxCoord x, wxCoord y, wxDragResult def);
 
233
    wxDragResult OnEnter (wxCoord x, wxCoord y, wxDragResult def);
 
234
    virtual bool OnDrop(wxCoord x, wxCoord y)
 
235
    {
 
236
        //wxDropTarget::OnDrop
 
237
        //virtual bool OnDrop(wxCoord x, wxCoord y)
 
238
        //Called when the user drops a data object on the target.
 
239
        //Return false to veto the operation.
 
240
        #ifdef LOGGING
 
241
         LOGIT( wxT("DropTargets:OnDrop") );
 
242
        #endif //LOGGING
 
243
        return true;
 
244
    }
 
245
 
 
246
    void OnLeave();
 
247
 
 
248
  private:
 
249
 
 
250
    CodeSnippets* m_pcbDndExtn;
 
251
 
 
252
    wxFileDataObject *m_file;
 
253
    wxTextDataObject *m_text;
 
254
 
 
255
};
 
256
//----------------------------------------------------------------------------
 
257
// drop targets composite
 
258
// ----------------------------------------------------------------------------
 
259
class DropTargetsComposite: public wxDataObjectComposite
 
260
// ----------------------------------------------------------------------------
 
261
{
 
262
  public:
 
263
    // constructor
 
264
    DropTargetsComposite () { m_dataObjectLast = NULL; };
 
265
 
 
266
    bool SetData (const wxDataFormat& format, size_t len, const void *buf)
 
267
    {
 
268
        m_dataObjectLast = GetObject (format);
 
269
        wxCHECK_MSG ( m_dataObjectLast, FALSE, wxT("unsupported format in wxDataObjectComposite"));
 
270
        return m_dataObjectLast->SetData (len, buf);
 
271
    }
 
272
 
 
273
    wxDataObjectSimple *GetLastDataObject() { return m_dataObjectLast; }
 
274
 
 
275
  private:
 
276
    wxDataObjectSimple *m_dataObjectLast;
 
277
 
 
278
};
 
279
 
 
280
#endif // CODESNIPPETS_H_INCLUDED