summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrewski207 <drewski207@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2007-07-14 19:58:11 +0000
committerdrewski207 <drewski207@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2007-07-14 19:58:11 +0000
commitef29793241a17b67eef1b3ca7389b3ce1ac95a6e (patch)
tree556dd9d12a8c31b4bacc0d14eea4d0504fea55c9
parentb6b2b8e0e99c7136f727454772b0da838db56734 (diff)
downloadfpGUI-ef29793241a17b67eef1b3ca7389b3ce1ac95a6e.tar.xz
* Fixed memo scrollbar position and logic
* Added Ctrl+End and Ctrl+Home to Memo * Made Buttons on ScrollBar react to clicks
-rw-r--r--prototypes/fpgui2/source/gui/gui_memo.pas70
-rw-r--r--prototypes/fpgui2/source/gui/gui_scrollbar.pas55
2 files changed, 84 insertions, 41 deletions
diff --git a/prototypes/fpgui2/source/gui/gui_memo.pas b/prototypes/fpgui2/source/gui/gui_memo.pas
index f10ba212..53b0b7db 100644
--- a/prototypes/fpgui2/source/gui/gui_memo.pas
+++ b/prototypes/fpgui2/source/gui/gui_memo.pas
@@ -14,6 +14,8 @@ uses
type
+ { TfpgMemo }
+
TfpgMemo = class(TfpgWidget)
private
FLines: TStringList;
@@ -57,6 +59,7 @@ type
procedure SetText(const AValue: string);
function GetText: string;
procedure SetCursorLine(aValue: integer);
+ procedure UpdateScrollBarCoords;
protected
procedure HandleKeyChar(var keycode: word; var shiftstate: word; var consumed: boolean); override;
procedure HandleLMouseDown(x, y: integer; shiftstate: word); override;
@@ -132,6 +135,28 @@ begin
end;
end;
+procedure TfpgMemo.UpdateScrollBarCoords;
+var
+ HWidth,
+ VHeight: Integer;
+begin
+ VHeight := Height - 4;
+ HWidth := Width - 4;
+
+ if FVScrollBar.Visible then Dec(HWidth, FVScrollBar.Width);
+ if FHScrollBar.Visible then Dec(VHeight, FHScrollBar.Height);
+
+ FHScrollBar.Top := Height -FHScrollBar.Height - 2;
+ FHScrollBar.Left := 2;
+ FHScrollBar.Width := HWidth;
+
+ FVScrollBar.Top := 2;
+ FVScrollBar.Left := Width - FVScrollBar.Width - 2;
+ FVScrollBar.Height := VHeight;
+ FVScrollBar.UpdateWindowPosition;
+ FHScrollBar.UpdateWindowPosition;
+end;
+
constructor TfpgMemo.Create(AOwner: TComponent);
begin
inherited;
@@ -165,14 +190,10 @@ begin
FVScrollBar := TfpgScrollBar.Create(self);
FVScrollBar.Orientation := orVertical;
FVScrollBar.OnScroll := @VScrollBarMove;
- FVScrollBar.Top := 0;
- FVScrollBar.Left := Width - FVScrollBar.Width;
- FVScrollBar.Height := Height;
FHScrollBar := TfpgScrollBar.Create(self);
FHScrollBar.Orientation := orHorizontal;
FHScrollBar.OnScroll := @HScrollBarMove;
- FHScrollBar.Top := Height - FHScrollbar.Height;
FWrapping := False;
end;
@@ -445,18 +466,7 @@ begin
FVScrollBar.Visible := vsbvis;
- if FHScrollBar.Visible then
- begin
- if not FVScrollBar.Visible then
- x := Width
- else
- x := Width - FVscrollBar.Width;
- if x <> FHScrollBar.Width then
- begin
- FHScrollBar.Width := x;
- FHScrollBar.UpdateWindowPosition;
- end;
- end;
+ UpdateScrollBarCoords;
if FHScrollBar.Visible then
begin
@@ -583,6 +593,7 @@ begin
inherited HandleShow;
RecalcLongestLine;
UpdateScrollBar;
+ UpdateScrollBarCoords;
end;
procedure TfpgMemo.VScrollBarMove(Sender: TObject; position: integer);
@@ -621,7 +632,7 @@ begin
r.Width := Width - 4;
r.Height := Height - 4;
Canvas.SetClipRect(r);
-
+
if Enabled then
Canvas.SetColor(FBackgroundColor)
else
@@ -689,6 +700,13 @@ begin
if not Focused then
fpgCaret.UnSetCaret(Canvas);
+
+ if FHScrollBar.Visible and FVScrollBar.Visible then begin
+ Canvas.SetColor(clWindowBackground);
+ Canvas.FillRectangle(FHScrollBar.Left + FHScrollBar.Width,
+ FVScrollBar.Top + FVScrollBar.Height,
+ FVScrollBar.Width, FHScrollBar.Height);
+ end;
Canvas.EndDraw;
end;
@@ -789,10 +807,18 @@ begin
end;
end;
KEY_HOME:
+ begin
+ if (shiftstate and ss_control) <> 0 then
+ FCursorLine := 1;
FCursorPos := 0;// home
+ end;
KEY_END:
+ begin
+ if (shiftstate and ss_control) <> 0 then
+ FCursorLine := LineCount;
FCursorPos := UTF8Length(CurrentLine);// end
+ end;
KEY_PGUP:
if FCursorLine > 1 then
@@ -1096,15 +1122,7 @@ procedure TfpgMemo.HandleResize(dwidth, dheight: integer);
begin
inherited HandleResize(dwidth, dheight);
- FVScrollBar.Top := 0;
- FVScrollBar.Height := Height - FHScrollBar.Height;
- FVScrollBar.Left := Width - FVScrollBar.Width;
- FVScrollBar.UpdateWindowPosition;
-
- FHScrollBar.Top := Height - FHScrollBar.Height;
- FHScrollBar.Width := Width - FVScrollBar.Width;
- FHScrollBar.UpdateWindowPosition;
-
+ //UpdateScrollBarCoords;
UpdateScrollBar;
end;
diff --git a/prototypes/fpgui2/source/gui/gui_scrollbar.pas b/prototypes/fpgui2/source/gui/gui_scrollbar.pas
index 7a9e7c0a..8d995928 100644
--- a/prototypes/fpgui2/source/gui/gui_scrollbar.pas
+++ b/prototypes/fpgui2/source/gui/gui_scrollbar.pas
@@ -14,13 +14,17 @@ uses
type
TScrollNotifyEvent = procedure(Sender: TObject; position: integer) of object;
+ { TfpgScrollBar }
+
TfpgScrollBar = class(TfpgWidget)
protected
FSliderPos, FSliderLength: TfpgCoord;
FSliderDragging: boolean;
+ FStartBtnPressed,
+ FEndBtnPressed: Boolean;
FSliderDragPos: TfpgCoord;
FSliderDragStart: TfpgCoord;
- procedure DrawButton(x, y, w, h: TfpgCoord; const imgname: string);
+ procedure DrawButton(x, y, w, h: TfpgCoord; const imgname: string; Pressed: Boolean = False);
procedure DrawSlider(recalc: boolean);
procedure HandleLMouseDown(x, y: integer; shiftstate: word); override;
procedure HandleLMouseUp(x, y: integer; shiftstate: word); override;
@@ -62,13 +66,13 @@ begin
if Orientation = orVertical then
begin
- DrawButton(0, 0, Width, Width, 'sys.sb.up');
- DrawButton(0, Height - Width, Width, Width, 'sys.sb.down');
+ DrawButton(0, 0, Width, Width, 'sys.sb.up' ,FStartBtnPressed);
+ DrawButton(0, Height - Width, Width, Width, 'sys.sb.down', FEndBtnPressed);
end
else
begin
- DrawButton(0, 0, Height, Height, 'sys.sb.left');
- DrawButton(Width - Height, 0, Height, Height, 'sys.sb.right');
+ DrawButton(0, 0, Height, Height, 'sys.sb.left', FStartBtnPressed);
+ DrawButton(Width - Height, 0, Height, Height, 'sys.sb.right', FEndBtnPressed);
end;
DrawSlider(True);
@@ -82,11 +86,14 @@ begin
DrawSlider(True);
end;
-procedure TfpgScrollBar.DrawButton(x, y, w, h: TfpgCoord; const imgname: string);
+procedure TfpgScrollBar.DrawButton(x, y, w, h: TfpgCoord; const imgname: string; Pressed: Boolean = False);
var
img: TfpgImage;
begin
- Canvas.DrawButtonFace(x, y, w, h, [btnIsEmbedded]);
+ if Pressed then
+ Canvas.DrawButtonFace(x, y, w, h, [btnIsEmbedded, btnIsPressed])
+ else
+ Canvas.DrawButtonFace(x, y, w, h, [btnIsEmbedded]);
Canvas.SetColor(clText1);
img := fpgImages.GetImage(imgname);
if img <> nil then
@@ -153,20 +160,28 @@ begin
if Orientation = orVertical then
begin
- if y <= Width then
- PositionChange(-1)
- else if y >= Height - Width then
- PositionChange(1)
+ if y <= Width then begin
+ PositionChange(-1);
+ FStartBtnPressed := True;
+ end
+ else if y >= Height - Width then begin
+ PositionChange(1);
+ FEndBtnPressed := True;
+ end
else if (y >= Width + FSliderPos) and (y <= Width + FSliderPos + FSliderLength) then
begin
FSliderDragging := True;
FSliderDragPos := y;
end;
end
- else if x <= Height then
- PositionChange(-1)
- else if x >= Width - Height then
- PositionChange(1)
+ else if x <= Height then begin
+ PositionChange(-1);
+ FStartBtnPressed := True;
+ end
+ else if x >= Width - Height then begin
+ PositionChange(1);
+ FEndBtnPressed := True;
+ end
else if (x >= Height + FSliderPos) and (x <= Height + FSliderPos + FSliderLength) then
begin
FSliderDragging := True;
@@ -177,13 +192,23 @@ begin
begin
FSliderDragStart := FSliderPos;
DrawSlider(False);
+ end
+ else if FStartBtnPressed or FEndBtnPressed then begin
+ HandlePaint;
end;
+
end;
procedure TfpgScrollBar.HandleLMouseUp(x, y: integer; shiftstate: word);
+var
+ WasPressed: Boolean;
begin
inherited;
+ WasPressed := FStartBtnPressed or FEndBtnPressed;
+ FStartBtnPressed := False;
+ FEndBtnPressed := False;
FSliderDragging := False;
+ if WasPressed then HandlePaint;
end;
procedure TfpgScrollBar.HandleMouseMove(x, y: integer; btnstate, shiftstate: word);