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 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
|
unit UPaintbox32;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Menus, ComCtrls;
///////////////////
//* TPaintbox32 *//
///////////////////
type
TMouseEvent = procedure(sender : TObject;shift : TShiftState;x,y : integer) of object;
TKeyPressEvent = procedure(Sender: TObject; var Key: Char) of object;
TMouseWheelEvent =procedure(Sender: TObject; Shift: TShiftState;WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean) of object;
TPaintbox32 = class(TWINCONTROL)
private
//f
fwidth,fheight,ftop,fleft,fTag : integer;
fClientRect : TRect;
fHelpKeyWord,fhint : string;
fHelpType : THelpType;
fDragKind : TDragKind;
fDragCursor,fCursor : TCursor;
fDragMode : TDragMode;
fAlign : TAlign;
fHelpContext : THelpContext;
fPopupMenu : TPopupMenu;
fClientOrigin : TPoint;
fShowHint,fVisible : boolean;
fAnchors : TAnchors;
fConstraints : TSizeConstraints;
//evenements
fPaint,fClick,fdblclick : TNotifyEvent;
fMouseMove : TMouseEvent;
fKeyPress : TKeyPressEvent;
fMouseWheel : TMouseWheelEvent;
//objets
Paintbox1 : TPaintbox;
bmp : TBitmap;
Button : TButton;
SCrollBox : TScrollBox;
//procedure
procedure Paint(sender : TObject);
procedure clic(sender : TObject);
procedure dblclic(sender : TObject);
procedure setleft(x : integer);
procedure settop(x : integer);
procedure setwidth(x : integer);
procedure setheight(x : integer);
procedure setCanvas(x : TCanvas);
procedure setCursor(x : TCursor);
procedure setAlign(x : TAlign);
procedure setAnchors(x : TAnchors);
procedure setConstraints(x : TSizeConstraints);
procedure setDragCursor(x : TCursor);
procedure setDragKind(x : TDragKind);
procedure setDragMode(x : TDragMode);
procedure setHelpContext(x : THelpContext);
procedure setHelpKeyWord(x : string);
procedure setHelpType(x : THelpType);
procedure setPopupMenu(x : TPopupMenu);
procedure setTag(x : integer);
procedure setHint(x : string);
procedure setShowHint(x : boolean);
procedure setVisible(x : boolean);
procedure move(Sender: TObject; Shift: TShiftState; X,Y: Integer);
procedure KeyPress(Sender: TObject; var Key: Char);
procedure MouseWheel(Sender: TObject; Shift: TShiftState;WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
// function
function getCanvas : TCanvas;
public
//constructor
constructor create (aowner : TWINCONTROL);
//canvas
property Canvas : TCanvas read getcanvas write setcanvas;
//procedure
procedure BringToFront;
procedure SendToBack;
published
//property
property Left : integer read fleft write setleft;
property Top : integer read ftop write settop;
property Width : integer read fwidth write setwidth;
property Height : integer read fheight write setheight;
property ClientRect : TRect read fClientRect;
property Constraints : TSizeConstraints read fConstraints write setConstraints;
property Cursor : TCursor read fCursor write setCursor;
property ClientOrigin : TPoint read fClientOrigin;
property Align : TAlign read fAlign write setAlign;
property Anchors : TAnchors read fAnchors write setAnchors;
property DragCursor : TCursor read fDragCursor write setDragCursor;
property DragKind : TDragKind read fDragKind write setDragKind;
property DragMode : TDragMode read fDragMode write setDragMode;
property HelpContext : THelpContext read fHelpContext write setHelpContext;
property HelpKeyWord : string read fHelpKeyWord write setHelpKeyWord;
property HelpType : THelpType read fHelpType write setHelpType;
property PopupMenu : TPopupMenu read fPopupMenu write setPopupMenu;
property Tag : integer read fTag write setTag;
property Hint : string read fHint write setHint;
property ShowHint : boolean read fShowHint write setShowHint;
property Visible : boolean read fVisible write setVisible;
//TNotifyEvent
property OnPaint : TNotifyEvent read fPaint write fPaint;
property OnClick : TNotifyEvent read fClick write fClick;
property OndblClick : TNotifyEvent read fdblclick write fdblclick;
property OnMouseMove : TMouseEvent read fMouseMove write fMouseMove;
property OnKeyPress : TKeyPressEvent read fKeyPress write fKeyPress;
property OnMouseWheel : TMouseWheelEvent read fMouseWheel write fMouseWheel;
end;
implementation
constructor TPaintbox32.create(aowner : TWINCONTROL);
begin
inherited create(aowner);
fWidth:=100;
fHeight:=100;
fVisible:=true;
//create
paintbox1:=TPaintbox.Create(aowner);
ScrollBox:=TScrollBox.Create(aowner);
Button:=TButton.Create(aowner);
bmp:=TBitmap.Create;
//with object do
With Paintbox1 do
begin
parent:=aowner;
Width:=fWidth;
Top:=fTop;
Left:=fLeft;
Enabled:=false;
Height:=fHeight;
OnPaint:=Paint;
OnClick:=clic;
OndblClick:=dblClic;
OnMouseMove:=move;
end;
With bmp do
begin
Width:=fWidth;
Height:=fHeight;
end;
With Button do
begin
parent:=self;
Visible:=true;
BringToFront;
Width:=fWidth;
Height:=fHeight;
OnKeyPress:=KeyPress;
end;
With ScrollBox do
begin
parent:=self;
Width:=fWidth;
Height:=fHeight;
OnMouseWheel:=MouseWheel;
end;
fclientrect:=rect(0,0,fWidth,fHeight);
end;
procedure TPaintbox32.setleft(x : integer);
begin
fLeft:=x;
Paintbox1.Left:=fLeft;
end;
procedure TPaintbox32.settop(x : integer);
begin
fTop:=x;
Paintbox1.Top:=ftop;
end;
procedure TPaintbox32.setwidth(x : integer);
begin
fWidth:=x;
Paintbox1.Width:=fWidth;
bmp.Width:=fWidth;
Button.Width:=fWidth;
ScrollBox.Width:=fWidth;
fClientRect:=rect(0,0,fwidth,fheight);
end;
procedure TPaintbox32.setheight(x : integer);
begin
fHeight:=x;
Paintbox1.Height:=fHeight;
bmp.Height:=fHeight;
Button.Height:=fHeight;
ScrollBox.Height:=fHeight;
fClientRect:=rect(0,0,fwidth,fheight);
end;
procedure TPaintbox32.Paint(sender : TObject);
begin
if assigned(fPaint) then fPaint(self);
end;
procedure TPaintbox32.setCanvas(x : TCanvas);
begin
bmp.Assign(x);
end;
function TPaintbox32.getCanvas : TCanvas;
begin
result:=bmp.Canvas;
if fVisible then Paintbox1.Canvas.Draw(0,0,bmp) else Paintbox1.Canvas.Draw(fWidth,fHeight,bmp);
end;
procedure TPaintbox32.setCursor(x : TCursor);
begin
Paintbox1.Cursor:=x;
fCursor:=Paintbox1.Cursor;
end;
procedure TPaintbox32.move(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
fClientOrigin.X:=x;
fClientOrigin.Y:=y;
if assigned(fMouseMove) then fMouseMove(self,shift,x,y);
end;
procedure TPaintbox32.clic(sender : TObject);
begin
if assigned(fclick) then fclick(self);
end;
procedure TPaintbox32.dblclic(sender : TObject);
begin
if assigned(fdblclick) then fdblclick(self);
end;
procedure TPaintbox32.setAlign(x : TAlign);
begin
Paintbox1.Align:=x;
fAlign:=Paintbox1.Align;
fWidth:=Paintbox1.Width;
fHeight:=Paintbox1.Height;
With ScrollBox do
begin
Align:=fAlign;
end;
Button.Align:=fAlign;
bmp.Width:=fWidth;
bmp.Height:=fHeight;
fclientrect:=rect(0,0,fWidth,fHeight);
end;
procedure TPaintbox32.setAnchors(x : TAnchors);
begin
Paintbox1.Anchors:=x;
fAnchors:=Paintbox1.Anchors;
end;
procedure TPaintbox32.setConstraints(x : TSizeConstraints);
begin
Paintbox1.Constraints:=x;
fConstraints:=Paintbox1.Constraints;
end;
procedure TPaintbox32.setDragCursor(x : TCursor);
begin
Paintbox1.DragCursor:=x;
fDragCursor:=Paintbox1.DragCursor;
end;
procedure TPaintbox32.setDragKind(x : TDragKind);
begin
Paintbox1.DragKind:=x;
fDragKind:=Paintbox1.DragKind;
end;
procedure TPaintbox32.setDragMode(x : TDragMode);
begin
Paintbox1.DragMode:=x;
fDragMode:=Paintbox1.DragMode;
end;
procedure TPaintbox32.setHelpContext(x : THelpContext);
begin
Paintbox1.HelpContext:=x;
fHelpContext:=Paintbox1.HelpContext;
end;
procedure TPaintbox32.setHelpKeyWord(x : string);
begin
Paintbox1.HelpKeyword:=x;
fHelpKeyWord:=Paintbox1.HelpKeyword;
end;
procedure TPaintbox32.setHelpType(x : THelpType);
begin
Paintbox1.HelpType:=x;
fHelpType:=Paintbox1.HelpType;
end;
procedure TPaintbox32.setPopupMenu(x : TPopupMenu);
begin
Paintbox1.PopupMenu:=x;
fPopupMenu:=Paintbox1.PopupMenu;
end;
procedure TPaintbox32.setTag(x : integer);
begin
Paintbox1.Tag:=x;
fTag:=Paintbox1.Tag;
end;
procedure TPaintbox32.BringToFront;
begin
Paintbox1.BringToFront;
end;
procedure TPaintbox32.SendToBack;
begin
Paintbox1.SendToBack;
end;
procedure TPaintbox32.setHint(x : string);
begin
Paintbox1.Hint:=x;
fHint:=Paintbox1.Hint;
end;
procedure TPaintbox32.setShowHint(x : boolean);
begin
Paintbox1.ShowHint:=x;
fShowHint:=Paintbox1.ShowHint;
end;
procedure TPaintbox32.setVisible(x : boolean);
begin
Paintbox1.Visible:=x;
fVisible:=Paintbox1.Visible;
end;
procedure TPaintbox32.KeyPress(Sender: TObject; var Key: Char);
begin
key:=upCase(Key);
if assigned(fKeyPress) then fKeyPress(self,key);
end;
procedure TPaintbox32.MouseWheel(Sender: TObject; Shift: TShiftState;WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
begin
if assigned(fMouseWheel) then fMouseWheel(self,shift,WheelDelta,MousePos,Handled);
end;
end. |
Partager