Skip to content

Commit

Permalink
worky 2
Browse files Browse the repository at this point in the history
  • Loading branch information
murrty committed Sep 25, 2022
1 parent 865aa67 commit 15c998f
Show file tree
Hide file tree
Showing 19 changed files with 273 additions and 112 deletions.
1 change: 0 additions & 1 deletion Controls/BetterFolderBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* Improvements are always welcome :)
*
* modified by murrty
*
*/


Expand Down
4 changes: 3 additions & 1 deletion Controls/ExtendedLinkLabel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace murrty.controls;
/* ExtendedLinkLabel by murrty */

namespace murrty.controls;

using System;
using System.ComponentModel;
Expand Down
7 changes: 5 additions & 2 deletions Controls/ExtendedProgressBar.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace murrty.controls;
// Derived from wyDay's progress bar.
/* ExtendedProgressBar by murrty
Derived from wyDay's progress bar with heavy modifications.
*/

namespace murrty.controls;

using System.ComponentModel;
using System.ComponentModel.Design;
Expand Down
124 changes: 110 additions & 14 deletions Controls/ExtendedRichTextBox.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
namespace murrty.controls;
/* ExtendedRichTextBox by murrty */

namespace murrty.controls;

using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using murrty.controls.natives;

class ExtendedRichTextBox : RichTextBox {
public class ExtendedRichTextBox : RichTextBox {
private bool fAutoWordSelection = false;

[Category("Behavior")]
Expand All @@ -29,20 +32,85 @@ public bool ViewOnly {
get; set;
} = false;

[DefaultValue(false)]
public new bool HideSelection {
get => base.HideSelection;
set => base.HideSelection = value;
}

public ExtendedRichTextBox() {
base.HideSelection = false;
}

private const int WM_SETFOCUS = 0x07;
private const int WM_ENABLE = 0x0A;
private const int WM_SETCURSOR = 0x20;

private const int WM_USER = 0x400;
private const int WM_SETREDRAW = 0x000B;
private const int EM_GETEVENTMASK = WM_USER + 59;
private const int EM_SETEVENTMASK = WM_USER + 69;
private const int EM_GETSCROLLPOS = WM_USER + 221;
private const int EM_SETSCROLLPOS = WM_USER + 222;

private System.Drawing.Point _ScrollPoint;
private bool _Painting = true;
private nint _EventMask;
private int _SuspendIndex = 0;
private int _SuspendLength = 0;
private SCROLLINFO ScrollPos;

[DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)]
private static extern bool GetScrollInfo(IntPtr hwnd, SBOrientation fnBar, ref SCROLLINFO lpsi);

/// <summary>
/// Appends text to the rich text box, scrolling to the bottom when necessary.
/// </summary>
/// <param name="text">Text to append.</param>
public new void AppendText(string text) {
try {
this.Text += text;
NativeMethods.SendMessage(this.Handle, 0x115, 7, 0);
public void AppendAndTryScroll(string text) {
ScrollPos = new SCROLLINFO() {
cbSize = Marshal.SizeOf<SCROLLINFO>(),
fMask = ScrollInfoMask.SIF_ALL
};
if (GetScrollInfo(this.Handle, SBOrientation.SB_VERT, ref ScrollPos) && ScrollPos.ScrolledToBottom) {
AppendText(text);
}
else {
SuspendPaint();
AppendText(text);
ResumePaint();
}
}

public void AppendAndTryScrollNewLine(string text) => AppendAndTryScroll("\r\n" + text);

public void ScrollToBottom() => ScrollToBottom(true);

public void ScrollToBottom(bool UpdateSelection) {
NativeMethods.SendMessage(this.Handle, 0x115, 7, 0);
if (UpdateSelection)
SelectionStart = Text.Length;
}

private void SuspendPaint() {
if (_Painting) {
_SuspendIndex = this.SelectionStart;
_SuspendLength = this.SelectionLength;
NativeMethods.SendMessage(this.Handle, EM_GETSCROLLPOS, 0, ref _ScrollPoint);
NativeMethods.SendMessage(this.Handle, WM_SETREDRAW, 0, 0);
_EventMask = NativeMethods.SendMessage(this.Handle, EM_GETEVENTMASK, 0, 0);
_Painting = false;
}
}
private void ResumePaint() {
if (!_Painting) {
this.Select(_SuspendIndex, _SuspendLength);
NativeMethods.SendMessage(this.Handle, EM_SETSCROLLPOS, 0, ref _ScrollPoint);
NativeMethods.SendMessage(this.Handle, EM_SETEVENTMASK, 0, _EventMask);
NativeMethods.SendMessage(this.Handle, WM_SETREDRAW, 1, IntPtr.Zero);
_Painting = true;
this.Invalidate();
}
catch { }
}

protected override void OnMouseDown(MouseEventArgs e) {
Expand All @@ -53,6 +121,7 @@ protected override void OnMouseDown(MouseEventArgs e) {
}
}

[System.Diagnostics.DebuggerStepThrough]
protected override void WndProc(ref Message m) {
switch (m.Msg) {
case WM_SETFOCUS when ViewOnly:
Expand All @@ -61,14 +130,41 @@ protected override void WndProc(ref Message m) {
m.Result = IntPtr.Zero;
} return;

case WM_SETCURSOR: {
if (Cursor == Cursors.Hand) {
NativeMethods.SetCursor(Consts.SystemHand);
m.Result = IntPtr.Zero;
return;
}
case WM_SETCURSOR when Cursor == Cursors.Hand: {
NativeMethods.SetCursor(Consts.SystemHand);
m.Result = IntPtr.Zero;
} break;

default: {
base.WndProc(ref m);
} break;
}
base.WndProc(ref m);
}
}
[Flags]
internal enum ScrollInfoMask : uint {
SIF_RANGE = 0x1,
SIF_PAGE = 0x2,
SIF_POS = 0x4,
SIF_DISABLENOSCROLL = 0x8,
SIF_TRACKPOS = 0x10,
SIF_ALL = (SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS),
}
[Flags]
internal enum SBOrientation : int {
SB_HORZ = 0x0,
SB_VERT = 0x1,
SB_CTL = 0x2,
SB_BOTH = 0x3
}
[Serializable, StructLayout(LayoutKind.Sequential)]
internal struct SCROLLINFO {
public int cbSize; // (uint) int is because of Marshal.SizeOf
public ScrollInfoMask fMask;
public int nMin;
public int nMax;
public uint nPage;
public int nPos;
public int nTrackPos;
public bool ScrolledToBottom => nPage + nPos >= nMax;
}
4 changes: 3 additions & 1 deletion Controls/ExtendedTextBox.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace murrty.controls;
/* ExtendedTextBox by murrty */

namespace murrty.controls;

using System;
using System.ComponentModel;
Expand Down
4 changes: 3 additions & 1 deletion Controls/ExtendedWebClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace murrty.classcontrols;
/* ExtendedWebClient by murrty */

namespace murrty.classcontrols;

using System;
using System.ComponentModel;
Expand Down
11 changes: 9 additions & 2 deletions Controls/Natives/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@ internal static class NativeMethods {
/// <param name="lParam">Additional message-specific information.</param>
/// <returns>The return value specifies the result of the message processing; it depends on the message sent.</returns>
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
internal static extern int SendMessage(
internal static extern nint SendMessage(
[In] nint hWnd,
[In] uint wMsg,
[In] nint wMsg,
[In] nint wParam,
[In] nint lParam);

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
internal static extern nint SendMessage(
[In] nint hWnd,
[In] nint wMsg,
[In] nint wParam,
[In] ref System.Drawing.Point lParam);

/// <summary>
/// Loads the specified cursor resource from the executable (.EXE) file associated with an application instance.
/// This function has been superseded by the LoadImage function.
Expand Down
4 changes: 3 additions & 1 deletion Controls/SplitButton.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace murrty.controls;
/* SplitButton by murrty, originally based on another SplitButton from somewhere I don't remember where. */

namespace murrty.controls;

using System.ComponentModel;
using System.Windows.Forms;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion youtube-dl-gui-updater/Forms/frmUpdaterInvalidData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ public frmUpdaterInvalidData() {
this.Shown += (s, e) => System.Media.SystemSounds.Hand.Play();
}
private void LoadLanguage() {

this.Text = Language.frmUpdaterInvalidData;
lbUpdaterInvalidData.Text = Language.lbUpdaterInvalidData;
btnUpdaterInvalidDataUpdateLatest.Text = Language.btnUpdaterInvalidDataUpdateLatest;
btnUpdaterInvalidDataUpdatePreRelease.Text = Language.btnUpdaterInvalidDataUpdatePreRelease;
btnUpdaterInvalidDataDoNotUpdate.Text = Language.btnUpdaterInvalidDataDoNotUpdate;
}
}
Loading

0 comments on commit 15c998f

Please sign in to comment.