3
* GNOME Do is the legal property of its developers. Please refer to the
4
* COPYRIGHT file distributed with this source distribution.
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
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.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21
using System.Collections.Generic;
29
using Do.Universe.Common;
31
using Do.Interface.Widgets;
33
namespace Do.Interface {
35
public class ClassicWindow : Gtk.Window, IDoWindow {
37
//-------------------Class Members------------------
38
Do.Interface.Widgets.Frame frame;
39
SymbolDisplayLabel label;
40
ResultsWindow resultsWindow;
41
PositionWindow positionWindow;
44
GConf.Client gconfClient;
45
IDoController controller;
47
const int IconBoxIconSize = 128;
48
const uint IconBoxPadding = 6;
49
const int IconBoxRadius = 20;
50
const int NumberResultsDisplayed = 6;
52
const double WindowTransparency = 0.91;
56
//-------------------Events-----------------------
57
public new event DoEventKeyDelegate KeyPressEvent;
59
//-------------------Properties-------------------
61
public new string Name {
62
get { return "Simple"; }
65
public Pane CurrentPane {
70
if (currentPane == value) return;
73
iconbox[0].IsFocused = value == Pane.First;
74
iconbox[1].IsFocused = value == Pane.Second;
75
iconbox[2].IsFocused = value == Pane.Third;
81
public PositionWindow PositionWindow {
83
if (positionWindow == null)
84
positionWindow = new PositionWindow (this, resultsWindow);
85
return positionWindow;
89
//-------------------ctor----------------------
90
public ClassicWindow () : base (Gtk.WindowType.Toplevel)
95
public void Initialize (IDoController controller)
97
this.controller = controller;
99
gconfClient = new GConf.Client ();
100
gconfClient.AddNotify ("/desktop/gnome/interface",
101
new GConf.NotifyEventHandler (DesktopThemeChanged));
106
//-------------------methods------------------
107
protected void Build ()
111
Gtk.Image settings_icon;
116
// This typehint gets the window to raise all the way to top.
117
TypeHint = WindowTypeHint.Splashscreen;
120
SetIconFromFile ("/usr/share/icons/gnome/scalable/actions/system-run.svg");
124
resultsWindow = new ResultsWindow (BackgroundColor,
125
NumberResultsDisplayed);
126
resultsWindow.SelectionChanged += OnResultsWindowSelectionChanged;
128
currentPane = Pane.First;
130
frame = new GlossyRoundedFrame ();
131
frame.DrawFill = frame.DrawFrame = true;
132
frame.FillColor = frame.FrameColor = BackgroundColor;
133
frame.FillAlpha = frame.FrameAlpha = WindowTransparency;
134
frame.Radius = Screen.IsComposited ? IconBoxRadius : 0;
138
vbox = new VBox (false, 0);
140
vbox.BorderWidth = IconBoxPadding;
143
settings_icon = new Gtk.Image (GetType().Assembly, "settings-triangle.png");
145
align = new Alignment (1.0F, 0.0F, 0, 0);
146
align.SetPadding (3, 0, 0, IconBoxPadding);
147
align.Add (settings_icon);
148
vbox.PackStart (align, false, false, 0);
149
settings_icon.Show ();
152
resultsHBox = new HBox (false, (int) IconBoxPadding * 2);
153
resultsHBox.BorderWidth = IconBoxPadding;
154
vbox.PackStart (resultsHBox, false, false, 0);
157
iconbox = new IconBox[3];
159
iconbox[0] = new IconBox (IconBoxIconSize);
160
iconbox[0].IsFocused = true;
161
iconbox[0].Radius = IconBoxRadius;
162
resultsHBox.PackStart (iconbox[0], false, false, 0);
165
iconbox[1] = new IconBox (IconBoxIconSize);
166
iconbox[1].IsFocused = false;
167
iconbox[1].Radius = IconBoxRadius;
168
resultsHBox.PackStart (iconbox[1], false, false, 0);
171
iconbox[2] = new IconBox (IconBoxIconSize);
172
iconbox[2].IsFocused = false;
173
iconbox[2].Radius = IconBoxRadius;
174
resultsHBox.PackStart (iconbox[2], false, false, 0);
175
// iconbox[2].Show ();
177
align = new Alignment (0.5F, 0.5F, 1, 1);
178
align.SetPadding (0, 2, 0, 0);
179
label = new SymbolDisplayLabel ();
181
vbox.PackStart (align, false, false, 0);
185
ScreenChanged += OnScreenChanged;
186
ConfigureEvent += OnConfigureEvent;
187
SizeAllocated += delegate { Reposition (); };
188
iconbox[0].LinesChanged += OnLineChangedEvent;
189
iconbox[1].LinesChanged += OnLineChangedEvent;
190
iconbox[2].LinesChanged += OnLineChangedEvent;
194
protected override bool OnKeyPressEvent (EventKey evnt)
196
KeyPressEvent (evnt);
198
return base.OnKeyPressEvent (evnt);
201
protected virtual void SetColormap ()
203
Gdk.Colormap colormap;
205
colormap = Screen.RgbaColormap;
206
if (colormap == null) {
207
colormap = Screen.RgbColormap;
208
Console.Error.WriteLine ("No alpha support.");
215
private Gdk.Color BackgroundColor
221
using (Gtk.Style style = Gtk.Rc.GetStyle (this)) {
222
bgColor = style.Backgrounds[(int) StateType.Selected];
224
r = (byte) ((bgColor.Red) >> 8);
225
g = (byte) ((bgColor.Green) >> 8);
226
b = (byte) ((bgColor.Blue) >> 8);
228
// Useful for making overbright themes less ugly. Still trying
229
// to find a happy balance between 50 and 90...
231
double hue, sat, val;
232
Interface.Util.Appearance.RGBToHSV(r, g, b, out hue,
234
val = Math.Min (val, maxLum);
236
Interface.Util.Appearance.HSVToRGB(hue, sat, val, out r,
239
return new Gdk.Color (r, g, b);
243
private void OnScreenChanged (object sender, EventArgs args)
248
private void OnConfigureEvent (object sender, ConfigureEventArgs args)
253
private void DesktopThemeChanged (object o, GConf.NotifyEventArgs e)
255
//this is needed to account for the delay between the gconf change
256
//and the theme change propogating to this application.
257
GLib.Timeout.Add (3000, delegate {
258
Gdk.Threads.Enter ();
259
frame.FrameColor = frame.FillColor = BackgroundColor;
260
resultsWindow.UpdateColors (BackgroundColor);
261
Gdk.Threads.Leave ();
266
public virtual void Reposition ()
268
Gtk.Application.Invoke (delegate {
269
Gdk.Rectangle offset;
272
offset = new Rectangle (IconBoxRadius, 0, 0 ,0);
273
iconboxWidth = IconBoxIconSize + 60;
275
PositionWindow.UpdatePosition (iconboxWidth, currentPane, offset);
279
protected void OnLineChangedEvent (object o, EventArgs a)
281
if ((int) o <= 2) return;
287
protected override bool OnButtonPressEvent (EventButton evnt)
289
int start_x, start_y, end_x, end_y;
290
int click_x, click_y;
291
bool click_on_window, click_near_settings_icon;
293
GetPosition (out start_x, out start_y);
294
GetSize (out end_x, out end_y);
297
click_x = (int) evnt.XRoot;
298
click_y = (int) evnt.YRoot;
299
click_on_window = start_x <= click_x && click_x < end_x &&
300
start_y <= click_y && click_y < end_y;
301
click_near_settings_icon = (end_x - 27) <= click_x && click_x < end_x &&
302
start_y <= click_y && click_y < (start_y + 27);
303
if (click_near_settings_icon) {
304
Services.Windowing.ShowMainMenu (end_x - 21, start_y + 16);
305
// Have to re-grab the pane from the menu.
306
Interface.Windowing.PresentWindow (this);
307
} else if (!click_on_window) {
308
controller.ButtonPressOffWindow ();
310
return base.OnButtonPressEvent (evnt);
313
private void OnResultsWindowSelectionChanged (object sender,
314
ResultsWindowSelectionEventArgs args)
316
controller.NewContextSelection (CurrentPane, args.SelectedIndex);
319
///////////////////////
321
///////////////////////
323
public void Summon ()
325
frame.Radius = Screen.IsComposited ? IconBoxRadius : 0;
330
Interface.Windowing.PresentWindow (this);
333
public void Vanish ()
340
resultsWindow.Clear ();
350
iconbox[0].DisplayObject = new Do.Interface.Widgets.DefaultIconBoxItem ();
351
label.SetDisplayLabel (Catalog.GetString ("Type to begin searching"),
352
Catalog.GetString ("Type to start searching."));
361
public void Shrink ()
367
public void GrowResults ()
369
if (!resultsWindow.Visible)
370
resultsWindow.Show ();
373
public void ShrinkResults ()
375
if (resultsWindow.Visible)
376
resultsWindow.Hide ();
379
public void SetPaneContext (Pane pane, IUIContext context)
381
if (!context.Results.Any () && !context.LargeTextDisplay) {
382
if (pane == Pane.First && context.ParentContext == null) {
383
iconbox[0].TextOverlay = context.LargeTextDisplay;
384
iconbox[0].DisplayObject = new Do.Interface.Widgets.DefaultIconBoxItem ();
385
label.SetDisplayLabel (Catalog.GetString ("Type to begin searching"),
386
Catalog.GetString ("Type to start searching."));
388
Do.Universe.Item noRes = new NoResultsFoundItem (context.Query);
389
for (int i = (int) pane; i < 3; i++) {
391
iconbox[i].DisplayObject = noRes;
392
if (i == (int) CurrentPane) {
393
label.SetDisplayLabel (noRes.Name, noRes.Description);
394
resultsWindow.Clear ();
401
if (string.IsNullOrEmpty (context.Query) && context.LargeTextDisplay) {
402
iconbox[(int) pane].TextOverlay = context.LargeTextDisplay;
403
iconbox[(int) pane].DisplayObject = new TextItem ("Enter Text") as Do.Universe.Item;
405
if (!context.Results.Any ()) return;
407
iconbox[(int) pane].TextOverlay = context.LargeTextDisplay;
408
iconbox[(int) pane].DisplayObject = context.Selection;
410
if (!context.LargeTextDisplay)
411
iconbox[(int) pane].Highlight = context.Query;
414
if (context.Selection == null) return;
416
if (pane == CurrentPane) {
417
resultsWindow.Context = context;
418
if (!context.LargeTextDisplay)
419
label.SetDisplayLabel (context.Selection.Name, context.Selection.Description);
421
label.SetDisplayLabel ("", "Raw Text Mode");
425
public void ClearPane (Pane pane)
427
iconbox[(int) pane].Clear ();
429
if (pane == CurrentPane)
430
resultsWindow.Clear ();
433
public bool ResultsCanHide { get { return true; } }
435
protected override bool OnExposeEvent (EventExpose evnt)
439
using (cairo = Gdk.CairoHelper.Create (GdkWindow)) {
440
cairo.Rectangle (evnt.Area.X, evnt.Area.Y, evnt.Area.Width, evnt.Area.Height);
441
cairo.Color = new Cairo.Color (1.0, 1.0, 1.0, 0.0);
442
cairo.Operator = Cairo.Operator.Source;
445
return base.OnExposeEvent (evnt);