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

« back to all changes in this revision

Viewing changes to src/sdk/wxscintilla/samples/test/edit.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:
1
 
//////////////////////////////////////////////////////////////////////////////
2
 
// File:        edit.cpp
3
 
// Purpose:     wxScintilla test module
4
 
// Maintainer:  Otto Wyss
5
 
// Created:     2003-09-01
6
 
// RCS-ID:      $Id: edit.cpp 1960 2006-02-07 13:36:51Z thomasdenk $
7
 
// Copyright:   (c) 2004wxCode
8
 
// Licence:     wxWindows
9
 
//////////////////////////////////////////////////////////////////////////////
10
 
 
11
 
//----------------------------------------------------------------------------
12
 
// informations
13
 
//----------------------------------------------------------------------------
14
 
 
15
 
 
16
 
//----------------------------------------------------------------------------
17
 
// headers
18
 
//----------------------------------------------------------------------------
19
 
 
20
 
// For compilers that support precompilation, includes <wx/wx.h>.
21
 
#include <wx/wxprec.h>
22
 
 
23
 
#ifdef __BORLANDC__
24
 
    #pragma hdrstop
25
 
#endif
26
 
 
27
 
// for all others, include the necessary headers (this file is usually all you
28
 
// need because it includes almost all 'standard' wxWindows headers)
29
 
#ifndef WX_PRECOMP
30
 
    #include <wx/wx.h>
31
 
#endif
32
 
 
33
 
//! wxWindows headers
34
 
#include <wx/file.h>     // raw file io support
35
 
#include <wx/filename.h> // filename support
36
 
 
37
 
//! application headers
38
 
#include "defsext.h"     // additional definitions
39
 
 
40
 
#include "edit.h"        // edit module
41
 
 
42
 
 
43
 
//----------------------------------------------------------------------------
44
 
// resources
45
 
//----------------------------------------------------------------------------
46
 
 
47
 
 
48
 
//============================================================================
49
 
// declarations
50
 
//============================================================================
51
 
 
52
 
 
53
 
//============================================================================
54
 
// implementation
55
 
//============================================================================
56
 
 
57
 
//----------------------------------------------------------------------------
58
 
// Edit
59
 
//----------------------------------------------------------------------------
60
 
 
61
 
BEGIN_EVENT_TABLE (Edit, wxScintilla)
62
 
    // common
63
 
    EVT_SIZE (                         Edit::OnSize)
64
 
    // edit
65
 
    EVT_MENU (wxID_CLEAR,              Edit::OnEditClear)
66
 
    EVT_MENU (wxID_CUT,                Edit::OnEditCut)
67
 
    EVT_MENU (wxID_COPY,               Edit::OnEditCopy)
68
 
    EVT_MENU (wxID_PASTE,              Edit::OnEditPaste)
69
 
    EVT_MENU (myID_INDENTINC,          Edit::OnEditIndentInc)
70
 
    EVT_MENU (myID_INDENTRED,          Edit::OnEditIndentRed)
71
 
    EVT_MENU (wxID_SELECTALL,          Edit::OnEditSelectAll)
72
 
    EVT_MENU (myID_SELECTLINE,         Edit::OnEditSelectLine)
73
 
    EVT_MENU (wxID_REDO,               Edit::OnEditRedo)
74
 
    EVT_MENU (wxID_UNDO,               Edit::OnEditUndo)
75
 
    // find
76
 
    EVT_MENU (wxID_FIND,               Edit::OnFind)
77
 
    EVT_MENU (myID_FINDNEXT,           Edit::OnFindNext)
78
 
    EVT_MENU (myID_REPLACE,            Edit::OnReplace)
79
 
    EVT_MENU (myID_REPLACENEXT,        Edit::OnReplaceNext)
80
 
    EVT_MENU (myID_BRACEMATCH,         Edit::OnBraceMatch)
81
 
    EVT_MENU (myID_GOTO,               Edit::OnGoto)
82
 
    // view
83
 
    EVT_MENU_RANGE (myID_HILIGHTFIRST, myID_HILIGHTLAST,
84
 
                                       Edit::OnHilightLang)
85
 
    EVT_MENU (myID_DISPLAYEOL,         Edit::OnDisplayEOL)
86
 
    EVT_MENU (myID_INDENTGUIDE,        Edit::OnIndentGuide)
87
 
    EVT_MENU (myID_LINENUMBER,         Edit::OnLineNumber)
88
 
    EVT_MENU (myID_LONGLINEON,         Edit::OnLongLineOn)
89
 
    EVT_MENU (myID_WHITESPACE,         Edit::OnWhiteSpace)
90
 
    EVT_MENU (myID_FOLDTOGGLE,         Edit::OnFoldToggle)
91
 
    EVT_MENU (myID_OVERTYPE,           Edit::OnSetOverType)
92
 
    EVT_MENU (myID_READONLY,           Edit::OnSetReadOnly)
93
 
    EVT_MENU (myID_WRAPMODEON,         Edit::OnWrapmodeOn)
94
 
    EVT_MENU (myID_CHARSETANSI,        Edit::OnUseCharset)
95
 
    EVT_MENU (myID_CHARSETMAC,         Edit::OnUseCharset)
96
 
    // extra
97
 
    EVT_MENU (myID_CHANGELOWER,        Edit::OnChangeCase)
98
 
    EVT_MENU (myID_CHANGEUPPER,        Edit::OnChangeCase)
99
 
    EVT_MENU (myID_CONVERTCR,          Edit::OnConvertEOL)
