Skip to content

Commit 7bbcf23

Browse files
committed
Squashed commit of the following:
commit e409c57 Author: 春风化雨细如丝 <[email protected]> Date: Sat Nov 5 09:54:20 2022 +0800 release 1.5.5.8 commit d0bf8eb Author: 春风化雨细如丝 <[email protected]> Date: Sat Nov 5 09:44:01 2022 +0800 😀 commit fdd26a8 Author: 春风化雨细如丝 <[email protected]> Date: Sat Nov 5 09:42:46 2022 +0800 😀 commit 7ee2dec Author: 春风化雨细如丝 <[email protected]> Date: Thu Nov 3 11:23:37 2022 +0800 🎅 commit 82df51b Author: 春风化雨细如丝 <[email protected]> Date: Thu Nov 3 11:23:03 2022 +0800 🎅 commit 303ee7d Author: 春风化雨细如丝 <[email protected]> Date: Thu Nov 3 11:20:24 2022 +0800 👀 commit 4d52dca Author: 春风化雨细如丝 <[email protected]> Date: Thu Nov 3 11:19:36 2022 +0800 👀
1 parent 3a8de3a commit 7bbcf23

File tree

146 files changed

+18840
-609
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+18840
-609
lines changed

BandObjectLib/BandObject.cs

+158-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of QTTabBar, a shell extension for Microsoft
22
// Windows Explorer.
3-
// Copyright (C) 2002-2010 Pavel Zolnikov, Quizo, Paul Accisano
3+
// Copyright (C) 2002-2022 Pavel Zolnikov, Quizo, Paul Accisano, indiff
44
//
55
// QTTabBar is free software: you can redistribute it and/or modify
66
// it under the terms of the GNU General Public License as published by
@@ -20,12 +20,23 @@
2020
using System.Drawing;
2121
using System.IO;
2222
using System.Runtime.InteropServices;
23+
using System.Text;
24+
using System.Threading;
2325
using System.Windows.Forms;
2426
using SHDocVw;
2527

2628

