forked from vladk1973/npp.connections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomDialogUnit.pas
161 lines (138 loc) · 4.09 KB
/
CustomDialogUnit.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
unit CustomDialogUnit;
interface
uses
Windows, Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.StdCtrls, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, NppForms, Vcl.ExtCtrls,
{$IFDEF NPPCONNECTIONS}TranslateComponentsUnit,{$ENDIF}
Vcl.Buttons;
type
TCustomDialogForm = class(TNppForm)
TopPanel: TPanel;
OkPanel: TPanel;
CancelPanel: TPanel;
CancelBtn: TBitBtn;
OkBtn: TBitBtn;
procedure OkPanelMouseEnter(Sender: TObject);
procedure OkPanelMouseLeave(Sender: TObject);
procedure TopPanelMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure OkPanelClick(Sender: TObject);
procedure CancelPanelClick(Sender: TObject);
private
{ Private declarations }
procedure WMNCHitTest(var M:TWMNCHitTest); Message WM_NCHitTest;
protected
procedure ChangeColorMode(Sender: TObject); override;
public
function DoForm: TModalResult; virtual;
end;
var
CustomDialogForm: TCustomDialogForm;
implementation
{$R *.dfm}
{ TNppForm1 }
procedure TCustomDialogForm.CancelPanelClick(Sender: TObject);
begin
CancelBtn.Click;
end;
procedure TCustomDialogForm.ChangeColorMode(Sender: TObject);
var
i: integer;
C: TComponent;
begin
inherited;
if DarkMode then
begin
Self.Color := ColorBackground;
for i := 0 to ComponentCount-1 do
begin
C := Components[i];
if C is TLabel then TLabel(C).Font.Color := ColorText;
if C is TCheckBox then
begin
TCheckBox(C).Font.Color := ColorText;
end;
if C is TComboBox then
begin
TComboBox(C).Font.Color := ColorText;
TComboBox(C).Color := ColorSofterBackground;
end;
if C is TGroupBox then
begin
TGroupBox(C).Font.Color := ColorText;
TGroupBox(C).Color := ColorSofterBackground;
end;
if C is TMemo then
begin
TMemo(C).Font.Color := ColorText;
TMemo(C).Color := ColorSofterBackground;
end;
if C is TEdit then
begin
TEdit(C).Font.Color := ColorText;
TEdit(C).Color := ColorSofterBackground;
end;
end;
CancelPanel.Color := ColorBackground;
CancelPanel.Font.Color := ColorText;
OkPanel.Color := ColorBackground;
OkPanel.Font.Color := ColorText;
TopPanel.Color := clNone;
TopPanel.Font.Color := ColorText;
end
else
TopPanel.Color := ColorDefaultBackground;
end;
function TCustomDialogForm.DoForm: TModalResult;
begin
Result := Self.ShowModal;
end;
procedure TCustomDialogForm.FormCreate(Sender: TObject);
begin
windows.SetWindowLong(Handle, GWL_STYLE, GetWindowLong(Handle, GWL_STYLE) and not WS_CAPTION);
windows.SetWindowPos(Handle, HWND_TOP,Left, Top,Width, Height, SWP_FRAMECHANGED);
{$IFDEF NPPCONNECTIONS}
TranslateComponents(Self);
{$ENDIF}
if DarkMode then
begin
OkPanel.Visible := True;
OkPanel.Top := OkBtn.Top;
OkPanel.Caption := OkBtn.Caption;
OkPanel.Left := OkBtn.Left;
CancelPanel.Visible := True;
CancelPanel.Top := CancelBtn.Top;
CancelPanel.Caption := CancelBtn.Caption;
CancelPanel.Left := CancelBtn.Left;
OkBtn.Visible := False;
CancelBtn.Visible := False;
end;
TopPanel.Caption := Caption;
end;
procedure TCustomDialogForm.OkPanelClick(Sender: TObject);
begin
OkBtn.Click;
end;
procedure TCustomDialogForm.OkPanelMouseEnter(Sender: TObject);
begin
TPanel(Sender).Color := RGB(GetRValue(Color)+10,GetGValue(Color)+10,GetBValue(Color)+10)
end;
procedure TCustomDialogForm.OkPanelMouseLeave(Sender: TObject);
begin
TPanel(Sender).Color := Color;
end;
procedure TCustomDialogForm.TopPanelMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
Self.Perform(WM_SysCommand,$F012,0);
end;
procedure TCustomDialogForm.WMNCHitTest(var M: TWMNCHitTest);
begin
if M.Result = htClient then
M.Result := htCaption
else
DefaultHandler(M);
end;
end.