100
 
    EVT_MENU (myID_CONVERTCRLF,        Edit::OnConvertEOL)
101
 
    EVT_MENU (myID_CONVERTLF,          Edit::OnConvertEOL)
102
 
    // scintilla
103
 
    EVT_SCI_MARGINCLICK (-1,           Edit::OnMarginClick)
104
 
    EVT_SCI_CHARADDED (-1,             Edit::OnCharAdded)
105
 
END_EVENT_TABLE()
106
 
 
107
 
Edit::Edit (wxWindow *parent, wxWindowID id,
108
 
            const wxPoint &pos,
109
 
            const wxSize &size,
110
 
            long style)
111
 
    : wxScintilla (parent, id, pos, size, style) {
112
 
 
113
 
    m_filename = _T("");
114
 
    m_language = NULL;
115
 
 
116
 
    m_LineNrID = 0;
117
 
    m_LineNrMargin = TextWidth (wxSCI_STYLE_LINENUMBER, _T("_999999"));
118
 
    m_FoldingID = 1;
119
 
    m_FoldingMargin = 16;
120
 
    m_DividerID = 2;
121
 
 
122
 
    // default font for all styles
123
 
    SetViewEOL (g_CommonPrefs.displayEOLEnable);
124
 
    SetIndentationGuides (g_CommonPrefs.indentGuideEnable);
125
 
    SetMarginWidth (m_LineNrID,
126
 
                    g_CommonPrefs.lineNumberEnable? m_LineNrMargin: 0);
127
 
    SetEdgeMode (g_CommonPrefs.longLineOnEnable?
128
 
                 wxSCI_EDGE_LINE: wxSCI_EDGE_NONE);
129
 
    SetViewWhiteSpace (g_CommonPrefs.whiteSpaceEnable?
130
 
                       wxSCI_WS_VISIBLEALWAYS: wxSCI_WS_INVISIBLE);
131
 
    SetOvertype (g_CommonPrefs.overTypeInitial);
132
 
    SetReadOnly (g_CommonPrefs.readOnlyInitial);
133
 
    SetWrapMode (g_CommonPrefs.wrapModeInitial?
134
 
                 wxSCI_WRAP_WORD: wxSCI_WRAP_NONE);
135
 
    wxFont font (10, wxTELETYPE, wxNORMAL, wxNORMAL);
136
 
    StyleSetFont (wxSCI_STYLE_DEFAULT, font);
137
 
    StyleSetForeground (wxSCI_STYLE_DEFAULT, wxColour (_T("BLACK")));
138
 
    StyleSetBackground (wxSCI_STYLE_DEFAULT, wxColour (_T("WHITE")));
139
 
    StyleSetForeground (wxSCI_STYLE_LINENUMBER, wxColour (_T("DARK GREY")));
140
 
    StyleSetBackground (wxSCI_STYLE_LINENUMBER, wxColour (_T("WHITE")));
141
 
    StyleSetForeground(wxSCI_STYLE_INDENTGUIDE, wxColour (_T("DARK GREY")));
142
 
    InitializePrefs (DEFAULT_LANGUAGE);
143
 
 
144
 
    // set visibility
145
 
    SetVisiblePolicy (wxSCI_VISIBLE_STRICT|wxSCI_VISIBLE_SLOP, 1);
146
 
    SetXCaretPolicy (wxSCI_CARET_EVEN|wxSCI_VISIBLE_STRICT|wxSCI_CARET_SLOP, 1);
147
 
    SetYCaretPolicy (wxSCI_CARET_EVEN|wxSCI_VISIBLE_STRICT|wxSCI_CARET_SLOP, 1);
148
 
 
149
 
    // markers
150
 
    MarkerDefine (wxSCI_MARKNUM_FOLDER, wxSCI_MARK_BOXPLUS);
151
 
    MarkerSetBackground (wxSCI_MARKNUM_FOLDER, wxColour (_T("BLACK")));
152
 
    MarkerSetForeground (wxSCI_MARKNUM_FOLDER, wxColour (_T("WHITE")));
153
 
    MarkerDefine (wxSCI_MARKNUM_FOLDEROPEN, wxSCI_MARK_BOXMINUS);
154
 
    MarkerSetBackground (wxSCI_MARKNUM_FOLDEROPEN, wxColour (_T("BLACK")));
155
 
    MarkerSetForeground (wxSCI_MARKNUM_FOLDEROPEN, wxColour (_T("WHITE")));
156
 
    MarkerDefine (wxSCI_MARKNUM_FOLDERSUB, wxSCI_MARK_EMPTY);
157
 
    MarkerDefine (wxSCI_MARKNUM_FOLDEREND, wxSCI_MARK_SHORTARROW);
158
 
    MarkerDefine (wxSCI_MARKNUM_FOLDEROPENMID, wxSCI_MARK_ARROWDOWN);
159
 
    MarkerDefine (wxSCI_MARKNUM_FOLDERMIDTAIL, wxSCI_MARK_EMPTY);
160
 
    MarkerDefine (wxSCI_MARKNUM_FOLDERTAIL, wxSCI_MARK_EMPTY);
161
 
 
162
 
    // clear wrong default keys
163
 
#if !defined(__WXGTK__)
164
 
    CmdKeyClear (wxSCI_KEY_TAB, 0);
165
 
    CmdKeyClear (wxSCI_KEY_TAB, wxSCI_SCMOD_SHIFT);
166
 
#endif
167
 
    CmdKeyClear ('A', wxSCI_SCMOD_CTRL);
168
 
#if !defined(__WXGTK__)
169
 
    CmdKeyClear ('C', wxSCI_SCMOD_CTRL);
170
 
#endif
171
 
    CmdKeyClear ('D', wxSCI_SCMOD_CTRL);
172
 
    CmdKeyClear ('D', wxSCI_SCMOD_SHIFT | wxSCI_SCMOD_CTRL);
173
 
    CmdKeyClear ('F', wxSCI_SCMOD_ALT | wxSCI_SCMOD_CTRL);
174
 
    CmdKeyClear ('L', wxSCI_SCMOD_CTRL);
175
 
    CmdKeyClear ('L', wxSCI_SCMOD_SHIFT | wxSCI_SCMOD_CTRL);
176
 
    CmdKeyClear ('T', wxSCI_SCMOD_CTRL);
177
 
    CmdKeyClear ('T', wxSCI_SCMOD_SHIFT | wxSCI_SCMOD_CTRL);
178
 
    CmdKeyClear ('U', wxSCI_SCMOD_CTRL);
179
 
    CmdKeyClear ('U', wxSCI_SCMOD_SHIFT | wxSCI_SCMOD_CTRL);
180
 
#if !defined(__WXGTK__)
181
 
    CmdKeyClear ('V', wxSCI_SCMOD_CTRL);
182
 
    CmdKeyClear ('X', wxSCI_SCMOD_CTRL);
183
 
#endif
184
 
    CmdKeyClear ('Y', wxSCI_SCMOD_CTRL);
185
 
#if !defined(__WXGTK__)
186
 
    CmdKeyClear ('Z', wxSCI_SCMOD_CTRL);
187
 
#endif
188
 
 
189
 
    // miscelaneous
190
 
    UsePopUp (0);
191
 
    SetLayoutCache (wxSCI_CACHE_PAGE);
192
 
    SetBufferedDraw (1);
193
 
 
194
 
}
195
 
 
196
 
