~ubuntu-branches/ubuntu/wily/apparmor/wily

« back to all changes in this revision

Viewing changes to deprecated/management/profile-editor/src/ProfileTextCtrl.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2011-04-27 10:38:07 UTC
  • mfrom: (5.1.118 natty)
  • Revision ID: james.westby@ubuntu.com-20110427103807-ym3rhwys6o84ith0
Tags: 2.6.1-2
debian/copyright: clarify for some full organization names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*      AppArmor Profile Editor (C) 2006 Novell, Inc.
 
2
 *
 
3
 *      This program is free software; you can redistribute it and/or modify
 
4
 *      it under the terms of the GNU General Public License as published by
 
5
 *      the Free Software Foundation; either version 2 of the License, or
 
6
 *      (at your option) any later version.
 
7
 * 
 
8
 */
 
9
#include "wx/wxprec.h"
 
10
 
 
11
#ifndef WX_PRECOMP
 
12
#include "wx/wx.h"
 
13
#endif
 
14
 
 
15
#include <wx/textctrl.h>
 
16
#include <wx/textfile.h>
 
17
#include <wx/config.h>
 
18
#include "ProfileTextCtrl.h"
 
19
#include "Preferences.h"
 
20
#include "Configuration.h"
 
21
 
 
22
BEGIN_EVENT_TABLE(ProfileTextCtrl, wxStyledTextCtrl)
 
23
        EVT_STC_CHANGE(ID_STYLED_PROFILE_WINDOW, ProfileTextCtrl::OnModified)
 
24
END_EVENT_TABLE()
 
25
 
 
26
ProfileTextCtrl::ProfileTextCtrl(wxWindow *parent, wxWindowID id,
 
27
                                const wxPoint &pos,
 
28
                                const wxSize &size,
 
29
                                long style)
 
30
                :  wxStyledTextCtrl (parent, id, pos, size, style|wxTE_WORDWRAP|wxTE_MULTILINE|wxTE_PROCESS_ENTER)
 
31
{
 
32
        mpParentWindow = parent;
 
33
        SetLexer(wxSTC_LEX_APPARMOR);
 
34
        StyleClearAll();
 
35
        RefreshColoursAndFonts();
 
36
        mNeedSaving = false;
 
37
        mIsNew = false;
 
38
}
 
39
 
 
40
/**
 
41
 * Loads a file from disk
 
42
 * @param filename The file to load
 
43
 * @return true on success, false on failure
 
44
 */
 
45
bool ProfileTextCtrl::LoadFile(const wxString& filename)
 
46
{
 
47
        wxTextFile file;
 
48
        wxString currentLine;
 
49
 
 
50
        if (!file.Open(filename))
 
51
                return false;
 
52
 
 
53
        mIgnoreChanges = true; // Have OnModified ignore the events from loading the file
 
54
        Clear();
 
55
        mFilename = filename;   
 
56
        wxStyledTextCtrl::LoadFile(filename);
 
57
        mIgnoreChanges = false;
 
58
 
 
59
        mNeedSaving = false;
 
60
        mIsNew = false;
 
61
        return true;
 
62
}
 
63
 
 
64
/**
 
65
 * Event handler triggered by any change in the window
 
66
 * @param event 
 
67
 */
 
68
void ProfileTextCtrl::OnModified(wxStyledTextEvent &event)
 
69
{
 
70
        if (!mIgnoreChanges)
 
71
        {
 
72
                mNeedSaving = true;
 
73
                wxPostEvent(mpParentWindow, event);     
 
74
        }
 
75
}
 
76
 
 
77
/**
 
78
 * Reloads the syntax colouring and fonts
 
79
 * @param  
 
80
 */
 
81
void ProfileTextCtrl::RefreshColoursAndFonts(void)
 
82
{
 
83
        wxColour yellowColour(252,253,127);
 
84
        wxFont defaultFont (10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
 
85
        wxFont commentFont = Configuration::GetCommentFont();
 
86
        wxFont includeFont = Configuration::GetIncludeFont();
 
87
        wxFont capabilityFont = Configuration::GetCapabilityFont();
 
88
        wxFont permFont = Configuration::GetPermFont();
 
89
        wxFont pathFont = Configuration::GetPathFont();
 
90
 
 
91
        StyleSetFont (wxSTC_STYLE_DEFAULT, defaultFont);
 
92
        StyleSetForeground (wxSTC_STYLE_DEFAULT, *wxBLACK);
 
93
        StyleSetBackground (wxSTC_STYLE_DEFAULT, *wxWHITE);
 
94
        StyleSetFont (wxSTC_APPARMOR_COMMENT, commentFont);
 
95
        StyleSetForeground (wxSTC_APPARMOR_COMMENT, Configuration::GetCommentColour());
 
96
        StyleSetBackground (wxSTC_APPARMOR_COMMENT, *wxWHITE);
 
97
        StyleSetFont (wxSTC_APPARMOR_INCLUDE, includeFont);
 
98
        StyleSetForeground (wxSTC_APPARMOR_INCLUDE, Configuration::GetIncludeColour());
 
99
        StyleSetBackground (wxSTC_APPARMOR_INCLUDE, *wxWHITE);
 
100
        StyleSetFont (wxSTC_APPARMOR_CAPABILITY, capabilityFont);
 
101
        StyleSetForeground (wxSTC_APPARMOR_CAPABILITY, Configuration::GetCapColour());
 
102
        StyleSetBackground (wxSTC_APPARMOR_CAPABILITY, *wxWHITE);
 
103
        StyleSetFont (wxSTC_APPARMOR_PATH, pathFont);
 
104
        StyleSetForeground (wxSTC_APPARMOR_PATH, Configuration::GetPathColour());
 
105
        StyleSetBackground (wxSTC_APPARMOR_PATH, *wxWHITE);
 
106
        StyleSetFont (wxSTC_APPARMOR_PERMS, permFont);
 
107
        StyleSetForeground (wxSTC_APPARMOR_PERMS, Configuration::GetPermColour());
 
108
        StyleSetBackground (wxSTC_APPARMOR_PERMS, *wxWHITE);
 
109
        StyleSetForeground (wxSTC_STYLE_BRACELIGHT, *wxBLACK);
 
110
        StyleSetBackground (wxSTC_STYLE_BRACELIGHT, yellowColour);
 
111
        StyleSetForeground (wxSTC_STYLE_BRACEBAD, *wxBLACK);
 
112
        StyleSetBackground (wxSTC_STYLE_BRACEBAD, *wxRED);
 
113
        SetCaretWidth(2);
 
114
}
 
115