Exemple #1
0
        /// <summary>
        /// Applies one step of the async highlighting against the main scheme.
        /// </summary>
        /// <returns>Whether another step should be called.</returns>
        protected bool StepHiliteMain(AsyncHighlightState state)
        {
            if (!state.Enum.MoveNext())
            {
                state.ActualSearchHits = state.Words; // As the main scheme has succeeded, the original word list is the same as the final one
                return(false);                        // Over!
            }

            // Get the current word
            WordPtr word = (WordPtr)state.Enum.Current;

            if (word.StartOffset < 0)
            {
                return(StartHiliteBackup(state));                  // Fallback to the backup scheme
            }
            // Choose a color for highlighting this word
            state.PickNextColor(word.Original);

            // Select the supposed search hit location
            Select(word.StartOffset, word.Text.Length);

            // Check whether we've selected the proper thing
            if (String.Compare(SelectedText, word.Text, true, CultureInfo.InvariantCulture) != 0)
            {
                Trace.WriteLine(String.Format("Main highlighting expected to find \"{0}\" but got \"{1}\", aborting.", word.Text, SelectedText), "[JRTB]");
                return(StartHiliteBackup(state));                  // Fallback to the backup scheme
            }

            // Apply the coloring!!
            Win32Declarations.SendMessage(Handle, EditMessage.SETCHARFORMAT, SCF.SELECTION, ref state.Fmt);

            return(true);            // Call more
        }
