~skiter23/codeblocks/Stable

« back to all changes in this revision

Viewing changes to plugins/contrib/dragscroll/dragscroll.cpp

  • Committer: skiter
  • Date: 2008-04-13 02:17:50 UTC
  • Revision ID: skiter@anonymous-20080413021750-idptbpxvdui6ms6y
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************
 
2
 * Name:      dragscroll.cpp
 
3
 * Purpose:   Code::Blocks plugin
 
4
 * Author:    Pecan<>
 
5
 * Copyright: (c) Pecan
 
6
 * License:   GPL
 
7
 **************************************************************/
 
8
 
 
9
#if defined(__GNUG__) && !defined(__APPLE__)
 
10
        #pragma implementation "dragscroll.h"
 
11
#endif
 
12
 
 
13
 
 
14
#include <sdk.h>
 
15
#ifndef CB_PRECOMP
 
16
        #include <wx/intl.h>
 
17
        #include <wx/listctrl.h>
 
18
        #include "cbeditor.h"
 
19
        #include "configmanager.h"
 
20
        #include "editormanager.h"
 
21
        #include "manager.h"
 
22
        #include "personalitymanager.h"
 
23
        #include "sdk_events.h" // EVT_APP_STARTUP_DONE
 
24
#endif
 
25
#include <wx/fileconf.h> // wxFileConfig
 
26
#include "cbstyledtextctrl.h"
 
27
#include "dragscroll.h"
 
28
#include "dragscrollcfg.h"
 
29
 
 
30
// Register the plugin
 
31
namespace
 
32
{
 
33
    PluginRegistrant<cbDragScroll> reg(_T("cbDragScroll"));
 
34
};
 
35
 
 
36
int ID_DLG_DONE = wxNewId();
 
37
 
 
38
// ----------------------------------------------------------------------------
 
39
BEGIN_EVENT_TABLE(cbDragScroll, cbPlugin)
 
40
        // add events here...
 
41
    EVT_UPDATE_UI(ID_DLG_DONE, cbDragScroll::OnDoConfigRequests)
 
42
END_EVENT_TABLE()
 
43
// ----------------------------------------------------------------------------
 
44
//  Statics
 
45
// ----------------------------------------------------------------------------
 
46
// global used by mouse events to get user configuration settings
 
47
cbDragScroll* cbDragScroll::pDragScroll;
 
48
 
 
49
// ----------------------------------------------------------------------------
 
50
cbDragScroll::cbDragScroll()
 
51
// ----------------------------------------------------------------------------
 
52
{
 
53
        //ctor
 
54
        // anchor to this one and only object
 
55
    pDragScroll = this;
 
56
}
 
57
// ----------------------------------------------------------------------------
 
58
cbDragScroll::~cbDragScroll()
 
59
// ----------------------------------------------------------------------------
 
60
{
 
61
        //dtor
 
62
}
 
63
 
 
64
// ----------------------------------------------------------------------------
 
65
void cbDragScroll::OnAttach()
 
66
// ----------------------------------------------------------------------------
 
67
{
 
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...
 
74
 
 
75
    pMyLog = NULL;
 
76
    m_bNotebooksAttached = false;
 
77
 
 
78
    wxWindow* pcbWindow = Manager::Get()->GetAppWindow();
 
79
    m_pMS_Window = pcbWindow;
 
80
    #if defined(LOGGING)
 
81
        wxLog::EnableLogging(true);
 
82
        /*wxLogWindow**/ pMyLog = new wxLogWindow(pcbWindow, wxT("DragScroll"), true, false);
 
83
        wxLog::SetActiveTarget(pMyLog);
 
84
        pMyLog->Flush();
 
85
        pMyLog->GetFrame()->Move(20,20);
 
86
        wxLogMessage(_T("Logging cbDragScroll version %s"),wxString(wxT(VERSION)).c_str());
 
87
        #endif
 
88
 
 
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"));
 
98
 
 
99
    MouseDragScrollEnabled  = true;
 
100
    MouseEditorFocusEnabled = false;
 
101
    MouseFocusEnabled       = false;
 
102
    MouseDragDirection      = 0;
 
103
    MouseDragKey            = 0;
 
104
    MouseDragSensitivity    = 5;
 
105
    MouseToLineRatio        = 30;
 
106
    //-MouseRightKeyCtrl       = 0 ;
 
107
    MouseContextDelay       = 10;
 
108
 
 
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);
 
114
 
 
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("/"));
 
119
 
 
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() );
 
124
 
 
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");
 
130
 
 
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");
 
136
    }
 
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);
 
144
 
 
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) ;
 
154
 
 
155
        // Don't allow less than 10 mils on context/scroll delay.
 
156
        if ( MouseContextDelay < 10) { MouseContextDelay = 10;}
 
