diff options
author | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2010-04-15 17:07:50 +0200 |
---|---|---|
committer | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2010-04-15 17:07:50 +0200 |
commit | 3bf2023bbc715575512faf590fe416d48467c7ff (patch) | |
tree | 6f2b57f5403ce056d0fa04fb159b799462a6558e | |
parent | 062b4b964ef4be4495bf8e3ae18db4efa093cf11 (diff) | |
download | fpGUI-3bf2023bbc715575512faf590fe416d48467c7ff.tar.xz |
New unit fpg_editbtn.pas: Adds TfpgFileNameEdit component.
-rw-r--r-- | src/corelib/gdi/fpgui_toolkit.lpk | 6 | ||||
-rw-r--r-- | src/corelib/gdi/fpgui_toolkit.pas | 48 | ||||
-rw-r--r-- | src/corelib/x11/fpgui_toolkit.lpk | 6 | ||||
-rw-r--r-- | src/corelib/x11/fpgui_toolkit.pas | 21 | ||||
-rw-r--r-- | src/gui/fpg_editbtn.pas | 180 |
5 files changed, 224 insertions, 37 deletions
diff --git a/src/corelib/gdi/fpgui_toolkit.lpk b/src/corelib/gdi/fpgui_toolkit.lpk index d3856084..36e40d61 100644 --- a/src/corelib/gdi/fpgui_toolkit.lpk +++ b/src/corelib/gdi/fpgui_toolkit.lpk @@ -31,7 +31,7 @@ <Description Value="fpGUI Toolkit"/>
<License Value="LGPL 2 with static linking exception."/>
<Version Minor="7"/>
- <Files Count="74">
+ <Files Count="75">
<Item1>
<Filename Value="..\stdimages.inc"/>
<Type Value="Include"/>
@@ -328,6 +328,10 @@ <Filename Value="fpg_interface.pas"/>
<UnitName Value="fpg_interface"/>
</Item74>
+ <Item75>
+ <Filename Value="..\..\gui\fpg_editbtn.pas"/>
+ <UnitName Value="fpg_editbtn"/>
+ </Item75>
</Files>
<LazDoc Paths="..\..\..\docs\xml\corelib\;..\..\..\docs\xml\corelib\x11\;..\..\..\docs\xml\corelib\gdi\;..\..\..\docs\xml\gui\"/>
<RequiredPkgs Count="1">
diff --git a/src/corelib/gdi/fpgui_toolkit.pas b/src/corelib/gdi/fpgui_toolkit.pas index 607ac0bc..90e84c74 100644 --- a/src/corelib/gdi/fpgui_toolkit.pas +++ b/src/corelib/gdi/fpgui_toolkit.pas @@ -1,24 +1,24 @@ -{ This file was automatically created by Lazarus. do not edit! - This source is only used to compile and install the package. - } - -unit fpgui_toolkit; - -interface - -uses - fpg_base, fpg_main, fpg_cmdlineparams, fpg_command_intf, fpg_constants, - fpg_extinterpolation, fpg_imagelist, fpg_imgfmt_bmp, fpg_pofiles, - fpg_popupwindow, fpg_stdimages, fpg_stringhashlist, fpg_translations, - fpg_stringutils, fpg_utils, fpg_widget, fpg_wuline, fpg_animation, - fpg_basegrid, fpg_button, fpg_checkbox, fpg_combobox, fpg_customgrid, - fpg_dialogs, fpg_editcombo, fpg_edit, fpg_form, fpg_gauge, fpg_grid, - fpg_hyperlink, fpg_iniutils, fpg_label, fpg_listbox, fpg_listview, fpg_memo, - fpg_menu, fpg_mru, fpg_panel, fpg_popupcalendar, fpg_progressbar, - fpg_radiobutton, fpg_scrollbar, fpg_style, fpg_tab, fpg_trackbar, fpg_tree, - fpgui_db, fpg_gdi, fpg_impl, fpg_splitter, fpg_hint, fpg_spinedit, - fpg_extgraphics, fpg_ColorMapping, fpg_ColorWheel, fpg_interface; - -implementation - -end. +{ This file was automatically created by Lazarus. do not edit!
+ This source is only used to compile and install the package.
+ }
+
+unit fpgui_toolkit;
+
+interface
+
+uses
+ fpg_base, fpg_main, fpg_cmdlineparams, fpg_command_intf, fpg_constants,
+ fpg_extinterpolation, fpg_imagelist, fpg_imgfmt_bmp, fpg_pofiles,
+ fpg_popupwindow, fpg_stdimages, fpg_stringhashlist, fpg_translations,
+ fpg_stringutils, fpg_utils, fpg_widget, fpg_wuline, fpg_animation,
+ fpg_basegrid, fpg_button, fpg_checkbox, fpg_combobox, fpg_customgrid,
+ fpg_dialogs, fpg_editcombo, fpg_edit, fpg_form, fpg_gauge, fpg_grid,
+ fpg_hyperlink, fpg_iniutils, fpg_label, fpg_listbox, fpg_listview, fpg_memo,
+ fpg_menu, fpg_mru, fpg_panel, fpg_popupcalendar, fpg_progressbar,
+ fpg_radiobutton, fpg_scrollbar, fpg_style, fpg_tab, fpg_trackbar, fpg_tree,
+ fpgui_db, fpg_gdi, fpg_impl, fpg_splitter, fpg_hint, fpg_spinedit,
+ fpg_extgraphics, fpg_ColorMapping, fpg_ColorWheel, fpg_interface, fpg_editbtn;
+
+implementation
+
+end.
diff --git a/src/corelib/x11/fpgui_toolkit.lpk b/src/corelib/x11/fpgui_toolkit.lpk index 4670bf77..9f5476d3 100644 --- a/src/corelib/x11/fpgui_toolkit.lpk +++ b/src/corelib/x11/fpgui_toolkit.lpk @@ -32,7 +32,7 @@ <License Value="LGPL 2 with static linking exception. "/> <Version Minor="7"/> - <Files Count="78"> + <Files Count="79"> <Item1> <Filename Value="../stdimages.inc"/> <Type Value="Include"/> @@ -345,6 +345,10 @@ <Filename Value="fpg_interface.pas"/> <UnitName Value="fpg_interface"/> </Item78> + <Item79> + <Filename Value="../../gui/fpg_editbtn.pas"/> + <UnitName Value="fpg_editbtn"/> + </Item79> </Files> <LazDoc Paths="../../../docs/xml/corelib/;../../../docs/xml/corelib/x11/;../../../docs/xml/corelib/gdi/;../../../docs/xml/gui/"/> <RequiredPkgs Count="1"> diff --git a/src/corelib/x11/fpgui_toolkit.pas b/src/corelib/x11/fpgui_toolkit.pas index d6531ef9..caa8c921 100644 --- a/src/corelib/x11/fpgui_toolkit.pas +++ b/src/corelib/x11/fpgui_toolkit.pas @@ -1,4 +1,4 @@ -{ This file was automatically created by Lazarus. do not edit! +{ This file was automatically created by Lazarus. do not edit ! This source is only used to compile and install the package. } @@ -8,17 +8,16 @@ interface uses fpg_base, fpg_main, fpg_cmdlineparams, fpg_command_intf, fpg_constants, - fpg_extinterpolation, fpg_imagelist, fpg_imgfmt_bmp, fpg_pofiles, - fpg_popupwindow, fpg_stdimages, fpg_stringhashlist, fpg_translations, - fpg_stringutils, fpg_utils, fpg_widget, fpg_wuline, fpg_impl, fpg_x11, - fpg_netlayer_x11, fpg_keyconv_x11, fpg_xft_x11, fpg_animation, fpg_basegrid, - fpg_button, fpg_checkbox, fpg_combobox, fpg_customgrid, fpg_dialogs, - fpg_editcombo, fpg_edit, fpg_form, fpg_gauge, fpg_grid, fpg_hyperlink, - fpg_iniutils, fpg_label, fpg_listbox, fpg_listview, fpg_memo, fpg_menu, + fpg_extinterpolation, fpg_imagelist, fpg_imgfmt_bmp, fpg_pofiles, fpg_popupwindow, + fpg_stdimages, fpg_stringhashlist, fpg_translations, fpg_stringutils, fpg_utils, + fpg_widget, fpg_wuline, fpg_impl, fpg_x11, fpg_netlayer_x11, fpg_keyconv_x11, + fpg_xft_x11, fpg_animation, fpg_basegrid, fpg_button, fpg_checkbox, fpg_combobox, + fpg_customgrid, fpg_dialogs, fpg_editcombo, fpg_edit, fpg_form, fpg_gauge, fpg_grid, + fpg_hyperlink, fpg_iniutils, fpg_label, fpg_listbox, fpg_listview, fpg_memo, fpg_menu, fpg_mru, fpg_panel, fpg_popupcalendar, fpg_progressbar, fpg_radiobutton, - fpg_scrollbar, fpg_style, fpg_tab, fpg_trackbar, fpg_tree, fpgui_db, - fpg_splitter, fpg_hint, fpg_spinedit, fpg_extgraphics, fpg_ColorMapping, - fpg_ColorWheel, fpg_interface; + fpg_scrollbar, fpg_style, fpg_tab, fpg_trackbar, fpg_tree, fpgui_db, fpg_splitter, + fpg_hint, fpg_spinedit, fpg_extgraphics, fpg_ColorMapping, fpg_ColorWheel, + fpg_interface, fpg_editbtn; implementation diff --git a/src/gui/fpg_editbtn.pas b/src/gui/fpg_editbtn.pas new file mode 100644 index 00000000..12c5a8ef --- /dev/null +++ b/src/gui/fpg_editbtn.pas @@ -0,0 +1,180 @@ +{ + fpGUI - Free Pascal GUI Toolkit + + Copyright (C) 2006 - 2010 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. + + Description: + Defines a Text Edit control. Also known a Text Entry control. +} + +unit fpg_editbtn; + +{$mode objfpc}{$H+} + +interface + +uses + Classes + ,fpg_base + ,fpg_main + ,fpg_widget + ,fpg_edit + ,fpg_button + ; + +type + TfpgFileNameEdit = class(TfpgWidget) + private + FEdit: TfpgEdit; + FButton: TfpgButton; + FFilter: TfpgString; + FOnButtonClick: TNotifyEvent; + FInitialDir: TfpgString; + procedure SetFilter(const AValue: TfpgString); + procedure btnClick(Sender: TObject); + procedure SetFileName(const AValue: TfpgString); + function GetFileName: TfpgString; + protected + procedure HandlePaint; override; + public + constructor Create(AOwner: TComponent); override; + procedure SetPosition(aleft, atop, awidth, aheight: TfpgCoord); override; + published + property FileName: TfpgString read GetFileName write SetFileName; + property InitialDir: TfpgString read FInitialDir write FInitialDir; + property Filter: TfpgString read FFilter write SetFilter; + property TabOrder; + property OnButtonClick: TNotifyEvent read FOnButtonClick write FOnButtonClick; + //property OnEnter; + //property OnExit; + //property OnKeyPress; + //property OnMouseEnter; + //property OnMouseExit; + //property OnPaint; + end; + + +implementation + +uses + fpg_constants + ,fpg_dialogs + ,fpg_utils + ; + +constructor TfpgFileNameEdit.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + FIsContainer := True; + FFocusable := False; + FFilter := ''; + FEdit := TfpgEdit.Create(self); + with FEdit do + begin + Name := 'FEdit'; + Text := ''; + FontDesc := '#Edit1'; + TabOrder := 0; + end; + FButton := TfpgButton.Create(self); + with FButton do + begin + Name := 'FButton'; + Text := ''; + FontDesc := '#Label1'; + ImageMargin := 1; + ImageName := 'stdimg.folderopen'; + TabOrder := 1; + OnClick := @btnClick; + end; +end; + +procedure TfpgFileNameEdit.SetFilter(const AValue: TfpgString); +begin + FFilter := AValue; +end; + +procedure TfpgFileNameEdit.SetPosition(aleft, atop, awidth, aheight: TfpgCoord); +begin + inherited SetPosition(aleft, atop, awidth, aheight); + FEdit.SetPosition(0, 0, Width - Height, Height); + FButton.SetPosition(Width - Height, 0, Height, Height); +end; + +procedure TfpgFileNameEdit.btnClick(Sender: TObject); +var + dlg: TfpgFileDialog; +begin + dlg := TfpgFileDialog.Create(nil); + try + if FileName = '' then + begin + if FInitialDir <> '' then + dlg.InitialDir := FInitialDir; + end + else + begin + // Use path of existing filename + dlg.InitialDir := fpgExtractFilePath(FileName); + if dlg.InitialDir = '' then // FileName had no path + dlg.InitialDir := FInitialDir; + end; + if FFilter = '' then + dlg.Filter := rsAllFiles + ' (' + AllFilesMask + ')' + '|' + AllFilesMask + else + dlg.Filter := FFilter + '|' + rsAllFiles + ' (' + AllFilesMask + ')' + '|' + AllFilesMask; + if dlg.RunOpenFile then + begin + FEdit.Text := dlg.FileName; + end; + finally + dlg.Free; + end; + if Assigned(OnButtonClick) then + OnButtonClick(self); +end; + +procedure TfpgFileNameEdit.SetFileName(const AValue: TfpgString); +begin + FEdit.Text := AValue; +end; + +function TfpgFileNameEdit.GetFileName: TfpgString; +begin + Result := FEdit.Text; +end; + +procedure TfpgFileNameEdit.HandlePaint; +var + fnt: TfpgFont; +begin + inherited HandlePaint; + // only so that it looks pretty in the UI Designer + if csDesigning in ComponentState then + begin + FEdit.Visible := False; + FButton.Visible := False; + Canvas.Clear(clBoxColor); + fpgStyle.DrawControlFrame(Canvas, 0, 0, Width - Height, Height); + fpgStyle.DrawButtonFace(Canvas, Width - Height, 0, Height, Height, [btfIsEmbedded]); + Canvas.TextColor := clShadow1; + Canvas.DrawText(0, 0, Width - Height, Height, ClassName, [txtHCenter, txtVCenter]); + Canvas.TextColor := clText1; + fnt := fpgGetFont('DeJaVu-9:bold'); + Canvas.SetFont(fnt); + Canvas.DrawText(Width - Height, 0, Height, Height, 'ยทยทยท', [txtHCenter, txtVCenter]); + fnt.Free; + end; +end; + + +end. + |