1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198:
|
unit Controls.Gui.GhostEdit;
interface
uses Windows , Messages , SysUtils , Variants , Classes , Graphics , Controls , StdCtrls , cxContainer , cxEdit , cxTextEdit ;
type TEdit = class(StdCtrls.TEdit) private FBannerText: String; procedure SetBannerText(const Value: String); protected procedure WMPaint(var Message: TWMPaint); message WM_PAINT; public property BannerText: String read FBannerText write SetBannerText; end;
TcxTextEdit = class(cxTextEdit.TcxTextEdit) public type TcxTextEditProperties = class(cxTextEdit.TcxTextEditProperties) private FBannerText: string; procedure SetBannerText(AValue: string); public property BannerText: string read FBannerText write SetBannerText; class function GetContainerClass: TcxContainerClass; override; procedure PrepareDisplayValue(const AEditValue: TcxEditValue; var DisplayValue: TcxEditValue; AEditFocused: Boolean); override; end; public procedure AdjustInnerEdit; override; class function GetPropertiesClass: TcxCustomEditPropertiesClass; override; procedure PrepareEditValue(const ADisplayValue: TcxEditValue; out EditValue: TcxEditValue; AEditFocused: Boolean); override; end;
implementation
uses cxVariants ;
const ECM_FIRST = $1500; EM_SETCUEBANNER = ECM_FIRST + 1;
function Edit_SetCueBannerText(hEdit: HWND; lpcwText: PWideChar): bool; begin Result := Bool(SendMessage(hEdit,EM_SETCUEBANNER,0,LPARAM(lpcwText))); end;
procedure TEdit.SetBannerText(const Value: String); begin FBannerText := Value; Invalidate; end;
procedure TEdit.WMPaint(var Message: TWMPaint); begin if not (csDesigning in ComponentState) then begin if (Text = '') and (trim(FBannerText) <> '') then begin Edit_SetCueBannerText(Self.Handle,PWideChar(FBannerText)); end; end; inherited; end;
class function TcxTextEdit.TcxTextEditProperties.GetContainerClass: TcxContainerClass; begin Result := TcxTextEdit; end;
procedure TcxTextEdit.TcxTextEditProperties.PrepareDisplayValue(const AEditValue: TcxEditValue; var DisplayValue: TcxEditValue; AEditFocused: Boolean); begin if (VarIsSoftNull(AEditValue)) and (BannerText <> '') then begin if AEditFocused then DisplayValue := '' else if FBannerText <> '' then begin DisplayValue := FBannerText; end else inherited PrepareDisplayValue(0, DisplayValue, AEditFocused) end else inherited; end;
procedure TcxTextEdit.TcxTextEditProperties.SetBannerText(AValue: string); begin if FBannerText <> AValue then begin FBannerText := AValue; Changed; end; end;
type TControlAccess = class(TControl);
procedure TcxTextEdit.AdjustInnerEdit; var AFont: TFont; begin inherited; if TcxTextEditProperties(ActiveProperties).BannerText = '' then Exit; with TControlAccess(InnerTextEdit.Control) do begin InnerEdit.LockBounds(True); AFont := TFont.Create; try if CompareStr(Text, TcxTextEditProperties(ActiveProperties).BannerText) = 0 then begin AFont.Color := clGray; AssignFonts(Font, AFont); end; finally FreeAndNil(AFont); end; InnerEdit.LockBounds(True); end; end;
class function TcxTextEdit.GetPropertiesClass: TcxCustomEditPropertiesClass; begin Result := TcxTextEditProperties; end;
procedure TcxTextEdit.PrepareEditValue(const ADisplayValue: TcxEditValue; out EditValue: TcxEditValue; AEditFocused: Boolean); begin if CompareStr(ADisplayValue, TcxTextEditProperties(ActiveProperties).BannerText) = 0 then EditValue := Null else inherited; end;
end. |