157
 
 
158
    #ifdef LOGGING
 
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 ) ;
 
168
    #endif //LOGGING
 
169
 
 
170
    // Pointer to "Search Results" Window (first listCtrl window)
 
171
    m_pSearchResultsWindow = 0;
 
172
 
 
173
    // Catch creation of windows
 
174
    Connect( wxEVT_CREATE,
 
175
        (wxObjectEventFunction) (wxEventFunction)
 
176
        (wxCommandEventFunction) &cbDragScroll::OnWindowOpen);
 
177
 
 
178
    // Catch Destroyed windows
 
179
    Connect( wxEVT_DESTROY,
 
180
        (wxObjectEventFunction) (wxEventFunction)
 
181
        (wxCommandEventFunction) &cbDragScroll::OnWindowClose);
 
182
 
 
183
    // Set current plugin version
 
184
        PluginInfo* pInfo = (PluginInfo*)(Manager::Get()->GetPluginManager()->GetPluginInfo(this));
 
185
        pInfo->version = wxT(VERSION);
 
186
 
 
187
        // register event sink
 
188
    Manager::Get()->RegisterEventSink(cbEVT_APP_STARTUP_DONE, new cbEventFunctor<cbDragScroll, CodeBlocksEvent>(this, &cbDragScroll::OnAppStartupDone));
 
189
 
 
190
        return ;
 
191
}
 
192
// ----------------------------------------------------------------------------
 
193
void cbDragScroll::OnRelease(bool appShutDown)
 
194
// ----------------------------------------------------------------------------
 
195
{
 
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...
 
201
 
 
202
        // Remove all Mouse event handlers
 
203
        DetachAll();
 
204
}
 
205
// ----------------------------------------------------------------------------
 
206
cbConfigurationPanel* cbDragScroll::GetConfigurationPanel(wxWindow* parent)
 
207
// ----------------------------------------------------------------------------
 
208
{
 
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
 
212
 
 
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 );
 
225
 
 
226
 
 
227
    // when the configuration panel is closed with OK, OnDialogDone() will be called
 
228
    return pDlg;
 
229
}
 
230
// ----------------------------------------------------------------------------
 
231
void cbDragScroll::OnDialogDone(cbDragScrollCfg* pDlg)
 
232
// ----------------------------------------------------------------------------
 
233
{
 
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.
 
236
 
 
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();
 
246
    #ifdef LOGGING
 
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("-----------------------------"));
 
257
    #endif //LOGGING
 
258
 
 
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);
 
264
 
 
265
    // don't delete dlg; Codeblocks should destroy the dialog
 
266
 
 
267
}//OnDialogDone
 
268
// ----------------------------------------------------------------------------
 
269
void cbDragScroll::OnDoConfigRequests(wxUpdateUIEvent& event)
 
270
// ----------------------------------------------------------------------------
 
271
{
 
272
    // This is an event triggered by OnDialogDone() to update config settings
 
273
 
 
274
    LOGIT(_T("OnDoConfigRequest event"));
 
275
 
 
276
    // Attach or Detach windows to match  Mouse Enabled config setting
 
277
    if (GetMouseDragScrollEnabled() )  //v04.14
 
278
    {   if (not m_bNotebooksAttached)
 
279
        {
 
280
            AttachRecursively(Manager::Get()->GetAppWindow());
 
281
            m_bNotebooksAttached = true;
 
282
        }
 
283
    }//fi
 
284
    else {
 
285
        DetachAll();
 
286
        m_bNotebooksAttached = false;
 
287
    }//esle
 
288
 
 
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);
 
295
 
 
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 ) ;
 
305
 
 
306
}
 
307
// ----------------------------------------------------------------------------
 
308
bool cbDragScroll::IsAttachedTo(wxWindow* p)
 
309
// ----------------------------------------------------------------------------
 
310
 
 
311
{
 
312
    if ( wxNOT_FOUND == m_EditorPtrs.Index(p))
 
313
        return false;
 
314
    return true;
 
315
 
 
316
}//IsAttachedTo
 
317
// ----------------------------------------------------------------------------
 
318
void cbDragScroll::Attach(wxWindow *p)
 
319
// ----------------------------------------------------------------------------{
 
320
{
 
321
        if (!p || IsAttachedTo(p))
 
322
                return;         // already attached !!!
 
323
 
 
324
    // allow only static windows to be attached by codeblocks
 
325
    // Disappearing frames/windows cause crashes
 
326
    // eg., wxArrayString m_UsableWindows = "sciwindow notebook";
 
327
 
 
328
    wxString windowName = p->GetName().MakeLower();
 
329
 
 
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;
 
334
        #ifdef LOGGING
 
335
         LOGIT(wxT("SearchResultsWindow: %p"),p );
 
336
        #endif
 
337
    }
 
