MODULE Find; (* ========================================================================= Find Text Dialog Author : Chris Burrows Created: May 2007 (c) 2007-2008 CFB Software http://www.cfbsoftware.com/cpide ========================================================================= *) IMPORT Sys := "[mscorlib]System", Cpm := "[System]System.ComponentModel", Wfm := "[System.Windows.Forms]System.Windows.Forms", Drw := "[System.Drawing]System.Drawing", Data := "[System.Data]System.Data"; TYPE FindForm* = POINTER TO EXTENSIBLE RECORD (Wfm.Form) components: Cpm.Container; labelFind: Wfm.Label; cboFind*: Wfm.ComboBox; btnFindFirst: Wfm.Button; btnFindNext: Wfm.Button; checkMatch: Wfm.CheckBox; checkCase: Wfm.CheckBox; btnCancel: Wfm.Button; wholeWord*: BOOLEAN; matchCase*: BOOLEAN; findFirst*: BOOLEAN; findText*: Sys.String END; (* ==================================================================== *) PROCEDURE (frm: FindForm) Dispose*(disposing: BOOLEAN); BEGIN IF disposing THEN IF frm.components # NIL THEN frm.components.Dispose() END; frm.Dispose^(disposing) END END Dispose; (* ==================================================================== *) PROCEDURE (frm: FindForm) DoFind*(), NEW, EXTENSIBLE; BEGIN frm.findText := ''; frm.findFirst := TRUE; frm.wholeWord := FALSE; frm.matchCase := FALSE END DoFind; (* ==================================================================== *) PROCEDURE (frm: FindForm) OnActivatedAction(sender: Sys.Object; e: Sys.EventArgs), NEW; VAR b: BOOLEAN; BEGIN b := frm.cboFind.Focus() END OnActivatedAction; (* ==================================================================== *) PROCEDURE (frm: FindForm) btnFindClick(sender: Sys.Object; e: Sys.EventArgs), NEW; BEGIN frm.findText := frm.cboFind.get_Text(); IF frm.findText # '' THEN frm.cboFind.get_Items().Remove(frm.findText); frm.cboFind.get_Items().Insert(0, frm.findText); frm.cboFind.set_Text(frm.findText) END; frm.findFirst := sender(Wfm.Button) = frm.btnFindFirst; frm.wholeWord := frm.checkMatch.get_Checked(); frm.matchCase := frm.checkCase.get_Checked(); frm.DoFind() END btnFindClick; (* ==================================================================== *) PROCEDURE (frm: FindForm) btnCancelClick(sender: Sys.Object; e: Sys.EventArgs), NEW; BEGIN frm.Hide() END btnCancelClick; (* ==================================================================== *) PROCEDURE (frm: FindForm) OnClosingAction(sender: Sys.Object; e: Wfm.FormClosingEventArgs), NEW; BEGIN IF frm = Wfm.Form.get_ActiveForm() THEN e.set_Cancel(TRUE); frm.Hide() END END OnClosingAction; (* ==================================================================== *) PROCEDURE (frm: FindForm) NewLabel(VAR lbl: Wfm.Label; s: Sys.String; col, row: INTEGER), NEW; BEGIN NEW(lbl); lbl.set_Location(Drw.Point.init(col, row)); lbl.set_Text(s); lbl.set_AutoSize(TRUE); frm.get_Controls().Add(lbl) END NewLabel; (* ==================================================================== *) PROCEDURE (frm: FindForm) NewButton(VAR button: Wfm.Button; s: Sys.String; col, row: INTEGER), NEW; BEGIN NEW(button); button.set_FlatStyle(Wfm.FlatStyle.System); button.set_Location(Drw.Point.init(col, row)); button.set_Text(s); frm.get_Controls().Add(button) END NewButton; (* ==================================================================== *) PROCEDURE (frm: FindForm) NewCheckBox(VAR checkBox: Wfm.CheckBox; s: Sys.String; width, col, row: INTEGER), NEW; BEGIN NEW(checkBox); checkBox.set_Location(Drw.Point.init(col, row)); checkBox.set_Text(s); checkBox.set_Size(Drw.Size.init(width, 20)); frm.get_Controls().Add(checkBox) END NewCheckBox; (* ==================================================================== *) PROCEDURE (frm: FindForm) NewComboBox(VAR cb: Wfm.ComboBox; width, col, row: INTEGER), NEW; BEGIN NEW(cb); cb.set_Location(Drw.Point.init(col, row)); cb.set_Size(Drw.Size.init(width, 20)); frm.get_Controls().Add(cb) END NewComboBox; (* ==================================================================== *) PROCEDURE (frm: FindForm) InitializeComponent*(), NEW; CONST labelWidth = 100; textWidth = 150; rowHeight = 16; spacer = 12; col1 = spacer; col2 = col1 + labelWidth + spacer; col3 = col2 + textWidth + spacer; VAR frmSize: Drw.Size; i, row: INTEGER; BEGIN NEW(frm.components); frm.SuspendLayout(); row := rowHeight; frm.NewLabel(frm.labelFind, "Find what:", col1, row); frm.NewComboBox(frm.cboFind, textWidth, col2, row); frm.NewButton(frm.btnFindFirst, "&Find First", col3, row); REGISTER(frm.btnFindFirst.Click, frm.btnFindClick); INC(row, 2 * rowHeight); frm.NewCheckBox(frm.checkMatch, "Exact matches", labelWidth, col1, row); frm.NewCheckBox(frm.checkCase, "Case sensitive", labelWidth, col2, row); frm.NewButton(frm.btnFindNext, "Find &Next", col3, row); frm.set_AcceptButton(frm.btnFindNext); REGISTER(frm.btnFindNext.Click, frm.btnFindClick); INC(row, 2 * rowHeight); frm.NewButton(frm.btnCancel, "Close", col3, row); frm.set_CancelButton(frm.btnCancel); REGISTER(frm.btnCancel.Click, frm.btnCancelClick); REGISTER(frm.Activated, frm.OnActivatedAction); REGISTER(frm.FormClosing, frm.OnClosingAction); INC(row, 2 * rowHeight); frm.set_StartPosition(Wfm.FormStartPosition.CenterScreen); frm.set_Text("Find"); frm.set_AutoScaleBaseSize(Drw.Size.init(5, 13)); frm.set_ClientSize(Drw.Size.init(col3 + frm.btnFindFirst.get_Width() + spacer, row)); frm.set_FormBorderStyle(Wfm.FormBorderStyle.FixedDialog); frm.set_MinimizeBox(FALSE); frm.set_MaximizeBox(FALSE); frm.ResumeLayout(FALSE) END InitializeComponent; END Find.