1 // CFPrefs.h
2 // this file is part of Context Free
3 // ---------------------
4 // Copyright (C) 2008 John Horigan - john@glyphic.com
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 //
20 // John Horigan can be contacted at john@glyphic.com or at
21 // John Horigan, 1209 Villa St., Mountain View, CA 94041-1123, USA
22 //
23 //
24 
25 #pragma once
26 
27 #include "PreferenceManager.h"
28 
29 namespace ContextFreeNet {
30     public ref class CFPrefs : public OzoneUtil::PreferenceManager
31     {
32     public:
CFPrefs()33         CFPrefs()
34             : OzoneUtil::PreferenceManager("Software\\OzoneSoft\\ContextFree\\Settings", false)
35         { }
36 
37     protected:
~CFPrefs()38         ~CFPrefs()
39         { }
40 
41     public:
42         enum class OpenAction { Welcome = 0, New = 1, Nothing = 2 };
43         // These random bytes are courtesy of http://www.fourmilab.ch/hotbits/
44         static array<System::Byte>^ CFentropy = {
45             210, 61, 229, 177, 254, 52, 150, 62, 81, 246, 248, 185, 59, 89, 93, 117,
46             142, 120, 64, 79, 229, 71, 195, 27, 181, 140, 195, 78, 123, 167, 45,
47             224, 108, 172, 164, 130, 68, 64, 103, 98, 136, 132, 14, 3, 240, 232,
48             152, 220, 29, 154, 78, 181, 92, 109, 92, 176, 46, 128, 13, 79, 108, 144,
49             83, 219, 42, 161, 158, 81, 213, 120, 13, 198, 163, 40, 14, 135, 30, 13,
50             117, 128, 172, 184, 61, 69, 50, 233, 116, 202, 161, 204, 223, 52, 126,
51             151, 223, 14, 123, 12, 29, 100, 71, 22, 247, 41, 231, 97, 116, 58, 168,
52             125, 92, 26, 4, 3, 228, 182, 204, 43, 185, 79, 118, 137, 173, 163, 215,
53             111, 60, 253
54         };
55         property bool AnimateZoom {
set(bool setTo)56             void set(bool setTo) { SetPrefBool("AnimateZoom", setTo); }
get()57             bool get() { return GetPrefBool("AnimateZoom", true); }
58         }
59         property bool ProgressiveRender {
set(bool setTo)60             void set(bool setTo) { SetPrefBool("ProgressiveRender", setTo); }
get()61             bool get() { return GetPrefBool("ProgressiveRender", true); }
62         }
63         property bool DontDisplay {
set(bool setTo)64             void set(bool setTo) { SetPrefBool("DontDisplay", setTo); }
get()65             bool get() { return GetPrefBool("DontDisplay", false); }
66         }
67         property bool ImageCrop {
set(bool setTo)68             void set(bool setTo) { SetPrefBool("ImageCrop", setTo); }
get()69             bool get() { return GetPrefBool("ImageCrop", true); }
70         }
71         property bool ImageAppendVariation {
set(bool setTo)72             void set(bool setTo) { SetPrefBool("ImageAppendVariation", setTo); }
get()73             bool get() { return GetPrefBool("ImageAppendVariation", false); }
74         }
75         property bool RenderOnOpen {
set(bool setTo)76             void set(bool setTo) { SetPrefBool("RenderOnOpen", setTo); }
get()77             bool get() { return GetPrefBool("RenderOnOpen", true); }
78         }
79         property double BorderWidth {
set(double setTo)80             void set(double setTo) { SetPrefDouble("BorderWidth", setTo); }
get()81             double get() { return GetPrefDouble("BorderWidth", 2.0); }
82         }
83         property double MinimumSize {
set(double setTo)84             void set(double setTo) { SetPrefDouble("MinimumSize", setTo); }
get()85             double get() { return GetPrefDouble("MinimumSize", 0.3); }
86         }
87         property int AnimateHeight {
set(int setTo)88             void set(int setTo) { SetPrefInt("AnimateHeight", setTo); }
get()89             int get() { return GetPrefInt("AnimateHeight", 480); }
90         }
91         property int AnimateWidth {
set(int setTo)92             void set(int setTo) { SetPrefInt("AnimateWidth", setTo); }
get()93             int get() { return GetPrefInt("AnimateWidth", 640); }
94         }
95         property int AnimateLength {
set(int setTo)96             void set(int setTo) { SetPrefInt("AnimateLength", setTo); }
get()97             int get() { return GetPrefInt("AnimateLength", 10); }
98         }
99         property int AnimateFrameRate {
set(int setTo)100             void set(int setTo) { SetPrefInt("AnimateFPS", setTo); }
get()101             int get() { return GetPrefInt("AnimateFPS", 15); }
102         }
103         property int AnimateCodec {
set(int setTo)104             void set(int setTo) { SetPrefInt("AnimateCodec", setTo); }
get()105             int get() { return GetPrefInt("AnimateCodec", 0); }
106         }
107         property bool AnimatePreview {
set(bool setTo)108             void set(bool setTo) { SetPrefBool("AnimatePreview", setTo); }
get()109             bool get() { return GetPrefBool("AnimatePreview", true); }
110         }
111         property bool AnimatePreviewLoop {
set(bool setTo)112             void set(bool setTo) { SetPrefBool("AnimatePreviewLoop", setTo); }
get()113             bool get() { return GetPrefBool("AnimatePreviewLoop", false); }
114         }
115         property int JPEGQuality {
set(int setTo)116             void set(int setTo) { SetPrefInt("JPEGQuality", setTo); }
get()117             int get() { return GetPrefInt("JPEGQuality", 90); }
118         }
119         property int RenderHeight {
set(int setTo)120             void set(int setTo) { SetPrefInt("RenderHeight", setTo); }
get()121             int get() { return GetPrefInt("RenderHeight", 1000); }
122         }
123         property int RenderWidth {
set(int setTo)124             void set(int setTo) { SetPrefInt("RenderWidth", setTo); }
get()125             int get() { return GetPrefInt("RenderWidth", 1000); }
126         }
127         property int FormHeight {
set(int setTo)128             void set(int setTo) { SetPrefInt("FormHeight", setTo); }
get()129             int get() { return GetPrefInt("FormHeight", 715); }
130         }
131         property int FormWidth {
set(int setTo)132             void set(int setTo) { SetPrefInt("FormWidth", setTo); }
get()133             int get() { return GetPrefInt("FormWidth", 1100); }
134         }
135         property int EditorSplitter {
set(int setTo)136             void set(int setTo) { SetPrefInt("EditorSplitterInt", setTo); }
get()137             int get() { return GetPrefInt("EditorSplitterInt", 600); }
138         }
139         property int DocumentSplitter {
set(int setTo)140             void set(int setTo) { SetPrefInt("DocumentSplitterInt", setTo); }
get()141             int get() { return GetPrefInt("DocumentSplitterInt", 300); }
142         }
143         property OpenAction StartupDocument {
set(OpenAction setTo)144             void set(OpenAction setTo) { SetPrefInt("StartupDocument", (int)setTo); }
get()145             OpenAction get() { return (OpenAction)GetPrefInt("StartupDocument", (int)OpenAction::Welcome); }
146         }
147         property bool SkipAccount {
set(bool setTo)148             void set(bool setTo) { SetPrefBool("SkipAccount", setTo); }
get()149             bool get() { return GetPrefBool("SkipAccount", false); }
150         }
151         property System::String^ GalUsername {
152             void set(System::String^ setTo) { SetPrefString("GalUsername", setTo); }
153             System::String^ get() { return GetPrefString("GalUsername", "please specify"); }
154         }
155         property System::String^ GalPassword {
156             void set(System::String^ setTo) { SetPrefProtectedString("GalPassword", CFentropy, setTo); }
157             System::String^ get() { return GetPrefProtectedString("GalPassword", CFentropy, nullptr); }
158         }
159         property System::String^ GalPasswordCleartext {
160             // No setter, destructive getter
161             System::String^ get()
162             {
163                 System::String^ ret = GetPrefString("GalPassword", nullptr);
164                 if (ret)
165                     DeletePref("GalPassword");
166                 return ret;
167             }
168         }
169         property System::String^ ccLicense {
170             void set(System::String^ setTo) { SetPrefString("ccLicense", setTo); }
171             System::String^ get() { return GetPrefString("ccLicense", ""); }
172         }
173         property System::String^ ccImage {
174             void set(System::String^ setTo) { SetPrefString("ccImage", setTo); }
175             System::String^ get() { return GetPrefString("ccImage", ""); }
176         }
177         property System::String^ ccName {
178             void set(System::String^ setTo) { SetPrefString("ccName", setTo); }
179             System::String^ get() { return GetPrefString("ccName", ""); }
180         }
181         property int TabWidth {
set(int setTo)182             void set(int setTo) { SetPrefInt("TabWidth", setTo); }
get()183             int get() { return GetPrefInt("TabWidth", 4); }
184         }
185         property System::Drawing::Font^ TextFont {
186             void set(System::Drawing::Font^ setTo)
187             {
188                 try {
189                     System::IO::MemoryStream^ ms = gcnew System::IO::MemoryStream();
190                     System::Runtime::Serialization::Formatters::Binary::BinaryFormatter^ fmt =
191                         gcnew System::Runtime::Serialization::Formatters::Binary::BinaryFormatter();
192                     fmt->Serialize(ms, setTo);
193                     SetPrefBinary("TextFont", ms->GetBuffer());
194                 } catch (System::Runtime::Serialization::SerializationException^ e) {
195                     System::Console::WriteLine("Failed to serialize. Reason: {0}", e->Message );
196                 }
197             }
198             System::Drawing::Font^ get() {
199                 array<System::Byte>^ data = GetPrefBinary("TextFont", nullptr);
200 
201                 if (data != nullptr) {
202                     try {
203                         System::IO::MemoryStream^ ms = gcnew System::IO::MemoryStream(data, false);
204                         System::Runtime::Serialization::Formatters::Binary::BinaryFormatter^ fmt =
205                             gcnew System::Runtime::Serialization::Formatters::Binary::BinaryFormatter();
206                         return dynamic_cast<System::Drawing::Font^>(fmt->Deserialize(ms));
207                     } catch (System::Runtime::Serialization::SerializationException^ e) {
208                         System::Console::WriteLine("Failed to deserialize. Reason: {0}", e->Message );
209                     }
210                 }
211 
212                 return gcnew System::Drawing::Font("Microsoft Sans Serif", 8.0);
213             }
214         }
215         property bool StyleDefaultBold {
set(bool setTo)216             void set(bool setTo) { SetPrefBool("StyleDefaultBold", setTo); }
get()217             bool get() { return GetPrefBool("StyleDefaultBold", false); }
218         }
219         property bool StyleCommentsBold {
set(bool setTo)220             void set(bool setTo) { SetPrefBool("StyleCommentsBold", setTo); }
get()221             bool get() { return GetPrefBool("StyleCommentsBold", false); }
222         }
223         property bool StyleSymbolsBold {
set(bool setTo)224             void set(bool setTo) { SetPrefBool("StyleSymbolsBold", setTo); }
get()225             bool get() { return GetPrefBool("StyleSymbolsBold", false); }
226         }
227         property bool StyleIdentifiersBold {
set(bool setTo)228             void set(bool setTo) { SetPrefBool("StyleIdentifiersBold", setTo); }
get()229             bool get() { return GetPrefBool("StyleIdentifiersBold", false); }
230         }
231         property bool StyleKeywordsBold {
set(bool setTo)232             void set(bool setTo) { SetPrefBool("StyleKeywordsBold", setTo); }
get()233             bool get() { return GetPrefBool("StyleKeywordsBold", true); }
234         }
235         property bool StyleBuiltinsBold {
set(bool setTo)236             void set(bool setTo) { SetPrefBool("StyleBuiltinsBold", setTo); }
get()237             bool get() { return GetPrefBool("StyleBuiltinsBold", true); }
238         }
239         property bool StyleStringsBold {
set(bool setTo)240             void set(bool setTo) { SetPrefBool("StyleStringsBold", setTo); }
get()241             bool get() { return GetPrefBool("StyleStringsBold", false); }
242         }
243         property bool StyleNumbersBold {
set(bool setTo)244             void set(bool setTo) { SetPrefBool("StyleNumbersBold", setTo); }
get()245             bool get() { return GetPrefBool("StyleNumbersBold", false); }
246         }
247         property bool StyleDefaultItalic {
set(bool setTo)248             void set(bool setTo) { SetPrefBool("StyleDefaultItalic", setTo); }
get()249             bool get() { return GetPrefBool("StyleDefaultItalic", false); }
250         }
251         property bool StyleCommentsItalic {
set(bool setTo)252             void set(bool setTo) { SetPrefBool("StyleCommentsItalic", setTo); }
get()253             bool get() { return GetPrefBool("StyleCommentsItalic", true); }
254         }
255         property bool StyleSymbolsItalic {
set(bool setTo)256             void set(bool setTo) { SetPrefBool("StyleSymbolsItalic", setTo); }
get()257             bool get() { return GetPrefBool("StyleSymbolsItalic", false); }
258         }
259         property bool StyleIdentifiersItalic {
set(bool setTo)260             void set(bool setTo) { SetPrefBool("StyleIdentifiersItalic", setTo); }
get()261             bool get() { return GetPrefBool("StyleIdentifiersItalic", false); }
262         }
263         property bool StyleKeywordsItalic {
set(bool setTo)264             void set(bool setTo) { SetPrefBool("StyleKeywordsItalic", setTo); }
get()265             bool get() { return GetPrefBool("StyleKeywordsItalic", false); }
266         }
267         property bool StyleBuiltinsItalic {
set(bool setTo)268             void set(bool setTo) { SetPrefBool("StyleBuiltinsItalic", setTo); }
get()269             bool get() { return GetPrefBool("StyleBuiltinsItalic", false); }
270         }
271         property bool StyleStringsItalic {
set(bool setTo)272             void set(bool setTo) { SetPrefBool("StyleStringsItalic", setTo); }
get()273             bool get() { return GetPrefBool("StyleStringsItalic", false); }
274         }
275         property bool StyleNumbersItalic {
set(bool setTo)276             void set(bool setTo) { SetPrefBool("StyleNumbersItalic", setTo); }
get()277             bool get() { return GetPrefBool("StyleNumbersItalic", false); }
278         }
279         property System::String^ StyleDefaultColor {
280             void set(System::String^ setTo) { SetPrefColorString("StyleDefaultColor", setTo, "#000"); }
281             System::String^ get() { return GetPrefString("StyleDefaultColor", "#000"); }
282         }
283         property System::String^ StyleCommentsColor {
284             void set(System::String^ setTo) { SetPrefColorString("StyleCommentsColor", setTo, "#097BF7"); }
285             System::String^ get() { return GetPrefString("StyleCommentsColor", "#097BF7"); }
286         }
287         property System::String^ StyleSymbolsColor {
288             void set(System::String^ setTo) { SetPrefColorString("StyleSymbolsColor", setTo, "#101010"); }
289             System::String^ get() { return GetPrefString("StyleSymbolsColor", "#101010"); }
290         }
291         property System::String^ StyleIdentifiersColor {
292             void set(System::String^ setTo) { SetPrefColorString("StyleIdentifiersColor", setTo, "#00567F"); }
293             System::String^ get() { return GetPrefString("StyleIdentifiersColor", "#00567F"); }
294         }
295         property System::String^ StyleKeywordsColor {
296             void set(System::String^ setTo) { SetPrefColorString("StyleKeywordsColor", setTo, "#56007F"); }
297             System::String^ get() { return GetPrefString("StyleKeywordsColor", "#56007F"); }
298         }
299         property System::String^ StyleBuiltinsColor {
300             void set(System::String^ setTo) { SetPrefColorString("StyleBuiltinsColor", setTo, "#007F00"); }
301             System::String^ get() { return GetPrefString("StyleBuiltinsColor", "#007F00"); }
302         }
303         property System::String^ StyleStringsColor {
304             void set(System::String^ setTo) { SetPrefColorString("StyleStringsColor", setTo, "#FFAA3E"); }
305             System::String^ get() { return GetPrefString("StyleStringsColor", "#FFAA3E"); }
306         }
307         property System::String^ StyleNumbersColor {
308             void set(System::String^ setTo) { SetPrefColorString("StyleNumbersColor", setTo, "#7F7F00"); }
309             System::String^ get() { return GetPrefString("StyleNumbersColor", "#7F7F00"); }
310         }
311     } ;
312 }
313