Changeset 89 for trunk/LocalPlayer/PVSB.pas
- Timestamp:
- Jan 19, 2017, 8:40:22 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LocalPlayer/PVSB.pas
r70 r89 18 18 private 19 19 FOnUpdate: TNotifyEvent; 20 ScrollBar: TScrollBar; 21 function GetMax: Integer; 22 function GetPageSize: Integer; 23 function GetPosition: Integer; 20 24 procedure ScrollBarChanged(Sender: TObject); 25 procedure SetMax(AValue: Integer); 26 procedure SetPageSize(AValue: Integer); 27 procedure SetPosition(AValue: Integer); 21 28 public 22 ScrollBar: TScrollBar; 23 si: TScrollInfo; 29 constructor Create(Parent: TWinControl); 24 30 destructor Destroy; override; 25 procedure Setup(TopSpacing, RightSpacing, BottomSpacing: integer; Parent: TWinControl); 26 procedure Init(max, Page: integer); 31 procedure Init(Max, Page: Integer); 27 32 procedure SetPos(Pos: Integer); 28 33 function Process(const m: TMessage): boolean; 29 function ProcessMouseWheel(Delta: Integer) : boolean;34 function ProcessMouseWheel(Delta: Integer): Boolean; 30 35 procedure Show(Visible: boolean); 31 36 procedure EndSB; 32 procedure UpdateScrollBar;37 procedure SetBorderSpacing(Top, Right, Bottom: Integer); 33 38 property OnUpdate: TNotifyEvent read FOnUpdate write FOnUpdate; 39 property Position: Integer read GetPosition write SetPosition; 40 property Max: Integer read GetMax write SetMax; 41 property PageSize: Integer read GetPageSize write SetPageSize; 34 42 end; 35 43 … … 38 46 39 47 const 40 Count: integer = 0;48 Count: Integer = 0; 41 49 42 procedure TPVScrollBar.Setup(TopSpacing, RightSpacing, BottomSpacing: integer; 43 Parent: TWinControl); 50 procedure TPVScrollBar.Init(Max, Page: Integer); 44 51 begin 45 inc(Count); 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 (* 61 {$ENDIF} 62 {$IFDEF WINDOWS} 63 sb.h := CreateWindowEx(0, 'SCROLLBAR', pchar('PVSB' + IntToStr(Count)), 64 SBS_VERT or WS_CHILD or SBS_RIGHTALIGN, x1 - 100, y0, 100, y1 - y0, 65 Handle, 0, 0, nil); 66 {$ENDIF} 67 *) 68 si.cbSize := 28; 69 end; 70 71 procedure TPVScrollBar.Init(max, Page: integer); 72 begin 73 with si do begin 74 nMin := 0; 75 nMax := max; 76 npos := 0; 77 nPage := Page; 78 FMask := SIF_PAGE or SIF_POS or SIF_RANGE; 79 end; 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; 52 ScrollBar.Min := 0; 53 ScrollBar.Max := Max; 54 ScrollBar.PageSize := Page; 55 ScrollBar.Position := 0; 56 ScrollBar.Visible := ScrollBar.Max >= ScrollBar.PageSize; 84 57 end; 85 58 … … 87 60 begin 88 61 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; 62 ScrollBar.Position := Pos; 93 63 end; 94 64 end; … … 98 68 NewPos: integer; 99 69 begin 100 with si do 101 if nMax < integer(nPage) then 70 if ScrollBar.Max < ScrollBar.PageSize then 102 71 result := false 103 72 else … … 105 74 if (m.wParam and $ffff) in [SB_THUMBPOSITION, SB_THUMBTRACK] then 106 75 begin 107 result := ((m.wParam shr 16) and $ffff) <> npos; 108 npos := (m.wParam shr 16) and $ffff; 109 end 110 else 111 begin 76 result := ((m.wParam shr 16) and $ffff) <> ScrollBar.Position; 77 ScrollBar.Position := (m.wParam shr 16) and $ffff; 78 end else begin 112 79 case (m.wParam and $ffff) of 113 80 SB_LINEUP: 114 NewPos := npos- 1;81 NewPos := ScrollBar.Position - 1; 115 82 SB_LINEDOWN: 116 NewPos := npos+ 1;83 NewPos := ScrollBar.Position + 1; 117 84 SB_PAGEUP: 118 NewPos := npos - integer(nPage);85 NewPos := ScrollBar.Position - ScrollBar.PageSize; 119 86 SB_PAGEDOWN: 120 NewPos := npos + integer(nPage);87 NewPos := ScrollBar.Position + ScrollBar.PageSize; 121 88 else 122 NewPos := npos89 NewPos := ScrollBar.Position 123 90 end; 124 91 if NewPos < 0 then 125 92 NewPos := 0; 126 if NewPos > nMax - integer(nPage)+ 1 then127 NewPos := nMax - integer(nPage)+ 1;128 result := NewPos <> npos;129 if (NewPos <> npos) or ((m.wParam and $ffff) = SB_ENDSCROLL) then93 if NewPos > ScrollBar.Max - ScrollBar.PageSize + 1 then 94 NewPos := ScrollBar.Max - ScrollBar.PageSize + 1; 95 result := NewPos <> ScrollBar.Position; 96 if (NewPos <> ScrollBar.Position) or ((m.wParam and $ffff) = SB_ENDSCROLL) then 130 97 begin 131 npos := NewPos; 132 FMask := SIF_POS; 133 UpdateScrollBar; 134 //SetScrollInfo(sb.ScrollBar.Handle, SB_CTL, sb.si, true); 98 ScrollBar.Position := NewPos; 135 99 end; 136 end 137 end 100 end; 101 end; 138 102 end; 139 103 140 function TPVScrollBar.ProcessMouseWheel(Delta: Integer 141 ): boolean; 104 function TPVScrollBar.ProcessMouseWheel(Delta: Integer): Boolean; 142 105 var 143 106 NewPos: integer; 144 107 begin 145 with si do 146 if nMax < integer(nPage) then 147 result := false 148 else 149 begin 150 NewPos := npos - Delta div 300; 151 if NewPos < 0 then 152 NewPos := 0; 153 if NewPos > nMax - integer(nPage) + 1 then 154 NewPos := nMax - integer(nPage) + 1; 155 result := NewPos <> npos; 156 if NewPos <> npos then 157 begin 158 npos := NewPos; 159 FMask := SIF_POS; 160 UpdateScrollBar; 161 //SetScrollInfo(sb.ScrollBar.Handle, SB_CTL, sb.si, true); 162 end 163 end 108 if ScrollBar.Max < ScrollBar.PageSize then Result := False 109 else begin 110 NewPos := ScrollBar.Position - Delta div 300; 111 if NewPos < 0 then NewPos := 0; 112 if NewPos > ScrollBar.Max - ScrollBar.PageSize + 1 then 113 NewPos := ScrollBar.Max - ScrollBar.PageSize + 1; 114 Result := NewPos <> ScrollBar.Position; 115 if NewPos <> ScrollBar.Position then begin 116 ScrollBar.Position := NewPos; 117 end; 118 end; 164 119 end; 165 120 166 121 procedure TPVScrollBar.Show(Visible: boolean); 167 122 begin 168 if not Visible or ( si.nMax < integer(si.nPage)) then123 if not Visible or (ScrollBar.Max < ScrollBar.PageSize) then 169 124 ScrollBar.Visible := False 170 125 else ScrollBar.Visible := True; … … 173 128 procedure TPVScrollBar.EndSB; 174 129 begin 175 with si do begin 176 if nMax < integer(nPage) then 177 npos := 0 // hidden 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); 183 end 184 end 130 if ScrollBar.Max < ScrollBar.PageSize then 131 ScrollBar.Position := 0 // hidden 132 else begin 133 ScrollBar.Position := ScrollBar.Max - ScrollBar.PageSize + 1; 134 end; 185 135 end; 186 136 187 procedure TPVScrollBar. UpdateScrollBar;137 procedure TPVScrollBar.SetBorderSpacing(Top, Right, Bottom: Integer); 188 138 begin 189 ScrollBar.Min := si.nMin; 190 ScrollBar.Max := Max(si.nMax{$IFDEF LINUX} - si.nPage + 1{$ENDIF}, 0); 191 ScrollBar.PageSize := si.nPage; 192 ScrollBar.Position := si.nPos; 139 ScrollBar.BorderSpacing.Top := Top; 140 ScrollBar.BorderSpacing.Right := Right; 141 ScrollBar.BorderSpacing.Bottom := Bottom; 193 142 end; 194 143 … … 197 146 procedure TPVScrollBar.ScrollBarChanged(Sender: TObject); 198 147 begin 199 si.npos := ScrollBar.Position;200 148 if Assigned(FOnUpdate) then FOnUpdate(Self); 149 end; 150 151 procedure TPVScrollBar.SetMax(AValue: Integer); 152 begin 153 ScrollBar.Max := AValue; 154 end; 155 156 procedure TPVScrollBar.SetPageSize(AValue: Integer); 157 begin 158 ScrollBar.PageSize := AValue; 159 end; 160 161 function TPVScrollBar.GetPosition: Integer; 162 begin 163 Result := ScrollBar.Position; 164 end; 165 166 function TPVScrollBar.GetMax: Integer; 167 begin 168 Result := ScrollBar.Max; 169 end; 170 171 function TPVScrollBar.GetPageSize: Integer; 172 begin 173 Result := ScrollBar.PageSize; 174 end; 175 176 procedure TPVScrollBar.SetPosition(AValue: Integer); 177 begin 178 ScrollBar.Position := AValue; 179 end; 180 181 constructor TPVScrollBar.Create(Parent: TWinControl); 182 begin 183 Inc(Count); 184 ScrollBar := TScrollBar.Create(Parent); 185 ScrollBar.Kind := sbVertical; 186 ScrollBar.Name := 'PVSB' + IntToStr(Count); 187 ScrollBar.Align := alRight; 188 ScrollBar.OnChange := ScrollBarChanged; 189 ScrollBar.Parent := Parent; 201 190 end; 202 191 203 192 destructor TPVScrollBar.Destroy; 204 193 begin 205 //h := 0;206 si.cbSize := 0;207 194 FreeAndNil(ScrollBar); 208 195 end;
Note:
See TracChangeset
for help on using the changeset viewer.