~ubuntu-branches/ubuntu/raring/codeblocks/raring-proposed

« back to all changes in this revision

Viewing changes to src/plugins/contrib/codesnippets/snippetsconfig.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-08-09 04:38:38 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20100809043838-a59ygguym4eg0jgw
Tags: 10.05-0ubuntu1
* New upstream release. Closes (LP: #322350)
 - Switch to dpkg-source 3.0 (quilt) format
 - Remove unneeded README.source
 - Add debian/get-source-orig script that removes all
   Windows prebuilt binaries
* Bump Standards-Version to 3.9.1
 - Stop shipping *.la files
* debian/control
 - Add cdbs package as Build-Depend
 - Add libbz2-dev and zlib1g-dev packages as
   Build-Depends (needed by libhelp_plugin.so)
 - Remove dpatch package of Build-Depends
 - Add codeblocks-contrib-debug package
 - Split architecture-independent files of codeblocks
   package in codeblocks-common package
* debian/rules
 - Switch to CDBS rules system
 - Add parallel build support
 - Add a call to debian/get-source-orig script
 - Use lzma compression (saves 23,5 MB of free space)
* debian/patches
 - Refresh 01_codeblocks_plugin_path
 - Add 02_no_Makefiles_in_debian_dir to remove any link
   in codeblocks build system to deleted Makefiles of debian directory
 - Drop 02_ftbfs_gcc44 and 03_ftbfs_glib221 (merged in upstream)
* debian/watch
 - Update to use the new host (berlios.de)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
// RCS-ID: $Id: snippetsconfig.cpp 102 2007-10-29 21:16:50Z Pecan $
20
20
#ifdef WX_PRECOMP
21
21
    #include "wx_pch.h"
22
 
#else
23
22
#endif
 
23
 
 
24
    #include "pluginmanager.h"
 
25
 
24
26
    #include <wx/fileconf.h>
25
 
    #include <wx/stdpaths.h>
 
27
    #include <wx/stdpaths.h>
26
28
    #include <wx/app.h>
27
29
    #include <wx/filename.h>
28
30
 
31
33
#include "manager.h"
32
34
#include "version.h"
33
35
#include "snippetsconfig.h"
 
36
#include "seditormanager.h"
 
37
 
 
38
    // CodeSnippetsApp main menu id, but referenced in snippetproperty.cpp
 
39
    // So each has an extern to the definition here.
 
40
    //-int idMenuProperties = wxNewId();
34
41
 
35
42
    // anchor to global configuration
36
43
    CodeSnippetsConfig* g_pConfig = 0;
37
44
    CodeSnippetsConfig* GetConfig(){return g_pConfig;}
38
 
    int g_activeMenuId = 0;
 
45
    void SetConfig( CodeSnippetsConfig* p) {g_pConfig = p;}
 
46
 
 
47
    int     g_activeMenuId = 0;
39
48
    int     GetActiveMenuId(){return g_activeMenuId;}
40
 
    void    SetActiveMenuId(int menuId)
41
 
        {   g_activeMenuId = menuId;
42
 
        }
 
49
    void    SetActiveMenuId(int menuId) { g_activeMenuId = menuId; }
43
50
 
44
51
    // ------------------------------------
45
52
    // UTF8 conversion routines
69
76
// ----------------------------------------------------------------------------
70
77
{
71
78
 
72
 
    //ctor
73
 
    AppVersion SnippetVersion;
 
79
    //ctor
 
80
    AppVersion SnippetVersion;
74
81
 
75
82
    AppName = wxEmptyString;
76
 
    pMainFrame = 0;
 
83
    pMainFrame = 0;
77
84
    m_pMenuBar = 0;
78
 
    pSnippetsWindow = 0;
 
85
    pSnippetsWindow = 0;
79
86
    pSnippetsTreeCtrl = 0;
80
87
    pSnippetsSearchCtrl = 0;
81
 
    m_pCfgFile = 0;
82
88
    m_bIsPlugin = 0;
83
 
        SettingsExternalEditor = wxEmptyString;
84
 
        SettingsSnippetsCfgFullPath = wxEmptyString;
85
 
        SettingsSnippetsXmlFullPath = wxEmptyString;
86
 
        SettingsSnippetsFolder = wxEmptyString;
 
89
        SettingsExternalEditor  = wxEmptyString;
 
90
        SettingsSnippetsCfgPath = wxEmptyString;
 
91
        SettingsSnippetsXmlPath = wxEmptyString;
 
92
        SettingsSnippetsFolder  = wxEmptyString;
 
93
        SettingsCBConfigPath    = wxEmptyString;
87
94
        SettingsSearchBox = false;
 
95
        SettingsEditorsStayOnTop = true;
 
96
        SettingsToolTipsOption = true;
88
97
        m_SearchConfig.caseSensitive = false;
89
98
        m_SearchConfig.scope = SCOPE_BOTH;
90
99
    pSnipImages = 0;
94
103
    windowXpos = 0;
95
104
    windowYpos = 0;
96
105
    windowWidth = 0;
97
 
    windowHeight = 0;
 
106
    windowHeight = 0;
98
107
    m_VersionStr = SnippetVersion.GetVersion();
99
108
    m_sWindowHandle = wxEmptyString;
100
 
    SettingsWindowState = wxT("Floating");
101
 
    m_pEvtCloseConnect = 0;
 
109
    m_SettingsWindowState = wxT("Floating");
102
110
    m_bWindowStateChanged = false;
 
111
    m_pOpenFilesList = 0;
 
112
    m_pThreadSearchPlugin = 0;
 
113
    m_pDragScrollPlugin = 0;
 
114
    g_lKeepAlivePid = 0;
 
115
    m_AppParent = wxEmptyString;
 
116
 
103
117
}
104
118
 
105
119
// ----------------------------------------------------------------------------
106
120
CodeSnippetsConfig::~CodeSnippetsConfig()
107
121
// ----------------------------------------------------------------------------
108
122
{
109
 
    //dtor
110
 
        delete m_pCfgFile; // Valgrind complaint about it not being freed
111
 
 
 
123
    //dtor
112
124
}
113
 
 
114
125
// ----------------------------------------------------------------------------
115
126
void CodeSnippetsConfig::SettingsLoad()
116
127
// ----------------------------------------------------------------------------
122
133
    #ifdef LOGGING
123
134
     wxString fn(__FUNCTION__, wxConvUTF8);
124
135
     LOGIT( _T("--- [%s] ---"),fn.c_str() );
125
 
     LOGIT(wxT("Loading Settings File[%s]"),SettingsSnippetsCfgFullPath.c_str());
 
136
     LOGIT(wxT("Loading Settings File[%s]"),SettingsSnippetsCfgPath.c_str());
126
137
    #endif //LOGGING
127
138
 
128
 
    //    wxFileConfig cfgFile(wxEmptyString,       // appname
129
 
    //                        wxEmptyString,      // vendor
130
 
    //                        SettingsSnippetsCfgFullPath,      // local filename
131
 
    //                        wxEmptyString,      // global file
132
 
    //                        wxCONFIG_USE_LOCAL_FILE);
133
 
    //                        //0);
134
 
    if (m_pCfgFile)
135
 
    {   // if we dont do this, we only get in-memory cache
136
 
        // and we want the new physical file data.
137
 
         delete(m_pCfgFile);
138
 
         m_pCfgFile = 0;
139
 
    }
140
 
    if (not m_pCfgFile)
141
 
        m_pCfgFile = new wxFileConfig(
 
139
    wxFileConfig cfgFile(
142
140
                    wxEmptyString,              // appname
143
141
                    wxEmptyString,              // vendor
144
 
                    SettingsSnippetsCfgFullPath,// local filename
 
142
                    SettingsSnippetsCfgPath,// local filename
145
143
                    wxEmptyString,              // global file
146
144
                    wxCONFIG_USE_LOCAL_FILE);
147
 
                    //0);
148
 
    wxFileConfig& cfgFile = *GetCfgFile();
149
145
 
150
146
        cfgFile.Read( wxT("ExternalEditor"),  &SettingsExternalEditor, wxEmptyString ) ;
151
 
        cfgFile.Read( wxT("SnippetFile"),     &SettingsSnippetsXmlFullPath, wxEmptyString ) ;
 
147
        cfgFile.Read( wxT("SnippetFile"),     &SettingsSnippetsXmlPath, wxEmptyString ) ;
152
148
        cfgFile.Read( wxT("SnippetFolder"),   &SettingsSnippetsFolder, wxEmptyString ) ;
153
149
        cfgFile.Read( wxT("ViewSearchBox"),   &GetConfig()->SettingsSearchBox, true ) ;
154
 
        cfgFile.Read( wxT("casesensitive"),     &m_SearchConfig.caseSensitive, true ) ;
 
150
        cfgFile.Read( wxT("casesensitive"),   &m_SearchConfig.caseSensitive, true ) ;
155
151
        int nScope;
156
152
        cfgFile.Read( wxT("scope"),             &nScope, SCOPE_BOTH ) ;
157
153
    m_SearchConfig.scope = (SearchScope)nScope;
158
154
 
159
 
    // read mouse DragScrolling settings
160
 
    //cfgFile.Read(_T("MouseDragScrollEnabled"),  &MouseDragScrollEnabled ) ;
161
 
        //cfgFile.Read(_T("MouseEditorFocusEnabled"), &MouseEditorFocusEnabled ) ;
162
 
        //cfgFile.Read(_T("MouseFocusEnabled"),       &MouseFocusEnabled ) ;
163
 
        //cfgFile.Read(_T("MouseDragDirection"),      &MouseDragDirection ) ;
164
 
        //cfgFile.Read(_T("MouseDragKey"),            &MouseDragKey ) ;
165
 
        cfgFile.Read(_T("MouseDragSensitivity"),    &MouseDragSensitivity, 8 ) ;
166
 
        cfgFile.Read(_T("MouseToLineRatio"),        &MouseToLineRatio, 30 ) ;
167
 
    cfgFile.Read(_T("MouseContextDelay"),       &MouseContextDelay, 192 );
 
155
    // read Editors Stay-On-Top of main window option
 
156
    cfgFile.Read( _T("EditorsStayOnTop"), &SettingsEditorsStayOnTop, true);
 
157
    // read Editors ToolTips option
 
158
    cfgFile.Read( _T("ToolTipsOption"), &SettingsToolTipsOption, true);
 
159
 
 
160
    // Read External App state. Launched App will see it as false because
 
161
    // plugin has not set it true yet, so if this is launched App, set it true
 
162
        cfgFile.Read( wxT("ExternalPersistentOpen"), &m_IsExternalPersistentOpen, false ) ;
 
163
        if ( IsApplication() ) SetExternalPersistentOpen(true);
168
164
 
169
165
    // read user specified window state (External, Floating, or Docked)
170
 
    cfgFile.Read( wxT("WindowState"), &SettingsWindowState, wxT("Floating") );
171
 
     LOGIT( _T("WindowState[%s]"), SettingsWindowState.c_str() );
172
 
 
 
166
    cfgFile.Read( wxT("WindowState"), &m_SettingsWindowState, wxT("Floating") );
 
167
    #if defined(LOGGING)
 
168
     LOGIT( _T("WindowState[%s]"), GetSettingsWindowState().c_str() );
 
169
    #endif
173
170
    // read last window position
174
171
    wxString winPos;
175
172
    cfgFile.Read( wxT("WindowPosition"),  &winPos, wxEmptyString) ;
193
190
    LOGIT( _T("WindowPosition[%s]"),winPos.c_str() );
194
191
 
195
192
    #ifdef LOGGING
196
 
     LOGIT( _T("SettingsExternalEditor[%s]"),SettingsExternalEditor.c_str() );
197
 
     LOGIT( _T("SettingsSnippetsXmlFullPath[%s]"),SettingsSnippetsXmlFullPath.c_str() );
198
 
     LOGIT( _T("SettingsSnippetsFolder[%s]"),SettingsSnippetsFolder.c_str() );
199
 
     LOGIT( _T("SettingsSearchBox[%d]"),SettingsSearchBox );
200
 
     LOGIT( _T("caseSensitive[%d]"),m_SearchConfig.caseSensitive );
201
 
     LOGIT( _T("SettingsSnippetsXmlFullPath[%s]"),SettingsSnippetsXmlFullPath.c_str() );
 
193
     LOGIT( _T("SettingsExternalEditor[%s]"), SettingsExternalEditor.c_str() );
 
194
     LOGIT( _T("SettingsSnippetsXmlPath[%s]"),SettingsSnippetsXmlPath.c_str() );
 
195
     LOGIT( _T("SettingsSnippetsFolder[%s]"), SettingsSnippetsFolder.c_str() );
 
196
     LOGIT( _T("SettingsSearchBox[%d]"),      SettingsSearchBox );
 
197
     LOGIT( _T("caseSensitive[%d]"),            m_SearchConfig.caseSensitive );
 
198
     LOGIT( _T("SettingsSnippetsXmlPath[%s]"),  SettingsSnippetsXmlPath.c_str() );
 
199
     LOGIT( _T("SettingsEditorsStayOnTop[%s]"), SettingsEditorsStayOnTop?_T("True"):_T("False") );
 
200
     LOGIT( _T("SettingsToolTipsOption[%s]"),   SettingsToolTipsOption?_T("True"):_T("False") );
 
201
     LOGIT( _T("ExternalPersistentOpen[%s]"),   IsExternalPersistentOpen()?_T("True"):_T("False") );
202
202
    #endif //LOGGING
203
203
 
204
 
    // read windowHandle. Will be empty if this is first instance
205
 
    cfgFile.Read( wxT("WindowHandle"),  &m_sWindowHandle, wxEmptyString) ;
 
204
    // read windowHandle of last or current pgm instance that ran
 
205
    // CodeSnippetsApp will check if it's actually running
 
206
    if ( cfgFile.Exists( wxT("WindowHandle")))
 
207
        cfgFile.Read( wxT("WindowHandle"),  &m_sWindowHandle, wxEmptyString) ;
206
208
 
207
209
    // set a global snippets xml file path
208
 
    if (SettingsSnippetsXmlFullPath.IsEmpty())
209
 
        SettingsSnippetsXmlFullPath = stdPaths.GetUserDataDir() + wxFILE_SEP_PATH +  AppName+ _T(".xml");
 
210
    wxFileName SettingsFullPath(SettingsSnippetsCfgPath);
 
211
    if (SettingsSnippetsXmlPath.IsEmpty())
 
212
        SettingsSnippetsXmlPath = SettingsFullPath.GetPath() + wxFILE_SEP_PATH +  AppName + _T(".xml");
210
213
 
211
214
}
212
215
// ----------------------------------------------------------------------------
218
221
    #ifdef LOGGING
219
222
     wxString fn(__FUNCTION__, wxConvUTF8);
220
223
     LOGIT( _T("--- [%s] ---"),fn.c_str() );
221
 
     LOGIT(wxT("Saving Settings File[%s]"),SettingsSnippetsCfgFullPath.c_str());
 
224
     LOGIT(wxT("Saving Settings File[%s]"),SettingsSnippetsCfgPath.c_str());
222
225
    #endif //LOGGING
223
226
 
224
 
//    wxFileConfig cfgFile(wxEmptyString, // appname
225
 
//                        wxEmptyString,      // vendor
226
 
//                        SettingsSnippetsCfgFullPath,    // local filename
227
 
//                        wxEmptyString,                  // global file
228
 
//                        wxCONFIG_USE_LOCAL_FILE);
 
227
    wxFileConfig cfgFile(wxEmptyString, // appname
 
228
                        wxEmptyString,      // vendor
 
229
                        SettingsSnippetsCfgPath,    // local filename
 
230
                        wxEmptyString,                  // global file
 
231
                        wxCONFIG_USE_LOCAL_FILE);
229
232
 
230
 
    wxFileConfig& cfgFile = *GetCfgFile();
 
233
    //-wxFileConfig& cfgFile = *GetCfgFile();
231
234
 
232
235
        cfgFile.Write( wxT("ExternalEditor"),  SettingsExternalEditor ) ;
233
 
        cfgFile.Write( wxT("SnippetFile"),     SettingsSnippetsXmlFullPath ) ;
 
236
        cfgFile.Write( wxT("SnippetFile"),     SettingsSnippetsXmlPath ) ;
234
237
        cfgFile.Write( wxT("SnippetFolder"),   SettingsSnippetsFolder ) ;
235
238
        cfgFile.Write( wxT("ViewSearchBox"),   SettingsSearchBox ) ;
236
239
        cfgFile.Write( wxT("casesensitive"),   m_SearchConfig.caseSensitive ) ;
237
 
        cfgFile.Write( wxT("scope"),           m_SearchConfig.scope );
238
 
 
239
 
    // Write Mouse DragScrolling settings
240
 
    cfgFile.Write( wxT("MouseDragSensitivity"),  MouseDragSensitivity ) ;
241
 
    cfgFile.Write( wxT("MouseToLineRatio"),      MouseToLineRatio );
242
 
    cfgFile.Write( wxT("MouseContextDelay"),     MouseContextDelay );
 
240
        cfgFile.Write( wxT("scope"),           int(m_SearchConfig.scope) );
 
241
        cfgFile.Write( wxT("EditorsStayOnTop"),SettingsEditorsStayOnTop );
 
242
        cfgFile.Write( wxT("ToolTipsOption"),  SettingsToolTipsOption );
 
243
        if ( IsPlugin() )
 
244
        {   // Write ExternalPersistent for plugin use only
 
245
        cfgFile.Write( wxT("ExternalPersistentOpen"),IsExternalPersistentOpen() );
 
246
        #if defined(LOGGING)
 
247
        //LOGIT( _T("ExternalPersistentOpen is[%s]"), IsExternalPersistentOpen()?_T("true"):_T("false"));
 
248
        #endif
 
249
        }
243
250
 
244
251
    //wxString lastWindowState = wxT("External");
245
252
    //if ( IsFloatingWindow() ) {lastWindowState = wxT("Floating");}
246
253
    //if ( IsDockedWindow() ) {lastWindowState = wxT("Docked");}
247
 
     LOGIT( _T("WindowState[%s]"), SettingsWindowState.c_str() );
248
 
    cfgFile.Write( wxT("WindowState"), SettingsWindowState );
 
254
    #if defined(LOGGING)
 
255
     LOGIT( _T("WindowState[%s]"), m_SettingsWindowState.c_str() );
 
256
    #endif
 
257
    cfgFile.Write( wxT("WindowState"), m_SettingsWindowState );
249
258
 
250
259
    if (IsApplication())
251
 
    {   // record the current window position and size
252
 
        // here, use the main frame, not the snippets window
253
 
        wxWindow* pwin = (wxWindow*)GetMainFrame();;
254
 
        int winXposn, winYposn, winWidth, winHeight;
255
 
        pwin->GetPosition( &winXposn, &winYposn );
256
 
        pwin->GetSize( &winWidth, &winHeight );
 
260
        if ( GetMainFrame() && GetMainFrame()->IsShown() )
 
261
        {   // record the current window position and size
 
262
            // here, use the main frame, not the snippets window
 
263
            wxWindow* pwin = (wxWindow*)GetMainFrame();;
 
264
            int winXposn, winYposn, winWidth, winHeight;
 
265
            pwin->GetPosition( &winXposn, &winYposn );
 
266
            pwin->GetSize( &winWidth, &winHeight );
257
267
 
258
 
        wxString winPos;
259
 
        winPos = wxString::Format(wxT("%d %d %d %d"), winXposn,winYposn,winWidth,winHeight);
260
 
        cfgFile.Write(wxT("WindowPosition"),  winPos) ;
261
 
         LOGIT( _T("Saving WindowPosition[%s]"), winPos.c_str() );
262
 
    }
 
268
            wxString winPos;
 
269
            winPos = wxString::Format(wxT("%d %d %d %d"), winXposn,winYposn,winWidth,winHeight);
 
270
            cfgFile.Write(wxT("WindowPosition"),  winPos) ;
 
271
             LOGIT( _T("Saving WindowPosition[%s]"), winPos.c_str() );
 
272
        }
263
273
    cfgFile.Flush();
264
274
}
265
275
// ----------------------------------------------------------------------------
271
281
        // ALL entries are re-written to the conf, overwritting any put there