Exemple #2
0
        /// <summary>
        /// Calculates the rectangle needed for rendering the text string.
        /// </summary>
        /// <param name="control">Control to which the text will be rendered.
        /// It's used for getting the device context and setting the initial text bounds
        /// (the latter is ignored in the single-line case).</param>
        /// <param name="text">Text to be rendered.</param>
        /// <param name="font">Font in which the text will be rendered.</param>
        /// <param name="bounds">Initial size that should be expanded to fit the text.</param>
        /// <param name="dtf">Additional parameters that control rendering of the text.</param>
        /// <returns>Size of the text's bounding rectangle.</returns>
        public static Size GetTextSize(Control control, string text, Font font, Size bounds, DrawTextFormatFlags dtf)
        {
            using (Graphics g = control.CreateGraphics())
            {
                IntPtr hdc = g.GetHdc();
                try
                {
                    IntPtr hFont   = _fontCache.GetHFont(font);
                    IntPtr oldFont = Win32Declarations.SelectObject(hdc, hFont);
                    RECT   rc      = new RECT(0, 0, bounds.Width, bounds.Height);

                    Win32Declarations.DrawText(hdc, text, text.Length, ref rc,
                                               dtf | DrawTextFormatFlags.DT_CALCRECT);

                    int height = rc.bottom - rc.top;
                    //height += 1;
                    Size sz = new Size(rc.right - rc.left, height);

                    Win32Declarations.SelectObject(hdc, oldFont);

                    return(sz);
                }
                finally
                {
                    g.ReleaseHdc(hdc);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Renders some text to a graphics device.
        /// </summary>
        /// <param name="graphics">Graphics device to render the text into.</param>
        /// <param name="text">Text to render.</param>
        /// <param name="rect">Bounding rectangle for the text to fit into.</param>
        /// <param name="font">Font in which the text is rendered.</param>
        /// <param name="color">Text color.</param>
        /// <param name="dtf">Formatting flags.</param>
        public static void DrawText(Graphics graphics, string text, Rectangle rect, Font font, Color color, DrawTextFormatFlags dtf)
        {
            IntPtr hdc = graphics.GetHdc();

            try
            {
                // Font
                IntPtr hFont   = _fontCache.GetHFont(font);
                IntPtr oldFont = Win32Declarations.SelectObject(hdc, hFont);

                // Bounding rectangle
                RECT rc = new RECT(rect.Left, rect.Top, rect.Right, rect.Bottom);

                // Color
                int            textColor = Win32Declarations.ColorToRGB(color);
                int            oldColor  = Win32Declarations.SetTextColor(hdc, textColor);
                BackgroundMode oldMode   = Win32Declarations.SetBkMode(hdc, BackgroundMode.TRANSPARENT);

                // Render the text
                Win32Declarations.DrawText(hdc, text, text.Length, ref rc, dtf);

                // Do deinit
                Win32Declarations.SetBkMode(hdc, oldMode);
                Win32Declarations.SetTextColor(hdc, oldColor);
                Win32Declarations.SelectObject(hdc, oldFont);
            }
            finally
            {
                graphics.ReleaseHdc(hdc);
            }
        }
Exemple #4
0
        internal void CreateHandle()
        {
            CreateParams cp = new CreateParams();

            cp.Parent    = _ownerControl.Handle;
            cp.ClassName = TOOLTIP_CLASS;
            unchecked
            {
                cp.Style = (int)Win32Declarations.WS_POPUP | Win32Declarations.TTS_NOFADE | Win32Declarations.TTS_NOPREFIX;
            }
            cp.ExStyle = 0;
            cp.Caption = null;

            CreateHandle(cp);

            Win32Declarations.SetWindowPos(this.Handle, (IntPtr)Win32Declarations.HWND_TOPMOST, 0, 0, 0, 0, 19);

            TOOLINFOCB ti = new TOOLINFOCB();

            ti.cbSize       = Marshal.SizeOf(typeof(TOOLINFO));
            ti.flags        = Win32Declarations.TTF_IDISHWND | Win32Declarations.TTF_SUBCLASS | Win32Declarations.TTF_TRANSPARENT;
            ti.hwnd         = _ownerControl.Handle;
            ti.uId          = _ownerControl.Handle;
            ti.textCallback = Win32Declarations.LPSTR_TEXTCALLBACK;

            if (Win32Declarations.SendMessage(Handle, Win32Declarations.TTM_ADDTOOLW, 0, ref ti) == 0)
            {
                throw new Exception("Failed to add tool");
            }

            Win32Declarations.SendMessage(Handle, Win32Declarations.TTM_ACTIVATE, (IntPtr)1, IntPtr.Zero);
        }
Exemple #5
0
        /// <summary><seealso cref="OptimalWidth"/>
        /// Calculates the preferred width on a per-tab basis.
        /// </summary>
        private void CalcPreferredWidth(TabBarTab tab)
        {
            IntPtr hdc = (IntPtr)0;

            try
            {
                if (IsHandleCreated)
                {
                    hdc = Win32Declarations.GetDC(Handle);
                }
                else
                {
                    hdc = Win32Declarations.GetDC((IntPtr)0);
                }

                IntPtr oldFont = Win32Declarations.SelectObject(hdc, _fontHandle);
                Win32Declarations.SelectObject(hdc, oldFont);
                SIZE sz = new SIZE();
                Win32Declarations.GetTextExtentPoint32(hdc, tab.Text, tab.Text.Length, ref sz);

                int prefWidth = sz.cx + 2 * 8;
                tab.PreferredWidth = Math.Max(50, prefWidth);
                tab.Width          = tab.PreferredWidth;
            }
            finally
            {
                if (hdc != (IntPtr)0)
                {
                    Win32Declarations.ReleaseDC(Handle, hdc);
                    hdc = (IntPtr)0;
                }
            }
        }
Exemple #6
0
        private void ProcessWmNcPaint(ref Message message)
        {
            // GetDCEx usually returns 0, so just get the windows DC
            var hdc = GetDCEx(message.HWnd, message.WParam, DCX_WINDOW | DCX_INTERSECTRGN);

            if (hdc == IntPtr.Zero)
            {
                hdc = GetWindowDC(message.HWnd);
            }

            try
            {
                using (var graphics = Graphics.FromHdc(hdc))
                {
                    var windowRectangle = new Rectangle(0, 0, Width, Height);
                    var clientRectangle = OnCalculateNonClientSize(windowRectangle);
                    graphics.ExcludeClip(clientRectangle);
                    OnPaintNonClient(graphics, windowRectangle);
                }
            }
            finally
            {
                Win32Declarations.ReleaseDC(message.HWnd, hdc);
            }
        }
Exemple #7
0
        /// <summary>
        /// Draws the formatted string on a given graphics, clipping the text by the
        /// ClipBounds set on the Graphics.
        /// </summary>
        /// <param graphics device context to draw the string in.</param>
        /// <param name="rect">The rectangle where the string is drawn.</param>
        /// <exception cref="ArgumentNullException"><i>g</i> is null</exception>
        public void DrawClipped(Graphics graphics, Rectangle rect)
        {
            RectangleF rcClip = graphics.ClipBounds;
            IntPtr     hdc    = graphics.GetHdc();

            try
            {
                IntPtr clipRgn = Win32Declarations.CreateRectRgn(0, 0, 0, 0);
                if (Win32Declarations.GetClipRgn(hdc, clipRgn) != 1)
                {
                    Win32Declarations.DeleteObject(clipRgn);
                    clipRgn = IntPtr.Zero;
                }
                Win32Declarations.IntersectClipRect(hdc, (int)rcClip.Left, (int)rcClip.Top,
                                                    (int)rcClip.Right, (int)rcClip.Bottom);

                Draw(hdc, rect);

                Win32Declarations.SelectClipRgn(hdc, clipRgn);
                Win32Declarations.DeleteObject(clipRgn);
            }
            finally
            {
                graphics.ReleaseHdc(hdc);
            }
        }
Exemple #8
0
        public Size MeasureText(Graphics g, string text, Font font, int maxWidth)
        {
            Size   result;
            IntPtr hdc = g.GetHdc();

            try
            {
                IntPtr hFont   = _fontCache.GetHFont(font);
                IntPtr oldFont = Win32Declarations.SelectObject(hdc, hFont);
                SIZE   sz      = new SIZE();
                Win32Declarations.GetTextExtentPoint32(hdc, text, text.Length, ref sz);
                if (sz.cx < maxWidth)
                {
                    result = new Size(sz.cx, sz.cy);
                }
                else
                {
                    RECT rc     = new RECT(0, 0, maxWidth, Screen.PrimaryScreen.Bounds.Height);
                    int  height = Win32Declarations.DrawText(hdc, text, text.Length, ref rc, DrawTextFormatFlags.DT_CALCRECT | DrawTextFormatFlags.DT_WORDBREAK);
                    result = new Size(maxWidth, height);
                }

                Win32Declarations.SelectObject(hdc, oldFont);
            }
            finally
            {
                g.ReleaseHdc(hdc);
            }
            return(result);
        }
Exemple #9
0
        // TODO: remove?

/*
 *          private void HighlightRtfWords( WordPtr[] words )
 *          {
 *          // we use plain text for indexing, so the offsets will not match =>
 *          // use token-based highlighting
 *
 *          _wordsToHighlight = words;
 *          _lastHighlightOffset = 0;
 *          for( _lastHighlightIndex = 0; _lastHighlightIndex < words.Length; _lastHighlightIndex++ )
 *          {
 *              // if there are too many words to highlight - use async highlighting, in
 *              // order not to lock up the UI for too long
 *              if ( _lastHighlightIndex == 5 )
 *              {
 *                  _wordHighlightTimer.Start();
 *                  break;
 *              }
 *              HighlightNextWord();
 *          }
 *      }
 */

        private void HighlightNextWord()
        {
            if (_wordsToHighlight [_lastHighlightIndex].Section != DocumentSection.BodySection)
            {
                return;
            }

            int offset = _richTextBox.Find(_wordsToHighlight [_lastHighlightIndex].Text,
                                           _lastHighlightOffset, RichTextBoxFinds.WholeWord);

            if (offset >= 0)
            {
                int highlightLength = _wordsToHighlight [_lastHighlightIndex].Text.Length;
                _lastHighlightOffset = offset + highlightLength;

                _richTextBox.Select(offset, highlightLength);

                CHARFORMAT2 fmt = new CHARFORMAT2();
                fmt.cbSize      = Marshal.SizeOf(fmt);
                fmt.dwMask      = CFM.BACKCOLOR | CFM.COLOR;
                fmt.crBackColor = ColorTranslator.ToWin32(SystemColors.Highlight);
                fmt.crTextColor = ColorTranslator.ToWin32(SystemColors.HighlightText);

                Win32Declarations.SendMessage(_richTextBox.Handle, EditMessage.SETCHARFORMAT, SCF.SELECTION, ref fmt);
            }
        }
Exemple #10
0
        public TreeNode GetNodeAt(TreeView treeView, Point point)
        {
            TVHITTESTINFO hti = new TVHITTESTINFO();

            hti.pt = new POINT(point);
            Win32Declarations.SendMessage(treeView.Handle, TreeViewMessage.TVM_HITTEST, 0, ref hti);
            if ((hti.flags & TreeViewHitTestFlags.ONITEM) != 0)
            {
                return(TreeNode.FromHandle(treeView, hti.hItem));
            }
            if ((hti.flags & TreeViewHitTestFlags.ONITEMRIGHT) != 0)
            {
                using (Graphics g = treeView.CreateGraphics())
                {
                    IntPtr hdc = g.GetHdc();
                    try
                    {
                        TreeNode  node    = TreeNode.FromHandle(treeView, hti.hItem);
                        int       offset  = CalculateOffset(node);
                        Rectangle content = CalculateContentRectangle(node, hdc, offset);
                        if (content.Contains(point))
                        {
                            return(node);
                        }
                    }
                    finally
                    {
                        g.ReleaseHdc(hdc);
                    }
                }
            }

            return(null);
        }
Exemple #11
0
        /// <summary>
        /// Does the asynchronous highlighting step.
        /// </summary>
        private void StepHilite()
        {
            if (_stateHilite == null)
            {
                return;                 // Has been shut down
            }
            uint dwStart = Win32Declarations.GetTickCount();
            uint dwLimit = 222;             // Allow running for this much milliseconds continuously

            // Freeze the control
            Win32Declarations.SendMessage(Handle, Win32Declarations.WM_SETREDRAW, IntPtr.Zero, IntPtr.Zero);

            try
            {
                int nIterations;
                for (nIterations = 0; Win32Declarations.GetTickCount() - dwStart < dwLimit; nIterations++) // Work for some limited time
                {
                    if (!_stateHilite.StepHiliteDelegate(_stateHilite))                                    // Invoke the individual highlighting step
                    {                                                                                      // Highlighting Completed!
                        // Reset the status bar dials
                        _statuswriter.ClearStatus();
                        _statuswriter = null;

                        // Retrieve the values
                        _wordsSearchHits   = _stateHilite.ActualSearchHits;
                        _nCurrentSearchHit = -1;

                        // Deinitialize the hilite search
                        _stateHilite = null;

                        // Jump to the next search hit
                        GotoNextSearchHit(true, false);

                        // Invalidate
                        Win32Declarations.SendMessage(Handle, Win32Declarations.WM_SETREDRAW, (IntPtr)1, IntPtr.Zero);
                        Invalidate();

                        // Done!
                        Trace.WriteLine(String.Format("The JetRichTextBox has completed the async highlighting with {0} hits total.", (_wordsSearchHits != null ? _wordsSearchHits.Length.ToString() : "#ERROR#")), "[JRTB]");
                        return;
                    }
                }
                Trace.WriteLine(String.Format("The JetRichTextBox async highlighting has done {0} highlightings on this step.", nIterations), "[JRTB]");
            }
            finally
            {
                // Unfreeze the events and repaint
                Win32Declarations.SendMessage(Handle, Win32Declarations.WM_SETREDRAW, (IntPtr)1, IntPtr.Zero);
                if ((_stateHilite != null) && (Win32Declarations.GetTickCount() - _stateHilite.LastRepaintTime > 2000))                  // Repaint rarely
                {
                    Invalidate();
                    _stateHilite.LastRepaintTime = Win32Declarations.GetTickCount();
                }
            }

            // Requeue the rest of execution
            Application.DoEvents();             // Without this, the painting events won't occur
            Core.UserInterfaceAP.QueueJob("Highlight the search hits.", new MethodInvoker(StepHilite));
        }
Exemple #12
0
        private void DrawTab(Graphics g, int index)
        {
            Rectangle rc = GetTabRect(index);

            if (rc.IsEmpty)
            {
                return;
            }

            GraphicsPath gp = BuildBorderPath(rc);

            using ( gp )
            {
                if (index == _activeTabIndex)
                {
                    g.FillPath(GUIControls.ColorScheme.GetBrush(_colorScheme, "ResourceTypeTabs.ActiveBackground",
                                                                rc, SystemBrushes.Control), gp);
                }
                else
                {
                    g.FillPath(GUIControls.ColorScheme.GetBrush(_colorScheme, "ResourceTypeTabs.InactiveBackground",
                                                                rc, SystemBrushes.Control), gp);

                    Rectangle rcGradient = new Rectangle(rc.Left, rc.Bottom - 6, rc.Width, 6);
                    g.FillRectangle(GUIControls.ColorScheme.GetBrush(_colorScheme, "ResourceTypeTabs.InactiveBackgroundBottom",
                                                                     rcGradient, SystemBrushes.Control), rcGradient);
                }

                g.DrawPath(GUIControls.ColorScheme.GetPen(_colorScheme,
                                                          (index == _activeTabIndex) ? "PaneCaption.Border" : "ResourceTypeTabs.Border",
                                                          Pens.Black), gp);
            }

            string tabText = ((TabBarTab)_tabs [index]).Text;
            IntPtr hdc     = g.GetHdc();

            try
            {
                Color clrText = (index == _activeTabIndex)
                    ? GUIControls.ColorScheme.GetColor(_colorScheme, "ResourceTypeTabs.ActiveText", Color.Black)
                    : GUIControls.ColorScheme.GetColor(_colorScheme, "ResourceTypeTabs.InactiveText", Color.Black);
                int            oldColor  = Win32Declarations.SetTextColor(hdc, ColorTranslator.ToWin32(clrText));
                IntPtr         oldFont   = Win32Declarations.SelectObject(hdc, _fontHandle);
                BackgroundMode oldBkMode = Win32Declarations.SetBkMode(hdc, BackgroundMode.TRANSPARENT);

                RECT rect = Win32Declarations.RectangleToRECT(rc);
                Win32Declarations.DrawText(hdc, tabText, tabText.Length, ref rect,
                                           DrawTextFormatFlags.DT_CENTER | DrawTextFormatFlags.DT_VCENTER | DrawTextFormatFlags.DT_NOPREFIX |
                                           DrawTextFormatFlags.DT_END_ELLIPSIS | DrawTextFormatFlags.DT_SINGLELINE);

                Win32Declarations.SetBkMode(hdc, oldBkMode);
                Win32Declarations.SelectObject(hdc, oldFont);
                Win32Declarations.SetTextColor(hdc, oldColor);
            }
            finally
            {
                g.ReleaseHdc(hdc);
            }
        }
Exemple #13
0
        protected override void OnPaint(PaintEventArgs e)
        {
            // Paint background
            if (BackColor != Color.Transparent)
            {
                using (Brush brush = new SolidBrush(BackColor))
                    e.Graphics.FillRectangle(brush, ClientRectangle);
            }

            base.OnPaint(e);

            // Paint foreground
            IntPtr hdc = e.Graphics.GetHdc();

            try
            {
                IntPtr hFont   = _fontCache.GetHFont(_underline ? _underlineFont : Font);
                IntPtr oldFont = Win32Declarations.SelectObject(hdc, hFont);

                RECT rc        = new RECT(0, 0, Bounds.Width, Bounds.Height);
                int  textColor = Enabled
                    ? Win32Declarations.ColorToRGB(ForeColor)
                    : Win32Declarations.ColorToRGB(SystemColors.GrayText);

                int            oldColor = Win32Declarations.SetTextColor(hdc, textColor);
                BackgroundMode oldMode  = Win32Declarations.SetBkMode(hdc, BackgroundMode.TRANSPARENT);

                int postfixLeft = 0;
                if (_postfixText.Length > 0)
                {
                    Win32Declarations.DrawText(hdc, Text, Text.Length, ref rc,
                                               GetTextFormatFlags() | DrawTextFormatFlags.DT_CALCRECT);
                    postfixLeft = rc.right;
                }
                Win32Declarations.DrawText(hdc, Text, Text.Length, ref rc, GetTextFormatFlags());

                if (_postfixText.Length > 0)
                {
                    Win32Declarations.SetTextColor(hdc, ColorTranslator.ToWin32(Color.Black));
                    if (_underline)
                    {
                        Win32Declarations.SelectObject(hdc, _fontCache.GetHFont(Font));
                    }
                    rc.left  = postfixLeft;
                    rc.right = Bounds.Width;
                    Win32Declarations.DrawText(hdc, _postfixText, _postfixText.Length, ref rc, GetTextFormatFlags());
                }

                Win32Declarations.SetBkMode(hdc, oldMode);
                Win32Declarations.SetTextColor(hdc, oldColor);
                Win32Declarations.SelectObject(hdc, oldFont);
            }
            finally
            {
                e.Graphics.ReleaseHdc(hdc);
            }
        }
Exemple #14
0
        public static Bitmap ConvertIco2Bmp(Icon icon, Brush backBrush)
        {
            Bitmap bmp;

            // Declare the raw handles
            IntPtr hdcDisplay = IntPtr.Zero, hdcMem = IntPtr.Zero, hBitmap = IntPtr.Zero;

            try
            {
                // Get the display's Device Context so that the generated bitmaps were compatible
                hdcDisplay = Win32Declarations.CreateDC("DISPLAY", null, null, IntPtr.Zero);
                if (hdcDisplay == IntPtr.Zero)
                {
                    throw new Exception("Failed to get the display device context.");
                }

                // Create a pixel format compatible device context, and a bitmap to draw into using this context
                hdcMem = Win32Declarations.CreateCompatibleDC(hdcDisplay);
                if (hdcMem == IntPtr.Zero)
                {
                    throw new Exception("Could not cerate a compatible device context.");
                }
                hBitmap = Win32Declarations.CreateCompatibleBitmap(hdcDisplay, icon.Width, icon.Height);
                if (hBitmap == IntPtr.Zero)
                {
                    throw new Exception("Could not cerate a compatible offscreen bitmap.");
                }
                Win32Declarations.SelectObject(hdcMem, hBitmap);

                // Attach a GDI+ Device Context to the offscreen facility, and render the scene
                using (Graphics gm = Graphics.FromHdc(hdcMem))
                {
                    gm.FillRectangle(backBrush, 0, 0, icon.Width, icon.Height);
                    gm.DrawIcon(icon, 0, 0);
                }

                // Wrap the offscreen bitmap into a .NET bitmap in order to save it
                bmp = Image.FromHbitmap(hBitmap);
            }
            finally
            {
                // Cleanup the native resources in use
                if (hBitmap != IntPtr.Zero)
                {
                    Win32Declarations.DeleteObject(hBitmap);
                }
                if (hdcMem != IntPtr.Zero)
                {
                    Win32Declarations.DeleteDC(hdcMem);
                }
                if (hdcDisplay != IntPtr.Zero)
                {
                    Win32Declarations.DeleteDC(hdcDisplay);
                }
            }
            return(bmp);
        }
Exemple #15
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            base.OnDrawItem(e);
            e.DrawBackground();

            object    obj        = (e.Index >= 0) ? Items [e.Index] : null;
            IResource res        = obj as IResource;
            int       textOffset = 0;

            // don't apply indent when drawing the item in the combo box itself -
            // only for drop-down items
            if (e.Bounds.X != 3 && e.Bounds.Y != 3)
            {
                if (obj != null && _resourceIndents.Contains(obj))
                {
                    textOffset = (int)_resourceIndents [obj];
                }
            }
            string text = null;

            if (res != null)
            {
                int imageIndex = Core.ResourceIconManager.GetIconIndex(res);
                if (imageIndex >= 0 && imageIndex < Core.ResourceIconManager.ImageList.Images.Count)
                {
                    Core.ResourceIconManager.ImageList.Draw(e.Graphics, e.Bounds.X + textOffset, e.Bounds.Y, imageIndex);
                    textOffset += 18;
                }
                text = res.DisplayName;
            }
            else if (obj != null)
            {
                text        = obj.ToString();
                textOffset += 2;
            }
            else
            {
                text = "";
            }

            IntPtr hdc = e.Graphics.GetHdc();

            try
            {
                RECT           rc       = new RECT(e.Bounds.Left + textOffset, e.Bounds.Top, e.Bounds.Right, e.Bounds.Bottom);
                int            oldColor = Win32Declarations.SetTextColor(hdc, Win32Declarations.ColorToRGB(e.ForeColor));
                BackgroundMode oldMode  = Win32Declarations.SetBkMode(hdc, BackgroundMode.TRANSPARENT);
                Win32Declarations.DrawText(hdc, text, text.Length, ref rc, DrawTextFormatFlags.DT_NOPREFIX);
                Win32Declarations.SetBkMode(hdc, oldMode);
                Win32Declarations.SetTextColor(hdc, oldColor);
            }
            finally
            {
                e.Graphics.ReleaseHdc(hdc);
            }
        }
Exemple #16
0
        private static string DateToString(IResource res, int propID, int widthInChars)
        {
            DateTime dt = res.GetDateProp(propID);

            if (dt == DateTime.MinValue)
            {
                return(string.Empty);
            }

            if (dt.Hour == 0 && dt.Minute == 0 && dt.Second == 0)
            {
                return(dt.ToShortDateString());
            }

            DateTime today = DateTime.Today;
            TimeSpan ts    = today - dt.Date;

            string dateStr;

            if (ts.Days == 0)
            {
                dateStr = "Today";
            }
            else
            if (dt.Date.Year == today.Year && haveToShortenDateString(widthInChars))
            {
                byte iDate, iDayLZero;
                Win32Declarations.GetLocaleInfo(Win32Declarations.LOCALE_USER_DEFAULT,
                                                Win32Declarations.LOCALE_IDATE, out iDate, 1);
                Win32Declarations.GetLocaleInfo(Win32Declarations.LOCALE_USER_DEFAULT,
                                                Win32Declarations.LOCALE_IDAYLZERO, out iDayLZero, 1);

                string dayFormat   = (iDayLZero == '1') ? "dd" : "d";
                string monthFormat = "MMM";

                if (iDate == '0' || iDate == '2')
                {
                    dateStr = dt.ToString(monthFormat + /*"/"*/ " " + dayFormat);
                }
                else
                {
                    dateStr = dt.ToString(dayFormat + /*"/"*/ " " + monthFormat);
                }
            }
            else
            {
                dateStr = dt.ToShortDateString();
            }

            if (!_useShortDate)
            {
                dateStr += " " + TimeToStringWin32(dt);
            }

            return(dateStr);
        }
Exemple #17
0
        private Size MeasureText(IntPtr hdc, Font font, string text)
        {
            SIZE   sz      = new SIZE();
            IntPtr hFont   = _fontCache.GetHFont(font);
            IntPtr oldFont = Win32Declarations.SelectObject(hdc, hFont);

            Win32Declarations.GetTextExtentPoint32(hdc, text, text.Length, ref sz);
            Win32Declarations.SelectObject(hdc, oldFont);
            return(new Size(sz.cx, sz.cy));
        }
Exemple #18
0
 public void Dispose()
 {
     foreach (IntPtr fontHandle in _fontHandleList)
     {
         Win32Declarations.DeleteObject(fontHandle);
     }
     _fontHandleList.Clear();
     _fontList.Clear();
     _fontFamilies.Clear();
 }
Exemple #19
0
        /**
         * Checks if a node is marked as drop-highlighted.
         */

        public bool IsNodeDropHighlighted(TreeNode node)
        {
            TVITEM item = new TVITEM();

            item.mask      = TreeViewItemFlags.HANDLE | TreeViewItemFlags.STATE;
            item.hItem     = node.Handle;
            item.stateMask = 0xFFFF;
            Win32Declarations.SendMessage(Handle, TreeViewMessage.TVM_GETITEMA, 0, ref item);
            return((item.state & (int)TreeViewItemState.DROPHILITED) != 0);
        }
Exemple #20
0
        public NodeCheckState GetNodeCheckState(TreeNode node)
        {
            TVITEM item = new TVITEM();

            item.mask      = TreeViewItemFlags.STATE | TreeViewItemFlags.HANDLE;
            item.stateMask = 0xFFFF;
            item.hItem     = node.Handle;
            Win32Declarations.SendMessage(Handle, TreeViewMessage.TVM_GETITEMA, 0, ref item);
            return((NodeCheckState)(item.state >> 12));
        }
Exemple #21
0
        internal void UpdateToolTip(Point pt)
        {
            JetListViewNode   node = _ownerControl.GetNodeAt(pt);
            JetListViewColumn col  = _ownerControl.GetColumnAt(pt);

            if (node != _lastToolTipNode || col != _lastToolTipColumn)
            {
                Hide();
                Win32Declarations.SendMessage(Handle, Win32Declarations.TTM_UPDATE, IntPtr.Zero, IntPtr.Zero);
            }
        }
Exemple #22
0
 /// <summary>
 /// Clean up any resources being used.
 /// </summary>
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (components != null)
         {
             components.Dispose();
         }
     }
     Win32Declarations.DeleteObject(_fontHandle);
     base.Dispose(disposing);
 }
