Skip to content

Commit d5c7dce

Browse files
committed
Remove all hibernation bug fix hacks per v4.24.2
This is a merge of two commits proposed by @SirRufo per PR#160, with trivial FrOverview.dfm changes removed.
1 parent ada3a44 commit d5c7dce

File tree

4 files changed

+0
-104
lines changed

4 files changed

+0
-104
lines changed

Src/FmMain.pas

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -526,12 +526,6 @@ TMainForm = class(THelpAwareForm)
526526
/// <summary>Object that manages favourites.</summary>
527527
fFavouritesMgr: TFavouritesManager;
528528

529-
/// <summary>Handles the <c>WM_POWERBROADCAST</c> messages to detect and
530-
/// respond to hibernation messages.</summary>
531-
/// <remarks>!! HACK necessary as part of the fix for an obscure bug. See
532-
/// https://github.com/delphidabbler/codesnip/issues/70</remarks>
533-
procedure WMPowerBroadcast(var Msg: TMessage); message WM_POWERBROADCAST;
534-
535529
/// <summary>Displays view item given by TViewItemAction instance
536530
/// referenced by Sender and adds to history list.</summary>
537531
procedure ActViewItemExecute(Sender: TObject);
@@ -1601,19 +1595,5 @@ procedure TMainForm.splitVertCanResize(Sender: TObject;
16011595
Accept := False;
16021596
end;
16031597

1604-
procedure TMainForm.WMPowerBroadcast(var Msg: TMessage);
1605-
begin
1606-
// !! HACK
1607-
// Sometimes when the computer is resumed from hibernation the tree view in
1608-
// the overview frame is destroyed and recreated by Windows. Unfortunately the
1609-
// IView instances associated with the recreated tree nodes are lost.
1610-
// Attempting to read those (now nil) IView instances was resulting in an
1611-
// access violation.
1612-
case Msg.WParam of
1613-
PBT_APMSUSPEND:
1614-
fMainDisplayMgr._HACK_PrepareForHibernate;
1615-
end;
1616-
end;
1617-
16181598
end.
16191599

Src/FrOverview.pas

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,6 @@ interface
2626

2727
type
2828

29-
// !! HACK
30-
// Horrible hack to expose CreateWnd for overiding TTreeView.CreateWnd for the
31-
// existing TTreeView component of TOverviewFrame. The hack avoids having to
32-
// remove the component and replacing it with a descendant class that is
33-
// manually constructed at run time.
34-
// This is here to enable the tree view to be recreated with correctly
35-
// instantiated TViewItemTreeNode nodes after Windows recreates the tree
36-
// behind the scenes after resuming from hibernation.
37-
// I am deeply ashamed of this hack.
38-
TTreeView = class(ComCtrls.TTreeView)
39-
strict private
40-
var
41-
_HACK_fOnAfterCreateNilViews: TNotifyEvent;
42-
protected
43-
procedure CreateWnd; override;
44-
public
45-
/// <summary>!! HACK. Event triggered after the inherited CreateWnd is
46-
/// called. Only called if the tree view has nil references to IView
47-
/// objects.</summary>
48-
property _HACK_OnAfterCreateNilViews: TNotifyEvent
49-
read _HACK_fOnAfterCreateNilViews write _HACK_fOnAfterCreateNilViews;
50-
end;
51-
5229
{
5330
TOverviewFrame:
5431
Titled frame that displays lists of snippets grouped in various ways and
@@ -237,10 +214,6 @@ TTVDraw = class(TSnippetsTVDraw)
237214
procedure RestoreTreeState;
238215
{Restores last saved treeview expansion state from memory.
239216
}
240-
/// <summary>!! HACK: Sets an event handler on the tree view to work
241-
/// around a bug that can occur after resuming from hibernation.</summary>
242-
/// <remarks>Method of IOverviewDisplayMgr.</remarks>
243-
procedure _HACK_SetHibernateHandler(const AHandler: TNotifyEvent);
244217
{ IPaneInfo }
245218
function IsInteractive: Boolean;
246219
{Checks if the pane is currently interactive with user.
@@ -982,12 +955,6 @@ procedure TOverviewFrame.UpdateTreeState(const State: TTreeNodeAction);
982955
end;
983956
end;
984957

985-
procedure TOverviewFrame._HACK_SetHibernateHandler(
986-
const AHandler: TNotifyEvent);
987-
begin
988-
tvSnippets._HACK_OnAfterCreateNilViews := AHandler;
989-
end;
990-
991958
{ TOverviewFrame.TTVDraw }
992959

993960
function TOverviewFrame.TTVDraw.IsSectionHeadNode(
@@ -1026,24 +993,5 @@ function TOverviewFrame.TTVDraw.IsUserDefinedNode(
1026993
Result := False;
1027994
end;
1028995

1029-
{ TTreeView }
1030-
1031-
procedure TTreeView.CreateWnd;
1032-
var
1033-
HasNilViews: Boolean;
1034-
Node: TTreeNode;
1035-
begin
1036-
inherited;
1037-
HasNilViews := False;
1038-
for Node in Items do
1039-
begin
1040-
HasNilViews := not Assigned((Node as TViewItemTreeNode).ViewItem);
1041-
if HasNilViews then
1042-
Break;
1043-
end;
1044-
if HasNilViews and Assigned(_HACK_fOnAfterCreateNilViews) then
1045-
_HACK_fOnAfterCreateNilViews(Self);
1046-
end;
1047-
1048996
end.
1049997

Src/IntfFrameMgrs.pas

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ interface
1919
uses
2020
// Delphi
2121
SHDocVw, ActiveX,
22-
Classes, // !! For HACK
2322
// Project
2423
Browser.IntfDocHostUI, DB.USnippet, Compilers.UGlobals, UCommandBars, UView;
2524

@@ -146,9 +145,6 @@ interface
146145
/// <summary>Restore expand / collapse state of treeview to last save
147146
/// state.</summary>
148147
procedure RestoreTreeState;
149-
/// <summary>!! HACK: Sets an event handler on the tree view to work
150-
/// around a bug that can occur after resuming from hibernation.</summary>
151-
procedure _HACK_SetHibernateHandler(const AHandler: TNotifyEvent);
152148
end;
153149

154150
type

Src/UMainDisplayMgr.pas

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,6 @@ TMainDisplayMgr = class(TObject)
165165
procedure DisplayViewItem(ViewItem: IView; Mode: TDetailPageDisplayMode);
166166
overload;
167167

168-
/// <summary>!! HACK event handle to redisplay the overview pane treeview.
169-
/// Called only if Windows has mysteriously recreated the treeview and lost
170-
/// necessary object references.</summary>
171-
procedure _HACK_HibernateHandler(Sender: TObject);
172-
173168
public
174169
/// <summary>Object contructor. Sets up object to work with given frame
175170
/// manager objects.</summary>
@@ -297,13 +292,6 @@ TMainDisplayMgr = class(TObject)
297292
/// <summary>Prepares display ready for database to be reloaded.</summary>
298293
procedure PrepareForDBReload;
299294

300-
/// <summary>!!HACK: gets the overview frame prepared for program
301-
/// hibernation.</summary>
302-
/// <remarks>Saves the overview tree view state ready for restoring after
303-
/// hibernation if Windows has recreated the overview pane's treeview,
304-
/// losing necessary IView object references..</remarks>
305-
procedure _HACK_PrepareForHibernate;
306-
307295
end;
308296

309297

@@ -704,21 +692,5 @@ procedure TMainDisplayMgr.UpdateOverviewTreeState(const State: TTreeNodeAction);
704692
(fOverviewMgr as IOverviewDisplayMgr).UpdateTreeState(State);
705693
end;
706694

707-
procedure TMainDisplayMgr._HACK_HibernateHandler(Sender: TObject);
708-
begin
709-
(fOverviewMgr as IOverviewDisplayMgr).Display(Query.Selection, True);
710-
(fOverviewMgr as IOverviewDisplayMgr).RestoreTreeState;
711-
// disable this handler until next resume from hibernation
712-
(fOverviewMgr as IOverviewDisplayMgr)._HACK_SetHibernateHandler(nil);
713-
end;
714-
715-
procedure TMainDisplayMgr._HACK_PrepareForHibernate;
716-
begin
717-
(fOverviewMgr as IOverviewDisplayMgr).SaveTreeState;
718-
(fOverviewMgr as IOverviewDisplayMgr)._HACK_SetHibernateHandler(
719-
_HACK_HibernateHandler
720-
);
721-
end;
722-
723695
end.
724696

0 commit comments

Comments
 (0)