1
/***************************************************************
3
* Purpose: Code::Blocks plugin
7
**************************************************************/
12
#if defined(__GNUG__) && !defined(__APPLE__)
13
#pragma interface "dragscroll.h"
20
#include <wx/arrstr.h>
21
#include <wx/dynarray.h>
22
#include <wx/event.h> // wxEvtHandler
23
#include <wx/gdicmn.h> //wxPoint
25
#include <cbplugin.h> // the base class we 're inheriting
27
#include "dragscrollevent.h"
29
// ---------------------------------------------------------------------------
30
// Logging / debugging
31
// ---------------------------------------------------------------------------
33
//----------------------------------------
34
//#define VERSION "1.2.11t 2008/04/22"
35
//----------------------------------------
38
////#define LOGIT wxLogDebug
39
////#if defined(dsLOGGING)
40
//// #define LOGGING 1
42
//// #define LOGIT wxLogMessage
43
//// #define TRAP asm("int3")
46
// anchor to one and only DragScroll object
47
class MouseEventsHandler;
48
class cbDragScrollCfg;
51
class dsTextCtrlLogger;
53
// ----------------------------------------------------------------------------
54
// cbDragScroll class declaration
55
// ----------------------------------------------------------------------------
56
class cbDragScroll : public cbPlugin
58
friend class CodeSnippetsAppFrame;
59
friend class MouseEventHandler;
63
int GetConfigurationGroup() const { return cgEditor; }
64
void BuildMenu(wxMenuBar* menuBar){ return; }
65
void BuildModuleMenu(const ModuleType type, wxMenu* menu, const FileTreeData* data){ return; }
66
bool BuildToolBar(wxToolBar* toolBar){ return false; }
67
void OnAttach(); // fires when the plugin is attached to the application
68
void OnRelease(bool appShutDown); // fires when the plugin is released from the application
69
virtual cbConfigurationPanel* GetConfigurationPanel(wxWindow* parent);
70
virtual int Configure(wxWindow* parent = 0);
72
static cbDragScroll* pDragScroll;
74
cbConfigurationPanel* CreatecbCfgPanel(wxWindow* parent);
77
void SearchForScrollableWindows(){OnAppStartupDoneInit();}
78
void OnDialogDone(cbDragScrollCfg* pdlg);
80
bool GetMouseDragScrollEnabled() const { return MouseDragScrollEnabled; }
81
bool GetMouseEditorFocusEnabled() const { return MouseEditorFocusEnabled; }
82
bool GetMouseFocusEnabled() const { return MouseFocusEnabled; }
83
int GetMouseDragDirection() const { return MouseDragDirection; }
84
int GetMouseDragKey() const { return MouseDragKey; }
85
int GetMouseDragSensitivity() const { return MouseDragSensitivity; }
86
int GetMouseToLineRatio() const { return MouseToLineRatio; }
87
int GetMouseContextDelay() const { return MouseContextDelay; }
88
int GetMouseWheelZoom() const { return MouseWheelZoom; }
89
int IsLogZoomSizePropagated() const { return PropagateLogZoomSize; }
90
int GetMouseHtmlFontSize() const { return m_MouseHtmlFontSize; }
92
void OnAppStartupDoneInit();
93
bool IsAttachedTo(wxWindow* p);
94
void SetWindowZoom(wxWindow* pWxWindow);
96
wxWindow* m_pCB_AppWindow;
100
void OnAppStartupDone(CodeBlocksEvent& event);
101
void OnDoConfigRequests(wxUpdateUIEvent& event);
103
void AttachRecursively(wxWindow *p);
104
void Detach(wxWindow* thisEditor);
106
void Attach(wxWindow *p);
107
void DisconnectEvtHandler(MouseEventsHandler* thisEvtHandler);
108
void CenterChildOnParent(wxWindow* parent, wxWindow* child);
110
void OnDragScrollEvent_Dispatcher(wxCommandEvent& event );
111
void OnDragScrollEventAddWindow(wxCommandEvent& event );
112
void OnDragScrollEventRemoveWindow(wxCommandEvent& event );
113
void OnDragScrollEventRescan(wxCommandEvent& event );
114
void OnDragScrollTestRescan(wxCommandEvent& event );
115
void OnDragScrollEvent_RereadConfig(wxCommandEvent& event );
116
void OnDragScrollEvent_InvokeConfig(wxCommandEvent& event );
117
void OnMouseWheelEvent(wxMouseEvent& event);
118
dsTextCtrlLogger* IsLoggerControl(const wxTextCtrl* pControl);
119
bool OnMouseWheelInHtmlWindowEvent(wxMouseEvent& event);
120
void OnProjectClose(CodeBlocksEvent& event);
121
void OnStartShutdown(CodeBlocksEvent& event);
123
wxWindow* winExists(wxWindow *parent);
124
wxWindow* FindWindowRecursively(const wxWindow* parent, const wxWindow* handle);
125
wxString FindAppPath(const wxString& argv0, const wxString& cwd, const wxString& appVariableName);
126
void OnWindowOpen(wxEvent& event);
127
void OnWindowClose(wxEvent& event);
129
MouseEventsHandler* GetMouseEventsHandler();
130
void CleanUpWindowPointerArray();
131
void SetZoomWindowsStrings(wxString zoomWindowIds, wxString zoomFontSizes)
132
{m_ZoomWindowIds = zoomWindowIds; m_ZoomFontSizes = zoomFontSizes;}
133
int GetZoomWindowsArraysFrom(wxString zoomWindowIds, wxString zoomFontSizes);
134
void UpdateConfigFile();
136
wxString m_ConfigFolder;
137
wxString m_ExecuteFolder;
138
wxString m_DataFolder;
139
wxString m_CfgFilenameStr;
141
wxArrayString m_UsableWindows;
142
wxArrayPtrVoid m_WindowPtrs;
144
bool m_bNotebooksAttached;
145
//-deprecated-wxArrayPtrVoid m_EventHandlerArray;
146
MouseEventsHandler* m_pMouseEventsHandler; //one and only
148
wxString m_DragScrollFirstId;
149
wxString m_ZoomWindowIds;
150
wxString m_ZoomFontSizes;
151
wxArrayInt m_ZoomWindowIdsAry;
152
wxArrayInt m_ZoomFontSizesAry;
155
bool MouseDragScrollEnabled ; //Enable/Disable mouse event handler
156
bool MouseEditorFocusEnabled; //Enable/Disable mouse focus() editor
157
bool MouseFocusEnabled ; //Enable/Disable focus follows mouse
158
int MouseDragDirection ; //Move with or opposite mouse
159
int MouseDragKey ; //Right or Middle mouse key
160
int MouseDragSensitivity ; //Adaptive speed sensitivity
161
int MouseToLineRatio ; //Percentage of mouse moves that make a line
162
int MouseContextDelay ; //Linux context menu delay to catch possible mouse scroll move
163
int MouseWheelZoom ; //MouseWheel zooms tree, text, list controls
164
int PropagateLogZoomSize ; //Propagate Zoom Font size for all logs
165
int m_MouseHtmlFontSize ; //Ctrl-MouseWheel zoomed htmlWindow font size
167
PluginInfo* plugin ; //pointer to plugin info or null
171
DECLARE_EVENT_TABLE()
175
// ----------------------------------------------------------------------------
176
// MOUSE DRAG and SCROLL CLASS
177
// ----------------------------------------------------------------------------
181
#define DRAG_DRAGGING 2
182
// ----------------------------------------------------------------------------
183
class MouseEventsHandler : public wxEvtHandler
184
// ----------------------------------------------------------------------------
190
m_DragMode = DRAG_NONE;
191
m_MouseHasMoved = false;
192
m_RatioX = 1; m_RatioY = 1;
193
m_MouseMoveToLineMoveRatio = 0.30;
195
m_gtkContextDelay = 240 ;
197
~MouseEventsHandler();
199
void OnMouseEvent(wxMouseEvent& event);
204
wxPoint m_DragStartPos;
205
wxObject* m_pEvtObject;
206
bool m_MouseHasMoved;
207
double m_MouseMoveToLineMoveRatio;
208
double m_RatioX, m_RatioY;
209
int m_StartX, m_StartY;
210
int m_InitX, m_InitY;
211
// Scroll Direction move -1(mouse direction) +1(reverse mouse direction)
213
unsigned m_gtkContextDelay;
215
bool KeyDown(wxMouseEvent& event)
216
{ if ( 0 == cbDragScroll::pDragScroll->GetMouseDragKey() )
217
return event.RightDown();
218
return event.MiddleDown();
220
bool KeyIsDown(wxMouseEvent& event)
221
{ if ( 0 == cbDragScroll::pDragScroll->GetMouseDragKey() )
222
return event.RightIsDown();
223
return event.MiddleIsDown();
225
bool KeyUp(wxMouseEvent& event)
226
{ if ( 0 == cbDragScroll::pDragScroll->GetMouseDragKey() )
227
return event.RightUp();
228
return event.MiddleUp();
231
{ return ( cbDragScroll::pDragScroll->GetMouseDragKey() ? wxMOUSE_BTN_MIDDLE:wxMOUSE_BTN_RIGHT );}
233
DECLARE_EVENT_TABLE()
236
// ----------------------------------------------------------------------------
237
// Modification/ToDo History
238
// ----------------------------------------------------------------------------
241
// ----------------------------------------------------------------------------
242
// tiwag conversion to unicode
243
// Re: Right Mouse Drag and Scroll Plugin
244
// Reply #4 on: December 29, 2005, 08:05:40 PM
245
// thanks for this fine plugin,
246
// in the course of switching CodeBlocks to unicode build as standard development version
247
// i've done some necessary modifications to your code and also updated the project file to
248
// the NewBuild global variable system.
249
// attached DragScroll 0.4 NewBuild unicode
250
// * DragScroll-NewBuild-u.zip (5.77 KB - downloaded 0 times.)
251
// http://forums.codeblocks.org/index.php?topic=1594.msg13387#msg13387
253
// Added scrolling in text and textCtrl windows
256
// ---------------------------------------------------------------------------
257
// Removed event.Skip() when first Right mouse key down to avoid in text/textctrl
258
// the event.Skip() was activating text/textctrl mouse activity in codeblocks
259
// eg., mouse RightKeydown in "Search results" caused loading of editors etc.
260
// ---------------------------------------------------------------------------
262
// CodeBlocks SDK version changed. Modified BuildModuleMenu().
263
// void BuildModuleMenu(const ModuleType type, wxMenu* menu, const FileTreeData* data = 0){ return; }
265
// mod v0.13 1/22/2006
266
// Added GTK scrolling
268
// mod v0.14 1/25/2006 12
269
// Added cbConfiguratonDialog for configuration dialog
270
// ----------------------------------------------------------------------------
271
// commit v0.15 2/3/2006 1:03 PM
272
// ----------------------------------------------------------------------------
274
// closed v0.15 2/3/2006 12 open 1/26/2006 5:41 PM
275
// Need to stow/read user configuration settings
276
// Make MSW changes for GTK
277
// Removed-Test on ubuntu
278
// Linux version of C::B doesnt compile; will wait for Linux nightly builds(if ever provided)
280
// ----------------------------------------------------------------------------
281
// commit v0.16 2/4/2006
282
// ----------------------------------------------------------------------------
283
// mod fixes for unix/GTK
285
// ----------------------------------------------------------------------------
286
// commit v0.17 2/13/2006
287
// ----------------------------------------------------------------------------
289
// Set focus to editor when mouse in editor window.
291
// mod middle mouse key to avoid waits/delays
293
// CB_IMPLEMENT_PLUGIN(cbDragScroll, "DragScroll" );
295
// ----------------------------------------------------------------------------
296
// commit v0.18 2/14/2006
297
// ----------------------------------------------------------------------------
299
// Added "Mouse sets Editor Focus" configuration item
301
// ----------------------------------------------------------------------------
302
// commit v0.19 committed 2006/03/21
303
// ----------------------------------------------------------------------------
305
// 1.Added "Mouse sets Editor Focus" for GTK
306
// 2.Capture GTK middle mouse key immediately when used for scrolling
307
// ----------------------------------------------------------------------------
308
// commit v0.20 2006/04/5
309
// ----------------------------------------------------------------------------
310
// closed 2006/04/6 open 2006/04/5
311
// Conflict with Build messages context menu
312
// Removed events for ListCtrl windows
313
// ----------------------------------------------------------------------------
314
// commit v0.21 2006/04/6
315
// ----------------------------------------------------------------------------
317
// Resolution of above: event.Skip() on Right mouse Key down.
318
// Put back events for listctrl windows
319
// Catch address of Search Results window for scrolling.
320
// ----------------------------------------------------------------------------
322
// listCtrl windows activate on right mouse click. eg, Search and compiler
323
// error windows move the editor window on "right click". Very annoying.
324
// Suggest option to hide right mouse keydown from listCtrls
325
// Added config option []"Smooth Message List Scrolling"
326
// "(Conflicts with some Context Menus)"
327
// Set the Editor focus and Smooth Scrolling to default=false
328
// ----------------------------------------------------------------------------
329
// testing v0.22 2006/04/8 Capture ListCtrl Right Mouse Keydown
330
// ----------------------------------------------------------------------------
331
// fix v0.23 2006/04/25
332
// Added MS windows test for main window because events were getting
333
// to mouse handler even though main window didnt have focus
334
// ----------------------------------------------------------------------------
335
// commit v0.23 2006/04/25
336
// ----------------------------------------------------------------------------
337
// closed opened 2006/06/11
338
// split windows are unrecognized because no event is issued
339
// that a split has taken place
340
// Had to add wxEVT_CREATE and wxEVT_DESTROY event sinks to catch
341
// split window open/close. wxWindows nor CodeBlocks has events
342
// usable for the purpose.
343
// ----------------------------------------------------------------------------
344
// commit v0.24 2006/06/14
345
// ----------------------------------------------------------------------------
346
// closed 2006/06/16 open 2006/06/15
347
// MouseEventsHandler are being leaked because of split windows. When the
348
// windows close, no event is sent to allow cleanup before Destroy()
349
// Deleting an eventHandler during Destroy() causes wxWidgets to crash.
351
// Switched to runtime Connect/Disconnect/EVT_CREATE/EVT_DESTROY
352
// in order to stop leaks on split windows & pushed event handlers.
353
// ----------------------------------------------------------------------------
354
// fixed v 0.26 2006/06/29
355
// Broken by change in plugin interface 1.80
356
// Had to add the following to the project file
358
// Compile Options #defines
359
// -Winvalid-pch BUILDING_PLUGIN
361
// -mthreads WX_PRECOMP
362
// -fmessage-length=0 HAVE_W32API_H
363
// -fexceptions __WXMSW__
364
// -include "sdk.h" WXUSINGDLL
368
// ----------------------------------------------------------------------------
369
// commit v0.26 2006/06/29
370
// ----------------------------------------------------------------------------
371
// closed 2006/09/11 open 2006/07/2
372
// Clean up code after conversion to Connec/Disconnect event handlers
373
// ----------------------------------------------------------------------------
375
// Complaints that config font was too small on some linux systems
376
// and that the background color was incorrect.
378
// Removed all Setfont()'s from config. Removed SetBackGroundColorColor()
379
// ----------------------------------------------------------------------------
380
// commit v0.28 2006/09/11
381
// ----------------------------------------------------------------------------
382
// Commit v0.29 2006/09/22
383
// Edited manifest.xml requirement for codeblocks plugins
384
// Set displayed Menu About version dynamically.
385
// Removed all "eq". Conflicted with wxWidgest hash equates
386
// Added (__WXMAC__) to (_WXGTK_)defines to support mac.
387
// ----------------------------------------------------------------------------
388
// Commit 1.0.30 2006/10/16
389
// Add focus follow mouse option for MSW
390
// ----------------------------------------------------------------------------
391
// Commit 1.0.31 2006/10/18
392
// Default Auto focus editor to OFF
393
// ----------------------------------------------------------------------------
395
// Determine RTTI GetClassName() in mouse event
396
// ----------------------------------------------------------------------------
397
// Commit 1.0.33 2006/12/19
398
// 33) Removed dependency on EVT_APP_STARTUP_DONE
399
// ----------------------------------------------------------------------------
400
// Commit 1.0.36 2006/12/19 - 2006/12/22
401
// 34) Added focus follows mouse for wxGTK
402
// 35) Fixed GTK RightMouse scrolling (avoiding Context Menu conflict)
403
// 36) Added slider allowing user to set GTK RightMouse scrolling/context menu sensitivity
404
// ----------------------------------------------------------------------------
406
// 37) Re-instated GTK wxTextCtrl y-axis scrolling
407
// GTK cannot scroll a wxListCtrl
408
// 38) Corrected GTK dialog layout
409
// ----------------------------------------------------------------------------
410
// Commit 1.0.39 2007/02/28
411
// 39) If exists executable folder .ini file, use it.
412
// ----------------------------------------------------------------------------
413
// Commit 1.1.01 2007/04/28
414
// 01) Removed wx2.6.3 workarounds fixed by wx2.8.3
415
// ----------------------------------------------------------------------------
416
// Commit 1.1.02 2007/06/7
417
// 01) Prepend --personality arg to .ini filename
418
// ----------------------------------------------------------------------------
419
// Commit 1.1.04 2007/06/27
420
// 03) Reduce minimum Unix Context menu sentry delay
421
// 04) Clean up configuration panel
422
// ----------------------------------------------------------------------------
424
// 05) mandrav changes for sdk RegisterEventSink
425
// ----------------------------------------------------------------------------
426
// commit 1.2.04 2007/11/29
427
// 1) add non-pch logmanager header
428
// 2) correct "focus follows mouse" event on long compilations
429
// 3) correct editor focus event on long compilations
430
// 4) remove unused MouseRightKeyCtrl code
431
// ----------------------------------------------------------------------------
432
// Commit 1.2.05 2008/01/29
433
// 05) Killerbot header and const(ipation) changes (2007/12/28)
434
// 06) Fixed: Middle-mouse conflict with msWindows paste (2008/01/29)
435
// ----------------------------------------------------------------------------
436
// Commit 1.2.07 2008/02/2
437
// 06) Fixed: On some Linux's context menu missing in loggers bec mouse
438
// events always reported right-mouse was dragged. (Jens fix)
439
// ----------------------------------------------------------------------------
441
// 08) Allow multiple invocations of OnAppStartupDoneInit() in order
442
// to catch windows that open after we intialize. (2008/03/4)
443
// 09) Conversion to use only one event handler (2008/04/22)
444
// 10) Optimizations in MouseEventsHanderl
445
// 11) SearchForScrollableWindows() as service to external callers
446
// 12) Added DragScroll events for rescanning/adding/removing windows
447
// ----------------------------------------------------------------------------
449
// ----------------------------------------------------------------------------
450
// ----------------------------------------------------------------------------
451
#endif // DRAGSCROLL_H