338
 
 
339
    if (wxNOT_FOUND == m_UsableWindows.Index(windowName,false))
 
340
     {
 
341
        LOGIT(wxT("cbDS::Attach skipping [%s]"), p->GetName().c_str());
 
342
        return;
 
343
     }
 
344
 
 
345
    LOGIT(wxT("cbDS::Attach - attaching to [%s] %p"), p->GetName().c_str(),p);
 
346
 
 
347
    //add window to our array, create a mouse event handler
 
348
    // and memorize event handler instance
 
349
    m_EditorPtrs.Add(p);
 
350
    MyMouseEvents* thisEvtHndlr = new MyMouseEvents(p);
 
351
    m_EventHandlerArray.Add(thisEvtHndlr);
 
352
 
 
353
    p->Connect(wxEVT_MIDDLE_DOWN,
 
354
                    (wxObjectEventFunction)(wxEventFunction)
 
355
                    (wxMouseEventFunction)&MyMouseEvents::OnMouseEvent,
 
356
                     NULL, thisEvtHndlr);
 
357
    p->Connect(wxEVT_MIDDLE_UP,
 
358
                    (wxObjectEventFunction)(wxEventFunction)
 
359
                    (wxMouseEventFunction)&MyMouseEvents::OnMouseEvent,
 
360
                     NULL, thisEvtHndlr);
 
361
    p->Connect(wxEVT_RIGHT_DOWN,
 
362
                    (wxObjectEventFunction)(wxEventFunction)
 
363
                    (wxMouseEventFunction)&MyMouseEvents::OnMouseEvent,
 
364
                     NULL, thisEvtHndlr);
 
365
    p->Connect(wxEVT_RIGHT_UP,
 
366
                    (wxObjectEventFunction)(wxEventFunction)
 
367
                    (wxMouseEventFunction)&MyMouseEvents::OnMouseEvent,
 
368
                     NULL, thisEvtHndlr);
 
369
    p->Connect(wxEVT_MOTION,
 
370
                    (wxObjectEventFunction)(wxEventFunction)
 
371
                    (wxMouseEventFunction)&MyMouseEvents::OnMouseEvent,
 
372
                     NULL, thisEvtHndlr);
 
373
    p->Connect(wxEVT_ENTER_WINDOW,
 
374
                    (wxObjectEventFunction)(wxEventFunction)
 
375
                    (wxMouseEventFunction)&MyMouseEvents::OnMouseEvent,
 
376
                     NULL, thisEvtHndlr);
 
377
 
 
378
    #if defined(LOGGING)
 
379
     LOGIT(_T("cbDS:Attach Window:%p Handler:%p"), p,thisEvtHndlr);
 
380
    #endif
 
381
}
 
382
 
 
383
// ----------------------------------------------------------------------------
 
384
void cbDragScroll::AttachRecursively(wxWindow *p)
 
385
// ----------------------------------------------------------------------------{
 
386
{
 
387
        if (!p)
 
388
                return;
 
389
 
 
390
        Attach(p);
 
391
 
 
392
        // this is the standard way wxWidgets uses to iterate through children...
 
393
        for (wxWindowList::compatibility_iterator node = p->GetChildren().GetFirst();
 
394
                node;
 
395
                node = node->GetNext())
 
396
        {
 
397
                // recursively attach each child
 
398
                wxWindow *win = (wxWindow *)node->GetData();
 
399
 
 
400
                if (win)
 
401
                        AttachRecursively(win);
 
402
        }
 
403
}
 
404
// ----------------------------------------------------------------------------
 
405
wxWindow* cbDragScroll::FindWindowRecursively(const wxWindow* parent, const wxWindow* handle)
 
406
// ----------------------------------------------------------------------------{
 
407
{//+v0.4.4
 
408
    if ( parent )
 
409
    {
 
410
        // see if this is the one we're looking for
 
411
        if ( parent == handle )
 
412
            return (wxWindow *)parent;
 
413
 
 
414
        // It wasn't, so check all its children
 
415
        for ( wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst();
 
416
              node;
 
417
              node = node->GetNext() )
 
418
        {
 
419
            // recursively check each child
 
420
            wxWindow *win = (wxWindow *)node->GetData();
 
421
            wxWindow *retwin = FindWindowRecursively(win, handle);
 
422
            if (retwin)
 
423
                return retwin;
 
424
        }
 
425
    }
 
426
 
 
427
    // Not found
 
428
    return NULL;
 
429
}
 
430
// ----------------------------------------------------------------------------
 
431
wxWindow* cbDragScroll::winExists(wxWindow *parent)
 
432
// ----------------------------------------------------------------------------{
 
