예제 #1
0
 private static string GetString <T>(GetStringMethod <T> method, T localeId)
 {
     return(NativeMethods.GetAnsiString((ptr, length) =>
     {
         length = method(localeId, ptr, length, out var err);
         return new Tuple <ErrorCode, int>(err, length);
     }));
 }
예제 #2
0
 private static string GetString(GetStringMethod method, string src, string locale)
 {
     return(NativeMethods.GetUnicodeString((ptr, length) =>
     {
         length = method(ptr, length, src, src.Length, locale, out var err);
         return new Tuple <ErrorCode, int>(err, length);
     }, src.Length + 10));
 }
예제 #3
0
        private static void Check(GetStringMethod left, GetStringMethod right, List <DataEntry[]> violations)
        {
            var l = GetString(left);
            var r = GetString(right);

            if (l != r)
            {
                violations.Add(left, l, r);
            }
        }
예제 #4
0
        private static void CheckCommaSeparated(GetStringMethod left, GetStringMethod right, List <DataEntry[]> violations)
        {
            var l = GetString(left);
            var r = GetString(right);

            if (!l.Split(',').OrderedItemsEqual(r.Split(',')))
            {
                violations.Add(left, l, r);
            }
        }
예제 #5
0
        public static string GetString(GetStringMethod method)
        {
            uint size = method(0, null);

            if (size > 0)
            {
                var sb = new StringBuilder {
                    Length = (int)size
                };
                method(size, sb);

                return(sb.ToString());
            }

            return(string.Empty);
        }
예제 #6
0
        public static string GetString(GetStringMethod method)
        {
            uint size = method(0, null);

            if (size > 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.Length = (int)size;
                method(size, sb);

                return(sb.ToString());
            }
            else
            {
                return(string.Empty);
            }
        }
예제 #7
0
        private static string GetString(GetStringMethod method, string localeId)
        {
            const int nSize  = 255;
            IntPtr    resPtr = Marshal.AllocCoTaskMem(nSize);

            try
            {
                ErrorCode err;
                method(localeId, resPtr, nSize, out err);
                if (!Failure(err))
                {
                    return(Marshal.PtrToStringAnsi(resPtr));
                }
                return(string.Empty);
            }
            finally
            {
                Marshal.FreeCoTaskMem(resPtr);
            }
        }
