1
/* AppArmor Profile Editor (C) 2006 Novell, Inc.
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.
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"
22
BEGIN_EVENT_TABLE(ProfileTextCtrl, wxStyledTextCtrl)
23
EVT_STC_CHANGE(ID_STYLED_PROFILE_WINDOW, ProfileTextCtrl::OnModified)
26
ProfileTextCtrl::ProfileTextCtrl(wxWindow *parent, wxWindowID id,
30
: wxStyledTextCtrl (parent, id, pos, size, style|wxTE_WORDWRAP|wxTE_MULTILINE|wxTE_PROCESS_ENTER)
32
mpParentWindow = parent;
33
SetLexer(wxSTC_LEX_APPARMOR);
35
RefreshColoursAndFonts();
41
* Loads a file from disk
42
* @param filename The file to load
43
* @return true on success, false on failure
45
bool ProfileTextCtrl::LoadFile(const wxString& filename)
50
if (!file.Open(filename))
53
mIgnoreChanges = true; // Have OnModified ignore the events from loading the file
56
wxStyledTextCtrl::LoadFile(filename);
57
mIgnoreChanges = false;
65
* Event handler triggered by any change in the window
68
void ProfileTextCtrl::OnModified(wxStyledTextEvent &event)
73
wxPostEvent(mpParentWindow, event);
78
* Reloads the syntax colouring and fonts
81
void ProfileTextCtrl::RefreshColoursAndFonts(void)
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();
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);