433
{ //+v0.4.4
 
434
 
 
435
    if ( !parent )
 
436
    {
 
437
        return NULL;
 
438
    }
 
439
 
 
440
    // start at very top of wx's windows
 
441
    for ( wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
 
442
          node;
 
443
          node = node->GetNext() )
 
444
    {
 
445
        // recursively check each window & its children
 
446
        wxWindow* win = node->GetData();
 
447
        wxWindow* retwin = FindWindowRecursively(win, parent);
 
448
        if (retwin)
 
449
            return retwin;
 
450
    }
 
451
 
 
452
    return NULL;
 
453
}//winExists
 
454
// ----------------------------------------------------------------------------
 
455
void cbDragScroll::Detach(wxWindow* thisEditor)
 
456
// ----------------------------------------------------------------------------
 
457
{
 
458
    if ( (thisEditor) && (m_EditorPtrs.Index(thisEditor) != wxNOT_FOUND))
 
459
    {
 
460
         #if defined(LOGGING)
 
461
          LOGIT(_T("cbDS:Detaching %p"), thisEditor);
 
462
         #endif
 
463
 
 
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);
 
468
 
 
469
        // If win already deleted, dont worry about receiving events
 
470
            if ( not winExists(thisEditor) )
 
471
            {
 
472
                LOGIT(_T("cbDS:DetachAll window NOT found %p Handlr: %p"),
 
473
                    thisEditor, thisEvtHandler);
 
474
            } else {
 
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);
 
499
        }//fi (not winExists
 
500
 
 
501
        delete(thisEvtHandler);
 
502
 
 
503
        #if defined(LOGGING)
 
504
         LOGIT(_T("Detach: Editor:%p EvtHndlr: %p"),thisEditor,thisEvtHandler);
 
505
        #endif
 
506
    }//if (thisEditor..
 
507
}//Detach
 
508
// ----------------------------------------------------------------------------
 
509
void cbDragScroll::DetachAll()
 
510
// ----------------------------------------------------------------------------
 
511
{
 
512
        // delete all handlers
 
513
        LOGIT(wxT("cbDS:DetachAll - detaching all [%d] targets"),m_EditorPtrs.GetCount() );
 
514
 
 
515
    // Detach from memorized windows and remove event handlers
 
516
    while( m_EditorPtrs.GetCount() )
 
517
    {
 
518
            wxWindow* pw = (wxWindow*)m_EditorPtrs.Item(0);
 
519
        Detach(pw);
 
520
    }//elihw
 
521
 
 
522
    m_EditorPtrs.Empty();
 
523
 
 
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++)
 
528
        {
 
529
            MyMouseEvents* pHdlr = (MyMouseEvents*)m_EventHandlerArray.Item(i);
 
530
            delete pHdlr;
 
531
        LOGIT(_T("cbDS:DetachAll - Removing Leaked EventHdl:[%p]"), pHdlr );
 
532
        }//rof
 
533
 
 
534
    m_EventHandlerArray.Empty();
 
535
    // say no windows attached
 
536
    m_bNotebooksAttached = false;
 
537
    m_pSearchResultsWindow = 0;
 
538
    return;
 
539
 
 
540
}//DetachAll
 
541
// ----------------------------------------------------------------------------
 
542
wxString cbDragScroll::FindAppPath(const wxString& argv0, const wxString& cwd, const wxString& appVariableName)
 
543
// ----------------------------------------------------------------------------
 
544
{
 
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.
 
550
 
 
551
    wxString str;
 
552
 
 
553
    // Try appVariableName
 
554
    if (!appVariableName.IsEmpty())
 
555
    {
 
556
        str = wxGetenv(appVariableName);
 
557
        if (!str.IsEmpty())
 
558
            return str;
 
559
    }
 
560
 
 
561
#if defined(__WXMAC__) && !defined(__DARWIN__)
 
562
    // On Mac, the current directory is the relevant one when
 
563
    // the application starts.
 
564
    return cwd;
 
565
#endif
 
566
 
 
567
    if (wxIsAbsolutePath(argv0))
 
568
        return wxPathOnly(argv0);
 
569
    else
 
570
    {
 
571
        // Is it a relative path?
 
572
        wxString currentDir(cwd);
 
573
        if (currentDir.Last() != wxFILE_SEP_PATH)
 
574
            currentDir += wxFILE_SEP_PATH;
 
575
 
 
576
        str = currentDir + argv0;
 
577
        if (wxFileExists(str))
 
578
            return wxPathOnly(str);
 
579
    }
 
580
 
 
581
    // OK, it's neither an absolute path nor a relative path.
 
582
    // Search PATH.
 
583
 
 
584
    wxPathList pathList;
 
585
    pathList.AddEnvList(wxT("PATH"));
 
586
    str = pathList.FindAbsoluteValidPath(argv0);
 
587
    if (!str.IsEmpty())
 
588
        return wxPathOnly(str);
 
589
 
 
590
    // Failed
 
591
    return wxEmptyString;
 
592
}
 