272
282
        // by an external pgm.
273
283
 
274
 
//    wxFileConfig cfgFile(wxEmptyString,                 // appname
275
 
//                        wxEmptyString,                  // vendor
276
 
//                        SettingsSnippetsCfgFullPath,    // local filename
277
 
//                        wxEmptyString,                  // global file
278
 
//                        wxCONFIG_USE_LOCAL_FILE);
279
 
    wxFileConfig& cfgFile = *GetCfgFile();
 
284
    wxFileConfig cfgFile(wxEmptyString,                 // appname
 
285
                        wxEmptyString,                  // vendor
 
286
                        SettingsSnippetsCfgPath,    // local filename
 
287
                        wxEmptyString,                  // global file
 
288
                        wxCONFIG_USE_LOCAL_FILE);
280
289
 
281
290
        cfgFile.Write( settingName,  settingValue ) ;
282
291
        cfgFile.Flush();
292
301
 
293
302
    wxFileConfig cfgFile(wxEmptyString,                 // appname
294
303
                         wxEmptyString,      // vendor
295
 
                         GetConfig()->SettingsSnippetsCfgFullPath, // local filename
 
304
                         GetConfig()->SettingsSnippetsCfgPath, // local filename
296
305
                         wxEmptyString,      // global file
297
306
                         wxCONFIG_USE_LOCAL_FILE);
