~ubuntu-branches/ubuntu/vivid/monodevelop/vivid-proposed

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Components/DropDownBoxListWindow.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2014-10-09 14:09:23 UTC
  • mfrom: (10.3.5)
  • Revision ID: package-import@ubuntu.com-20141009140923-s0d22u5f9kg8jvds
Tags: 5.5.0.227-1
* [b2c8331] Imported Upstream version 5.5.0.227 (Closes: #754316)
* [d210995] Delete obsolete patches
* [1b59ae1] Clear patch fizz, via quilt refresh
* [3dd147d] Fix error in configure.in which applies for tarball builds but 
  not git builds when running autoreconf
* [21c2a57] Remove Metacity references for good
* [3331661] Ensure NUnit 2.6.3 is installed
* [fd85c88] Build-depend on NuGet
* [a1ae116] Add WebKit to build dependencies, for Xwt moduleref resolution
* [9b4cf12] Since the GDB addin is integrated now, declare it in 
  debian/control
* [6231562] Correct NUnit links
* [3d2b693] Fix NuGet addin, by copying libs locally
* [74bf9a8] Don't symlink unused Mocks NUnit assembly
* [ade52b2] Ensure IKVM.Reflection is built with default (4.5) profile

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
// THE SOFTWARE.
26
26
 
27
27
using System;
28
 
using System.Collections.Generic;
29
28
using MonoDevelop.Ide;
30
29
using Gtk;
31
 
using Mono.TextEditor;
32
 
using MonoDevelop.Ide.TypeSystem;
33
30
using System.Text;
34
31
 
35
32
namespace MonoDevelop.Components
36
33
{
37
34
        public class DropDownBoxListWindow : Window
38
35
        {
39
 
                ScrolledWindow vScrollbar;
 
36
                readonly ScrolledWindow vScrollbar;
40
37
                internal ListWidget list;
41
 
                
 
38
 
42
39
                public IListDataProvider DataProvider {
43
40
                        get;
44
41
                        private set;
45
42
                }
46
 
                
47
 
                public DropDownBoxListWindow (IListDataProvider provider) : base(Gtk.WindowType.Popup)
 
43
 
 
44
                public int FixedRowHeight {
 
45
                        get {
 
46
                                return list.FixedRowHeight;
 
47
                        }
 
48
                        set {
 
49
                                list.FixedRowHeight = value;
 
50
                                list.CalcRowHeight ();
 
51
                        }
 
52
                }
 
53
 
 
54
                public int MaxVisibleRows {
 
55
                        get {
 
56
                                return list.MaxVisibleRows;
 
57
                        }
 
58
                        set {
 
59
                                list.MaxVisibleRows = value;
 
60
                                list.CalcVisibleRows ();
 
61
                                SetSizeRequest (list.WidthRequest, list.HeightRequest);
 
62
                        }
 
63
                }
 
64
 
 
65
                public DropDownBoxListWindow (IListDataProvider provider) : this (provider, WindowType.Toplevel)
 
66
                {
 
67
                }
 
68
 
 
69
                public DropDownBoxListWindow (IListDataProvider provider, WindowType windowType) : base (windowType)
48
70
                {
49
71
                        this.DataProvider = provider;
50
 
                        this.TransientFor = MonoDevelop.Ide.IdeApp.Workbench.RootWindow;
 
72
                        this.TransientFor = IdeApp.Workbench.RootWindow;
51
73
                        this.TypeHint = Gdk.WindowTypeHint.Menu;
 
74
                        this.Decorated = false;
52
75
                        this.BorderWidth = 1;
53
 
                        this.Events |= Gdk.EventMask.KeyPressMask;
54
76
                        list = new ListWidget (this);
55
77
                        list.SelectItem += delegate {
56
78
                                var sel = list.Selection;
61
83
                        };
62
84
                        SetSizeRequest (list.WidthRequest, list.HeightRequest);
63
85
                        vScrollbar = new ScrolledWindow ();
64
 
                        vScrollbar.VScrollbar.SizeAllocated += (object o, SizeAllocatedArgs args) => {
 
86
                        vScrollbar.VScrollbar.SizeAllocated += (o, args) => {
65
87
                                var minWidth = list.WidthRequest + args.Allocation.Width;
66
88
                                if (this.Allocation.Width < minWidth)
67
89
                                        SetSizeRequest (minWidth, list.HeightRequest);
82
104
                                }
83
105
                        }
84
106
                }
85
 
                
86
 
                protected override void OnMapped ()
87
 
                {
88
 
                        base.OnMapped ();
89
 
                        Gdk.Pointer.Grab (this.GdkWindow, true, Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonReleaseMask | Gdk.EventMask.PointerMotionMask | Gdk.EventMask.EnterNotifyMask | Gdk.EventMask.LeaveNotifyMask, null, null, Gtk.Global.CurrentEventTime);
90
 
                        Gtk.Grab.Add (this);
91
 
                        this.GrabBrokenEvent += delegate {
92
 
                                Destroy ();
93
 
                        };
94
 
                }
95
 
                
96
 
                protected override void OnUnmapped ()
97
 
                {
98
 
                        Gtk.Grab.Remove (this);
99
 
                        Gdk.Pointer.Ungrab (Gtk.Global.CurrentEventTime);
100
 
                        base.OnUnmapped ();
101
 
                }
102
107
 
103
108
                void SwitchToSeletedWord ()
104
109
                {
118
123
                                if (list.SelectionDisabled)
119
124
                                        list.SelectionDisabled = false;
120
125
                                else
121
 
                                        list.Selection --;
 
126
                                        list.Selection--;
122
127
                                return true;
123
128
                                
124
129
                        case Gdk.Key.Down:
125
130
                                if (list.SelectionDisabled)
126
131
                                        list.SelectionDisabled = false;
127
132
                                else
128
 
                                        list.Selection ++;
 
133
                                        list.Selection++;
129
134
                                return true;
130
 
                                
 
135
 
131
136
                        case Gdk.Key.Page_Up:
132
137
                                list.Selection -= list.VisibleRows - 1;
133
138
                                return true;
137
142
                                return true;
138
143
 
139
144
                        case Gdk.Key.Home:
140
 
                                list.Selection = (int)0;
 
145
                                list.Selection = 0;
141
146
                                return true;
142
147
                        
143
148
                        case Gdk.Key.End:
171
176
                        Destroy ();
172
177
                        return base.OnFocusOutEvent (evnt);
173
178
                }
174
 
                
 
179
 
175
180
                protected override bool OnButtonPressEvent (Gdk.EventButton evnt)
176
181
                {
177
182
                        if (left)
179
184
                        return base.OnButtonPressEvent (evnt);
180
185
                }
181
186
 
182
 
 
183
187
                bool left = true;
 
188
 
184
189
                protected override bool OnLeaveNotifyEvent (Gdk.EventCrossing evnt)
185
190
                {
186
191
                        left = true;
189
194
 
190
195
                protected override bool OnEnterNotifyEvent (Gdk.EventCrossing evnt)
191
196
                {
192
 
                        if (evnt.Window == this.GdkWindow)
193
 
                                left = false;
 
197
                        left &= evnt.Window != GdkWindow;
194
198
                        return base.OnEnterNotifyEvent (evnt);
195
199
                }
196
200
 
197
 
                protected override bool OnKeyPressEvent (Gdk.EventKey evnt)
198
 
                {
199
 
                        ProcessKey (evnt.Key, evnt.State);
200
 
                        return base.OnKeyPressEvent (evnt);
201
 
                }
202
 
                
203
 
                internal class ListWidget: Gtk.DrawingArea
204
 
                {
205
 
                        int margin = 0;
206
 
                        int padding = 4;
 
201
                internal class ListWidget: DrawingArea
 
202
                {
 
203
                        const int margin = 0;
 
204
                        const int padding = 4;
207
205
                        int listWidth = 300;
208
 
                        
209
206
                        Pango.Layout layout;
210
 
                        DropDownBoxListWindow win;
211
 
                        int selection = 0;
212
 
 
 
207
                        readonly DropDownBoxListWindow win;
 
208
                        int selection;
213
209
                        int rowHeight;
214
210
 
215
211
                        public int RowHeight {
218
214
                                }
219
215
                        }
220
216
 
221
 
                //      bool buttonPressed;
 
217
                        public int FixedRowHeight {
 
218
                                get;
 
219
                                set;
 
220
                        }
 
221
                        //      bool buttonPressed;
222
222
                        bool disableSelection;
223
 
        
 
223
 
224
224
                        public event EventHandler SelectionChanged;
225
 
                                        
 
225
 
226
226
                        public ListWidget (DropDownBoxListWindow win)
227
227
                        {
228
228
                                this.win = win;
229
229
                                this.Events = Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonReleaseMask | Gdk.EventMask.PointerMotionMask | Gdk.EventMask.LeaveNotifyMask;
 
230
                                this.CanFocus = true;
230
231
                                layout = new Pango.Layout (this.PangoContext);
231
232
                                CalcRowHeight ();
232
233
                                CalcVisibleRows ();
233
234
                        }
234
 
                        
235
 
                        void CalcRowHeight ()
 
235
 
 
236
                        internal void CalcRowHeight ()
236
237
                        {
237
 
                                layout.SetText ("|");
238
 
                                int rowWidth;
239
 
                                layout.GetPixelSize (out rowWidth, out rowHeight);
240
 
                                rowHeight += padding;
241
 
                                SetBounds (Allocation);
 
238
                                if (FixedRowHeight > 0) {
 
239
                                        rowHeight = FixedRowHeight;
 
240
                                } else {
 
241
                                        layout.SetText ("|");
 
242
                                        int rowWidth;
 
243
                                        layout.GetPixelSize (out rowWidth, out rowHeight);
 
244
                                        rowHeight += padding;
 
245
                                }
 
246
                                SetBounds ();
242
247
                        }
243
 
                        
 
248
 
244
249
                        protected override bool OnLeaveNotifyEvent (Gdk.EventCrossing evnt)
245
250
                        {
246
251
                                selection = -1;
247
252
                                QueueDraw ();
248
253
                                return base.OnLeaveNotifyEvent (evnt);
249
254
                        }
250
 
        
251
 
                        
 
255
 
252
256
                        protected override void OnDestroyed ()
253
257
                        {
254
258
                                if (layout != null) {
257
261
                                }
258
262
                                base.OnDestroyed ();
259
263
                        }
260
 
                        
 
264
 
261
265
                        public void Reset ()
262
266
                        {
263
267
                                if (win.DataProvider == null) {
265
269
                                        return;
266
270
                                }
267
271
                                
268
 
                                if (win.DataProvider.IconCount == 0)
269
 
                                        selection = -1;
270
 
                                else
271
 
                                        selection = 0;
 
272
                                selection = win.DataProvider.IconCount == 0 ? -1 : 0;
272
273
                                CalcVisibleRows ();
273
274
                                disableSelection = false;
274
275
                                if (IsRealized) {
275
276
                                        UpdateStyle ();
276
277
                                        QueueDraw ();
277
278
                                }
278
 
                                if (SelectionChanged != null) SelectionChanged (this, EventArgs.Empty);
 
279
                                if (SelectionChanged != null)
 
280
                                        SelectionChanged (this, EventArgs.Empty);
279
281
                        }
280
 
                        StringBuilder wordSelection = new StringBuilder ();
 
282
 
 
283
                        readonly StringBuilder wordSelection = new StringBuilder ();
281
284
 
282
285
                        public StringBuilder WordSelection {
283
286
                                get {
285
288
                                }
286
289
                        }
287
290
 
288
 
                        public int Selection
289
 
                        {
 
291
                        public int Selection {
290
292
                                get {
291
293
                                        return selection;
292
294
                                }
303
305
                                                        SelectionChanged (this, EventArgs.Empty);
304
306
                                        }
305
307
                                        
306
 
                                        if (disableSelection)
307
 
                                                disableSelection = false;
 
308
                                        disableSelection &= !disableSelection;
308
309
        
309
 
                                        this.QueueDraw ();
 
310
                                        QueueDraw ();
310
311
                                }
311
312
                        }
312
 
                        
 
313
 
313
314
                        void UpdatePage ()
314
315
                        {
315
316
                                var area = GetRowArea (selection);
316
 
                                if (area.Y < vadj.Value) {
317
 
                                        vadj.Value = area.Y;
318
 
                                        return;
319
 
                                }
320
 
                                if (vadj.Value + Allocation.Height < area.Bottom) {
321
 
                                        vadj.Value = System.Math.Max (0, area.Bottom - vadj.PageSize + 1);
322
 
                                }
 
317
                                var value = vAdjustment.Value;
 
318
                                if (area.Y < value) {
 
319
                                        value = area.Y;
 
320
                                } else if (value + Allocation.Height < area.Bottom) {
 
321
                                        value = Math.Max (0, area.Bottom - vAdjustment.PageSize + 1);
 
322
                                }
 
323
                                vAdjustment.Value = Math.Max (vAdjustment.Lower, Math.Min (value, vAdjustment.Upper - vAdjustment.PageSize));
 
324
 
323
325
                        }
324
 
                        
 
326
 
325
327
                        public bool SelectionDisabled {
326
328
                                get { return disableSelection; }
327
329
                                set {
328
330
                                        disableSelection = value; 
329
 
                                        this.QueueDraw ();
 
331
                                        QueueDraw ();
330
332
                                }
331
333
                        }
332
334
 
333
 
                        protected override bool OnButtonPressEvent (Gdk.EventButton e)
 
335
                        protected override bool OnButtonPressEvent (Gdk.EventButton evnt)
334
336
                        {
335
 
                                Selection = GetRowByPosition ((int) e.Y);
336
 
                                if (e.Type == Gdk.EventType.ButtonPress) {
 
337
                                Selection = GetRowByPosition ((int)evnt.Y);
 
338
                                if (evnt.Type == Gdk.EventType.ButtonPress) {
337
339
                                        OnSelectItem (EventArgs.Empty);
338
340
                                        Destroy ();
339
341
                                }
340
342
                                //buttonPressed = true;
341
 
                                return base.OnButtonPressEvent (e);
342
 
                        }
343
 
                        
344
 
                        protected override bool OnButtonReleaseEvent (Gdk.EventButton e)
345
 
                        {
346
 
                                //buttonPressed = false;
347
 
                                return base.OnButtonReleaseEvent (e);
348
 
                        }
349
 
                        
350
 
                        protected override bool OnMotionNotifyEvent (Gdk.EventMotion e)
 
343
                                return base.OnButtonPressEvent (evnt);
 
344
                        }
 
345
                        int curMouseY;
 
346
                        protected override bool OnMotionNotifyEvent (Gdk.EventMotion evnt)
351
347
                        {
352
348
                                int winWidth, winHeight;
353
 
                                this.GdkWindow.GetSize (out winWidth, out winHeight);
354
 
                                
355
 
                                Selection = GetRowByPosition ((int) e.Y);
356
 
                                
357
 
                                return base.OnMotionNotifyEvent (e);
358
 
                        }
359
 
                        
 
349
                                GdkWindow.GetSize (out winWidth, out winHeight);
 
350
                                curMouseY = (int)evnt.Y;
 
351
                                Selection = GetRowByPosition (curMouseY);
 
352
                                
 
353
                                return base.OnMotionNotifyEvent (evnt);
 
354
                        }
 
355
 
 
356
                        protected override bool OnKeyPressEvent (Gdk.EventKey evnt)
 
357
                        {
 
358
                                return win.ProcessKey (evnt.Key, evnt.State);
 
359
                        }
 
360
 
360
361
                        protected override bool OnScrollEvent (Gdk.EventScroll evnt)
361
362
                        {
362
 
                                var s = GetRowByPosition ((int) evnt.Y);
363
 
                                if (Selection != s)
364
 
                                        Selection = s;
 
363
                                var s = GetRowByPosition ((int)evnt.Y);
 
364
                                Selection = s;
365
365
                                
366
366
                                return base.OnScrollEvent (evnt);
367
367
                        }
368
 
        
369
 
                        protected override bool OnExposeEvent (Gdk.EventExpose args)
 
368
 
 
369
                        protected override bool OnExposeEvent (Gdk.EventExpose evnt)
370
370
                        {
371
 
                                base.OnExposeEvent (args);
 
371
                                base.OnExposeEvent (evnt);
372
372
                                DrawList ();
373
373
                                return false;
374
374
                        }
375
 
        
 
375
 
376
376
                        void DrawList ()
377
377
                        {
378
378
                                int winWidth, winHeight;
379
 
                                this.GdkWindow.GetSize (out winWidth, out winHeight);
 
379
                                GdkWindow.GetSize (out winWidth, out winHeight);
380
380
 
381
 
                                int ypos = margin;
382
381
                                int lineWidth = winWidth - margin * 2;
383
 
                                int xpos = margin + padding;
 
382
                                const int xpos = margin + padding;
384
383
 
385
 
                                int n = (int)(vadj.Value / rowHeight);
 
384
                                int n = (int)(vAdjustment.Value / rowHeight);
 
385
                                int ypos = (int)(margin + n * rowHeight - vAdjustment.Value);
386
386
                                while (ypos < winHeight - margin && n < win.DataProvider.IconCount) {
387
387
                                        string text = win.DataProvider.GetMarkup (n) ?? "&lt;null&gt;";
388
 
                                        layout.SetMarkup (text);
389
 
 
390
 
                                        Gdk.Pixbuf icon = win.DataProvider.GetIcon (n);
391
 
                                        int iconHeight = icon != null ? icon.Height : 24;
392
 
                                        int iconWidth = icon != null ? icon.Width : 0;
 
388
 
 
389
                                        var icon = win.DataProvider.GetIcon (n);
 
390
                                        int iconHeight = icon != null ? (int)icon.Height : 24;
 
391
                                        int iconWidth = icon != null ? (int)icon.Width : 0;
 
392
 
 
393
                                        layout.Ellipsize = Pango.EllipsizeMode.End;
 
394
                                        layout.Width = (Allocation.Width - xpos - iconWidth - 2) * (int)Pango.Scale.PangoScale;
 
395
                                        layout.SetMarkup (PathBar.GetFirstLineFromMarkup (text));
393
396
 
394
397
                                        int wi, he, typos, iypos;
395
398
                                        layout.GetPixelSize (out wi, out he);
396
 
                                        if (wi > Allocation.Width) {
397
 
                                                int idx, trail;
398
 
                                                if (layout.XyToIndex (
399
 
                                                        (int)((Allocation.Width - xpos - iconWidth - 2) * Pango.Scale.PangoScale),
400
 
                                                        0,
401
 
                                                        out idx,
402
 
                                                        out trail
403
 
                                                ) && idx > 3) {
404
 
                                                        text = AmbienceService.UnescapeText (text);
405
 
                                                        text = text.Substring (0, idx - 3) + "...";
406
 
                                                        text = AmbienceService.EscapeText (text);
407
 
                                                        layout.SetMarkup (text);
408
 
                                                        layout.GetPixelSize (out wi, out he);
409
 
                                                }
410
 
                                        }
411
399
                                        typos = he < rowHeight ? ypos + (rowHeight - he) / 2 : ypos;
412
400
                                        iypos = iconHeight < rowHeight ? ypos + (rowHeight - iconHeight) / 2 : ypos;
413
401
                                        
414
402
                                        if (n == selection) {
415
403
                                                if (!disableSelection) {
416
 
                                                        this.GdkWindow.DrawRectangle (this.Style.BaseGC (StateType.Selected), 
417
 
                                                                                      true, margin, ypos, lineWidth, he + padding);
418
 
                                                        this.GdkWindow.DrawLayout (this.Style.TextGC (StateType.Selected), 
419
 
                                                                                           xpos + iconWidth + 2, typos, layout);
 
404
                                                        GdkWindow.DrawRectangle (Style.BaseGC (StateType.Selected), 
 
405
                                                                true, margin, ypos, lineWidth, rowHeight);
 
406
                                                        GdkWindow.DrawLayout (Style.TextGC (StateType.Selected), 
 
407
                                                                              xpos + iconWidth + 2, typos, layout);
420
408
                                                } else {
421
 
                                                        this.GdkWindow.DrawRectangle (this.Style.BaseGC (StateType.Selected), 
422
 
                                                                                      false, margin, ypos, lineWidth, he + padding);
423
 
                                                        this.GdkWindow.DrawLayout (this.Style.TextGC (StateType.Normal), 
424
 
                                                                                   xpos + iconWidth + 2, typos, layout);
 
409
                                                        GdkWindow.DrawRectangle (Style.BaseGC (StateType.Selected), 
 
410
                                                                false, margin, ypos, lineWidth, rowHeight);
 
411
                                                        GdkWindow.DrawLayout (Style.TextGC (StateType.Normal), 
 
412
                                                                              xpos + iconWidth + 2, typos, layout);
425
413
                                                }
426
414
                                        } else
427
 
                                                this.GdkWindow.DrawLayout (this.Style.TextGC (StateType.Normal), 
428
 
                                                                           xpos + iconWidth + 2, typos, layout);
 
415
                                                GdkWindow.DrawLayout (Style.TextGC (StateType.Normal), 
 
416
                                                                      xpos + iconWidth + 2, typos, layout);
429
417
                                        
430
 
                                        if (icon != null)
431
 
                                                this.GdkWindow.DrawPixbuf (this.Style.ForegroundGC (StateType.Normal), icon, 0, 0, 
432
 
                                                                           xpos, iypos, iconWidth, iconHeight, Gdk.RgbDither.None, 0, 0);
 
418
                                        if (icon != null) {
 
419
                                                using (var ctx = Gdk.CairoHelper.Create (this.GdkWindow))
 
420
                                                        ctx.DrawImage (this, icon, xpos, iypos);
 
421
                                        }
433
422
                                        
434
423
                                        ypos += rowHeight;
435
424
                                        n++;
436
425
                                        
437
426
//reset the markup or it carries over to the next SetText
438
427
                                        layout.SetMarkup (string.Empty);
439
 
                                        }
440
428
                                }
441
 
                        
 
429
                        }
 
430
 
442
431
                        int GetRowByPosition (int ypos)
443
432
                        {
444
 
                                return (int)(vadj.Value + ypos) / rowHeight;
 
433
                                return (int)(vAdjustment.Value + ypos) / rowHeight;
445
434
                        }
446
435
 
447
436
                        public Gdk.Rectangle GetRowArea (int row)
448
437
                        {
449
438
                                return new Gdk.Rectangle (0, row * rowHeight, Allocation.Width, rowHeight - 1);
450
439
                        }
451
 
                        
 
440
 
452
441
                        public int VisibleRows {
453
442
                                get {
454
443
                                        return Allocation.Height / rowHeight;
455
444
                                }
456
445
                        }
457
446
 
458
 
                        const int maxVisibleRows = 8;
459
 
                        void CalcVisibleRows ()
 
447
                        internal int MaxVisibleRows = 8;
 
448
 
 
449
                        internal void CalcVisibleRows ()
460
450
                        {
461
451
                                int lvWidth, lvHeight;
462
 
                                this.GetSizeRequest (out lvWidth, out lvHeight);
 
452
                                GetSizeRequest (out lvWidth, out lvHeight);
463
453
                                if (layout == null)
464
454
                                        return;
465
 
 
466
455
                                int newHeight;
467
 
                                if (this.win.DataProvider.IconCount > maxVisibleRows)
468
 
                                        newHeight = (rowHeight * maxVisibleRows) + margin * 2;
469
 
                                else
470
 
                                        newHeight = (rowHeight * this.win.DataProvider.IconCount) + margin * 2;
 
456
                                newHeight = win.DataProvider.IconCount > MaxVisibleRows ? 
 
457
                                                                (rowHeight * MaxVisibleRows) + margin * 2 :
 
458
                                                                (rowHeight * win.DataProvider.IconCount) + margin * 2;
 
459
                                newHeight += 2;
471
460
                                listWidth = Math.Min (450, CalcWidth ());
472
 
                                this.SetSizeRequest (listWidth, newHeight);
473
 
                        } 
 
461
                                SetSizeRequest (listWidth, newHeight);
 
462
                        }
 
463
 
474
464
                        internal int CalcWidth ()
475
465
                        {
476
466
                                if (win.DataProvider.IconCount == 0)
488
478
                                layout.SetMarkup (win.DataProvider.GetMarkup (longest) ?? "&lt;null&gt;");
489
479
                                int w, h;
490
480
                                layout.GetPixelSize (out w, out h);
491
 
                                Gdk.Pixbuf icon = win.DataProvider.GetIcon (longest);
492
 
                                int iconWidth = icon != null ? icon.Width : 24;
 
481
                                var icon = win.DataProvider.GetIcon (longest);
 
482
                                int iconWidth = icon != null ? (int) icon.Width : 24;
493
483
                                w += iconWidth + 2 + padding * 2 + margin;
494
484
                                return w;
495
485
                        }
496
486
 
497
 
                        void SetBounds (Gdk.Rectangle allocation)
 
487
                        void SetBounds ()
498
488
                        {
499
 
                                if (vadj == null)
 
489
                                if (vAdjustment == null)
500
490
                                        return;
501
 
                                var h = allocation.Height;
 
491
                                var h = Allocation.Height;
502
492
                                var height = Math.Max (h, rowHeight * win.DataProvider.IconCount);
503
 
                                if (this.win.DataProvider.IconCount < maxVisibleRows) {
504
 
                                        vadj.SetBounds (0, h, 0, 0, h);
 
493
                                if (win.DataProvider.IconCount < MaxVisibleRows) {
 
494
                                        vAdjustment.SetBounds (0, h, 0, 0, h);
505
495
                                } else {
506
 
                                        vadj.SetBounds (0, height, RowHeight, h, h);
 
496
                                        vAdjustment.SetBounds (0, height, RowHeight, h, h);
507
497
                                }
 
498
                                UpdatePage ();
508
499
                        }
509
500
 
510
501
                        protected override void OnSizeAllocated (Gdk.Rectangle allocation)
511
502
                        {
512
503
                                base.OnSizeAllocated (allocation);
513
504
 
514
 
                                hadj.SetBounds (0, allocation.Width, 0, 0, allocation.Width);
 
505
                                hAdjustment.SetBounds (0, allocation.Width, 0, 0, allocation.Width);
515
506
 
516
 
                                SetBounds (allocation);
 
507
                                SetBounds ();
517
508
 
518
509
                                UpdatePage ();
519
510
                        }
520
 
                        
 
511
 
521
512
                        protected override void OnRealized ()
522
513
                        {
523
514
                                base.OnRealized ();
524
515
                                UpdateStyle ();
525
516
                        }
526
 
                        
 
517
 
527
518
                        void UpdateStyle ()
528
519
                        {
529
 
                                this.GdkWindow.Background = this.Style.Base (StateType.Normal);
 
520
                                GdkWindow.Background = Style.Base (StateType.Normal);
530
521
                                if (layout != null)
531
522
                                        layout.Dispose ();
532
 
                                layout = new Pango.Layout (this.PangoContext);
 
523
                                layout = new Pango.Layout (PangoContext);
533
524
                                layout.Wrap = Pango.WrapMode.Char;
534
 
                                layout.FontDescription = this.Style.FontDescription.Copy();
 
525
                                layout.FontDescription = Style.FontDescription.Copy ();
535
526
                                CalcRowHeight ();
536
527
                                CalcVisibleRows ();
537
528
                        }
538
529
 
539
 
                        Adjustment hadj;
540
 
                        Adjustment vadj;
 
530
                        Adjustment hAdjustment;
 
531
                        Adjustment vAdjustment;
541
532
 
542
533
                        protected override void OnSetScrollAdjustments (Adjustment hadj, Adjustment vadj)
543
534
                        {
544
 
                                this.hadj = hadj;
545
 
                                this.vadj = vadj;
546
 
                                if (this.vadj != null)
547
 
                                        this.vadj.ValueChanged += (sender, e) => QueueDraw ();
 
535
                                hAdjustment = hadj;
 
536
                                vAdjustment = vadj;
 
537
                                if (vAdjustment != null)
 
538
                                        vAdjustment.ValueChanged += delegate {
 
539
                                                if (selection > -1)
 
540
                                                        Selection = GetRowByPosition (curMouseY);
 
541
                                                QueueDraw ();
 
542
                                        };
548
543
                                base.OnSetScrollAdjustments (hadj, vadj);
549
544
                        }
550
545
 
553
548
                                if (SelectItem != null)
554
549
                                        SelectItem (this, e);
555
550
                        }
 
551
 
556
552
                        public event EventHandler SelectItem;
557
553
                }
558
 
                
 
554
 
559
555
                public interface IListDataProvider
560
556
                {
561
557
                        int IconCount {
562
558
                                get;
563
559
                        }
 
560
 
564
561
                        void Reset ();
 
562
 
565
563
                        string GetMarkup (int n);
566
 
                        Gdk.Pixbuf GetIcon (int n);
 
564
 
 
565
                        Xwt.Drawing.Image GetIcon (int n);
 
566
 
567
567
                        object GetTag (int n);
568
 
                        
 
568
 
569
569
                        void ActivateItem (int n);
570
570
                }
571
571
        }