Exemple #23
0
        public void EnableMinimize()
        {
            ControlBox    = true;
            MinimizeBox   = true;
            ShowInTaskbar = true;

            IntPtr hMenu  = Win32Declarations.GetSystemMenu(Handle, false);
            int    cItems = Win32Declarations.GetMenuItemCount(hMenu);

            Win32Declarations.RemoveMenu(hMenu, (uint)(cItems - 1), Win32Declarations.MF_BYPOSITION);
            Win32Declarations.RemoveMenu(hMenu, (uint)(cItems - 2), Win32Declarations.MF_BYPOSITION);
            Win32Declarations.DrawMenuBar(Handle);
        }
Exemple #24
0
        /// <summary>
        /// Get the size on the screen HDC
        /// </summary>
        /// <returns></returns>
        public Size GetSize()
        {
            IntPtr hDC = Win32Declarations.GetDC(IntPtr.Zero);

            try
            {
                return(GetSize(hDC).ToSize());
            }
            finally
            {
                Win32Declarations.ReleaseDC(IntPtr.Zero, hDC);
            }
        }
Exemple #25
0
        public Size MeasureText(string text, Font font)
        {
            IntPtr hdc = Win32Declarations.GetDC(IntPtr.Zero);

            try
            {
                return(MeasureText(hdc, font, text));
            }
            finally
            {
                Win32Declarations.ReleaseDC(IntPtr.Zero, hdc);
            }
        }