Edit::~Edit () {}
197
 
 
198
 
//----------------------------------------------------------------------------
199
 
// common event handlers
200
 
void Edit::OnSize( wxSizeEvent& event ) {
201
 
    int x = GetClientSize().x +
202
 
            (g_CommonPrefs.lineNumberEnable? m_LineNrMargin: 0) +
203
 
            (g_CommonPrefs.foldEnable? m_FoldingMargin: 0);
204
 
    if (x > 0) SetScrollWidth (x);
205
 
    event.Skip();
206
 
}
207
 
 
208
 
// edit event handlers
209
 
void Edit::OnEditRedo (wxCommandEvent &WXUNUSED(event)) {
210
 
    if (!CanRedo()) return;
211
 
    Redo ();
212
 
}
213
 
 
214
 
void Edit::OnEditUndo (wxCommandEvent &WXUNUSED(event)) {
215
 
    if (!CanUndo()) return;
216
 
    Undo ();
217
 
}
218
 
 
219
 
void Edit::OnEditClear (wxCommandEvent &WXUNUSED(event)) {
220
 
    if (GetReadOnly()) return;
221
 
    Clear ();
222
 
}
223
 
 
224
 
void Edit::OnEditCut (wxCommandEvent &WXUNUSED(event)) {
225
 
    if (GetReadOnly() || (GetSelectionEnd()-GetSelectionStart() <= 0)) return;
226
 
    Cut ();
227
 
}
228
 
 
229
 
void Edit::OnEditCopy (wxCommandEvent &WXUNUSED(event)) {
230
 
    if (GetSelectionEnd()-GetSelectionStart() <= 0) return;
231
 
    Copy ();
232
 
}
233
 
 
234
 
void Edit::OnEditPaste (wxCommandEvent &WXUNUSED(event)) {
235
 
    if (!CanPaste()) return;
236
 
    Paste ();
237
 
}
238
 
 
239
 
void Edit::OnFind (wxCommandEvent &WXUNUSED(event)) {
240
 
}
241
 
 
242
 
void Edit::OnFindNext (wxCommandEvent &WXUNUSED(event)) {
243
 
}
244
 
 
245
 
void Edit::OnReplace (wxCommandEvent &WXUNUSED(event)) {
246
 
}
247
 
 
248
 
void Edit::OnReplaceNext (wxCommandEvent &WXUNUSED(event)) {
249
 
}
250
 
 
251
 
void Edit::OnBraceMatch (wxCommandEvent &WXUNUSED(event)) {
252
 
    int min = GetCurrentPos ();
253
 
    int max = BraceMatch (min);
254
 
    if (max > (min+1)) {
255
 
        BraceHighlight (min+1, max);
256
 
        SetSelection (min+1, max);
257
 
    }else{
258
 
        BraceBadLight (min);
259
 
    }
260
 
}
261
 
 
262
 
void Edit::OnGoto (wxCommandEvent &WXUNUSED(event)) {
263
 
}
264
 
 
265
 
void Edit::OnEditIndentInc (wxCommandEvent &WXUNUSED(event)) {
266
 
    CmdKeyExecute (wxSCI_CMD_TAB);
267
 
}
268
 
 
269
 
void Edit::OnEditIndentRed (wxCommandEvent &WXUNUSED(event)) {
270
 
    CmdKeyExecute (wxSCI_CMD_DELETEBACK);
271
 
}
272
 
 
273
 
void Edit::OnEditSelectAll (wxCommandEvent &WXUNUSED(event)) {
274
 
    SetSelection (0, GetLength());
275
 
}
276
 
 
277
 
