home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 September / Chip_2001-09_cd1.bin / zkuste / delphi / kolekce / d56 / RMCTL.ZIP / rmInspectorItems.pas < prev    next >
Pascal/Delphi Source File  |  2001-06-22  |  19KB  |  680 lines

  1. {================================================================================
  2. Copyright (C) 1997-2001 Mills Enterprise
  3.  
  4. Unit     : rmInspectorItems
  5. Purpose  : This unit contains the actual implementations of the rmInspectorItem
  6.            items.
  7. Date     : 01-18-2001
  8. Author   : Ryan J. Mills
  9. Version  : 1.80
  10. ================================================================================}
  11.  
  12. unit rmInspectorItems;
  13.  
  14. interface
  15.  
  16. {$I CompilerDefines.INC}
  17.  
  18. uses rmInspector, Controls, stdctrls, classes;
  19.  
  20. {
  21. TrmStringInspectorItem
  22. TrmComplexInspectorItem
  23. TrmComboInspectorItem
  24. TrmIntegerInspectorItem
  25. TrmDateInspectorItem
  26. TrmCheckBoxInspectorItem
  27. }
  28.  
  29.  
  30. type
  31.   TrmStringInspectorItem = class(TrmCustomInspectorItem)
  32.   private
  33.     fValue: string;
  34.     fPassChar: char;
  35.     fMaxLen: integer;
  36.     procedure SetValue(const Value: string);
  37.   protected
  38.     function GetStringValue: string; override;
  39.     procedure SetStringValue(const Value: string); override;
  40.   public
  41.     constructor create(AOwner:TComponent); override;
  42.     function EditorClass: TWinControlClass; override;
  43.     procedure GetValueFromEditor(Editor: TWinControl); override;
  44.     procedure SetValueIntoEditor(Editor: TWinControl); override;
  45.     procedure SetupEditor(Inspector:TrmInspector; Editor:TWinControl); override;
  46.   published
  47.     property MaxLength : integer read fMaxLen write fMaxLen;
  48.     property PasswordChar : char read fPassChar write fPassChar;
  49.     property Value: string read fValue write SetValue;
  50.   end;
  51.  
  52.   TrmComplexInspectorItem = class(TrmCustomInspectorItem)
  53.   private
  54.     fValue: String;
  55.     procedure SetValue(const Value: String);
  56.   protected
  57.     function GetStringValue: string; override;
  58.     procedure SetStringValue(const Value: string); override;
  59.   public
  60.     function EditorClass: TWinControlClass; override;
  61.     procedure GetValueFromEditor(Editor: TWinControl); override;
  62.     procedure SetValueIntoEditor(Editor: TWinControl); override;
  63.     procedure SetupEditor(Inspector:TrmInspector; Editor:TWinControl); override;
  64.   published
  65.     property Value: String read fValue write SetValue;
  66.   end;
  67.  
  68.   TrmComboInspectorItem = class(TrmCustomInspectorItem)
  69.   private
  70.     fValue: String;
  71.     fItems: TStrings;
  72.     function GetItems: TStrings;
  73.     procedure SetItems(const Value: TStrings);
  74.     procedure SetValue(const Value: String);
  75.   protected
  76.     function GetStringValue: string; override;
  77.     procedure SetStringValue(const Value: string); override;
  78.   public
  79.     constructor create(AOwner:TComponent); override;
  80.     destructor destroy; override;
  81.     function EditorClass: TWinControlClass; override;
  82.     procedure GetValueFromEditor(Editor: TWinControl); override;
  83.     procedure SetValueIntoEditor(Editor: TWinControl); override;
  84.     procedure SetupEditor(Inspector:TrmInspector; Editor:TWinControl); override;
  85.   published
  86.     property Value: String read fValue write SetValue;
  87.     property Items: TStrings read GetItems write SetItems;
  88.   end;
  89.  
  90.   TrmIntegerInspectorItem = class(TrmCustomInspectorItem)
  91.   private
  92.     fValue: Integer;
  93.     fUseRange: boolean;
  94.     fMaxValue: integer;
  95.     fMinValue: integer;
  96.     procedure SetMaxValue(const Value: integer);
  97.     procedure SetMinValue(const Value: integer);
  98.     procedure SetUseRange(const Value: boolean);
  99.     procedure SetValue(const Value: integer);
  100.   protected
  101.     function GetStringValue: string; override;
  102.     procedure SetStringValue(const Value: string); override;
  103.   public
  104.     constructor create(AOwner:TComponent); override;
  105.     function EditorClass: TWinControlClass; override;
  106.     procedure GetValueFromEditor(Editor: TWinControl); override;
  107.     procedure SetValueIntoEditor(Editor: TWinControl); override;
  108.     procedure SetupEditor(Inspector:TrmInspector; Editor:TWinControl); override;
  109.   published
  110.     property MinValue:integer read fMinValue write SetMinValue default 0;
  111.     property MaxValue:integer read fMaxValue write SetMaxValue default 1;
  112.     property UseRange:boolean read fUseRange write SetUseRange default false;
  113.     property Value: integer read fValue write SetValue;
  114.   end;
  115.  
  116.   TrmDateInspectorItem = class(TrmCustomInspectorItem)
  117.   private
  118.     fValue: TDate;
  119.     fDateFormat: string;
  120.     procedure SetValue(const Value: TDate);
  121.   protected
  122.     function GetStringValue: string; override;
  123.     procedure SetStringValue(const Value: string); override;
  124.   public
  125.     function EditorClass: TWinControlClass; override;
  126.     procedure GetValueFromEditor(Editor: TWinControl); override;
  127.     procedure SetValueIntoEditor(Editor: TWinControl); override;
  128.     procedure SetupEditor(Inspector:TrmInspector; Editor:TWinControl); override;
  129.   published
  130.     property Value: TDate read fValue write SetValue;
  131.     property DateFormat:string read fDateFormat write fDateFormat;
  132.   end;
  133.  
  134.   TrmCheckBoxInspectorItem = class(TrmCustomInspectorItem)
  135.   private
  136.     fValue: Boolean;
  137.     procedure SetValue(const Value: Boolean);
  138.   protected
  139.     function GetStringValue: string; override;
  140.     procedure SetStringValue(const Value: string); override;
  141.   public
  142.     function EditorClass: TWinControlClass; override;
  143.     procedure GetValueFromEditor(Editor: TWinControl); override;
  144.     procedure SetValueIntoEditor(Editor: TWinControl); override;
  145.     procedure SetupEditor(Inspector:TrmInspector; Editor:TWinControl); override;
  146.   published
  147.     property Value: Boolean read fValue write SetValue;
  148.   end;
  149.  
  150.  
  151. implementation
  152.                                                      
  153. uses windows, SysUtils, Forms, rmBaseEdit, rmBtnEdit, rmBtnCombo, rmCalendar, rmLibrary, rmCheckBox;
  154.  
  155. type
  156.   TrmInspectorInvasion = class(TrmInspector)
  157.   end;
  158.  
  159.   TrmInspectorBtnCombo = class(TrmBtnCombo)
  160.   protected
  161.      procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  162.   end;
  163.  
  164.   TrmInspectorCheckBox = class(TrmCheckBox)
  165.   protected
  166.     procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  167.     procedure keypress(var Key: Char); override;
  168.   end;
  169.  
  170.   TrmInspectorEdit = class(TrmCustomEdit)
  171.   protected
  172.     procedure keypress(var Key: Char); override;
  173.   published
  174.     property Anchors;
  175.     property AutoSelect;
  176.     property AutoSize;
  177.     property BiDiMode;
  178.     property BorderStyle;
  179.     property CharCase;
  180.     property Color;
  181.     property Constraints;
  182.     property Ctl3D;
  183.     property DragCursor;
  184.     property DragKind;
  185.     property DragMode;
  186.     property Enabled;
  187.     property Font;
  188.     property HideSelection;
  189.     property ImeMode;
  190.     property ImeName;
  191.     property MaxLength;
  192.     property OEMConvert;
  193.     property ParentBiDiMode;
  194.     property ParentColor;
  195.     property ParentCtl3D;
  196.     property ParentFont;
  197.     property ParentShowHint;
  198.     property PasswordChar;
  199.     property PopupMenu;
  200.     property ReadOnly;
  201.     property ShowHint;
  202.     property TabOrder;
  203.     property TabStop;
  204.     property Text;
  205.     property Visible;
  206.     property OnChange;
  207.     property OnClick;
  208.     property OnContextPopup;
  209.     property OnDblClick;
  210.     property OnDragDrop;
  211.     property OnDragOver;
  212.     property OnEndDock;
  213.     property OnEndDrag;
  214.     property OnEnter;
  215.     property OnExit;
  216.     property OnKeyDown;
  217.     property OnKeyPress;
  218.     property OnKeyUp;
  219.     property OnMouseDown;
  220.     property OnMouseMove;
  221.     property OnMouseUp;
  222.     property OnStartDock;
  223.     property OnStartDrag;
  224.   end;
  225.  
  226. { TrmStringInspectorItem }
  227.  
  228. constructor TrmStringInspectorItem.create(AOwner: TComponent);
  229. begin
  230.   inherited;
  231.   fMaxLen := 0;
  232.   fPassChar := #0;
  233. end;
  234.  
  235. function TrmStringInspectorItem.EditorClass: TWinControlClass;
  236. begin
  237.   result := TrmInspectorEdit;
  238. end;
  239.  
  240. function TrmStringInspectorItem.GetStringValue: string;
  241. begin
  242.   result := fValue;
  243. end;
  244.  
  245. procedure TrmStringInspectorItem.GetValueFromEditor(Editor: TWinControl);
  246. begin
  247.   if Editor is TrmInspectorEdit then
  248.     Value := TrmInspectorEdit(Editor).Text;
  249. end;
  250.  
  251. procedure TrmStringInspectorItem.SetStringValue(const Value: string);
  252. begin
  253.   fValue := value;
  254.    if assigned(InspectorControl) then
  255.       InspectorControl.Invalidate;
  256. end;
  257.  
  258. procedure TrmStringInspectorItem.SetupEditor(Inspector: TrmInspector;
  259.   Editor: TWinControl);
  260. begin
  261.    if Editor is TrmInspectorEdit then
  262.    begin
  263.       with TrmInspectorEdit(Editor) do
  264.       begin
  265.          BorderStyle := bsNone;
  266.          Font := Inspector.Font;
  267.          WantTabs := true;
  268.          MaxLength := fMaxLen;
  269.          PasswordChar := fPassChar;
  270.       end;
  271.    end;
  272. end;
  273.  
  274. procedure TrmStringInspectorItem.SetValue(const Value: string);
  275. begin
  276.   fValue := Value;
  277.    if assigned(InspectorControl) then
  278.       InspectorControl.Invalidate;
  279. end;
  280.  
  281. procedure TrmStringInspectorItem.SetValueIntoEditor(Editor: TWinControl);
  282. begin
  283.   if Editor is TrmInspectorEdit then
  284.     TrmInspectorEdit(Editor).Text := Value;
  285. end;
  286.  
  287. { TrmComplexInspectorItem }
  288.  
  289. function TrmComplexInspectorItem.EditorClass: TWinControlClass;
  290. begin
  291.    Result := TrmBtnEdit;
  292. end;
  293.  
  294. function TrmComplexInspectorItem.GetStringValue: string;
  295. begin
  296.    result := fValue;
  297. end;
  298.  
  299. procedure TrmComplexInspectorItem.GetValueFromEditor(Editor: TWinControl);
  300. begin
  301.    //Do Nothing...
  302. end;
  303.  
  304. procedure TrmComplexInspectorItem.SetStringValue(const Value: string);
  305. begin
  306.    fValue := Value;
  307.    if assigned(InspectorControl) then
  308.       InspectorControl.Invalidate;
  309. end;
  310.  
  311. procedure TrmComplexInspectorItem.SetupEditor(Inspector: TrmInspector;
  312.   Editor: TWinControl);
  313. begin
  314.    if Editor is TrmBtnEdit then
  315.    begin
  316.       with TrmBtnEdit(Editor) do
  317.       begin
  318.          borderstyle := bsNone;
  319.          Readonly := true;
  320.          font := Inspector.Font;
  321.          WantTabs := true;
  322.          OnBtn1Click := Inspector.DoComplexEdit;
  323.       end;
  324.    end;
  325. end;
  326.  
  327. procedure TrmComplexInspectorItem.SetValue(const Value: String);
  328. begin
  329.   fValue := Value;
  330.    if assigned(InspectorControl) then
  331.       InspectorControl.Invalidate;
  332. end;
  333.  
  334. procedure TrmComplexInspectorItem.SetValueIntoEditor(Editor: TWinControl);
  335. begin
  336.    if Editor is TrmBtnEdit then
  337.       TrmBtnEdit(Editor).text := fValue;
  338. end;
  339.  
  340. { TrmComboInspectorItem }
  341.  
  342. constructor TrmComboInspectorItem.create(AOwner: TComponent);
  343. begin
  344.   inherited;
  345.   fItems := TStringList.Create;
  346. end;
  347.  
  348. destructor TrmComboInspectorItem.destroy;
  349. begin
  350.   fItems.free;
  351.   inherited;
  352. end;
  353.  
  354. function TrmComboInspectorItem.EditorClass: TWinControlClass;
  355. begin
  356.    result := TrmInspectorBtnCombo;
  357. end;
  358.  
  359. function TrmComboInspectorItem.GetItems: TStrings;
  360. begin
  361.    result := fItems;
  362. end;
  363.  
  364. function TrmComboInspectorItem.GetStringValue: string;
  365. begin
  366.    result := fValue;
  367. end;
  368.  
  369. procedure TrmComboInspectorItem.GetValueFromEditor(Editor: TWinControl);
  370. begin
  371.    if editor is TrmInspectorBtnCombo then
  372.       fValue := TrmInspectorBtnCombo(Editor).Text;
  373. end;
  374.  
  375. procedure TrmComboInspectorItem.SetItems(const Value: TStrings);
  376. begin
  377.    fItems.assign(Value);  
  378. end;
  379.  
  380. procedure TrmComboInspectorItem.SetStringValue(const Value: string);
  381. begin
  382.    fValue := Value;
  383.    if assigned(InspectorControl) then
  384.       InspectorControl.Invalidate;
  385. end;
  386.  
  387. procedure TrmComboInspectorItem.SetupEditor(Inspector: TrmInspector;
  388.   Editor: TWinControl);
  389. begin
  390.    if Editor is TrmInspectorBtnCombo then
  391.    begin
  392.       with TrmInspectorBtnCombo(Editor) do
  393.       begin
  394.          borderstyle := bsNone;
  395.          readonly := true;
  396.          font := Inspector.font;
  397.          EllipsisBtnVisible := false;
  398.          WantTabs := true;
  399.          Items.Assign(Self.Items);
  400.       end;
  401.    end;
  402. end;
  403.  
  404. procedure TrmComboInspectorItem.SetValue(const Value: String);
  405. begin
  406.   fValue := Value;
  407.    if assigned(InspectorControl) then
  408.       InspectorControl.Invalidate;
  409. end;
  410.  
  411. procedure TrmComboInspectorItem.SetValueIntoEditor(Editor: TWinControl);
  412. begin
  413.    if editor is TrmInspectorBtnCombo then
  414.       TrmInspectorBtnCombo(Editor).Text := fvalue;
  415. end;
  416.  
  417. { TrmIntegerInspectorItem }
  418.  
  419. constructor TrmIntegerInspectorItem.create(AOwner: TComponent);
  420. begin
  421.   inherited;
  422.   fMaxValue := 1;
  423.   fMinValue := 0;
  424.   fUseRange := false;
  425. end;
  426.  
  427. function TrmIntegerInspectorItem.EditorClass: TWinControlClass;
  428. begin
  429.    Result := TrmInspectorEdit;
  430. end;
  431.  
  432. function TrmIntegerInspectorItem.GetStringValue: string;
  433. begin
  434.    Result := inttostr(fValue);
  435. end;
  436.  
  437. procedure TrmIntegerInspectorItem.GetValueFromEditor(Editor: TWinControl);
  438. begin
  439.    if Editor is TrmInspectorEdit then
  440.       AsString := TrmInspectorEdit(Editor).Text;
  441. end;
  442.  
  443. procedure TrmIntegerInspectorItem.SetMaxValue(const Value: integer);
  444. begin
  445.   if Value > fMinValue then
  446.      fMaxValue := Value;
  447.  
  448.   if fUseRange and (fValue > fMaxValue) then
  449.      fValue := fMaxValue;
  450. end;
  451.  
  452. procedure TrmIntegerInspectorItem.SetMinValue(const Value: integer);
  453. begin
  454.   if Value < fMaxValue then
  455.      fMinValue := Value;
  456.  
  457.   if fUseRange and (fValue < fMinValue) then
  458.      fValue := fMinValue;
  459. end;
  460.  
  461. procedure TrmIntegerInspectorItem.SetStringValue(const Value: string);
  462. var
  463.    wTemp : integer;
  464. begin
  465.    wTemp := strtoint(Value);
  466.    if fUseRange then
  467.    begin
  468.       if (wTemp <= fMaxValue) and (wTemp >= fMinValue) then
  469.          fValue := wTemp
  470.       else
  471.          raise exception.create('Value must be between '+inttostr(fMinValue)+' and '+inttostr(fMaxValue));
  472.    end
  473.    else
  474.       fValue := wTemp;
  475.    if assigned(InspectorControl) then
  476.       InspectorControl.Invalidate;
  477. end;
  478.  
  479. procedure TrmIntegerInspectorItem.SetupEditor(Inspector: TrmInspector;
  480.   Editor: TWinControl);
  481. begin
  482.    if Editor is TrmInspectorEdit then
  483.    begin
  484.       with TrmInspectorEdit(Editor) do
  485.       begin
  486.          Font := Inspector.Font;
  487.          BorderStyle := bsNone;
  488.          WantTabs := true;
  489.       end;
  490.    end;
  491. end;
  492.  
  493. procedure TrmIntegerInspectorItem.SetUseRange(const Value: boolean);
  494. begin
  495.   fUseRange := Value;
  496. end;
  497.  
  498. procedure TrmIntegerInspectorItem.SetValue(const Value: integer);
  499. begin
  500.    if fUseRange then
  501.    begin
  502.       if (Value <= fMaxValue) and (Value >= MinValue) then
  503.          fValue := Value
  504.       else
  505.          raise exception.create('Value must be between '+inttostr(fMinValue)+' and '+inttostr(fMaxValue));
  506.    end
  507.    else
  508.       fValue := Value;
  509.    if assigned(InspectorControl) then
  510.       InspectorControl.Invalidate;
  511. end;
  512.  
  513. procedure TrmIntegerInspectorItem.SetValueIntoEditor(Editor: TWinControl);
  514. begin
  515.    if Editor is TrmInspectorEdit then
  516.       TrmInspectorEdit(Editor).Text := AsString;
  517. end;
  518.  
  519. { TrmDateInspectorItem }
  520.  
  521. function TrmDateInspectorItem.EditorClass: TWinControlClass;
  522. begin
  523.   result := TrmComboCalendar;
  524. end;
  525.  
  526. function TrmDateInspectorItem.GetStringValue: string;
  527. begin
  528.    result := datetostr(fValue);
  529. end;
  530.  
  531. procedure TrmDateInspectorItem.GetValueFromEditor(Editor: TWinControl);
  532. begin
  533.    if Editor is TrmComboCalendar then
  534.       AsString := TrmComboCalendar(Editor).Text;
  535. end;
  536.  
  537. procedure TrmDateInspectorItem.SetStringValue(const Value: string);
  538. begin
  539.    fValue := strtoDate(Value);
  540.    if assigned(InspectorControl) then
  541.       InspectorControl.Invalidate;
  542. end;
  543.  
  544. procedure TrmDateInspectorItem.SetupEditor(Inspector: TrmInspector;
  545.   Editor: TWinControl);
  546. begin
  547.    if Editor is TrmComboCalendar then
  548.    begin
  549.       with TrmComboCalendar(Editor) do
  550.       begin
  551.          Font := Inspector.Font;
  552.          BorderStyle := bsNone;
  553.          WantTabs := true;
  554.          DateFormat := fDateFormat;
  555.       end;
  556.    end;
  557. end;
  558.  
  559. procedure TrmDateInspectorItem.SetValue(const Value: TDate);
  560. begin
  561.   fValue := Value;
  562.    if assigned(InspectorControl) then
  563.       InspectorControl.Invalidate;
  564. end;
  565.  
  566. procedure TrmDateInspectorItem.SetValueIntoEditor(Editor: TWinControl);
  567. begin
  568.    if Editor is TrmComboCalendar then
  569.       TrmComboCalendar(Editor).SelectedDate := Value;
  570. end;
  571.  
  572. { TrmInspectorEdit }
  573.  
  574. procedure TrmInspectorEdit.keypress(var Key: Char);
  575. begin
  576.   inherited;
  577.   if key = #9 then
  578.      key := #0;
  579. end;
  580.  
  581. { TrmInspectorBtnCombo }
  582.  
  583. procedure TrmInspectorBtnCombo.KeyDown(var Key: Word; Shift: TShiftState);
  584. begin
  585.   if (not DroppedDown and ((key = vk_Down) or (key = vk_up)) and (shift = [])) then
  586.   begin
  587.      if Owner is TrmInspector then
  588.         TrmInspectorInvasion(Owner).EditorKeyDown(Self, key, shift);
  589.   end
  590.   else
  591.   inherited;
  592. end;
  593.  
  594. { TrmCheckBoxInspectorItem }
  595.  
  596. function TrmCheckBoxInspectorItem.EditorClass: TWinControlClass;
  597. begin
  598.    result := TrmInspectorCheckBox;
  599. end;
  600.  
  601. function TrmCheckBoxInspectorItem.GetStringValue: string;
  602. begin
  603.    result := booltostr(fValue);
  604. end;
  605.  
  606. procedure TrmCheckBoxInspectorItem.GetValueFromEditor(Editor: TWinControl);
  607. begin
  608.    if Editor is TrmInspectorCheckBox then
  609.       AsString := BoolTostr(TrmInspectorCheckBox(Editor).checked);
  610. end;
  611.  
  612. procedure TrmCheckBoxInspectorItem.SetStringValue(const Value: string);
  613. begin
  614.    fValue := strtoBool(Value);
  615.    if assigned(InspectorControl) then
  616.       InspectorControl.Invalidate;
  617. end;
  618.  
  619. procedure TrmCheckBoxInspectorItem.SetupEditor(Inspector: TrmInspector;
  620.   Editor: TWinControl);
  621. begin
  622.    if Editor is TrmInspectorCheckBox then
  623.    begin
  624.       with TrmInspectorCheckBox(Editor) do
  625.       begin
  626.          Font := Inspector.Font;
  627.          Caption := 'Ryan';
  628.          CBXAlignment := cbxCentered;
  629.          WantTabs := true;
  630.          WantArrows := true;
  631.          Flat := true;
  632.          ShowFocusRect := false;
  633.       end;
  634.    end;
  635. end;
  636.  
  637. procedure TrmCheckBoxInspectorItem.SetValue(const Value: Boolean);
  638. begin
  639.    fValue := value;  
  640.    if assigned(InspectorControl) then
  641.       InspectorControl.Invalidate;
  642. end;
  643.  
  644. procedure TrmCheckBoxInspectorItem.SetValueIntoEditor(Editor: TWinControl);
  645. begin
  646.    if Editor is TrmInspectorCheckBox then
  647.       TrmInspectorCheckBox(Editor).checked := strtobool(AsString);
  648. end;
  649.  
  650. { TrmInspectorCheckBox }
  651.  
  652. { TrmInspectorCheckBox }
  653.  
  654. procedure TrmInspectorCheckBox.KeyDown(var Key: Word; Shift: TShiftState);
  655. begin
  656.   if ((key = vk_Down) or (key = vk_up)) and (shift = []) then
  657.   begin
  658.      if Owner is TrmInspector then
  659.         TrmInspectorInvasion(Owner).EditorKeyDown(Self, key, shift);
  660.   end
  661.   else
  662.   inherited;
  663. end;
  664.  
  665. procedure TrmInspectorCheckBox.keypress(var Key: Char);
  666. begin
  667.   inherited;
  668.   if key = #9 then
  669.      key := #0;
  670. end;
  671.  
  672. initialization
  673.    RegisterClasses([ TrmStringInspectorItem,
  674.                      TrmComplexInspectorItem,
  675.                      TrmComboInspectorItem,
  676.                      TrmIntegerInspectorItem,
  677.                      TrmDateInspectorItem,
  678.                      TrmCheckboxInspectorItem ]);
  679. end.
  680.