Exemple #26
0
 private int GetLocaleITimeMarkPosn()
 {
     try
     {
         byte iTime;
         Win32Declarations.GetLocaleInfo(Win32Declarations.LOCALE_USER_DEFAULT, Win32Declarations.LOCALE_ITIMEMARKPOSN, out iTime, 1);
         return(Int32.Parse(((char)iTime).ToString()));
     }
     catch
     {
         return(0);
     }
 }
Exemple #27
0
        /// <summary>
        /// Draws the formatted string on a given graphics
        /// </summary>
        /// <param name="hdc">The device context to draw the string in.</param>
        /// <param name="parameters">Text formatting parameters</param>
        /// <exception cref="ArgumentNullException"><i>g</i> is null</exception>
        /// <exception cref="ArgumentNullException"><i>font</i> is null</exception>
        public int Draw(IntPtr hdc, Rectangle rect, RichTextParameters parameters)
        {
            Font hFont = GetParametrizedFont(parameters);
            RECT rc    = new RECT();

            rc.left   = rect.Left;
            rc.top    = rect.Top;
            rc.bottom = rect.Bottom;

            RectangleF bounds;

            IntPtr         oldFont    = Win32Declarations.SelectObject(hdc, ourFontCache.GetHFont(hFont));
            int            oldColor   = Win32Declarations.SetTextColor(hdc, Win32Declarations.ColorToRGB(myStyle.ForegroundColor));
            int            oldBkColor = Win32Declarations.SetBkColor(hdc, Win32Declarations.ColorToRGB(myStyle.BackgroundColor));
            BackgroundMode oldBkMode  = Win32Declarations.SetBkMode(hdc, myStyle.BackgroundColor == Color.Transparent ? BackgroundMode.TRANSPARENT : BackgroundMode.OPAQUE);

            Win32Declarations.DrawText(hdc, PartText, PartText.Length, ref rc, DrawTextFormatFlags.DT_CALCRECT | DrawTextFormatFlags.DT_SINGLELINE | DrawTextFormatFlags.DT_NOPREFIX | DrawTextFormatFlags.DT_VCENTER | DrawTextFormatFlags.DT_NOCLIP);
            if (rc.bottom > rect.Bottom)
            {
                rc.bottom = rect.Bottom;
            }
            if (rc.right > rect.Right)
            {
                rc.right = rect.Right;
            }
            bounds = new RectangleF(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);

            Win32Declarations.DrawText(hdc, PartText, PartText.Length, ref rc, DrawTextFormatFlags.DT_SINGLELINE | DrawTextFormatFlags.DT_NOPREFIX | DrawTextFormatFlags.DT_VCENTER | DrawTextFormatFlags.DT_NOCLIP);

            Win32Declarations.SetBkMode(hdc, oldBkMode);
            Win32Declarations.SetBkColor(hdc, oldBkColor);
            Win32Declarations.SetTextColor(hdc, oldColor);
            Win32Declarations.SelectObject(hdc, oldFont);

            switch (myStyle.Effect)
            {
            case TextStyle.EffectStyle.StrikeOut:
                StrikeOut(hdc, bounds);
                break;

            case TextStyle.EffectStyle.StraightUnderline:
                UnderlineStraight(hdc, bounds);
                break;

            case TextStyle.EffectStyle.WeavyUnderline:
                UnderlineWeavy(hdc, bounds);
                break;
            }

            return(rc.right - rc.left);
        }
