formdesigner.pas 77.5 KB
Newer Older
1
{ MSEide Copyright (c) 1999-2008 by Martin Schreiber
mse1's avatar
mse1 committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
   
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
}
unit formdesigner;

mse1's avatar
mse1 committed
19
{$ifdef FPC}{$mode objfpc}{$h+}{$GOTO ON}{$endif}
mse1's avatar
mse1 committed
20 21 22

interface
uses
mse1's avatar
mse1 committed
23
 classes,mseforms,msegui,mseevent,msegraphutils,msegraphics,msedesignintf,
mse1's avatar
mse1 committed
24
 mseclasses,msemenuwidgets,msemenus,msefiledialog,msedesigner,typinfo,
mse1's avatar
mse1 committed
25
 componentpaletteform,msestrings,msewidgets,mseglob
mse1's avatar
mse1 committed
26
  {$ifdef FPC}{$ifndef mse_withoutdb},msereport{$endif}{$endif};
mse1's avatar
mse1 committed
27 28

type
mse1's avatar
mse1 committed
29 30
 areaty = (ar_none,ar_component,ar_componentmove,ar_selectrect,ht_topleft,
             ht_top,ht_topright,ht_right,
mse1's avatar
mse1 committed
31 32 33 34 35 36 37 38 39 40 41 42
             ht_bottomright,ht_bottom,ht_bottomleft,ht_left);
 markerty = (mt_topleft,mt_topright,mt_bottomright,mt_bottomleft);

const
 firsthandle = ht_topleft;
 lasthandle = ht_left;
 defaultgridsizex = 8;
 defaultgridsizey = 8;
 handlesize = 5;
 componentsize = 24;
 complabelleftmargin = 2;
 complabelrightmargin = 2 + handlesize div 2;
mse1's avatar
mse1 committed
43
 movethreshold = 3;
mse1's avatar
mse1 committed
44 45

type
mse1's avatar
mse1 committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
 formselectedinfoty = record
  selectedinfo: selectedinfoty;
  rect: rectty;
  nohandles: boolean;
  handles: array[firsthandle..lasthandle] of rectty;
  markers: array[markerty] of rectty;
 end;

 pformselectedinfoty = ^formselectedinfoty;

 tdesignwindow = class;

 tformdesignerselections = class(tdesignerselections)
  private
   fowner: tdesignwindow;
   finfovalid: boolean;
   fmovingchecked: boolean;
mse1's avatar
mse1 committed
63
   fcandelete: boolean;
mse1's avatar
mse1 committed
64 65 66 67 68 69 70 71
   procedure paint(const canvas: tcanvas);
   procedure beforepaintmoving;
   procedure paintmoving(const canvas: tcanvas; const pos: pointty);
   function move(const dist: pointty): boolean;
                  //false if nothing is moved
   procedure resize(const dist: pointty);
   procedure deletecomponents;
   function getareainfo(const pos: pointty; out index: integer): areaty;
mse1's avatar
mse1 committed
72
   function getcandelete: boolean;
mse1's avatar
mse1 committed
73
   procedure updateinfos;
mse1's avatar
mse1 committed
74 75 76 77
  protected
   function getrecordsize: integer; override;
   procedure externalcomponentchanged(const acomponent: tobject);
   procedure removeforeign; //removes form and components in other modules
mse1's avatar
mse1 committed
78
   property candelete: boolean read getcandelete;
mse1's avatar
mse1 committed
79 80 81 82 83 84 85 86 87 88 89 90 91
  public
   constructor create(owner: tdesignwindow);
   function assign(const source: idesignerselections): boolean;
              //true if owned components involved
   function remove(const ainstance: tcomponent): integer; override;
   procedure change; override;
   procedure dochanged; override;
   procedure componentschanged;
   function itempo(const index: integer): pformselectedinfoty;
 end;
 
 selectmodety = (sm_select,sm_add,sm_flip,sm_remove);

mse1's avatar
mse1 committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
 tformdesignerfo = class(tmseform)
   popupme: tpopupmenu;
   procedure doshowobjectinspector(const sender: tobject);
   procedure doshowcomponentpalette(const sender: tobject);
   procedure doshowastext(const sender: tobject);
   procedure doeditcomponent(const sender: tobject);
   procedure doinsertsubmodule(const sender: tobject);
   procedure dobringtofront(const sender: tobject);
   procedure dosendtoback(const sender: tobject);
   procedure dosettaborder(const sender: tobject);
   procedure dosyncfontheight(const sender: tobject);
   procedure copyexe(const sender: TObject);
   procedure pasteexe(const sender: TObject);
   procedure deleteexe(const sender: TObject);
   procedure undeleteexe(const sender: TObject);
   procedure cutexe(const sender: TObject);
   procedure calcscrollsize(const sender: tscrollingwidget; var asize: sizety);
   procedure formdeonclose(const sender: TObject);
   procedure revertexe(const sender: TObject);
111
   procedure doinsertcomponent(const sender: TObject);
112
   procedure dotouch(const sender: TObject);
113
   procedure dosetcreationorder(const sender: TObject);
mse1's avatar
mse1 committed
114 115 116 117
  private
   fdesigner: tdesigner;
   fform: twidget;
   fmodule: tmsecomponent;
mse1's avatar
mse1 committed
118
   fmoduleintf: pdesignmoduleintfty;
mse1's avatar
mse1 committed
119
   fmodulesetting: integer;
120
   fformsizesetting: integer;
mse1's avatar
mse1 committed
121
   procedure setmodule(const Value: tmsecomponent);
mse1's avatar
mse1 committed
122
   function getselections: tformdesignerselections;
mse1's avatar
mse1 committed
123
  protected
mse1's avatar
mse1 committed
124
   property selections: tformdesignerselections read getselections;
mse1's avatar
mse1 committed
125
   procedure formcontainerscrolled;
mse1's avatar
mse1 committed
126 127 128 129 130 131 132
   procedure widgetregionchanged(const sender: twidget); override;
   procedure sizechanged; override;
   procedure doasyncevent(var atag: integer); override;
   procedure dobeforepaint(const canvas: tcanvas); override;
   procedure doafterpaint(const canvas: tcanvas); override;
   procedure createwindow; override;
   procedure doactivate; override;
mse1's avatar
mse1 committed
133 134 135 136
   procedure validaterename(acomponent: tcomponent;
                                      const curname, newname: string); override;
   procedure notification(acomponent: tcomponent;
                                      operation: toperation); override;
mse1's avatar
mse1 committed
137
   procedure doshow; override;
mse1's avatar
mse1 committed
138

mse1's avatar
mse1 committed
139 140
   procedure componentselected(const aselections: tformdesignerselections); virtual;
   function getmoduleparent: twidget; virtual;
mse1's avatar
mse1 committed
141 142 143
   function insertoffset: pointty; virtual;
   function gridoffset: pointty; virtual;
   function gridrect: rectty; virtual;
144 145
   function widgetrefpoint: pointty; virtual;
   function compplacementrect: rectty; virtual;
mse1's avatar
mse1 committed
146 147 148 149
   function gridsizex: integer; virtual;
   function gridsizey: integer; virtual;
   function showgrid: boolean; virtual;
   function snaptogrid: boolean; virtual;
150 151
   procedure recalcclientsize;
   procedure setcomponentscrollsize(const avalue: sizety); virtual;
mse1's avatar
mse1 committed
152 153 154
   class function fixformsize: boolean; virtual;
   function getdesignrect: rectty; virtual;
   procedure setdesignrect(const arect: rectty); virtual;
mse1's avatar
mse1 committed
155
   function candelete(const acomponent: tcomponent): boolean; virtual;
mse1's avatar
mse1 committed
156
   procedure componentmoving(const apos: pointty); virtual;
157 158
   procedure placecomponent(const component: tcomponent; const apos: pointty;
                                 aparent: tcomponent = nil);
mse1's avatar
mse1 committed
159
  public
mse1's avatar
mse1 committed
160
   constructor create(const aowner: tcomponent; const adesigner: tdesigner;
161
                      const aintf: pdesignmoduleintfty); reintroduce; virtual;
mse1's avatar
mse1 committed
162
                        
mse1's avatar
mse1 committed
163
   destructor destroy; override;
mse1's avatar
mse1 committed
164
   function designnotification: idesignnotification;
mse1's avatar
mse1 committed
165
   property modulerect: rectty read fwidgetrect;
mse1's avatar
mse1 committed
166
   procedure updatecaption;
mse1's avatar
mse1 committed
167 168 169
   procedure placemodule;
   procedure beginplacement;
   procedure endplacement;
mse1's avatar
mse1 committed
170 171
   procedure beginstreaming; virtual;
   procedure endstreaming; virtual;
mse1's avatar
mse1 committed
172 173 174 175
   property module: tmsecomponent read fmodule write setmodule;
   property form: twidget read fform;
 end;

mse1's avatar
mse1 committed
176 177
 designformclassty = class of tformdesignerfo;

