fphelper.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. {%MainUnit fpcanvas.pp}
  2. {
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2003 by the Free Pascal development team
  5. Implementation of TFPCanvasHelper
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. { TFPCanvasHelper }
  13. constructor TFPCanvasHelper.Create;
  14. begin
  15. inherited create;
  16. FCanvas := nil;
  17. FFixedCanvas := false;
  18. FAllocated := false;
  19. end;
  20. destructor TFPCanvasHelper.destroy;
  21. begin
  22. if Allocated then
  23. DeAllocateResources;
  24. inherited;
  25. end;
  26. procedure TFPCanvasHelper.SetFixedCanvas (AValue : boolean);
  27. begin
  28. FFixedCanvas := AValue;
  29. end;
  30. procedure TFPCanvasHelper.NotifyCanvas;
  31. // called to unbind from canvas
  32. begin
  33. if FCanvas<>nil then
  34. FCanvas.CheckHelper (self);
  35. end;
  36. procedure TFPCanvasHelper.CheckAllocated (ValueNeeded:boolean);
  37. procedure RaiseErrAllocation;
  38. begin
  39. Raise TFPFontException.CreateFmt (ErrAllocation,
  40. [EFont, ErrAlloc[ValueNeeded]]);
  41. end;
  42. begin
  43. if (Allocated <> ValueNeeded) then
  44. RaiseErrAllocation;
  45. end;
  46. procedure TFPCanvasHelper.SetFPColor(const AValue:TFPColor);
  47. begin
  48. FFPColor := AValue;
  49. end;
  50. procedure TFPCanvasHelper.Changing;
  51. begin
  52. if Assigned(FOnChanging) then FOnChanging(Self);
  53. end;
  54. procedure TFPCanvasHelper.Changed;
  55. begin
  56. if Assigned(FOnChange) then FOnChange(Self);
  57. end;
  58. procedure TFPCanvasHelper.Lock;
  59. begin
  60. end;
  61. procedure TFPCanvasHelper.UnLock;
  62. begin
  63. end;
  64. procedure TFPCanvasHelper.SetFlags (index:integer; AValue:boolean);
  65. begin
  66. if AValue then
  67. FFlags := FFlags or (1 shl index)
  68. else
  69. FFlags := FFlags and not (1 shl index);
  70. end;
  71. function TFPCanvasHelper.GetFlags (index:integer) : boolean;
  72. begin
  73. result := (FFlags and (1 shl index)) <> 0;
  74. end;
  75. function TFPCanvasHelper.GetAllocated : boolean;
  76. begin
  77. if FFixedCanvas then
  78. result := assigned(FCanvas)
  79. else
  80. result := FAllocated;
  81. end;
  82. procedure TFPCanvasHelper.AllocateResources (ACanvas : TFPCustomCanvas;
  83. CanDelay: boolean);
  84. begin
  85. if FFixedCanvas and FAllocated then
  86. DeallocateResources;
  87. FCanvas := ACanvas;
  88. if DelayAllocate and CanDelay then exit;
  89. try
  90. DoAllocateResources;
  91. FAllocated := True;
  92. except
  93. FCanvas := nil;
  94. FAllocated := False;
  95. end;
  96. end;
  97. procedure TFPCanvasHelper.DeallocateResources;
  98. begin
  99. if FAllocated then
  100. try
  101. DoDeallocateResources;
  102. finally
  103. FAllocated := false;
  104. NotifyCanvas;
  105. FCanvas := nil;
  106. end;
  107. end;
  108. procedure TFPCanvasHelper.DoCopyProps (From:TFPCanvasHelper);
  109. begin
  110. FPColor := from.FPColor;
  111. end;
  112. procedure TFPCanvasHelper.DoAllocateResources;
  113. begin
  114. end;
  115. procedure TFPCanvasHelper.DoDeallocateResources;
  116. begin
  117. end;