protected virtual IDisposable DrawRibbonQATFullbarSquare(RenderContext context,
Rectangle rect,
PaletteState state,
IPaletteRibbonBack palette,
IDisposable memento)
{
if ((rect.Width > 0) && (rect.Height > 0))
{
Color c1 = palette.GetRibbonBackColor1(state);
Color c2 = palette.GetRibbonBackColor2(state);
Color c3 = palette.GetRibbonBackColor3(state);
bool generate = true;
MementoRibbonQATFullbarSquare cache;
// Access a cache instance and decide if cache resources need generating
if ((memento == null) || !(memento is MementoRibbonQATFullbarSquare))
{
if (memento != null)
memento.Dispose();
cache = new MementoRibbonQATFullbarSquare(rect, c1, c2, c3);
memento = cache;
}
else
{
cache = (MementoRibbonQATFullbarSquare)memento;
generate = !cache.UseCachedValues(rect, c1, c2, c3);
}
// Do we need to generate the contents of the cache?
if (generate)
{
// Dispose of existing values
cache.Dispose();
cache.lightPen = new Pen(c1);
cache.mediumBrush = new SolidBrush(c2);
cache.darkPen = new Pen(c3);
}
// Fill entire area in background brush
context.Graphics.FillRectangle(cache.mediumBrush, rect);
// Draw the outside border
context.Graphics.DrawRectangle(cache.darkPen, rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
// Draw ligher top and bottom lines
context.Graphics.DrawLine(cache.lightPen, rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Y + 1);
context.Graphics.DrawLine(cache.lightPen, rect.X + 1, rect.Bottom - 2, rect.Width - 2, rect.Bottom - 2);
}
return memento;
}