mse1's avatar
mse1 committed
178 179 180 181 182 183 184 185 186 187 188 189 190 191
 tdesignwindow = class(twindow,idesignnotification)
  private
   fpickpos: pointty;
   fmousepos: pointty;
   fpickwidget: twidget;
   fsizerect,factsizerect: rectty;
   fxorpicoffset: pointty;
   fxorpicactive: boolean;
   fxorpicshowed: boolean;
   factarea: areaty;
   factcompindex: integer;
   fselecting: integer;
   fselections: tformdesignerselections;
   fdesigner: tdesigner;
mse1's avatar
mse1 committed
192 193
   fgridsizex: integer;
   fgridsizey: integer;
mse1's avatar
mse1 committed
194 195 196 197
   fsnaptogrid: boolean;
   fshowgrid: boolean;
   fdelobjs: objinfoarty;
   fclipinitcomps: boolean;
198 199
   finitcompsoffset: pointty;
   fuseinitcompsoffset: boolean;
200
   fcompsoffsetused: boolean;
mse1's avatar
mse1 committed
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
   fclickedcompbefore: tcomponent;
   procedure drawgrid(const canvas: tcanvas);
   procedure hidexorpic(const canvas: tcanvas);
   procedure showxorpic(const canvas: tcanvas);
   procedure paintxorpic(const canvas: tcanvas);
   procedure checkdelobjs(const aitem: tcomponent);

   procedure doaddcomponent(component: tcomponent);
   procedure doinitcomponent(component: tcomponent; parent: tcomponent);

   procedure setshowgrid(const avalue: boolean);
   procedure setgridsizex(const avalue: integer);
   procedure setgridsizey(const avalue: integer);
   procedure doundelete;
   procedure dodelete;
216
   procedure dopaste(const usemousepos: boolean);
mse1's avatar
mse1 committed
217 218 219
   procedure docopy(const noclear: boolean);
   procedure docut;
   procedure recalcclientsize;
220 221
   procedure adjustchildcomponentpos(var apos: pointty);
   procedure readjustchildcomponentpos(var apos: pointty);
mse1's avatar
mse1 committed
222
  protected
223 224 225 226
   function getcomponentrect(const component: tcomponent): rectty;
   function getcomponentrect1(const component: tcomponent): rectty;
   function componentatpos(const pos: pointty): tcomponent;
 
mse1's avatar
mse1 committed
227 228 229 230 231 232 233 234 235 236 237 238
   procedure sizechanged; override;
   procedure poschanged; override;
   procedure dispatchmouseevent(var info: mouseeventinfoty; capture: twidget); override;
   procedure dispatchkeyevent(const eventkind: eventkindty; var info: keyeventinfoty); override;
   procedure dobeforepaint(const canvas: tcanvas);
   procedure doafterpaint(const canvas: tcanvas);
   procedure movewindowrect(const dist: pointty; const rect: rectty); override;
   function dosnaptogrid(const pos: pointty): pointty;
   function snaptogriddelta(const pos: pointty): pointty;
   function form: twidget;
   function module: tmsecomponent;
   function componentscrollsize: sizety;
239
   function componentoffset: pointty;
mse1's avatar
mse1 committed
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

   procedure setrootpos(const component: tcomponent; const apos: pointty);
   procedure beginselect;
   procedure endselect;
   procedure updateselections;
   procedure deletecomponent(const component: tcomponent);
   procedure selectcomponent(const component: tcomponent; mode: selectmodety = sm_select);
   procedure clearselection;
   procedure domodified;

   procedure dopopup(var info: mouseeventinfoty);

   function widgetatpos(const apos: pointty; onlywidgets: boolean): twidget;

   //idesignnotification
   procedure itemdeleted(const adesigner: idesigner;
                  const amodule: tmsecomponent; const aitem: tcomponent);
   procedure iteminserted(const adesigner: idesigner;
                  const amodule: tmsecomponent; const aitem: tcomponent);
   procedure itemsmodified(const adesigner: idesigner; const aitem: tobject);
   procedure componentnamechanging(const adesigner: idesigner;
                     const amodule: tmsecomponent; const aitem: tcomponent;
                     const newname: string);
   procedure moduleclassnamechanging(const adesigner: idesigner;
                     const amodule: tmsecomponent; const newname: string);
   procedure instancevarnamechanging(const adesigner: idesigner;
                     const amodule: tmsecomponent; const newname: string);
   procedure selectionchanged(const adesigner: idesigner;
                                    const aselection: idesignerselections);
   procedure moduleactivated(const adesigner: idesigner; const amodule: tmsecomponent);
   procedure moduledeactivated(const adesigner: idesigner; 
                   const amodule: tmsecomponent);
   procedure moduledestroyed(const adesigner: idesigner; const amodule: tmsecomponent);
   procedure methodcreated(const adesigner: idesigner;
                          const amodule: tmsecomponent;
                          const aname: string; const atype: ptypeinfo);
   procedure methodnamechanged(const adesigner: idesigner;
                          const amodule: tmsecomponent;
                          const newname,oldname: string; const atypeinfo: ptypeinfo);
   procedure showobjecttext(const adesigner: idesigner;
                  const afilename: filenamety; const backupcreated: boolean);
   procedure closeobjecttext(const adesigner: idesigner;
                    const afilename: filenamety; var cancel: boolean);
283 284
   procedure beforefilesave(const adesigner: idesigner;
                                    const afilename: filenamety);
mse1's avatar
mse1 committed
285 286 287
   procedure beforemake(const adesigner: idesigner; const maketag: integer;
                         var abort: boolean);
   procedure aftermake(const adesigner: idesigner; const exitcode: integer);
mse1's avatar
mse1 committed
288 289

  public
mse1's avatar
mse1 committed
290
   constructor create(const aowner: tformdesignerfo; const adesigner: tdesigner);
mse1's avatar
mse1 committed
291 292 293 294 295 296 297 298 299 300
   destructor destroy; override;
   procedure updateprojectoptions;
   property snaptogrid: boolean read fsnaptogrid write fsnaptogrid default true;
   property showgrid: boolean read fshowgrid write setshowgrid default true;
   property gridsizex: integer read fgridsizex write setgridsizex 
                                     default defaultgridsizex;
   property gridsizey: integer read fgridsizey write setgridsizey
                                     default defaultgridsizey;
 end;

mse1's avatar
mse1 committed
301 302 303
procedure registerdesignmoduleclass(const aclass: tcomponentclass;
                               const aintf: designmoduleintfty;
                               const adesignformclass: designformclassty = nil);
mse1's avatar
mse1 committed
304 305
function createdesignmodule(const amodule: pmoduleinfoty; designmoduleclassname: string;
                           const aclassname: pshortstring): tmsecomponent;
mse1's avatar
mse1 committed
306 307 308 309 310
function createdesignform(const aowner: tdesigner; 
                 const amodule: pmoduleinfoty): tformdesignerfo;
function selectinheritedmodule(const amodule: pmoduleinfoty;
                               const caption: msestring = ''): pmoduleinfoty;

mse1's avatar
mse1 committed
311 312 313 314
implementation
uses
 formdesigner_mfm,mselist,msekeyboard,mseguiglob,msepointer,msebits,sysutils,
 msestockobjects,msedrawtext,selectsubmoduledialogform,mseshapes,settaborderform,
315
 msedatalist,objectinspector,projectoptionsform,main,msedatamodules,msetypes,
mse1's avatar
mse1 committed
316
 setcreateorderform,mseactions;
mse1's avatar
mse1 committed
317 318 319 320 321 322

type
 tcomponent1 = class(tcomponent);
 twidget1 = class(twidget);
 tmseform1 = class(tmseform);
 tframe1 = class(tframe);
323
 tscrollingwidget1 = class(tscrollingwidget);
mse1's avatar
mse1 committed
324

mse1's avatar
mse1 committed
325 326
 designerfoeventty = (fde_none,fde_syncsize,fde_updatecaption,fde_scrolled,
                      fde_showastext);
mse1's avatar
mse1 committed
327

mse1's avatar
mse1 committed
328 329 330
 designmoduleinfoty = record
  classtype: tcomponentclass;
  intf: pdesignmoduleintfty;
mse1's avatar
mse1 committed
331
  formclass: designformclassty;
mse1's avatar
mse1 committed
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
 end;
 designmoduleinfoarty = array of designmoduleinfoty;

 tdesignmoduleinfoar = class
  private
   flist: designmoduleinfoarty;
 end;
 
var
 fregistereddesignmoduleclasses: tdesignmoduleinfoar;

function registereddesignmoduleclasses: tdesignmoduleinfoar;
begin
 if fregistereddesignmoduleclasses = nil then begin
  fregistereddesignmoduleclasses:= tdesignmoduleinfoar.create;
 end;
 result:= fregistereddesignmoduleclasses;
end;
 
procedure registerdesignmoduleclass(const aclass: tcomponentclass;
                               const aintf: designmoduleintfty;
                               const adesignformclass: designformclassty = nil);
var
 int1: integer;
