diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-07-15 21:02:49 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-07-15 21:02:49 +0000 |
commit | 2bf7e9419decd0191da4007aa750e0f967197f0a (patch) | |
tree | a5a715243e1fd8743757e0135c0f73e803d9f3b5 /prototypes | |
parent | e2c678e978a64538b853b6585fda273ce8349ca7 (diff) | |
download | fpGUI-2bf7e9419decd0191da4007aa750e0f967197f0a.tar.xz |
* Did some code cleanup in gui_scrollbar.pas
* Enabled Mouse Wheel support in TfpgWidget
* Implemented mouse wheel support in TfpgListBox
* Started keyboard support in TfpgListBox. (still needs testing)
Diffstat (limited to 'prototypes')
-rw-r--r-- | prototypes/fpgui2/source/core/gfx_widget.pas | 25 | ||||
-rw-r--r-- | prototypes/fpgui2/source/core/x11/fpGFX2.pas | 8 | ||||
-rw-r--r-- | prototypes/fpgui2/source/gui/gui_listbox.pas | 135 | ||||
-rw-r--r-- | prototypes/fpgui2/source/gui/gui_scrollbar.pas | 58 |
4 files changed, 179 insertions, 47 deletions
diff --git a/prototypes/fpgui2/source/core/gfx_widget.pas b/prototypes/fpgui2/source/core/gfx_widget.pas index 5b246681..54882811 100644 --- a/prototypes/fpgui2/source/core/gfx_widget.pas +++ b/prototypes/fpgui2/source/core/gfx_widget.pas @@ -37,6 +37,7 @@ type procedure MsgDoubleClick(var msg: TfpgMessageRec); message FPGM_DOUBLECLICK; procedure MsgMouseEnter(var msg: TfpgMessageRec); message FPGM_MOUSEENTER; procedure MsgMouseExit(var msg: TfpgMessageRec); message FPGM_MOUSEEXIT; + procedure MsgMouseScroll(var msg: TfpgMessageRec); message FPGM_SCROLL; procedure SetActiveWidget(const AValue: TfpgWidget); procedure SetEnabled(const AValue: boolean); procedure SetVisible(const AValue: boolean); @@ -68,6 +69,7 @@ type procedure HandleDoubleClick(x, y: integer; button: word; shiftstate: word); virtual; procedure HandleMouseEnter; virtual; procedure HandleMouseExit; virtual; + procedure HandleMouseScroll(x, y: integer; shiftstate: word; delta: smallint); virtual; function FindFocusWidget(startwg: TfpgWidget; direction: TFocusSearchDirection): TfpgWidget; procedure HandleAlignments(dwidth, dheight: TfpgCoord); virtual; procedure HandleShow; virtual; @@ -346,6 +348,12 @@ begin FOnMouseExit(Self); end; +procedure TfpgWidget.MsgMouseScroll(var msg: TfpgMessageRec); +begin + HandleMouseScroll(msg.Params.mouse.x, msg.Params.mouse.y, + msg.Params.mouse.shiftstate, msg.Params.mouse.delta); +end; + procedure TfpgWidget.HandleShow; var n: integer; @@ -540,37 +548,42 @@ end; procedure TfpgWidget.HandleRMouseDown(x, y: integer; shiftstate: word); begin - + // do nothing yet end; procedure TfpgWidget.HandleLMouseUp(x, y: integer; shiftstate: word); begin - + // do nothing yet end; procedure TfpgWidget.HandleRMouseUp(x, y: integer; shiftstate: word); begin - + // do nothing yet end; procedure TfpgWidget.HandleMouseMove(x, y: integer; btnstate: word; shiftstate: word); begin - + // do nothing yet end; procedure TfpgWidget.HandleDoubleClick(x, y: integer; button: word; shiftstate: word); begin - + // do nothing yet end; procedure TfpgWidget.HandleMouseEnter; begin - + // do nothing yet end; procedure TfpgWidget.HandleMouseExit; begin + // do nothing yet +end; +procedure TfpgWidget.HandleMouseScroll(x, y: integer; shiftstate: word; delta: smallint); +begin + // do nothing yet end; function TfpgWidget.FindFocusWidget(startwg: TfpgWidget; direction: TFocusSearchDirection): TfpgWidget; diff --git a/prototypes/fpgui2/source/core/x11/fpGFX2.pas b/prototypes/fpgui2/source/core/x11/fpGFX2.pas index 1cd62b83..b48f0672 100644 --- a/prototypes/fpgui2/source/core/x11/fpGFX2.pas +++ b/prototypes/fpgui2/source/core/x11/fpGFX2.pas @@ -7,10 +7,10 @@ unit fpGFX2; interface uses - x11_xft, x11_keyconv, gfxbase, gfxbaseinterfaces, gfx_x11, fpgfx, gfx_stdimages, - gfx_imgfmt_bmp, gfx_widget, gui_form, gui_label, gui_button, gui_edit, - gui_combobox, gui_popupwindow, gui_scrollbar, gui_memo, gfx_UTF8utils, - gui_dialogs, gui_listbox; + x11_xft, x11_keyconv, gfxbase, gfxbaseinterfaces, gfx_x11, fpgfx, + gfx_stdimages, gfx_imgfmt_bmp, gfx_widget, gui_form, gui_label, gui_button, + gui_edit, gui_combobox, gui_popupwindow, gui_scrollbar, gui_memo, + gfx_UTF8utils, gui_dialogs, gui_listbox; implementation diff --git a/prototypes/fpgui2/source/gui/gui_listbox.pas b/prototypes/fpgui2/source/gui/gui_listbox.pas index e8ad4dde..c59b7fe1 100644 --- a/prototypes/fpgui2/source/gui/gui_listbox.pas +++ b/prototypes/fpgui2/source/gui/gui_listbox.pas @@ -32,7 +32,6 @@ type FFirstItem: integer; FMargin: integer; FBackgroundColor: TfpgColor; // This should move to TfpgWidget - procedure DoShow; {override;} procedure SetFirstItem(item: integer); procedure UpdateScrollBar; procedure FollowFocus; @@ -45,6 +44,8 @@ type procedure HandleKeyPress(var keycode: word; var shiftstate: word; var consumed : boolean); override; procedure HandleLMouseDown(x, y: integer; shiftstate: word); override; procedure HandleLMouseUp(x, y: integer; shiftstate: word); override; + procedure HandleMouseMove(x, y: integer; btnstate: word; shiftstate: word); override; + procedure HandleMouseScroll(x, y: integer; shiftstate: word; delta: smallint); override; procedure HandleShow; override; // ToDo // * handle mouse move @@ -65,7 +66,7 @@ type property OnChange: TNotifyEvent read FOnChange write FOnChange; property OnSelect: TNotifyEvent read FOnSelect write FOnSelect; published - property FontName: string read GetFontName write SetFontName; + property FontName: string read GetFontName write SetFontName; end; @@ -123,13 +124,6 @@ begin FScrollBar.UpdateWindowPosition; end; -procedure TfpgBaseListBox.DoShow; -begin - TfpgScrollbarFriend(FScrollBar).SetPosition(Width-18, 0, 18, Height); -// inherited DoShow; - UpdateScrollBar; -end; - procedure TfpgBaseListBox.SetFirstItem(item: integer); begin FFirstItem := item; @@ -222,7 +216,69 @@ end; procedure TfpgBaseListBox.HandleKeyPress(var keycode: word; var shiftstate: word; var consumed: boolean); begin - inherited HandleKeyPress(keycode, shiftstate, consumed); + consumed := true; + case keycode of + KEY_UP: + begin // up + if FFocusItem > 1 then + begin + dec(FFocusItem); + FollowFocus; + RePaint; + DoChange; + end; + end; + KEY_DOWN: + begin // down + if FFocusItem < ItemCount then + begin + inc(FFocusItem); + FollowFocus; + RePaint; + DoChange; + end; + end; + KEY_PGUP: + begin // pgup + dec(FFocusItem,PageLength); + if FFocusItem < 1 then FFocusItem := 1; + FollowFocus; + RePaint; + DoChange; + end; + KEY_PGDN: + begin // pgdown + inc(FFocusItem,PageLength); + if FFocusItem > ItemCount then FFocusItem := ItemCount; + FollowFocus; + RePaint; + DoChange; + end; + KEY_HOME: + begin // home + FFocusItem := 1; + FollowFocus; + RePaint; + DoChange; + end; + KEY_END: + begin // end + FFocusItem := ItemCount; + FollowFocus; + RePaint; + DoChange; + end; + KEY_ENTER: + begin // enter + DoSelect; + consumed := false; // to allow the forms to detect it + end; + else + begin + consumed := false; + inherited HandleKeyPress(keycode, shiftstate, consumed); + end; + end; end; procedure TfpgBaseListBox.HandleLMouseDown(x, y: integer; shiftstate: word); @@ -245,6 +301,65 @@ end; procedure TfpgBaseListBox.HandleLMouseUp(x, y: integer; shiftstate: word); begin inherited HandleLMouseUp(x, y, shiftstate); + if ItemCount < 1 then + Exit; //==> + + FMouseDragging := False; + + FFocusItem := FFirstItem + Trunc((y - FMargin) / RowHeight); + if FFocusItem > ItemCount then + FFocusItem := ItemCount; + + FollowFocus; + Repaint; + DoChange; + DoSelect; +end; + +procedure TfpgBaseListBox.HandleMouseMove(x, y: integer; btnstate: word; shiftstate: word); +var + oldf: integer; +begin + inherited HandleMouseMove(x, y, btnstate, shiftstate); + + if ItemCount < 1 then + Exit; //==> + + if ((not FMouseDragging) or (btnstate and 1 = 0)) and (not HotTrack) then + Exit; //==> + + oldf := FFocusItem; + + FFocusItem := FFirstItem + Trunc((y - FMargin) / RowHeight); + if FFocusItem > ItemCount then + FFocusItem := ItemCount; + + if oldf <> FFocusItem then + begin + FollowFocus; + Repaint; + end; +end; + +procedure TfpgBaseListBox.HandleMouseScroll(x, y: integer; shiftstate: word; delta: smallint); +var + pfi: integer; +begin + pfi := FFirstItem; + if delta > 0 then // scroll down + FFirstItem := FFirstItem + abs(delta) + else // scroll up + FFirstItem := FFirstItem - abs(delta); + + if FFirstItem + PageLength > ItemCount then + FFirstItem := ItemCount - PageLength + 1; + if FFirstItem < 1 then + FFirstItem := 1; + if pfi <> FFirstItem then + begin + UpdateScrollBar; + Repaint; + end; end; procedure TfpgBaseListBox.HandleShow; diff --git a/prototypes/fpgui2/source/gui/gui_scrollbar.pas b/prototypes/fpgui2/source/gui/gui_scrollbar.pas index b76c103c..84fc2859 100644 --- a/prototypes/fpgui2/source/gui/gui_scrollbar.pas +++ b/prototypes/fpgui2/source/gui/gui_scrollbar.pas @@ -18,6 +18,10 @@ type TfpgScrollBar = class(TfpgWidget) private + FMax: integer; + FMin: integer; + FOnScroll: TScrollNotifyEvent; + FPosition: integer; FScrollStep: integer; protected FSliderPos: TfpgCoord; @@ -39,16 +43,16 @@ type procedure HandlePaint; override; procedure PositionChange(d: integer); public - OnScroll: TScrollNotifyEvent; Orientation: TOrientation; - Min: integer; - Max: integer; SliderSize: double; // 0-1 - Position: integer; constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure RepaintSlider; + property Position: integer read FPosition write FPosition default 10; property ScrollStep: integer read FScrollStep write FScrollStep default 1; + property Min: integer read FMin write FMin default 0; + property Max: integer read FMax write FMax default 100; + property OnScroll: TScrollNotifyEvent read FOnScroll write FOnScroll; end; @@ -63,11 +67,11 @@ begin FScrollTimer.Enabled := False; FScrollTimer.OnTimer := @ScrollTimer; Orientation := orVertical; - Min := 0; - Max := 100; - Position := 10; + FMin := 0; + FMax := 100; + FPosition := 10; SliderSize := 0.5; - OnScroll := nil; + FOnScroll := nil; FSliderPos := 0; FSliderDragging := False; FSliderLength := 10; @@ -162,20 +166,20 @@ begin if recalc then begin - if Position > Max then - Position := Max; - if Position < min then - Position := Min; + if FPosition > FMax then + FPosition := FMax; + if FPosition < FMin then + FPosition := FMin; FSliderLength := trunc(area * SliderSize); if FSliderLength < 8 then FSliderLength := 8; area := area - FSliderLength; - mm := Max - Min; + mm := FMax - FMin; if mm = 0 then FSliderPos := 0 else - FSliderPos := Trunc(area * ((Position - min) / mm)); + FSliderPos := Trunc(area * ((FPosition - FMin) / mm)); end; if Orientation = orVertical then @@ -298,30 +302,30 @@ begin DrawSlider(False); if area <> 0 then - newp := Min + trunc((Max - Min) * FSliderPos / area) + newp := FMin + Trunc((FMax - FMin) * FSliderPos / area) else - newp := Min; + newp := FMin; - if newp <> Position then + if newp <> FPosition then begin - Position := newp; - if Assigned(OnScroll) then - OnScroll(self, Position); + FPosition := newp; + if Assigned(FOnScroll) then + FOnScroll(self, FPosition); end; end; procedure TfpgScrollBar.PositionChange(d: integer); begin - Position := Position + d; - if Position < Min then - Position := Min; - if Position > Max then - Position := Max; + FPosition := FPosition + d; + if FPosition < FMin then + FPosition := FMin; + if FPosition > FMax then + FPosition := FMax; DrawSlider(True); - if Assigned(OnScroll) then - OnScroll(self, Position); + if Assigned(FOnScroll) then + FOnScroll(self, FPosition); end; end. |