コード例 #1
0
ファイル: TextItText.cs プロジェクト: zhujingcheng/CP3
        /// <summary>
        /// updates longest_line_width_ to show the longest line width by iterating through
        /// all of the lines and finding the maximum. It is inefficient, but is also the safest method, and allows
        /// for the smallest amount of books. Since we won't be writing epics here, efficiency isn't incredibly important
        /// anyway.
        /// </summary>
        private void UpdateLongestLine()
        {
            ///change size of the TextItBox to reflect the change to the textut
            TextItBox parent = (TextItBox)this.Parent;

            if (parent == null)
            {
                return;
            }

            int limit = parent.viewer_.SlideWidth - kXMargin_ - parent.Location.X;

            for (int i = 0; i < this.Lines.Length; i++)
            {
                int width = TextRenderer.MeasureText(this.Lines[i], this.Font).Width;
                if (width > longest_line_width_)
                {
                    if (width < limit)
                    {
                        longest_line_width_ = width;
                    }
                    else
                    {
                        longest_line_width_ = limit;
                    }
                    index_of_longest_line_ = i;
                }
            }
            parent.SaveLongestWidthToSheet();
        }
コード例 #2
0
ファイル: TextItText.cs プロジェクト: zhujingcheng/CP3
        protected override void OnGotFocus(EventArgs e)
        {
            base.OnGotFocus(e);
            TextItBox parent = (TextItBox)this.Parent;

            parent.BringToFront();
        }
コード例 #3
0
ファイル: TextItText.cs プロジェクト: zhujingcheng/CP3
        /// <summary>
        /// when we change text, we need to check if we need to change the dimensions of the box.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnTextChanged(EventArgs e)
        {
            base.OnTextChanged(e);
            ///change size of the TextItBox to reflect the change to the textut
            TextItBox parent = (TextItBox)this.Parent;

            if (parent == null)
            {
                return;
            }

            ///update the width of text box when first typing
            UpdateWidth();
            ///update the height of text box when typing and font changing
            UpdateHeight();

            parent.SaveTextToSheet();
        }
コード例 #4
0
        /// <summary>
        /// Constructs a new TextItBox at the specified point.
        /// </summary>
        /// <param name="p"></param>
        public TextItText(Point p, TextItBox par)
        {
            InitializeComponent();
            this.Location = p;
            this.BorderStyle = BorderStyle.None;
            this.MaxLength = 2000;
            this.Parent = par;

                        //Attatch property listeners to the LightColor NATALIE - had to make viewer and presenter model public
            this.m_LightColorListener = new EventQueue.PropertyEventDispatcher(new ControlEventQueue(this)/*NATALIEthis.m_EventQueue*/,
                new PropertyEventHandler(this.OnLightColorChanged));
            using (Synchronizer.Lock(((PresentItBox)(par)).viewer_.presenter_model_.SyncRoot)) {
                using (Synchronizer.Lock(((PresentItBox)(par)).viewer_.presenter_model_.ViewerState.SyncRoot)) {
                    ((PresentItBox)(par)).viewer_.presenter_model_.ViewerState.Changed["UseLightColorSet"].Add(this.m_LightColorListener.Dispatcher);
                }
            }
            this.m_LightColorListener.Dispatcher(this, null);

            this.Focus();
        }
コード例 #5
0
ファイル: TextItText.cs プロジェクト: zhujingcheng/CP3
        /// <summary>
        /// Constructs a new TextItBox at the specified point.
        /// </summary>
        /// <param name="p"></param>
        public TextItText(Point p, TextItBox par)
        {
            InitializeComponent();
            this.Location    = p;
            this.BorderStyle = BorderStyle.None;
            this.MaxLength   = 2000;
            this.Parent      = par;

            //Attatch property listeners to the LightColor NATALIE - had to make viewer and presenter model public
            this.m_LightColorListener = new EventQueue.PropertyEventDispatcher(new ControlEventQueue(this) /*NATALIEthis.m_EventQueue*/,
                                                                               new PropertyEventHandler(this.OnLightColorChanged));
            using (Synchronizer.Lock(((PresentItBox)(par)).viewer_.presenter_model_.SyncRoot)) {
                using (Synchronizer.Lock(((PresentItBox)(par)).viewer_.presenter_model_.ViewerState.SyncRoot)) {
                    ((PresentItBox)(par)).viewer_.presenter_model_.ViewerState.Changed["UseLightColorSet"].Add(this.m_LightColorListener.Dispatcher);
                }
            }
            this.m_LightColorListener.Dispatcher(this, null);

            this.Focus();
        }