begin
 with registereddesignmoduleclasses do begin
  for int1:= 0 to high(flist) do begin
   with flist[int1] do begin
    if classtype = aclass then begin
     intf:= @aintf;
mse1's avatar
mse1 committed
362
     formclass:= adesignformclass;
mse1's avatar
mse1 committed
363 364 365 366 367 368 369 370 371
     exit;
    end;
   end;
  end;
  registerclass(aclass);
  setlength(flist,high(flist)+2);
  with flist[high(flist)] do begin
   classtype:= aclass;
   intf:= @aintf;
mse1's avatar
mse1 committed
372
   formclass:= adesignformclass;
mse1's avatar
mse1 committed
373 374 375 376
  end;
 end;
end;

mse1's avatar
mse1 committed
377 378
function createdesignmodule(const amodule: pmoduleinfoty; designmoduleclassname: string;
              const aclassname: pshortstring): tmsecomponent;
mse1's avatar
mse1 committed
379 380 381
var
 int1: integer;
begin
mse1's avatar
mse1 committed
382 383 384 385 386 387 388 389 390 391 392 393 394 395
 with amodule^ do begin
  if designmoduleclassname = '' then begin
   designmoduleclassname:= defaultmoduleclassname;
  end;
  designmoduleclassname:= uppercase(designmoduleclassname);
  with registereddesignmoduleclasses do begin
   for int1:= 0 to high(flist) do begin
    with flist[int1] do begin
     if uppercase(classtype.classname) = designmoduleclassname then begin
      designformclass:= formclass;
      moduleintf:= intf;
      result:= intf^.createfunc(classtype,aclassname);
      exit;
     end;
mse1's avatar
mse1 committed
396 397 398 399 400 401 402 403 404 405 406
    end;
   end;
  end;
 end;
 raise exception.Create('Unknown moduleclass for "'+ aclassname^ +'": "'+
              designmoduleclassname+'".');
end;

function createdesignform(const aowner: tdesigner; 
                 const amodule: pmoduleinfoty): tformdesignerfo;
begin
mse1's avatar
mse1 committed
407 408 409 410 411 412 413
 with amodule^ do begin
  if designformclass = nil then begin
   designformclass:= tformdesignerfo;
  end;
  result:= designformclassty(designformclass).create(nil,aowner,moduleintf);
  result.module:= instance;
 end;
mse1's avatar
mse1 committed
414
end;
415
{
mse1's avatar
mse1 committed
416 417 418 419
function getcomponentrect(const sender: twidget;
                                    const component: tcomponent): rectty;
begin
 result.pos:= getcomponentpos(component);
420
 addpoint1(result.pos,tdesignwindow(sender.window).componentoffset);
mse1's avatar
mse1 committed
421 422 423 424 425 426 427 428 429 430
 result.cx:= componentsize + complabelleftmargin + 
                 sender.getcanvas.getstringwidth(component.name) +
                  complabelrightmargin;
 result.cy:= componentsize;
end;

function getcomponentrect1(const sender: twidget; const component: tcomponent;
                                     const module: tcomponent): rectty;
var
 comp1: tcomponent;
431
 bo1: boolean;
mse1's avatar
mse1 committed
432 433 434 435
begin
 result:= getcomponentrect(sender,component);
 if module is twidget then begin
  comp1:= component;
436
  bo1:= false;
mse1's avatar
mse1 committed
437 438
  while (comp1 <> module) and (comp1 <> nil) do begin
   if comp1 is twidget then begin
439 440 441 442
    if not bo1 then begin
     tdesignwindow(sender.window).adjustchildcomponentpos(result.pos);
     bo1:= true;
    end;
mse1's avatar
mse1 committed
443 444 445 446 447 448
    addpoint1(result.pos,twidget(comp1).pos);
   end;
   comp1:= comp1.owner;
  end;
 end;
end;
449
}
mse1's avatar
mse1 committed
450

451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
function tdesignwindow.getcomponentrect(const component: tcomponent): rectty;
begin
 result.pos:= getcomponentpos(component);
 addpoint1(result.pos,componentoffset);
 result.cx:= componentsize + complabelleftmargin + 
                 fowner.getcanvas.getstringwidth(component.name) +
                  complabelrightmargin;
 result.cy:= componentsize;
end;

function tdesignwindow.getcomponentrect1(const component: tcomponent): rectty;
var
 comp1: tcomponent;
 bo1: boolean;
begin
 result:= getcomponentrect(component);
 if tformdesignerfo(fowner).fform <> nil then begin
  comp1:= component;
  bo1:= false;
  while (comp1 <> module) and (comp1 <> nil) do begin
   if comp1 is twidget then begin
    if not bo1 then begin
     adjustchildcomponentpos(result.pos);
     bo1:= true;
    end;
    addpoint1(result.pos,twidget(comp1).pos);
   end;
   comp1:= comp1.owner;
  end;
 end;
end;

function tdesignwindow.componentatpos(const pos: pointty): tcomponent;
mse1's avatar
mse1 committed
484 485 486 487 488 489 490 491 492 493 494 495

var
 isdatamodule: boolean;
 toplevel: boolean;
                                       
 function checkcomponent(const component: tcomponent; const pos: pointty): tcomponent;
 var
  int1: integer;
  po1: pointty;
  bo1: boolean;
 begin
  result:= nil;
496 497
  bo1:= (component is twidget) and not isdatamodule;
  if bo1 and not toplevel then begin
mse1's avatar
mse1 committed
498
   po1:= subpoint(pos,twidget(component).pos);
499 500 501
   if (component.owner = module) and (module is twidget) then begin
    tdesignwindow(twidget(component).window).readjustchildcomponentpos(po1);
   end;
mse1's avatar
mse1 committed
502 503 504 505 506 507 508
  end
  else begin
   po1:= pos;
  end;
  if toplevel or 
              not isdatamodule and bo1 and 
              not (cssubcomponent in component.componentstyle) and
509
              (component.componentstate * [csinline,csancestor] <> []) then begin
mse1's avatar
mse1 committed
510 511 512 513 514 515 516 517
   toplevel:= false;
   for int1:= component.componentcount - 1 downto 0 do begin
    result:= checkcomponent(component.components[int1],po1);
    if result <> nil then begin
     exit;
    end;
   end;
  end;
518 519
  if not bo1 {or isdatamodule} then begin
   if pointinrect(pos,getcomponentrect(component)) then begin
mse1's avatar
mse1 committed
520 521 522 523 524 525
    result:= component;
   end;
  end;
 end;
 
begin
526
 isdatamodule:= tformdesignerfo(fowner).fform = nil;
mse1's avatar
mse1 committed
527
 toplevel:= true;
528 529
 result:= checkcomponent(tformdesignerfo(fowner).fmodule,pos);
 if result = tformdesignerfo(fowner).fmodule then begin
mse1's avatar
mse1 committed
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
  result:= nil;
 end;
end;

{ tformdesignerselections }

constructor tformdesignerselections.create(owner: tdesignwindow);
begin
 fowner:= owner;
 inherited create;
end;

function tformdesignerselections.assign(const source: idesignerselections): boolean;
              //true if owned components involved
var
 amodule: tmsecomponent;

 procedure checkowned;
 var
  int1: integer;
  po1: pformselectedinfoty;
 begin
  po1:= datapo;
  for int1:= 0 to count - 1 do begin
   if (po1^.selectedinfo.instance = amodule) or
           (po1^.selectedinfo.instance.Owner = amodule) then begin
    result:= true;
    break;
   end;
   inc(po1);
  end;
 end;

begin
 result:= false;
 amodule:= tformdesignerfo(fowner.fowner).fmodule;
 checkowned;
 inherited assign(source);
 if not result then begin
  checkowned;
 end;
end;

procedure tformdesignerselections.updateinfos;
var
 marker: markerty;
 int1: integer;
begin
 if not finfovalid then begin
mse1's avatar
mse1 committed
579
  fcandelete:= count > 0;
mse1's avatar
mse1 committed
580 581 582
  for int1:= 0 to count - 1 do begin
   with itempo(int1)^,selectedinfo do begin
    if (instance is twidget) and (fowner.form <> nil) then begin
mse1's avatar
mse1 committed
583 584 585
     with twidget1(instance) do begin
      nohandles:= ws1_nodesignhandles in fwidgetstate1;
      fcandelete:= fcandelete and not (ws1_nodesigndelete in fwidgetstate1);
mse1's avatar
mse1 committed
586 587 588 589
      rect:= makerect(rootpos,size);
     end;
    end
    else begin
mse1's avatar
mse1 committed
590
     nohandles:= false;
mse1's avatar
mse1 committed
591
     if instance is tcomponent then begin
592
      rect:= fowner.getcomponentrect1(tcomponent(instance));
