1
/***************************************************************
3
* Purpose: Code::Blocks plugin
7
**************************************************************/
9
#if defined(__GNUG__) && !defined(__APPLE__)
10
#pragma implementation "dragscroll.h"
17
#include <wx/listctrl.h>
19
#include "configmanager.h"
20
#include "editormanager.h"
22
#include "personalitymanager.h"
23
#include "sdk_events.h" // EVT_APP_STARTUP_DONE
25
#include <wx/fileconf.h> // wxFileConfig
26
#include "cbstyledtextctrl.h"
27
#include "dragscroll.h"
28
#include "dragscrollcfg.h"
30
// Register the plugin
33
PluginRegistrant<cbDragScroll> reg(_T("cbDragScroll"));
36
int ID_DLG_DONE = wxNewId();
38
// ----------------------------------------------------------------------------
39
BEGIN_EVENT_TABLE(cbDragScroll, cbPlugin)
41
EVT_UPDATE_UI(ID_DLG_DONE, cbDragScroll::OnDoConfigRequests)
43
// ----------------------------------------------------------------------------
45
// ----------------------------------------------------------------------------
46
// global used by mouse events to get user configuration settings
47
cbDragScroll* cbDragScroll::pDragScroll;
49
// ----------------------------------------------------------------------------
50
cbDragScroll::cbDragScroll()
51
// ----------------------------------------------------------------------------
54
// anchor to this one and only object
57
// ----------------------------------------------------------------------------
58
cbDragScroll::~cbDragScroll()
59
// ----------------------------------------------------------------------------
64
// ----------------------------------------------------------------------------
65
void cbDragScroll::OnAttach()
66
// ----------------------------------------------------------------------------
68
// do whatever initialization you need for your plugin
69
// NOTE: after this function, the inherited member variable
70
// IsAttached() will be TRUE...
71
// You should check for it in other functions, because if it
72
// is FALSE, it means that the application did *not* "load"
73
// (see: does not need) this plugin...
76
m_bNotebooksAttached = false;
78
wxWindow* pcbWindow = Manager::Get()->GetAppWindow();
79
m_pMS_Window = pcbWindow;
81
wxLog::EnableLogging(true);
82
/*wxLogWindow**/ pMyLog = new wxLogWindow(pcbWindow, wxT("DragScroll"), true, false);
83
wxLog::SetActiveTarget(pMyLog);
85
pMyLog->GetFrame()->Move(20,20);
86
wxLogMessage(_T("Logging cbDragScroll version %s"),wxString(wxT(VERSION)).c_str());
89
// names of windows we're allowed to attach
90
m_UsableWindows.Add(_T("text"));
91
m_UsableWindows.Add(_T("listctrl"));
92
m_UsableWindows.Add(_T("textctrl"));
93
m_UsableWindows.Add(_T("treectrl"));
94
m_UsableWindows.Add(_T("treeAll"));
95
m_UsableWindows.Add(_T("treeMembers"));
96
m_UsableWindows.Add(_T("csTreeCtrl"));
97
m_UsableWindows.Add(_T("sciwindow"));
99
MouseDragScrollEnabled = true;
100
MouseEditorFocusEnabled = false;
101
MouseFocusEnabled = false;
102
MouseDragDirection = 0;
104
MouseDragSensitivity = 5;
105
MouseToLineRatio = 30;
106
//-MouseRightKeyCtrl = 0 ;
107
MouseContextDelay = 10;
109
// Create filename like cbDragScroll.ini
110
//memorize the key file name as {%HOME%}\cbDragScroll.ini
111
m_ConfigFolder = ConfigManager::GetConfigFolder();
112
m_DataFolder = ConfigManager::GetDataFolder();
113
m_ExecuteFolder = FindAppPath(wxTheApp->argv[0], ::wxGetCwd(), wxEmptyString);
115
//GTK GetConfigFolder is returning double "//?, eg, "/home/pecan//.codeblocks"
116
// remove the double //s from filename //+v0.4.11
117
m_ConfigFolder.Replace(_T("//"),_T("/"));
118
m_ExecuteFolder.Replace(_T("//"),_T("/"));
120
// get the CodeBlocks "personality" argument
121
wxString m_Personality = Manager::Get()->GetPersonalityManager()->GetPersonality();
122
if (m_Personality == wxT("default")) m_Personality = wxEmptyString;
123
LOGIT( _T("Personality is[%s]"), m_Personality.GetData() );
125
// if DragScroll.ini is in the executable folder, use it
126
// else use the default config folder
127
m_CfgFilenameStr = m_ExecuteFolder + wxFILE_SEP_PATH;
128
if (not m_Personality.IsEmpty()) m_CfgFilenameStr << m_Personality + wxT(".") ;
129
m_CfgFilenameStr << _T("DragScroll.ini");
131
if (::wxFileExists(m_CfgFilenameStr)) {;/*OK Use exe path*/}
132
else //use the default.conf folder
133
{ m_CfgFilenameStr = m_ConfigFolder + wxFILE_SEP_PATH;
134
if (not m_Personality.IsEmpty()) m_CfgFilenameStr << m_Personality + wxT(".") ;
135
m_CfgFilenameStr << _T("DragScroll.ini");
137
LOGIT(_T("DragScroll Config Filename:[%s]"), m_CfgFilenameStr.GetData());
138
// read configuaton file
139
wxFileConfig cfgFile(wxEmptyString, // appname
140
wxEmptyString, // vendor
141
m_CfgFilenameStr, // local filename
142
wxEmptyString, // global file
143
wxCONFIG_USE_LOCAL_FILE);
145
cfgFile.Read(_T("MouseDragScrollEnabled"), &MouseDragScrollEnabled ) ;
146
cfgFile.Read(_T("MouseEditorFocusEnabled"), &MouseEditorFocusEnabled ) ;
147
cfgFile.Read(_T("MouseFocusEnabled"), &MouseFocusEnabled ) ;
148
cfgFile.Read(_T("MouseDragDirection"), &MouseDragDirection ) ;
149
cfgFile.Read(_T("MouseDragKey"), &MouseDragKey ) ;
150
cfgFile.Read(_T("MouseDragSensitivity"), &MouseDragSensitivity ) ;
151
cfgFile.Read(_T("MouseToLineRatio"), &MouseToLineRatio ) ;
152
//-cfgFile.Read(_T("MouseRightKeyCtrl"), &MouseRightKeyCtrl) ;
153
cfgFile.Read(_T("MouseContextDelay"), &MouseContextDelay) ;
155
// Don't allow less than 10 mils on context/scroll delay.
156
if ( MouseContextDelay < 10) { MouseContextDelay = 10;}
159
LOGIT(_T("MouseDragScrollEnabled:%d"), MouseDragScrollEnabled ) ;
160
LOGIT(_T("MouseEditorFocusEnabled:%d"), MouseEditorFocusEnabled ) ;
161
LOGIT(_T("MouseFocusEnabled:%d"), MouseFocusEnabled ) ;
162
LOGIT(_T("MouseDragDirection:%d"), MouseDragDirection ) ;
163
LOGIT(_T("MouseDragKey:%d"), MouseDragKey ) ;
164
LOGIT(_T("MouseDragSensitivity:%d"), MouseDragSensitivity ) ;
165
LOGIT(_T("MouseToLineRatio:%d"), MouseToLineRatio ) ;
166
//-LOGIT(_T("MouseRightKeyCtrl:%d"), MouseRightKeyCtrl ) ;
167
LOGIT(_T("MouseContextDelay:%d"), MouseContextDelay ) ;
170
// Pointer to "Search Results" Window (first listCtrl window)
171
m_pSearchResultsWindow = 0;
173
// Catch creation of windows
174
Connect( wxEVT_CREATE,
175
(wxObjectEventFunction) (wxEventFunction)
176
(wxCommandEventFunction) &cbDragScroll::OnWindowOpen);
178
// Catch Destroyed windows
179
Connect( wxEVT_DESTROY,
180
(wxObjectEventFunction) (wxEventFunction)
181
(wxCommandEventFunction) &cbDragScroll::OnWindowClose);
183
// Set current plugin version
184
PluginInfo* pInfo = (PluginInfo*)(Manager::Get()->GetPluginManager()->GetPluginInfo(this));
185
pInfo->version = wxT(VERSION);
187
// register event sink
188
Manager::Get()->RegisterEventSink(cbEVT_APP_STARTUP_DONE, new cbEventFunctor<cbDragScroll, CodeBlocksEvent>(this, &cbDragScroll::OnAppStartupDone));
192
// ----------------------------------------------------------------------------
193
void cbDragScroll::OnRelease(bool appShutDown)
194
// ----------------------------------------------------------------------------
196
// do de-initialization for your plugin
197
// if appShutDown is false, the plugin is unloaded because Code::Blocks is being shut down,
198
// which means you must not use any of the SDK Managers
199
// NOTE: after this function, the inherited member variable
200
// IsAttached() will be FALSE...
202
// Remove all Mouse event handlers
205
// ----------------------------------------------------------------------------
206
cbConfigurationPanel* cbDragScroll::GetConfigurationPanel(wxWindow* parent)
207
// ----------------------------------------------------------------------------
209
//create and display the configuration dialog for your plugin
210
if(!IsAttached()) { return 0;}
211
// Create a configuration dialogue and hand it off to codeblocks
213
//cbConfigurationPanel* pDlg = new cbDragScrollCfg(parent, this);
214
cbDragScrollCfg* pDlg = new cbDragScrollCfg(parent, this);
215
// set current mouse scrolling options
216
pDlg->SetMouseDragScrollEnabled ( MouseDragScrollEnabled );
217
pDlg->SetMouseEditorFocusEnabled ( MouseEditorFocusEnabled );
218
pDlg->SetMouseFocusEnabled ( MouseFocusEnabled );
219
pDlg->SetMouseDragDirection ( MouseDragDirection );
220
pDlg->SetMouseDragKey ( MouseDragKey );
221
pDlg->SetMouseDragSensitivity ( MouseDragSensitivity );
222
pDlg->SetMouseToLineRatio ( MouseToLineRatio );
223
//-pDlg->SetMouseRightKeyCtrl ( MouseRightKeyCtrl );
224
pDlg->SetMouseContextDelay ( MouseContextDelay );
227
// when the configuration panel is closed with OK, OnDialogDone() will be called
230
// ----------------------------------------------------------------------------
231
void cbDragScroll::OnDialogDone(cbDragScrollCfg* pDlg)
232
// ----------------------------------------------------------------------------
234
// The configuration panel has run its OnApply() function.
235
// So here it's like we were using ShowModal() and it just returned wxID_OK.
237
MouseDragScrollEnabled = pDlg->GetMouseDragScrollEnabled();
238
MouseEditorFocusEnabled = pDlg->GetMouseEditorFocusEnabled();
239
MouseFocusEnabled = pDlg->GetMouseFocusEnabled();
240
MouseDragDirection = pDlg->GetMouseDragDirection();
241
MouseDragKey = pDlg->GetMouseDragKey();
242
MouseDragSensitivity = pDlg->GetMouseDragSensitivity();
243
MouseToLineRatio = pDlg->GetMouseToLineRatio();
244
//- MouseRightKeyCtrl = pDlg->GetMouseRightKeyCtrl(); removed
245
MouseContextDelay = pDlg->GetMouseContextDelay();
247
LOGIT(_T("MouseDragScrollEnabled:%d"), MouseDragScrollEnabled);
248
LOGIT(_T("MouseEditorFocusEnabled:%d"), MouseEditorFocusEnabled);
249
LOGIT(_T("MouseFocusEnabled:%d"), MouseFocusEnabled);
250
LOGIT(_T("MouseDragDirection:%d"), MouseDragDirection);
251
LOGIT(_T("MouseDragKey:%d"), MouseDragKey);
252
LOGIT(_T("MouseDragSensitivity:%d"), MouseDragSensitivity);
253
LOGIT(_T("MouseToLineRatio:%d"), MouseToLineRatio);
254
//-LOGIT(_T("MouseRightKeyCtrl:%d"), MouseRightKeyCtrl);
255
LOGIT(_T("MouseContextDelay:%d"), MouseContextDelay);
256
LOGIT(_T("-----------------------------"));
259
// Post a pending request to later update the configuration requests
260
// Doing work here will stall the dlg window on top of the editor
261
wxUpdateUIEvent eventdone(ID_DLG_DONE);
262
eventdone.SetEventObject(Manager::Get()->GetAppWindow() );
263
Manager::Get()->GetAppWindow()->GetEventHandler()->AddPendingEvent(eventdone);
265
// don't delete dlg; Codeblocks should destroy the dialog
268
// ----------------------------------------------------------------------------
269
void cbDragScroll::OnDoConfigRequests(wxUpdateUIEvent& event)
270
// ----------------------------------------------------------------------------
272
// This is an event triggered by OnDialogDone() to update config settings
274
LOGIT(_T("OnDoConfigRequest event"));
276
// Attach or Detach windows to match Mouse Enabled config setting
277
if (GetMouseDragScrollEnabled() ) //v04.14
278
{ if (not m_bNotebooksAttached)
280
AttachRecursively(Manager::Get()->GetAppWindow());
281
m_bNotebooksAttached = true;
286
m_bNotebooksAttached = false;
289
// update/write configuaton file
290
wxFileConfig cfgFile(wxEmptyString, // appname
291
wxEmptyString, // vendor
292
m_CfgFilenameStr, // local filename
293
wxEmptyString, // global file
294
wxCONFIG_USE_LOCAL_FILE);
296
cfgFile.Write(_T("MouseDragScrollEnabled"), MouseDragScrollEnabled ) ;
297
cfgFile.Write(_T("MouseEditorFocusEnabled"), MouseEditorFocusEnabled ) ;
298
cfgFile.Write(_T("MouseFocusEnabled"), MouseFocusEnabled ) ;
299
cfgFile.Write(_T("MouseDragDirection"), MouseDragDirection ) ;
300
cfgFile.Write(_T("MouseDragKey"), MouseDragKey ) ;
301
cfgFile.Write(_T("MouseDragSensitivity"), MouseDragSensitivity ) ;
302
cfgFile.Write(_T("MouseToLineRatio"), MouseToLineRatio ) ;
303
//-cfgFile.Write(_T("MouseRightKeyCtrl"), MouseRightKeyCtrl ) ;
304
cfgFile.Write(_T("MouseContextDelay"), MouseContextDelay ) ;
307
// ----------------------------------------------------------------------------
308
bool cbDragScroll::IsAttachedTo(wxWindow* p)
309
// ----------------------------------------------------------------------------
312
if ( wxNOT_FOUND == m_EditorPtrs.Index(p))
317
// ----------------------------------------------------------------------------
318
void cbDragScroll::Attach(wxWindow *p)
319
// ----------------------------------------------------------------------------{
321
if (!p || IsAttachedTo(p))
322
return; // already attached !!!
324
// allow only static windows to be attached by codeblocks
325
// Disappearing frames/windows cause crashes
326
// eg., wxArrayString m_UsableWindows = "sciwindow notebook";
328
wxString windowName = p->GetName().MakeLower();
330
// memorize "Search Results" Window address
331
// We're assuming it's the first listcrl window found
332
if ( (not m_pSearchResultsWindow) && (windowName == wxT("listctrl")) )
333
{ m_pSearchResultsWindow = p;
335
LOGIT(wxT("SearchResultsWindow: %p"),p );
339
if (wxNOT_FOUND == m_UsableWindows.Index(windowName,false))
341
LOGIT(wxT("cbDS::Attach skipping [%s]"), p->GetName().c_str());
345
LOGIT(wxT("cbDS::Attach - attaching to [%s] %p"), p->GetName().c_str(),p);
347
//add window to our array, create a mouse event handler
348
// and memorize event handler instance
350
MyMouseEvents* thisEvtHndlr = new MyMouseEvents(p);
351
m_EventHandlerArray.Add(thisEvtHndlr);
353
p->Connect(wxEVT_MIDDLE_DOWN,
354
(wxObjectEventFunction)(wxEventFunction)
355
(wxMouseEventFunction)&MyMouseEvents::OnMouseEvent,
357
p->Connect(wxEVT_MIDDLE_UP,
358
(wxObjectEventFunction)(wxEventFunction)
359
(wxMouseEventFunction)&MyMouseEvents::OnMouseEvent,
361
p->Connect(wxEVT_RIGHT_DOWN,
362
(wxObjectEventFunction)(wxEventFunction)
363
(wxMouseEventFunction)&MyMouseEvents::OnMouseEvent,
365
p->Connect(wxEVT_RIGHT_UP,
366
(wxObjectEventFunction)(wxEventFunction)
367
(wxMouseEventFunction)&MyMouseEvents::OnMouseEvent,
369
p->Connect(wxEVT_MOTION,
370
(wxObjectEventFunction)(wxEventFunction)
371
(wxMouseEventFunction)&MyMouseEvents::OnMouseEvent,
373
p->Connect(wxEVT_ENTER_WINDOW,
374
(wxObjectEventFunction)(wxEventFunction)
375
(wxMouseEventFunction)&MyMouseEvents::OnMouseEvent,
379
LOGIT(_T("cbDS:Attach Window:%p Handler:%p"), p,thisEvtHndlr);
383
// ----------------------------------------------------------------------------
384
void cbDragScroll::AttachRecursively(wxWindow *p)
385
// ----------------------------------------------------------------------------{
392
// this is the standard way wxWidgets uses to iterate through children...
393
for (wxWindowList::compatibility_iterator node = p->GetChildren().GetFirst();
395
node = node->GetNext())
397
// recursively attach each child
398
wxWindow *win = (wxWindow *)node->GetData();
401
AttachRecursively(win);
404
// ----------------------------------------------------------------------------
405
wxWindow* cbDragScroll::FindWindowRecursively(const wxWindow* parent, const wxWindow* handle)
406
// ----------------------------------------------------------------------------{
410
// see if this is the one we're looking for
411
if ( parent == handle )
412
return (wxWindow *)parent;
414
// It wasn't, so check all its children
415
for ( wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst();
417
node = node->GetNext() )
419
// recursively check each child
420
wxWindow *win = (wxWindow *)node->GetData();
421
wxWindow *retwin = FindWindowRecursively(win, handle);
430
// ----------------------------------------------------------------------------
431
wxWindow* cbDragScroll::winExists(wxWindow *parent)
432
// ----------------------------------------------------------------------------{
440
// start at very top of wx's windows
441
for ( wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
443
node = node->GetNext() )
445
// recursively check each window & its children
446
wxWindow* win = node->GetData();
447
wxWindow* retwin = FindWindowRecursively(win, parent);
454
// ----------------------------------------------------------------------------
455
void cbDragScroll::Detach(wxWindow* thisEditor)
456
// ----------------------------------------------------------------------------
458
if ( (thisEditor) && (m_EditorPtrs.Index(thisEditor) != wxNOT_FOUND))
461
LOGIT(_T("cbDS:Detaching %p"), thisEditor);
464
int edIndex = m_EditorPtrs.Index(thisEditor);
465
MyMouseEvents* thisEvtHandler = (MyMouseEvents*)m_EventHandlerArray.Item(edIndex);
466
m_EditorPtrs.Remove(thisEditor);
467
m_EventHandlerArray.Remove(thisEvtHandler);
469
// If win already deleted, dont worry about receiving events
470
if ( not winExists(thisEditor) )
472
LOGIT(_T("cbDS:DetachAll window NOT found %p Handlr: %p"),
473
thisEditor, thisEvtHandler);
475
thisEditor->Disconnect(wxEVT_MIDDLE_DOWN,
476
(wxObjectEventFunction)(wxEventFunction)
477
(wxMouseEventFunction)&MyMouseEvents::OnMouseEvent,
478
NULL, thisEvtHandler);
479
thisEditor->Disconnect(wxEVT_MIDDLE_UP,
480
(wxObjectEventFunction)(wxEventFunction)
481
(wxMouseEventFunction)&MyMouseEvents::OnMouseEvent,
482
NULL, thisEvtHandler);
483
thisEditor->Disconnect(wxEVT_RIGHT_DOWN,
484
(wxObjectEventFunction)(wxEventFunction)
485
(wxMouseEventFunction)&MyMouseEvents::OnMouseEvent,
486
NULL, thisEvtHandler);
487
thisEditor->Disconnect(wxEVT_RIGHT_UP,
488
(wxObjectEventFunction)(wxEventFunction)
489
(wxMouseEventFunction)&MyMouseEvents::OnMouseEvent,
490
NULL, thisEvtHandler);
491
thisEditor->Disconnect(wxEVT_MOTION,
492
(wxObjectEventFunction)(wxEventFunction)
493
(wxMouseEventFunction)&MyMouseEvents::OnMouseEvent,
494
NULL, thisEvtHandler);
495
thisEditor->Disconnect(wxEVT_ENTER_WINDOW,
496
(wxObjectEventFunction)(wxEventFunction)
497
(wxMouseEventFunction)&MyMouseEvents::OnMouseEvent,
498
NULL, thisEvtHandler);
501
delete(thisEvtHandler);
504
LOGIT(_T("Detach: Editor:%p EvtHndlr: %p"),thisEditor,thisEvtHandler);
508
// ----------------------------------------------------------------------------
509
void cbDragScroll::DetachAll()
510
// ----------------------------------------------------------------------------
512
// delete all handlers
513
LOGIT(wxT("cbDS:DetachAll - detaching all [%d] targets"),m_EditorPtrs.GetCount() );
515
// Detach from memorized windows and remove event handlers
516
while( m_EditorPtrs.GetCount() )
518
wxWindow* pw = (wxWindow*)m_EditorPtrs.Item(0);
522
m_EditorPtrs.Empty();
524
// Free any leaked event handlers caused by disappearing windows
525
// *Danger* There are dynamic events connected to these Event Handlers
526
// Could cause segfaults. This shouldnt happen. Fix the bug if it does.
527
for (int i=0; i < (int)m_EventHandlerArray.GetCount(); i++)
529
MyMouseEvents* pHdlr = (MyMouseEvents*)m_EventHandlerArray.Item(i);
531
LOGIT(_T("cbDS:DetachAll - Removing Leaked EventHdl:[%p]"), pHdlr );
534
m_EventHandlerArray.Empty();
535
// say no windows attached
536
m_bNotebooksAttached = false;
537
m_pSearchResultsWindow = 0;
541
// ----------------------------------------------------------------------------
542
wxString cbDragScroll::FindAppPath(const wxString& argv0, const wxString& cwd, const wxString& appVariableName)
543
// ----------------------------------------------------------------------------
545
// Find the absolute path where this application has been run from.
546
// argv0 is wxTheApp->argv[0]
547
// cwd is the current working directory (at startup)
548
// appVariableName is the name of a variable containing the directory for this app, e.g.
549
// MYAPPDIR. This is checked first.
553
// Try appVariableName
554
if (!appVariableName.IsEmpty())
556
str = wxGetenv(appVariableName);
561
#if defined(__WXMAC__) && !defined(__DARWIN__)
562
// On Mac, the current directory is the relevant one when
563
// the application starts.
567
if (wxIsAbsolutePath(argv0))
568
return wxPathOnly(argv0);
571
// Is it a relative path?
572
wxString currentDir(cwd);
573
if (currentDir.Last() != wxFILE_SEP_PATH)
574
currentDir += wxFILE_SEP_PATH;
576
str = currentDir + argv0;
577
if (wxFileExists(str))
578
return wxPathOnly(str);
581
// OK, it's neither an absolute path nor a relative path.
585
pathList.AddEnvList(wxT("PATH"));
586
str = pathList.FindAbsoluteValidPath(argv0);
588
return wxPathOnly(str);
591
return wxEmptyString;
593
// ----------------------------------------------------------------------------
595
// ----------------------------------------------------------------------------
596
// cbDragScroll Routines to push/remove mouse event handlers
597
// ----------------------------------------------------------------------------
598
void cbDragScroll::OnAppStartupDone(CodeBlocksEvent& event)
599
// ----------------------------------------------------------------------------
601
// EVT_APP_STARTUP_DONE
603
LOGIT(_T("AppStartupDone"));
605
OnAppStartupDoneInit();
610
// ----------------------------------------------------------------------------
611
void cbDragScroll::OnAppStartupDoneInit()
612
// ----------------------------------------------------------------------------
614
if (not GetMouseDragScrollEnabled() ) //v04.14
617
if (! m_bNotebooksAttached)
619
AttachRecursively(Manager::Get()->GetAppWindow());
620
m_bNotebooksAttached = true;
623
// ----------------------------------------------------------------------------
624
void cbDragScroll::OnWindowOpen(wxEvent& event)
625
// ----------------------------------------------------------------------------
627
// wxEVT_CREATE entry
628
// Have to do this especially for split windows since CodeBlocks does not have
629
// events when opening/closing split windows
631
wxWindow* pWindow = (wxWindow*)(event.GetEventObject());
633
// Some code (at times) is not event.Skip()ing on EVT_APP_STARTUP_DONE
634
// so here we do it ourselves. If not initialized and this is the first
635
// scintilla window, initialize now.
636
if ( (not m_bNotebooksAttached)
637
&& ( pWindow->GetName().Lower() == wxT("sciwindow")) )
638
OnAppStartupDoneInit();
640
// Attach a split window (or any other window)
641
if ( m_bNotebooksAttached )
643
wxWindow* pWindow = (wxWindow*)(event.GetEventObject());
645
ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
648
if (pWindow->GetParent() == ed)
651
LOGIT( _T("OnWindowOpen Attached:%p name: %s"),
652
pWindow, pWindow->GetName().GetData() );
660
// ----------------------------------------------------------------------------
661
void cbDragScroll::OnWindowClose(wxEvent& event)
662
// ----------------------------------------------------------------------------
664
// wxEVT_DESTROY entry
666
wxWindow* pWindow = (wxWindow*)(event.GetEventObject());
668
if ( (pWindow) && (m_EditorPtrs.Index(pWindow) != wxNOT_FOUND))
669
{ // window is one of ours
672
LOGIT( _T("OnWindowClose Detached %p"), pWindow);
677
// ----------------------------------------------------------------------------
678
// MOUSE DRAG and SCROLL Routines
679
// ----------------------------------------------------------------------------
680
BEGIN_EVENT_TABLE(MyMouseEvents, wxEvtHandler)
681
//-Deprecated- EVT_MOUSE_EVENTS( MyMouseEvents::OnMouseEvent)
682
// Using Connect/Disconnect events and EVT_CREATE/EVT_DESTROY
683
// wxWidgets events since split-windows were
684
// introduced without providing codeblocks events to plugins.
685
// Without CB events, event handlers were being leaked for each split
688
// ----------------------------------------------------------------------------
689
MyMouseEvents::~MyMouseEvents()
692
LOGIT(_T("MyMouseEvents dtor"));
697
///////////////////////////////////////////////////////////////////////////////
698
// ----------------------------------------------------------------------------
699
// MOUSE SCROLLING for __WXMSW__
700
// ----------------------------------------------------------------------------
701
///////////////////////////////////////////////////////////////////////////////
703
// ----------------------------------------------------------------------------
704
void MyMouseEvents::OnMouseEvent(wxMouseEvent& event) //MSW
705
// ----------------------------------------------------------------------------
708
//remember event window pointer
709
m_pEvtObject = event.GetEventObject();
710
cbDragScroll* pDS = cbDragScroll::pDragScroll;
712
// Why is an event getting in here when this window doesnt have the OS focus
713
if (::wxGetActiveWindow() != pDS->m_pMS_Window)
714
{event.Skip(); return;}
716
// For efficiency, skip wheel events now
717
if ( event.GetEventType() == wxEVT_MOUSEWHEEL)
718
{ event.Skip(); return; }
720
// if "focus follows mouse" enabled, set focus to window
721
if (pDS->GetMouseFocusEnabled() )
722
{ // use EVT_ENTER_WINDOW instead of EVT_MOTION so that double
723
// clicking a search window item allows activating the editor cursor
724
// while mouse is still in the search window
725
if (event.GetEventType() == wxEVT_ENTER_WINDOW)
726
if (m_pEvtObject) ((wxWindow*)m_pEvtObject)->SetFocus();
729
// differentiate window, left, right split window
731
cbStyledTextCtrl* p_cbStyledTextCtrl = 0;
732
cbStyledTextCtrl* pLeftSplitWin = 0;
733
cbStyledTextCtrl* pRightSplitWin = 0;
734
ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
736
{ p_cbStyledTextCtrl = ed->GetControl();
737
pLeftSplitWin = ed->GetLeftSplitViewControl();
738
pRightSplitWin = ed->GetRightSplitViewControl();
741
// set focus to editor window if mouse is in it
742
if (event.GetEventType() == wxEVT_MOTION)
743
{ // use EVT_MOTION here to avoid missing EVT_ENTER_WINDOW.
744
// also allows auto activating the editor during long compiles
745
if (pDS->GetMouseEditorFocusEnabled() ) do
746
{ wxWindow* currentFocus = wxWindow::FindFocus();
747
if (p_cbStyledTextCtrl && (m_pEvtObject == pLeftSplitWin))
748
if (currentFocus != (wxWindow*)m_pEvtObject)
749
{ pLeftSplitWin->SetFocus();
751
//LOGIT( _T("OnMouseEvent:SetFocus Left %p"), pLeftSplitWin );
755
if (pRightSplitWin && (m_pEvtObject == pRightSplitWin))
756
if (currentFocus != (wxWindow*)m_pEvtObject)
757
{ pRightSplitWin->SetFocus();
759
//LOGIT( _T("OnMouseEvent:SetFocus Right %p"), pRightSplitWin );
770
//LOGIT(_T("OnMouseEvent"));
775
m_Direction = pDS->GetMouseDragDirection() ? 1 : -1 ; //v0.14
776
m_MouseMoveToLineMoveRatio = pDS->GetMouseToLineRatio()/100.0;
778
//LOGIT( _T("m_MouseMoveToLineMoveRatio %f"),m_MouseMoveToLineMoveRatio );
780
// We tentatively start dragging, but wait for
781
// mouse movement before dragging properly.
783
m_MouseHasMoved = false;
784
//start position will change for each move
785
m_StartY = event.GetPosition().y; m_StartX = event.GetPosition().x;
786
//remember initial position for entire drag activity
787
m_InitY = m_StartY; m_InitX = m_StartX;
789
m_DragMode = DRAG_START;
790
m_DragStartPos = event.GetPosition();
792
//LOGIT(_T("Down X:%d Y:%d"), m_InitY, m_InitX);
794
if ( (GetUserDragKey() == wxMOUSE_BTN_MIDDLE ) && event.MiddleIsDown() )
795
return; //dont allow paste from middle-mouse used as scroll key
796
event.Skip(); //v0.21
800
else if (KeyUp(event) && (m_DragMode != DRAG_NONE) )
803
int lastmode = m_DragMode;
804
m_DragMode = DRAG_NONE;
805
// if our trapped drag, hide event from others, ie. don't event.skip()
809
if (lastmode == DRAG_DRAGGING) return;
810
// allow context menu processing
815
else if ( event.Dragging() && (m_DragMode != DRAG_NONE ) )
817
//make sure user didnt leave client area and lift mouse key
818
if ( not KeyIsDown(event))
819
{ m_DragMode = DRAG_NONE;
823
//allow user some slop moves in case this is a "moving" context menu request
824
if ( ! m_MouseHasMoved
825
&& abs(event.GetPosition().x - m_InitX) < 3
826
&& abs(event.GetPosition().y - m_InitY) < 3)
829
//+v0.6 code moved here to allow sloppier context menu requests
830
if (m_DragMode == DRAG_START)
832
// Start the drag. This will stop the context popup
834
//LOGIT(_T("Drag_Start"));
836
m_DragMode = DRAG_DRAGGING;
839
m_MouseHasMoved = true;
840
int dX = event.GetPosition().x - m_StartX;
841
int dY = event.GetPosition().y - m_StartY;
843
//show some sensitivity to speed of user mouse movements
844
m_RatioX = m_RatioY = m_MouseMoveToLineMoveRatio;
845
// build up some mouse movements to guarantee ratios won't cancel scrolling
846
if ( (abs(dX)*m_RatioX >= 1) || (abs(dY)*m_RatioY >= 1) )
847
{ m_StartY = event.GetPosition().y; m_StartX = event.GetPosition().x;}
849
//add one full mousemove for every x mouse positions beyond start position
850
//so scrolling is faster as user is faster
851
// slider values 1...2...3...4...5...6...7...8...9...10 //v0.14
852
// divisn values 90 80 70 60 50 40 30 20 10 1
853
int nThreshold = 1+( 100-(pDS->GetMouseDragSensitivity()*10) );
854
m_RatioX += (abs(dX)/nThreshold);
855
m_RatioY += (abs(dY)/nThreshold);
857
// scroll the client area
858
if (abs(dX) > abs(dY))
860
scrolly = 0; scrollx = int(dX * m_RatioX);
864
scrollx = 0; scrolly = int(dY * m_RatioY);
867
// LOGIT(_T("RatioX:%f RatioY:%f"), m_RatioX, m_RatioY);
868
// LOGIT(_T("Drag: dX:%d dY:%d scrollx:%d scrolly:%d"), dX, dY, scrollx, scrolly);
871
// Scroll horizontally and vertically.
872
// void LineScroll (int columns, int lines);
873
if ((scrollx==0) && (scrolly==0)) return;
874
scrollx *= m_Direction; scrolly *= m_Direction;
876
// if editor window, use scintilla scroll
877
if (p_cbStyledTextCtrl && (m_pEvtObject == p_cbStyledTextCtrl))
879
p_cbStyledTextCtrl->LineScroll (scrollx,scrolly);
881
else //use control scrolling
883
//use wxTextCtrl scroll for y scrolling
885
((wxWindow*)m_pEvtObject)->ScrollLines(scrolly);
886
else // use listCtrl for x scrolling
887
((wxListCtrl*)m_pEvtObject)->ScrollList(scrollx<<2,scrolly);
889
}//else if ( event.Dragging() && (m_DragMode != DRAG_NONE )
891
// pass the event onward
895
#endif //__WXMSW__ scroling
897
///////////////////////////////////////////////////////////////////////////////
898
// ----------------------------------------------------------------------------
899
// __WXGTK__ MOUSE SCROLLING __WXGTK__
900
// ----------------------------------------------------------------------------
901
///////////////////////////////////////////////////////////////////////////////
902
#if defined(__WXGTK__) || defined(__WXMAC__)
903
// ----------------------------------------------------------------------------
904
void MyMouseEvents::OnMouseEvent(wxMouseEvent& event) //GTK
905
// ----------------------------------------------------------------------------
908
// For efficiency, skip wheel events now
909
if ( event.GetEventType() == wxEVT_MOUSEWHEEL)
910
{ event.Skip(); return; }
912
//remember window pointer
913
m_pEvtObject = event.GetEventObject();
914
cbDragScroll* pDS = cbDragScroll::pDragScroll;
917
//LOGIT( _T("m_MouseMoveToLineMoveRatio %f"),m_MouseMoveToLineMoveRatio );
920
// if "focus follows mouse" enabled, set focus to window
921
if (pDS->GetMouseFocusEnabled() )
922
{ // use EVT_ENTER_WINDOW instead of EVT_MOTION so that double
923
// clicking a search window item allows activating the editor cursor
924
if (event.GetEventType() == wxEVT_ENTER_WINDOW)
925
if (m_pEvtObject) ((wxWindow*)m_pEvtObject)->SetFocus();
929
cbStyledTextCtrl* p_cbStyledTextCtrl = 0;
930
cbStyledTextCtrl* pLeftSplitWin = 0;
931
cbStyledTextCtrl* pRightSplitWin = 0;
932
ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
934
{ p_cbStyledTextCtrl = ed->GetControl();
935
pLeftSplitWin = ed->GetLeftSplitViewControl();
936
pRightSplitWin = ed->GetRightSplitViewControl();
939
// set focus to editor window if mouse is in it
940
if (event.GetEventType() == wxEVT_MOTION)
941
{ // use EVT_MOTION here to avoid missing EVT_ENTER_WINDOW
942
// and allow activating the editor during compiles
943
if (pDS->GetMouseEditorFocusEnabled() ) do
944
{ wxWindow* currentFocus = wxWindow::FindFocus();
945
if (p_cbStyledTextCtrl && (m_pEvtObject == pLeftSplitWin))
946
if (currentFocus != (wxWindow*)m_pEvtObject)
947
{ pLeftSplitWin->SetFocus();
949
//LOGIT( _T("OnMouseEvent:SetFocus Left %p"), pLeftSplitWin );
953
if (pRightSplitWin && (m_pEvtObject == pRightSplitWin))
954
if (currentFocus != (wxWindow*)m_pEvtObject)
955
{ pRightSplitWin->SetFocus();
957
//LOGIT( _T("OnMouseEvent:SetFocus Right %p"), pRightSplitWin );
968
//LOGIT(_T("OnMouseEvent"));
971
//--------- Key Down ------------------------------------------------------
974
m_Direction = pDS->GetMouseDragDirection() ? 1 : -1 ; //v0.14
975
m_MouseMoveToLineMoveRatio = pDS->GetMouseToLineRatio()/100.0;
977
// We tentatively start dragging, but wait for
978
// mouse movement before dragging properly.
980
m_MouseHasMoved = false;
981
//start position will change for each move
982
m_StartY = event.GetPosition().y; m_StartX = event.GetPosition().x;
983
//remember initial position for entire drag activity
984
m_InitY = m_StartY; m_InitX = m_StartX;
986
m_DragMode = DRAG_NONE;
987
m_DragStartPos = event.GetPosition();
989
LOGIT(_T("Down at X:%d Y:%d"), m_InitX, m_InitY);
992
wxPoint mouseXY = ((wxWindow*)m_pEvtObject)->ScreenToClient(wxGetMousePosition());
993
LOGIT(_T("Down MoveTo X:%d Y:%d"), mouseXY.x, mouseXY.y);
995
// wait for possible mouse moves before poping context menu
996
for (int i = 0; i < pDS->GetMouseContextDelay();)
998
::wxMilliSleep(10); // wait for move (if any)
999
mouseXY = ((wxWindow*)m_pEvtObject)->ScreenToClient(wxGetMousePosition());
1000
scrollx = abs(mouseXY.x - m_InitX) ;
1001
scrolly = abs(mouseXY.y - m_InitY) ;
1002
//-if ( ( scrolly > 1) || (scrollx > 1) ) break; 2008/02/2
1003
if ( ( scrolly > 2) || (scrollx > 2) ) break;
1007
// capture middle mouse key for immediate dragging
1008
if ( (GetUserDragKey() == wxMOUSE_BTN_MIDDLE ) && event.MiddleIsDown() )
1009
{ m_DragMode = DRAG_START;
1012
else // wait for movement if right mouse key; might be context menu request
1014
#if defined(LOGGING)
1015
LOGIT(_T("Down delta x:%d y:%d"), scrollx, scrolly );
1017
if (p_cbStyledTextCtrl && (m_pEvtObject == p_cbStyledTextCtrl) //v0.21
1018
//-&& ( ( scrolly > 1) || (scrollx > 1) )) 2008/02/2
1019
&& ( ( scrolly > 2) || (scrollx > 2) ))
1020
{ m_DragMode = DRAG_START;
1023
// Since scrolling other types of windows doesnt work on GTK
1024
// just event.Skip()
1025
//else { // listctrl windows ALWAYS report 24 pixel y move
1026
// // when just hitting the mouse button.
1027
// if ( (scrolly > 24) || (scrollx > 1))
1028
// { m_DragMode = DRAG_START;
1032
else { // listctrl windows ALWAYS report 24 pixel y move
1033
// when just hitting the mouse button.
1034
//-if ( (scrolly > 1) || (scrollx > 1)) 2008/02/2
1035
if ( (scrolly > 2) || (scrollx > 2))
1036
{ m_DragMode = DRAG_START;
1040
}//else wait for movement
1042
//// // --------------------------------
1043
//// // Dont do the following on Linux, it kills all context menus
1044
//// // --------------------------------
1045
//// //// If hiding Right mouse keydown from ListCtrls, return v0.22
1046
//// //// RightMouseDown is causing an immediate selection in the control
1047
//// //// This stops it.
1048
//// //-if (pDS->GetMouseRightKeyCtrl()) return; removed
1049
//// //-event.Skip(); //v0.21
1052
//no mouse movements, so pass off to context menu processing
1055
}//fi (event.RightDown()
1056
//--------- Key UP -------------------------------------------------------
1057
else if (KeyUp(event) )
1060
int lastmode = m_DragMode;
1061
m_DragMode = DRAG_NONE;
1062
#if defined(LOGGING)
1065
if (lastmode == DRAG_DRAGGING) return;
1066
// allow non-drag processing
1069
}//fi (event.RighUp)
1070
//--------- DRAGGING -----------------------------------------------------
1071
else if ( (m_DragMode!=DRAG_NONE) && event.Dragging() ) //v0.12
1074
//-LOGIT( _T("Dragging") ) ;
1075
//make sure user didnt leave client area and lift mouse key
1076
if ( not KeyIsDown(event))
1077
{ m_DragMode = DRAG_NONE;
1081
////allow user some slop moves in case this is a "moving" context menu request
1082
//if ( ! m_MouseHasMoved
1083
// && abs(event.GetPosition().x - m_InitX) < 3
1084
// && abs(event.GetPosition().y - m_InitY) < 3)
1086
//else m_DragMode = DRAG_START;//v0.12
1088
if (m_DragMode == DRAG_START)
1090
// Start the drag. This will stop the context popup
1091
#if defined(LOGGING)
1092
LOGIT(_T("Drag_Start"));
1094
m_DragMode = DRAG_DRAGGING;
1097
m_MouseHasMoved = true;
1098
int dX = event.GetPosition().x - m_StartX;
1099
int dY = event.GetPosition().y - m_StartY;
1101
//set ration of mouse moves to lines scrolled (currently 30 percent)
1102
m_RatioX = m_RatioY = m_MouseMoveToLineMoveRatio;
1103
// build up some mouse movements to guarantee ratios won't cancel scrolling
1104
if ( (abs(dX)*m_RatioX >= 1) || (abs(dY)*m_RatioY >= 1) )
1105
{ m_StartY = event.GetPosition().y; m_StartX = event.GetPosition().x;}
1107
//add one full mousemove for every x mouse positions beyond start position
1108
//so scrolling is faster as user is faster
1109
// slider values 1...2...3...4...5...6...7...8...9...10 //v0.14
1110
// divisn values 90 80 70 60 50 40 30 20 10 1
1111
int nThreshold = 1+( 100-(pDS->GetMouseDragSensitivity()*10) );
1112
m_RatioX += (abs(dX)/nThreshold);
1113
m_RatioY += (abs(dY)/nThreshold);
1115
// scroll the client area
1116
if (abs(dX) > abs(dY))
1118
scrolly = 0; scrollx = int(dX * m_RatioX);
1122
scrollx = 0; scrolly = int(dY * m_RatioY);
1124
#if defined(LOGGING)
1125
// LOGIT(_T("RatioX:%f RatioY:%f"), m_RatioX, m_RatioY);
1126
// LOGIT(_T("Drag: dX:%d dY:%d scrollx:%d scrolly:%d"), dX, dY, scrollx, scrolly);
1129
// Scroll horizontally and vertically.
1130
// void LineScroll (int columns, int lines);
1131
if ((scrollx==0) && (scrolly==0)) return;
1132
scrollx *= m_Direction; scrolly *= m_Direction;
1135
// if editor window, use scintilla scroll
1136
if (p_cbStyledTextCtrl && (m_pEvtObject == p_cbStyledTextCtrl))
1138
p_cbStyledTextCtrl->LineScroll (scrollx,scrolly);
1140
else //use control scrolling
1142
// //Returns the string form of the class name.
1143
// const wxChar* pClassName = 0;
1144
// wxString classname;
1145
// if (m_pEvtObject)
1146
// { pClassName = m_pEvtObject->GetClassInfo()->GetClassName();
1147
// classname = wxString(pClassName,10);
1148
// LOGIT( _T("ClassName[%s]"), classname.c_str() );
1150
// ---------------------------------
1151
//The following works in the BuildLog, but now the SearchResults
1152
// ---------------------------------
1153
//use wxTextCtrl scroll for y scrolling
1154
if ( scrolly )//&& (classname == wxT("wxTextCtrl")) )
1155
{ //LOGIT(wxT("ScrollText x:%d y:%d"),scrollx, scrolly );
1156
((wxWindow*)m_pEvtObject)->ScrollLines(scrolly);
1158
// Following does not work. GTK does not scroll wxListCtrl
1159
//else // use listCtrl for x scrolling
1160
//{ LOGIT(wxT("ScrollList x:%d y:%d"),scrollx, scrolly );
1161
// ((wxListCtrl*)m_pEvtObject)->ScrollList(scrollx,scrolly);
1164
}//esle fi (event.Dragging() && m_dragMode != DRAG_NONE)
1166
// pass on the event
1170
#endif //__WXGTK__ scrolling
1171
// ----------------------------------------------------------------------------
1172
// end __WXGTK__ scrolling
1173
// ----------------------------------------------------------------------------