593
// ----------------------------------------------------------------------------
 
594
 
 
595
// ----------------------------------------------------------------------------
 
596
//    cbDragScroll Routines to push/remove mouse event handlers
 
597
// ----------------------------------------------------------------------------
 
598
void cbDragScroll::OnAppStartupDone(CodeBlocksEvent& event)
 
599
// ----------------------------------------------------------------------------
 
600
{
 
601
    // EVT_APP_STARTUP_DONE
 
602
    //attach windows
 
603
    LOGIT(_T("AppStartupDone"));
 
604
 
 
605
    OnAppStartupDoneInit();
 
606
 
 
607
    event.Skip();
 
608
    return;
 
609
}//OnAppStartupDone
 
610
// ----------------------------------------------------------------------------
 
611
void cbDragScroll::OnAppStartupDoneInit()
 
612
// ----------------------------------------------------------------------------
 
613
{
 
614
    if (not GetMouseDragScrollEnabled() )    //v04.14
 
615
        return;
 
616
 
 
617
    if (! m_bNotebooksAttached)
 
618
    {
 
619
        AttachRecursively(Manager::Get()->GetAppWindow());
 
620
        m_bNotebooksAttached = true;
 
621
    }
 
622
}
 
623
// ----------------------------------------------------------------------------
 
624
void cbDragScroll::OnWindowOpen(wxEvent& event)
 
625
// ----------------------------------------------------------------------------
 
626
{
 
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
 
630
 
 
631
    wxWindow* pWindow = (wxWindow*)(event.GetEventObject());
 
632
 
 
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();
 
639
 
 
640
    // Attach a split window (or any other window)
 
641
    if ( m_bNotebooksAttached )
 
642
    {
 
643
        wxWindow* pWindow = (wxWindow*)(event.GetEventObject());
 
644
        cbEditor* ed = 0;
 
645
        ed  = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
 
646
        if (ed)
 
647
        {
 
648
            if (pWindow->GetParent() ==  ed)
 
649
            {   Attach(pWindow);
 
650
                #ifdef LOGGING
 
651
                    LOGIT( _T("OnWindowOpen Attached:%p name: %s"),
 
652
                            pWindow, pWindow->GetName().GetData() );
 
653
                #endif //LOGGING
 
654
            }
 
655
        }//fi (ed)
 
656
    }//fi m_bNote...
 
657
 
 
658
    event.Skip();
 
659
}//OnWindowOpen
 
660
// ----------------------------------------------------------------------------
 
661
void cbDragScroll::OnWindowClose(wxEvent& event)
 
662
// ----------------------------------------------------------------------------
 
663
{
 
664
    // wxEVT_DESTROY entry
 
665
 
 
666
    wxWindow* pWindow = (wxWindow*)(event.GetEventObject());
 
667
 
 
668
    if ( (pWindow) && (m_EditorPtrs.Index(pWindow) != wxNOT_FOUND))
 
669
    {   // window is one of ours
 
670
        Detach(pWindow);
 
671
        #ifdef LOGGING
 
672
         LOGIT( _T("OnWindowClose Detached %p"), pWindow);
 
673
        #endif //LOGGING
 
674
    }
 
675
    event.Skip();
 
676
}//OnWindowClose
 
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
 
686
    // window.
 
687
END_EVENT_TABLE()
 
688
// ----------------------------------------------------------------------------
 
689
MyMouseEvents::~MyMouseEvents()
 
690
{
 
691
    #if defined(LOGGING)
 
692
     LOGIT(_T("MyMouseEvents dtor"));
 
693
    #endif
 
694
    return;
 
695
}//dtor
 
696
 
 
697
///////////////////////////////////////////////////////////////////////////////
 
698
// ----------------------------------------------------------------------------
 
699
//      MOUSE SCROLLING for __WXMSW__
 
700
// ----------------------------------------------------------------------------
 
701
///////////////////////////////////////////////////////////////////////////////
 
702
#ifdef __WXMSW__
 
703
// ----------------------------------------------------------------------------
 
704
void MyMouseEvents::OnMouseEvent(wxMouseEvent& event)    //MSW
 
705
// ----------------------------------------------------------------------------
 
706
{
 
707
 
 
708
    //remember event window pointer
 
709
    m_pEvtObject = event.GetEventObject();
 
710
    cbDragScroll* pDS = cbDragScroll::pDragScroll;
 
711
 
 
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;}
 
715
 
 
716
    // For efficiency, skip wheel events now
 
717
    if ( event.GetEventType() ==  wxEVT_MOUSEWHEEL)
 
718
        { event.Skip(); return; }
 