mse1's avatar
mse1 committed
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667
     end
     else begin
      rect:= nullrect;
     end;
    end;
    with rect do begin
     centerrect(pos,handlesize,handles[ht_topleft]);
     centerrect(makepoint(x+cx div 2,y),handlesize,handles[ht_top]);
     centerrect(makepoint(x+cx-1,y),handlesize,handles[ht_topright]);
     centerrect(makepoint(x+cx-1,y+cy div 2),handlesize,handles[ht_right]);
     centerrect(makepoint(x+cx-1,y+cy-1),handlesize,handles[ht_bottomright]);
     centerrect(makepoint(x+cx div 2,y+cy-1),handlesize,handles[ht_bottom]);
     centerrect(makepoint(x,y+cy-1),handlesize,handles[ht_bottomleft]);
     centerrect(makepoint(x,y+cy div 2),handlesize,handles[ht_left]);

     for marker:= low(marker) to high(marker) do begin
      markers[marker].cx:= handlesize;
      markers[marker].cy:= handlesize;
     end;
     markers[mt_topleft].pos:= pos;
     markers[mt_topright].x:= x + cx - handlesize;
     markers[mt_topright].y:= y;
     markers[mt_bottomright].x:= x + cx - handlesize;
     markers[mt_bottomright].y:= y + cy - handlesize;
     markers[mt_bottomleft].x:= x;
     markers[mt_bottomleft].y:= y + cy - handlesize;

    end;
   end;
  end;
 end;
 finfovalid:= true;
end;

procedure tformdesignerselections.beforepaintmoving;
begin
 if not fmovingchecked then begin
  removeforeign;
  fmovingchecked:= true;
 end;
 updateinfos;
end;

procedure tformdesignerselections.paintmoving(const canvas: tcanvas;
                 const pos: pointty);
var
 int1: integer;
 po1: pformselectedinfoty;
begin
 beforepaintmoving;
 with canvas do begin
  save;
  move(pos);
  rasterop:= rop_xor;
  for int1:= 0 to count-1 do begin
   po1:= itempo(int1);
   if po1^.selectedinfo.instance <> fowner.module then begin
    drawframe(itempo(int1)^.rect,-2,cl_white);
   end;
  end;
  restore;
 end;
end;

procedure tformdesignerselections.paint(const canvas: tcanvas);
var
 int1: integer;
 handle: areaty;
 marker: markerty;
begin
 updateinfos;
 with canvas do begin
  if count > 1 then begin
   for int1:= 0 to count - 1 do begin
    with itempo(int1)^,selectedinfo do begin
668 669
     if not nohandles and (instance <> fowner.module) and 
                            fowner.module.checkowned(instance) then begin
mse1's avatar
mse1 committed
670 671 672 673 674 675 676 677 678 679
      for marker:= low(markerty) to high(markerty) do begin
       fillrect(markers[marker],cl_dkgray);
      end;
     end;
    end;
   end;
  end
  else begin
   for int1:= 0 to count - 1 do begin
    with itempo(int1)^,selectedinfo do begin
mse1's avatar
mse1 committed
680 681
     if not nohandles and (instance <> fowner.module) and 
                               fowner.module.checkowned(instance) then begin
mse1's avatar
mse1 committed
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696
      for handle:= firsthandle to lasthandle do begin
       fillrect(handles[handle],cl_black);
      end;
     end;
    end;
   end;
  end;
 end;
end;

function tformdesignerselections.move(const dist: pointty): boolean;
var
 int1: integer;
 widget1: twidget;
 comp1: tcomponent;
697
 rect1,rect2: rectty;
698
 pt1: pointty;
mse1's avatar
mse1 committed
699 700 701 702 703 704
begin
 result:= false;
 if (dist.x <> 0) or (dist.y <> 0) then begin
  for int1:= 0 to count - 1 do begin
   with itempo(int1)^,selectedinfo do begin
    if (fowner.form <> nil) and (instance is twidget) and
mse1's avatar
mse1 committed
705 706 707 708 709 710 711 712
                                    (instance <> fowner.module) then begin
     if not nohandles then begin
      widget1:= twidget(instance).parentwidget;
      while widget1 <> nil do begin
       if (widget1 <> fowner.form) and (indexof(widget1) >= 0) then begin
        break;  //moved by parent
       end;
       widget1:= widget1.parentwidget;
mse1's avatar
mse1 committed
713
      end;
mse1's avatar
mse1 committed
714 715 716 717 718
      if widget1 = nil then begin
       with twidget(instance) do begin
        pos:= addpoint(pos,dist);
        result:= true;
       end;
mse1's avatar
mse1 committed
719 720 721 722 723 724 725 726 727 728 729 730 731
      end;
     end;
    end
    else begin
     comp1:= tcomponent(instance).owner;
     while comp1 <> nil do begin
      if (comp1 <> fowner.module) and (comp1 is twidget) and
                                        (indexof(comp1) >= 0) then begin 
       break; //moved by owner
      end;
      comp1:= comp1.owner;
     end;
     if comp1 = nil then begin
732
      rect1:= fowner.getcomponentrect1(tcomponent(instance));
733
      fowner.fowner.invalidaterect(rect1);
734
      pt1:= rect1.pos;
735 736
      addpoint1(rect1.pos,dist);
      with tformdesignerfo(fowner.fowner) do begin
737
       rect2:= compplacementrect;
738 739
       if form <> nil then begin      
        shiftinrect(rect1,rect2);
740
//        subpoint1(rect1.pos,rect2.pos);
741 742 743 744 745 746 747 748 749 750
       end
       else begin
        if rect1.x < rect2.x then begin
         rect1.x:= rect2.x;
        end;
        if rect1.y < rect2.y then begin
         rect1.y:= rect2.y;
        end;
       end;
      end;
751 752 753
      setcomponentpos(tcomponent(instance),
                addpoint(getcomponentpos(tcomponent(instance)),
                subpoint(rect1.pos,pt1)));
754 755
      fowner.fowner.invalidaterect(rect1);
{                                         
mse1's avatar
mse1 committed
756 757 758 759 760
      setcomponentpos(tcomponent(instance),
             addpoint(getcomponentpos(tcomponent(instance)),dist));
      fowner.fowner.invalidaterect(getcomponentrect1(
                                         fowner.fowner,tcomponent(instance),
                                         fowner.module));
761
                                         }
mse1's avatar
mse1 committed
762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779
      result:= true;
     end;
    end;
   end;
  end;
  componentschanged;
 end;
end;

procedure tformdesignerselections.resize(const dist: pointty);
var
 int1: integer;
begin
 if (dist.x <> 0) or (dist.y <> 0) then begin
  for int1:= 0 to count - 1 do begin
   with itempo(int1)^,selectedinfo do begin
    if instance is twidget then begin
     with twidget(instance) do begin
mse1's avatar
mse1 committed
780 781 782
      if not nohandles then begin
       size:= sizety(addpoint(pointty(size),dist));
      end;
mse1's avatar
mse1 committed
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827
     end;
    end;
   end;
  end;
  componentschanged;
 end;
end;

procedure tformdesignerselections.change;
begin
 finfovalid:= false;
 fmovingchecked:= false;
 inherited;
end;

procedure tformdesignerselections.dochanged;
begin
 inherited;
 fowner.fowner.invalidate;
end;

procedure tformdesignerselections.componentschanged;
var
 int1: integer;
begin
 change;
 for int1:= 0 to count - 1 do begin
  fowner.fdesigner.componentmodified(items[int1]);
 end;
end;

procedure tformdesignerselections.externalcomponentchanged(const acomponent: tobject);
begin
 finfovalid:= false;
 if count > 0 then begin
  fowner.fowner.invalidate;
 end;
end;

function tformdesignerselections.getareainfo(const pos: pointty;
                out index: integer): areaty;
var
 handle: areaty;
 int1: integer;
begin
828
 updateinfos;
mse1's avatar
mse1 committed
829 830 831 832
 result:= ar_none;
 index:= -1;
 if count = 1 then begin
  with itempo(0)^,selectedinfo do begin
mse1's avatar
mse1 committed
833 834 835 836 837 838 839 840 841
   if not nohandles then begin
    if instance is tcomponent then begin
     if instance is twidget then begin
      for handle:= firsthandle to lasthandle do begin
       if pointinrect(pos,handles[handle]) then begin
        result:= handle;
        index:= 0;
        exit;
       end;
mse1's avatar
mse1 committed
842 843
      end;
     end;
mse1's avatar
mse1 committed
844 845 846 847 848
     if pointinrect(pos,rect) then begin
      result:= ar_component;
      index:= 0;
      exit;
     end;
mse1's avatar
mse1 committed
849 850 851 852 853 854 855
    end;
   end;
  end;
 end
 else begin
  for int1:= 0 to count - 1 do begin
   with itempo(int1)^,selectedinfo do begin
mse1's avatar
mse1 committed
856 857 858 859 860 861
    if not nohandles then begin
     if pointinrect(pos,rect) and (instance is tcomponent) then begin
      result:= ar_component;
      index:= int1;
      break;
     end;
mse1's avatar
mse1 committed
862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923
    end;
   end;
  end;
 end;
end;

procedure tformdesignerselections.deletecomponents;
var
 int1: integer;
 int2: integer;