2729
namespace BandObjectLib {
28-
public class BandObject : UserControl, IDeskBand, IDockingWindow, IInputObject, IObjectWithSite, IOleWindow, IPersistStream {
30+
public class BandObject :
31+
UserControl,
32+
IDeskBand,
33+
IDockingWindow,
34+
IInputObject,
35+
IObjectWithSite,
36+
IOleWindow,
37+
IPersistStream,
38+
IDpiAwareObject
39+
{
2940
private Size _minSize = new Size(-1, -1);
3041
protected IInputObjectSite BandObjectSite;
3142
protected WebBrowserClass Explorer;
@@ -43,6 +54,9 @@ public class BandObject : UserControl, IDeskBand, IDockingWindow, IInputObject,
4354
protected const int E_NOTIMPL = -2147467263; // _HRESULT_TYPEDEF_(0x80004001L)
4455
protected const int E_FAIL = -2147467259; // _HRESULT_TYPEDEF_(0x80004005L)
4556

57+
// 判断是否启用日志,发布改为false, 调试启用. 默认是关闭的,在常规选项里面可以设置启用
58+
// public static bool ENABLE_LOGGER = true;
59+
4660
// We must subclass the rebar in order to fix a certain bug in
4761
// Windows 7.
4862
internal sealed class RebarBreakFixer : NativeWindow {
@@ -58,6 +72,7 @@ public RebarBreakFixer(IntPtr hwnd, BandObject parent) {
5872
}
5973

6074
protected override void WndProc(ref Message m) {
75+
// bandLog("WndProc");
6176
if(!Enabled) {
6277
base.WndProc(ref m);
6378
return;
@@ -67,9 +82,9 @@ protected override void WndProc(ref Message m) {
6782
// RBBS_BREAK set. Catch RB_SETBANDINFO to fix this.
6883
if(m.Msg == RB.SETBANDINFO) {
6984
if(MonitorSetInfo) {
85+
Util2.bandLog("msg SETBANDINFO");
7086
REBARBANDINFO pInfo = (REBARBANDINFO)Marshal.PtrToStructure(m.LParam, typeof(REBARBANDINFO));
7187
if(pInfo.hwndChild == parent.Handle && (pInfo.fMask & RBBIM.STYLE) != 0) {
72-
7388
// Ask the bar if we actually want a break.
7489
if(parent.ShouldHaveBreak()) {
7590
pInfo.fStyle |= RBBS.BREAK;
@@ -84,6 +99,7 @@ protected override void WndProc(ref Message m) {
8499
// Whenever a band is deleted, the RBBS_BREAKs come back!
85100
// Catch RB_DELETEBAND to fix it.
86101
else if(m.Msg == RB.DELETEBAND) {
102+
Util2.bandLog("msg DELETEBAND");
87103
int del = (int)m.WParam;
88104

89105
// Look for our band
@@ -140,10 +156,12 @@ protected bool BandHasBreak() {
140156
}
141157

142158
public virtual void CloseDW(uint dwReserved) {
159+
Util2.bandLog("CloseDW");
143160
fClosedDW = true;
144161
ShowDW(false);
145162
Dispose(true);
146163
if(Explorer != null) {
164+
// Util2.bandLog("ReleaseComObject Explorer");
147165
Marshal.ReleaseComObject(Explorer);
148166
Explorer = null;
149167
}
@@ -188,6 +206,7 @@ public virtual void GetBandInfo(uint dwBandID, uint dwViewMode, ref DESKBANDINFO
188206
}
189207

190208
private REBARBANDINFO GetRebarBand(int idx, int fMask) {
209+
Util2.bandLog("GetRebarBand");
191210
REBARBANDINFO info = new REBARBANDINFO();
192211
info.cbSize = Marshal.SizeOf(info);
193212
info.fMask = fMask;
@@ -220,13 +239,15 @@ protected virtual void OnExplorerAttached() {
220239
protected override void OnGotFocus(EventArgs e) {
221240
base.OnGotFocus(e);
222241
if((!fClosedDW && (BandObjectSite != null)) && IsHandleCreated) {
242+
Util2.bandLog("OnGotFocus");
223243
BandObjectSite.OnFocusChangeIS(this, 1);
224244
}
225245
}
226246

227247
protected override void OnLostFocus(EventArgs e) {
228248
base.OnLostFocus(e);
229249
if((!fClosedDW && (BandObjectSite != null)) && (ActiveControl == null)) {
250+
Util2.bandLog("OnLostFocus");
230251
BandObjectSite.OnFocusChangeIS(this, 0);
231252
}
232253
}
@@ -259,9 +280,8 @@ public virtual void SetSite(object pUnkSite) {
259280
Explorer = (WebBrowserClass)Marshal.CreateWrapperOfType(obj2 as IWebBrowser, typeof(WebBrowserClass));
260281
OnExplorerAttached();
261282
}
262-
catch {
263-
// (COMException exception) { // exception
264-
// QTUtility2.MakeErrorLog(exception, "MSG:" + exception.Message);
283+
catch (COMException exception) { // exception
284+
Util2.MakeErrorLog(exception, "QueryService CreateWrapperOfType");
265285
}
266286
}
267287
try {
@@ -270,8 +290,9 @@ public virtual void SetSite(object pUnkSite) {
270290
window.GetWindow(out ReBarHandle);
271291
}
272292
}
273-
catch (Exception ) // exc
293+
catch (Exception e) // exc
274294
{
295+
Util2.MakeErrorLog(e, "BandObject SetSite");
275296
// logger.Log(exc);
276297
}
277298
}
@@ -343,10 +364,136 @@ public virtual int GetSizeMax(out ulong pcbSize) {
343364
pcbSize = 0;
344365
return E_NOTIMPL;
345366
}
367+
368+
private void InitializeComponent()
369+
{
370+
this.SuspendLayout();
371+
//
372+
// BandObject
373+
//
374+
this.ForeColor = System.Drawing.Color.Black;
375+
this.Name = "BandObject";
376+
this.ResumeLayout(false);
377+
}
378+
379+
public int Dpi { get; private set; }
380+
381+
public float Scaling
382+
{
383+
get
384+
{
385+
return (float) this.Dpi / 96f;
386+
}
387+
}
388+
389+
public void NotifyDpiChanged(int oldDpi, int dpiNew)
390+
{
391+
Util2.bandLog("BandObject NotifyDpiChanged oldDpi " + oldDpi + " dpiNew " + dpiNew);
392+
this.Dpi = dpiNew;
393+
Action<Control> act = (Action<Control>) null;
394+
act = (Action<Control>)(
395+
control =>
396+
{
397+
for (var i = 0; i < control.Controls.Count; i++)
398+
{
399+
var cc = (Control) control.Controls[i];
400+
401+
if (cc is IDpiAwareObject)
402+
((IDpiAwareObject)cc).NotifyDpiChanged(oldDpi, dpiNew);
403+
act(cc);
404+
}
405+
}
406+
/*.ForEach<Control>((Action<Control>)
407+
(c =>
408+
{
409+
if (c is IDpiAwareObject )
410+
((IDpiAwareObject)c).NotifyDpiChanged(oldDpi, dpiNew);
411+
act(c);
412+
})*/
413+
);
414+
act((Control) this);
415+
this.OnDpiChanged(oldDpi, dpiNew);
416+
}
417+
418+
419+
protected virtual void OnDpiChanged(int oldDpi, int newDpi)
420+
{
421+
}
346422
}
347423

348-
/*internal class QTUtility2
424+
internal class Util2
349425
{
426+
private const bool ENABLE_LOGGER = true;
427+
428+
429+
public static void bandLog(string optional)
430+
{
431+
if (ENABLE_LOGGER)
432+
bandLog("bandLog", optional);
433+
}
434+
435+
436+
437+
public static void err(string optional)
438+
{
439+
if (ENABLE_LOGGER)
440+
bandLog("err", optional);
441+
442+
}
443+
444+
private static void writeStr(string path, StringBuilder formatLogLine)
445+
{
446+
using (StreamWriter writer = new StreamWriter(path, true))
447+
{
448+
writer.WriteLine(formatLogLine);
449+
}
450+
}
451+
452+
public static void bandLog(string level, string optional)
453+
{
454+
string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
455+
string appdataQT = Path.Combine(appdata, "QTTabBar");
456+
if (!Directory.Exists(appdataQT))
457+
{
458+
Directory.CreateDirectory(appdataQT);
459+
}
460+
461+
Process process = Process.GetCurrentProcess();
462+
var cThreadId = Thread.CurrentThread.ManagedThreadId;
463+
var currentThreadId = AppDomain.GetCurrentThreadId();
464+
465+
string path = Path.Combine(appdataQT, "bandLog.log");
466+
var formatLogLine = new StringBuilder();
467+
formatLogLine
468+
.Append("[")
469+
.Append(level)
470+
.Append("]");
471+
if (process != null)
472+
{
473+
formatLogLine
474+
.Append(" PID:")
475+
.Append(process.Id);
476+
}
477+
if (cThreadId != null)
478+
{
479+
formatLogLine
480+
.Append(" TID:")
481+
.Append(cThreadId);
482+
}
483+
else if (currentThreadId != null)
484+
{
485+
formatLogLine
486+
.Append(" TID:")
487+
.Append(currentThreadId);
488+
}
489+
formatLogLine
490+
.Append(" ")
491+
.Append(DateTime.Now.ToString())
492+
.Append(" ")
493+
.Append(optional);
494+
writeStr(path, formatLogLine);
495+
}
496+
350497
internal static void MakeErrorLog(Exception ex, string optional = null)
351498
{
352499
try
@@ -357,7 +504,8 @@ internal static void MakeErrorLog(Exception ex, string optional = null)
357504
{
358505
Directory.CreateDirectory(appdataQT);
359506
}
360-
string path = Path.Combine(appdataQT, "QTTabBarException.log");
507+
// string path = Path.Combine(appdataQT, "QTTabBarBandObject.bandLog");
508+
string path = Path.Combine(appdataQT, "QTTabBarBandObjectException.log");
361509
using (StreamWriter writer = new StreamWriter(path, true))
362510
{
363511
writer.WriteLine(DateTime.Now.ToString());
@@ -398,5 +546,5 @@ internal static void MakeErrorLog(Exception ex, string optional = null)
398546
{
399547
}
400548
}
401-
}*/
549+
}
402550
}

0 commit comments

Comments
 (0)