void Edit::OnEditSelectLine (wxCommandEvent &WXUNUSED(event)) {
278
 
    int lineStart = PositionFromLine (GetCurrentLine());
279
 
    int lineEnd = PositionFromLine (GetCurrentLine() + 1);
280
 
    SetSelection (lineStart, lineEnd);
281
 
}
282
 
 
283
 
void Edit::OnHilightLang (wxCommandEvent &event) {
284
 
    InitializePrefs (g_LanguagePrefs [event.GetId() - myID_HILIGHTFIRST].name);
285
 
}
286
 
 
287
 
void Edit::OnDisplayEOL (wxCommandEvent &WXUNUSED(event)) {
288
 
    SetViewEOL (!GetViewEOL());
289
 
}
290
 
 
291
 
void Edit::OnIndentGuide (wxCommandEvent &WXUNUSED(event)) {
292
 
    SetIndentationGuides (!GetIndentationGuides());
293
 
}
294
 
 
295
 
void Edit::OnLineNumber (wxCommandEvent &WXUNUSED(event)) {
296
 
    SetMarginWidth (m_LineNrID,
297
 
                    GetMarginWidth (m_LineNrID) == 0? m_LineNrMargin: 0);
298
 
}
299
 
 
300
 
void Edit::OnLongLineOn (wxCommandEvent &WXUNUSED(event)) {
301
 
    SetEdgeMode (GetEdgeMode() == 0? wxSCI_EDGE_LINE: wxSCI_EDGE_NONE);
302
 
}
303
 
 
304
 
void Edit::OnWhiteSpace (wxCommandEvent &WXUNUSED(event)) {
305
 
    SetViewWhiteSpace (GetViewWhiteSpace() == 0?
306
 
                       wxSCI_WS_VISIBLEALWAYS: wxSCI_WS_INVISIBLE);
307
 
}
308
 
 
309
 
void Edit::OnFoldToggle (wxCommandEvent &WXUNUSED(event)) {
310
 
    ToggleFold (GetFoldParent(GetCurrentLine()));
311
 
}
312
 
 
313
 
void Edit::OnSetOverType (wxCommandEvent &WXUNUSED(event)) {
314
 
    SetOvertype (!GetOvertype());
315
 
}
316
 
 
317
 
void Edit::OnSetReadOnly (wxCommandEvent &WXUNUSED(event)) {
318
 
    SetReadOnly (!GetReadOnly());
319
 
}
320
 
 
321
 
void Edit::OnWrapmodeOn (wxCommandEvent &WXUNUSED(event)) {
322
 
    SetWrapMode (GetWrapMode() == 0? wxSCI_WRAP_WORD: wxSCI_WRAP_NONE);
323
 
}
324
 
 
325
 
void Edit::OnUseCharset (wxCommandEvent &event) {
326
 
    int Nr;
327
 
    int charset = GetCodePage();
328
 
    switch (event.GetId()) {
329
 
        case myID_CHARSETANSI: {charset = wxSCI_CHARSET_ANSI; break;}
330
 
        case myID_CHARSETMAC: {charset = wxSCI_CHARSET_ANSI; break;}
331
 
    }
332
 
    for (Nr = 0; Nr < wxSCI_STYLE_LASTPREDEFINED; Nr++) {
333
 
        StyleSetCharacterSet (Nr, charset);
334
 
    }
335
 
    SetCodePage (charset);
336
 
}
337
 
 
338
 
void Edit::OnChangeCase (wxCommandEvent &event) {
339
 
    switch (event.GetId()) {
340
 
        case myID_CHANGELOWER: {
341
 
            CmdKeyExecute (wxSCI_CMD_LOWERCASE);
342
 
            break;
343
 
        }
344
 
        case myID_CHANGEUPPER: {
345
 
            CmdKeyExecute (wxSCI_CMD_UPPERCASE);
346
 
            break;
347
 
        }
348
 
    }
349
 
}
350
 
 
351
 
void Edit::OnConvertEOL (wxCommandEvent &event) {
352
 
    int eolMode = GetEOLMode();
353
 
    switch (event.GetId()) {
354
 
        case myID_CONVERTCR: { eolMode = wxSCI_EOL_CR; break;}
355
 
        case myID_CONVERTCRLF: { eolMode = wxSCI_EOL_CRLF; break;}
356
 
        case myID_CONVERTLF: { eolMode = wxSCI_EOL_LF; break;}
357
 
    }
358
 
    ConvertEOLs (eolMode);
359
 
    SetEOLMode (eolMode);
360
 
}
361
 
 
362
 
//! misc
363
 
void Edit::OnMarginClick (wxScintillaEvent &event) {
364
 
    if (event.GetMargin() == 2) {
365
 
        int lineClick = LineFromPosition (event.GetPosition());
366
 
        int levelClick = GetFoldLevel (lineClick);
367
 
        if ((levelClick & wxSCI_FOLDLEVELHEADERFLAG) > 0) {
368
 
            ToggleFold (lineClick);
369
 
        }
370
 
    }
371
 
}
372
 
 
373
 
void Edit::OnCharAdded (wxScintillaEvent &event) {
374
 
    char chr = event.GetKey();
375
 
    int currentLine = GetCurrentLine();
376
 
    // Change this if support for mac files with \r is needed
377
 
    if (chr == '\n') {
378
 
        int lineInd = 0;
379
 
        if (currentLine > 0) {
380
 
            lineInd = GetLineIndentation(currentLine - 1);
381
 
        }
382
 
        if (lineInd == 0) return;
383
 
        SetLineIndentation (currentLine, lineInd);
384
 
        GotoPos(PositionFromLine (currentLine) + lineInd);
385
 
    }
386
 
}
387
 
 
388
 
 
389
 