begin
 int2:= count;
 beginupdate;
 for int1:= count-1 downto 0 do begin
  if isembedded(items[int1]) then begin
   delete(int1);
  end;
 end;
 endupdate;
 if count <> int2 then begin
  fowner.updateselections;
 end;
 fowner.fDesigner.DeleteSelection;
end;

function tformdesignerselections.getrecordsize: integer;
begin
 result:= sizeof(formselectedinfoty);
end;

function tformdesignerselections.itempo(
  const index: integer): pformselectedinfoty;
begin
 result:= pformselectedinfoty(getitempo(index));
end;

function tformdesignerselections.remove(
  const ainstance: tcomponent): integer;
begin
 if ainstance = fowner.fpickwidget then begin
  fowner.fpickwidget:= nil;
 end;
 result:= inherited remove(ainstance);
end;

procedure tformdesignerselections.removeforeign; 
    //removes form and components in other modules
var
 int1: integer;
 co1: tcomponent;
begin
 beginupdate;
 for int1:= count - 1 downto 0 do begin
  co1:= items[int1];
  if (co1 = fowner.module) or not fowner.module.checkowned(co1) then begin
   delete(int1);
  end;
 end;
 endupdate;
 fowner.updateselections;
end;

mse1's avatar
mse1 committed
924 925 926 927 928 929
function tformdesignerselections.getcandelete: boolean;
begin
 updateinfos;
 result:= fcandelete;
end;

mse1's avatar
mse1 committed
930 931
{ tdesignwindow }

mse1's avatar
mse1 committed
932 933
constructor tdesignwindow.create(const aowner: tformdesignerfo; 
                                   const adesigner: tdesigner);
mse1's avatar
mse1 committed
934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956
begin
 fdesigner:= adesigner;
 fshowgrid:= true;
 fsnaptogrid:= true;
 fgridsizex:= defaultgridsizex;
 fgridsizey:= defaultgridsizey;
 fselections:= tformdesignerselections.create(self);
 inherited create(aowner);
 updateprojectoptions;
 designnotifications.registernotification(idesignnotification(self));
end;

destructor tdesignwindow.destroy;
begin
 designnotifications.unregisternotification(idesignnotification(self));
 inherited;
 fselections.free;
end;

procedure tdesignwindow.paintxorpic(const canvas: tcanvas);
begin
 if fxorpicactive then begin
  canvas.save;
mse1's avatar
mse1 committed
957 958
//  canvas.intersectcliprect(fowner.container.paintrect);
  canvas.intersectcliprect(tformdesignerfo(fowner).gridrect);
959
//  canvas.move(fowner.container.clientpos);
mse1's avatar
mse1 committed
960 961 962 963 964 965 966 967 968
  case factarea of
   firsthandle..lasthandle: begin
    with canvas do begin
     save;
     rasterop:= rop_xor;
     drawframe(factsizerect,-2,cl_white);
     restore;
    end;
   end;
mse1's avatar
mse1 committed
969
   ar_componentmove: begin
mse1's avatar
mse1 committed
970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018
    fselections.paintmoving(canvas,fxorpicoffset);
   end;
   ar_selectrect: begin
    with canvas do begin
     drawxorframe(fpickpos,fxorpicoffset,1,stockobjects.bitmaps[stb_block3]);
    end;
   end;
  end;
  canvas.restore;
 end;
end;

procedure tdesignwindow.hidexorpic(const canvas: tcanvas);
begin
 if fxorpicshowed then begin
  paintxorpic(canvas);
  fxorpicshowed:= false;
 end;
end;

procedure tdesignwindow.showxorpic(const canvas: tcanvas);
begin
 if not fxorpicshowed then begin
  paintxorpic(canvas);
  fxorpicshowed:= true;
 end;
end;

procedure tdesignwindow.movewindowrect(const dist: pointty; const rect: rectty);
var
 canvas: tcanvas;
begin
 if isnullpoint(dist) then begin
  exit;
 end;
 canvas:= fowner.getcanvas(org_widget);
 hidexorpic(canvas);
 fxorpicactive:= false;
 fselections.change;
 inherited;
 invalidaterect(moverect(rect,dist)); //redraw grid
end;

procedure tdesignwindow.dobeforepaint(const canvas: tcanvas);
begin
 hidexorpic(canvas);
 inherited;
end;

1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034
procedure tdesignwindow.adjustchildcomponentpos(var apos: pointty);
begin
 subpoint1(apos,componentoffset);
 addpoint1(apos,tformdesignerfo(fowner).widgetrefpoint);
// addpoint1(apos,tformdesignerfo(fowner).insertoffset);
// addpoint1(apos,tformdesignerfo(fowner).gridrect.pos);
end;

procedure tdesignwindow.readjustchildcomponentpos(var apos: pointty);
begin
 addpoint1(apos,componentoffset);
 subpoint1(apos,tformdesignerfo(fowner).widgetrefpoint);
// subpoint1(apos,tformdesignerfo(fowner).insertoffset);
// subpoint1(apos,tformdesignerfo(fowner).gridrect.pos);
end;

mse1's avatar
mse1 committed
1035 1036 1037 1038 1039 1040
procedure tdesignwindow.doafterpaint(const canvas: tcanvas);

 procedure drawcomponent(const component: tcomponent);
 var
  rect1: rectty;
  int1: integer;
1041
  pt1: pointty;
mse1's avatar
mse1 committed
1042 1043 1044
 begin
  if ((form = nil) or not (component is twidget)) and 
           not (cssubcomponent in component.componentstyle) then begin
1045
   rect1:= getcomponentrect(component);
mse1's avatar
mse1 committed
1046 1047 1048 1049 1050 1051 1052
   rect1.cx:= rect1.cx - complabelrightmargin;
   drawtext(canvas,component.name,rect1,[tf_ycentered,tf_right],
                      stockobjects.fonts[stf_default]);
   rect1.cx:= rect1.cy;
   registeredcomponents.drawcomponenticon(component,canvas,rect1);
  end;
  if (form <> nil) and (component is twidget) and 
1053 1054 1055 1056 1057 1058 1059
                      not (cssubcomponent in component.componentstyle){ and 
                      (csinline in component.componentstate)} then begin
   pt1:= twidget(component).pos;
   if component.owner = tformdesignerfo(fowner).fmodule then begin
    adjustchildcomponentpos(pt1);
   end;
   canvas.move(pt1);
mse1's avatar
mse1 committed
1060 1061 1062
   for int1:= 0 to component.componentcount - 1 do begin
    drawcomponent(component.components[int1]);        //components of submodule
   end;
1063
   canvas.remove(pt1);
mse1's avatar
mse1 committed
1064 1065 1066 1067 1068
  end;
 end;
 
var
 int1: integer;
1069
 rect1: rectty;
mse1's avatar
mse1 committed
1070
begin
mse1's avatar
mse1 committed
1071
 if tformdesignerfo(fowner).fmodule <> nil then begin
mse1's avatar
mse1 committed
1072
  canvas.intersectcliprect(tformdesignerfo(fowner).gridrect);
1073 1074
//  canvas.move(fowner.container.clientpos);
//  canvas.move(tformdesignerfo(fowner).gridoffset);
mse1's avatar
mse1 committed
1075 1076 1077 1078
  with tformdesignerfo(fowner).fmodule do begin
   for int1:= 0 to componentcount - 1 do begin
    drawcomponent(components[int1]);
   end;
mse1's avatar
mse1 committed
1079
  end;
1080
//  canvas.remove(tformdesignerfo(fowner).gridoffset);
mse1's avatar
mse1 committed
1081 1082 1083 1084
  if form <> nil then begin
   drawgrid(canvas);
  end;
  fselections.paint(canvas);
1085
//  canvas.remove(fowner.container.clientpos);
mse1's avatar
mse1 committed
1086
  showxorpic(canvas);
mse1's avatar
mse1 committed
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
 end;
end;

function tdesignwindow.componentscrollsize: sizety;
var
 int1,int2: integer;
 component: tcomponent;
 rect1: rectty;
begin
 result:= nullsize;
 if tformdesignerfo(fowner).fmodule <> nil then begin
  with tformdesignerfo(fowner).fmodule do begin
   for int1:= 0 to componentcount - 1 do begin
1100
    component:= components[int1];
mse1's avatar
mse1 committed
1101
    if (form = nil) or not (component is twidget) then begin
1102
     rect1:= getcomponentrect(component);
1103
     subpoint1(rect1.pos,componentoffset);
mse1's avatar
mse1 committed
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114
     int2:= rect1.x + rect1.cx;
     if int2 > result.cx then begin
      result.cx:= int2;
     end;
     int2:= rect1.y + rect1.cy;
     if int2 > result.cy then begin
      result.cy:= int2;
     end;
    end;
   end;
  end;
1115
  subsize1(result,sizety(tformdesignerfo(fowner).gridrect.pos));
mse1's avatar
mse1 committed
1116 1117 1118 1119 1120 1121 1122 1123 1124 1125
 end;
 inc(result.cx,handlesize);
 inc(result.cy,handlesize);
end;

procedure tdesignwindow.doaddcomponent(component: tcomponent);
var
 comp1: tcomponent;
