303
305
SelectionChanged (this, EventArgs.Empty);
306
if (disableSelection)
307
disableSelection = false;
308
disableSelection &= !disableSelection;
313
314
void UpdatePage ()
315
316
var area = GetRowArea (selection);
316
if (area.Y < vadj.Value) {
320
if (vadj.Value + Allocation.Height < area.Bottom) {
321
vadj.Value = System.Math.Max (0, area.Bottom - vadj.PageSize + 1);
317
var value = vAdjustment.Value;
318
if (area.Y < value) {
320
} else if (value + Allocation.Height < area.Bottom) {
321
value = Math.Max (0, area.Bottom - vAdjustment.PageSize + 1);
323
vAdjustment.Value = Math.Max (vAdjustment.Lower, Math.Min (value, vAdjustment.Upper - vAdjustment.PageSize));
325
327
public bool SelectionDisabled {
326
328
get { return disableSelection; }
328
330
disableSelection = value;
333
protected override bool OnButtonPressEvent (Gdk.EventButton e)
335
protected override bool OnButtonPressEvent (Gdk.EventButton evnt)
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);
340
342
//buttonPressed = true;
341
return base.OnButtonPressEvent (e);
344
protected override bool OnButtonReleaseEvent (Gdk.EventButton e)
346
//buttonPressed = false;
347
return base.OnButtonReleaseEvent (e);
350
protected override bool OnMotionNotifyEvent (Gdk.EventMotion e)
343
return base.OnButtonPressEvent (evnt);
346
protected override bool OnMotionNotifyEvent (Gdk.EventMotion evnt)
352
348
int winWidth, winHeight;
353
this.GdkWindow.GetSize (out winWidth, out winHeight);
355
Selection = GetRowByPosition ((int) e.Y);
357
return base.OnMotionNotifyEvent (e);
349
GdkWindow.GetSize (out winWidth, out winHeight);
350
curMouseY = (int)evnt.Y;
351
Selection = GetRowByPosition (curMouseY);
353
return base.OnMotionNotifyEvent (evnt);
356
protected override bool OnKeyPressEvent (Gdk.EventKey evnt)
358
return win.ProcessKey (evnt.Key, evnt.State);
360
361
protected override bool OnScrollEvent (Gdk.EventScroll evnt)
362
var s = GetRowByPosition ((int) evnt.Y);
363
var s = GetRowByPosition ((int)evnt.Y);
366
366
return base.OnScrollEvent (evnt);
369
protected override bool OnExposeEvent (Gdk.EventExpose args)
369
protected override bool OnExposeEvent (Gdk.EventExpose evnt)
371
base.OnExposeEvent (args);
371
base.OnExposeEvent (evnt);
378
378
int winWidth, winHeight;
379
this.GdkWindow.GetSize (out winWidth, out winHeight);
379
GdkWindow.GetSize (out winWidth, out winHeight);
382
381
int lineWidth = winWidth - margin * 2;
383
int xpos = margin + padding;
382
const int xpos = margin + padding;
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) ?? "<null>";
388
layout.SetMarkup (text);
390
Gdk.Pixbuf icon = win.DataProvider.GetIcon (n);
391
int iconHeight = icon != null ? icon.Height : 24;
392
int iconWidth = icon != null ? icon.Width : 0;
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;
393
layout.Ellipsize = Pango.EllipsizeMode.End;
394
layout.Width = (Allocation.Width - xpos - iconWidth - 2) * (int)Pango.Scale.PangoScale;
395
layout.SetMarkup (PathBar.GetFirstLineFromMarkup (text));
394
397
int wi, he, typos, iypos;
395
398
layout.GetPixelSize (out wi, out he);
396
if (wi > Allocation.Width) {
398
if (layout.XyToIndex (
399
(int)((Allocation.Width - xpos - iconWidth - 2) * Pango.Scale.PangoScale),
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);
411
399
typos = he < rowHeight ? ypos + (rowHeight - he) / 2 : ypos;
412
400
iypos = iconHeight < rowHeight ? ypos + (rowHeight - iconHeight) / 2 : ypos;
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);
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);
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);
431
this.GdkWindow.DrawPixbuf (this.Style.ForegroundGC (StateType.Normal), icon, 0, 0,
432
xpos, iypos, iconWidth, iconHeight, Gdk.RgbDither.None, 0, 0);
419
using (var ctx = Gdk.CairoHelper.Create (this.GdkWindow))
420
ctx.DrawImage (this, icon, xpos, iypos);
434
423
ypos += rowHeight;
437
426
//reset the markup or it carries over to the next SetText
438
427
layout.SetMarkup (string.Empty);
442
431
int GetRowByPosition (int ypos)
444
return (int)(vadj.Value + ypos) / rowHeight;
433
return (int)(vAdjustment.Value + ypos) / rowHeight;
447
436
public Gdk.Rectangle GetRowArea (int row)
449
438
return new Gdk.Rectangle (0, row * rowHeight, Allocation.Width, rowHeight - 1);
452
441
public int VisibleRows {
454
443
return Allocation.Height / rowHeight;
458
const int maxVisibleRows = 8;
459
void CalcVisibleRows ()
447
internal int MaxVisibleRows = 8;
449
internal void CalcVisibleRows ()
461
451
int lvWidth, lvHeight;
462
this.GetSizeRequest (out lvWidth, out lvHeight);
452
GetSizeRequest (out lvWidth, out lvHeight);
463
453
if (layout == null)
467
if (this.win.DataProvider.IconCount > maxVisibleRows)
468
newHeight = (rowHeight * maxVisibleRows) + margin * 2;
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;
471
460
listWidth = Math.Min (450, CalcWidth ());
472
this.SetSizeRequest (listWidth, newHeight);
461
SetSizeRequest (listWidth, newHeight);
474
464
internal int CalcWidth ()
476
466
if (win.DataProvider.IconCount == 0)
488
478
layout.SetMarkup (win.DataProvider.GetMarkup (longest) ?? "<null>");
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;
497
void SetBounds (Gdk.Rectangle allocation)
489
if (vAdjustment == null)
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);
506
vadj.SetBounds (0, height, RowHeight, h, h);
496
vAdjustment.SetBounds (0, height, RowHeight, h, h);
510
501
protected override void OnSizeAllocated (Gdk.Rectangle allocation)
512
503
base.OnSizeAllocated (allocation);
514
hadj.SetBounds (0, allocation.Width, 0, 0, allocation.Width);
505
hAdjustment.SetBounds (0, allocation.Width, 0, 0, allocation.Width);
516
SetBounds (allocation);
521
512
protected override void OnRealized ()
523
514
base.OnRealized ();
527
518
void UpdateStyle ()
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 ();
530
Adjustment hAdjustment;
531
Adjustment vAdjustment;
542
533
protected override void OnSetScrollAdjustments (Adjustment hadj, Adjustment vadj)
546
if (this.vadj != null)
547
this.vadj.ValueChanged += (sender, e) => QueueDraw ();
537
if (vAdjustment != null)
538
vAdjustment.ValueChanged += delegate {
540
Selection = GetRowByPosition (curMouseY);
548
543
base.OnSetScrollAdjustments (hadj, vadj);