//----------------------------------------------------------------------------
390
 
// private functions
391
 
wxString Edit::DeterminePrefs (const wxString &filename) {
392
 
 
393
 
    LanguageInfo const* curInfo;
394
 
 
395
 
    // determine language from filepatterns
396
 
    int languageNr;
397
 
    for (languageNr = 0; languageNr < g_LanguagePrefsSize; languageNr++) {
398
 
        curInfo = &g_LanguagePrefs [languageNr];
399
 
        wxString filepattern = curInfo->filepattern;
400
 
        filepattern.Lower();
401
 
        while (!filepattern.IsEmpty()) {
402
 
            wxString cur = filepattern.BeforeFirst (';');
403
 
            if ((cur == filename) ||
404
 
                (cur == (filename.BeforeLast ('.') + _T(".*"))) ||
405
 
                (cur == (_T("*.") + filename.AfterLast ('.')))) {
406
 
                return curInfo->name;
407
 
            }
408
 
            filepattern = filepattern.AfterFirst (';');
409
 
        }
410
 
    }
411
 
    return wxEmptyString;
412
 
 
413
 
}
414
 
 
415
 
bool Edit::InitializePrefs (const wxString &name) {
416
 
 
417
 
    // initialize styles
418
 
    StyleClearAll();
419
 
    LanguageInfo const* curInfo = NULL;
420
 
 
421
 
    // determine language
422
 
    bool found = false;
423
 
    int languageNr;
424
 
    for (languageNr = 0; languageNr < g_LanguagePrefsSize; languageNr++) {
425
 
        curInfo = &g_LanguagePrefs [languageNr];
426
 
        if (curInfo->name == name) {
427
 
            found = true;
428
 
            break;
429
 
        }
430
 
    }
431
 
    if (!found) return false;
432
 
 
433
 
    // set lexer and language
434
 
    SetLexer (curInfo->lexer);
435
 
    m_language = curInfo;
436
 
 
437
 
    // set margin for line numbers
438
 
    SetMarginType (m_LineNrID, wxSCI_MARGIN_NUMBER);
439
 
    StyleSetForeground (wxSCI_STYLE_LINENUMBER, wxColour (_T("DARK GREY")));
440
 
    StyleSetBackground (wxSCI_STYLE_LINENUMBER, wxColour (_T("WHITE")));
441
 
    SetMarginWidth (m_LineNrID,
442
 
                    g_CommonPrefs.lineNumberEnable? m_LineNrMargin: 0);
443
 
 
444
 
    // set common styles
445
 
    StyleSetForeground (wxSCI_STYLE_DEFAULT, wxColour (_T("DARK GREY")));
446
 
    StyleSetForeground (wxSCI_STYLE_INDENTGUIDE, wxColour (_T("DARK GREY")));
447
 
 
448
 
    // initialize settings
449
 
    if (g_CommonPrefs.syntaxEnable) {
450
 
        int keywordnr = 0;
451
 
        int Nr;
452
 
        for (Nr = 0; Nr < STYLE_TYPES_COUNT; Nr++) {
453
 
            if (curInfo->styles[Nr].type == -1) continue;
454
 
            const StyleInfo &curType = g_StylePrefs [curInfo->styles[Nr].type];
455
 
            wxFont font (curType.fontsize, wxTELETYPE, wxNORMAL, wxNORMAL, false,
456
 
                         curType.fontname);
457
 
            StyleSetFont (Nr, font);
458
 
            if (curType.foreground) {
459
 
                StyleSetForeground (Nr, wxColour (curType.foreground));
460
 
            }
461
 
            if (curType.background) {
462
 
                StyleSetBackground (Nr, wxColour (curType.background));
463
 
            }
464
 
            StyleSetBold (Nr, (curType.fontstyle & TOKEN_STYLE_BOLD) > 0);
465
 
            StyleSetItalic (Nr, (curType.fontstyle & TOKEN_STYLE_ITALIC) > 0);
466
 
            StyleSetUnderline (Nr, (curType.fontstyle & TOKEN_STYLE_UNDERL) > 0);
467
 
            StyleSetVisible (Nr, (curType.fontstyle & TOKEN_STYLE_HIDDEN) == 0);
468
 
            StyleSetCase (Nr, curType.lettercase);
469
 
            const wxChar *pwords = curInfo->styles[Nr].words;
470
 
            if (pwords) {
471
 
                SetKeyWords (keywordnr, pwords);
472
 
                keywordnr += 1;
473
 
            }
474
 
        }
475
 
    }
476
 
 
477
 
    // set margin as unused
478
 
    SetMarginType (m_DividerID, wxSCI_MARGIN_SYMBOL);
479
 
    SetMarginWidth (m_DividerID, 8);
480
 
    SetMarginSensitive (m_DividerID, false);
481
 
 
482
 
    // folding
483
 
    SetMarginType (m_FoldingID, wxSCI_MARGIN_SYMBOL);
484
 
    SetMarginMask (m_FoldingID, wxSCI_MASK_FOLDERS);
485
 
    StyleSetBackground (m_FoldingID, wxColour (_T("WHITE")));
486
 
    SetMarginWidth (m_FoldingID, 0);
487
 
    SetMarginSensitive (m_FoldingID, false);
488
 
    if (g_CommonPrefs.foldEnable) {
489
 
        SetMarginWidth (m_FoldingID, curInfo->folds != 0? m_FoldingMargin: 0);
490
 
        SetMarginSensitive (m_FoldingID, curInfo->folds != 0);
491
 
        SetProperty (_T("fold"), curInfo->folds != 0? _T("1"): _T("0"));
492
 
        SetProperty (_T("fold.comment"),
493
 
                     (curInfo->folds & FOLD_TYPE_COMMENT) > 0? _T("1"): _T("0"));
494
 
        SetProperty (_T("fold.compact"),
495
 
                     (curInfo->folds & FOLD_TYPE_COMPACT) > 0? _T("1"): _T("0"));
496
 
        SetProperty (_T("fold.preprocessor"),
497
 
                     (curInfo->folds & FOLD_TYPE_PREPROC) > 0? _T("1"): _T("0"));
498
 
        SetProperty (_T("fold.html"),
499
 
                     (curInfo->folds & FOLD_TYPE_HTML) > 0? _T("1"): _T("0"));
500
 
        SetProperty (_T("fold.html.preprocessor"),
501
 
                     (curInfo->folds & FOLD_TYPE_HTMLPREP) > 0? _T("1"): _T("0"));
502
 
        SetProperty (_T("fold.comment.python"),
503
 
                     (curInfo->folds & FOLD_TYPE_COMMENTPY) > 0? _T("1"): _T("0"));
504
 
        SetProperty (_T("fold.quotes.python"),
505
 
                     (curInfo->folds & FOLD_TYPE_QUOTESPY) > 0? _T("1"): _T("0"));
506
 
    }
507
 
    SetFoldFlags (wxSCI_FOLDFLAG_LINEBEFORE_CONTRACTED |
508
 
                  wxSCI_FOLDFLAG_LINEAFTER_CONTRACTED);
509
 
 
510
 
    // set spaces and indention
511
 
    SetTabWidth (4);
512
 
    SetUseTabs (false);
513
 
    SetTabIndents (true);
514
 
    SetBackSpaceUnIndents (true);
515
 
    SetIndent (g_CommonPrefs.indentEnable? 4: 0);
516
 
 
517
 
    // others
518
 
    SetViewEOL (g_CommonPrefs.displayEOLEnable);
519
 
    SetIndentationGuides (g_CommonPrefs.indentGuideEnable);
520
 
    SetEdgeColumn (80);
521
 
    SetEdgeMode (g_CommonPrefs.longLineOnEnable? wxSCI_EDGE_LINE: wxSCI_EDGE_NONE);
522
 
    SetViewWhiteSpace (g_CommonPrefs.whiteSpaceEnable?
523
 
                       wxSCI_WS_VISIBLEALWAYS: wxSCI_WS_INVISIBLE);
524
 
    SetOvertype (g_CommonPrefs.overTypeInitial);
525
 
    SetReadOnly (g_CommonPrefs.readOnlyInitial);
526
 
    SetWrapMode (g_CommonPrefs.wrapModeInitial?
527
 
                 wxSCI_WRAP_WORD: wxSCI_WRAP_NONE);
528
 
 
529
 
    return true;
530
 
}
531
 
 
532
 