begin
 comp1:= component.owner;
1126 1127
 if (comp1 <> nil) and not 
            issubcomponent(tformdesignerfo(fowner).fmodule,comp1) then begin
1128 1129
  comp1.removecomponent(component);
 end;
mse1's avatar
mse1 committed
1130
 fdesigner.addcomponent(module,component);
1131 1132
// if csinline in component.ComponentState then begin
 if component.ComponentState * [csancestor,csinline] <> [] then begin
mse1's avatar
mse1 committed
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
  tcomponent1(component).getchildren({$ifdef FPC}@{$endif}doaddcomponent,component);
 end
 else begin
// if comp1 <> nil then begin //else submodule
  tcomponent1(component).getchildren({$ifdef FPC}@{$endif}doaddcomponent,comp1);
 end;
end;

procedure tdesignwindow.doinitcomponent(component: tcomponent; parent: tcomponent);
var
 rect1: rectty;
1144
 pt1: pointty;
mse1's avatar
mse1 committed
1145 1146 1147
begin
 doaddcomponent(component);
 if (component is twidget) and (parent is twidget) then begin
1148
  with twidget(component) do begin
1149 1150
   if fuseinitcompsoffset then begin
    pt1:= finitcompsoffset;
1151 1152 1153
    subpoint1(finitcompsoffset,pos);
    fcompsoffsetused:= true;
    fuseinitcompsoffset:= false;
1154 1155
   end
   else begin 
1156 1157 1158 1159 1160 1161
    if fcompsoffsetused then begin
     pt1:= addpoint(pos,finitcompsoffset);
    end
    else begin
     pt1:= addpoint(pos,twidget(parent).containeroffset);
    end;
1162
   end;
1163
  end;
1164
  twidget(parent).insertwidget(twidget(component),pt1);
mse1's avatar
mse1 committed
1165 1166
  if fclipinitcomps then begin
   rect1:= twidget(component).widgetrect;
1167 1168 1169 1170 1171
//   if fuseinitcompsoffset then begin
//    addpoint1(rect1.pos,finitcompsoffset);
//   end;
   shiftinrect(rect1,twidget(component).parentwidget.clientwidgetrect);
//   shiftinrect(rect1,makerect(nullpoint,twidget(component).parentwidget.size));
mse1's avatar
mse1 committed
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
   twidget(component).widgetrect:= rect1;
  end;
 end;
end;

procedure tdesignwindow.docopy(const noclear: boolean);
var
 int1: integer;
 widget1: twidget;
begin
 fselections.remove(module);
 fselections.copytoclipboard;
 if not noclear then begin
  if form = nil then begin
   selectcomponent(module);
  end
  else begin
   widget1:= nil;
   if (fselections.count > 0) and (fselections[0] is twidget) then begin
    widget1:= twidget(fselections[0]).parentofcontainer;
    for int1:= 1 to fselections.count - 1 do begin
     if not (fselections[int1] is twidget) or 
       (twidget(fselections[int1]).parentofcontainer <> widget1) then begin
      widget1:= nil; //no common parent
      break;
     end;
    end;
   end;
   if widget1 = nil then begin
    selectcomponent(module);
   end
   else begin
    selectcomponent(widget1);
   end;
  end;
 end;
end;

procedure tdesignwindow.docut;
begin
 docopy(true);
 dodelete;
end;

1216
procedure tdesignwindow.dopaste(const usemousepos: boolean);
mse1's avatar
mse1 committed
1217 1218 1219 1220 1221
var
 widget1: twidget;
begin
 try
  if form <> nil then begin
1222
   fclipinitcomps:= not usemousepos;
mse1's avatar
mse1 committed
1223 1224 1225 1226
   with fselections do begin
    if count = 1 then begin
     widget1:= twidget(items[0]);
     if (widget1 is twidget) and form.checkdescendent(widget1) then begin
1227
      fuseinitcompsoffset:= usemousepos;
1228
      fcompsoffsetused:= false;
1229
      if usemousepos then begin
1230
       finitcompsoffset:= subpoint(dosnaptogrid(fmousepos),widget1.rootpos);
1231
      end;
mse1's avatar
mse1 committed
1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295
      clear;
      pastefromclipboard(module,widget1,{$ifdef FPC}@{$endif}doinitcomponent);
      updateselections;
     end;
    end;
   end;
  end
  else begin
   fselections.clear;
   fselections.pastefromclipboard(module,module,{$ifdef FPC}@{$endif}doinitcomponent);
   updateselections;
   //todo
  end;
 finally
  fclipinitcomps:= false;
 end;
 recalcclientsize;
end;

procedure tdesignwindow.doundelete;
var
 int1: integer;
begin
 if fdelobjs <> nil then begin
  with fselections do begin
   clear;
   for int1:= 0 to high(fdelobjs) do begin
    with fdelobjs[int1] do begin
     pastefromobjecttext(objtext,owner,parent,
                    {$ifdef FPC}@{$endif}doinitcomponent);
    end;
   end;
   for int1:= count-1 downto 0 do begin
    if isembedded(items[int1]) then begin
     delete(int1);
    end;
   end;
  end;
  updateselections;
  fdelobjs:= nil;
 end;
end;

procedure tdesignwindow.dodelete;
begin
 with fselections do begin
  removeforeign;
  fdelobjs:= fselections.getobjinfoar;
  deletecomponents;
 end;
 domodified;
 recalcclientsize;
end;

procedure tdesignwindow.dispatchkeyevent(const eventkind: eventkindty;
  var info: keyeventinfoty);


var
 po1: pointty;
 widget1: twidget;
// component1: tcomponent;

begin
mse1's avatar
mse1 committed
1296 1297 1298 1299
 if module = nil then begin
  inherited;
  exit;
 end;
mse1's avatar
mse1 committed
1300 1301
 if eventkind = ek_keypress then begin
  with info do begin
1302
   if shiftstate * keyshiftstatesmask = [] then begin
mse1's avatar
mse1 committed
1303 1304 1305
    include(eventstate,es_processed);
    case key of
     key_escape: begin
1306 1307 1308 1309
      if factarea <> ar_none then begin
       hidexorpic(fowner.container.getcanvas(org_widget));
       fxorpicactive:= false;
       factarea:= ar_none;
mse1's avatar
mse1 committed
1310
      end
1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327
      else begin      
       if (fselections.count > 1) or (form = nil) then begin
        selectcomponent(module);
       end
       else begin
        if fselections.count = 1 then begin
         widget1:= twidget(fselections[0]);
         if widget1 is twidget then begin
          repeat
           widget1:= widget1.parentwidget;
          until (widget1 = nil) or (ws_iswidget in widget1.widgetstate);
          if (widget1 <> nil) and (widget1 <> fowner) then begin
           selectcomponent(widget1);
          end
          else begin
           selectcomponent(module);
          end;
mse1's avatar
mse1 committed
1328 1329 1330 1331 1332 1333 1334 1335 1336
         end
         else begin
          selectcomponent(module);
         end;
        end;
       end;
      end;
     end;
     key_delete: begin
mse1's avatar
mse1 committed
1337 1338 1339
      if fselections.candelete then begin
       dodelete;
      end;
mse1's avatar
mse1 committed
1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359
     end;
     else begin
      exclude(eventstate,es_processed);
     end;
    end;
   end
   else begin
    if (shiftstate = [ss_ctrl]) or (shiftstate = [ss_shift]) then begin
     include(eventstate,es_processed);
     po1:= nullpoint;
     case key of
      key_right: po1.x:= 1;
      key_up: po1.y:= -1;
      key_left: po1.x:= -1;
      key_down: po1.y:= 1;
      else exclude(eventstate,es_processed);
     end;
     if (es_processed in eventstate) then begin
      if shiftstate = [ss_ctrl] then begin
       fselections.move(po1);
mse1's avatar
mse1 committed
1360 1361 1362 1363 1364
       if fselections.count > 0 then begin
        fselections.updateinfos;
        tformdesignerfo(fowner).componentmoving(
             rectcenter(fselections.itempo(0)^.handles[ht_topleft]));
       end;
mse1's avatar
mse1 committed
1365 1366 1367
      end
      else begin
       fselections.resize(po1);
mse1's avatar
mse1 committed
1368 1369 1370 1371 1372 1373 1374
       if fselections.count > 0 then begin
        fselections.updateinfos;
        with fselections.itempo(0)^.handles[ht_bottomright] do begin
         tformdesignerfo(fowner).componentmoving(
                             makepoint(x+cx div 2 + 1,y+cy div 2 +1));
        end;
       end;
mse1's avatar
mse1 committed
1375 1376 1377 1378 1379 1380 1381
      end;
      fowner.invalidate;
      recalcclientsize;
     end;
    end;
   end;
   if not (es_processed in eventstate) then begin
