diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-05-23 22:21:26 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-05-23 22:21:26 +0000 |
commit | 5fd1d1516c9e83957f5ed0d51528304320b8ab0d (patch) | |
tree | a52ae09db9cc0062263376b210ef4d9bd269bb6e | |
parent | e29573ef760662063079065e735b2b9047a60eb7 (diff) | |
download | fpGUI-5fd1d1516c9e83957f5ed0d51528304320b8ab0d.tar.xz |
* Minor changes to the Widgettest Edit Form.
* Implemented a very basic TFMemo component. Lots of things
are still outstanding. This is just the beginnings of the
component.
* Updated the WidgetTest example to include a Memo Form
-rw-r--r-- | examples/gui/widgettest/editform.frm | 8 | ||||
-rw-r--r-- | examples/gui/widgettest/mainform.frm | 5 | ||||
-rw-r--r-- | examples/gui/widgettest/widgettest.pas | 68 | ||||
-rw-r--r-- | gui/fpgui.pas | 2 | ||||
-rw-r--r-- | gui/fpguimemo.inc | 295 |
5 files changed, 374 insertions, 4 deletions
diff --git a/examples/gui/widgettest/editform.frm b/examples/gui/widgettest/editform.frm index 9051a927..8e8c97de 100644 --- a/examples/gui/widgettest/editform.frm +++ b/examples/gui/widgettest/editform.frm @@ -42,9 +42,9 @@ object EditForm: TEditForm end
item
Widget = cbBorderStyle
- x = 0
+ x = 2
y = 4
- Width = 3
+ Width = 1
Height = 1
end>
object Label1: TFLabel
@@ -70,7 +70,7 @@ object EditForm: TEditForm OnChange = Edit2Change
end
object GrayCheckBox2: TFCheckBox
- Text = 'Disabled'
+ Text = 'Show Text'
OnClick = GrayCheckBox2Click
end
object PasswordDisplay: TFLabel
@@ -82,4 +82,4 @@ object EditForm: TEditForm OnClick = cbBorderStyleClick
end
end
-end
\ No newline at end of file +end diff --git a/examples/gui/widgettest/mainform.frm b/examples/gui/widgettest/mainform.frm index ce0f8ae6..bf91f0fd 100644 --- a/examples/gui/widgettest/mainform.frm +++ b/examples/gui/widgettest/mainform.frm @@ -70,6 +70,11 @@ object MainForm: TMainForm Text = 'Progress Bar'
OnClick = ProgressBarBtnClick
end
+ object MemoBtn: TFButton
+ CanExpandWidth = True
+ Text = 'Memo widget'
+ OnClick = MemoBtnClick
+ end
object ShowMessageBtn: TFButton
CanExpandWidth = True
Text = 'ShowMessage()'
diff --git a/examples/gui/widgettest/widgettest.pas b/examples/gui/widgettest/widgettest.pas index 2435200e..22a70a89 100644 --- a/examples/gui/widgettest/widgettest.pas +++ b/examples/gui/widgettest/widgettest.pas @@ -22,6 +22,7 @@ type TMenuForm = class; TPanelForm = class; TProgressBarForm = class; + TMemoForm = class; { TMainForm } @@ -39,6 +40,7 @@ type _frmMenu: TMenuForm; _frmPanel: TPanelForm; _frmProgressBar: TProgressBarForm; + _frmMemo: TMemoForm; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; @@ -57,6 +59,7 @@ type MenuBtn: TFButton; PanelBtn: TFButton; ProgressBarBtn: TFButton; + MemoBtn: TFButton; ShowMessageBtn: TFButton; Separator: TSeparator; ExitBtn: TFButton; @@ -73,6 +76,7 @@ type procedure MenuBtnClick(Sender: TObject); procedure PanelBtnClick(Sender: TObject); procedure ProgressBarBtnClick(Sender: TObject); + procedure MemoBtnClick(Sender: TObject); procedure ShowMessageBtnClick(Sender: TObject); end; @@ -247,6 +251,61 @@ type Separator: TSeparator; btnRandom: TFButton; end; + + + { TMemoForm } + + TMemoForm = class(TTestForm) + private + BoxLayout: TFBoxLayout; + Memo: TFMemo; + lblTitle: TFLabel; + public + constructor Create(AOwner: TComponent); override; + end; + +{ TMemoForm } + +constructor TMemoForm.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + Name := 'MemoForm'; + Text := 'Memo Test'; + BorderWidth := 8; + + BoxLayout := TFBoxLayout.Create(self); + BoxLayout.Orientation := Vertical; + self.InsertChild(BoxLayout); + + lblTitle := TFLabel.Create('Work in progress! No mouse or cursor support yet.', self); + lblTitle.FontColor := clBlue; + lblTitle.CanExpandWidth := True; + BoxLayout.InsertChild(lblTitle); + + Memo := TFMemo.Create(self); + BoxLayout.InsertChild(Memo); + + Memo.Lines.Text := + 'constructor TMemoForm.Create(AOwner: TComponent); ' + #10 + + 'begin ' + #10 + + ' inherited Create(AOwner); ' + #10 + + ' Name := ''MemoForm''; ' + #10 + + ' Text := ''Memo Test''; ' + #10 + + ' BorderWidth := 8; ' + #10 + + ' ' + #10 + + ' BoxLayout := TFBoxLayout.Create(self); ' + #10 + + ' BoxLayout.Orientation := Vertical; ' + #10 + + ' self.InsertChild(BoxLayout); ' + #10 + + ' ' + #10 + + ' lblTitle := TFLabel.Create(''Work in progress!'', self); ' + #10 + + ' lblTitle.FontColor := clBlue; ' + #10 + + ' lblTitle.CanExpandWidth := True; ' + #10 + + ' BoxLayout.InsertChild(lblTitle); ' + #10 + + ' ' + #10 + + ' Memo := TFMemo.Create(self); ' + #10 + + ' BoxLayout.InsertChild(Memo); '; +end; + { TListBoxForm } @@ -480,6 +539,7 @@ begin _frmMenu.Free; _frmPanel.Free; _frmProgressBar.Free; + _frmMemo.Free; inherited Destroy; end; @@ -586,6 +646,14 @@ begin _frmProgressBar.SetPosition(Point(Left + Width + 5, FindForm.Top)); end; +procedure TMainForm.MemoBtnClick(Sender: TObject); +begin + if not Assigned(_frmMemo) then + _frmMemo := TMemoForm.Create(self); + _frmMemo.Show; + _frmMemo.SetPosition(Point(Left + Width + 5, FindForm.Top)); +end; + procedure TMainForm.ShowMessageBtnClick(Sender: TObject); begin ShowMessage('Hello World!'); diff --git a/gui/fpgui.pas b/gui/fpgui.pas index ac69f788..ca17a278 100644 --- a/gui/fpgui.pas +++ b/gui/fpgui.pas @@ -145,6 +145,7 @@ type {$I fpguipanel.inc} {$I fpguimenus.inc} {$I fpguiprogressbar.inc} +{$I fpguimemo.inc} function ClipMinMax(val, min, max: Integer): Integer; @@ -334,6 +335,7 @@ end; {$I fpguipanel.inc} {$I fpguimenus.inc} {$I fpguiprogressbar.inc} +{$I fpguimemo.inc} const diff --git a/gui/fpguimemo.inc b/gui/fpguimemo.inc new file mode 100644 index 00000000..c9682e2d --- /dev/null +++ b/gui/fpguimemo.inc @@ -0,0 +1,295 @@ +{ + fpGUI - Free Pascal GUI Library + + Memo class declarations + + Copyright (C) 2000 - 2007 See the file AUTHORS.txt, included in this + distribution, for details of the copyright. + + See the file COPYING.modifiedLGPL, included in this distribution, + for details about redistributing fpGUI. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +} + +{%mainunit fpgui.pas} + +{$IFDEF read_interface} + + + { TFCustomMemo } + + TFCustomMemo = class(TFWidget) + private + FLines: TStrings; + function EvMousePressed(Event: TMousePressedEventObj): Boolean; + function EvMouseReleased(Event: TMouseReleasedEventObj): Boolean; + function EvMouseMoved(Event: TMouseMoveEventObj): Boolean; + function ProcessMouseEvent(Event: TMouseEventObj): Boolean; + protected + FScrollingSupport: TScrollingSupport; + FMaxItemWidth: Integer; + FItemHeight: Integer; + procedure SetLines(const AValue: TStrings); + procedure Paint(Canvas: TFCanvas); override; + function ProcessEvent(Event: TEventObj): Boolean; override; + function DistributeEvent(Event: TEventObj): Boolean; override; + procedure CalcSizes; override; + procedure UpdateScrollBars; + procedure RecalcWidth; + procedure Resized; override; + public + constructor Create(AOwner: TComponent); override; + destructor Destroy; override; + property Lines: TStrings read FLines write SetLines; + end; + + + TFMemo = class(TFCustomMemo) + published +// property Alignment; +// property BorderStyle; +// property Color; + property Enabled; + property Lines; +// property MaxLength; + end; +{$ENDIF read_interface} + + + +{$IFDEF read_implementation} + +type + + TFMemoStrings = class(TStringList) + protected + Memo: TFCustomMemo; + procedure SetUpdateState(Updating: Boolean); override; + public + constructor Create(AMemo: TFCustomMemo); + function Add(const s: String): Integer; override; + end; + + +constructor TFMemoStrings.Create(AMemo: TFCustomMemo); +begin + inherited Create; + Memo := AMemo; +end; + +function TFMemoStrings.Add(const s: String): Integer; +var + ItemWidth: Integer; +begin + Result := inherited Add(s); + if Assigned(Memo.FindForm) and Assigned(Memo.FindForm.Wnd) then + begin + ItemWidth := Memo.FindForm.Wnd.Canvas.TextWidth(s) + 4; + if ItemWidth > Memo.FMaxItemWidth then + Memo.FMaxItemWidth := ItemWidth; + Memo.UpdateScrollBars; + end; +end; + +procedure TFMemoStrings.SetUpdateState(Updating: Boolean); +begin + if not Updating then + Memo.RecalcWidth; +end; + + +{ TFCustomMemo } + +function TFCustomMemo.EvMousePressed(Event: TMousePressedEventObj): Boolean; +begin + +end; + +function TFCustomMemo.EvMouseReleased(Event: TMouseReleasedEventObj): Boolean; +begin + +end; + +function TFCustomMemo.EvMouseMoved(Event: TMouseMoveEventObj): Boolean; +begin + +end; + +function TFCustomMemo.ProcessMouseEvent(Event: TMouseEventObj): Boolean; +var + Index: Integer; +begin + if not PtInRect(FScrollingSupport.ClientRect, Event.Position) then + begin + Result := False; + exit; + end; +{ // Graeme: TODO + + Index := (Event.Position.y - FScrollingSupport.ClientRect.Top + + FScrollingSupport.VerTFScrollBar.Position) div FItemHeight; + if (Index >= 0) and (Index < FLines.Count) and ((Index <> FItemIndex) or + (HotTrack and Event.InheritsFrom(TMouseReleasedEventObj))) then + begin + RedrawItem(ItemIndex); + FItemIndex := Index; + RedrawItem(ItemIndex); + if (not Event.InheritsFrom(TMouseMoveEventObj)) and Assigned(OnClick) then + OnClick(Self); + end; +} + Result := True; +end; + +procedure TFCustomMemo.SetLines(const AValue: TStrings); +begin + FLines.Assign(AValue); +end; + +procedure TFCustomMemo.Paint(Canvas: TFCanvas); +var + i, StartIndex, EndIndex: Integer; + ItemRect: TRect; + ItemFlags: TItemFlags; +begin + inherited Paint(Canvas); + + if not Canvas.IntersectClipRect(FScrollingSupport.ClientRect) then + Exit; //==> + + Style.SetUIColor(Canvas, clWindow); + Canvas.FillRect(FScrollingSupport.ClientRect); + Style.SetUIColor(Canvas, clWindowText); + + with FScrollingSupport.VerTFScrollBar do + begin + StartIndex := Position div FItemHeight; + EndIndex := (Position + PageSize) div FItemHeight; + end; + + Canvas.AppendTranslation(FScrollingSupport.ClientRect.TopLeft - FScrollingSupport.ScrollPos); + + if StartIndex < 0 then + StartIndex := 0; + if EndIndex >= FLines.Count then + EndIndex := FLines.Count - 1; + + for i := StartIndex to EndIndex do + begin + Canvas.SaveState; + + ItemRect.Left := FScrollingSupport.HorzScrollBar.Position; + ItemRect.Top := i * FItemHeight; + ItemRect.Right := FScrollingSupport.ClientRect.Right + - FScrollingSupport.ClientRect.Left + + FScrollingSupport.HorzScrollBar.Position; + ItemRect.Bottom := (i + 1) * FItemHeight; + + Canvas.IntersectClipRect(ItemRect); + + ItemFlags := []; +// if (wsHasFocus in WidgetState) and ((i = ItemIndex) or +// ((ItemIndex = -1) and (i = 0))) then +// Include(ItemFlags, ifFocused); +// if i = ItemIndex then +// Include(ItemFlags, ifSelected); + +// Style.DrawItemBefore(Canvas, ItemRect, ItemFlags); + Style.DrawText(Canvas, Point(2, i * FItemHeight), FLines[i], WidgetState); +// Style.DrawItemAfter(Canvas, ItemRect, ItemFlags); + + Canvas.RestoreState; + end; +end; + +function TFCustomMemo.ProcessEvent(Event: TEventObj): Boolean; +begin + if Event.InheritsFrom(TMousePressedEventObj) then + Result := FScrollingSupport.ProcessEvent(Event) or + EvMousePressed(TMousePressedEventObj(Event)) or + inherited ProcessEvent(Event) + else if Event.InheritsFrom(TMouseReleasedEventObj) then + Result := FScrollingSupport.ProcessEvent(Event) or + EvMouseReleased(TMouseReleasedEventObj(Event)) or + inherited ProcessEvent(Event) + else if Event.InheritsFrom(TMouseMoveEventObj) then + Result := FScrollingSupport.ProcessEvent(Event) or + EvMouseMoved(TMouseMoveEventObj(Event)) or + inherited ProcessEvent(Event) + else + Result := FScrollingSupport.ProcessEvent(Event) or + inherited ProcessEvent(Event); +end; + +function TFCustomMemo.DistributeEvent(Event: TEventObj): Boolean; +begin + Result := FScrollingSupport.DistributeEvent(Event) or + inherited DistributeEvent(Event); +end; + +procedure TFCustomMemo.CalcSizes; +begin + FScrollingSupport.CalcSizes; + FItemHeight := FindForm.Wnd.Canvas.FontCellHeight; + FScrollingSupport.VerTFScrollBar.SmallChange := FItemHeight; + RecalcWidth; +end; + +procedure TFCustomMemo.UpdateScrollBars; +begin + FScrollingSupport.SetVirtualSize(Size(FMaxItemWidth, FLines.Count * FItemHeight - 1)); +end; + +procedure TFCustomMemo.RecalcWidth; +var + i, ItemWidth: Integer; +begin + if (not Assigned(FindForm)) or (not Assigned(FindForm.Wnd)) then + Exit; //==> + + FMaxItemWidth := 0; + for i := 0 to FLines.Count - 1 do + begin + ItemWidth := FindForm.Wnd.Canvas.TextWidth(FLines[i]) + 4; + if ItemWidth > FMaxItemWidth then + FMaxItemWidth := ItemWidth; + end; + UpdateScrollBars; +end; + +procedure TFCustomMemo.Resized; +begin + FScrollingSupport.Resized; + UpdateScrollBars; +end; + +constructor TFCustomMemo.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + WidgetStyle := WidgetStyle + [wsCaptureMouse, wsClickable, wsOpaque]; + FCanExpandWidth := True; + FCanExpandHeight := True; + + FScrollingSupport := TScrollingSupport.Create(Self); + FScrollingSupport.HorzScrollBar.OnScroll := @FScrollingSupport.DefHorzScrollHandler; + FScrollingSupport.VerTFScrollBar.OnScroll := @FScrollingSupport.DefVertScrollHandler; + + FLines := TFMemoStrings.Create(self); +// SetBounds(10, 10, 180, 90); + UpdateScrollBars; +end; + +destructor TFCustomMemo.Destroy; +begin + FLines.Free; + FScrollingSupport.Free; + inherited Destroy; +end; + + +{$ENDIF read_implementation} + + |