bool Edit::LoadFile () {
533
 
 
534
 
    // get filname
535
 
    if (!m_filename) {
536
 
        wxFileDialog dlg (this, _T("Open file"), _T(""), _T(""),
537
 
                          _T("Any file (*)|*"), wxOPEN | wxFILE_MUST_EXIST | wxCHANGE_DIR);
538
 
        if (dlg.ShowModal() != wxID_OK) return false;
539
 
        m_filename = dlg.GetPath();
540
 
    }
541
 
 
542
 
    // load file
543
 
    return LoadFile (m_filename);
544
 
}
545
 
 
546
 
bool Edit::LoadFile (const wxString &filename) {
547
 
 
548
 
    // load file in edit and clear undo
549
 
    if (!filename.IsEmpty()) m_filename = filename;
550
 
    if (!wxScintilla::LoadFile (m_filename)) return false;
551
 
 
552
 
    // determine lexer language
553
 
    wxFileName fname (m_filename);
554
 
    InitializePrefs (DeterminePrefs (fname.GetFullName()));
555
 
 
556
 
    return true;
557
 
}
558
 
 
559
 
bool Edit::SaveFile () {
560
 
 
561
 
    // return if no change
562
 
    if (!Modified()) return true;
563
 
 
564
 
    // get filname
565
 
    if (!m_filename) {
566
 
        wxFileDialog dlg (this, _T("Save file"), _T(""), _T(""), _T("Any file (*)|*"),
567
 
                          wxSAVE | wxOVERWRITE_PROMPT);
568
 
        if (dlg.ShowModal() != wxID_OK) return false;
569
 
        m_filename = dlg.GetPath();
570
 
    }
571
 
 
572
 
    // save file
573
 
    return SaveFile (m_filename);
574
 
}
575
 
 
576
 
bool Edit::SaveFile (const wxString &filename) {
577
 
 
578
 
    // return if no change
579
 
    if (!Modified()) return true;
580
 
 
581
 
    return wxScintilla::SaveFile(filename);
582
 
 
583
 
}
584
 
 
585
 
bool Edit::Modified () {
586
 
 
587
 
    // return modified state
588
 
    return (GetModify() && !GetReadOnly());
589
 
}
590
 
 
591
 
//----------------------------------------------------------------------------
592
 
