2
This file is part of Code Snippets, a plugin for Code::Blocks
3
Copyright (C) 2006 Arto Jonsson
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.
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.
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.
20
#ifndef CODESNIPPETS_H_INCLUDED
21
#define CODESNIPPETS_H_INCLUDED
25
#include "cbplugin.h" // for "class cbPlugin"
26
//#include "wxaui/manager.h"
27
#include "snippetsconfig.h"
30
class CodeSnippetsWindow;
32
// ----------------------------------------------------------------------------
33
class CodeSnippets : public cbPlugin
34
// ----------------------------------------------------------------------------
36
friend class wxMyFileDropTarget;
37
friend class DropTargets;
45
/** Invoke configuration dialog. */
46
int Configure() { return 0; }
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.
53
int GetConfigurationPriority() const { return 50; }
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".
59
int GetConfigurationGroup() const { return cgContribPlugin; }
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.
65
cbConfigurationPanel* GetConfigurationPanel(wxWindow* parent){ return 0; }
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.
74
cbConfigurationPanel* GetProjectConfigurationPanel(wxWindow* parent, cbProject* project){ return 0; }
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,
81
* @param menuBar the wxMenuBar to create items in
83
void BuildMenu(wxMenuBar* menuBar);
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,
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)
100
void BuildModuleMenu(const ModuleType type, wxMenu* menu, const FileTreeData* data = 0){}
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,
107
* @param toolBar the wxToolBar to create items on
108
* @return The plugin should return true if it needed the toolbar, false if not
110
bool BuildToolBar(wxToolBar* toolBar){ return false; }
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...
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...
133
void OnRelease(bool appShutDown);
134
void OnDisable(bool appShutDown);
137
void SetSnippetsWindow(CodeSnippetsWindow* p);
138
CodeSnippetsWindow* GetSnippetsWindow(){return GetConfig()->GetSnippetsWindow();}
139
//-void OnTreeDragEvent(wxTreeEvent& event); 2011/01/9
140
//-void OnPrjTreeDragEvent(wxMouseEvent& event);
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();
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);
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 );
174
ProjectManager* m_pProjectMgr;
175
wxTreeCtrl* m_pMgtTreeBeginDrag;
176
//-wxPoint m_TreeMousePosn;
177
wxTreeItemId m_TreeItemId;
179
int m_nOnActivateBusy;
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;
194
DECLARE_EVENT_TABLE();
196
}; //class CodeSnippets
197
// ----------------------------------------------------------------------------
198
// ::MainFrame Drop Target (taken from ../src/main.cpp)
199
// ----------------------------------------------------------------------------
200
class wxMyFileDropTarget : public wxFileDropTarget
201
// ----------------------------------------------------------------------------
203
// This class declaration must mirror the one used in ::MainFrame
204
// We pass our filename array off to MainFrame using this class
207
wxMyFileDropTarget(CodeSnippets* frame):m_frame(frame){}
208
virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames)
210
if(!m_frame) return false;
211
return m_frame->OnDropFiles(x,y,filenames);
214
CodeSnippets* m_frame;
217
// ----------------------------------------------------------------------------
218
// Local drop targets
219
// ----------------------------------------------------------------------------
220
class DropTargets: public wxDropTarget
221
// ----------------------------------------------------------------------------
226
DropTargets (CodeSnippets* pcbDndExtn);
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);
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)
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.
241
LOGIT( wxT("DropTargets:OnDrop") );
250
CodeSnippets* m_pcbDndExtn;
252
wxFileDataObject *m_file;
253
wxTextDataObject *m_text;
256
//----------------------------------------------------------------------------
257
// drop targets composite
258
// ----------------------------------------------------------------------------
259
class DropTargetsComposite: public wxDataObjectComposite
260
// ----------------------------------------------------------------------------
264
DropTargetsComposite () { m_dataObjectLast = NULL; };
266
bool SetData (const wxDataFormat& format, size_t len, const void *buf)
268
m_dataObjectLast = GetObject (format);
269
wxCHECK_MSG ( m_dataObjectLast, FALSE, wxT("unsupported format in wxDataObjectComposite"));
270
return m_dataObjectLast->SetData (len, buf);
273
wxDataObjectSimple *GetLastDataObject() { return m_dataObjectLast; }
276
wxDataObjectSimple *m_dataObjectLast;
280
#endif // CODESNIPPETS_H_INCLUDED