コード例 #6
0
ファイル: TextItText.cs プロジェクト: zhujingcheng/CP3
        private void UpdateWidth()
        {
            ///change size of the TextItBox to reflect the change to the textut
            TextItBox parent = (TextItBox)this.Parent;

            if (parent == null)
            {
                return;
            }

            if (width_accommodate_)
            {
                ///get the new length of the longest line.
                UpdateLongestLine();
                ///the largest line width in the textbox
                int largest_width = longest_line_width_ + kXMargin_;

                if (largest_width > this.Width)
                {
                    this.Width   = largest_width;
                    parent.Width = this.Width;
                }
            }
        }
コード例 #7
0
            /// <summary>
            /// When we create a TextSheetModel, make sure to add the appropriate TextItBox,
            /// assuming the textsheetmodel is editable.
            /// </summary>
            /// <param name="index"></param>
            /// <param name="member"></param>
            /// <returns></returns>
            protected override object SetUpMember(int index, object member)
            {
                if(member is TextSheetModel){
                    ///we are creating a textsheetmodel
                    TextSheetModel t_sheet = (TextSheetModel) member;

                    ///Initialize the Textitbox
                    bool is_editable;

                    using (Synchronizer.Lock(t_sheet)) {
                         is_editable= t_sheet.IsEditable;
                    }
                    if (is_editable) {
                        TextItBox t;
                        ///the textsheet is editable, so we need to add a control.
                        t = new TextItBox(t_sheet, slide_viewer_);
                        slide_viewer_.SuspendLayout();
                        slide_viewer_.Controls.Add(t);
                        t.BringToFront();
                        slide_viewer_.ResumeLayout();
                        t.Focus();
                        return t;
                    }
                }
                return null;
            }
コード例 #8
0
ファイル: TextItText.cs プロジェクト: zhujingcheng/CP3
        private void UpdateHeight()
        {
            ///change size of the TextItBox to reflect the change to the textut
            TextItBox parent = (TextItBox)this.Parent;

            if (parent == null)
            {
                return;
            }

            /// longest_line_with_ should be a positive value.
            if (longest_line_width_ <= 0)
            {
                return;
            }

            ///adapt height of box
            int new_height = this.FontHeight * (this.Lines.Length + 1);
            // deal with word wrap
            int si = 0, sp = 0, nsp = 0, width = 0, w = 0;

            for (int i = 0; i < this.Lines.Length; i++)
            {
                while (si < this.Lines[i].Length && (nsp = this.Lines[i].IndexOf(" ", si)) != -1)
                {
                    while (width > longest_line_width_)
                    {
                        width      -= longest_line_width_;
                        new_height += this.FontHeight;
                    }
                    w = TextRenderer.MeasureText(this.Lines[i].Substring(si, nsp - si + 1), this.Font).Width;
                    if (width + w > longest_line_width_)
                    {
                        new_height += this.FontHeight;
                        width       = w;
                        sp          = nsp + 1;
                    }
                    else
                    {
                        width = TextRenderer.MeasureText(this.Lines[i].Substring(sp, nsp - sp + 1), this.Font).Width;
                    }

                    si = nsp + 1;
                }
                if (sp < this.Lines[i].Length)
                {
                    width = TextRenderer.MeasureText(this.Lines[i].Substring(sp), this.Font).Width;
                    while (width > longest_line_width_)
                    {
                        width      -= longest_line_width_;
                        new_height += this.FontHeight;
                    }
                }
            }

            if (new_height > this.Height)
            {
                this.Height   = new_height + 20;
                parent.Height = this.Height;
            }
        }