298
307
 
304
313
wxString CodeSnippetsConfig::GetSettingsWindowState()
305
314
// ----------------------------------------------------------------------------
306
315
{
307
 
    SettingsWindowState = SettingsReadString(wxT("WindowState"));
 
316
    m_SettingsWindowState = SettingsReadString(wxT("WindowState"));
308
317
    //LOGIT( _T("GetSettingsWindowState[%s]"),GetConfig()->SettingsWindowState.c_str() );
309
 
    return GetConfig()->SettingsWindowState;
310
 
}
311
 
 
 
318
    return m_SettingsWindowState;
 
319
}
 
320
// ----------------------------------------------------------------------------
 
321
void CodeSnippetsConfig::SetSettingsWindowState(const wxString windowState)
 
322
// ----------------------------------------------------------------------------
 
323
{
 
324
    m_SettingsWindowState = windowState;
 
325
    SettingsSaveString( _T("WindowState"), m_SettingsWindowState );
 
326
    //LOGIT( _T("SetSettingsWindowState[%s]"),GetSettingsWindowState.c_str() );
 
327
    return ;
 
328
}
312
329
// ----------------------------------------------------------------------------
313
330
void CodeSnippetsConfig::SettingsSaveWinPosition()
314
331
// ----------------------------------------------------------------------------
317
334
    // It should only be called on floating windows just before the window is undocked/hidden