719
 
 
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();
 
727
    }
 
728
 
 
729
    // differentiate window, left, right split window
 
730
    cbEditor* ed = 0;
 
731
    cbStyledTextCtrl* p_cbStyledTextCtrl = 0;
 
732
    cbStyledTextCtrl* pLeftSplitWin = 0;
 
733
    cbStyledTextCtrl* pRightSplitWin = 0;
 
734
    ed  = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
 
735
    if (ed)
 
736
    {   p_cbStyledTextCtrl = ed->GetControl();
 
737
        pLeftSplitWin = ed->GetLeftSplitViewControl();
 
738
        pRightSplitWin = ed->GetRightSplitViewControl();
 
739
    }
 
740
 
 
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();
 
750
                    #ifdef LOGGING
 
751
                     //LOGIT( _T("OnMouseEvent:SetFocus Left %p"), pLeftSplitWin );
 
752
                    #endif //LOGGING
 
753
                    break;
 
754
                }
 
755
           if (pRightSplitWin && (m_pEvtObject ==  pRightSplitWin))
 
756
                if (currentFocus != (wxWindow*)m_pEvtObject)
 
757
                {   pRightSplitWin->SetFocus();
 
758
                    #ifdef LOGGING
 
759
                     //LOGIT( _T("OnMouseEvent:SetFocus Right %p"), pRightSplitWin );
 
760
                    #endif //LOGGING
 
761
                    break;
 
762
                }
 
763
        }while(0);
 
764
    }
 
765
 
 
766
    int scrollx;
 
767
    int scrolly;
 
768
 
 
769
    #if defined(LOGGING)
 
770
    //LOGIT(_T("OnMouseEvent"));
 
771
    #endif
 
772
 
 
773
    if (KeyDown(event))
 
774
    {
 
775
            m_Direction = pDS->GetMouseDragDirection() ? 1 : -1 ; //v0.14
 
776
            m_MouseMoveToLineMoveRatio = pDS->GetMouseToLineRatio()/100.0;
 
777
            #ifdef LOGGING
 
778
             //LOGIT( _T("m_MouseMoveToLineMoveRatio %f"),m_MouseMoveToLineMoveRatio );
 
779
            #endif //LOGGING
 
780
            // We tentatively start dragging, but wait for
 
781
            // mouse movement before dragging properly.
 
782
 
 
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;
 
788
 
 
789
            m_DragMode = DRAG_START;
 
790
            m_DragStartPos = event.GetPosition();
 
791
            #if defined(LOGGING)
 
792
             //LOGIT(_T("Down X:%d Y:%d"), m_InitY, m_InitX);
 
793
            #endif
 
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
 
797
            return;
 
798
    }// if KeyDown
 
799
 
 
800
    else if (KeyUp(event) && (m_DragMode != DRAG_NONE) )
 
801
    {
 
802
        // Finish dragging
 
803
        int lastmode = m_DragMode;
 
804
        m_DragMode = DRAG_NONE;
 
805
        // if our trapped drag, hide event from others, ie. don't event.skip()
 
806
        #if defined(LOGGING)
 
807
         //LOGIT(_T("Up"));
 
808
        #endif
 
809
        if (lastmode ==  DRAG_DRAGGING) return;
 
810
        // allow context menu processing
 
811
        event.Skip();
 
812
        return;
 
813
    }// if KeyUp
 
814
 
 
815
    else if ( event.Dragging() && (m_DragMode != DRAG_NONE ) )
 
816
    {
 
817
        //make sure user didnt leave client area and lift mouse key
 
818
        if ( not KeyIsDown(event))
 
819
         {  m_DragMode = DRAG_NONE;
 
820
            return;
 
821
         }
 
822
 
 
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)
 
827
        {  return;}
 
828
 
 
829
        //+v0.6 code moved here to allow sloppier context menu requests
 
830
        if (m_DragMode == DRAG_START)
 
831
         {
 
832
            // Start the drag. This will stop the context popup
 
833
            #if defined(LOGGING)
 
834
              //LOGIT(_T("Drag_Start"));
 
835
            #endif
 
836
            m_DragMode = DRAG_DRAGGING;
 
837
         }
 
838
 
 
839
        m_MouseHasMoved = true;
 
840
        int dX = event.GetPosition().x - m_StartX;
 
841
        int dY = event.GetPosition().y - m_StartY;
 
842
 
 
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;}
 
848
 
 
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);
 
856
 
 
857
        // scroll the client area
 
858
        if (abs(dX) > abs(dY))
 
859
        {
 
860
            scrolly = 0; scrollx = int(dX * m_RatioX);
 
861
        }
 
862
        else
 
863
        {
 
864
            scrollx = 0; scrolly = int(dY * m_RatioY);
 
865
        }
 
