| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427 |
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- // Copyright (c) 2004 Novell, Inc.
- //
- // Authors:
- // Jordi Mas i Hernandez, [email protected]
- //
- //
- // $Revision: 1.10 $
- // $Modtime: $
- // $Log: Theme.cs,v $
- // Revision 1.10 2004/09/28 18:44:25 pbartok
- // - Streamlined Theme interfaces:
- // * Each DrawXXX method for a control now is passed the object for the
- // control to be drawn in order to allow accessing any state the theme
- // might require
- //
- // * ControlPaint methods for the theme now have a CP prefix to avoid
- // name clashes with the Draw methods for controls
- //
- // * Every control now retrieves it's DefaultSize from the current theme
- //
- // Revision 1.9 2004/09/17 12:18:42 jordi
- // Very early menu support
- //
- // Revision 1.8 2004/09/07 17:12:26 jordi
- // GroupBox control
- //
- // Revision 1.7 2004/09/07 09:40:15 jordi
- // LinkLabel fixes, methods, multiple links
- //
- // Revision 1.6 2004/09/02 16:32:54 jordi
- // implements resource pool for pens, brushes, and hatchbruses
- //
- // Revision 1.5 2004/08/25 20:04:40 ravindra
- // Added the missing divider code and grip for ToolBar Control.
- //
- // Revision 1.4 2004/08/24 18:37:02 jordi
- // fixes formmating, methods signature, and adds missing events
- //
- // Revision 1.3 2004/08/24 16:16:46 jackson
- // Handle drawing picture boxes in the theme now. Draw picture box borders and obey sizing modes
- //
- // Revision 1.2 2004/08/20 00:12:51 jordi
- // fixes methods signature
- //
- // Revision 1.1 2004/08/19 22:26:30 jordi
- // move themes from an interface to a class
- //
- //
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Drawing.Imaging;
- using System.Collections;
- namespace System.Windows.Forms
- {
-
-
- // Implements a pool of system resources
- internal class SystemResPool
- {
- private Hashtable pens = new Hashtable ();
- private Hashtable solidbrushes = new Hashtable ();
- private Hashtable hatchbrushes = new Hashtable ();
-
- public SystemResPool () {}
-
- public Pen GetPen (Color color)
- {
- string hash = color.ToString();
-
- if (pens.Contains (hash))
- return (Pen) pens[hash];
-
- Pen pen = new Pen (color);
- pens.Add (hash, pen);
- return pen;
- }
-
- public SolidBrush GetSolidBrush (Color color)
- {
- string hash = color.ToString ();
-
- if (solidbrushes.Contains (hash))
- return (SolidBrush) solidbrushes[hash];
-
- SolidBrush brush = new SolidBrush (color);
- solidbrushes.Add (hash, brush);
- return brush;
- }
-
- public HatchBrush GetHatchBrush (HatchStyle hatchStyle, Color foreColor, Color backColor)
- {
- string hash = hatchStyle.ToString () + foreColor.ToString () + backColor.ToString ();
-
- if (hatchbrushes.Contains (hash))
- return (HatchBrush) hatchbrushes[hash];
-
- HatchBrush brush = new HatchBrush (hatchStyle, foreColor, backColor);
- hatchbrushes.Add (hash, brush);
- return brush;
- }
-
- }
- internal abstract class Theme
- {
- protected Array syscolors;
- protected Font default_font;
- protected Color defaultWindowBackColor;
- protected Color defaultWindowForeColor;
- internal SystemResPool ResPool = new SystemResPool ();
-
- /* Default properties */
- public virtual Color ColorScrollbar {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_SCROLLBAR);}
- }
- public virtual Color ColorBackground {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BACKGROUND);}
- }
- public virtual Color ColorActiveTitle {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_ACTIVECAPTION);}
- }
- public virtual Color ColorInactiveTitle {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INACTIVECAPTION);}
- }
- public virtual Color ColorMenu {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_MENU);}
- }
- public virtual Color ColorWindow {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_WINDOW);}
- }
- public virtual Color ColorWindowFrame {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_WINDOWFRAME);}
- }
- public virtual Color ColorMenuText {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_MENUTEXT);}
- }
- public virtual Color ColorWindowText {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_WINDOWTEXT);}
- }
- public virtual Color ColorTitleText {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_CAPTIONTEXT);}
- }
- public virtual Color ColorActiveBorder {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_ACTIVEBORDER);}
- }
- public virtual Color ColorInactiveBorder{
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INACTIVEBORDER);}
- }
- public virtual Color ColorAppWorkSpace {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_APPWORKSPACE);}
- }
- public virtual Color ColorHilight {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_HIGHLIGHT);}
- }
- public virtual Color ColorHilightText {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_HIGHLIGHTTEXT);}
- }
- public virtual Color ColorButtonFace {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BTNFACE);}
- }
- public virtual Color ColorButtonShadow {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BTNSHADOW);}
- }
- public virtual Color ColorGrayText {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_GRAYTEXT);}
- }
- public virtual Color ColorButtonText {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BTNTEXT);}
- }
- public virtual Color ColorInactiveTitleText {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INACTIVECAPTIONTEXT);}
- }
- public virtual Color ColorButtonHilight {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_BTNHIGHLIGHT);}
- }
- public virtual Color ColorButtonDkShadow {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_3DDKSHADOW);}
- }
- public virtual Color ColorButtonLight {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_3DLIGHT);}
- }
- public virtual Color ColorInfoText {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INFOTEXT);}
- }
- public virtual Color ColorInfoWindow {
- get {return GetColor (XplatUIWin32.GetSysColorIndex.COLOR_INFOBK);}
- }
- public virtual Color DefaultControlBackColor {
- get { return ColorButtonFace; }
- }
- public virtual Color DefaultControlForeColor {
- get { return ColorButtonText; }
- }
- public virtual Font DefaultFont {
- get { return default_font; }
- }
- public virtual Color DefaultWindowBackColor {
- get { return defaultWindowBackColor; }
- }
- public virtual Color DefaultWindowForeColor {
- get { return defaultWindowForeColor; }
- }
- public virtual Color GetColor (XplatUIWin32.GetSysColorIndex idx)
- {
- return (Color) syscolors.GetValue ((int)idx);
- }
- public virtual void SetColor (XplatUIWin32.GetSysColorIndex idx, Color color)
- {
- syscolors.SetValue (color, (int) idx);
- }
- #region Principal Theme Methods
- // If the theme writes directly to a window instead of a device context
- public abstract bool DoubleBufferingSupported {get;}
- #endregion // Principal Theme Methods
- #region OwnerDraw Support
- public abstract void DrawOwnerDrawBackground (DrawItemEventArgs e);
- public abstract void DrawOwnerDrawFocusRectangle (DrawItemEventArgs e);
- #endregion // OwnerDraw Support
- #region Button
- #endregion // Button
- #region ButtonBase
- // Drawing
- public abstract void DrawButtonBase(Graphics dc, Rectangle clip_area, ButtonBase button);
- // Sizing
- public abstract Size ButtonBaseDefaultSize{get;}
- #endregion // ButtonBase
- #region CheckBox
- public abstract void DrawCheckBox(Graphics dc, Rectangle clip_area, CheckBox checkbox);
- #endregion // CheckBox
- #region Control
- #endregion // Control
- #region GroupBox
- // Drawing
- public abstract void DrawGroupBox (Graphics dc, Rectangle clip_area, GroupBox box);
- // Sizing
- public abstract Size GroupBoxDefaultSize{get;}
- #endregion // GroupBox
- #region HScrollBar
- public abstract Size HScrollBarDefaultSize{get;} // Default size of the scrollbar
- #endregion // HScrollBar
- #region Label
- // Drawing
- public abstract void DrawLabel (Graphics dc, Rectangle clip_rectangle, Label label);
- // Sizing
- public abstract Size LabelDefaultSize{get;}
- #endregion // Label
- #region LinkLabel
- #endregion // LinkLabel
- #region Panel
- // Sizing
- public abstract Size PanelDefaultSize{get;}
- #endregion // Panel
- #region PictureBox
- // Drawing
- public abstract void DrawPictureBox (Graphics dc, PictureBox pb);
- // Sizing
- public abstract Size PictureBoxDefaultSize{get;}
- #endregion // PictureBox
- #region ProgressBar
- // Drawing
- public abstract void DrawProgressBar (Graphics dc, Rectangle clip_rectangle, ProgressBar progress_bar);
- // Sizing
- public abstract Size ProgressBarDefaultSize{get;}
- #endregion // ProgressBar
- #region RadioButton
- // Drawing
- public abstract void DrawRadioButton (Graphics dc, Rectangle clip_rectangle, RadioButton radio_button);
- // Sizing
- public abstract Size RadioButtonDefaultSize{get;}
- #endregion // RadioButton
- #region ScrollBar
- // Drawing
- //public abstract void DrawScrollBar (Graphics dc, Rectangle area, ScrollBar bar, ref Rectangle thumb_pos, ref Rectangle first_arrow_area, ref Rectangle second_arrow_area, ButtonState first_arrow, ButtonState second_arrow, ref int scrollbutton_width, ref int scrollbutton_height, bool vert);
- public abstract void DrawScrollBar (Graphics dc, Rectangle clip_rectangle, ScrollBar bar);
- // Sizing
- public abstract int ScrollBarButtonSize {get;} // Size of the scroll button
- #endregion // ScrollBar
- #region StatusBar
- // Drawing
- public abstract void DrawStatusBar (Graphics dc, Rectangle clip_rectangle, StatusBar sb);
- // Sizing
- public abstract int StatusBarSizeGripWidth {get;} // Size of Resize area
- public abstract int StatusBarHorzGapWidth {get;} // Gap between panels
- public abstract Size StatusBarDefaultSize{get;}
- #endregion // StatusBar
- #region ToolBar
- // Drawing
- public abstract void DrawToolBar (Graphics dc, Rectangle clip_area, ToolBar control);
- // Sizing
- public abstract int ToolBarGripWidth {get;} // Grip width for the ToolBar
- public abstract int ToolBarImageGripWidth {get;} // Grip width for the Image on the ToolBarButton
- public abstract int ToolBarSeparatorWidth {get;} // width of the separator
- public abstract int ToolBarDropDownWidth { get; } // width of the dropdown arrow rect
- public abstract int ToolBarDropDownArrowWidth { get; } // width for the dropdown arrow on the ToolBarButton
- public abstract int ToolBarDropDownArrowHeight { get; } // height for the dropdown arrow on the ToolBarButton
- public abstract Size ToolBarDefaultSize{get;}
- #endregion // ToolBar
- #region TrackBar
- // Drawing
- public abstract void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb);
- //public abstract void DrawTrackBar (Graphics dc, Rectangle area, TrackBar tb,
- //ref Rectangle thumb_pos,
- //ref Rectangle thumb_area,
- //bool highli_thumb,
- //float ticks,
- //int value_pos,
- //bool mouse_value);
- // Sizing
- public abstract Size TrackBarDefaultSize{get; } // Default size for the TrackBar control
- #endregion // TrackBar
- #region VScrollBar
- public abstract Size VScrollBarDefaultSize{get;} // Default size of the scrollbar
- #endregion // VScrollBar
- #region ControlPaint Methods
- public abstract void CPDrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
- ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
- Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
- int bottomWidth, ButtonBorderStyle bottomStyle);
- public abstract void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides);
- public abstract void CPDrawButton (Graphics graphics, Rectangle rectangle, ButtonState state);
- public abstract void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state);
- public abstract void CPDrawCheckBox (Graphics graphics, Rectangle rectangle, ButtonState state);
- public abstract void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state);
- public abstract void CPDrawContainerGrabHandle (Graphics graphics, Rectangle bounds);
- public abstract void CPDrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor);
- public abstract void CPDrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled);
- public abstract void CPDrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor);
- public abstract void CPDrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background);
- public abstract void CPDrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary);
- public abstract void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph);
- public abstract void CPDrawRadioButton (Graphics graphics, Rectangle rectangle, ButtonState state);
- public abstract void CPDrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style);
- public abstract void CPDrawReversibleLine (Point start, Point end, Color backColor);
- public abstract void CPDrawScrollButton (Graphics graphics, Rectangle rectangle, ScrollButton button, ButtonState state);
- public abstract void CPDrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
- Color backColor);
- public abstract void CPDrawSizeGrip (Graphics graphics, Color backColor, Rectangle bounds);
- public abstract void CPDrawStringDisabled (Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle,
- StringFormat format);
- public abstract void CPDrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style);
- #endregion // ControlPaint Methods
- }
- }
|