/// <summary> /// Factory widget creation /// </summary> /// <param name="aDefaultMethod"> /// Default creation method fallback <see cref="WidgetCreationEvent"/> /// </param> /// <param name="aArgs"> /// Widget creation arguments <see cref="FactoryInvocationArgs"/> /// </param> /// <returns> /// Result widget <see cref="IAdaptableControl"/> /// </returns> public static IAdaptableControl CreateWidget(WidgetCreationEvent aDefaultMethod, FactoryInvocationArgs aArgs) { if (aDefaultMethod == null) { aDefaultMethod = new WidgetCreationEvent(CreateDefaultWidget); } IAdaptableControl wdg = null; if (aArgs.PropertyInfo == null) { return(null); } if (aArgs.Description != null) { switch (aArgs.Description.HandlerType) { case PropertyHandlerType.Default: wdg = aDefaultMethod(aArgs); break; case PropertyHandlerType.Custom: wdg = CreateHandlerWidget(aDefaultMethod, aArgs); break; } } else if ((aArgs.HandlerOverride != "") && (aArgs.HandlerOverride.ToLower().Trim() != "default")) { wdg = CreateHandlerWidget(aDefaultMethod, aArgs); } else { wdg = aDefaultMethod(aArgs); } if (wdg != null) { wdg.InheritedDataSource = true; } return(wdg); }
/// <summary> /// Creates default widgets for properties which don't specify their property description /// </summary> /// <param name="aArgs"> /// Widget creation arguments <see cref="FactoryInvocationArgs"/> /// </param> /// <returns> /// Result widget <see cref="IAdaptableControl"/> /// </returns> private static IAdaptableControl CreateDefaultGtkWidget(FactoryInvocationArgs aArgs) { foreach (FactoryInvokerClass invoker in AllWidgetsForType(aArgs.PropertyInfo.PropertyType)) { return(invoker.Invoke(aArgs)); } // Silly fallback if registration is not done IAdaptableControl wdg = null; switch (aArgs.State) { case PropertyDefinition.ReadOnly: if (aArgs.PropertyInfo.PropertyType == typeof(string)) { wdg = new DataLabel(aArgs.PropertyName); break; } else if (aArgs.PropertyInfo.PropertyType == typeof(bool)) { wdg = new DataCheckButton(aArgs.PropertyName); (wdg as DataCheckButton).Editable = false; } else if (aArgs.PropertyInfo.PropertyType == typeof(Gdk.Pixbuf)) { wdg = new DataImage(aArgs.PropertyName); } else { wdg = new DataLabel(aArgs.PropertyName); } break; case PropertyDefinition.ReadWrite: if (aArgs.PropertyInfo.PropertyType == typeof(string)) { wdg = new DataEntry(aArgs.PropertyName); } else if (aArgs.PropertyInfo.PropertyType == typeof(bool)) { wdg = new DataCheckButton(aArgs.PropertyName); } else if ((aArgs.PropertyInfo.PropertyType == typeof(int)) || (aArgs.PropertyInfo.PropertyType == typeof(float)) || (aArgs.PropertyInfo.PropertyType == typeof(double))) { wdg = new DataSpinButton(-100000000, 100000000, 1, aArgs.PropertyName); } else if (aArgs.PropertyInfo.PropertyType == typeof(DateTime)) { wdg = new DataCalendar(aArgs.PropertyName); } else if (aArgs.PropertyInfo.PropertyType == typeof(Gdk.Pixbuf)) { wdg = new DataImage(aArgs.PropertyName); } else { wdg = new DataLabel(aArgs.PropertyName); } break; } return(wdg); }