866
        #if defined(LOGGING)
 
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);
 
869
        #endif
 
870
 
 
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;
 
875
 
 
876
        // if editor window, use scintilla scroll
 
877
        if (p_cbStyledTextCtrl && (m_pEvtObject == p_cbStyledTextCtrl))
 
878
        {
 
879
                p_cbStyledTextCtrl->LineScroll (scrollx,scrolly);
 
880
        }
 
881
        else //use control scrolling
 
882
        {
 
883
            //use wxTextCtrl scroll for y scrolling
 
884
            if ( scrolly)
 
885
                ((wxWindow*)m_pEvtObject)->ScrollLines(scrolly);
 
886
            else  // use listCtrl for x scrolling
 
887
                ((wxListCtrl*)m_pEvtObject)->ScrollList(scrollx<<2,scrolly);
 
888
        }//else
 
889
    }//else if ( event.Dragging() && (m_DragMode != DRAG_NONE )
 
890
 
 
891
    // pass the event onward
 
892
    event.Skip();
 
893
 
 
894
}//OnMouseEvent
 
895
#endif //__WXMSW__ scroling
 
896
 
 
897
///////////////////////////////////////////////////////////////////////////////
 
898
// ----------------------------------------------------------------------------
 
899
//      __WXGTK__ MOUSE SCROLLING __WXGTK__
 
900
// ----------------------------------------------------------------------------
 
901
///////////////////////////////////////////////////////////////////////////////
 
902
#if defined(__WXGTK__) || defined(__WXMAC__)
 
903
// ----------------------------------------------------------------------------
 
904
void MyMouseEvents::OnMouseEvent(wxMouseEvent& event)    //GTK
 
905
// ----------------------------------------------------------------------------
 
906
{
 
907
 
 
908
    // For efficiency, skip wheel events now
 
909
    if ( event.GetEventType() ==  wxEVT_MOUSEWHEEL)
 
910
        { event.Skip(); return; }
 
911
 
 
912
    //remember window pointer
 
913
    m_pEvtObject = event.GetEventObject();
 
914
    cbDragScroll* pDS = cbDragScroll::pDragScroll;
 
915
 
 
916
    #ifdef LOGGING
 
917
     //LOGIT( _T("m_MouseMoveToLineMoveRatio %f"),m_MouseMoveToLineMoveRatio );
 
918
    #endif //LOGGING
 
919
 
 
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();
 
926
    }
 
927
 
 
928
    cbEditor* ed = 0;
 
929
    cbStyledTextCtrl* p_cbStyledTextCtrl = 0;
 
930
    cbStyledTextCtrl* pLeftSplitWin = 0;
 
931
    cbStyledTextCtrl* pRightSplitWin = 0;
 
932
    ed  = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
 
933
    if (ed)
 
934
    {   p_cbStyledTextCtrl = ed->GetControl();
 
935
        pLeftSplitWin = ed->GetLeftSplitViewControl();
 
936
        pRightSplitWin = ed->GetRightSplitViewControl();
 
937
    }
 
938
 
 
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();
 
948
                    #ifdef LOGGING
 
949
                     //LOGIT( _T("OnMouseEvent:SetFocus Left %p"), pLeftSplitWin );
 
950
                    #endif //LOGGING
 
951
                    break;
 
952
                }
 
953
           if (pRightSplitWin && (m_pEvtObject ==  pRightSplitWin))
 
954
                if (currentFocus != (wxWindow*)m_pEvtObject)
 
955
                {   pRightSplitWin->SetFocus();
 
956
                    #ifdef LOGGING
 
957
                     //LOGIT( _T("OnMouseEvent:SetFocus Right %p"), pRightSplitWin );
 
958
                    #endif //LOGGING
 
959
                    break;
 
960
                }
 
961
        }while(0);
 
962
    }
 
963
 
 
964
    int scrollx;
 
965
    int scrolly;
 
966
 
 
967
    #if defined(LOGGING)
 
968
     //LOGIT(_T("OnMouseEvent"));
 
969
    #endif
 
970
 
 
971
    //--------- Key Down ------------------------------------------------------
 
972
    if (KeyDown(event))
 
