1
// GSymbolWindow.cs created with MonoDevelop
2
// User: dave at 11:15 AM 8/25/2007
4
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
8
using System.Runtime.InteropServices;
14
// Do.Core dependency needs to be removed
20
public class SymbolWindow : Gtk.Window
22
class DefaultIconBoxObject : IObject {
23
public string Icon { get { return "gtk-find"; } }
24
public string Name { get { return ""; } }
25
public string Description { get { return ""; } }
28
class NoItemsFoundObject : IObject {
29
public string Icon { get { return "gtk-dialog-question"; } }
30
public string Name { get { return "No items found."; } }
31
public string Description { get { return ""; } }
34
class NoCommandsFoundObject : IObject {
35
public string Icon { get { return "gtk-dialog-question"; } }
36
public string Name { get { return "No commands found."; } }
37
public string Description { get { return ""; } }
40
const int IconBoxIconSize = 128;
41
const double WindowTransparency = 0.91;
43
protected enum WindowFocus {
46
ModifierItemFocus = 2,
50
SymbolDisplayLabel displayLabel;
51
ResultsWindow resultsWindow;
57
protected Commander commander;
58
protected Command currentCommand;
59
protected Core.Item currentItem;
60
protected int currentItemIndex;
61
protected int currentCommandIndex;
62
protected WindowFocus focus;
63
protected string searchString;
64
protected string itemSearchString;
66
public SymbolWindow (Commander commander) : base ("GNOME Go")
70
this.commander = commander;
73
commander.SetDefaultStateEvent += OnDefaultStateEvent;
74
commander.SetSearchingItemsStateEvent += OnSearchingStateEvent;
75
commander.SetSearchingCommandsStateEvent += OnSearchingStateEvent;
76
commander.SetItemSearchCompleteStateEvent += OnSearchCompleteStateEvent;
77
commander.SetCommandSearchCompleteStateEvent += OnSearchCompleteStateEvent;
80
protected void Build ()
88
// This typehint gets the window to raise all the way to top.
89
TypeHint = WindowTypeHint.Splashscreen;
91
try { SetIconFromFile ("/usr/share/icons/gnome/scalable/actions/system-run.svg"); } catch { }
94
resultsWindow = new ResultsWindow ();
95
resultsWindow.SelectionChanged += OnResultsWindowSelectionChanged;
97
focus = WindowFocus.ItemFocus;
98
searchString = itemSearchString = "";
100
frame = new RoundedFrame ();
101
frame.DrawFill = true;
102
frame.FillColor = new Gdk.Color (0x35, 0x30, 0x45);
103
frame.FillAlpha = WindowTransparency;
108
vbox = new VBox (false, 0);
110
vbox.BorderWidth = 6;
113
resultsHBox = new HBox (false, 12);
114
resultsHBox.BorderWidth = 6;
115
vbox.PackStart (resultsHBox, false, false, 0);
118
itemBox = new IconBox (IconBoxIconSize);
119
itemBox.IsFocused = true;
120
resultsHBox.PackStart (itemBox, false, false, 0);
123
commandBox = new IconBox (IconBoxIconSize);
124
commandBox.IsFocused = false;
125
resultsHBox.PackStart (commandBox, false, false, 0);
128
modItemBox = new IconBox (IconBoxIconSize);
129
modItemBox.IsFocused = false;
130
// resultsHBox.PackStart (modItemBox, false, false, 0);
133
align = new Alignment (0.5F, 0.5F, 1, 1);
134
align.SetPadding (0, 0, 0, 0);
135
displayLabel = new SymbolDisplayLabel ();
136
align.Add (displayLabel);
137
vbox.PackStart (align, false, false, 0);
138
displayLabel.Show ();
141
ScreenChanged += OnScreenChanged;
146
protected virtual void SetColormap ()
148
Gdk.Colormap colormap;
150
colormap = Screen.RgbaColormap;
151
if (colormap == null) {
152
colormap = Screen.RgbColormap;
153
Console.WriteLine ("No alpha support.");
158
protected override bool OnButtonPressEvent (EventButton evnt)
164
public virtual new void Hide ()
167
resultsWindow.Hide ();
168
commander.State = CommanderState.Default;
171
public void Reposition ()
174
Gdk.Rectangle geo, main, results;
176
GetPosition (out main.X, out main.Y);
177
GetSize (out main.Width, out main.Height);
178
monitor = Screen.GetMonitorAtPoint (main.X, main.Y);
179
geo = Screen.GetMonitorGeometry (monitor);
180
main.X = (geo.Width - main.Width) / 2;
181
main.Y = (int) ((geo.Height - main.Height) / 2.5);
182
Move (main.X, main.Y);
184
resultsWindow.GetSize (out results.Width, out results.Height);
185
results.Y = main.Y + main.Height;
186
results.X = main.X + (IconBoxIconSize + 60) * (int) focus + 10;
187
resultsWindow.Move (results.X, results.Y);
190
protected override bool OnKeyPressEvent (EventKey evnt)
194
key = (Gdk.Key) evnt.KeyValue;
196
// Handle command keys (Quit, etc.)
197
if (((int) evnt.State & (int) ModifierType.ControlMask) != 0) {
208
case Gdk.Key.Shift_L:
209
case Gdk.Key.Control_L:
212
if (focus == WindowFocus.ItemFocus) {
213
if (searchString.Length == 0) {
216
resultsWindow.Hide ();
217
commander.State = CommanderState.Default;
219
if (searchString.Length == 0) {
220
resultsWindow.Hide ();
221
commander.State = CommanderState.Default;
229
case Gdk.Key.ISO_Enter:
233
case Gdk.Key.BackSpace:
234
if (searchString.Length > 1) {
235
searchString = searchString.Substring (0, searchString.Length-1);
238
commander.State = CommanderState.Default;
242
resultsWindow.Hide ();
243
if (focus == WindowFocus.ItemFocus && commander.CurrentItem != null) {
244
SetWindowFocus (WindowFocus.CommandFocus);
245
} else if (focus == WindowFocus.CommandFocus) {
246
SetWindowFocus (WindowFocus.ItemFocus);
252
if (key == Gdk.Key.Up) {
253
if (resultsWindow.SelectedIndex == 0) {
254
resultsWindow.Hide ();
256
resultsWindow.SelectPrev ();
259
else if (key == Gdk.Key.Down) {
260
if (resultsWindow.Visible) {
261
resultsWindow.SelectNext ();
263
resultsWindow.Show ();
274
c = (char) Gdk.Keyval.ToUnicode ((uint) key);
275
if (char.IsLetterOrDigit (c)
276
|| char.IsPunctuation (c)
278
|| char.IsSymbol (c)) {
288
protected virtual void ActivateCommand ()
290
commander.Execute ();
294
private void OnResultsWindowSelectionChanged (object sender, ResultsWindowSelectionEventArgs args)
296
if (focus == WindowFocus.ItemFocus) {
297
SetItemIndex (args.SelectedIndex, searchString);
298
} else if (focus == WindowFocus.CommandFocus) {
299
SetCommandIndex (args.SelectedIndex, searchString);
303
private void OnScreenChanged (object sender, EventArgs args)
308
protected virtual void SetFrameRadius ()
310
if (Screen.IsComposited) {
317
protected override bool OnExposeEvent (EventExpose evnt)
321
cairo = Gdk.CairoHelper.Create (GdkWindow);
322
cairo.Rectangle (evnt.Area.X, evnt.Area.Y, evnt.Area.Width, evnt.Area.Height);
323
cairo.Color = new Cairo.Color (1.0, 1.0, 1.0, 0.0);
324
cairo.Operator = Cairo.Operator.Source;
327
return base.OnExposeEvent (evnt);
330
protected virtual void SetWindowFocus (WindowFocus focus)
339
case WindowFocus.CommandFocus:
340
searchString = commander.CommandSearchString;
341
results = commander.CurrentCommands;
342
selectedIndex = commander.CurrentCommandIndex;
344
case WindowFocus.ItemFocus:
345
searchString = commander.ItemSearchString;
346
results = commander.CurrentItems;
347
selectedIndex = commander.CurrentItemIndex;
351
resultsWindow.Results = results;
352
resultsWindow.SelectedIndex = selectedIndex;
354
displayLabel.DisplayObject = resultsWindow.SelectedObject;
355
displayLabel.Highlight = searchString;
356
itemBox.IsFocused = (focus == WindowFocus.ItemFocus);
357
commandBox.IsFocused = (focus == WindowFocus.CommandFocus);
358
modItemBox.IsFocused = (focus == WindowFocus.ModifierItemFocus);
363
protected virtual void QueueSearch ()
366
case WindowFocus.ItemFocus:
367
commander.SearchItems (searchString);
369
case WindowFocus.CommandFocus:
370
commander.SearchCommands (searchString);
375
protected virtual void SetItemIndex (int itemIndex, string match)
377
if (itemIndex >= commander.CurrentItems.Length) {
378
SetItemIndex (commander.CurrentItems.Length-1, match);
382
commander.CurrentItemIndex = itemIndex;
383
} catch (IndexOutOfRangeException) {
386
itemBox.DisplayObject = commander.CurrentItem;
387
itemBox.Highlight = match;
388
if (focus == WindowFocus.ItemFocus) {
389
displayLabel.DisplayObject = commander.CurrentItem;
390
displayLabel.Highlight = searchString;
392
SetCommandIndex (0, "");
395
protected virtual void SetCommandIndex (int commandIndex, string match)
398
commander.CurrentCommandIndex = commandIndex;
399
} catch (IndexOutOfRangeException) {
403
commandBox.DisplayObject = commander.CurrentCommand;
404
commandBox.Highlight = match;
405
if (focus == WindowFocus.CommandFocus) {
406
displayLabel.DisplayObject = commander.CurrentCommand;
407
displayLabel.Highlight = match;
411
protected virtual void SetDefaultState ()
413
searchString = itemSearchString = "";
415
SetWindowFocus (WindowFocus.ItemFocus);
417
itemBox.DisplayObject = new DefaultIconBoxObject ();
420
displayLabel.SetDisplayLabel ("Type to begin searching", "Type to start searching.");
423
protected virtual void SetNoResultsFoundState ()
426
case WindowFocus.CommandFocus:
427
commandBox.DisplayObject = new NoCommandsFoundObject ();
430
// case WindowFocus.ItemFocus:
432
itemBox.DisplayObject = new NoItemsFoundObject ();
435
displayLabel.Text = "";
438
protected void OnDefaultStateEvent ()
443
protected void OnSearchingStateEvent ()
447
protected void OnSearchCompleteStateEvent ()
452
case WindowFocus.ItemFocus:
453
results = commander.CurrentItems;
455
case WindowFocus.CommandFocus:
456
results = commander.CurrentCommands;
459
results = new GCObject [0];
463
resultsWindow.Results = results;
464
if (results.Length == 0) {
465
SetNoResultsFoundState ();
467
SetItemIndex (commander.CurrentItemIndex, commander.ItemSearchString);
468
SetCommandIndex (commander.CurrentCommandIndex, commander.CommandSearchString);