Exemple #28
0
        ///<Summary>
        /// Converts a time to a string using the Win32 API which correctly handles
        /// locale customization. (The default .NET APIs take only the base user locale
        /// and ignore the customizations.)
        ///</Summary>
        private static string TimeToStringWin32(DateTime dt)
        {
            SYSTEMTIME st = new SYSTEMTIME();

            st.Hour   = (short)dt.Hour;
            st.Minute = (short)dt.Minute;
            lock ( _timeStringBuilder )
            {
                _timeStringBuilder.Length = 0;
                Win32Declarations.GetTimeFormat(Win32Declarations.LOCALE_USER_DEFAULT,
                                                Win32Declarations.TIME_NOSECONDS, ref st, null, _timeStringBuilder, 255);
                return(_timeStringBuilder.ToString());
            }
        }
Exemple #29
0
        public void DrawFocusRect(Graphics g, Rectangle rc)
        {
            RECT   rect = new RECT(rc.Left, rc.Top, rc.Right, rc.Bottom);
            IntPtr hdc  = g.GetHdc();

            try
            {
                Win32Declarations.DrawFocusRect(hdc, ref rect);
            }
            finally
            {
                g.ReleaseHdc(hdc);
            }
        }
Exemple #30
0
        /// <summary>
        /// A kick for the MILCORE to query for the display settings again, this time with our improved data.
        /// </summary>
        private static void Execute_InvalidateMil()
        {
            // Send an update to all the top-level windows on our thread
            Win32Declarations.EnumWindows(delegate(IntPtr hWnd, IntPtr lParam)
            {
                int dwDummy;
                if (Win32Declarations.GetWindowThreadProcessId(hWnd, out dwDummy) == Kernel32Dll.GetCurrentThreadId())
                {
                    User32Dll.Helpers.SendMessageW(hWnd, WindowsMessages.WM_SETTINGCHANGE, (IntPtr)Win32Declarations.SPI_SETFONTSMOOTHING, IntPtr.Zero);
                    User32Dll.Helpers.SendMessageW(hWnd, WindowsMessages.WM_SETTINGCHANGE, (IntPtr)Win32Declarations.SPI_SETFONTSMOOTHINGTYPE, IntPtr.Zero);
                }

                return(true);                // Go on
            }, 0);
        }