~do-win/do/test-paths

« back to all changes in this revision

Viewing changes to Do.Interface.Windows.AnimationBase/src/Do.Interface/Do.Interface.AnimationBase/Bezel.cs

  • Committer: Hardeep S
  • Date: 2009-06-23 04:22:47 UTC
  • Revision ID: ootz0rz@gmail.com-20090623042247-ciyax78ykbtlx4ee
added Do.Interface.Windows.AnimationBase and Do.Interface.Windows.Classic

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Bezel.cs
 
2
// 
 
3
// Copyright (C) 2008 GNOME-Do
 
4
//
 
5
// This program is free software: you can redistribute it and/or modify
 
6
// it under the terms of the GNU General Public License as published by
 
7
// the Free Software Foundation, either version 3 of the License, or
 
8
// (at your option) any later version.
 
9
//
 
10
// This program is distributed in the hope that it will be useful,
 
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
// GNU General Public License for more details.
 
14
//
 
15
// You should have received a copy of the GNU General Public License
 
16
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
//
 
18
 
 
19
using System;
 
20
using System.Collections.Generic;
 
21
using System.Linq;
 
22
 
 
23
using Cairo;
 
24
using Gdk;
 
25
using Gtk;
 
26
 
 
27
using Do.Universe;
 
28
using Do.Platform;
 
29
using Do.Platform.Windows;
 
30
using Do.Interface;
 
31
 
 
32
namespace Do.Interface.AnimationBase
 
