annotate QRForm.cs @ 0:aca8706f4eec default tip

Initial commit
author Brad Greco <brad@bgreco.net>
date Mon, 13 Oct 2014 21:28:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
1 using System;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
2 using System.Collections.Generic;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
3 using System.ComponentModel;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
4 using System.Data;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
5 using System.Drawing;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
6 using System.Drawing.Imaging;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
7 using System.IO;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
8 using System.Runtime.InteropServices;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
9 using System.Text;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
10 using System.Windows.Forms;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
11 using ZXing;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
12 using Microsoft.Win32;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
13
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
14 /*
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
15 * Copyright (c) 2014 Brad Greco <brad@bgreco.net>
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
16 */
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
17 namespace QuickQR
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
18 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
19 public partial class QRForm : Form
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
20 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
21 const int WM_HOTKEY = 786;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
22
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
23 private BarcodeWriter writer;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
24 private KeyBinding keyBinding;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
25 private String currentText;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
26 private Settings settings;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
27
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
28 [DllImport("user32.dll")]
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
29 private static extern int RegisterHotKey(IntPtr hwnd, int id, int fsModifiers, int vk);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
30 [DllImport("user32.dll")]
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
31 private static extern int UnregisterHotKey(IntPtr hwnd, int id);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
32
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
33 public QRForm()
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
34 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
35 InitializeComponent();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
36 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
37
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
38 private void QRForm_Load(object sender, EventArgs e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
39 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
40 settings = new Settings();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
41 loadSettings();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
42 registerHotkey(keyBinding);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
43 writer = new BarcodeWriter { Format = BarcodeFormat.QR_CODE };
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
44 writer.Options.Margin = 2;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
45 fileHide.ShortcutKeyDisplayString = "Esc";
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
46 reset();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
47 notifyIcon.Icon = new System.Drawing.Icon(this.Icon, 16, 16);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
48 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
49
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
50 private void notifyIcon_DoubleClick(object sender, EventArgs e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
51 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
52 this.Show();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
53 this.Activate();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
54 generateFromClipboard();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
55 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
56
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
57 private void generateFromClipboard()
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
58 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
59 if (Clipboard.ContainsText())
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
60 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
61 inputTextBox.Text = Clipboard.GetText();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
62 generate(Clipboard.GetText());
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
63 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
64 else
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
65 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
66 reset();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
67 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
68 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
69
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
70 private void generateFromTextBox()
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
71 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
72 if (inputTextBox.Text.Length > 0)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
73 generate(inputTextBox.Text);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
74 else
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
75 reset();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
76 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
77
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
78 private void generate(String text)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
79 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
80 System.Diagnostics.Debug.WriteLine("Generating: " + text);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
81 currentText = text;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
82 draw();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
83 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
84
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
85 private void draw()
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
86 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
87 writer.Options.Width = QRImage.Width;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
88 writer.Options.Height = QRImage.Height;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
89 try
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
90 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
91 QRImage.Image = writer.Write(currentText);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
92 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
93 catch (Exception e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
94 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
95 System.Diagnostics.Debug.WriteLine(e.Message);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
96 showError(e.Message);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
97 return;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
98 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
99 finally
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
100 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
101 inputTextBox.SelectAll();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
102 inputTextBox.Focus();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
103 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
104 if (QRLabel.ForeColor != Color.Black)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
105 QRLabel.ForeColor = Color.Black;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
106 QRLabel.Text = currentText;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
107 fileSaveAs.Enabled = true;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
108 QRImage.ContextMenuStrip = imageMenu;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
109 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
110
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
111 private void registerHotkey(KeyBinding hotkey)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
112 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
113 settings.setHotkey(hotkey);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
114 unregisterHotkey();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
115 if (hotkey.key > 0)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
116 RegisterHotKey(this.Handle, hotkey.getID(), hotkey.sum(), hotkey.key);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
117 keyBinding = hotkey;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
118 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
119
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
120 private void unregisterHotkey()
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
121 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
122 if (keyBinding.key > 0)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
123 UnregisterHotKey(this.Handle, keyBinding.getID());
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
124 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
125
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
126 private void showHotkeyForm()
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
127 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
128 unregisterHotkey();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
129 SetHotkey form = new SetHotkey(keyBinding);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
130 if (form.ShowDialog() == DialogResult.OK)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
131 registerHotkey(form.keyBinding);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
132 form.Dispose();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
133 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
134
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
135 private void loadSettings()
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
136 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
137 optionWinStart.Checked = menuAutorun.Checked = settings.autostart;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
138 optionBackground.Checked = settings.background;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
139 keyBinding = new KeyBinding(settings.hotkey);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
140 registerAutostart();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
141 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
142
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
143 private void registerAutostart()
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
144 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
145 RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
146 if (settings.autostart)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
147 key.SetValue("QuickQR", Application.ExecutablePath.ToString());
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
148 else
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
149 key.DeleteValue("QuickQR", false);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
150 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
151
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
152 private void showError(String message)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
153 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
154 QRLabel.ForeColor = Color.Red;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
155 QRLabel.Text = message;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
156 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
157
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
158 private void reset()
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
159 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
160 inputTextBox.Text = string.Empty;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
161 QRImage.Image = null;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
162 QRLabel.Text = String.Empty;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
163 inputTextBox.Focus();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
164 currentText = string.Empty;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
165 fileSaveAs.Enabled = false;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
166 QRImage.ContextMenuStrip = null;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
167 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
168
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
169 private void toggleBackground()
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
170 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
171 settings.setBackground(!settings.background);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
172 optionBackground.Checked = settings.background;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
173 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
174
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
175 private void toggleAutorun()
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
176 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
177 settings.setAutostart(!settings.autostart);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
178 optionWinStart.Checked = menuAutorun.Checked = settings.autostart;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
179 registerAutostart();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
180 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
181
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
182 private void saveImage()
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
183 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
184 SaveFileDialog dialog = new SaveFileDialog();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
185 dialog.DefaultExt = "png";
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
186 dialog.Filter = "PNG images (*.png)|*.png|All files (*.*)|*.*";
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
187 String fileName = currentText;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
188 foreach (char c in Path.GetInvalidFileNameChars())
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
189 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
190 fileName = fileName.Replace(c.ToString(), "");
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
191 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
192 dialog.FileName = fileName;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
193 if (dialog.ShowDialog() == DialogResult.OK)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
194 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
195 QRImage.Image.Save(dialog.FileName, ImageFormat.Png);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
196 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
197 dialog.Dispose();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
198 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
199
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
200 [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
201 protected override void WndProc(ref Message m)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
202 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
203 // Listen for operating system messages.
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
204 switch (m.Msg)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
205 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
206 case WM_HOTKEY:
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
207 System.Diagnostics.Debug.WriteLine(m.WParam.ToString());
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
208 if (m.WParam.ToInt32() == keyBinding.getID())
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
209 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
210 System.Diagnostics.Debug.WriteLine("Our hotkey received");
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
211 this.Show();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
212 this.Activate();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
213 generateFromClipboard();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
214 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
215 break;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
216 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
217 base.WndProc(ref m);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
218 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
219
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
220 protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
221 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
222 if (keyData == Keys.Escape)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
223 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
224 if (settings.background)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
225 this.Hide();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
226 else
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
227 Application.Exit();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
228 return true;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
229 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
230 return base.ProcessCmdKey(ref msg, keyData);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
231 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
232
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
233 private void QRForm_Resize(object sender, EventArgs e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
234 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
235 if (currentText != string.Empty)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
236 draw();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
237 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
238
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
239 private void inputTextBox_KeyDown(object sender, KeyEventArgs e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
240 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
241 if (e.KeyCode == Keys.Enter)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
242 generateFromTextBox();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
243 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
244
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
245 private void generateButton_Click(object sender, EventArgs e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
246 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
247 generateFromTextBox();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
248 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
249
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
250 private void fileHide_Click(object sender, EventArgs e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
251 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
252 this.Hide();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
253 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
254
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
255 private void fileExit_Click(object sender, EventArgs e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
256 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
257 Application.Exit();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
258 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
259
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
260 private void menuGenerateClipboard_Click(object sender, EventArgs e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
261 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
262 this.Show();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
263 generateFromClipboard();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
264 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
265
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
266 private void menuNew_Click(object sender, EventArgs e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
267 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
268 this.Show();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
269 reset();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
270 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
271
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
272 private void exitToolStripMenuItem_Click(object sender, EventArgs e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
273 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
274 Application.Exit();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
275 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
276
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
277 private void QRForm_FormClosing(object sender, FormClosingEventArgs e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
278 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
279 System.Diagnostics.Debug.WriteLine("Reason: " + e.CloseReason);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
280 if (settings.background && (e.CloseReason == CloseReason.None || e.CloseReason == CloseReason.UserClosing))
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
281 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
282 this.Hide();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
283 e.Cancel = true;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
284 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
285 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
286
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
287 private void optionHotkey_Click(object sender, EventArgs e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
288 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
289 showHotkeyForm();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
290 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
291
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
292 private void menuAutorun_Click(object sender, EventArgs e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
293 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
294 toggleAutorun();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
295 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
296
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
297 private void menuHotkey_Click(object sender, EventArgs e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
298 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
299 showHotkeyForm();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
300 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
301
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
302 private void optionWinStart_Click(object sender, EventArgs e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
303 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
304 toggleAutorun();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
305 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
306
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
307 private void optionBackground_Click(object sender, EventArgs e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
308 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
309 toggleBackground();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
310 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
311
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
312 private void imageCopy_Click(object sender, EventArgs e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
313 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
314 Clipboard.SetImage(QRImage.Image);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
315 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
316
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
317 private void fileSaveAs_Click(object sender, EventArgs e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
318 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
319 saveImage();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
320 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
321
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
322 private void imageSaveAs_Click(object sender, EventArgs e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
323 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
324 saveImage();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
325 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
326
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
327 private void helpAbout_Click(object sender, EventArgs e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
328 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
329 AboutForm form = new AboutForm();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
330 form.ShowDialog();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
331 form.Dispose();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
332 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
333 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
334 }