mse1's avatar
mse1 committed
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398
    if issysshortcut(sho_copy,info) then begin
     docopy(false);
     include(eventstate,es_processed);
    end
    else begin
     if issysshortcut(sho_cut,info) then begin
      docut;
      include(eventstate,es_processed);
     end
     else begin
      if issysshortcut(sho_paste,info) then begin
       dopaste(false);
       include(eventstate,es_processed);
      end;
     end;
    end;
    (*
mse1's avatar
mse1 committed
1399 1400 1401
    if shiftstate = [ss_ctrl] then begin
     include(eventstate,es_processed);
     case key of
1402
      key_c{,key_insert}: begin
mse1's avatar
mse1 committed
1403 1404 1405
       docopy(false);
      end;
      key_x: begin
mse1's avatar
mse1 committed
1406 1407 1408
       if fselections.candelete then begin
        docut;
       end;
mse1's avatar
mse1 committed
1409 1410
      end;
      key_v: begin
1411
       dopaste(false);
mse1's avatar
mse1 committed
1412 1413 1414 1415 1416 1417
      end;
      else begin
       exclude(eventstate,es_processed);
      end;
     end;
    end;
mse1's avatar
mse1 committed
1418
    *)
mse1's avatar
mse1 committed
1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429
   end;
  end;
 end;
 if not (es_processed in info.eventstate) then begin
  inherited;
 end;
end;

procedure tdesignwindow.dopopup(var info: mouseeventinfoty);

var
mse1's avatar
mse1 committed
1430
 bo1,bo2: boolean;
mse1's avatar
mse1 committed
1431
begin
mse1's avatar
mse1 committed
1432
 with tformdesignerfo(fowner),popupme,menu do begin
mse1's avatar
mse1 committed
1433
  bo1:= (fselections.count > 0) and (fselections[0] <> module);
mse1's avatar
mse1 committed
1434
  bo2:= bo1 and fselections.candelete;
mse1's avatar
mse1 committed
1435
  itembyname('copy').enabled:= bo1;
mse1's avatar
mse1 committed
1436 1437
  itembyname('cut').enabled:= bo2;
  itembyname('delete').enabled:= bo2;
mse1's avatar
mse1 committed
1438 1439 1440 1441 1442 1443 1444 1445
  itembyname('undelete').enabled:= fdelobjs <> nil;
  itembyname('paste').enabled:= true;
  itembyname('editcomp').enabled:= designer.componentcanedit;
  bo1:= not((fselections.count <> 1) or not(fselections.items[0] is twidget) or
           not fowner.checkdescendent(twidget(fselections.items[0])));
  itembyname('insertsub').enabled:= bo1;
  itembyname('revert').enabled:= (fselections.count = 1) and 
          (fselections[0].componentstate * [csinline,csancestor] <> []);
1446 1447
  itembyname('insertcomp').enabled:= designer.hascurrentcomponent and
           (fselections.count = 1);
mse1's avatar
mse1 committed
1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460
  itembyname('bringtofro').enabled:= bo1;
  itembyname('sendtoba').enabled:= bo1;
  itembyname('settabord').enabled:= bo1 and 
          (twidget(fselections.items[0]).parentwidget.childrencount >= 2);
  itembyname('synctofo').enabled:= fselections.count > 0;
  show(fowner,info);
 end;
end;

function tdesignwindow.widgetatpos(const apos: pointty; onlywidgets: boolean): twidget;
var
 widgetinfo: widgetatposinfoty;
begin
mse1's avatar
mse1 committed
1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472
 result:= nil;
 if pointinrect(apos,tformdesignerfo(fowner).gridrect) then begin
  fillchar(widgetinfo,sizeof(widgetinfo),0);
  with widgetinfo do begin
   pos:= subpoint(apos,form.rootpos);
   if onlywidgets then begin
    childstate:= [ws_iswidget,ws_isvisible];
   end
   else begin
    childstate:= [ws_isvisible];
   end;
   parentstate:= [ws_isvisible];
mse1's avatar
mse1 committed
1473
  end;
mse1's avatar
mse1 committed
1474
  result:= form.widgetatpos(widgetinfo);
mse1's avatar
mse1 committed
1475 1476 1477 1478 1479
 end;
end;

procedure tdesignwindow.recalcclientsize;
begin
1480
 tformdesignerfo(fowner).recalcclientsize;
mse1's avatar
mse1 committed
1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552
end;

procedure tdesignwindow.dispatchmouseevent(var info: mouseeventinfoty;
                         capture: twidget);

 function griddelta: pointty;
 begin
  result:= snaptogriddelta(subpoint(info.pos,fpickpos));
 end;

 procedure updatesizerect;
 var
  pos1,posbefore: pointty;
 begin
  pos1:= griddelta;
  posbefore:= pos1;
  with fsizerect,pos1 do begin
   case factarea of
    ht_topleft,ht_left,ht_bottomleft: begin
     if x > size.cx then begin
      x:= size.cx
     end;
     factsizerect.pos.x:= pos.x + x;
     factsizerect.size.cx:= size.cx - x;
    end;
    ht_topright,ht_right,ht_bottomright: begin
     if x < -size.cx then begin
      x:= -size.cx;
     end;
     factsizerect.size.cx:= size.cx + x;
    end;
   end;
   case factarea of
    ht_topleft,ht_top,ht_topright: begin
     if y > size.cy then begin
      y:= size.cy
     end;
     factsizerect.pos.y:= pos.y + y;
     factsizerect.size.cy:= size.cy - y;
    end;
    ht_bottomleft,ht_bottom,ht_bottomright: begin
     if y < -size.cy then begin
      y:= -size.cy;
     end;
     factsizerect.size.cy:= size.cy + y;
    end;
   end;
  end;
  case factarea of
   ht_top,ht_bottom: begin
    info.pos.x:= fpickpos.x;
   end;
   ht_left,ht_right: begin
    info.pos.y:= fpickpos.y;
   end;
  end;
  application.mouse.move(subpoint(pos1,posbefore));
 end;

 procedure updatecursorshape(area: areaty);
 var
  shape: cursorshapety;
 begin
  case area of
   ht_topleft: shape:= cr_topleftcorner;
   ht_bottomright: shape:= cr_bottomrightcorner;
   ht_topright: shape:= cr_toprightcorner;
   ht_bottomleft: shape:= cr_bottomleftcorner;
   ht_top,ht_bottom: shape:= cr_sizever;
   ht_left,ht_right: shape:= cr_sizehor;
   else shape:= cr_arrow;
  end;
1553
  application.widgetcursorshape:= shape;
mse1's avatar
mse1 committed
1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565
 end;


var
 component: tcomponent;
 int1: integer;
 bo1: boolean;
 posbefore: pointty;
 widget1: twidget;
 rect1: rectty;
 selectmode: selectmodety;
 area1: areaty;
1566
// clipo: pointty;
mse1's avatar
mse1 committed
1567 1568
 isinpaintrect: boolean;
 ss1: shiftstatesty;
mse1's avatar
mse1 committed
1569 1570
 po1: pformselectedinfoty;
 pt1: pointty; 
mse1's avatar
mse1 committed
1571 1572 1573
label
 1;
begin
mse1's avatar
mse1 committed
1574 1575 1576 1577
 if module = nil then begin
  inherited;
  exit;
 end;
mse1's avatar
mse1 committed
1578 1579 1580 1581 1582 1583 1584
 if info.eventkind in [ek_mouseleave,ek_mouseenter] then begin
  fclickedcompbefore:= nil;
  exit;
 end;
 checkmousewidget(info,capture);
 with info do begin
  ss1:= shiftstate * shiftstatesmask;
1585
  isinpaintrect:= pointinrect(pos,tformdesignerfo(fowner).gridrect);
1586 1587
//  clipo:= fowner.container.clientpos;
//  subpoint1(pos,clipo);
mse1's avatar
mse1 committed
1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605
  posbefore:= pos;
  if eventkind in [ek_buttonpress,ek_buttonrelease] then begin
   fmousepos:= pos;
  end;
  component:= nil;
  if not (es_processed in eventstate) then begin
   bo1:= false;
   if (eventkind = ek_buttonpress) and (button = mb_left) then begin
    fpickpos:= pos;
    if (ss1 = [ss_left]) or (ss1 = [ss_left,ss_ctrl]) or 
                (ss1 = [ss_left,ss_double]) then begin
     factarea:= fselections.getareainfo(pos,factcompindex);
     if factcompindex >= 0 then begin
      fsizerect:= fselections.itempo(factcompindex)^.rect;
      factsizerect:= fsizerect;
     end;
     if (factarea in [ar_component,ar_none]) then begin
      if isinpaintrect then begin
1606
       component:= componentatpos(pos);
mse1's avatar
mse1 committed
1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627
       if (component = nil) then begin
        if form <> nil then begin
         component:= widgetatpos(pos,true);
        end
        else begin
         component:= module;
        end;
       end;
      end;
      if component <> nil then begin
       if (factcompindex < 0) or (component <> fselections[factcompindex]) then begin
        factarea:= ar_none;
       end;
       bo1:= true;
       if ss_ctrl in ss1 then begin
        selectcomponent(component,sm_flip);
       end
       else begin
        if (component = form) and (fselections.count > 1) or 
               (fselections.indexof(component) < 0) then begin
         selectcomponent(component,sm_select);
1628 1629 1630
         if projectoptions.moveonfirstclick then begin
          factarea:= ar_component;
         end;
mse1's avatar
mse1 committed
1631
        end;
1632 1633 1634
        if ss_double in shiftstate then begin
         designer.showobjectinspector;
        end;
mse1's avatar
mse1 committed
1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656
       end;
      end
      else begin
       factarea:= ar_none;
      end;
      fclickedcompbefore:= component;
     end
     else begin
      fowner.capturemouse;
      include(eventstate,es_processed);
     end;
    end
   end;
   if (eventkind = ek_buttonrelease) and (button = mb_right) and
           not (es_processed in eventstate) then begin
    dopopup(info);
   end;
   if not (es_processed in eventstate) then begin
    area1:= fselections.getareainfo(pos,int1);
    if ((area1 < firsthandle) or (area1 > lasthandle)) and
       ((factarea < firsthandle) or (factarea > lasthandle)) and 
       not (fdesigner.hascurrentcomponent and (eventkind = ek_buttonpress) and 
1657 1658 1659 1660
       (button = mb_left) and (ss1 = [ss_left])) and 
       not ((area1 = ar_component) and 
           not(fselections[int1] is twidget)) and 
       (factarea <> ar_componentmove) then begin
1661
//     addpoint1(pos,clipo);
mse1's avatar
mse1 committed
1662
     inherited;
1663
//     subpoint1(pos,clipo);
mse1's avatar
mse1 committed
1664 1665 1666 1667
    end;
    pos:= posbefore;
    if bo1 then begin
     if not (es_processed in eventstate) then begin
mse1's avatar
mse1 committed
1668 1669 1670 1671
      if (capture = nil) or not 
             (ws1_designactive in twidget1(capture).fwidgetstate1) then begin
       fowner.capturemouse; //capture mouse
      end;
mse1's avatar
mse1 committed
1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685
      updatecursorshape(factarea);
     end
     else begin
      factarea:= ar_none;
     end;
    end;
   end;
   if not (es_processed in eventstate) then begin
    if (eventkind = ek_buttonpress) and (button = mb_left) then begin
     if ss1 = [ss_left] then begin
      if isinpaintrect then begin
       component:= fdesigner.createcurrentcomponent(module);
      end;
      if component <> nil then begin
mse1's avatar
mse1 committed
1686
       tformdesignerfo(fowner).placecomponent(component,pos);
mse1's avatar
mse1 committed
1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718
      end;
     end
     else begin
      if (ss1 = [ss_left,ss_shift]) and isinpaintrect then begin
       factarea:= ar_selectrect;
       fxorpicoffset:= pos;
       if form <> nil then begin
        fpickwidget:= widgetatpos(pos,false);
       end
       else begin
        fpickwidget:= fowner;
       end;
      end;
     end;
    end;
    if (eventkind = ek_buttonrelease) and (button = mb_left) then begin
     hidexorpic(fowner.container.getcanvas(org_widget));
     fxorpicactive:= false;
     case factarea of
      firsthandle..lasthandle: begin
       if (factcompindex >= 0) and (factcompindex < fselections.count) then begin
        component:= tcomponent(fselections.itempo(factcompindex)^.selectedinfo.instance);
        if (component is twidget) and (form <> nil) then begin
         with twidget(component) do begin
          subpoint1(factsizerect.pos,parentwidget.rootpos);
          widgetrect:= factsizerect;
         end;
         fselections.componentschanged;
        end;
       end;
       fowner.invalidate;
      end;
mse1's avatar
mse1 committed
1719
      ar_componentmove: begin
mse1's avatar
mse1 committed
1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744
       if fselections.move(griddelta) then begin
        fowner.invalidate; //redraw handles
        recalcclientsize;
       end;
      end;
      ar_selectrect: begin
       if fpickwidget <> nil then begin
        rect1.pos:= fpickpos;
        rect1.cx:= pos.x - fpickpos.x;
        rect1.cy:= pos.y - fpickpos.y;
        if (rect1.cx < 0) or (rect1.cy < 0) then begin
         selectmode:= sm_remove;
        end
        else begin
         selectmode:= sm_add;
        end;
        beginselect;
        try
         if (selectmode = sm_add) and (fselections.count = 1) and
               (fselections[0] = module) then begin
          fselections.clear; //remove underlaying form
         end;
         for int1:= 0 to module.componentcount - 1 do begin
          component:= module.Components[int1];
          if (form = nil) or (not (component is twidget)) then begin
1745
           if rectinrect(getcomponentrect1(component),rect1) then begin
mse1's avatar
mse1 committed
1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779
            selectcomponent(component,selectmode);
           end;
          end;
         end;
         if fpickwidget <> fowner then begin
          rect1.pos:= subpoint(fpickpos,fpickwidget.rootpos);
          for int1:= 0 to fpickwidget.widgetcount -1 do begin
           widget1:= fpickwidget[int1];
           if rectinrect(widget1.widgetrect,rect1) then begin
            selectcomponent(widget1,selectmode);
           end;
          end;
         end;
        finally
         endselect;
        end;
       end;
      end;
     end;
     fpickwidget:= nil;
     factarea:= ar_none;
     factcompindex:= -1;
     fowner.releasemouse;
    end;
 
    if not (es_processed in eventstate) then begin
     if (eventkind = ek_mousemove) then begin
      hidexorpic(fowner.getcanvas(org_widget));
      bo1:= true;
      case factarea of
       firsthandle..lasthandle: begin
        updatesizerect;
       end;
       ar_component: begin
mse1's avatar
mse1 committed
1780 1781 1782 1783 1784 1785 1786 1787 1788
        if distance(fpickpos,pos) > movethreshold then begin
         fxorpicoffset:= griddelta;
         factarea:= ar_componentmove;
        end
        else begin
         bo1:= false;
        end;
       end;
       ar_componentmove: begin
mse1's avatar
mse1 committed
1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800
        fxorpicoffset:= griddelta;
       end;
       ar_selectrect: begin
        fxorpicoffset:= pos;
       end;
       else begin
        bo1:= false;
        updatecursorshape(fselections.getareainfo(pos,int1));
       end;
      end;
      if bo1 then begin
       fxorpicactive:= true;
mse1's avatar
mse1 committed
1801 1802 1803
       if factarea <> ar_component then begin
        fselections.beforepaintmoving; //resets canvas
       end;
mse1's avatar
mse1 committed
1804 1805 1806 1807 1808 1809 1810
       showxorpic(fowner.container.getcanvas(org_widget));
      end;
     end;
    end;
   end;
  end;
1:
mse1's avatar
mse1 committed
1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881
  if (eventkind in mouseposevents) and (fselections.count = 1) then begin
   fselections.updateinfos;
   po1:= fselections.itempo(0);
   if po1^.selectedinfo.instance <> tformdesignerfo(fowner).fmodule then begin
    bo1:= true;
    case factarea of
     ar_component: begin
      if (eventkind = ek_buttonpress) and (button = mb_left) then begin
       pt1:= rectcenter(po1^.handles[ht_topleft]);
      end
      else begin
       bo1:= false;
      end;
     end;
     ht_topleft: begin
      pt1:= factsizerect.pos;
     end;
     ht_left: begin
      with factsizerect do begin
       pt1.x:= x;
       pt1.y:= y + cy div 2;
      end;
     end;
     ht_bottomleft: begin
      with factsizerect do begin
       pt1.x:= x;
       pt1.y:= y + cy;
      end;
     end;
     ht_bottom: begin
      with factsizerect do begin
       pt1.x:= x + cx div 2;
       pt1.y:= y + cy ;
      end;
     end;
     ht_bottomright: begin
      with factsizerect do begin
       pt1.x:= x + cx;
       pt1.y:= y + cy;
      end;
     end;
     ht_right: begin
      with factsizerect do begin
       pt1.x:= x + cx;
       pt1.y:= y + cy div 2;
      end;
     end;
     ht_topright: begin
      with factsizerect do begin
       pt1.x:= x + cx;
       pt1.y:= y;
      end;
     end;
     ht_top: begin
      with factsizerect do begin
       pt1.x:= x + cx div 2;
       pt1.y:= y;
      end;
     end;
     ar_componentmove: begin
      pt1:= addpoint(rectcenter(po1^.handles[ht_topleft]),fxorpicoffset);
     end;
     else begin
      bo1:= false;
     end;
    end;
    if bo1 then begin
     tformdesignerfo(fowner).componentmoving(pt1);
    end;
   end;
  end;
1882
//  addpoint1(pos,clipo);
mse1's avatar
mse1 committed
1883 1884 1885 1886 1887 1888 1889
 end;
end;

procedure tdesignwindow.selectionchanged(const adesigner: idesigner;
      const aselection: idesignerselections);
begin
 if fselections.assign(aselection) then begin
mse1's avatar
mse1 committed
1890
  tformdesignerfo(fowner).componentselected(fselections);
mse1's avatar
mse1 committed
1891 1892 1893 1894