33
{
 
34
        
 
35
        
 
36
        public abstract class AbstractAnimatedInterface : Gtk.Window, IDoWindow, IConfigurable
 
37
        {
 
38
                BezelDrawingArea bezel_drawing_area;
 
39
                BezelGlassResults bezel_glass_results;
 
40
                BezelGlassWindow bezel_glass_window;
 
41
                IDoController controller;
 
42
                PositionWindow pw;
 
43
                
 
44
                public Pane CurrentPane {
 
45
                        get { return bezel_drawing_area.Focus; }
 
46
                        set { bezel_drawing_area.Focus = value; }
 
47
                }
 
48
                
 
49
                public new string Name { 
 
50
                        get { return RenderTheme.Name; }
 
51
                }
 
52
                
 
53
                protected abstract IRenderTheme RenderTheme { get; }
 
54
                
 
55
                public AbstractAnimatedInterface () : base (Gtk.WindowType.Toplevel)
 
56
                {
 
57
                }
 
58
                
 
59
                public void Initialize (IDoController controller)
 
60
                {
 
61
                        this.controller = controller;
 
62
                        Build ();
 
63
                }
 
64
                
 
65
                void Build ()
 
66
                {
 
67
                        Decorated = false;
 
68
                        AppPaintable = true;
 
69
                        KeepAbove = true;
 
70
                        
 
71
                        TypeHint = WindowTypeHint.Splashscreen;
 
72
                        SetColormap ();
 
73
                        
 
74
                        bezel_drawing_area = new BezelDrawingArea (controller, RenderTheme, false);
 
75
                        bezel_drawing_area.Show ();
 
76
                        
 
77
                        bezel_glass_results = bezel_drawing_area.Results;
 
78
                        bezel_glass_window = new BezelGlassWindow (bezel_glass_results);
 
79
        
 
80
                        Add (bezel_drawing_area);
 
81
                        
 
82
                        pw = new PositionWindow (this, bezel_glass_window);
 
83
                }
 
84
                
 
85
                protected override void OnDestroyed ()
 
86
                {
 
87
                        base.OnDestroyed ();
 
88
                        bezel_drawing_area.Destroy ();
 
89
                        bezel_drawing_area = null;
 
90
                        bezel_glass_results.Destroy ();
 
91
                        bezel_glass_results = null;
 
92
                }
 
93
 
 
94
                protected override bool OnButtonPressEvent (EventButton evnt)
 
95
                {
 
96
                        Gdk.Point global_point = new Gdk.Point ((int) evnt.XRoot, (int) evnt.YRoot);
 
97
                        Gdk.Point local_point = new Gdk.Point ((int) evnt.X, (int) evnt.Y);
 
98
                        
 
99
                        switch (bezel_drawing_area.GetPointLocation (local_point)) {
 
100
                        case PointLocation.Close:
 
101
                        case PointLocation.Outside:
 
102
                                controller.ButtonPressOffWindow ();
 
103
                                break;
 
104
                        case PointLocation.Preferences:
 
105
                                Services.Windowing.ShowMainMenu (global_point.X, global_point.Y);
 
106
                                // Have to re-grab the pane from the menu.
 
107
                                Interface.Windowing.PresentWindow (this);
 
108
                                break;
 
109
                        }
 
110
 
 
111
                        return base.OnButtonPressEvent (evnt);
 
112
                }
 
113
                
 
114
                protected override bool OnKeyPressEvent (EventKey evnt)
 
115
                {
 
116
                        KeyPressEvent (evnt);
 
117
 
 
118
                        return base.OnKeyPressEvent (evnt);
 
119
                }
 
120
                
 
121
                protected override bool OnExposeEvent (EventExpose evnt)
 
122
                {
 
123
                        if (IsDrawable) {
 
124
                                Cairo.Context cr = Gdk.CairoHelper.Create (GdkWindow);
 
125
                                cr.Operator = Cairo.Operator.Source;
 
126
                                cr.Paint ();
 
127
                                (cr as IDisposable).Dispose ();
 
128
                        }
 
129
                        return base.OnExposeEvent (evnt);
 
130
                }
 
131
 
 
132
                
 
133
                protected virtual void SetColormap ()
 
134
                {
 
135
                        Gdk.Colormap  colormap;
 
136
 
 
137
                        colormap = Screen.RgbaColormap;
 
138
                        if (colormap == null) {
 
139
                                colormap = Screen.RgbColormap;
 
140
                                Console.Error.WriteLine ("No alpha support.");
 
141
                        }
 
142
                        
 
143
                        Colormap = colormap;
 
144
                        colormap.Dispose ();
 
145
                }
 
146
 
 
147
                public void Summon ()
 
148
                {
 
149
                        int width, height;
 
150
                        GetSize (out width, out height);
 
151
                        
 
152
                        pw.UpdatePosition (0, Pane.First, new Gdk.Rectangle (((int) (bezel_drawing_area.WindowWidth - bezel_glass_results.WidthRequest) / 2), -10, 0, 0));
 
153
                        Show ();
 
154
                        bezel_glass_window.Show ();
 
155
                        Interface.Windowing.PresentWindow (this);
 
156
                }
 
157
 
 
158
                public void Vanish ()
 
159
                {
 
160
                        Interface.Windowing.UnpresentWindow (this);
 
161
                        Hide ();
 
162
                        bezel_glass_window.Hide ();
 
163
                }
 
164
 
 
165
                public void Reset ()
 
166
                {
 
167
                        bezel_drawing_area.Clear ();
 
168
                        bezel_glass_results.Clear ();
 
169
                }
 
170
 
 
171
                public void Grow ()
 
172
                {
 
173
                        bezel_drawing_area.ThirdPaneVisible = true;
 
174
                }
 
175
 
 
176
                public void Shrink ()
 
177
                {
 
178
                        bezel_drawing_area.ThirdPaneVisible = false;
 
179
                }
 
180
 
 
181
                public void GrowResults ()
 
182
                {
 
183
                        bezel_glass_results.SlideIn ();
 
184
                }
 
185
 
 
186
                public void ShrinkResults ()
 
187
                {
 
188
                        bezel_glass_results.SlideOut ();
 
189
                }
 
190
 
 
191
                public void SetPaneContext (Pane pane, IUIContext context)
 
192
                {
 
193
                        // This prevents the odd situation of nothing drawing in the third pane.  Ultimately what has
 
194
                        // happened is the universe has "nulled" the pane by fluke.  We detect this and replace the
 
195
                        // query with an invisible space.
 
196
                        string query;
 
197
                        if (pane == Pane.Third && context.Selection == null && string.IsNullOrEmpty (context.Query) && !context.Results.Any ()) {
 
198
                                query = " ";
 
199
                        } else {
 
200
                                query = context.Query;
 
201
                        }
 
202
                        bezel_drawing_area.BezelSetPaneObject (pane, context.Selection);
 
203
                        bezel_drawing_area.BezelSetQuery      (pane, query);
 
204
                        bezel_drawing_area.BezelSetTextMode   (pane, context.LargeTextDisplay);
 
205
                        bezel_drawing_area.BezelSetEntryMode (pane, context.LargeTextModeType == TextModeType.Explicit);
 
206
                        
 
207
                        if (CurrentPane == pane) {
 
208
                                bezel_glass_results.Context = context;
 
209
                        }
 
210
                }
 
211
 
 
212
                public void ClearPane (Pane pane)
 
213
                {
 
214
                        bezel_drawing_area.BezelSetPaneObject (pane, null);
 
215
                        bezel_drawing_area.BezelSetQuery (pane, "");
 
216
                        bezel_drawing_area.BezelSetEntryMode (pane, false);
 
217
                        
 
218
                        if (pane == CurrentPane) {
 
219
                                bezel_glass_results.Clear ();
 
220
                        }
 
221
                }
 
222
 
 
223
                #region IConfigurable implementation
 
224
                public Bin GetConfiguration ()
 
225
                {
 
226
                        return new AnimationBaseConfigurationWidget (bezel_drawing_area);
 
227
                }
 
228
                
 
229
                public string Description {
 
230
                        get {
 
231
                                return "Animated Interface Configuration";
 
232
                        }
 
233
                }
 
234
                
 
235
                public new string Icon {
 
236
                        get {
 
237
                                return "preferences";
 
238
                        }
 
239
                }
 
240
                #endregion
 
241
 
 
242
 
 
243
                public bool ResultsCanHide { get { return true; } }
 
244
                
 
245
                public new event DoEventKeyDelegate KeyPressEvent;
 
246
        }
 
247
}