318
335
    // else the mainframe position will be recorded instead of the floating window.
319
336
 
320
 
//    wxFileConfig cfgFile(wxEmptyString, // appname
321
 
//                        wxEmptyString,      // vendor
322
 
//                        SettingsSnippetsCfgFullPath,    // local filename
323
 
//                        wxEmptyString,                  // global file
324
 
//                        wxCONFIG_USE_LOCAL_FILE);
325
 
    wxFileConfig& cfgFile = *GetCfgFile();
 
337
    wxFileConfig cfgFile(wxEmptyString, // appname
 
338
                        wxEmptyString,      // vendor
 
339
                        SettingsSnippetsCfgPath,    // local filename
 
340
                        wxEmptyString,                  // global file
 
341
                        wxCONFIG_USE_LOCAL_FILE);
326
342
 
327
343
    // record the current window position and size
328
344
    // here use the snippets windows' parent, not the main frame
343
359
 
344
360
}
345
361
// ----------------------------------------------------------------------------
346
 
void CodeSnippetsConfig::CenterChildOnParent(wxWindow* child)
 
362
void CodeSnippetsConfig::CenterChildOnParent(wxWindow* child, wxWindow* parentParam )
347
363
// ----------------------------------------------------------------------------
348
364
{
349
365
    //For docked window we cannot get its position. Just move
350
366
    // the window over the last known parent position
351
 
    if ( GetConfig()->IsPlugin() )
352
 
    {   wxPoint parentPosn( GetConfig()->windowXpos+(GetConfig()->windowWidth>>1),
 
367
 
 
368
    int displayX; int displayY;
 
369
    ::wxDisplaySize(&displayX, &displayY);
 
370
 
 
371
    //(pecan 2008/5/04)
 
372
    // Now using Plugin code for both app and plugin
 
373
    //if ( GetConfig()->IsPlugin() ) // //(pecan 2008/5/04)
 
374
    {
 
375
        wxPoint parentPosn( GetConfig()->windowXpos+(GetConfig()->windowWidth>>1),
353
376
            GetConfig()->windowYpos+(GetConfig()->windowHeight>>1) );
 
377
        do {   // place bottomLeft child at bottomLeft of parent window
 
378
            int parentx,parenty;
 
379
            int parentsizex,parentsizey;
 
380
            int childsizex,childsizey;
 
381
            wxWindow* parent = child->GetParent();
 
382
            if (parentParam) parent = parentParam;
 
383
            if (not parent) break;
 
384
            parent->GetScreenPosition(&parentx,&parenty);
 
385
            parent->GetSize(&parentsizex,&parentsizey);
 
386
            child->GetSize(&childsizex,&childsizey);
 
387
            parentPosn.x = parentx+20;
 
388
            parentPosn.y = parenty+parentsizey-childsizey;
 
389
            // Make sure child is not off right/bottom of screen
 
390
            if ( (parentPosn.x+childsizex) > displayX)
 
391
                parentPosn.x = displayX-childsizex;
 
392
            if ( (parentPosn.y+childsizey) > displayY)
 
393
                parentPosn.y = displayY-childsizey;
 
394
            // Make sure child is not off left/top of screen
 
395
            if ( parentPosn.x < 1) parentPosn.x = 1;
 
396
            if ( parentPosn.y < 1) parentPosn.y = 1;
 
397
        }while(false);
354
398
        child->Move( parentPosn.x, parentPosn.y);
355
399
        return;
356
400
    }
357
401
 
358
 
    // If application window
359
 
    // Put Top left corner in center of parent (if possible)
360
 
 
361
 
    int h; int w;
362
 
    int x; int y;
363
 
    int displayX; int displayY;
364
 
    wxWindow* mainFrame = child->GetParent();
365
 
    if (not mainFrame) return;
366
 
 
367
 
    // move upper left dialog corner to center of parent
368
 
    ::wxDisplaySize(&displayX, &displayY);
369
 
    mainFrame->GetPosition(&x, &y );
370
 
    mainFrame->ClientToScreen(&x, &y );
371
 
    if ((x == 0) || (y == 0))
372
 
        if (GetConfig()->pMainFrame)
373
 
            GetConfig()->pMainFrame->GetPosition(&x, &y );
374
 
    mainFrame->GetClientSize(&w,&h);
375
 
 
376
 
    // move child underneath the mouse pointer
377
 
    wxPoint movePosn = ::wxGetMousePosition();
378
 
    movePosn.x = x+(w>>2);
379
 
    movePosn.y = y+(h>>2);
380
 
 
381
 
    // Make child is not off the screen
382
 
    wxSize size = child->GetSize();
383
 
    //-LOGIT( _T("X[%d]Y[%d]width[%d]height[%d]"), x,y,w,h );
384
 
 
385
 
    if ( (movePosn.x+size.GetWidth()) > displayX)
386
 
        movePosn.x = displayX-size.GetWidth();
387
 
    if ( (movePosn.y+size.GetHeight()) > displayY)
388
 
        movePosn.y = displayY-size.GetHeight();
389
 
 
390
 
    child->Move(movePosn.x, movePosn.y);
391
402
    return;
392
403
}
393
404
// ----------------------------------------------------------------------------
433
444
    //LOGIT( _T("IsDocked[%s]"),wxT("true"));
434
445
    return true;
435
446
}
 
447
////#include "../utils/ToolBox/ToolBox.h"
436
448
// ----------------------------------------------------------------------------
437
449
bool CodeSnippetsConfig::IsFloatingWindow(wxWindow** pWindowRequest, wxPoint* pCoordRequest, wxSize* pSizeRequest)
438
450
// ----------------------------------------------------------------------------
439
451
{
 
452
    //-ToolBox toolbox; debugging
 
453
    //-toolbox.ShowWindowsAndEvtHandlers(); debugging
 
454
 
440
455
    // If window is Floating window, return its info
441
456
 
442
457
    if ( IsApplication() ) {return false;}
445
460
    wxWindow* pwSnippet = (wxWindow*)GetSnippetsWindow();
446
461
    if ( not pwSnippet ) return false;
447
462
 
448
 
    //LOGIT( _T("IsFloating[%p][%s]"), pwSnippet, pwSnippet->GetName().c_str() );
449
463
    while (pwSnippet->GetParent())
450
464
    {
451
465
        pwSnippet = pwSnippet->GetParent();
452
 
        LOGIT( _T("IsFloating[%p][%s]"), pwSnippet, pwSnippet->GetName().c_str() );
 
466
        #if defined(LOGGING)
 
467
        //-LOGIT( _T("IsFloating Parent[%p][%s]"), pwSnippet, pwSnippet->GetName().c_str() );
 
468
        #endif
 
469
        // break out after we get a pointer to any parent frame
453
470
        if (pwSnippet->GetName() == wxT("frame")) break;
454
471
    }
455
472
    // Get CodeBlocks main window
456
473
    //wxWindow* pwCodeBlocks = Manager::Get()->GetAppWindow();
457
 
    wxWindow* pwCodeBlocks = wxTheApp->GetTopWindow();
 
474
    wxWindow* pwCodeBlocks = GetConfig()->GetMainFrame();
458
475
     //LOGIT( _T("IsFloating pwSnippet[%p]pwCodeBlocks[%p]"),pwSnippet,pwCodeBlocks );
459
476
     //LOGIT( _T("IsFloating pwSnippet[%s]pwCodeBlocks[%s]"),pwSnippet->GetName().c_str(),pwCodeBlocks->GetName().c_str() );
460
477
 
461
478
    // Floating windows have different parents than their original MainFrame
462
 
    // if parent window == CodeBlocks MainFrame, then floating, not docked
 
479
    // if parent window == CodeBlocks MainFrame, then docked
463
480
    if ( pwSnippet == pwCodeBlocks )
464
481
    {
 
482
        #if defined(LOGGING)
465
483
        //LOGIT( _T("IsFloating[%s]"),wxT("false"));
 
484
        #endif
466
485
        return false;
467
486
    }
468
487
 
 
488
    #if defined(LOGGING)
 
489
    //LOGIT( _T("IsFloating[%s]"),wxT("true"));
 
490
    #endif
 
491
 
469
492
    // Have floating window, point to reparented focused window
470
493
    wxWindow* pmf = pwSnippet;
471
494
    if (pWindowRequest) *pWindowRequest = pmf;
475
498
           pmf->ClientToScreen(&pCoordRequest->x, &pCoordRequest->y);
476
499
    }
477
500
    if (pSizeRequest) *pSizeRequest = pmf->GetSize();
478
 
    //LOGIT( _T("IsFloating[%s]"),wxT("true"));
 
501
 
479
502
    return true;
480
503
}
481
504
// ----------------------------------------------------------------------------
499
522
        return temp_folder;
