Changeset 69 for trunk/LocalPlayer/PVSB.pas
- Timestamp:
- Jan 14, 2017, 10:33:42 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LocalPlayer/PVSB.pas
r50 r69 8 8 Windows, 9 9 {$ENDIF} 10 Forms, LCLIntf, LCLType, LMessages, Messages, SysUtils; 10 Classes, Controls, Forms, LCLIntf, LCLType, LMessages, Messages, SysUtils, 11 StdCtrls, Math; 11 12 12 13 type … … 14 15 { TPVScrollbar } 15 16 16 TPVScrollbar = class 17 h: integer; 17 TPVScrollBar = class 18 private 19 FOnUpdate: TNotifyEvent; 20 procedure ScrollBarChanged(Sender: TObject); 21 public 22 ScrollBar: TScrollBar; 18 23 si: TScrollInfo; 19 Form: TForm;20 24 destructor Destroy; override; 25 procedure Setup(TopSpacing, RightSpacing, BottomSpacing: integer; Parent: TWinControl); 26 procedure Init(max, Page: integer); 27 procedure SetPos(Pos: Integer); 28 function Process(const m: TMessage): boolean; 29 function ProcessMouseWheel(Delta: Integer) : boolean; 30 procedure Show(Visible: boolean); 31 procedure EndSB; 32 procedure UpdateScrollBar; 33 property OnUpdate: TNotifyEvent read FOnUpdate write FOnUpdate; 21 34 end; 22 35 23 procedure CreatePVSB(var sb: TPVScrollbar; Handle, y0, x1, y1: integer);24 procedure InitPVSB(var sb: TPVScrollbar; max, Page: integer);25 function ProcessPVSB(var sb: TPVScrollbar; const m: TMessage): boolean;26 function ProcessMouseWheel(var sb: TPVScrollbar; const m: TMessage)27 : boolean;28 procedure ShowPVSB(var sb: TPVScrollbar; Visible: boolean);29 procedure EndPVSB(var sb: TPVScrollbar);30 36 31 37 implementation … … 34 40 Count: integer = 0; 35 41 36 procedure CreatePVSB(var sb: TPVScrollbar; Handle, y0, x1, y1: integer); 42 procedure TPVScrollBar.Setup(TopSpacing, RightSpacing, BottomSpacing: integer; 43 Parent: TWinControl); 37 44 begin 38 45 inc(Count); 39 {$IFDEF LINUX} 40 sb.Form := TForm.Create(nil); 41 sb.Form.SetBounds(x1 - 100, y0, 100, y1 - y0); 42 sb.Form.Name := 'PVSB' + IntToStr(Count); 43 sb.h := sb.Form.Handle; 46 //{$IFDEF LINUX} 47 // sb.Form := TForm.Create(nil); 48 // sb.Form.SetBounds(x1 - 100, y0, 100, y1 - y0); 49 // sb.Form.Name := 'PVSB' + IntToStr(Count); 50 ScrollBar := TScrollBar.Create(Parent); 51 ScrollBar.Kind := sbVertical; 52 ScrollBar.Name := 'PVSB' + IntToStr(Count); 53 ScrollBar.Parent := Parent; 54 ScrollBar.BorderSpacing.Top := TopSpacing; 55 ScrollBar.BorderSpacing.Right := RightSpacing; 56 ScrollBar.BorderSpacing.Bottom := BottomSpacing; 57 ScrollBar.Align := alRight; 58 ScrollBar.OnChange := ScrollBarChanged; 59 //sb.h := sb.ScrollBar.Handle; 60 (* 44 61 {$ENDIF} 45 62 {$IFDEF WINDOWS} … … 48 65 Handle, 0, 0, nil); 49 66 {$ENDIF} 50 sb.si.cbSize := 28;51 end;52 53 procedure InitPVSB(var sb: TPVScrollbar; max, Page: integer); 54 begin 55 with sb.si do 56 begin67 *) 68 si.cbSize := 28; 69 end; 70 71 procedure TPVScrollBar.Init(max, Page: integer); 72 begin 73 with si do begin 57 74 nMin := 0; 58 75 nMax := max; … … 61 78 FMask := SIF_PAGE or SIF_POS or SIF_RANGE; 62 79 end; 63 SetScrollInfo(sb.h, SB_CTL, sb.si, true); 64 if max < Page then 65 ShowWindow(sb.h, SW_HIDE) 66 else 67 ShowWindow(sb.h, SW_SHOW) 68 end; 69 70 function ProcessPVSB(var sb: TPVScrollbar; const m: TMessage): Boolean; 80 UpdateScrollBar; 81 //SetScrollInfo(sb.ScrollBar.Handle, SB_CTL, sb.si, true); 82 if max < Page then ScrollBar.Visible := False 83 else ScrollBar.Visible := True; 84 end; 85 86 procedure TPVScrollBar.SetPos(Pos: Integer); 87 begin 88 if Pos <> 0 then begin 89 si.npos := Pos; 90 si.FMask := SIF_POS; 91 //SetScrollInfo(sb.ScrollBar.Handle, SB_CTL, sb.si, true); 92 UpdateScrollBar; 93 end; 94 end; 95 96 function TPVScrollBar.Process(const m: TMessage): boolean; 71 97 var 72 98 NewPos: integer; 73 99 begin 74 with s b.si do100 with si do 75 101 if nMax < integer(nPage) then 76 102 result := false … … 105 131 npos := NewPos; 106 132 FMask := SIF_POS; 107 SetScrollInfo(sb.h, SB_CTL, sb.si, true); 133 UpdateScrollBar; 134 //SetScrollInfo(sb.ScrollBar.Handle, SB_CTL, sb.si, true); 108 135 end; 109 136 end … … 111 138 end; 112 139 113 function ProcessMouseWheel(var sb: TPVScrollbar; const m: TMessage): Boolean; 140 function TPVScrollBar.ProcessMouseWheel(Delta: Integer 141 ): boolean; 114 142 var 115 143 NewPos: integer; 116 144 begin 117 with s b.si do145 with si do 118 146 if nMax < integer(nPage) then 119 147 result := false 120 148 else 121 149 begin 122 NewPos := npos - m.wParam div (1 shl 16 * 40);150 NewPos := npos - Delta div 300; 123 151 if NewPos < 0 then 124 152 NewPos := 0; … … 130 158 npos := NewPos; 131 159 FMask := SIF_POS; 132 SetScrollInfo(sb.h, SB_CTL, sb.si, true); 160 UpdateScrollBar; 161 //SetScrollInfo(sb.ScrollBar.Handle, SB_CTL, sb.si, true); 133 162 end 134 163 end 135 164 end; 136 165 137 procedure ShowPVSB(var sb: TPVScrollbar; Visible: boolean); 138 begin 139 if not Visible or (sb.si.nMax < integer(sb.si.nPage)) then 140 ShowWindow(sb.h, SW_HIDE) 141 else 142 ShowWindow(sb.h, SW_SHOW) 143 end; 144 145 procedure EndPVSB(var sb: TPVScrollbar); 146 begin 147 with sb.si do 148 begin 166 procedure TPVScrollBar.Show(Visible: boolean); 167 begin 168 if not Visible or (si.nMax < integer(si.nPage)) then 169 ScrollBar.Visible := False 170 else ScrollBar.Visible := True; 171 end; 172 173 procedure TPVScrollBar.EndSB; 174 begin 175 with si do begin 149 176 if nMax < integer(nPage) then 150 177 npos := 0 // hidden 151 else 152 begin153 s b.si.npos := nMax - integer(nPage) + 1;154 sb.si.FMask := SIF_POS;155 SetScrollInfo(sb.h, SB_CTL, sb.si, true);178 else begin 179 si.npos := nMax - integer(nPage) + 1; 180 si.FMask := SIF_POS; 181 UpdateScrollBar; 182 //SetScrollInfo(sb.ScrollBar.Handle, SB_CTL, sb.si, true); 156 183 end 157 184 end 158 185 end; 159 186 187 procedure TPVScrollBar.UpdateScrollBar; 188 begin 189 ScrollBar.Min := si.nMin; 190 ScrollBar.Max := Max(si.nMax - si.nPage + 1, 0); 191 ScrollBar.PageSize := si.nPage; 192 ScrollBar.Position := si.nPos; 193 end; 194 160 195 { TPVScrollbar } 161 196 162 destructor TPVScrollbar.Destroy; 163 begin 164 h := 0; 197 procedure TPVScrollBar.ScrollBarChanged(Sender: TObject); 198 begin 199 si.npos := ScrollBar.Position; 200 if Assigned(FOnUpdate) then FOnUpdate(Self); 201 end; 202 203 destructor TPVScrollBar.Destroy; 204 begin 205 //h := 0; 165 206 si.cbSize := 0; 166 FreeAndNil( Form);207 FreeAndNil(ScrollBar); 167 208 end; 168 209
Note:
See TracChangeset
for help on using the changeset viewer.