#if DESIGN_MODE
internal static MethodInfo miDicStrStrAdd = typeof(Dictionary<string, string>).GetMethod ("set_Item", new Type[] { typeof(string), typeof(string) });
+ internal static FieldInfo fiWidget_design_id = typeof(Widget).GetField("design_id");
+ internal static FieldInfo fiWidget_design_line = typeof(Widget).GetField("design_line");
+ internal static FieldInfo fiWidget_design_column = typeof(Widget).GetField("design_column");
+ internal static FieldInfo fiWidget_design_imlPath = typeof(Widget).GetField("design_imlPath");
+ internal static FieldInfo fiWidget_design_iml_values = typeof(Widget).GetField("design_iml_values");
+
#endif
#region tree handling methods
void emitSetDesignAttribute (IMLContext ctx, string name, string value){
//store member value in iml
ctx.il.Emit (OpCodes.Ldloc_0);
- ctx.il.Emit (OpCodes.Ldfld, typeof(Widget).GetField("design_iml_values"));
+ ctx.il.Emit (OpCodes.Ldfld, CompilerServices.fiWidget_design_iml_values);
ctx.il.Emit (OpCodes.Ldstr, name);
if (string.IsNullOrEmpty (value))
ctx.il.Emit (OpCodes.Ldnull);
IXmlLineInfo li = (IXmlLineInfo)reader;
ctx.il.Emit (OpCodes.Ldloc_0);
ctx.il.Emit (OpCodes.Ldstr, this.NextDesignID);
- ctx.il.Emit (OpCodes.Stfld, typeof(Widget).GetField("design_id"));
+ ctx.il.Emit (OpCodes.Stfld, CompilerServices.fiWidget_design_id);
ctx.il.Emit (OpCodes.Ldloc_0);
ctx.il.Emit (OpCodes.Ldc_I4, ctx.curLine + li.LineNumber);
- ctx.il.Emit (OpCodes.Stfld, typeof(Widget).GetField("design_line"));
+ ctx.il.Emit (OpCodes.Stfld, CompilerServices.fiWidget_design_line);
ctx.il.Emit (OpCodes.Ldloc_0);
ctx.il.Emit (OpCodes.Ldc_I4, li.LinePosition);
- ctx.il.Emit (OpCodes.Stfld, typeof(Widget).GetField("design_column"));
+ ctx.il.Emit (OpCodes.Stfld, CompilerServices.fiWidget_design_column);
if (!string.IsNullOrEmpty (sourcePath)) {
ctx.il.Emit (OpCodes.Ldloc_0);
ctx.il.Emit (OpCodes.Ldstr, sourcePath);
- ctx.il.Emit (OpCodes.Stfld, typeof(Widget).GetField("design_imlPath"));
+ ctx.il.Emit (OpCodes.Stfld, CompilerServices.fiWidget_design_imlPath);
}
#endif
#region Styling and default values loading
/// </summary>
public static long TEXT_CURSOR_BLINK_FREQUENCY = 400;
internal Rectangle? textCursor = null;//last printed cursor, used to clear it.
- internal bool forceTextCursor = true;//when true, cursor is printed even if blinkingCursor.elapsed is not reached.
+ public bool forceTextCursor = true;//when true, cursor is printed even if blinkingCursor.elapsed is not reached.
Stopwatch blinkingCursor = Stopwatch.StartNew ();
void drawTextCursor (Context ctx) {
if (forceTextCursor) {
- if (FocusedWidget is Label lab) {
+ if (FocusedWidget is IEditableTextWidget lab) {
if (lab.DrawCursor (ctx, out Rectangle c)) {
if (textCursor != null && c != textCursor.Value)
RegisterClip (textCursor.Value);
RegisterClip (textCursor.Value);
textCursor = null;
blinkingCursor.Restart ();
- } else if (FocusedWidget is Label lab && lab.SelectionIsEmpty) {
+ } else if (FocusedWidget is IEditableTextWidget lab) {
if (blinkingCursor.ElapsedMilliseconds > TEXT_CURSOR_BLINK_FREQUENCY) {
if (lab.DrawCursor (ctx, out Rectangle c)) {
textCursor = c;
#endregion
#region ILayoutable implementation
- public virtual bool PointIsIn (ref Point m)
- {
- return true;
- }
+ public virtual bool PointIsIn (ref Point m) => true;
public void RegisterClip (Rectangle r)
{
clipping.UnionRectangle (r);
}
- public bool ArrangeChildren { get { return false; } }
+ public bool ArrangeChildren => false;
public int LayoutingTries {
get { throw new NotImplementedException (); }
set { throw new NotImplementedException (); }
}
public LayoutingType RegisteredLayoutings {
- get { return LayoutingType.None; }
+ get => LayoutingType.None;
set { throw new NotImplementedException (); }
}
public void RegisterForLayouting (LayoutingType layoutType) { throw new NotImplementedException (); }
public bool UpdateLayout (LayoutingType layoutType) { throw new NotImplementedException (); }
- public Rectangle ContextCoordinates (Rectangle r) { return r; }
- public Rectangle ScreenCoordinates (Rectangle r) { return r; }
+ public Rectangle ContextCoordinates (Rectangle r) => r;
+ public Rectangle ScreenCoordinates (Rectangle r) => r;
public ILayoutable Parent {
- get { return null; }
+ get => null;
set { throw new NotImplementedException (); }
}
public ILayoutable LogicalParent {
- get { return null; }
+ get => null;
set { throw new NotImplementedException (); }
}
- public Rectangle ClientRectangle {
- get { return clientRectangle; }
- }
+ public Rectangle ClientRectangle => clientRectangle;
public Interface HostContainer {
get { return this; }
}
- public Rectangle getSlot () { return ClientRectangle; }
+ public Rectangle getSlot () => ClientRectangle;
+ public void ChildrenLayoutingConstraints(ILayoutable layoutable, ref LayoutingType layoutType){ }
#endregion
}
}
--- /dev/null
+using System;
+using Crow.Cairo;
+
+namespace Crow
+{
+ /// <summary>
+ /// Implement this interface to have a blinking cursor for a widget
+ /// with editable text ability.
+ /// </summary>
+ public interface IEditableTextWidget
+ {
+ /// <summary>
+ /// Draw text cursor in widget with screen coordinates. This interface when implemented is called
+ /// automatically by the Interface to make the cursor blink. The blinking frequency is controlled by
+ /// Interface.TEXT_CURSOR_BLINK_FREQUENCY static field.
+ /// </summary>
+ /// <param name="ctx">The master interface context on which to draw the cursor</param>
+ /// <param name="rect">Return a clipping rectangle containing the cursor position to be cleared when needed</param>
+ /// <returns>True if cursor were drawed, false otherwise</returns>
+ bool DrawCursor (Context ctx, out Rectangle rect);
+ }
+}
\ No newline at end of file
/// <summary>
/// Simple label widget possibly multiline but without tabulation handling.
/// </summary>
- public class Label : Widget
+ public class Label : Widget, IEditableTextWidget
{
#region CTOR
protected Label () {}
return null;
return cursor;
}
- internal virtual bool DrawCursor (Context ctx, out Rectangle rect) {
+ public virtual bool DrawCursor (Context ctx, out Rectangle rect) {
+ if (CurrentLoc == null || !SelectionIsEmpty) {
+ rect = default;
+ return false;
+ }
if (!CurrentLoc.Value.HasVisualX) {
ctx.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
ctx.SetFontSize (Font.Size);
return cursor;
}
- /*internal override bool DrawCursor (Context ctx, out Rectangle rect) {
- ctx.Translate (-scrollX, -scrollY);
- bool result = base.DrawCursor (ctx, out rect);
- ctx.Translate (scrollX, scrollY);
- return result;
- }*/
void updateMaxScrolls (LayoutingType layout) {
Rectangle cb = ClientRectangle;