[672] | 1 |
|
---|
| 2 | {*****************************************************************************}
|
---|
| 3 | { }
|
---|
| 4 | { Tnt Delphi Unicode Controls }
|
---|
| 5 | { http://www.tntware.com/delphicontrols/unicode/ }
|
---|
| 6 | { Version: 2.3.0 }
|
---|
| 7 | { }
|
---|
| 8 | { Copyright (c) 2002-2007, Troy Wolbrink (troy.wolbrink@tntware.com) }
|
---|
| 9 | { }
|
---|
| 10 | {*****************************************************************************}
|
---|
| 11 |
|
---|
| 12 | unit TntGrids;
|
---|
| 13 |
|
---|
| 14 | {$INCLUDE TntCompilers.inc}
|
---|
| 15 |
|
---|
| 16 | interface
|
---|
| 17 |
|
---|
| 18 | uses
|
---|
| 19 | Classes, TntClasses, Grids, Windows, Controls, Messages;
|
---|
| 20 |
|
---|
| 21 | type
|
---|
| 22 | {TNT-WARN TInplaceEdit}
|
---|
| 23 | TTntInplaceEdit = class(TInplaceEdit{TNT-ALLOW TInplaceEdit})
|
---|
| 24 | private
|
---|
| 25 | function GetText: WideString;
|
---|
| 26 | procedure SetText(const Value: WideString);
|
---|
| 27 | protected
|
---|
| 28 | procedure UpdateContents; override;
|
---|
| 29 | procedure CreateWindowHandle(const Params: TCreateParams); override;
|
---|
| 30 | public
|
---|
| 31 | property Text: WideString read GetText write SetText;
|
---|
| 32 | end;
|
---|
| 33 |
|
---|
| 34 | TTntGetEditEvent = procedure (Sender: TObject; ACol, ARow: Longint; var Value: WideString) of object;
|
---|
| 35 | TTntSetEditEvent = procedure (Sender: TObject; ACol, ARow: Longint; const Value: WideString) of object;
|
---|
| 36 |
|
---|
| 37 | {TNT-WARN TCustomDrawGrid}
|
---|
| 38 | _TTntInternalCustomDrawGrid = class(TCustomDrawGrid{TNT-ALLOW TCustomDrawGrid})
|
---|
| 39 | private
|
---|
| 40 | FSettingEditText: Boolean;
|
---|
| 41 | procedure InternalSetEditText(ACol, ARow: Longint; const Value: string{TNT-ALLOW string}); dynamic; abstract;
|
---|
| 42 | protected
|
---|
| 43 | procedure SetEditText(ACol, ARow: Longint; const Value: string{TNT-ALLOW string}); override;
|
---|
| 44 | end;
|
---|
| 45 |
|
---|
| 46 | TTntCustomDrawGrid = class(_TTntInternalCustomDrawGrid)
|
---|
| 47 | private
|
---|
| 48 | FOnGetEditText: TTntGetEditEvent;
|
---|
| 49 | FOnSetEditText: TTntSetEditEvent;
|
---|
| 50 | function GetHint: WideString;
|
---|
| 51 | procedure SetHint(const Value: WideString);
|
---|
| 52 | function IsHintStored: Boolean;
|
---|
| 53 | procedure WMChar(var Msg: TWMChar); message WM_CHAR;
|
---|
| 54 | protected
|
---|
| 55 | function CreateEditor: TInplaceEdit{TNT-ALLOW TInplaceEdit}; override;
|
---|
| 56 | procedure InternalSetEditText(ACol, ARow: Longint; const Value: string{TNT-ALLOW string}); override;
|
---|
| 57 | function GetEditText(ACol, ARow: Longint): WideString; reintroduce; virtual;
|
---|
| 58 | procedure SetEditText(ACol, ARow: Longint; const Value: WideString); reintroduce; virtual;
|
---|
| 59 | protected
|
---|
| 60 | procedure CreateWindowHandle(const Params: TCreateParams); override;
|
---|
| 61 | procedure ShowEditorChar(Ch: WideChar); dynamic;
|
---|
| 62 | procedure DefineProperties(Filer: TFiler); override;
|
---|
| 63 | function GetActionLinkClass: TControlActionLinkClass; override;
|
---|
| 64 | procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); override;
|
---|
| 65 | property OnGetEditText: TTntGetEditEvent read FOnGetEditText write FOnGetEditText;
|
---|
| 66 | property OnSetEditText: TTntSetEditEvent read FOnSetEditText write FOnSetEditText;
|
---|
| 67 | published
|
---|
| 68 | property Hint: WideString read GetHint write SetHint stored IsHintStored;
|
---|
| 69 | end;
|
---|
| 70 |
|
---|
| 71 | {TNT-WARN TDrawGrid}
|
---|
| 72 | TTntDrawGrid = class(TTntCustomDrawGrid)
|
---|
| 73 | published
|
---|
| 74 | property Align;
|
---|
| 75 | property Anchors;
|
---|
| 76 | property BevelEdges;
|
---|
| 77 | property BevelInner;
|
---|
| 78 | property BevelKind;
|
---|
| 79 | property BevelOuter;
|
---|
| 80 | property BevelWidth;
|
---|
| 81 | property BiDiMode;
|
---|
| 82 | property BorderStyle;
|
---|
| 83 | property Color;
|
---|
| 84 | property ColCount;
|
---|
| 85 | property Constraints;
|
---|
| 86 | property Ctl3D;
|
---|
| 87 | property DefaultColWidth;
|
---|
| 88 | property DefaultRowHeight;
|
---|
| 89 | property DefaultDrawing;
|
---|
| 90 | property DragCursor;
|
---|
| 91 | property DragKind;
|
---|
| 92 | property DragMode;
|
---|
| 93 | property Enabled;
|
---|
| 94 | property FixedColor;
|
---|
| 95 | property FixedCols;
|
---|
| 96 | property RowCount;
|
---|
| 97 | property FixedRows;
|
---|
| 98 | property Font;
|
---|
| 99 | property GridLineWidth;
|
---|
| 100 | property Options;
|
---|
| 101 | property ParentBiDiMode;
|
---|
| 102 | property ParentColor;
|
---|
| 103 | property ParentCtl3D;
|
---|
| 104 | property ParentFont;
|
---|
| 105 | property ParentShowHint;
|
---|
| 106 | property PopupMenu;
|
---|
| 107 | property ScrollBars;
|
---|
| 108 | property ShowHint;
|
---|
| 109 | property TabOrder;
|
---|
| 110 | property Visible;
|
---|
| 111 | property VisibleColCount;
|
---|
| 112 | property VisibleRowCount;
|
---|
| 113 | property OnClick;
|
---|
| 114 | property OnColumnMoved;
|
---|
| 115 | property OnContextPopup;
|
---|
| 116 | property OnDblClick;
|
---|
| 117 | property OnDragDrop;
|
---|
| 118 | property OnDragOver;
|
---|
| 119 | property OnDrawCell;
|
---|
| 120 | property OnEndDock;
|
---|
| 121 | property OnEndDrag;
|
---|
| 122 | property OnEnter;
|
---|
| 123 | property OnExit;
|
---|
| 124 | property OnGetEditMask;
|
---|
| 125 | property OnGetEditText;
|
---|
| 126 | property OnKeyDown;
|
---|
| 127 | property OnKeyPress;
|
---|
| 128 | property OnKeyUp;
|
---|
| 129 | {$IFDEF COMPILER_9_UP}
|
---|
| 130 | property OnMouseActivate;
|
---|
| 131 | {$ENDIF}
|
---|
| 132 | property OnMouseDown;
|
---|
| 133 | {$IFDEF COMPILER_10_UP}
|
---|
| 134 | property OnMouseEnter;
|
---|
| 135 | property OnMouseLeave;
|
---|
| 136 | {$ENDIF}
|
---|
| 137 | property OnMouseMove;
|
---|
| 138 | property OnMouseUp;
|
---|
| 139 | property OnMouseWheelDown;
|
---|
| 140 | property OnMouseWheelUp;
|
---|
| 141 | property OnRowMoved;
|
---|
| 142 | property OnSelectCell;
|
---|
| 143 | property OnSetEditText;
|
---|
| 144 | property OnStartDock;
|
---|
| 145 | property OnStartDrag;
|
---|
| 146 | property OnTopLeftChanged;
|
---|
| 147 | end;
|
---|
| 148 |
|
---|
| 149 | TTntStringGrid = class;
|
---|
| 150 |
|
---|
| 151 | {TNT-WARN TStringGridStrings}
|
---|
| 152 | TTntStringGridStrings = class(TTntStrings)
|
---|
| 153 | private
|
---|
| 154 | FIsCol: Boolean;
|
---|
| 155 | FColRowIndex: Integer;
|
---|
| 156 | FGrid: TTntStringGrid;
|
---|
| 157 | function GridAnsiStrings: TStrings{TNT-ALLOW TStrings};
|
---|
| 158 | protected
|
---|
| 159 | function Get(Index: Integer): WideString; override;
|
---|
| 160 | procedure Put(Index: Integer; const S: WideString); override;
|
---|
| 161 | function GetCount: Integer; override;
|
---|
| 162 | function GetObject(Index: Integer): TObject; override;
|
---|
| 163 | procedure PutObject(Index: Integer; AObject: TObject); override;
|
---|
| 164 | procedure SetUpdateState(Updating: Boolean); override;
|
---|
| 165 | public
|
---|
| 166 | constructor Create(AGrid: TTntStringGrid; AIndex: Longint);
|
---|
| 167 | function Add(const S: WideString): Integer; override;
|
---|
| 168 | procedure Assign(Source: TPersistent); override;
|
---|
| 169 | procedure Clear; override;
|
---|
| 170 | procedure Delete(Index: Integer); override;
|
---|
| 171 | procedure Insert(Index: Integer; const S: WideString); override;
|
---|
| 172 | end;
|
---|
| 173 |
|
---|
| 174 | {TNT-WARN TStringGrid}
|
---|
| 175 | _TTntInternalStringGrid = class(TStringGrid{TNT-ALLOW TStringGrid})
|
---|
| 176 | private
|
---|
| 177 | FSettingEditText: Boolean;
|
---|
| 178 | procedure InternalSetEditText(ACol, ARow: Longint; const Value: string{TNT-ALLOW string}); dynamic; abstract;
|
---|
| 179 | protected
|
---|
| 180 | procedure SetEditText(ACol, ARow: Longint; const Value: string{TNT-ALLOW string}); override;
|
---|
| 181 | end;
|
---|
| 182 |
|
---|
| 183 | TTntStringGrid = class(_TTntInternalStringGrid)
|
---|
| 184 | private
|
---|
| 185 | FCreatedRowStrings: TStringList{TNT-ALLOW TStringList};
|
---|
| 186 | FCreatedColStrings: TStringList{TNT-ALLOW TStringList};
|
---|
| 187 | FOnGetEditText: TTntGetEditEvent;
|
---|
| 188 | FOnSetEditText: TTntSetEditEvent;
|
---|
| 189 | function GetHint: WideString;
|
---|
| 190 | procedure SetHint(const Value: WideString);
|
---|
| 191 | function IsHintStored: Boolean;
|
---|
| 192 | procedure WMChar(var Msg: TWMChar); message WM_CHAR;
|
---|
| 193 | function GetCells(ACol, ARow: Integer): WideString;
|
---|
| 194 | procedure SetCells(ACol, ARow: Integer; const Value: WideString);
|
---|
| 195 | function FindGridStrings(const IsCol: Boolean; const ListIndex: Integer): TTntStrings;
|
---|
| 196 | function GetCols(Index: Integer): TTntStrings;
|
---|
| 197 | function GetRows(Index: Integer): TTntStrings;
|
---|
| 198 | procedure SetCols(Index: Integer; const Value: TTntStrings);
|
---|
| 199 | procedure SetRows(Index: Integer; const Value: TTntStrings);
|
---|
| 200 | protected
|
---|
| 201 | function CreateEditor: TInplaceEdit{TNT-ALLOW TInplaceEdit}; override;
|
---|
| 202 | procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override;
|
---|
| 203 | procedure InternalSetEditText(ACol, ARow: Longint; const Value: string{TNT-ALLOW string}); override;
|
---|
| 204 | function GetEditText(ACol, ARow: Longint): WideString; reintroduce; virtual;
|
---|
| 205 | procedure SetEditText(ACol, ARow: Longint; const Value: WideString); reintroduce; virtual;
|
---|
| 206 | protected
|
---|
| 207 | procedure CreateWindowHandle(const Params: TCreateParams); override;
|
---|
| 208 | procedure ShowEditorChar(Ch: WideChar); dynamic;
|
---|
| 209 | procedure DefineProperties(Filer: TFiler); override;
|
---|
| 210 | function GetActionLinkClass: TControlActionLinkClass; override;
|
---|
| 211 | procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); override;
|
---|
| 212 | public
|
---|
| 213 | constructor Create(AOwner: TComponent); override;
|
---|
| 214 | destructor Destroy; override;
|
---|
| 215 | property Cells[ACol, ARow: Integer]: WideString read GetCells write SetCells;
|
---|
| 216 | property Cols[Index: Integer]: TTntStrings read GetCols write SetCols;
|
---|
| 217 | property Rows[Index: Integer]: TTntStrings read GetRows write SetRows;
|
---|
| 218 | published
|
---|
| 219 | property Hint: WideString read GetHint write SetHint stored IsHintStored;
|
---|
| 220 | property OnGetEditText: TTntGetEditEvent read FOnGetEditText write FOnGetEditText;
|
---|
| 221 | property OnSetEditText: TTntSetEditEvent read FOnSetEditText write FOnSetEditText;
|
---|
| 222 | end;
|
---|
| 223 |
|
---|
| 224 | implementation
|
---|
| 225 |
|
---|
| 226 | uses
|
---|
| 227 | SysUtils, TntSystem, TntGraphics, TntControls, TntStdCtrls, TntActnList, TntSysUtils;
|
---|
| 228 |
|
---|
| 229 | { TBinaryCompareAnsiStringList }
|
---|
| 230 | type
|
---|
| 231 | TBinaryCompareAnsiStringList = class(TStringList{TNT-ALLOW TStringList})
|
---|
| 232 | protected
|
---|
| 233 | function CompareStrings(const S1, S2: string{TNT-ALLOW string}): Integer; override;
|
---|
| 234 | end;
|
---|
| 235 |
|
---|
| 236 | function TBinaryCompareAnsiStringList.CompareStrings(const S1, S2: string{TNT-ALLOW string}): Integer;
|
---|
| 237 | begin
|
---|
| 238 | // must compare strings via binary for speed
|
---|
| 239 | if S1 = S2 then
|
---|
| 240 | result := 0
|
---|
| 241 | else if S1 < S2 then
|
---|
| 242 | result := -1
|
---|
| 243 | else
|
---|
| 244 | result := 1;
|
---|
| 245 | end;
|
---|
| 246 |
|
---|
| 247 | { TTntInplaceEdit }
|
---|
| 248 |
|
---|
| 249 | procedure TTntInplaceEdit.CreateWindowHandle(const Params: TCreateParams);
|
---|
| 250 | begin
|
---|
| 251 | TntCustomEdit_CreateWindowHandle(Self, Params);
|
---|
| 252 | end;
|
---|
| 253 |
|
---|
| 254 | function TTntInplaceEdit.GetText: WideString;
|
---|
| 255 | begin
|
---|
| 256 | if IsMasked then
|
---|
| 257 | Result := inherited Text
|
---|
| 258 | else
|
---|
| 259 | Result := TntControl_GetText(Self);
|
---|
| 260 | end;
|
---|
| 261 |
|
---|
| 262 | procedure TTntInplaceEdit.SetText(const Value: WideString);
|
---|
| 263 | begin
|
---|
| 264 | if IsMasked then
|
---|
| 265 | inherited Text := Value
|
---|
| 266 | else
|
---|
| 267 | TntControl_SetText(Self, Value);
|
---|
| 268 | end;
|
---|
| 269 |
|
---|
| 270 | type TAccessCustomGrid = class(TCustomGrid);
|
---|
| 271 |
|
---|
| 272 | procedure TTntInplaceEdit.UpdateContents;
|
---|
| 273 | begin
|
---|
| 274 | Text := '';
|
---|
| 275 | with TAccessCustomGrid(Grid) do
|
---|
| 276 | Self.EditMask := GetEditMask(Col, Row);
|
---|
| 277 | if (Grid is TTntStringGrid) then
|
---|
| 278 | with (Grid as TTntStringGrid) do
|
---|
| 279 | Self.Text := GetEditText(Col, Row)
|
---|
| 280 | else if (Grid is TTntCustomDrawGrid) then
|
---|
| 281 | with (Grid as TTntCustomDrawGrid) do
|
---|
| 282 | Self.Text := GetEditText(Col, Row)
|
---|
| 283 | else
|
---|
| 284 | with TAccessCustomGrid(Grid) do
|
---|
| 285 | Self.Text := GetEditText(Col, Row);
|
---|
| 286 | with TAccessCustomGrid(Grid) do
|
---|
| 287 | Self.MaxLength := GetEditLimit;
|
---|
| 288 | end;
|
---|
| 289 |
|
---|
| 290 | { _TTntInternalCustomDrawGrid }
|
---|
| 291 |
|
---|
| 292 | procedure _TTntInternalCustomDrawGrid.SetEditText(ACol, ARow: Integer; const Value: string{TNT-ALLOW string});
|
---|
| 293 | begin
|
---|
| 294 | if FSettingEditText then
|
---|
| 295 | inherited
|
---|
| 296 | else
|
---|
| 297 | InternalSetEditText(ACol, ARow, Value);
|
---|
| 298 | end;
|
---|
| 299 |
|
---|
| 300 |
|
---|
| 301 | { TTntCustomDrawGrid }
|
---|
| 302 |
|
---|
| 303 | function TTntCustomDrawGrid.CreateEditor: TInplaceEdit{TNT-ALLOW TInplaceEdit};
|
---|
| 304 | begin
|
---|
| 305 | Result := TTntInplaceEdit.Create(Self);
|
---|
| 306 | end;
|
---|
| 307 |
|
---|
| 308 | procedure TTntCustomDrawGrid.CreateWindowHandle(const Params: TCreateParams);
|
---|
| 309 | begin
|
---|
| 310 | CreateUnicodeHandle(Self, Params, '');
|
---|
| 311 | end;
|
---|
| 312 |
|
---|
| 313 | procedure TTntCustomDrawGrid.DefineProperties(Filer: TFiler);
|
---|
| 314 | begin
|
---|
| 315 | inherited;
|
---|
| 316 | TntPersistent_AfterInherited_DefineProperties(Filer, Self);
|
---|
| 317 | end;
|
---|
| 318 |
|
---|
| 319 | function TTntCustomDrawGrid.IsHintStored: Boolean;
|
---|
| 320 | begin
|
---|
| 321 | Result := TntControl_IsHintStored(Self);
|
---|
| 322 | end;
|
---|
| 323 |
|
---|
| 324 | function TTntCustomDrawGrid.GetHint: WideString;
|
---|
| 325 | begin
|
---|
| 326 | Result := TntControl_GetHint(Self);
|
---|
| 327 | end;
|
---|
| 328 |
|
---|
| 329 | procedure TTntCustomDrawGrid.SetHint(const Value: WideString);
|
---|
| 330 | begin
|
---|
| 331 | TntControl_SetHint(Self, Value);
|
---|
| 332 | end;
|
---|
| 333 |
|
---|
| 334 | function TTntCustomDrawGrid.GetEditText(ACol, ARow: Integer): WideString;
|
---|
| 335 | begin
|
---|
| 336 | Result := '';
|
---|
| 337 | if Assigned(FOnGetEditText) then FOnGetEditText(Self, ACol, ARow, Result);
|
---|
| 338 | end;
|
---|
| 339 |
|
---|
| 340 | procedure TTntCustomDrawGrid.InternalSetEditText(ACol, ARow: Integer; const Value: string{TNT-ALLOW string});
|
---|
| 341 | begin
|
---|
| 342 | if not FSettingEditText then
|
---|
| 343 | SetEditText(ACol, ARow, TntControl_GetText(InplaceEditor));
|
---|
| 344 | end;
|
---|
| 345 |
|
---|
| 346 | procedure TTntCustomDrawGrid.SetEditText(ACol, ARow: Integer; const Value: WideString);
|
---|
| 347 | begin
|
---|
| 348 | if Assigned(FOnSetEditText) then FOnSetEditText(Self, ACol, ARow, Value);
|
---|
| 349 | end;
|
---|
| 350 |
|
---|
| 351 | procedure TTntCustomDrawGrid.WMChar(var Msg: TWMChar);
|
---|
| 352 | begin
|
---|
| 353 | if (goEditing in Options)
|
---|
| 354 | and (AnsiChar(Msg.CharCode) in [^H, #32..#255]) then begin
|
---|
| 355 | RestoreWMCharMsg(TMessage(Msg));
|
---|
| 356 | ShowEditorChar(WideChar(Msg.CharCode));
|
---|
| 357 | end else
|
---|
| 358 | inherited;
|
---|
| 359 | end;
|
---|
| 360 |
|
---|
| 361 | procedure TTntCustomDrawGrid.ShowEditorChar(Ch: WideChar);
|
---|
| 362 | begin
|
---|
| 363 | ShowEditor;
|
---|
| 364 | if InplaceEditor <> nil then begin
|
---|
| 365 | if Win32PlatformIsUnicode then
|
---|
| 366 | PostMessageW(InplaceEditor.Handle, WM_CHAR, Word(Ch), 0)
|
---|
| 367 | else
|
---|
| 368 | PostMessageA(InplaceEditor.Handle, WM_CHAR, Word(Ch), 0);
|
---|
| 369 | end;
|
---|
| 370 | end;
|
---|
| 371 |
|
---|
| 372 | procedure TTntCustomDrawGrid.ActionChange(Sender: TObject; CheckDefaults: Boolean);
|
---|
| 373 | begin
|
---|
| 374 | TntControl_BeforeInherited_ActionChange(Self, Sender, CheckDefaults);
|
---|
| 375 | inherited;
|
---|
| 376 | end;
|
---|
| 377 |
|
---|
| 378 | function TTntCustomDrawGrid.GetActionLinkClass: TControlActionLinkClass;
|
---|
| 379 | begin
|
---|
| 380 | Result := TntControl_GetActionLinkClass(Self, inherited GetActionLinkClass);
|
---|
| 381 | end;
|
---|
| 382 |
|
---|
| 383 | { TTntStringGridStrings }
|
---|
| 384 |
|
---|
| 385 | procedure TTntStringGridStrings.Assign(Source: TPersistent);
|
---|
| 386 | var
|
---|
| 387 | UTF8Strings: TStringList{TNT-ALLOW TStringList};
|
---|
| 388 | i: integer;
|
---|
| 389 | begin
|
---|
| 390 | UTF8Strings := TStringList{TNT-ALLOW TStringList}.Create;
|
---|
| 391 | try
|
---|
| 392 | if Source is TStrings{TNT-ALLOW TStrings} then begin
|
---|
| 393 | for i := 0 to TStrings{TNT-ALLOW TStrings}(Source).Count - 1 do
|
---|
| 394 | UTF8Strings.AddObject(WideStringToUTF8(WideString(TStrings{TNT-ALLOW TStrings}(Source).Strings[i])),
|
---|
| 395 | TStrings{TNT-ALLOW TStrings}(Source).Objects[i]);
|
---|
| 396 | GridAnsiStrings.Assign(UTF8Strings);
|
---|
| 397 | end else if Source is TTntStrings then begin
|
---|
| 398 | for i := 0 to TTntStrings(Source).Count - 1 do
|
---|
| 399 | UTF8Strings.AddObject(WideStringToUTF8(TTntStrings(Source).Strings[i]),
|
---|
| 400 | TTntStrings(Source).Objects[i]);
|
---|
| 401 | GridAnsiStrings.Assign(UTF8Strings);
|
---|
| 402 | end else
|
---|
| 403 | GridAnsiStrings.Assign(Source);
|
---|
| 404 | finally
|
---|
| 405 | UTF8Strings.Free;
|
---|
| 406 | end;
|
---|
| 407 | end;
|
---|
| 408 |
|
---|
| 409 | function TTntStringGridStrings.GridAnsiStrings: TStrings{TNT-ALLOW TStrings};
|
---|
| 410 | begin
|
---|
| 411 | Assert(Assigned(FGrid));
|
---|
| 412 | if FIsCol then
|
---|
| 413 | Result := TStringGrid{TNT-ALLOW TStringGrid}(FGrid).Cols[FColRowIndex]
|
---|
| 414 | else
|
---|
| 415 | Result := TStringGrid{TNT-ALLOW TStringGrid}(FGrid).Rows[FColRowIndex];
|
---|
| 416 | end;
|
---|
| 417 |
|
---|
| 418 | procedure TTntStringGridStrings.Clear;
|
---|
| 419 | begin
|
---|
| 420 | GridAnsiStrings.Clear;
|
---|
| 421 | end;
|
---|
| 422 |
|
---|
| 423 | procedure TTntStringGridStrings.Delete(Index: Integer);
|
---|
| 424 | begin
|
---|
| 425 | GridAnsiStrings.Delete(Index);
|
---|
| 426 | end;
|
---|
| 427 |
|
---|
| 428 | function TTntStringGridStrings.GetCount: Integer;
|
---|
| 429 | begin
|
---|
| 430 | Result := GridAnsiStrings.Count;
|
---|
| 431 | end;
|
---|
| 432 |
|
---|
| 433 | function TTntStringGridStrings.Get(Index: Integer): WideString;
|
---|
| 434 | begin
|
---|
| 435 | Result := UTF8ToWideString(GridAnsiStrings[Index]);
|
---|
| 436 | end;
|
---|
| 437 |
|
---|
| 438 | procedure TTntStringGridStrings.Put(Index: Integer; const S: WideString);
|
---|
| 439 | begin
|
---|
| 440 | GridAnsiStrings[Index] := WideStringToUTF8(S);
|
---|
| 441 | end;
|
---|
| 442 |
|
---|
| 443 | procedure TTntStringGridStrings.Insert(Index: Integer; const S: WideString);
|
---|
| 444 | begin
|
---|
| 445 | GridAnsiStrings.Insert(Index, WideStringToUTF8(S));
|
---|
| 446 | end;
|
---|
| 447 |
|
---|
| 448 | function TTntStringGridStrings.Add(const S: WideString): Integer;
|
---|
| 449 | begin
|
---|
| 450 | Result := GridAnsiStrings.Add(WideStringToUTF8(S));
|
---|
| 451 | end;
|
---|
| 452 |
|
---|
| 453 | function TTntStringGridStrings.GetObject(Index: Integer): TObject;
|
---|
| 454 | begin
|
---|
| 455 | Result := GridAnsiStrings.Objects[Index];
|
---|
| 456 | end;
|
---|
| 457 |
|
---|
| 458 | procedure TTntStringGridStrings.PutObject(Index: Integer; AObject: TObject);
|
---|
| 459 | begin
|
---|
| 460 | GridAnsiStrings.Objects[Index] := AObject;
|
---|
| 461 | end;
|
---|
| 462 |
|
---|
| 463 | type TAccessStrings = class(TStrings{TNT-ALLOW TStrings});
|
---|
| 464 |
|
---|
| 465 | procedure TTntStringGridStrings.SetUpdateState(Updating: Boolean);
|
---|
| 466 | begin
|
---|
| 467 | TAccessStrings(GridAnsiStrings).SetUpdateState(Updating);
|
---|
| 468 | end;
|
---|
| 469 |
|
---|
| 470 | constructor TTntStringGridStrings.Create(AGrid: TTntStringGrid; AIndex: Integer);
|
---|
| 471 | begin
|
---|
| 472 | inherited Create;
|
---|
| 473 | FGrid := AGrid;
|
---|
| 474 | if AIndex > 0 then begin
|
---|
| 475 | FIsCol := False;
|
---|
| 476 | FColRowIndex := AIndex - 1;
|
---|
| 477 | end else begin
|
---|
| 478 | FIsCol := True;
|
---|
| 479 | FColRowIndex := -AIndex - 1;
|
---|
| 480 | end;
|
---|
| 481 | end;
|
---|
| 482 |
|
---|
| 483 | { _TTntInternalStringGrid }
|
---|
| 484 |
|
---|
| 485 | procedure _TTntInternalStringGrid.SetEditText(ACol, ARow: Integer; const Value: string{TNT-ALLOW string});
|
---|
| 486 | begin
|
---|
| 487 | if FSettingEditText then
|
---|
| 488 | inherited
|
---|
| 489 | else
|
---|
| 490 | InternalSetEditText(ACol, ARow, Value);
|
---|
| 491 | end;
|
---|
| 492 |
|
---|
| 493 | { TTntStringGrid }
|
---|
| 494 |
|
---|
| 495 | constructor TTntStringGrid.Create(AOwner: TComponent);
|
---|
| 496 | begin
|
---|
| 497 | inherited;
|
---|
| 498 | FCreatedRowStrings := TBinaryCompareAnsiStringList.Create;
|
---|
| 499 | FCreatedRowStrings.Sorted := True;
|
---|
| 500 | FCreatedRowStrings.Duplicates := dupError;
|
---|
| 501 | FCreatedColStrings := TBinaryCompareAnsiStringList.Create;
|
---|
| 502 | FCreatedColStrings.Sorted := True;
|
---|
| 503 | FCreatedColStrings.Duplicates := dupError;
|
---|
| 504 | end;
|
---|
| 505 |
|
---|
| 506 | destructor TTntStringGrid.Destroy;
|
---|
| 507 | var
|
---|
| 508 | i: integer;
|
---|
| 509 | begin
|
---|
| 510 | for i := FCreatedColStrings.Count - 1 downto 0 do
|
---|
| 511 | FCreatedColStrings.Objects[i].Free;
|
---|
| 512 | for i := FCreatedRowStrings.Count - 1 downto 0 do
|
---|
| 513 | FCreatedRowStrings.Objects[i].Free;
|
---|
| 514 | FreeAndNil(FCreatedColStrings);
|
---|
| 515 | FreeAndNil(FCreatedRowStrings);
|
---|
| 516 | inherited;
|
---|
| 517 | end;
|
---|
| 518 |
|
---|
| 519 | function TTntStringGrid.CreateEditor: TInplaceEdit{TNT-ALLOW TInplaceEdit};
|
---|
| 520 | begin
|
---|
| 521 | Result := TTntInplaceEdit.Create(Self);
|
---|
| 522 | end;
|
---|
| 523 |
|
---|
| 524 | procedure TTntStringGrid.CreateWindowHandle(const Params: TCreateParams);
|
---|
| 525 | begin
|
---|
| 526 | CreateUnicodeHandle(Self, Params, '');
|
---|
| 527 | end;
|
---|
| 528 |
|
---|
| 529 | procedure TTntStringGrid.DefineProperties(Filer: TFiler);
|
---|
| 530 | begin
|
---|
| 531 | inherited;
|
---|
| 532 | TntPersistent_AfterInherited_DefineProperties(Filer, Self);
|
---|
| 533 | end;
|
---|
| 534 |
|
---|
| 535 | function TTntStringGrid.IsHintStored: Boolean;
|
---|
| 536 | begin
|
---|
| 537 | Result := TntControl_IsHintStored(Self);
|
---|
| 538 | end;
|
---|
| 539 |
|
---|
| 540 | function TTntStringGrid.GetHint: WideString;
|
---|
| 541 | begin
|
---|
| 542 | Result := TntControl_GetHint(Self)
|
---|
| 543 | end;
|
---|
| 544 |
|
---|
| 545 | procedure TTntStringGrid.SetHint(const Value: WideString);
|
---|
| 546 | begin
|
---|
| 547 | TntControl_SetHint(Self, Value);
|
---|
| 548 | end;
|
---|
| 549 |
|
---|
| 550 | function TTntStringGrid.GetCells(ACol, ARow: Integer): WideString;
|
---|
| 551 | begin
|
---|
| 552 | Result := UTF8ToWideString(inherited Cells[ACol, ARow])
|
---|
| 553 | end;
|
---|
| 554 |
|
---|
| 555 | procedure TTntStringGrid.SetCells(ACol, ARow: Integer; const Value: WideString);
|
---|
| 556 | var
|
---|
| 557 | UTF8Str: AnsiString;
|
---|
| 558 | begin
|
---|
| 559 | UTF8Str := WideStringToUTF8(Value);
|
---|
| 560 | if inherited Cells[ACol, ARow] <> UTF8Str then
|
---|
| 561 | inherited Cells[ACol, ARow] := UTF8Str;
|
---|
| 562 | end;
|
---|
| 563 |
|
---|
| 564 | function TTntStringGrid.FindGridStrings(const IsCol: Boolean; const ListIndex: Integer): TTntStrings;
|
---|
| 565 | var
|
---|
| 566 | idx: integer;
|
---|
| 567 | SrcStrings: TStrings{TNT-ALLOW TStrings};
|
---|
| 568 | RCIndex: Integer;
|
---|
| 569 | begin
|
---|
| 570 | if IsCol then
|
---|
| 571 | SrcStrings := FCreatedColStrings
|
---|
| 572 | else
|
---|
| 573 | SrcStrings := FCreatedRowStrings;
|
---|
| 574 | Assert(Assigned(SrcStrings));
|
---|
| 575 | idx := SrcStrings.IndexOf(IntToStr(ListIndex));
|
---|
| 576 | if idx <> -1 then
|
---|
| 577 | Result := SrcStrings.Objects[idx] as TTntStrings
|
---|
| 578 | else begin
|
---|
| 579 | if IsCol then RCIndex := -ListIndex - 1 else RCIndex := ListIndex + 1;
|
---|
| 580 | Result := TTntStringGridStrings.Create(Self, RCIndex);
|
---|
| 581 | SrcStrings.AddObject(IntToStr(ListIndex), Result);
|
---|
| 582 | end;
|
---|
| 583 | end;
|
---|
| 584 |
|
---|
| 585 | function TTntStringGrid.GetCols(Index: Integer): TTntStrings;
|
---|
| 586 | begin
|
---|
| 587 | Result := FindGridStrings(True, Index);
|
---|
| 588 | end;
|
---|
| 589 |
|
---|
| 590 | function TTntStringGrid.GetRows(Index: Integer): TTntStrings;
|
---|
| 591 | begin
|
---|
| 592 | Result := FindGridStrings(False, Index);
|
---|
| 593 | end;
|
---|
| 594 |
|
---|
| 595 | procedure TTntStringGrid.SetCols(Index: Integer; const Value: TTntStrings);
|
---|
| 596 | begin
|
---|
| 597 | FindGridStrings(True, Index).Assign(Value);
|
---|
| 598 | end;
|
---|
| 599 |
|
---|
| 600 | procedure TTntStringGrid.SetRows(Index: Integer; const Value: TTntStrings);
|
---|
| 601 | begin
|
---|
| 602 | FindGridStrings(False, Index).Assign(Value);
|
---|
| 603 | end;
|
---|
| 604 |
|
---|
| 605 | procedure TTntStringGrid.DrawCell(ACol, ARow: Integer; ARect: TRect; AState: TGridDrawState);
|
---|
| 606 | var
|
---|
| 607 | SaveDefaultDrawing: Boolean;
|
---|
| 608 | begin
|
---|
| 609 | if DefaultDrawing then
|
---|
| 610 | WideCanvasTextRect(Canvas, ARect, ARect.Left+2, ARect.Top+2, Cells[ACol, ARow]);
|
---|
| 611 | SaveDefaultDrawing := DefaultDrawing;
|
---|
| 612 | try
|
---|
| 613 | DefaultDrawing := False;
|
---|
| 614 | inherited DrawCell(ACol, ARow, ARect, AState);
|
---|
| 615 | finally
|
---|
| 616 | DefaultDrawing := SaveDefaultDrawing;
|
---|
| 617 | end;
|
---|
| 618 | end;
|
---|
| 619 |
|
---|
| 620 | function TTntStringGrid.GetEditText(ACol, ARow: Integer): WideString;
|
---|
| 621 | begin
|
---|
| 622 | Result := Cells[ACol, ARow];
|
---|
| 623 | if Assigned(FOnGetEditText) then FOnGetEditText(Self, ACol, ARow, Result);
|
---|
| 624 | end;
|
---|
| 625 |
|
---|
| 626 | procedure TTntStringGrid.InternalSetEditText(ACol, ARow: Integer; const Value: string{TNT-ALLOW string});
|
---|
| 627 | begin
|
---|
| 628 | if not FSettingEditText then
|
---|
| 629 | SetEditText(ACol, ARow, TntControl_GetText(InplaceEditor));
|
---|
| 630 | end;
|
---|
| 631 |
|
---|
| 632 | procedure TTntStringGrid.SetEditText(ACol, ARow: Integer; const Value: WideString);
|
---|
| 633 | begin
|
---|
| 634 | FSettingEditText := True;
|
---|
| 635 | try
|
---|
| 636 | inherited SetEditText(ACol, ARow, WideStringToUTF8(Value));
|
---|
| 637 | finally
|
---|
| 638 | FSettingEditText := False;
|
---|
| 639 | end;
|
---|
| 640 | if Assigned(FOnSetEditText) then FOnSetEditText(Self, ACol, ARow, Value);
|
---|
| 641 | end;
|
---|
| 642 |
|
---|
| 643 | procedure TTntStringGrid.WMChar(var Msg: TWMChar);
|
---|
| 644 | begin
|
---|
| 645 | if (goEditing in Options)
|
---|
| 646 | and (AnsiChar(Msg.CharCode) in [^H, #32..#255]) then begin
|
---|
| 647 | RestoreWMCharMsg(TMessage(Msg));
|
---|
| 648 | ShowEditorChar(WideChar(Msg.CharCode));
|
---|
| 649 | end else
|
---|
| 650 | inherited;
|
---|
| 651 | end;
|
---|
| 652 |
|
---|
| 653 | procedure TTntStringGrid.ShowEditorChar(Ch: WideChar);
|
---|
| 654 | begin
|
---|
| 655 | ShowEditor;
|
---|
| 656 | if InplaceEditor <> nil then begin
|
---|
| 657 | if Win32PlatformIsUnicode then
|
---|
| 658 | PostMessageW(InplaceEditor.Handle, WM_CHAR, Word(Ch), 0)
|
---|
| 659 | else
|
---|
| 660 | PostMessageA(InplaceEditor.Handle, WM_CHAR, Word(Ch), 0);
|
---|
| 661 | end;
|
---|
| 662 | end;
|
---|
| 663 |
|
---|
| 664 | procedure TTntStringGrid.ActionChange(Sender: TObject; CheckDefaults: Boolean);
|
---|
| 665 | begin
|
---|
| 666 | TntControl_BeforeInherited_ActionChange(Self, Sender, CheckDefaults);
|
---|
| 667 | inherited;
|
---|
| 668 | end;
|
---|
| 669 |
|
---|
| 670 | function TTntStringGrid.GetActionLinkClass: TControlActionLinkClass;
|
---|
| 671 | begin
|
---|
| 672 | Result := TntControl_GetActionLinkClass(Self, inherited GetActionLinkClass);
|
---|
| 673 | end;
|
---|
| 674 |
|
---|
| 675 | end.
|
---|