500
523
    #endif
501
524
}
 
525
// ----------------------------------------------------------------------------
 
526
wxFrame* CodeSnippetsConfig::GetEditorManagerFrame(const int index)
 
527
// ----------------------------------------------------------------------------
 
528
{
 
529
    wxFrame* frame;
 
530
    SEditorManager* edMgr;
 
531
    if ( (index < 0) or (index > GetEditorManagerCount()) )
 
532
        return 0;
 
533
    // iterate over all the elements in the class
 
534
    EdManagerMapArray::iterator it;
 
535
    int i = 0;
 
536
    for( it = m_EdManagerMapArray.begin(); it != m_EdManagerMapArray.end(); ++it )
 
537
    {
 
538
        if (i == index)
 
539
        {
 
540
            frame = it->first;
 
541
            edMgr = it->second;
 
542
            return frame;
 
543
        }
 
544
        ++i;
 
545
    }
 
546
    return 0;
 
547
}
 
548
// ----------------------------------------------------------------------------
 
549
SEditorManager* CodeSnippetsConfig::GetEditorManager(const int index)
 
550
// ----------------------------------------------------------------------------
 
551
{
 
552
    wxFrame* frame;
 
553
    SEditorManager* edMgr;
 
554
    if ( (index < 0) or (index > GetEditorManagerCount()) )
 
555
        return 0;
 
556
    // iterate over all the elements in the class
 
557
    EdManagerMapArray::iterator it;
 
558
    int i = 0;
 
559
    for( it = m_EdManagerMapArray.begin(); it != m_EdManagerMapArray.end(); ++it )
 
560
    {
 
561
        if (i == index)
 
562
        {
 
563
            frame = it->first;
 
564
            edMgr = it->second;
 
565
            return edMgr;
 
566
        }
 
567
        ++i;
 
568
    }
 
569
    return 0;
 
570
}
 