973
     {
 
974
        m_Direction = pDS->GetMouseDragDirection() ? 1 : -1 ; //v0.14
 
975
        m_MouseMoveToLineMoveRatio = pDS->GetMouseToLineRatio()/100.0;
 
976
 
 
977
        // We tentatively start dragging, but wait for
 
978
        // mouse movement before dragging properly.
 
979
 
 
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;
 
985
 
 
986
        m_DragMode = DRAG_NONE;
 
987
        m_DragStartPos = event.GetPosition();
 
988
        #if defined(LOGGING)
 
989
         LOGIT(_T("Down at  X:%d Y:%d"), m_InitX, m_InitY);
 
990
        #endif
 
991
 
 
992
        wxPoint mouseXY = ((wxWindow*)m_pEvtObject)->ScreenToClient(wxGetMousePosition());
 
993
        LOGIT(_T("Down MoveTo X:%d Y:%d"), mouseXY.x, mouseXY.y);
 
994
 
 
995
        // wait for possible mouse moves before poping context menu
 
996
        for (int i = 0; i < pDS->GetMouseContextDelay();)
 
997
        {
 
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;
 
1004
            i += 10;
 
1005
        }
 
1006
 
 
1007
        // capture middle mouse key for immediate dragging
 
1008
        if ( (GetUserDragKey() ==  wxMOUSE_BTN_MIDDLE ) && event.MiddleIsDown() )
 
1009
        {   m_DragMode = DRAG_START;
 
1010
            return;
 
1011
        }
 
1012
        else // wait for movement if right mouse key; might be context menu request
 
1013
        {
 
1014
            #if defined(LOGGING)
 
1015
             LOGIT(_T("Down delta x:%d y:%d"), scrollx, scrolly );
 
1016
            #endif
 
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;
 
1021
                return;
 
1022
            }
 
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;
 
1029
            //        return;
 
1030
            //    }
 
1031
            //}//endelse
 
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;
 
1037
                    return;
 
1038
                }
 
1039
            }//endelse
 
1040
        }//else wait for movement
 
1041
 
 
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
 
1050
        ////        //-return;
 
1051
 
 
1052
        //no mouse movements, so pass off to context menu processing
 
1053
        event.Skip();
 
1054
        return;
 
1055
    }//fi (event.RightDown()
 
1056
    //--------- Key UP -------------------------------------------------------
 
1057
    else if (KeyUp(event) )
 
1058
     {
 
1059
        // Finish dragging
 
1060
        int lastmode = m_DragMode;
 
1061
        m_DragMode = DRAG_NONE;
 
1062
        #if defined(LOGGING)
 
1063
         LOGIT( _T("Up") ) ;
 
1064
        #endif
 
1065
        if (lastmode ==  DRAG_DRAGGING) return;
 
1066
        // allow non-drag processing
 
1067
        event.Skip();
 
1068
        return;
 
1069
     }//fi (event.RighUp)
 
1070
    //--------- DRAGGING  -----------------------------------------------------
 
1071
    else if ( (m_DragMode!=DRAG_NONE) && event.Dragging() ) //v0.12
 
1072
    {
 
1073
 
 
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;
 
1078
            return;
 
1079
         }
 
1080
 
 
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)
 
1085
        //{  return;}
 
1086
        //else m_DragMode = DRAG_START;//v0.12
 
1087
 
 
1088
        if (m_DragMode == DRAG_START)
 
1089
         {
 
1090
            // Start the drag. This will stop the context popup
 
1091
            #if defined(LOGGING)
 
1092
            LOGIT(_T("Drag_Start"));
 
1093
            #endif
 
1094
            m_DragMode = DRAG_DRAGGING;
 
1095
         }
 
1096
 
 
1097
       m_MouseHasMoved = true;
 
1098
       int dX = event.GetPosition().x - m_StartX;
 
1099
       int dY = event.GetPosition().y - m_StartY;
 
1100
 
 
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;}
 
1106
 
 
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);
 
1114
 
 
1115
      // scroll the client area
 
1116
      if (abs(dX) > abs(dY))
 
1117
       {
 
1118
            scrolly = 0; scrollx = int(dX * m_RatioX);
 
1119
       }
 
1120
      else
 
1121
       {
 
1122
            scrollx = 0; scrolly = int(dY * m_RatioY);
 
1123
       }
 
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);
 
1127
        #endif
 
1128
 
 
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;
 
1133
 
 
1134
 
 
1135
        // if editor window, use scintilla scroll
 
1136
        if (p_cbStyledTextCtrl && (m_pEvtObject == p_cbStyledTextCtrl))
 
1137
        {
 
1138
                p_cbStyledTextCtrl->LineScroll (scrollx,scrolly);
 
1139
        }
 
1140
        else //use control scrolling
 
1141
        {
 
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() );
 
1149
//            }
 
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);
 
1157
            }
 
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);
 
1162
            //}
 
1163
        }//esle
 
1164
    }//esle fi (event.Dragging() && m_dragMode != DRAG_NONE)
 
1165
 
 
1166
    // pass on the event
 
1167
    event.Skip();
 
1168
 
 
1169
}//OnMouseEvent
 
1170
#endif //__WXGTK__ scrolling
 
1171
// ----------------------------------------------------------------------------
 
1172
//   end __WXGTK__ scrolling
 
1173
// ----------------------------------------------------------------------------