// EditProperties
593
 
//----------------------------------------------------------------------------
594
 
 
595
 
EditProperties::EditProperties (Edit *edit,
596
 
                                long style)
597
 
        : wxDialog (edit, -1, wxEmptyString,
598
 
                    wxDefaultPosition, wxDefaultSize,
599
 
                    style | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {
600
 
 
601
 
    // sets the application title
602
 
    SetTitle (_("Properties"));
603
 
    wxString text;
604
 
 
605
 
    // fullname
606
 
    wxBoxSizer *fullname = new wxBoxSizer (wxHORIZONTAL);
607
 
    fullname->Add (10, 0);
608
 
    fullname->Add (new wxStaticText (this, -1, _("Full filename"),
609
 
                                     wxDefaultPosition, wxSize(80, -1)),
610
 
                   0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL);
611
 
    fullname->Add (new wxStaticText (this, -1, edit->GetFilename()),
612
 
                   0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL);
613
 
 
614
 
    // text info
615
 
    wxGridSizer *textinfo = new wxGridSizer (4, 0, 2);
616
 
    textinfo->Add (new wxStaticText (this, -1, _("Language"),
617
 
                                     wxDefaultPosition, wxSize(80, -1)),
618
 
                   0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
619
 
    textinfo->Add (new wxStaticText (this, -1, edit->m_language->name),
620
 
                   0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
621
 
    textinfo->Add (new wxStaticText (this, -1, _("Lexer-ID: "),
622
 
                                     wxDefaultPosition, wxSize(80, -1)),
623
 
                   0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
624
 
    text = wxString::Format (_T("%d"), edit->GetLexer());
625
 
    textinfo->Add (new wxStaticText (this, -1, text),
626
 
                   0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
627
 
    wxString EOLtype = _T("");
628
 
    switch (edit->GetEOLMode()) {
629
 
        case wxSCI_EOL_CR: {EOLtype = _T("CR (Unix)"); break; }
630
 
        case wxSCI_EOL_CRLF: {EOLtype = _T("CRLF (Windows)"); break; }
631
 
        case wxSCI_EOL_LF: {EOLtype = _T("CR (Macintosh)"); break; }
632
 
    }
633
 
    textinfo->Add (new wxStaticText (this, -1, _("Line endings"),
634
 
                                     wxDefaultPosition, wxSize(80, -1)),
635
 
                   0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
636
 
    textinfo->Add (new wxStaticText (this, -1, EOLtype),
637
 
                   0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
638
 
 
639
 
    // text info box
640
 
    wxStaticBoxSizer *textinfos = new wxStaticBoxSizer (
641
 
                     new wxStaticBox (this, -1, _("Informations")),
642
 
                     wxVERTICAL);
643
 
    textinfos->Add (textinfo, 0, wxEXPAND);
644
 
    textinfos->Add (0, 6);
645
 
 
646
 
    // statistic
647
 
    wxGridSizer *statistic = new wxGridSizer (4, 0, 2);
648
 
    statistic->Add (new wxStaticText (this, -1, _("Total lines"),
649
 
                                     wxDefaultPosition, wxSize(80, -1)),
650
 
                    0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
651
 
    text = wxString::Format (_T("%d"), edit->GetLineCount());
652
 
    statistic->Add (new wxStaticText (this, -1, text),
653
 
                    0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
654
 
    statistic->Add (new wxStaticText (this, -1, _("Total chars"),
655
 
                                     wxDefaultPosition, wxSize(80, -1)),
656
 
                    0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
657
 
    text = wxString::Format (_T("%d"), edit->GetTextLength());
658
 
    statistic->Add (new wxStaticText (this, -1, text),
659
 
                    0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
660
 
    statistic->Add (new wxStaticText (this, -1, _("Current line"),
661
 
                                     wxDefaultPosition, wxSize(80, -1)),
662
 
                    0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
663
 
    text = wxString::Format (_T("%d"), edit->GetCurrentLine());
664
 
    statistic->Add (new wxStaticText (this, -1, text),
665
 
                    0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
666
 
    statistic->Add (new wxStaticText (this, -1, _("Current pos"),
667
 
                                     wxDefaultPosition, wxSize(80, -1)),
668
 
                    0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
669
 
    text = wxString::Format (_T("%d"), edit->GetCurrentPos());
670
 
    statistic->Add (new wxStaticText (this, -1, text),
671
 
                    0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
672
 
 
673
 
    // char/line statistics
674
 
    wxStaticBoxSizer *statistics = new wxStaticBoxSizer (
675
 
                     new wxStaticBox (this, -1, _("Statistics")),
676
 
                     wxVERTICAL);
677
 
    statistics->Add (statistic, 0, wxEXPAND);
678
 
    statistics->Add (0, 6);
679
 
 
680
 
    // total pane
681
 
    wxBoxSizer *totalpane = new wxBoxSizer (wxVERTICAL);
682
 
    totalpane->Add (fullname, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 10);
683
 
    totalpane->Add (0, 6);
684
 
    totalpane->Add (textinfos, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
685
 
    totalpane->Add (0, 10);
686
 
    totalpane->Add (statistics, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
687
 
    totalpane->Add (0, 6);
688
 
    wxButton *okButton = new wxButton (this, wxID_OK, _("OK"));
689
 
    okButton->SetDefault();
690
 
    totalpane->Add (okButton, 0, wxALIGN_CENTER | wxALL, 10);
691
 
 
692
 
    SetSizerAndFit (totalpane);
693
 
 
694
 
    ShowModal();
695
 
}
696
 
 
697
 
//----------------------------------------------------------------------------
698
 
// EditPrint
699
 
//----------------------------------------------------------------------------
700
 
 
701
 
EditPrint::EditPrint (Edit *edit, wxChar *title)
702
 
              : wxPrintout(title) {
703
 
    m_edit = edit;
704
 
    m_printed = 0;
705
 
 
706
 
}
707
 
 
708
 
bool EditPrint::OnPrintPage (int page) {
709
 
 
710
 
    wxDC *dc = GetDC();
711
 
    if (!dc) return false;
712
 
 
713
 
    // scale DC
714
 
    PrintScaling (dc);
715
 
 
716
 
    // print page
717
 
    if (page == 1) m_printed = 0;
718
 
    m_printed = m_edit->FormatRange (1, m_printed, m_edit->GetLength(),
719
 
                                     dc, dc, m_printRect, m_pageRect);
720
 
 
721
 
    return true;
722
 
}
723
 
 
724
 
bool EditPrint::OnBeginDocument (int startPage, int endPage) {
725
 
 
726
 
    if (!wxPrintout::OnBeginDocument (startPage, endPage)) {
727
 
        return false;
728
 
    }
729
 
 
730
 
    return true;
731
 
}
732
 
 
733
 
void EditPrint::GetPageInfo (int *minPage, int *maxPage, int *selPageFrom, int *selPageTo) {
734
 
 
735
 
    // initialize values
736
 
    *minPage = 0;
737
 
    *maxPage = 0;
738
 
    *selPageFrom = 0;
739
 
    *selPageTo = 0;
740
 
 
741
 
    // scale DC if possible
742
 
    wxDC *dc = GetDC();
743
 
    if (!dc) return;
744
 
    PrintScaling (dc);
745
 
 
746
 
    // get print page informations and convert to printer pixels
747
 
    wxSize ppiScr;
748
 
    GetPPIScreen (&ppiScr.x, &ppiScr.y);
749
 
    wxSize page = g_pageSetupData->GetPaperSize();
750
 
    page.x = static_cast<int> (page.x * ppiScr.x / 25.4);
751
 
    page.y = static_cast<int> (page.y * ppiScr.y / 25.4);
752
 
    m_pageRect = wxRect (0,
753
 
                         0,
754
 
                         page.x,
755
 
                         page.y);
756
 
 
757
 
    // get margins informations and convert to printer pixels
758
 
    int  top = 25; // default 25
759
 
    int  bottom = 25; // default 25
760
 
    int  left = 20; // default 20
761
 
    int  right = 20; // default 20
762
 
    wxPoint (top, left) = g_pageSetupData->GetMarginTopLeft();
763
 
    wxPoint (bottom, right) = g_pageSetupData->GetMarginBottomRight();
764
 
    top = static_cast<int> (top * ppiScr.y / 25.4);
765
 
    bottom = static_cast<int> (bottom * ppiScr.y / 25.4);
766
 
    left = static_cast<int> (left * ppiScr.x / 25.4);
767
 
    right = static_cast<int> (right * ppiScr.x / 25.4);
768
 
    m_printRect = wxRect (left,
769
 
                          top,
770
 
                          page.x - (left + right),
771
 
                          page.y - (top + bottom));
772
 
 
773
 
    // count pages
774
 
    while (HasPage (*maxPage)) {
775
 
        m_printed = m_edit->FormatRange (0, m_printed, m_edit->GetLength(),
776
 
                                       dc, dc, m_printRect, m_pageRect);
777
 
        *maxPage += 1;
778
 
    }
779
 
    if (*maxPage > 0) *minPage = 1;
780
 
    *selPageFrom = *minPage;
781
 
    *selPageTo = *maxPage;
782
 
    m_printed = 0;
783
 
}
784
 
 
785
 
bool EditPrint::HasPage (int WXUNUSED(page)) {
786
 
 
787
 
    return (m_printed < m_edit->GetLength());
788
 
}
789
 
 
790
 
bool EditPrint::PrintScaling (wxDC *dc){
791
 
 
792
 
    // check for dc, return if none
793
 
    if (!dc) return false;
794
 
 
795
 
    // get printer and screen sizing values
796
 
    wxSize ppiScr;
797
 
    GetPPIScreen (&ppiScr.x, &ppiScr.y);
798
 
    if (ppiScr.x == 0) { // most possible guess 96 dpi
799
 
        ppiScr.x = 96;
800
 
        ppiScr.y = 96;
801
 
    }
802
 
    wxSize ppiPrt;
803
 
    GetPPIPrinter (&ppiPrt.x, &ppiPrt.y);
804
 
    if (ppiPrt.x == 0) { // scaling factor to 1
805
 
        ppiPrt.x = ppiScr.x;
806
 
        ppiPrt.y = ppiScr.y;
807
 
    }
808
 
    wxSize dcSize = dc->GetSize();
809
 
    wxSize pageSize;
810
 
    GetPageSizePixels (&pageSize.x, &pageSize.y);
811
 
 
812
 
    // set user scale
813
 
    float scale_x = (float)(ppiPrt.x * dcSize.x) /
814
 
                    (float)(ppiScr.x * pageSize.x);
815
 
    float scale_y = (float)(ppiPrt.y * dcSize.y) /
816
 
                    (float)(ppiScr.y * pageSize.y);
817
 
    dc->SetUserScale (scale_x, scale_y);
818
 
 
819
 
    return true;
820
 
}
821