571
// ----------------------------------------------------------------------------
 
572
int CodeSnippetsConfig::GetEditorManagerCount()
 
573
// ----------------------------------------------------------------------------
 
574
{
 
575
    return m_EdManagerMapArray.size();
 
576
}
 
577
// ----------------------------------------------------------------------------
 
578
SEditorManager* CodeSnippetsConfig::GetEditorManager(wxWindow* frame)
 
579
// ----------------------------------------------------------------------------
 
580
{
 
581
    return GetEditorManager((wxFrame*) frame);
 
582
}
 
583
// ----------------------------------------------------------------------------
 
584
SEditorManager* CodeSnippetsConfig::GetEditorManager(wxFrame* frame)
 
585
// ----------------------------------------------------------------------------
 
586
{
 
587
    // Return the EditorManager belonging to this frame.
 
588
 
 
589
    EdManagerMapArray::iterator it = m_EdManagerMapArray.find(frame);
 
590
    if (it not_eq m_EdManagerMapArray.end() )
 
591
        return it->second;
 
592
 
 
593
    wxWindow* p = frame;
 
594
    while (p->GetParent())
 
595
    {
 
596
        p = p->GetParent();
 
597
        if ( not p->IsTopLevel() ) continue;
 
598
        it =  m_EdManagerMapArray.find(frame);
 
599
        if (it not_eq m_EdManagerMapArray.end() )
 
600
        {
 
601
            #if defined(LOGGING)
 
602
            //LOGIT( _T("GetEditorManager frame[%p]Mgr[%p]"), frame, it->second);
 
603
            #endif
 
604
            return it->second;
 
605
        }
 
606
    }//while
 
607
 
 
608
    return 0;
 
609
}
 
