| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472 |
- //
- // System.Windows.Forms.Label.cs
- //
- // Author:
- // stubbed out by Daniel Carrera ([email protected])
- // implemented for Gtk+ by Rachel Hestilow ([email protected])
- // Dennis Hayes ([email protected])
- // WineLib implementation started by John Sohn ([email protected])
- //
- // (C) 2002/3 Ximian, Inc
- //
- namespace System.Windows.Forms {
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Text;
-
- public class Label : Control {
- Image background_image;
- BorderStyle border_style;
- bool autoSize;
- Image image;
- ContentAlignment image_align;
- StringFormat string_format;
- // ImeMode default_ime_mode;
- bool render_transparent;
- FlatStyle flat_style;
- int preferred_height;
- int preferred_width;
- bool tab_stop;
- ContentAlignment text_align;
- bool use_mnemonic;
-
- public Label () : base ()
- {
- // Defaults in the Spec
- autoSize = false;
- border_style = BorderStyle.None;
- // base.TabStop = false;
- text_align = ContentAlignment.TopLeft;
- // SetStyle (ControlStyles.Selectable, false);
- // SetStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
- string_format = new StringFormat();
- string_format.HotkeyPrefix=HotkeyPrefix.Show;
- }
- #region Properties
- public virtual bool AutoSize {
- get {
- return autoSize;
- }
- set {
- autoSize = value;
- }
- }
-
- public override Image BackgroundImage {
- get {
- return background_image;
- }
- set {
- background_image = value;
- Refresh ();
- }
- }
-
- public virtual BorderStyle BorderStyle {
- get {
- return border_style;
- }
- set {
- if (border_style == value)
- return;
-
- border_style = value;
- RecreateHandle ();
- }
- }
-
-
- public FlatStyle FlatStyle {
- get {
- return flat_style;
- }
- set {
- flat_style = value;
- Refresh ();
- }
- }
-
- public Image Image {
- get {
- return image;
- }
- set {
- image = value;
- Refresh ();
- }
- }
-
- public ContentAlignment ImageAlign {
- get {
- return image_align;
- }
- set {
- image_align = value;
- }
- }
-
-
- [MonoTODO]
- public int ImageIndex {
- get {
- throw new NotImplementedException ();
- }
- set {
- //FIXME:
- }
- }
- #if nodef
- [MonoTODO]
- public ImageList ImageList {
- get {
- throw new NotImplementedException ();
- }
- set {
- //FIXME:
- }
- }
- #endif
-
- protected override ImeMode DefaultImeMode {
- get {
- return ImeMode.Disable;
- }
- }
-
- public virtual int PreferredHeight {
- get {
- return preferred_height;
- }
- }
-
- public virtual int PreferredWidth {
- get {
- return preferred_width;
- }
- }
-
- public new bool TabStop {
- get {
- return tab_stop;
- }
- set {
- tab_stop = value;
- }
- }
-
- //Compact Framework
- public virtual ContentAlignment TextAlign {
- get {
- return text_align;
- }
- set {
- text_align = value;
- // Calculate vertical alignment
- if ((value == ContentAlignment.BottomLeft) || (value == ContentAlignment.BottomCenter) || (value == ContentAlignment.BottomRight)) {
- string_format.LineAlignment=StringAlignment.Far;
- } else if ((value == ContentAlignment.TopLeft) || (value == ContentAlignment.TopCenter) || (value == ContentAlignment.TopRight)) {
- string_format.LineAlignment=StringAlignment.Near;
- } else {
- string_format.LineAlignment=StringAlignment.Center;
- }
- // Calculate horizontal alignment
- if ((value == ContentAlignment.TopLeft) || (value == ContentAlignment.MiddleLeft) || (value == ContentAlignment.BottomLeft)) {
- string_format.Alignment=StringAlignment.Near;
- } else if ((value == ContentAlignment.TopRight) || (value == ContentAlignment.MiddleRight) || (value == ContentAlignment.BottomRight)) {
- string_format.LineAlignment=StringAlignment.Far;
- } else {
- string_format.LineAlignment=StringAlignment.Center;
- }
- }
- }
-
- public bool UseMnemonic {
- get {
- return use_mnemonic;
- }
- set {
- use_mnemonic = value;
- }
- }
-
- protected override CreateParams CreateParams {
- get {
- CreateParams createParams = base.CreateParams;
- createParams.ClassName = XplatUI.DefaultClassName;
- int bs = 0;
- #if notyet
- if (border_style == BorderStyle.FixedSingle)
- bs |= (int) WindowStyles.WS_BORDER;
- else if (border_style == BorderStyle.Fixed3D)
- bs |= (int) WindowStyles.WS_BORDER | (int) SS_Static_Control_Types.SS_SUNKEN;
-
- createParams.Style = (int) (
- (int)WindowStyles.WS_CHILD |
- (int)WindowStyles.WS_VISIBLE |
- (int)SS_Static_Control_Types.SS_LEFT |
- (int)WindowStyles.WS_CLIPCHILDREN |
- (int)WindowStyles.WS_CLIPSIBLINGS |
- (int)SS_Static_Control_Types.SS_OWNERDRAW |
- bs);
- #else
- createParams.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_VISIBLE |(int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
- #endif
- return createParams;
- }
- }
-
- protected override Size DefaultSize {
- get {
- return new Size(100,23);//Correct value
- }
- }
-
- protected virtual bool RenderTransparent {
- get {
- return render_transparent;
- }
- set {
- //FIXME:
- }
- }
- #if nodef
- protected override ImeMode DefaultImeMode {
- get {
- //FIXME:
- return default_ime_mode;
- }
- }
- #endif
-
- #endregion
- #region Methods
- public override string ToString()
- {
- //FIXME: add name of lable, as well as text. would adding base.ToString work?
- return "Label: " + base.Text;
- }
- [MonoTODO]
- protected override void Dispose(bool disposing){
- base.Dispose(disposing);
- }
- [MonoTODO]
- protected Rectangle CalcImageRenderBounds (
- Image image, Rectangle r, ContentAlignment align)
- {
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- protected override AccessibleObject CreateAccessibilityInstance()
- {
- //FIXME:
- return base.CreateAccessibilityInstance();
- }
- [MonoTODO]
- protected void DrawImage (Graphics g, Image image,
- Rectangle r, ContentAlignment align)
- {
- //FIXME:
- }
-
- protected virtual void OnAutoSizeChanged (EventArgs e)
- {
- if (AutoSizeChanged != null) AutoSizeChanged (this, e);
- }
-
- protected override void OnEnabledChanged (EventArgs e)
- {
- //FIXME:
- base.OnEnabledChanged (e);
- }
-
- protected override void OnFontChanged (EventArgs e)
- {
- //FIXME:
- base.OnFontChanged (e);
- }
-
- protected override void OnPaint (PaintEventArgs e)
- {
- Rectangle paintBounds = ClientRectangle;
- Bitmap bmp = new Bitmap( paintBounds.Width, paintBounds.Height,e.Graphics);
- Graphics paintOn = Graphics.FromImage(bmp);
-
- Color controlColor = BackColor; //SystemColors.Control;
- Color textColor = ForeColor; // SystemColors.ControlText;
- if (BackColor == System.Drawing.Color.Red) {
- Color t = System.Drawing.Color.Red;
- }
-
- Rectangle rc = paintBounds;
- Rectangle rcImageClip = paintBounds;
- rcImageClip.Inflate(-2,-2);
- SolidBrush sb = new SolidBrush( controlColor);
- paintOn.FillRectangle(sb, rc);
- sb.Dispose();
-
- // Do not place Text and Images on the borders
- paintOn.Clip = new Region(rcImageClip);
- if(Image != null) {
- int X = rc.X;
- int Y = rc.Y;
- if( ImageAlign == ContentAlignment.TopCenter ||
- ImageAlign == ContentAlignment.MiddleCenter ||
- ImageAlign == ContentAlignment.BottomCenter) {
- X += (rc.Width - Image.Width) / 2;
- }
- else if(ImageAlign == ContentAlignment.TopRight ||
- ImageAlign == ContentAlignment.MiddleRight||
- ImageAlign == ContentAlignment.BottomRight) {
- X += (rc.Width - Image.Width);
- }
- if( ImageAlign == ContentAlignment.BottomCenter ||
- ImageAlign == ContentAlignment.BottomLeft ||
- ImageAlign == ContentAlignment.BottomRight) {
- Y += rc.Height - Image.Height;
- }
- else if(ImageAlign == ContentAlignment.MiddleCenter ||
- ImageAlign == ContentAlignment.MiddleLeft ||
- ImageAlign == ContentAlignment.MiddleRight) {
- Y += (rc.Height - Image.Height) / 2;
- }
- paintOn.DrawImage(Image, X, Y, Image.Width, Image.Height);
- }
- if (Enabled) {
- SolidBrush brush;
- brush=new SolidBrush(textColor);
- paintOn.DrawString(Text, Font, brush, rc, string_format);
- brush.Dispose();
- }
- else {
- ControlPaint.DrawStringDisabled(paintOn, Text, Font, textColor, rc, string_format);
- }
- e.Graphics.DrawImage(bmp, 0, 0, paintBounds.Width, paintBounds.Height);
- paintOn.Dispose ();
- bmp.Dispose();
- }
-
- //Compact Framework
- protected override void OnParentChanged (EventArgs e)
- {
- base.OnParentChanged (e);
- }
-
- protected virtual void OnTextAlignChanged (EventArgs e) {
- if (TextAlignChanged != null) TextAlignChanged (this, e);
- }
-
- //Compact Framework
- protected override void OnTextChanged (EventArgs e) {
- base.OnTextChanged (e);
- Invalidate ();
- Refresh ();
- }
-
- protected override void OnVisibleChanged (EventArgs e)
- {
- base.OnVisibleChanged (e);
- }
-
- protected override bool ProcessMnemonic(char charCode)
- {
- return base.ProcessMnemonic (charCode);
- }
-
- // [MonoTODO]
- // protected new ContentAlignment RtlTranslateAlignment (
- // ContentAlignment alignment)
- // {
- // throw new NotImplementedException ();
- // }
- //
- // [MonoTODO]
- // protected new HorizontalAlignment RtlTranslateAlignment (
- // HorizontalAlignment alignment)
- // {
- // throw new NotImplementedException ();
- // }
- //
- // [MonoTODO]
- // protected new LeftRightAlignment RtlTranslateAlignment (
- // LeftRightAlignment align)
- // {
- // throw new NotImplementedException ();
- // }
- //
- // [MonoTODO]
- // protected new virtual void Select (bool directed, bool forward)
- // {
- // //FIXME:
- // }
- #if nodef
- protected override void SetBoundsCore (
- int x, int y, int width, int height,
- BoundsSpecified specified)
- {
- base.SetBoundsCore (x, y, width, height, specified);
- }
- #endif
-
- // protected new void UpdateBounds()
- // {
- // base.UpdateBounds ();
- // }
- //
- // protected new void UpdateBounds (int x, int y,
- // int width, int height)
- // {
- // base.UpdateBounds (x, y, width, height);
- // }
- //
- //
- // protected new void UpdateBounds (int x, int y, int width,
- // int height, int clientWidth,
- // int clientHeight)
- // {
- // base.UpdateBounds (x, y, width, height, clientWidth, clientHeight);
- // }
- protected override void WndProc(ref Message m)
- {
- switch ((Msg) m.Msg) {
- case Msg.WM_DRAWITEM: {
- m.Result = (IntPtr)1;
- }
- break;
- default:
- base.WndProc (ref m);
- break;
- }
- }
- #endregion
- #region Events
- public event EventHandler AutoSizeChanged;
-
- public event EventHandler TextAlignChanged;
- #endregion
-
- }
- }
|