예제 #8
0
        /*
         * Constructor
         */

        public TimeDurationSmartCIO(GroupNode specSnippet)
            : base(new Panel(), specSnippet)
        {
            if (_specSnippet.IsObject())
            {
                // single state translations

                /*
                 * There are three possible translations if there is only one state.
                 * If the state is read-only, then the time will be displayed in a label.
                 * The state will be displayed as a TimeSlider if the state is editable,
                 * numeric and bounded.  Otherwise it will be displayed as a TimeEditor.
                 */

                ApplianceState       state = (ApplianceState)_objects[SINGLE_STATE];
                PUC.Types.ValueSpace space = state.Type.ValueSpace;

                if (space is PUC.Types.IntegerSpace)
                {
                    _getString = new GetStringMethod(this.GetStringFromInt);
                }
                else if (space is PUC.Types.StringSpace)
                {
                    _getString = new GetStringMethod(this.GetStringFromString);
                }
                else if (space is PUC.Types.FixedPtSpace || space is PUC.Types.FloatingPtSpace)
                {
                    _getString = new GetStringMethod(this.GetStringFromFloat);
                }

                if (state.ReadOnly)
                {
                    _timeControl = new Label();

                    if (space is PUC.Types.IntegerSpace)
                    {
                        _setTime = new SetControlTime(this.SetLabel);
                    }
                    else if (space is PUC.Types.StringSpace)
                    {
                        _setTime = new SetControlTime(this.SetLabel);
                    }
                    else
                    {
                        _setTime = new SetControlTime(this.SetLabel);
                    }
                }
                else
                {
                    if (space is PUC.Types.IntegerSpace)
                    {
                        IntegerSpace intspc = (IntegerSpace)space;

                        if (intspc.IsRanged())
                        {
                            _timeControl = new TimeSlider();
                            _setTime     = new SetControlTime(this.SetSliderFromInt);
                            ((TimeSlider)_timeControl).TimeChanged += new EventHandler(this.IntSliderTimeChanged);
                            _sentValues = new Hashtable();
                        }
                        else
                        {
                            _format = new TimeFormat[4];
                            _format[(int)TimeUnits.Hours]    = new TimeFormat(true);
                            _format[(int)TimeUnits.Minutes]  = new TimeFormat(true);
                            _format[(int)TimeUnits.Seconds]  = new TimeFormat(true);
                            _format[(int)TimeUnits.Fraction] = new TimeFormat(false);

                            _timeControl = new TimeEditor(_format);
                            _setTime     = new SetControlTime(this.SetEditorFromInt);
                            ((TimeEditor)_timeControl).TimeChanged += new EventHandler(this.IntTimeEditorChanged);
                        }
                    }
                    else if (space is PUC.Types.FixedPtSpace)
                    {
                        FixedPtSpace fxdspc = (FixedPtSpace)space;

                        if (fxdspc.IsRanged())
                        {
                            _timeControl = new TimeSlider();
                            _setTime     = new SetControlTime(this.SetSliderFromFixed);
                            ((TimeSlider)_timeControl).TimeChanged += new EventHandler(this.FloatSliderTimeChanged);
                            _sentValues = new Hashtable();
                        }
                        else
                        {
                            _format = new TimeFormat[4];
                            _format[(int)TimeUnits.Hours]            = new TimeFormat(true);
                            _format[(int)TimeUnits.Minutes]          = new TimeFormat(true);
                            _format[(int)TimeUnits.Seconds]          = new TimeFormat(true);
                            _format[(int)TimeUnits.Fraction]         = new TimeFormat(true);
                            _format[(int)TimeUnits.Fraction].Maximum = ((int)Math.Pow(10, fxdspc.GetPointPosition())) - 1;

                            _timeControl = new TimeEditor(_format);
                            _setTime     = new SetControlTime(this.SetEditorFromFloat);
                            ((TimeEditor)_timeControl).TimeChanged += new EventHandler(this.FloatTimeEditorChanged);
                        }
                    }
                    else if (space is PUC.Types.FloatingPtSpace)
                    {
                        FloatingPtSpace fltspc = (FloatingPtSpace)space;

                        if (fltspc.IsRanged())
                        {
                            _timeControl = new TimeSlider();
                            _setTime     = new SetControlTime(this.SetSliderFromFloat);
                            ((TimeSlider)_timeControl).TimeChanged += new EventHandler(this.FloatSliderTimeChanged);
                            _sentValues = new Hashtable();
                        }
                        else
                        {
                            _format = new TimeFormat[4];
                            _format[(int)TimeUnits.Hours]            = new TimeFormat(true);
                            _format[(int)TimeUnits.Minutes]          = new TimeFormat(true);
                            _format[(int)TimeUnits.Seconds]          = new TimeFormat(true);
                            _format[(int)TimeUnits.Fraction]         = new TimeFormat(true);
                            _format[(int)TimeUnits.Fraction].Maximum = 999;

                            _timeControl = new TimeEditor(_format);
                            _setTime     = new SetControlTime(this.SetEditorFromFloat);
                            ((TimeEditor)_timeControl).TimeChanged += new EventHandler(this.FloatTimeEditorChanged);
                        }
                    }
                    else if (space is PUC.Types.StringSpace)
                    {
                        _format = new TimeFormat[4];
                        _format[(int)TimeUnits.Hours]    = new TimeFormat(true);
                        _format[(int)TimeUnits.Minutes]  = new TimeFormat(true);
                        _format[(int)TimeUnits.Seconds]  = new TimeFormat(true);
                        _format[(int)TimeUnits.Fraction] = new TimeFormat(true);

                        _timeControl = new TimeEditor();
                        _setTime     = new SetControlTime(this.SetEditorFromString);
                        ((TimeEditor)_timeControl).TimeChanged += new EventHandler(this.StringTimeEditorChanged);
                    }
                }

                if (_timeControl != null)
                {
                    doNotRenderObject(state);
                    state.ValueChangedEvent  += new PUC.ApplianceState.ValueChangedHandler(this.ValueChanged);
                    state.TypeChangedEvent   += new PUC.ApplianceState.TypeChangedHandler(this.TypeChanged);
                    state.EnableChangedEvent += new PUC.ApplianceObject.EnableChangedHandler(this.EnableChanged);
                }
            }
            else
            {
                // multiple state translation

                /*
                 * There are two possible translations if there are multiple
                 * states.  If any states are read-only, then the time will be displayed
                 * in a label.  Otherwise the time will displayed for editing in the
                 * PocketPCControls.TimeEditor control.
                 */

                ApplianceState hourState = (ApplianceState)_objects[HOURS_LABEL];
                ApplianceState minState  = (ApplianceState)_objects[MINUTES_LABEL];
                ApplianceState secState  = (ApplianceState)_objects[SECONDS_LABEL];
                ApplianceState fracState = (ApplianceState)_objects[FRACTION_LABEL];

                _getString = new GetStringMethod(this.GetStringFromMultiple);

                if ((hourState != null && hourState.ReadOnly) ||
                    (minState != null && minState.ReadOnly) ||
                    (secState != null && secState.ReadOnly) ||
                    (fracState != null && fracState.ReadOnly))
                {
                    _timeControl = new Label();
                    _setTime     = new SetControlTime(this.SetLabel);
                }
                else
                {
                    ApplianceState[] states = new ApplianceState[4];
                    _format = new TimeFormat[4];
                    IntegerSpace space;

                    states[(int)TimeUnits.Hours]    = hourState;
                    states[(int)TimeUnits.Minutes]  = minState;
                    states[(int)TimeUnits.Seconds]  = secState;
                    states[(int)TimeUnits.Fraction] = fracState;

                    for (int i = (int)TimeUnits.Hours; i <= (int)TimeUnits.Fraction; i++)
                    {
                        if (states[i] == null)
                        {
                            _format[i] = new TimeFormat(false);
                        }
                        else
                        {
                            _format[i] = new TimeFormat(true);

                            doNotRenderObject(states[i]);

                            space = (IntegerSpace)states[i].Type.ValueSpace;

                            if (space.IsRanged())
                            {
                                _format[i].Maximum = space.GetMaximum().GetIntValue();
                                _format[i].Minimum = space.GetMinimum().GetIntValue();
                            }
                            else
                            {
                                _format[i].Maximum = Int32.MaxValue;
                                _format[i].Minimum = 0;
                            }

                            if (space.IsIncremented())
                            {
                                _format[i].Increment = space.GetIncrement().GetIntValue();
                            }
                        }
                    }

                    _timeControl = new TimeEditor(_format);
                    _setTime     = new SetControlTime(this.SetEditorFromMultiple);
                    ((TimeEditor)_timeControl).TimeChanged += new EventHandler(this.MultipleTimeEditorChanged);
                }

                if (_timeControl != null)
                {
                    if (hourState != null)
                    {
                        hourState.ValueChangedEvent  += new PUC.ApplianceState.ValueChangedHandler(this.ValueChanged);
                        hourState.EnableChangedEvent += new PUC.ApplianceObject.EnableChangedHandler(this.EnableChanged);
                    }

                    if (minState != null)
                    {
                        minState.ValueChangedEvent  += new PUC.ApplianceState.ValueChangedHandler(this.ValueChanged);
                        minState.EnableChangedEvent += new PUC.ApplianceObject.EnableChangedHandler(this.EnableChanged);
                    }

                    if (secState != null)
                    {
                        secState.ValueChangedEvent  += new PUC.ApplianceState.ValueChangedHandler(this.ValueChanged);
                        secState.EnableChangedEvent += new PUC.ApplianceObject.EnableChangedHandler(this.EnableChanged);
                    }

                    if (fracState != null)
                    {
                        fracState.ValueChangedEvent  += new PUC.ApplianceState.ValueChangedHandler(this.ValueChanged);
                        fracState.EnableChangedEvent += new PUC.ApplianceObject.EnableChangedHandler(this.EnableChanged);
                    }
                }
            }

            if (_timeControl != null)
            {
                GetControl().Controls.Add(_timeControl);
                _timeControl.Location = new System.Drawing.Point(0, 0);
                _timeControl.Size     = GetControl().Size;
                _control.Resize      += new EventHandler(this.Resized);
            }
        }