610
// ----------------------------------------------------------------------------
 
611
void CodeSnippetsConfig::RegisterEditorManager(wxFrame* frame, SEditorManager* edMgr)
 
612
// ----------------------------------------------------------------------------
 
613
{
 
614
    EdManagerMapArray::iterator it = m_EdManagerMapArray.find(frame);
 
615
    if ( it == m_EdManagerMapArray.end()  )
 
616
        m_EdManagerMapArray[frame] = edMgr;
 
617
    #if defined(LOGGING)
 
618
    LOGIT( _T("RegisterEditorManager frame[%p]Mgr[%p]"), frame, edMgr);
 
619
    #endif
 
620
}
 
621
// ----------------------------------------------------------------------------
 
622
void CodeSnippetsConfig::RemoveEditorManager(wxFrame* frame)
 
623
// ----------------------------------------------------------------------------
 
624
{
 
625
    m_EdManagerMapArray.erase(frame);
 
626
}
 
627
// ----------------------------------------------------------------------------
 
628
wxEvtHandler* CodeSnippetsConfig::GetDragScrollEvtHandler()
 
629
// ----------------------------------------------------------------------------
 
630
{
 
631
    // if app, return resident DragScroll pointer
 
632
    if (IsApplication() ) return (wxEvtHandler*)m_pDragScrollPlugin;
 
633
 
 
634
    // If this is CodeSnippets plugin, verify that DragScroll still exists
 
635
    m_pDragScrollPlugin = (cbDragScroll*)(Manager::Get()->GetPluginManager()->FindPluginByName(_T("cbDragScroll")));
 
636
    if (m_pDragScrollPlugin)
 
637
        return (wxEvtHandler*)m_pDragScrollPlugin;
 
638
 
 
639
    m_pDragScrollPlugin = (cbDragScroll*)GetMainFrame();
 
640
    return (wxEvtHandler*)m_pDragScrollPlugin;
 
641
}
 
642
// ----------------------------------------------------------------------------