📄 outlookbar.cs
字号:
firstItem--;
Rectangle rc = GetViewPortRect();
Invalidate(rc);
}
}
else if ( arrowButton.Equals(downArrowRect) )
{
using ( Graphics g = Graphics.FromHwnd(Handle) )
{
// Get the last item rectangle
OutlookBarBand band = bands[currentBandIndex];
if ( band != null )
{
Rectangle rcItem = GetItemRect(g, band, band.Items.Count - 1, Rectangle.Empty);
Rectangle rc = GetViewPortRect();
if ( rcItem.Bottom > rc.Bottom )
{
firstItem++;
Invalidate(rc);
}
}
}
}
}
doScrollingLoop = false;
break;
}
case (int)Msg.WM_KEYDOWN:
{
if ( (int)msg.wParam == (int)VirtualKeys.VK_ESCAPE)
doScrollingLoop = false;
break;
}
default:
WindowsAPI.DispatchMessage(ref msg);
break;
}
}
// Release the capture
Capture = false;
// Stop timer
timer.Stop();
timer.Dispose();
// Reset flags
arrowVisible = false;
arrowPressed = false;
timerTicking = false;
Rectangle viewPortRect = GetViewPortRect();
Invalidate(viewPortRect);
}
void ScrollingTick(Object timeObject, EventArgs eventArgs)
{
// Get mouse coordinates
Point point = Control.MousePosition;
point = PointToClient(point);
if ( upTimerTicking )
{
if ( buttonPushed )
{
if ( upArrowRect.Contains(point))
{
upArrowPressed = true;
if ( firstItem > 0 )
{
firstItem--;
Rectangle rc = GetViewPortRect();
Invalidate(rc);
}
else
doScrollingLoop = false;
}
else
upArrowPressed = false;
}
}
else if ( downTimerTicking )
{
if ( buttonPushed )
{
if ( downArrowRect.Contains(point))
{
downArrowPressed = true;
using ( Graphics g = Graphics.FromHwnd(Handle) )
{
// Get the last item rectangle
OutlookBarBand band = bands[currentBandIndex];
Rectangle rcItem = GetItemRect(g, band, band.Items.Count - 1, Rectangle.Empty);
Rectangle rc = GetViewPortRect();
if ( rcItem.Bottom > rc.Bottom )
{
firstItem++;
Invalidate(rc);
}
}
}
else
doScrollingLoop = false;
}
else
downArrowPressed = false;
}
}
void ProcessHeaderHit(int index)
{
Capture = true;
Rectangle rc = GetHeaderRect(index);
// Draw header pressed
Graphics g = Graphics.FromHwnd(Handle);
bool headerPressed = true;
DrawHeader(g, index, rc, Border3DStyle.Sunken);
bool doLoop = true;
while (doLoop)
{
// Check messages until we find a condition to break out of the loop
Win32.MSG msg = new Win32.MSG();
WindowsAPI.GetMessage(ref msg, 0, 0, 0);
Point point = new Point(0,0);
if ( msg.message == (int)Msg.WM_MOUSEMOVE || msg.message == (int)Msg.WM_LBUTTONUP )
{
point = WindowsAPI.GetPointFromLPARAM((int)msg.lParam);
}
switch(msg.message)
{
case (int)Msg.WM_MOUSEMOVE:
{
int currentIndex;
HitTestType hit = HitTest(point, out currentIndex, false);
if (hit == HitTestType.Header && currentIndex == index)
{
if (!headerPressed)
{
DrawHeader(g, index, rc, Border3DStyle.Sunken);
headerPressed = true;
}
}
else
{
if (headerPressed)
{
DrawHeader(g, index, rc, Border3DStyle.RaisedInner);
headerPressed = false;
}
}
break;
}
case (int)Msg.WM_LBUTTONUP:
{
if (headerPressed)
{
DrawHeader(g, index, rc, Border3DStyle.RaisedInner);
headerPressed = false;
}
int newIndex;
HitTestType ht = HitTest(point, out newIndex, false);
if ( ht == HitTestType.Header && newIndex != selectedHeader )
SetCurrentBand(newIndex);
doLoop = false;
break;
}
case (int)Msg.WM_KEYDOWN:
{
if ( (int)msg.wParam == (int)VirtualKeys.VK_ESCAPE)
doLoop = false;
break;
}
default:
WindowsAPI.DispatchMessage(ref msg);
break;
}
}
// Reset flags
Capture = false;
g.Dispose();
}
void ProcessItemHit(int index, Point pt)
{
bool itemPressed = true;
Capture = true;
Graphics g = Graphics.FromHwnd(Handle);
Rectangle itemRect = GetItemRect(g, bands[currentBandIndex], index, Rectangle.Empty);
DrawItem(g, index, itemRect, true, true, Rectangle.Empty, null);
bool dragging = false;
int deltaX = 0;
int deltaY = 0;
bool itemHighlighted = false;
int dragItemIndex = -1;
bool doLoop = true;
while ( doLoop )
{
// Check messages until we find a condition to break out of the loop
Win32.MSG msg = new Win32.MSG();
WindowsAPI.GetMessage(ref msg, 0, 0, 0);
Point point = new Point(0,0);
if ( msg.message == (int)Msg.WM_MOUSEMOVE || msg.message == (int)Msg.WM_LBUTTONUP )
{
point = WindowsAPI.GetPointFromLPARAM((int)msg.lParam);
if ( msg.message == (int)Msg.WM_MOUSEMOVE )
{
deltaX = pt.X - point.X;
deltaY = pt.Y - point.Y;
}
}
switch(msg.message)
{
case (int)Msg.WM_MOUSEMOVE:
{
int currentIndex;
HitTestType hit = HitTest(point, out currentIndex, dragging);
if ( dragging )
{
if ( hit == HitTestType.DropLine || hit == HitTestType.DropLineLastItem )
{
Cursor.Current = dragCursor;
// Draw the Dragline
DrawDropLine(g, currentIndex, true, hit);
}
else
{
Cursor.Current = Cursors.No;
// Erase the Dragline
DrawDropLine(g, index, false, hit);
}
if ( hit == HitTestType.Item && currentIndex == index)
{
if ( itemHighlighted == false )
{
DrawItem(g, index, itemRect,
true, false, Rectangle.Empty, null);
itemHighlighted = true;
}
}
else
{
if ( hit == HitTestType.Item )
{
// Erase previous highlighting first
if ( itemHighlighted )
{
DrawItem(g, index, itemRect,
false, false, Rectangle.Empty, null);
}
// Highlight new item
itemRect = GetItemRect(g, bands[currentBandIndex], currentIndex, Rectangle.Empty);
index = currentIndex;
DrawItem(g, index, itemRect,
true, false, Rectangle.Empty, null);
}
else
{
// the mouse did not hit an item
if ( itemHighlighted )
{
DrawItem(g, index, itemRect,
false, false, Rectangle.Empty, null);
itemHighlighted = false;
}
}
}
}
else
{
if (hit == HitTestType.Item && currentIndex == index)
{
// Set no drag cursor if there have been at least
// a 5 pixel movement
int pixelmov = 5;
if ( bands[currentBandIndex].IconView == IconView.Small ) pixelmov = 2;
bool unpressed = false;
if ( Math.Abs(deltaX) >= pixelmov || Math.Abs(deltaY) >= pixelmov )
{
unpressed = true;
Cursor.Current = Cursors.No;
dragging = true;
dragItemIndex = index;
}
if (itemPressed && unpressed)
{
DrawItem(g, index, itemRect,
true, false, Rectangle.Empty, null);
itemPressed = false;
itemHighlighted = true;
}
}
}
break;
}
case (int)Msg.WM_LBUTTONUP:
{
// Highlight the item
if (itemPressed)
{
DrawItem(g, index, itemRect, true, false, Rectangle.Empty, null);
itemPressed = false;
}
int newIndex;
HitTestType ht = HitTest(point, out newIndex, true);
bool doDrop = false;
if ( dragging && (ht == HitTestType.DropLine || ht == HitTestType.DropLineLastItem) )
{
// Delete dropline
Cursor.Current = Cursors.Default;
// Erase the Dragline
DrawDropLine(g, index, false, ht);
// Move the dragged item to the new location
// only if the new location is not contiguous to its
// own location
if ( dragItemIndex > droppedPosition
&& Math.Abs(dragItemIndex - droppedPosition) > 0 )
doDrop = true;
else if ( dragItemIndex < droppedPosition
&& Math.Abs(dragItemIndex - droppedPosition) > 1 )
doDrop = true;
if ( doDrop )
{
// Remove item from its old location
OutlookBarItem dragItem = bands[currentBandIndex].Items[dragItemIndex];
bands[currentBandIndex].Items.RemoveAt(dragItemIndex);
// Insert item in its new location
if ( dragItemIndex < droppedPosition )
droppedPosition--;
bands[currentBandIndex].Items.Insert(droppedPosition, dragItem);
}
}
// Repaint the bar just in case we had a dropline painted
Invalidate();
// Highlight item
if ( !dragging )
{
// do not highlight if we are dropping
forceHightlight = true;
forceHightlightIndex = index;
// Fire item clicked property
FireItemClicked(index);
}
else
{
// Fire item dropped event
if ( droppedPosition != -1 && doDrop )
FireItemDropped(droppedPosition);
}
doLoop = false;
break;
}
case (int)Msg.WM_KEYDOWN:
{
if ( (int)msg.wParam == (int)VirtualKeys.VK_ESCAPE)
doLoop = false;
break;
}
default:
WindowsAPI.DispatchMessage(ref msg);
break;
}
}
g.Dispose();
Capture = false;
}
void DrawDropLine(Graphics g, int index, bool drawLine, HitTestType hit)
{
Brush brush;
Pen pen;
if ( drawLine )
{
droppedPosition = index;
lastDrawnLineIndex = index;
brush = SystemBrushes.ControlText;
pen = SystemPens.ControlText;
}
else
{
// If there is nothing painted, no need to erase
if ( lastDrawnLineIndex == -1) return;
index = lastDrawnLineIndex;
brush = new SolidBrush(bands[currentBandIndex].Background);
pen = new Pen(bands[currentBandIndex].Background);
lastDrawnLineIndex = -1;
}
int itemsCount = bands[currentBandIndex].Items.Count;
Rectangle itemRect = GetItemRect(g, bands[currentBandIndex], index, Rectangle.Empty);
Rectangle viewPortRect = GetViewPortRect();
int y;
if ( bands[currentBandIndex].IconView == IconView.Small)
y = itemRect.Top - Y_SMALLICON_SPACING/2;
else
y = itemRect.Top - Y_LARGEICON_SPACING;
if ( hit == HitTestType.DropLineLastItem )
{
// use the bottom of the label if dealing with the last item
Rectangle labelRect = GetLabelRect(itemsCount-1);
y = labelRect.Bottom + Y_LARGEICON_SPACING;
paintedDropLineLastItem = true;
// the none existing item index
droppedPosition = itemsCount;
}
else if ( paintedDropLineLastItem )
{
Rectangle labelRect = GetLabelRect(itemsCount-1);
y = labelRect.Bottom + Y_LARGEICON_SPACING;
paintedDropLineLastItem = false;
}
// If we are using a bitmap background, erase
// by painting the portion of the bitmap background
if ( backgroundBitmap != null && lastDrawnLineIndex == -1 )
{
Rectangle rcStrip = new Rectangle(viewPortRect.Left, y-6, viewPortRect.Width, 12);
g.DrawImage(backgroundBitmap, rcStrip, rcStrip, GraphicsUnit.Pixel);
return;
}
// Draw horizontal line
Point p1 = new Point(viewPortRect.Left+11, y);
Point p2 = new Point(viewPortRect.Right-11, y);
g.DrawLine(pen, p1, p2);
// Draw left triangle
Point top;
Point bottom;
if ( index == firstItem )
top = new Point(viewPortRect.Left+5, y);
else
top = new Point(viewPortRect.Left+5, y-6);
if ( hit == HitTestType.DropLineLastItem )
bottom = new Point(viewPortRect.Left+5, y+1);
else
bottom = new Point(viewPortRect.Left+5, y+6);
Point middle = new Point(viewPortRect.Left+11, y);
Point[] points = new Point[3];
points.SetValue(top, 0);
points.SetValue(middle, 1);
points.SetValue(bottom, 2);
g.FillPolygon(brush, points);
// Draw right triangle
if ( index == firstItem )
top = new Point(viewPortRect.Right-5, y);
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -