mseedit.pas 64.7 KB
Newer Older
1
{ MSEgui Copyright (c) 1999-2017 by Martin Schreiber
mse1's avatar
mse1 committed
2 3 4 5 6 7 8 9 10 11

    See the file COPYING.MSE, included in this distribution,
    for details about the copyright.

    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.
}
unit mseedit;

12 13 14
{$ifdef FPC}
 {$mode objfpc}{$h+}{$interfaces corba}
{$endif}
mse1's avatar
mse1 committed
15 16 17
{$ifndef mse_no_ifi}
 {$define mse_with_ifi}
{$endif}
mse1's avatar
mse1 committed
18 19 20 21

interface
uses
 msegui,mseeditglob,msegraphics,msegraphutils,msedatalist,
Martin Schreiber's avatar
Martin Schreiber committed
22
 mseevent,mseglob,mseguiglob,msestat,msestatfile,mserichstring,
mse1's avatar
mse1 committed
23
 mseinplaceedit,msegrids,msetypes,mseshapes,msewidgets,
Martin Schreiber's avatar
Martin Schreiber committed
24
 msedrawtext,classes,mclasses,msereal,mseclasses,msearrayprops,
25
 msebitmap,msemenus,msetimer,mseactions,msekeyboard,
26
 msesimplewidgets,msepointer,msestrings,msescrollbar,mseassistiveclient
mse1's avatar
mse1 committed
27
         {$ifdef mse_with_ifi},mseifiglob{$endif};
mse1's avatar
mse1 committed
28 29

const
30 31 32 33
 defaulteditwidgetoptions = defaultoptionswidget
                                {+[ow_fontglyphheight,ow_autoscale]};
 defaulteditwidgetoptions1 = defaultoptionswidget1+
                                  [ow1_fontglyphheight,ow1_autoscale];
mse1's avatar
mse1 committed
34 35 36 37
 defaulteditwidgetwidth = 100;
 defaulteditwidgetheight = 20;
 defaulttextflags = [tf_ycentered,tf_noselect];
 defaulttextflagsactive = [tf_ycentered];
38 39
 defaulttextflagsnoycentered = defaulttextflags - [tf_ycentered];
 defaulttextflagsactivenoycentered = defaulttextflagsactive - [tf_ycentered];
40
 defaulttextflagsempty = [tf_ycentered,tf_xcentered];
mse1's avatar
mse1 committed
41 42 43 44

type

 teditframe = class(tcustomcaptionframe)
45 46
  protected
   function actualcolorclient(): colorty override;
mse1's avatar
mse1 committed
47
  public
48
   constructor create(const aintf: icaptionframe);
mse1's avatar
mse1 committed
49
  published
mse1's avatar
mse1 committed
50
   property options;
mse1's avatar
mse1 committed
51 52 53 54
   property levelo default -2;
   property leveli;
   property framewidth;
   property colorframe;
mse1's avatar
mse1 committed
55
   property colorframeactive;
56 57 58
   property colorframedisabled;
   property colorframemouse;
   property colorframeclicked;
59
   property colorframedefault;
60 61 62 63 64 65
   property colordkshadow;
   property colorshadow;
   property colorlight;
   property colorhighlight;
   property colordkwidth;
   property colorhlwidth;
66
   property hiddenedges;
mse1's avatar
mse1 committed
67 68 69 70
   property framei_left default 1;
   property framei_top default 1;
   property framei_right default 1;
   property framei_bottom default 1;
Martin Schreiber's avatar
Martin Schreiber committed
71 72 73 74 75
   property frameo_left;
   property frameo_top;
   property frameo_right;
   property frameo_bottom;

76

mse1's avatar
mse1 committed
77
   property frameimage_list;
78 79 80 81
   property frameimage_left;
   property frameimage_top;
   property frameimage_right;
   property frameimage_bottom;
mse1's avatar
mse1 committed
82
   property frameimage_offset;
83
   property frameimage_offset1;
mse1's avatar
mse1 committed
84
   property frameimage_offsetdisabled;
mse1's avatar
mse1 committed
85 86 87
   property frameimage_offsetmouse;
   property frameimage_offsetclicked;
   property frameimage_offsetactive;
88 89
   property frameimage_offsetfocused;
{
90 91
   property frameimage_offsetactivemouse;
   property frameimage_offsetactiveclicked;
92
}
93 94
   property frameface_list;
   property frameface_offset;
95
   property frameface_offset1;
96 97 98 99
   property frameface_offsetdisabled;
   property frameface_offsetmouse;
   property frameface_offsetclicked;
   property frameface_offsetactive;
100 101
   property frameface_offsetfocused;
{
102 103
   property frameface_offsetactivemouse;
   property frameface_offsetactiveclicked;
104
}
105
   property colorclient {default cl_foreground};
mse1's avatar
mse1 committed
106
   property caption;
107
   property captiontextflags;
mse1's avatar
mse1 committed
108 109 110
   property captionpos;
   property captiondist;
   property captionoffset;
111
   property focusrectdist;
Martin Schreiber's avatar
Martin Schreiber committed
112 113 114 115
   property extraspace;
   property imagedist;
   property imagedist1;
   property imagedist2;
mse1's avatar
mse1 committed
116 117
   property font;
   property localprops; //before template
mse1's avatar
mse1 committed
118
   property localprops1; //before template
mse1's avatar
mse1 committed
119 120 121 122
   property template;
 end;
 
 tscrolleditframe = class(tcustomthumbtrackscrollframe)
123 124
  protected
   function actualcolorclient(): colorty override;
mse1's avatar
mse1 committed
125
  public
126
   constructor create(const aintf: iscrollframe; const scrollintf: iscrollbar);
mse1's avatar
mse1 committed
127
  published
128 129 130
   property options;
   property optionsscroll;
   property dragbuttons;
mse1's avatar
mse1 committed
131 132 133 134
   property levelo default -2;
   property leveli;
   property framewidth;
   property colorframe;
mse1's avatar
mse1 committed
135
   property colorframeactive;
136 137 138
   property colorframedisabled;
   property colorframemouse;
   property colorframeclicked;
139
   property colorframedefault;
140 141 142 143 144 145
   property colordkshadow;
   property colorshadow;
   property colorlight;
   property colorhighlight;
   property colordkwidth;
   property colorhlwidth;
146
   property hiddenedges;
147
   property colorclient {default cl_foreground};
mse1's avatar
mse1 committed
148 149 150 151
   property framei_left default 1;
   property framei_top default 1;
   property framei_right default 1;
   property framei_bottom default 1;
Martin Schreiber's avatar
Martin Schreiber committed
152 153 154 155
   property frameo_left;
   property frameo_top;
   property frameo_right;
   property frameo_bottom;
156 157 158 159 160 161 162 163 164 165 166 167

   property frameimage_list;
   property frameimage_left;
   property frameimage_top;
   property frameimage_right;
   property frameimage_bottom;
   property frameimage_offset;
   property frameimage_offset1;
   property frameimage_offsetdisabled;
   property frameimage_offsetmouse;
   property frameimage_offsetclicked;
   property frameimage_offsetactive;
168 169
   property frameimage_offsetfocused;
{
170 171
   property frameimage_offsetactivemouse;
   property frameimage_offsetactiveclicked;
172
}
173 174 175 176 177 178 179
   property frameface_list;
   property frameface_offset;
   property frameface_offset1;
   property frameface_offsetdisabled;
   property frameface_offsetmouse;
   property frameface_offsetclicked;
   property frameface_offsetactive;
180 181
   property frameface_offsetfocused;
{
182 183
   property frameface_offsetactivemouse;
   property frameface_offsetactiveclicked;
184
}   
185 186
   property optionsskin;

mse1's avatar
mse1 committed
187
   property caption;
188
   property captiontextflags;
mse1's avatar
mse1 committed
189 190 191
   property captionpos;
   property captiondist;
   property captionoffset;
192
   property focusrectdist;
Martin Schreiber's avatar
Martin Schreiber committed
193 194 195 196
   property extraspace;
   property imagedist;
   property imagedist1;
   property imagedist2;
mse1's avatar
mse1 committed
197 198
   property font;
   property localprops; //before template
mse1's avatar
mse1 committed
199
   property localprops1; //before template
mse1's avatar
mse1 committed
200
   property template;
201 202
   property sbhorz; 
   property sbvert;
mse1's avatar
mse1 committed
203 204 205
 end;

 tscrollboxeditframe = class(tcustomscrollboxframe)
206 207
  protected
   function actualcolorclient(): colorty override;
mse1's avatar
mse1 committed
208
  public
209
   constructor create(const aintf: iscrollframe; const owner: twidget);
mse1's avatar
mse1 committed
210 211 212 213 214
  published
   property levelo default -2;
   property leveli;
   property framewidth;
   property colorframe;
mse1's avatar
mse1 committed
215
   property colorframeactive;
216 217 218
   property colorframedisabled;
   property colorframemouse;
   property colorframeclicked;
219
   property colorframedefault;
220 221 222 223 224 225
   property colordkshadow;
   property colorshadow;
   property colorlight;
   property colorhighlight;
   property colordkwidth;
   property colorhlwidth;
226
   property hiddenedges;
mse1's avatar
mse1 committed
227 228 229 230 231 232
   property framei_left default 1;
   property framei_top default 1;
   property framei_right default 1;
   property framei_bottom default 1;
   property sbhorz; 
   property sbvert;
233
   property colorclient {default cl_foreground};
mse1's avatar
mse1 committed
234
   property caption;
235
   property captiontextflags;
mse1's avatar
mse1 committed
236 237 238 239 240
   property captionpos;
   property captiondist;
   property captionoffset;
   property font;
   property localprops; //before template
mse1's avatar
mse1 committed
241
   property localprops1; //before template
mse1's avatar
mse1 committed
242 243 244 245 246 247 248 249 250
   property template;
 end;

 buttonactionty = (ba_none,ba_buttonpress,ba_buttonrelease,ba_click);
 ibutton = interface(inullinterface)
  procedure buttonaction(var action: buttonactionty; const buttonindex: integer);
 end;
 buttoneventty = procedure(const sender: tobject; var action: buttonactionty;
                       const buttonindex: integer) of object;
251
 framebuttonoptionty = 
252 253
       (fbo_left,fbo_invisible,fbo_inactiveinvisible,
        fbo_disabled,fbo_enabled, //overrides frame readonly state
254
        fbo_executeonclientdblclick,
255
        fbo_flat,fbo_noanim,fbo_nomouseanim,fbo_noclickanim,fbo_nofocusanim);
mse1's avatar
mse1 committed
256 257
 framebuttonoptionsty = set of framebuttonoptionty;

258
 tcustombuttonsframe = class;
mse1's avatar
mse1 committed
259
 
mse1's avatar
mse1 committed
260
 tframebutton = class(townedeventpersistent,iframe,iimagelistinfo)
mse1's avatar
mse1 committed
261 262 263 264
  private
   fbuttonwidth: integer;
   foptions: framebuttonoptionsty;
   fonexecute: notifyeventty;
265
   faction: taction;
266
   fshortcut: shortcutty;
mse1's avatar
mse1 committed
267 268
   procedure setbuttonwidth(const Value: integer);
   procedure setoptions(const Value: framebuttonoptionsty);
269
   procedure optionstostate();
mse1's avatar
mse1 committed
270 271 272 273 274 275 276 277 278 279
   procedure changed;
   function getleft: boolean;
   procedure setleft(const Value: boolean);
   function getvisible: boolean;
   procedure setvisible(const Value: boolean);
   function getenabled: boolean;
   procedure setenabled(const Value: boolean);
   procedure setcolor(const avalue: colorty);
   procedure setcolorglyph(const avalue: colorty);
   procedure setimagelist(const Value: timagelist);
280 281
   procedure setimagenr(const avalue: imagenrty);
   procedure setimagenrdisabled(const avalue: imagenrty);
mse1's avatar
mse1 committed
282 283
   function getface: tface;
   procedure setface(const avalue: tface);
mse1's avatar
mse1 committed
284 285
   function getframe: tframe;
   procedure setframe(const avalue: tframe);
286
    //iframe
mse1's avatar
mse1 committed
287 288
   procedure setframeinstance(instance: tcustomframe);
   procedure setstaticframe(value: boolean);
289
   function getstaticframe: boolean;
mse1's avatar
mse1 committed
290 291
   function getwidgetrect: rectty;
   function getcomponentstate: tcomponentstate;
292
   function getmsecomponentstate: msecomponentstatesty;
mse1's avatar
mse1 committed
293 294 295 296
   procedure scrollwidgets(const dist: pointty);
   procedure clientrectchanged;
   procedure invalidate;
   procedure invalidatewidget;
297 298
   procedure invalidaterect(const rect: rectty; const org: originty = org_client;
                               const noclip: boolean = false);
mse1's avatar
mse1 committed
299
   function getwidget: twidget;
mse1's avatar
mse1 committed
300
   function getframestateflags: framestateflagsty; virtual;
mse1's avatar
mse1 committed
301
   function getimagelist: timagelist;
302
   procedure setaction(const avalue: taction);
mse1's avatar
mse1 committed
303
  protected
mse1's avatar
mse1 committed
304
   fframerect: rectty;
mse1's avatar
mse1 committed
305
   finfo: shapeinfoty;
mse1's avatar
mse1 committed
306
   fframe: tframe;
307
   freadonly: boolean; //for checkreadonlystate of tbuttonframe
308
   procedure doexec();
mse1's avatar
mse1 committed
309 310 311 312 313 314
   procedure mouseevent(var info: mouseeventinfoty;
                 const intf: iframe; const buttonintf: ibutton;
                 const index: integer);
  public
   constructor create(aowner: tobject); override;
   destructor destroy; override;
315 316
   procedure createface;
   procedure createframe;
317
   procedure checktemplate(const sender: tobject);
318
   procedure updatewidgetstate(const awidget: twidget);
mse1's avatar
mse1 committed
319 320 321 322
   procedure assign(source: tpersistent); override;
   property visible: boolean read getvisible write setvisible default true;
   property enabled: boolean read getenabled write setenabled default true;
   property left: boolean read getleft write setleft default false;
mse1's avatar
mse1 committed
323 324
  published
   property width: integer read fbuttonwidth write setbuttonwidth default 0;
325 326 327 328
   property color: colorty read finfo.color write setcolor default cl_default;
   property colorglyph: colorty read finfo.ca.colorglyph 
                             write setcolorglyph default cl_default;
                                 //cl_default maps to cl_glyph
mse1's avatar
mse1 committed
329
   property face: tface read getface write setface;
mse1's avatar
mse1 committed
330
   property frame: tframe read getframe write setframe;
331
   property imagelist: timagelist read finfo.ca.imagelist write setimagelist;
332 333 334 335
   property imagenr: imagenrty read finfo.ca.imagenr write setimagenr 
                                                                  default -1;
   property imagenrdisabled: imagenrty read finfo.imagenrdisabled 
                                 write setimagenrdisabled default -2; //grayed
mse1's avatar
mse1 committed
336 337
   property options: framebuttonoptionsty read foptions write setoptions
                                            default [];
338 339
   property shortcut: shortcutty read fshortcut write fshortcut
                                                    default ord(key_none) ;
340
   property action: taction read faction write setaction;
mse1's avatar
mse1 committed
341
   property onexecute: notifyeventty read fonexecute write fonexecute;
342
                                //executed after action execute
mse1's avatar
mse1 committed
343 344 345 346 347 348 349 350 351
 end;

 tstockglyphframebutton = class(tframebutton)
  private
   function isimageliststored: boolean;
   procedure setimagelist(const Value: timagelist);
  public
   constructor create(aowner: tobject); override;
  published
352 353
   property imagelist read finfo.ca.imagelist write setimagelist 
                                                     stored isimageliststored;
mse1's avatar
mse1 committed
354 355 356 357 358 359 360 361 362
 end;

 framebuttonclassty = class of tframebutton;

 tframebuttons = class(townedeventpersistentarrayprop)
  private
   function getitems1(const index: integer): tframebutton;
  protected
   procedure dosizechanged; override;
363
   procedure checkcount(var acount: integer); override;
364
   procedure updatestate;
mse1's avatar
mse1 committed
365
  public
366
   constructor create(const aowner: tcustombuttonsframe;
mse1's avatar
mse1 committed
367
                    const buttonclass: framebuttonclassty);
mse1's avatar
mse1 committed
368
   class function getitemclasstype: persistentclassty; override;
369
   procedure updatewidgetstate;
mse1's avatar
mse1 committed
370
   function wantmouseevent(const apos: pointty): boolean;
371
   procedure dokeydown(var info: keyeventinfoty);
mse1's avatar
mse1 committed
372 373
  public
   property items[const index: integer]: tframebutton read getitems1; default;
374
   procedure checktemplate(const sender: tobject);
mse1's avatar
mse1 committed
375 376
 end;

377
 tcustombuttonsframe = class(teditframe)
mse1's avatar
mse1 committed
378 379 380 381
  private
   fbuttons: tframebuttons;
   procedure setbuttons(const Value: tframebuttons);
  protected
382
   factivebutton: integer;
mse1's avatar
mse1 committed
383
   fbuttonintf: ibutton;
mse1's avatar
mse1 committed
384
   procedure getpaintframe(var aframe: framety); override;
mse1's avatar
mse1 committed
385
   function getbuttonclass: framebuttonclassty; virtual;
386
   procedure updatestate; override;
387 388
   procedure internalpaintoverlay(const canvas: tcanvas; 
                                           const arect: rectty) override;
389
   procedure dokeydown(var info: keyeventinfoty) override;
mse1's avatar
mse1 committed
390
  public
391
   constructor create(const aintf: icaptionframe; const buttonintf: ibutton);
mse1's avatar
mse1 committed
392
                                                   reintroduce; virtual;
mse1's avatar
mse1 committed
393
   destructor destroy; override;
mse1's avatar
mse1 committed
394
   procedure checktemplate(const sender: tobject); override;
mse1's avatar
mse1 committed
395
   function buttonframe: framety;
mse1's avatar
mse1 committed
396 397
   procedure updatemousestate(const sender: twidget;
                                 const info: mouseeventinfoty); override;
mse1's avatar
mse1 committed
398 399 400 401 402 403
   procedure updatewidgetstate; override;
   procedure mouseevent(var info: mouseeventinfoty);
   procedure initgridframe; override;
   property buttons: tframebuttons read fbuttons write setbuttons;
 end;

404 405 406 407 408 409 410 411 412 413 414 415
 tbuttonsframe = class(tcustombuttonsframe)
  published
   property buttons;
 end;
 
 tcustombuttonframe = class(tcustombuttonsframe) //has at least one button
  private
  protected
   procedure setactivebutton(avalue: integer);
   function getbutton: tframebutton;
   procedure setbutton(const avalue: tframebutton);
  public
416
   constructor create(const aintf: icaptionframe; const buttonintf: ibutton);
417 418 419 420 421 422
                                                                     override;
   property activebutton: integer read factivebutton write setactivebutton 
                                                                    default 0;
   property button: tframebutton read getbutton write setbutton;
 end;
 
mse1's avatar
mse1 committed
423 424 425 426 427
 tbuttonframe = class(tcustombuttonframe)
 end;

 tmultibuttonframe = class(tcustombuttonframe)
  published
428
   property activebutton;
mse1's avatar
mse1 committed
429 430 431 432 433
   property buttons;
 end;
 
 tcustomedit = class;
 texteditedeventty = procedure(const sender: tcustomedit;
mse1's avatar
mse1 committed
434
                                      var atext: msestring) of object;
mse1's avatar
mse1 committed
435
 
436 437 438 439 440
 emptyoptionty = (eo_defaulttext,   //use text of tfacecontroller
                  eo_showfocused,     //show empty_text if focused
                  eo_nocolorfocused); //do not show empty_color if focused 
 emptyoptionsty = set of emptyoptionty;

mse1's avatar
mse1 committed
441
 tcustomedit = class(tpublishedwidget,iedit)
mse1's avatar
mse1 committed
442 443 444
  private
   fonchange: notifyeventty;
   fontextedited: texteditedeventty;
445 446
   foncopytoclipboard: updatestringeventty;
   fonpastefromclipboard: updatestringeventty;
447
   fcursorreadonly: cursorshapety;
448
   fonpaintimage: painteventty;
449 450 451 452 453 454 455
   fempty_text: msestring;
   fempty_textflags: textflagsty;
   fempty_textcolor: colorty;
   fempty_textcolorbackground: colorty;
   fempty_fontstyle: fontstylesty;
   fempty_color: colorty;
   fempty_options: emptyoptionsty;
mse1's avatar
mse1 committed
456 457 458 459 460 461 462
   function getmaxlength: integer;
   function getpasswordchar: msechar;
   procedure setpasswordchar(const Value: msechar);
   function getoldtext: msestring;
   procedure settextflags(const value: textflagsty);
   procedure settextflagsactive(const value: textflagsty);
   function getcaretwidth: integer;
463 464
   procedure setcaretwidth(const Value: integer);   
   procedure setcursorreadonly(const avalue: cursorshapety);
mse1's avatar
mse1 committed
465
   function getoptionsedit1: optionsedit1ty;
466 467 468 469 470 471
   procedure setempty_text(const avalue: msestring);
   procedure setempty_textflags(const avalue: textflagsty);
   procedure setempty_textcolor(const avalue: colorty);
   procedure setempty_textcolorbackground(const avalue: colorty);
   procedure setempty_fontstyle(const avalue: fontstylesty);
   procedure setempty_color(const avalue: colorty);
mse1's avatar
mse1 committed
472
  protected
473 474
   ftextflags: textflagsty;
   ftextflagsactive: textflagsty;
mse1's avatar
mse1 committed
475 476
   feditor: tinplaceedit;
   foptionsedit: optionseditty;
477
   fstate: dataeditstatesty;
478 479 480
   function gettext: msestring virtual;
   procedure settext(const avalue: msestring) virtual;
//   procedure setcurrenttext(const avalue: msestring);
481 482
   function getreadonly: boolean; virtual;
   procedure setreadonly(const avalue: boolean); virtual;
483
   procedure setmaxlength(const avalue: integer);
484
   procedure updatetextflags; virtual;
485 486 487
   function getedittext: msestring; virtual;
   procedure updateedittext(const force: boolean);
   procedure updateemptytext();
488
   procedure updateflagtext(var avalue: msestring);
mse1's avatar
mse1 committed
489 490
   function geteditor: tinplaceedit;
   function geteditfont: tfont; virtual;
491
   function getinnerframe: framety; virtual;
492
   function geteditframe: framety; virtual;
493
   procedure gettextrects(out outer: rectty; out inner: rectty);
mse1's avatar
mse1 committed
494
   procedure setupeditor; virtual;
Martin Schreiber's avatar
Martin Schreiber committed
495
   function getformat(): formatinfoarty virtual;
mse1's avatar
mse1 committed
496 497
   procedure internalcreateframe; override;
   procedure clientrectchanged; override;
498
   procedure getautopaintsize(var asize: sizety); override;
mse1's avatar
mse1 committed
499 500
   procedure fontchanged; override;
   procedure enabledchanged; override;
mse1's avatar
mse1 committed
501
   procedure dragstarted; override;
502
   function navigrect: rectty; override;
mse1's avatar
mse1 committed
503

mse1's avatar
mse1 committed
504
   class function classskininfo: skininfoty; override;
505

506
    //interface to inplaceedit
mse1's avatar
mse1 committed
507 508
   procedure dokeydown(var info: keyeventinfoty); override;
   procedure clientmouseevent(var info: mouseeventinfoty); override;
509 510
   procedure updatepopupmenu(var amenu: tpopupmenu;
                                      var mouseinfo: mouseeventinfoty); override;
mse1's avatar
mse1 committed
511 512 513 514
   procedure doactivate; override;
   procedure dodeactivate; override;
   procedure dofocus; override;
   procedure dodefocus; override;
515
   procedure dopaintforeground(const canvas: tcanvas); override;
516
   procedure dopaintbackground(const canvas: tcanvas); override;
517
   procedure paintimage(const canvas: tcanvas); virtual;
518
   procedure painttext(const canvas: tcanvas); virtual;
519 520
   function needsfocuspaint: boolean; override;
//   procedure doafterpaint(const canvas: tcanvas); override;
521
   procedure rootchanged(const aflags: rootchangeflagsty); override;
522
   function gettextcliprect(): rectty; virtual;
523
   procedure showhint(const aid: int32; var info: hintinfoty); override;
mse1's avatar
mse1 committed
524 525

   procedure dochange; virtual;
526
   procedure formatchanged; virtual;
527
   procedure internaltextedited(const aevent: texteditedeventty);
mse1's avatar
mse1 committed
528
   procedure dotextedited; virtual;
529
   procedure emptychanged;
mse1's avatar
mse1 committed
530 531 532
   procedure readpwchar(reader: treader);
   procedure writepwchar(writer: twriter);
   procedure defineproperties(filer: tfiler); override;
533
   function verticalfontheightdelta: boolean; override;
534
   procedure setoptionsedit1(const avalue: optionsedit1ty); virtual;
535
     //iassistiveclient
536 537
   function getassistivecaretindex(): int32 override;
   function getassistiveflags(): assistiveflagsty override;
538 539 540 541 542 543 544 545 546 547 548 549 550 551
     //iedit
   function getoptionsedit: optionseditty; virtual;
   function hasselection: boolean; virtual;
   function cangridcopy: boolean; virtual;
   procedure setoptionsedit(const avalue: optionseditty); virtual;
   procedure updatereadonlystate; virtual;
   procedure editnotification(var info: editnotificationinfoty); virtual;
   procedure updatecopytoclipboard(var atext: msestring); virtual;
   procedure updatepastefromclipboard(var atext: msestring); virtual;
   function locatecount: integer; virtual;        //number of locate values
   function locatecurrentindex: integer; virtual; //index of current row
   procedure locatesetcurrentindex(const aindex: integer); virtual;
   function getkeystring(const aindex: integer): msestring; virtual; //locate text
   function getedited: boolean; virtual;
mse1's avatar
mse1 committed
552 553 554 555 556 557 558
  public
   constructor create(aowner: tcomponent); override;
   destructor destroy; override;
   procedure initnewcomponent(const ascale: real); override;
   procedure changed;
   procedure initfocus;
   procedure synctofontheight; override;
mse1's avatar
mse1 committed
559
   function actualcursor(const apos: pointty): cursorshapety; override;
mse1's avatar
mse1 committed
560 561

   property editor: tinplaceedit read feditor;
562
   property readonly: boolean read getreadonly write setreadonly;
mse1's avatar
mse1 committed
563
   property optionsedit: optionseditty read getoptionsedit write setoptionsedit
564
                                                     default defaultoptionsedit;
mse1's avatar
mse1 committed
565 566
   property optionsedit1: optionsedit1ty read getoptionsedit1 
                             write setoptionsedit1 default defaultoptionsedit1;
mse1's avatar
mse1 committed
567 568 569
   property passwordchar: msechar read getpasswordchar
                     write setpasswordchar stored false default #0;
           //FPC and Delphi bug: widechars are not streamed
mse1's avatar
mse1 committed
570 571
   property cursorreadonly: cursorshapety read fcursorreadonly 
                                write setcursorreadonly default cr_default;
mse1's avatar
mse1 committed
572 573 574 575 576 577 578 579 580
   property maxlength: integer read getmaxlength write setmaxlength
                     default -1;
   property text: msestring read gettext write settext;
   property oldtext: msestring read getoldtext;
   property textflags: textflagsty read ftextflags write settextflags
                          default defaulttextflags;
   property textflagsactive: textflagsty read ftextflagsactive
                  write settextflagsactive default defaulttextflagsactive;
   property font: twidgetfont read getfont write setfont stored isfontstored;
581 582
   property caretwidth: integer read getcaretwidth write setcaretwidth 
                                                    default defaultcaretwidth;
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599

   property empty_options: emptyoptionsty read fempty_options 
                                           write fempty_options default [];
   property empty_color: colorty read fempty_color write setempty_color 
                                           default cl_none;
   property empty_font: twidgetfontempty read getfontempty write setfontempty 
                                                  stored isfontemptystored;
   property empty_fontstyle: fontstylesty read fempty_fontstyle 
                    write setempty_fontstyle default [];
   property empty_textflags: textflagsty read fempty_textflags 
                    write setempty_textflags default defaulttextflagsempty;
   property empty_text: msestring read fempty_text write setempty_text;
   property empty_textcolor: colorty read fempty_textcolor 
                                   write setempty_textcolor default cl_none;
   property empty_textcolorbackground: colorty read fempty_textcolorbackground
                          write setempty_textcolorbackground default cl_none;

mse1's avatar
mse1 committed
600
   property onchange: notifyeventty read fonchange write fonchange;
601 602
   property ontextedited: texteditedeventty read fontextedited 
                                                           write fontextedited;
603 604
   property oncopytoclipboard: updatestringeventty read foncopytoclipboard 
                  write foncopytoclipboard;
605 606
   property onpastefromclipboard: updatestringeventty 
                read fonpastefromclipboard write fonpastefromclipboard;
607
   property onpaintimage: painteventty read fonpaintimage write fonpaintimage;
mse1's avatar
mse1 committed
608
  published
609 610
   property optionswidget1 default defaulteditwidgetoptions1; //first!
   property optionswidget default defaulteditwidgetoptions;   //first!
mse1's avatar
mse1 committed
611 612
   property bounds_cx default defaulteditwidgetwidth;
   property bounds_cy default defaulteditwidgetheight;
mse1's avatar
mse1 committed
613 614
 end;

615 616 617 618 619 620
 tedit = class(tcustomedit,istatfile)
  private
   ftimer: tsimpletimer;
   fontextediteddelayed: texteditedeventty;
   fstatfile: tstatfile;
   fstatvarname: msestring;
621
   fstatpriority: integer;
622 623 624 625 626
   procedure dotimer(const sender: tobject); virtual;
   function getdelay: integer;
   procedure setdelay(const avalue: integer);
   procedure setstatfile(const avalue: tstatfile);
  protected
627 628
   function gettext: msestring override;
   procedure settext(const avalue: msestring) override;
629 630
   procedure dotextedited; override;
   procedure editnotification(var info: editnotificationinfoty); override;
631
   procedure loaded() override;
632 633
   procedure dofocus() override;
   procedure dodefocus() override;
634 635 636 637 638 639 640

    //istatfile
   procedure dostatread(const reader: tstatreader); virtual;
   procedure dostatwrite(const writer: tstatwriter); virtual;
   procedure statreading;
   procedure statread;
   function getstatvarname: msestring;
641
   function getstatpriority: integer;
642 643 644
  public
   constructor create(aowner: tcomponent); override;
   destructor destroy; override;
mse1's avatar
mse1 committed
645
  published
646 647
   property statfile: tstatfile read fstatfile write setstatfile;
   property statvarname: msestring read getstatvarname write fstatvarname;
648 649
   property statpriority: integer read fstatpriority 
                                       write fstatpriority default 0;
650 651 652
   property delay: integer read getdelay write setdelay default 0; //ms
   property ontextediteddelayed: texteditedeventty read fontextediteddelayed 
                                                   write fontextediteddelayed;
653
   property optionsedit1; //before optionsedit!
mse1's avatar
mse1 committed
654 655 656 657
   property optionsedit;
   property font;
   property textflags;
   property textflagsactive;
mse1's avatar
mse1 committed
658
   property passwordchar;
659 660 661 662 663 664 665 666 667 668

   property empty_options;
   property empty_color;
   property empty_font;
   property empty_fontstyle;
   property empty_textflags;
   property empty_text;
   property empty_textcolor;
   property empty_textcolorbackground;
   
mse1's avatar
mse1 committed
669
   property maxlength;
mse1's avatar
mse1 committed
670
   property caretwidth;
mse1's avatar
mse1 committed
671 672
   property cursorreadonly;
   property text;
mse1's avatar
mse1 committed
673 674 675
   property onchange;
   property ontextedited;
   property onkeydown;
mse1's avatar
mse1 committed
676
   property onkeyup;
mse1's avatar
mse1 committed
677 678
   property oncopytoclipboard;
   property onpastefromclipboard;
mse1's avatar
mse1 committed
679 680 681 682
 end;

implementation
uses
683
 sysutils,msebits,msedataedits,msestockobjects,mseact,
684
 mseassistiveserver;
mse1's avatar
mse1 committed
685 686 687 688

type
 twidget1 = class(twidget);
 tdatacol1 = class(tdatacol);
689
// tcustombuttonframe1 = class(tcustombuttonframe);
mse1's avatar
mse1 committed
690 691 692 693
 tinplaceedit1 = class(tinplaceedit);

{ teditframe }

694
constructor teditframe.create(const aintf: icaptionframe);
mse1's avatar
mse1 committed
695 696 697
begin
 inherited;
 fi.levelo:= -2;
698
 inflateframe1(fi.innerframe,1);
mse1's avatar
mse1 committed
699 700 701
 internalupdatestate;
end;

702 703 704 705 706 707 708 709 710
function teditframe.actualcolorclient(): colorty;
begin
 result:= fi.colorclient;
 if result = cl_default then begin
  result:= cl_foreground;
 end;
end;


mse1's avatar
mse1 committed
711 712
{ tscrolleditframe }

713 714
constructor tscrolleditframe.create(const aintf: iscrollframe; 
                                             const scrollintf: iscrollbar);
mse1's avatar
mse1 committed
715 716 717
begin
 inherited;
 fi.levelo:= -2;
718
 inflateframe1(fi.innerframe,1);
mse1's avatar
mse1 committed
719 720 721
 internalupdatestate;
end;

722 723 724 725 726 727 728 729
function tscrolleditframe.actualcolorclient(): colorty;
begin
 result:= fi.colorclient;
 if result = cl_default then begin
  result:= cl_foreground;
 end;
end;

mse1's avatar
mse1 committed
730 731
{ tscrollboxeditframe }

732
constructor tscrollboxeditframe.create(const aintf: iscrollframe;
mse1's avatar
mse1 committed
733
                                                  const owner: twidget);
mse1's avatar
mse1 committed
734 735 736
begin
 inherited;
 fi.levelo:= -2;
737
 inflateframe1(fi.innerframe,1);
mse1's avatar
mse1 committed
738 739 740
 internalupdatestate;
end;

741 742 743 744 745 746 747 748
function tscrollboxeditframe.actualcolorclient(): colorty;
begin
 result:=  fi.colorclient;
 if result = cl_default then begin
  result:= cl_foreground;
 end;
end;

mse1's avatar
mse1 committed
749 750
{ tframebutton }

mse1's avatar
mse1 committed
751 752
constructor tframebutton.create(aowner: tobject);
begin
753 754
 finfo.color:= cl_default;
 finfo.ca.colorglyph:= cl_default;
755
 finfo.ca.imagenr:= -1;
mse1's avatar
mse1 committed
756
 finfo.imagenrdisabled:= -2;
757
 fshortcut:= ord(key_none);
758
 include(finfo.state,shs_widgetorg);
mse1's avatar
mse1 committed
759 760 761 762 763 764
 inherited;
end;

destructor tframebutton.destroy;
begin
 inherited;
765
 action:= nil; //remove link
mse1's avatar
mse1 committed
766 767 768 769
 finfo.face.free;
 fframe.free;
end;

mse1's avatar
mse1 committed
770 771
procedure tframebutton.changed;
begin
mse1's avatar
mse1 committed
772 773
 if not (csloading in tcustombuttonframe(fowner).
                        fintf.getwidget.componentstate) then begin
mse1's avatar
mse1 committed
774 775 776 777
  tcustombuttonframe(fowner).updatestate;
 end;
end;

778 779
procedure tframebutton.optionstostate();
begin
780 781
 updatebit(longword(finfo.state),ord(shs_invisible),
                                          (fbo_invisible in foptions));
782 783 784 785 786 787 788 789 790 791 792
 updatebit(longword(finfo.state),ord(shs_disabled),fbo_disabled in foptions);
 updatebit(longword(finfo.state),ord(shs_flat),fbo_flat in foptions);
 updatebit(longword(finfo.state),ord(shs_noanimation),fbo_noanim in foptions);
 updatebit(longword(finfo.state),ord(shs_nomouseanimation),
                                                  fbo_nomouseanim in foptions);
 updatebit(longword(finfo.state),ord(shs_noclickanimation),
                                                  fbo_noclickanim in foptions);
 updatebit(longword(finfo.state),ord(shs_nofocusanimation),
                                                  fbo_nofocusanim in foptions);
end;

mse1's avatar
mse1 committed
793
procedure tframebutton.setoptions(const Value: framebuttonoptionsty);
794 795
var
 statebefore: shapestatesty;
796
 optionsbefore: framebuttonoptionsty;
797 798
begin
 statebefore:= finfo.state;
799
 optionsbefore:= foptions;
800 801
 card32(foptions):= setsinglebit(card32(Value),card32(foptions),
                          card32([fbo_disabled,fbo_enabled]));;
802
 optionstostate();
803
 if (statebefore <> finfo.state) or 
804 805
       ((optionsbefore >< foptions) * 
          [fbo_left,fbo_invisible,fbo_inactiveinvisible] <> []) then begin
806
  changed();
mse1's avatar
mse1 committed
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872
 end;
end;

function tframebutton.getleft: boolean;
begin
 result:= fbo_left in foptions;
end;

procedure tframebutton.setleft(const Value: boolean);
begin
 if value then begin
  setoptions(foptions + [fbo_left]);
 end
 else begin
  setoptions(foptions - [fbo_left]);
 end;
end;

function tframebutton.getvisible: boolean;
begin
 result:= not (fbo_invisible in foptions);
end;

procedure tframebutton.setvisible(const Value: boolean);
begin
 if value then begin
  setoptions(foptions - [fbo_invisible]);
 end
 else begin
  setoptions(foptions + [fbo_invisible]);
 end;
end;

function tframebutton.getenabled: boolean;
begin
 result:= not (fbo_disabled in foptions);
end;

procedure tframebutton.setenabled(const Value: boolean);
begin
 if value then begin
  setoptions(foptions - [fbo_disabled]);
 end
 else begin
  setoptions(foptions + [fbo_disabled]);
 end;
end;

procedure tframebutton.setbuttonwidth(const Value: integer);
begin
 if fbuttonwidth <> value then begin
  fbuttonwidth := Value;
  changed;
 end;
end;

procedure tframebutton.setcolor(const avalue: colorty);
begin
 if finfo.color <> avalue then begin
  finfo.color := avalue;
  changed;
 end;
end;

procedure tframebutton.setcolorglyph(const avalue: colorty);
begin
873 874
 if finfo.ca.colorglyph <> avalue then begin
  finfo.ca.colorglyph := avalue;
mse1's avatar
mse1 committed
875 876 877 878
  changed;
 end;
end;

879 880 881 882 883 884 885 886 887 888
procedure tframebutton.doexec();
begin
 if faction <> nil then begin
  faction.execute();
 end;
 if assigned(fonexecute) then begin
  fonexecute(self);
 end;
end; //doexe

mse1's avatar
mse1 committed
889 890
procedure tframebutton.mouseevent(var info: mouseeventinfoty;
     const intf: iframe; const buttonintf: ibutton; const index: integer);
891

mse1's avatar
mse1 committed
892
var
893
 bo1,bo2: boolean;
894
 action1: buttonactionty;
mse1's avatar
mse1 committed
895
begin
896
 bo2:= false;
mse1's avatar
mse1 committed
897
 with finfo do begin
898
  bo1:= shs_clicked in state;
899
  if updatemouseshapestate(finfo,info,nil,nil) then begin
mse1's avatar
mse1 committed
900
   invalidate;
mse1's avatar
mse1 committed
901
  end;
902
  if shs_clicked in state then begin
mse1's avatar
mse1 committed
903
   if not bo1 then begin
904 905
    action1:= ba_buttonpress;
    buttonintf.buttonaction(action1,index);
mse1's avatar
mse1 committed
906 907 908 909
   end;
  end
  else begin
   if bo1 then begin
910 911
    action1:= ba_buttonrelease;
    buttonintf.buttonaction(action1,index);
mse1's avatar
mse1 committed
912 913 914
   end;
  end;
  if bo1 and (info.eventkind = ek_buttonrelease) then begin
915 916 917
   action1:= ba_click;
   buttonintf.buttonaction(action1,index);
   if action1 = ba_click then begin
918 919 920 921 922 923 924 925 926 927
    doexec();
    bo2:= true;
   end;
  end;
 end;
 if (fbo_executeonclientdblclick in foptions) and not bo2 and
                (finfo.state * [shs_disabled,shs_invisible] = []) then begin
  with getwidget() do begin
   if iswidgetdblclicked(info) then begin
    doexec();
mse1's avatar
mse1 committed
928 929 930 931 932 933 934
   end;
  end;
 end;
end;

procedure tframebutton.setimagelist(const Value: timagelist);
begin
935
 setlinkedcomponent(iobjectlink(self),value,tmsecomponent(finfo.ca.imagelist));
mse1's avatar
mse1 committed
936 937 938
 changed;
end;

939
procedure tframebutton.setimagenr(const avalue: imagenrty);
mse1's avatar
mse1 committed
940
begin
941 942
 if finfo.ca.imagenr <> avalue then begin
  finfo.ca.imagenr := avalue;
mse1's avatar
mse1 committed
943 944 945 946
  changed;
 end;
end;

947 948 949 950 951 952 953 954 955
procedure tframebutton.setimagenrdisabled(const avalue: imagenrty);
begin
 if finfo.imagenrdisabled <> avalue then begin
  finfo.imagenrdisabled := avalue;
  changed;
 end;
end;


mse1's avatar
mse1 committed
956 957
procedure tframebutton.createface;
begin
958 959 960
 if finfo.face = nil then begin
  finfo.face:= tface.create(iface(tcustombuttonframe(fowner).fintf.getwidget));
 end;
mse1's avatar
mse1 committed
961 962
end;

mse1's avatar
mse1 committed
963 964
procedure tframebutton.createframe;
begin
965 966 967
 if fframe = nil then begin
  tframe.create(iframe(self));
 end;
mse1's avatar
mse1 committed
968 969
end;

mse1's avatar
mse1 committed
970 971 972 973 974 975 976 977 978 979 980 981 982 983
function tframebutton.getface: tface;
begin
 tcustombuttonframe(fowner).fintf.getwidget.getoptionalobject(finfo.face,
                               {$ifdef FPC}@{$endif}createface);
 result:= tface(finfo.face);
end;

procedure tframebutton.setface(const avalue: tface);
begin
 tcustombuttonframe(fowner).fintf.getwidget.setoptionalobject(avalue,finfo.face,
                               {$ifdef FPC}@{$endif}createface);
 tcustombuttonframe(fowner).fintf.getwidget.invalidate;
end;

mse1's avatar
mse1 committed
984 985 986 987 988 989 990 991 992 993 994
function tframebutton.getframe: tframe;
begin
 tcustombuttonframe(fowner).fintf.getwidget.getoptionalobject(fframe,
                               {$ifdef FPC}@{$endif}createframe);
 result:= fframe;
end;

procedure tframebutton.setframe(const avalue: tframe);
begin
 tcustombuttonframe(fowner).fintf.getwidget.setoptionalobject(avalue,fframe,
                               {$ifdef FPC}@{$endif}createframe);
995 996
// tcustombuttonframe(fowner).fintf.getwidget.invalidate;
 changed();
mse1's avatar
mse1 committed
997 998
end;

999
procedure tframebutton.updatewidgetstate(const awidget: twidget);
1000 1001
//var
// invisiblebefore: boolean;
mse1's avatar
mse1 committed
1002
begin
1003
// invisiblebefore:= ss_invisible in finfo.state;
1004 1005
 updatewidgetshapestate(finfo,awidget,(fbo_disabled in foptions) or 
           freadonly and not (fbo_enabled in foptions),
1006
                                 {fbo_invisible in foptions,}fframe);
1007 1008 1009 1010 1011 1012 1013
 if (fbo_inactiveinvisible in foptions) and 
  (awidget.componentstate * [csdesigning,csdestroying] = []) then begin
  if awidget.active xor not(shs_invisible in finfo.state) then begin
   togglebit1(longword(finfo.state),ord(shs_invisible));
   tcustombuttonframe(fowner).internalupdatestate();
  end;
 end;
mse1's avatar
mse1 committed
1014
// updatebit(longword(finfo.state),ord(ss_invisible),invisiblebefore);
mse1's avatar
mse1 committed
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
end;

procedure tframebutton.assign(source: tpersistent);
begin
 if source is tframebutton then begin
  with tframebutton(source) do begin
   self.setoptions(foptions);
   self.left:= left;
   self.color:= color;
   self.imagelist:= imagelist;
   self.imagenr:= imagenr;
   self.onexecute:= onexecute;
mse1's avatar
mse1 committed
1027 1028
   self.frame:= frame;
   self.face:= face;
mse1's avatar
mse1 committed
1029 1030 1031 1032
  end;
 end;
end;

1033 1034 1035 1036 1037
procedure tframebutton.checktemplate(const sender: tobject);
begin
 if finfo.face <> nil then begin
  finfo.face.checktemplate(sender);
 end;
mse1's avatar
mse1 committed
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052
 if fframe <> nil then begin
  fframe.checktemplate(sender);
 end;
end;

procedure tframebutton.setframeinstance(instance: tcustomframe);
begin
 fframe:= tframe(instance);
end;

procedure tframebutton.setstaticframe(value: boolean);
begin
 //dummy
end;

1053 1054 1055 1056 1057
function tframebutton.getstaticframe: boolean;
begin
 result:= false;
end;

mse1's avatar
mse1 committed
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
function tframebutton.getwidgetrect: rectty;
begin
 result:= nullrect;
end;

function tframebutton.getcomponentstate: tcomponentstate;
begin
 result:= tcustombuttonframe(fowner).fintf.getwidget.componentstate;
end;

1068 1069 1070 1071 1072
function tframebutton.getmsecomponentstate: msecomponentstatesty;
begin
 result:= tcustombuttonframe(fowner).fintf.getwidget.msecomponentstate;
end;

mse1's avatar
mse1 committed
1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
procedure tframebutton.scrollwidgets(const dist: pointty);
begin
 //dummy
end;

procedure tframebutton.clientrectchanged;
begin
 changed;
end;

procedure tframebutton.invalidate;
begin
 tcustombuttonframe(fowner).fintf.getwidget.invalidaterect(
                                                 fframerect,org_widget);
end;

procedure tframebutton.invalidatewidget;
begin
 invalidate;
end;

procedure tframebutton.invalidaterect(const rect: rectty;
1095
               const org: originty = org_client; const noclip: boolean = false);
mse1's avatar
mse1 committed
1096 1097 1098 1099 1100 1101 1102 1103 1104
begin
 invalidate;
end;

function tframebutton.getwidget: twidget;
begin
 result:= tcustombuttonframe(fowner).fintf.getwidget
end;

mse1's avatar
mse1 committed
1105 1106
function tframebutton.getframestateflags: framestateflagsty;
begin
1107 1108
 with getwidget,finfo do begin
  result:= combineframestateflags(shs_disabled in state,focused,active,
1109
             shs_mouse in state,shs_clicked in state);
mse1's avatar
mse1 committed
1110 1111
 end;
end;
mse1's avatar
mse1 committed
1112

mse1's avatar
mse1 committed
1113
function tframebutton.getimagelist: timagelist;
mse1's avatar
mse1 committed
1114
begin
1115
 result:= finfo.ca.imagelist;
mse1's avatar
mse1 committed
1116 1117
end;

1118 1119 1120 1121 1122 1123
procedure tframebutton.setaction(const avalue: taction);
begin
 twidget1(iframe(tcustombuttonsframe(fowner).fintf).getwidget).
                          setlinkedvar(avalue,tmsecomponent(faction));
end;

mse1's avatar
mse1 committed
1124 1125 1126 1127 1128
{ tstockglyphframebutton}

constructor tstockglyphframebutton.create(aowner: tobject);
begin
 inherited;
1129
 finfo.ca.imagelist:= stockobjects.glyphs;
mse1's avatar
mse1 committed
1130 1131 1132 1133
end;

function tstockglyphframebutton.isimageliststored: boolean;
begin
1134
 result:= finfo.ca.imagelist <> stockobjects.glyphs;
mse1's avatar
mse1 committed
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
end;

procedure tstockglyphframebutton.setimagelist(const Value: timagelist);
begin
 if value = nil then begin
  inherited setimagelist(stockobjects.glyphs);
 end
 else begin
  inherited setimagelist(value);
 end;
end;

{ tframebuttons }

1149
constructor tframebuttons.create(const aowner: tcustombuttonsframe;
mse1's avatar
mse1 committed
1150 1151 1152 1153 1154
                      const buttonclass: framebuttonclassty);
begin
 inherited create(aowner,buttonclass{tframebutton});
end;

mse1's avatar
mse1 committed
1155 1156 1157 1158 1159
class function tframebuttons.getitemclasstype: persistentclassty;
begin
 result:= tframebutton;
end;

mse1's avatar
mse1 committed
1160 1161
procedure tframebuttons.dosizechanged;
begin
1162 1163 1164 1165
 if not (csloading in 
         tcustombuttonframe(fowner).fintf.getwidget.componentstate) then begin
  tcustombuttonframe(fowner).updatestate;
 end;
mse1's avatar
mse1 committed
1166 1167 1168 1169 1170 1171 1172 1173
 inherited;
end;

function tframebuttons.getitems1(const index: integer): tframebutton;
begin
 result:= tframebutton(inherited getitems(index));
end;

1174
procedure tframebuttons.updatewidgetstate;
mse1's avatar
mse1 committed
1175 1176 1177 1178
var
 int1: integer;
 widget1: twidget;
begin
1179
 widget1:= tcustombuttonsframe(fowner).fintf.getwidget;
mse1's avatar
mse1 committed
1180 1181
 for int1:= 0 to high(fitems) do begin
//  updatewidgetshapestate(tframebutton(fitems[int1]).finfo,widget1);
1182
  tframebutton(fitems[int1]).updatewidgetstate(widget1);
mse1's avatar
mse1 committed
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
 end;
end;

function tframebuttons.wantmouseevent(const apos: pointty): boolean;
var
 int1: integer;
begin
 result:= false;
 for int1:= 0 to high(fitems) do begin
  with tframebutton(fitems[int1]) do begin
mse1's avatar
mse1 committed
1193
   if not (fbo_invisible in foptions) and pointinrect(apos,fframerect) then begin
mse1's avatar
mse1 committed
1194 1195 1196 1197 1198 1199 1200
    result:= true;
    break;
   end;
  end;
 end;
end;

1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216
procedure tframebuttons.dokeydown(var info: keyeventinfoty);
var
 i1: int32;
begin
 for i1:= 0 to high(fitems) do begin
  with tframebutton(fitems[i1]) do begin
   if (finfo.state * [shs_disabled,shs_invisible] = []) and 
               checkshortcutcode(fshortcut,info) then begin
    include(info.eventstate,es_processed);
    doexec();
    break;
   end;
  end;
 end;
end;

1217 1218 1219 1220 1221 1222 1223 1224 1225
procedure tframebuttons.checktemplate(const sender: tobject);
var
 int1: integer;
begin
 for int1:= 0 to high(fitems) do begin
  tframebutton(fitems[int1]).checktemplate(sender);
 end;
end;

1226 1227 1228 1229 1230 1231
procedure tframebuttons.updatestate;
var
 int1: integer;
begin
 for int1:= 0 to high(fitems) do begin
  with tframebutton(fitems[int1]) do begin
mse1's avatar
mse1 committed
1232
   frameskinoptionstoshapestate(fframe,finfo);
1233
   finfo.state:= finfo.state - [shs_showfocusrect,shs_showdefaultrect];
1234 1235 1236
   if (fframe = nil) then begin
    optionstostate(); //restore flat and anim settings
   end;
1237 1238
  end;
 end;
1239
 updatewidgetstate(); //restore disabled state
1240 1241
end;

1242 1243 1244 1245 1246 1247 1248
procedure tframebuttons.checkcount(var acount: integer);
begin
 inherited;
 if acount <= tcustombuttonsframe(fowner).factivebutton then begin
  acount:= tcustombuttonsframe(fowner).factivebutton+1;
 end;
end;
mse1's avatar
mse1 committed
1249

1250 1251
{ tcustombuttonsframe }

1252
constructor tcustombuttonsframe.create(const aintf: icaptionframe;
1253
                                             const buttonintf: ibutton);
mse1's avatar
mse1 committed
1254
begin
1255
 factivebutton:= -1; //none
mse1's avatar
mse1 committed
1256 1257
 fbuttons:= tframebuttons.create(self,getbuttonclass);
 fbuttonintf:= buttonintf;
1258 1259
 aintf.setstaticframe(true);
 inherited create(aintf);
mse1's avatar
mse1 committed
1260 1261
end;

1262
destructor tcustombuttonsframe.destroy;
mse1's avatar
mse1 committed
1263 1264 1265 1266 1267
begin
 inherited;
 fbuttons.free;
end;

1268
function tcustombuttonsframe.getbuttonclass: framebuttonclassty;
mse1's avatar
mse1 committed
1269 1270 1271 1272
begin
 result:= tstockglyphframebutton;
end;

1273
function tcustombuttonsframe.buttonframe: framety;
mse1's avatar
mse1 committed
1274 1275 1276 1277 1278 1279
var
 int1: integer;
begin
 result:= nullframe;
 for int1:= 0 to fbuttons.count - 1 do begin
  with fbuttons[int1],finfo do begin
1280
   if not (shs_invisible in state) then begin
mse1's avatar
mse1 committed
1281
    if fbo_left in foptions then begin
mse1's avatar
mse1 committed
1282
     inc(result.left,fframerect.cx);
mse1's avatar
mse1 committed
1283 1284
    end
    else begin
mse1's avatar
mse1 committed
1285
     inc(result.right,fframerect.cx);
mse1's avatar
mse1 committed
1286 1287 1288 1289 1290 1291
    end;
   end;
  end;
 end;
end;

1292
procedure tcustombuttonsframe.getpaintframe(var aframe: framety);
mse1's avatar
mse1 committed
1293 1294 1295 1296 1297
var
 int1: integer;
begin
 inherited;
 for int1:= 0 to fbuttons.count-1 do begin
mse1's avatar
mse1 committed
1298
  with fbuttons[int1],finfo,fframerect do begin
1299
   if not (shs_invisible in state) then begin
1300
    cy:= fintf.getwidgetrect.cy - frameframedim.cy;
mse1's avatar
mse1 committed
1301
    if fbuttonwidth = 0 then begin
mse1's avatar
mse1 committed
1302
     cx:= cy;
mse1's avatar
mse1 committed
1303 1304
    end
    else begin
mse1's avatar
mse1 committed
1305
     cx:= fbuttonwidth;
1306 1307 1308
     if cx < 0 then begin
      cx:= 0;
     end;
mse1's avatar
mse1 committed
1309
    end;
mse1's avatar
mse1 committed
1310
    y:= fouterframe.top + fwidth.top;
mse1's avatar
mse1 committed
1311
    if fbo_left in foptions then begin
mse1's avatar
mse1 committed
1312 1313
     x:= fouterframe.left + fwidth.left + aframe.left;
     inc(aframe.left,cx);
mse1's avatar
mse1 committed
1314 1315
    end
    else begin
mse1's avatar
mse1 committed
1316 1317 1318 1319
     x:= fintf.getwidgetrect.cx -
       (fouterframe.right + fwidth.right + cx + aframe.right);
     inc(aframe.right,cx);
    end;
mse1's avatar
mse1 committed
1320 1321
    if (fframe <> nil) and 
                 not (fso_noinnerrect in fframe.optionsskin) then begin
1322 1323 1324
     finfo.ca.dim:= deflaterect(fframerect,fframe.paintframe);
     deflaterect1(finfo.ca.dim,fframe.frameo);
//     finfo.ca.dim:= deflaterect(fframerect,fframe.innerframe);
mse1's avatar
mse1 committed
1325 1326
    end
    else begin
1327
     finfo.ca.dim:= fframerect;
mse1's avatar
mse1 committed
1328 1329 1330 1331 1332 1333
    end;
   end;
  end;
 end;
end;

1334
procedure tcustombuttonsframe.initgridframe;
mse1's avatar
mse1 committed
1335 1336 1337 1338 1339 1340