| [15] | 1 | // Enhanced version of TCoolBar from Sibyl samples | 
|---|
|  | 2 | // - Bitmap for first button draws correctly | 
|---|
|  | 3 | // - Draws a border line underneath | 
|---|
|  | 4 | // - Buttons look better (have black frame, when pressed look sunken, background moves) | 
|---|
|  | 5 | // - Button text highlights under mouse (HotColor property) | 
|---|
|  | 6 | // - bitmap does not overwrite border of button | 
|---|
|  | 7 | // (C) 1998 SpeedSoft | 
|---|
|  | 8 |  | 
|---|
|  | 9 | Unit coolbar2; | 
|---|
|  | 10 |  | 
|---|
|  | 11 | Interface | 
|---|
|  | 12 |  | 
|---|
|  | 13 | Uses Classes,Forms,Graphics,Buttons,StdCtrls,ComCtrls,Dialogs, Messages; | 
|---|
|  | 14 |  | 
|---|
|  | 15 | Type | 
|---|
|  | 16 | TCoolSection2=Class(THeaderSection) | 
|---|
|  | 17 | Private | 
|---|
|  | 18 | FImage:LongInt; | 
|---|
|  | 19 | FHotImage:LongInt; | 
|---|
|  | 20 | FDisabledImage:LongInt; | 
|---|
|  | 21 | FDisabled:Boolean; | 
|---|
|  | 22 | Private | 
|---|
|  | 23 | Procedure SetDisabled(NewValue:Boolean); | 
|---|
|  | 24 | Procedure SetImage(NewValue:LongInt); | 
|---|
|  | 25 | Procedure SetHotImage(NewValue:LongInt); | 
|---|
|  | 26 | Procedure SetDisabledImage(NewValue:LongInt); | 
|---|
|  | 27 | Public | 
|---|
|  | 28 | Hint:string; | 
|---|
|  | 29 | Constructor Create(ACollection:TCollection);Override; | 
|---|
|  | 30 | Procedure Assign(Source:TCollectionItem);Override; | 
|---|
|  | 31 | Public | 
|---|
|  | 32 | Property Disabled:Boolean read FDisabled write SetDisabled; | 
|---|
|  | 33 | Property Image:LongInt read FImage write SetImage; | 
|---|
|  | 34 | Property HotImage:LongInt read FHotImage write SetHotImage; | 
|---|
|  | 35 | Property DisabledImage:LongInt read FDisabledImage write SetDisabledImage; | 
|---|
|  | 36 | End; | 
|---|
|  | 37 |  | 
|---|
|  | 38 | TCoolSections2=Class(THeaderSections) | 
|---|
|  | 39 | Protected | 
|---|
|  | 40 | Function GetSection( Index: longint ): TCoolSection2; | 
|---|
|  | 41 | Public | 
|---|
|  | 42 | Procedure SetupComponent;Override; | 
|---|
|  | 43 | Property Items[ Index: Longint ]: TCoolSection2 read GetSection; default; | 
|---|
|  | 44 | End; | 
|---|
|  | 45 |  | 
|---|
|  | 46 | TDrawCoolSectionEvent=Procedure(HeaderControl:THeaderControl;Section:TCoolSection2; | 
|---|
|  | 47 | Const rc:TRect;Pressed,Hot,Enabled:Boolean) Of Object; | 
|---|
|  | 48 |  | 
|---|
|  | 49 | TCoolBar2=Class(THeaderControl) | 
|---|
|  | 50 | Private | 
|---|
|  | 51 | FBackgroundBitmap:TBitmap; | 
|---|
|  | 52 | FActiveSection:TCoolSection2; | 
|---|
|  | 53 | FImages:TImageList; | 
|---|
|  | 54 | FFlat:Boolean; | 
|---|
|  | 55 | FBackgroundOffset:LongWord; | 
|---|
|  | 56 | FMouseTimer:TTimer; | 
|---|
|  | 57 | FOnDrawSection:TDrawCoolSectionEvent; | 
|---|
|  | 58 | FHotColor: TColor; | 
|---|
|  | 59 | FShowText: boolean; | 
|---|
|  | 60 | FShowImages: boolean; | 
|---|
|  | 61 | Private | 
|---|
|  | 62 | Procedure EvFMouseTimer(Sender:TObject); | 
|---|
|  | 63 | Procedure SetBackgroundBitmap(NewValue:TBitmap); | 
|---|
|  | 64 | Procedure UpdateHeader(Header:THeaderSection);Override; | 
|---|
|  | 65 | Procedure SetImages(NewValue:TImageList); | 
|---|
|  | 66 | Procedure SetFlat(NewValue:Boolean); | 
|---|
|  | 67 | Procedure SetBackgroundOffset(NewValue:LongWord); | 
|---|
|  | 68 | Function GetSections:TCoolSections2; | 
|---|
|  | 69 | Procedure SetSections(NewValue:TCoolSections2); | 
|---|
|  | 70 |  | 
|---|
|  | 71 | Procedure SetShowText( NewValue: boolean ); | 
|---|
|  | 72 | Procedure SetShowImages( NewValue: boolean ); | 
|---|
|  | 73 |  | 
|---|
|  | 74 | Protected | 
|---|
|  | 75 | Procedure DrawSection(Section:TCoolSection2;Const rc:TRect;Pressed,Hot,Enabled:Boolean);Virtual; | 
|---|
|  | 76 | Procedure MouseDown(Button:TMouseButton;ShiftState:TShiftState;X,Y:LongInt);Override; | 
|---|
|  | 77 | Procedure MouseDblClick(Button:TMouseButton;ShiftState:TShiftState;X,Y:LongInt);Override; | 
|---|
|  | 78 | Procedure MouseMove(ShiftState:TShiftState;X,Y:LongInt);Override; | 
|---|
|  | 79 | Procedure Notification( AComponent: TComponent; | 
|---|
|  | 80 | Operation:TOperation ); Override; | 
|---|
|  | 81 | Procedure DrawBackground( rec: TRect; | 
|---|
|  | 82 | XOffset, YOffset: longint ); | 
|---|
|  | 83 | Public | 
|---|
|  | 84 | Procedure SetupComponent;Override; | 
|---|
|  | 85 | Procedure Redraw(Const rec:TRect);Override; | 
|---|
|  | 86 | Procedure ReadSCUResource(Const ResName:TResourceName;Var Data;DataLen:LongInt);Override; | 
|---|
|  | 87 | Function WriteSCUResource(Stream:TResourceStream):Boolean;Override; | 
|---|
|  | 88 | Procedure EditSections; | 
|---|
|  | 89 |  | 
|---|
|  | 90 | Procedure SetMinConstButtonWidth; | 
|---|
|  | 91 | Published | 
|---|
|  | 92 | Property BackgroundBitmap:TBitmap read FBackgroundBitmap write SetBackgroundBitmap; | 
|---|
|  | 93 | Property BackgroundOffset:LongWord read FBackgroundOffset write SetBackgroundOffset; | 
|---|
|  | 94 | Property Images:TImageList read FImages write SetImages; | 
|---|
|  | 95 | Property Flat:Boolean read FFlat write SetFlat; | 
|---|
|  | 96 | Property Sections:TCoolSections2 Read GetSections Write SetSections; | 
|---|
|  | 97 | Property HotColor: TColor read FHotColor write FHotColor; | 
|---|
|  | 98 |  | 
|---|
|  | 99 | Property ShowText: boolean read FShowText write SetShowText; | 
|---|
|  | 100 | Property ShowImages: boolean read FShowImages write SetShowImages; | 
|---|
|  | 101 |  | 
|---|
|  | 102 | Published | 
|---|
|  | 103 | Property OnDrawSection:TDrawCoolSectionEvent Read FOnDrawSection Write FOnDrawSection; | 
|---|
|  | 104 | Property OnFontChange; | 
|---|
|  | 105 | End; | 
|---|
|  | 106 |  | 
|---|
|  | 107 | Implementation | 
|---|
|  | 108 |  | 
|---|
|  | 109 | // default bitmap from resource file | 
|---|
|  | 110 | // {$R CoolBar2} | 
|---|
|  | 111 |  | 
|---|
|  | 112 | exports | 
|---|
|  | 113 | TCoolBar2, 'User', 'Coolbar2.bmp'; | 
|---|
|  | 114 | { | 
|---|
|  | 115 | ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» | 
|---|
|  | 116 | º                                                                           º | 
|---|
|  | 117 | º Speed-Pascal/2 Version 2.0                                                º | 
|---|
|  | 118 | º                                                                           º | 
|---|
|  | 119 | º Speed-Pascal Component Classes (SPCC)                                     º | 
|---|
|  | 120 | º                                                                           º | 
|---|
|  | 121 | º This section: TCoolSection2 Class Implementation                           º | 
|---|
|  | 122 | º                                                                           º | 
|---|
|  | 123 | º (C) 1995,97 SpeedSoft. All rights reserved. Disclosure probibited !       º | 
|---|
|  | 124 | º                                                                           º | 
|---|
|  | 125 | ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍŒ | 
|---|
|  | 126 | } | 
|---|
|  | 127 |  | 
|---|
|  | 128 | Constructor TCoolSection2.Create(ACollection:TCollection); | 
|---|
|  | 129 | Begin | 
|---|
|  | 130 | Inherited Create(ACollection); | 
|---|
|  | 131 | FImage:=-1; | 
|---|
|  | 132 | FHotImage:=-1; | 
|---|
|  | 133 | FDisabledImage:=-1; | 
|---|
|  | 134 | AllowSize:= false; | 
|---|
|  | 135 | Width:= 60; | 
|---|
|  | 136 | Alignment:= taCenter; | 
|---|
|  | 137 | End; | 
|---|
|  | 138 |  | 
|---|
|  | 139 | Procedure TCoolSection2.Assign(Source:TCollectionItem); | 
|---|
|  | 140 | Begin | 
|---|
|  | 141 | Inherited Assign(Source); | 
|---|
|  | 142 | If Source Is TCoolSection2 Then | 
|---|
|  | 143 | If Source<>Self Then | 
|---|
|  | 144 | Begin | 
|---|
|  | 145 | FImage:=TCoolSection2(Source).Image; | 
|---|
|  | 146 | FHotImage:=TCoolSection2(Source).HotImage; | 
|---|
|  | 147 | FDisabledImage:=TCoolSection2(Source).DisabledImage; | 
|---|
|  | 148 | FDisabled:=TCoolSection2(Source).Disabled; | 
|---|
|  | 149 | End; | 
|---|
|  | 150 | End; | 
|---|
|  | 151 |  | 
|---|
|  | 152 | Procedure TCoolSection2.SetDisabled(NewValue:Boolean); | 
|---|
|  | 153 | Begin | 
|---|
|  | 154 | If NewValue=FDisabled Then exit; | 
|---|
|  | 155 | FDisabled:=NewValue; | 
|---|
|  | 156 | Changed(False); | 
|---|
|  | 157 | End; | 
|---|
|  | 158 |  | 
|---|
|  | 159 | Procedure TCoolSection2.SetImage(NewValue:LongInt); | 
|---|
|  | 160 | Begin | 
|---|
|  | 161 | If NewValue=FImage Then exit; | 
|---|
|  | 162 | FImage:=NewValue; | 
|---|
|  | 163 | Changed(False); | 
|---|
|  | 164 | End; | 
|---|
|  | 165 |  | 
|---|
|  | 166 | Procedure TCoolSection2.SetHotImage(NewValue:LongInt); | 
|---|
|  | 167 | Begin | 
|---|
|  | 168 | If NewValue=FHotImage Then exit; | 
|---|
|  | 169 | FHotImage:=NewValue; | 
|---|
|  | 170 | Changed(False); | 
|---|
|  | 171 | End; | 
|---|
|  | 172 |  | 
|---|
|  | 173 | Procedure TCoolSection2.SetDisabledImage(NewValue:LongInt); | 
|---|
|  | 174 | Begin | 
|---|
|  | 175 | If NewValue=FDisabledImage Then exit; | 
|---|
|  | 176 | FDisabledImage:=NewValue; | 
|---|
|  | 177 | Changed(False); | 
|---|
|  | 178 | End; | 
|---|
|  | 179 |  | 
|---|
|  | 180 | { | 
|---|
|  | 181 | ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» | 
|---|
|  | 182 | º                                                                           º | 
|---|
|  | 183 | º Speed-Pascal/2 Version 2.0                                                º | 
|---|
|  | 184 | º                                                                           º | 
|---|
|  | 185 | º Speed-Pascal Component Classes (SPCC)                                     º | 
|---|
|  | 186 | º                                                                           º | 
|---|
|  | 187 | º This section: TCoolSections2 Class Implementation                          º | 
|---|
|  | 188 | º                                                                           º | 
|---|
|  | 189 | º (C) 1995,97 SpeedSoft. All rights reserved. Disclosure probibited !       º | 
|---|
|  | 190 | º                                                                           º | 
|---|
|  | 191 | ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍŒ | 
|---|
|  | 192 | } | 
|---|
|  | 193 |  | 
|---|
|  | 194 | Procedure TCoolSections2.SetupComponent; | 
|---|
|  | 195 | Begin | 
|---|
|  | 196 | Inherited SetupComponent; | 
|---|
|  | 197 | Name:='CoolSections'; | 
|---|
|  | 198 | ItemClass:=TCoolSection2; | 
|---|
|  | 199 | End; | 
|---|
|  | 200 |  | 
|---|
|  | 201 | Function TCoolSections2.GetSection( Index: longint ): TCoolSection2; | 
|---|
|  | 202 | begin | 
|---|
|  | 203 | Result:= ( inherited Items[ Index ] ) as TCoolSection2; | 
|---|
|  | 204 | end; | 
|---|
|  | 205 |  | 
|---|
|  | 206 | { | 
|---|
|  | 207 | ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» | 
|---|
|  | 208 | º                                                                           º | 
|---|
|  | 209 | º Speed-Pascal/2 Version 2.0                                                º | 
|---|
|  | 210 | º                                                                           º | 
|---|
|  | 211 | º Speed-Pascal Component Classes (SPCC)                                     º | 
|---|
|  | 212 | º                                                                           º | 
|---|
|  | 213 | º This section: TCoolBar2 Class Implementation                               º | 
|---|
|  | 214 | º                                                                           º | 
|---|
|  | 215 | º (C) 1995,97 SpeedSoft. All rights reserved. Disclosure probibited !       º | 
|---|
|  | 216 | º                                                                           º | 
|---|
|  | 217 | ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍŒ | 
|---|
|  | 218 | } | 
|---|
|  | 219 |  | 
|---|
|  | 220 | Procedure TCoolBar2.SetupComponent; | 
|---|
|  | 221 | Begin | 
|---|
|  | 222 | Inherited SetupComponent; | 
|---|
|  | 223 |  | 
|---|
|  | 224 | FBackgroundBitmap := nil; | 
|---|
|  | 225 | //     FBackgroundBitmap.Create; | 
|---|
|  | 226 | //     FBackgroundBitmap.LoadFromResourceName('Cool'); | 
|---|
|  | 227 | FFlat:=True; | 
|---|
|  | 228 | FMouseTimer.Create(Self); | 
|---|
|  | 229 | Include(FMouseTimer.ComponentState, csDetail); | 
|---|
|  | 230 | FMouseTimer.Interval := 50; | 
|---|
|  | 231 | FMouseTimer.OnTimer := EvFMouseTimer; | 
|---|
|  | 232 | Name:='CoolBar'; | 
|---|
|  | 233 | SectionsClass:=TCoolSections2; | 
|---|
|  | 234 | FHotColor:= clBlue; | 
|---|
|  | 235 | End; | 
|---|
|  | 236 |  | 
|---|
|  | 237 | Procedure TCoolBar2.SetFlat(NewValue:Boolean); | 
|---|
|  | 238 | Begin | 
|---|
|  | 239 | If NewValue=FFlat Then exit; | 
|---|
|  | 240 | FFlat:=NewValue; | 
|---|
|  | 241 | Invalidate; | 
|---|
|  | 242 | End; | 
|---|
|  | 243 |  | 
|---|
|  | 244 | Function TCoolBar2.GetSections:TCoolSections2; | 
|---|
|  | 245 | Begin | 
|---|
|  | 246 | Result:=TCoolSections2(Inherited Sections); | 
|---|
|  | 247 | End; | 
|---|
|  | 248 |  | 
|---|
|  | 249 | Procedure TCoolBar2.SetSections(NewValue:TCoolSections2); | 
|---|
|  | 250 | Begin | 
|---|
|  | 251 | Inherited Sections:=NewValue; | 
|---|
|  | 252 | End; | 
|---|
|  | 253 |  | 
|---|
|  | 254 | Procedure TCoolBar2.SetImages(NewValue:TImageList); | 
|---|
|  | 255 | Begin | 
|---|
|  | 256 | If NewValue = FImages Then | 
|---|
|  | 257 | exit; | 
|---|
|  | 258 | If FImages<>Nil Then | 
|---|
|  | 259 | FImages.Notification( Self, opRemove ); | 
|---|
|  | 260 | FImages:= NewValue; | 
|---|
|  | 261 | If FImages <> Nil Then | 
|---|
|  | 262 | FImages.FreeNotification( Self ); | 
|---|
|  | 263 | Invalidate; | 
|---|
|  | 264 | End; | 
|---|
|  | 265 |  | 
|---|
|  | 266 | Procedure TCoolBar2.SetShowText( NewValue: boolean ); | 
|---|
|  | 267 | begin | 
|---|
|  | 268 | If NewValue = FShowText Then | 
|---|
|  | 269 | exit; | 
|---|
|  | 270 | FShowText := NewValue; | 
|---|
|  | 271 | Invalidate; | 
|---|
|  | 272 | end; | 
|---|
|  | 273 |  | 
|---|
|  | 274 | Procedure TCoolBar2.SetShowImages( NewValue: boolean ); | 
|---|
|  | 275 | begin | 
|---|
|  | 276 | If NewValue = FShowImages Then | 
|---|
|  | 277 | exit; | 
|---|
|  | 278 | FShowImages := NewValue; | 
|---|
|  | 279 | Invalidate; | 
|---|
|  | 280 | end; | 
|---|
|  | 281 |  | 
|---|
|  | 282 | Procedure TCoolBar2.SetMinConstButtonWidth; | 
|---|
|  | 283 | var | 
|---|
|  | 284 | i: longint; | 
|---|
|  | 285 | TextWidth: longint; | 
|---|
|  | 286 | ImageWidth: longint; | 
|---|
|  | 287 | Section: TCoolSection2; | 
|---|
|  | 288 | Bitmap: TBitmap; | 
|---|
|  | 289 | ButtonWidth: longint; | 
|---|
|  | 290 | begin | 
|---|
|  | 291 | if Handle = 0 then | 
|---|
|  | 292 | exit; | 
|---|
|  | 293 |  | 
|---|
|  | 294 | ButtonWidth := 0; | 
|---|
|  | 295 |  | 
|---|
|  | 296 | for i := 0 to Sections.Count - 1 do | 
|---|
|  | 297 | begin | 
|---|
|  | 298 | Section := Sections[ i ]; | 
|---|
|  | 299 |  | 
|---|
|  | 300 | TextWidth :=  0; | 
|---|
|  | 301 |  | 
|---|
|  | 302 | if FShowText then | 
|---|
|  | 303 | TextWidth := Canvas.TextWidth( Section.Text ); | 
|---|
|  | 304 |  | 
|---|
|  | 305 | ImageWidth := 0; | 
|---|
|  | 306 |  | 
|---|
|  | 307 | if     ( FImages <> nil ) | 
|---|
|  | 308 | and FShowImages then | 
|---|
|  | 309 | begin | 
|---|
|  | 310 | if Section.Image < FImages.Count then | 
|---|
|  | 311 | begin | 
|---|
|  | 312 | Bitmap := FImages.GetBitmapReference( Section.Image ); | 
|---|
|  | 313 | ImageWidth := Bitmap.Width; | 
|---|
|  | 314 | end; | 
|---|
|  | 315 | end; | 
|---|
|  | 316 |  | 
|---|
|  | 317 | if TextWidth > ButtonWidth then | 
|---|
|  | 318 | ButtonWidth := TextWidth; | 
|---|
|  | 319 | if ImageWidth > ButtonWidth then | 
|---|
|  | 320 | ButtonWidth := ImageWidth; | 
|---|
|  | 321 | end; | 
|---|
|  | 322 |  | 
|---|
|  | 323 | inc( ButtonWidth, 8 ); // allow for borders etc | 
|---|
|  | 324 |  | 
|---|
|  | 325 | for i := 0 to Sections.Count - 1 do | 
|---|
|  | 326 | begin | 
|---|
|  | 327 | Section := Sections[ i ]; | 
|---|
|  | 328 | Section.Width := ButtonWidth; | 
|---|
|  | 329 | end; | 
|---|
|  | 330 |  | 
|---|
|  | 331 | end; | 
|---|
|  | 332 |  | 
|---|
|  | 333 | Procedure TCoolBar2.Notification( AComponent: TComponent; | 
|---|
|  | 334 | Operation: TOperation ); | 
|---|
|  | 335 | Begin | 
|---|
|  | 336 | Inherited Notification( AComponent, Operation ); | 
|---|
|  | 337 |  | 
|---|
|  | 338 | If Operation = opRemove Then | 
|---|
|  | 339 | If AComponent = FImages Then | 
|---|
|  | 340 | FImages := Nil; | 
|---|
|  | 341 | End; | 
|---|
|  | 342 |  | 
|---|
|  | 343 |  | 
|---|
|  | 344 | Procedure TCoolBar2.SetBackgroundBitmap(NewValue:TBitmap); | 
|---|
|  | 345 | Begin | 
|---|
|  | 346 | If NewValue=FBackgroundBitmap Then exit; | 
|---|
|  | 347 | If FBackgroundBitmap<>Nil Then FBackgroundBitmap.Destroy; | 
|---|
|  | 348 | If NewValue<>Nil Then FBackgroundBitmap:=NewValue.Copy | 
|---|
|  | 349 | Else FBackgroundBitmap:=Nil; | 
|---|
|  | 350 | Invalidate; | 
|---|
|  | 351 | End; | 
|---|
|  | 352 |  | 
|---|
|  | 353 | Procedure TCoolBar2.SetBackgroundOffset(NewValue:LongWord); | 
|---|
|  | 354 | Begin | 
|---|
|  | 355 | If NewValue=FBackgroundOffset Then exit; | 
|---|
|  | 356 | FBackgroundOffset:=NewValue; | 
|---|
|  | 357 | Invalidate; | 
|---|
|  | 358 | End; | 
|---|
|  | 359 |  | 
|---|
|  | 360 | Procedure TCoolBar2.DrawSection(Section:TCoolSection2;Const rc:TRect;Pressed,Hot,Enabled:Boolean); | 
|---|
|  | 361 | Var | 
|---|
|  | 362 | Align:TAlignment; | 
|---|
|  | 363 | S:String; | 
|---|
|  | 364 | CX,CY,CX1,CY1,H,X,Y:LongInt; | 
|---|
|  | 365 | rec:TRect; | 
|---|
|  | 366 | PointsArray:Array[0..5] Of TPoint; | 
|---|
|  | 367 | offs:LongInt; | 
|---|
|  | 368 | Bitmap,Mask:TBitmap; | 
|---|
|  | 369 | bevelrc: TRect; | 
|---|
|  | 370 | bgrc: TRect; | 
|---|
|  | 371 |  | 
|---|
|  | 372 | HaveText: boolean; | 
|---|
|  | 373 | HaveImage: boolean; | 
|---|
|  | 374 |  | 
|---|
|  | 375 | Procedure DrawMasked(Bitmap,Mask:TBitmap;X,Y:LongInt); | 
|---|
|  | 376 | Var Source,Dest:TRect; | 
|---|
|  | 377 | Begin | 
|---|
|  | 378 | If Bitmap=Nil Then exit; | 
|---|
|  | 379 | Source.Left:=0; | 
|---|
|  | 380 | Source.Bottom:=0; | 
|---|
|  | 381 | Dest.Left:=X; | 
|---|
|  | 382 | Dest.Bottom:=Y; | 
|---|
|  | 383 |  | 
|---|
|  | 384 | If Mask<>Nil Then | 
|---|
|  | 385 | Begin | 
|---|
|  | 386 | Source.Right:=Mask.Width; | 
|---|
|  | 387 | Source.Top:=Mask.Height; | 
|---|
|  | 388 | Dest.Top:=Dest.Bottom+Mask.Height; | 
|---|
|  | 389 | Dest.Right:=Dest.Left+Mask.Width; | 
|---|
|  | 390 | Mask.Canvas.BitBlt(Canvas,Dest,Source,cmSrcAnd,bitfIgnore); | 
|---|
|  | 391 | End; | 
|---|
|  | 392 |  | 
|---|
|  | 393 | Source.Right:=Bitmap.Width; | 
|---|
|  | 394 | Source.Top:=Bitmap.Height; | 
|---|
|  | 395 | Dest.Top:=Dest.Bottom+Bitmap.Height; | 
|---|
|  | 396 | Dest.Right:=Dest.Left+Bitmap.Width; | 
|---|
|  | 397 | If Mask<>Nil Then | 
|---|
|  | 398 | Bitmap.Canvas.BitBlt(Canvas,Dest,Source,cmSrcPaint,bitfIgnore) | 
|---|
|  | 399 | Else | 
|---|
|  | 400 | Bitmap.Canvas.BitBlt(Canvas,Dest,Source,cmSrcCopy,bitfIgnore); | 
|---|
|  | 401 |  | 
|---|
|  | 402 | //        Canvas.ExcludeClipRect(Dest); | 
|---|
|  | 403 | End; | 
|---|
|  | 404 |  | 
|---|
|  | 405 | Procedure DestroyIfEmpty( Var Bitmap: TBitmap ); | 
|---|
|  | 406 | Begin | 
|---|
|  | 407 | If Bitmap<>Nil Then | 
|---|
|  | 408 | Begin | 
|---|
|  | 409 | If Bitmap.Empty Then | 
|---|
|  | 410 | begin | 
|---|
|  | 411 | Bitmap.Destroy; | 
|---|
|  | 412 | Bitmap := Nil; | 
|---|
|  | 413 | End; | 
|---|
|  | 414 | End; | 
|---|
|  | 415 | End; | 
|---|
|  | 416 |  | 
|---|
|  | 417 | Begin | 
|---|
|  | 418 | Align:=section.Alignment; | 
|---|
|  | 419 | S:=section.Text; | 
|---|
|  | 420 |  | 
|---|
|  | 421 | HaveText :=     ( S <> '' ) | 
|---|
|  | 422 | and FShowText; | 
|---|
|  | 423 | If not HaveText Then | 
|---|
|  | 424 | Begin | 
|---|
|  | 425 | CX:=0; | 
|---|
|  | 426 | CY:=0; | 
|---|
|  | 427 | End | 
|---|
|  | 428 | Else Canvas.GetTextExtent(S,CX,CY); | 
|---|
|  | 429 |  | 
|---|
|  | 430 | // First get or generate bitmap to draw. | 
|---|
|  | 431 |  | 
|---|
|  | 432 | Bitmap := Nil; | 
|---|
|  | 433 | Mask := Nil; | 
|---|
|  | 434 |  | 
|---|
|  | 435 | If     ( FImages <> Nil ) | 
|---|
|  | 436 | and FShowImages Then | 
|---|
|  | 437 | Begin | 
|---|
|  | 438 | If FImages.Count>0 Then | 
|---|
|  | 439 | Begin | 
|---|
|  | 440 | If not Enabled Then | 
|---|
|  | 441 | Begin | 
|---|
|  | 442 | If Section.DisabledImage>=0 Then | 
|---|
|  | 443 | begin | 
|---|
|  | 444 | If FImages.Count>Section.DisabledImage Then | 
|---|
|  | 445 | Begin | 
|---|
|  | 446 | Bitmap := TBitmap.Create; | 
|---|
|  | 447 | FImages.GetBitmap(Section.DisabledImage,Bitmap); | 
|---|
|  | 448 | Mask  := TBitmap.Create; | 
|---|
|  | 449 | Images.GetMask(Section.DisabledImage,Mask); | 
|---|
|  | 450 | End; | 
|---|
|  | 451 | end | 
|---|
|  | 452 | else | 
|---|
|  | 453 | begin | 
|---|
|  | 454 | Bitmap := TBitmap.Create; | 
|---|
|  | 455 | FImages.GetBitmap(Section.Image,Bitmap); | 
|---|
|  | 456 | Mask  := TBitmap.Create; | 
|---|
|  | 457 | FImages.GetMask(Section.Image,Mask); | 
|---|
|  | 458 | Y:= 0; | 
|---|
|  | 459 | while Y < Mask.Height do | 
|---|
|  | 460 | begin | 
|---|
|  | 461 | X:= 0; | 
|---|
|  | 462 | if ( Y mod 2 ) = 1 then | 
|---|
|  | 463 | X:= 1; | 
|---|
|  | 464 | while X < Mask.Width do | 
|---|
|  | 465 | begin | 
|---|
|  | 466 | Mask.Canvas.Pixels[ X, Y ]:= clBlack; | 
|---|
|  | 467 | Bitmap.Canvas.Pixels[ X, Y ]:= clBlack; | 
|---|
|  | 468 | inc( X, 2 ); | 
|---|
|  | 469 | end; | 
|---|
|  | 470 | inc( Y, 1 ); | 
|---|
|  | 471 | end; | 
|---|
|  | 472 | end; | 
|---|
|  | 473 | End | 
|---|
|  | 474 | Else If Hot Then | 
|---|
|  | 475 | Begin | 
|---|
|  | 476 | If Section.HotImage>=0 Then | 
|---|
|  | 477 | If Section.HotImage < FImages.Count Then | 
|---|
|  | 478 | Begin | 
|---|
|  | 479 | Bitmap := TBitmap.Create; | 
|---|
|  | 480 | FImages.GetBitmap(Section.HotImage,Bitmap); | 
|---|
|  | 481 | Mask := TBitmap.Create; | 
|---|
|  | 482 | FImages.GetMask(Section.HotImage,Mask); | 
|---|
|  | 483 | End; | 
|---|
|  | 484 | End; | 
|---|
|  | 485 |  | 
|---|
|  | 486 | DestroyIfEmpty( Bitmap ); | 
|---|
|  | 487 | DestroyIfEmpty( Mask ); | 
|---|
|  | 488 |  | 
|---|
|  | 489 | If Bitmap=Nil Then | 
|---|
|  | 490 | Begin | 
|---|
|  | 491 | If Section.Image>=0 Then | 
|---|
|  | 492 | If FImages.Count>Section.Image Then | 
|---|
|  | 493 | Begin | 
|---|
|  | 494 | Bitmap := TBitmap.Create; | 
|---|
|  | 495 | FImages.GetBitmap(Section.Image,Bitmap); | 
|---|
|  | 496 | Mask := TBitmap.Create; | 
|---|
|  | 497 | FImages.GetMask(Section.Image,Mask); | 
|---|
|  | 498 | End; | 
|---|
|  | 499 | End; | 
|---|
|  | 500 |  | 
|---|
|  | 501 | DestroyIfEmpty( Bitmap ); | 
|---|
|  | 502 | DestroyIfEmpty( Mask ); | 
|---|
|  | 503 | End; | 
|---|
|  | 504 | End; | 
|---|
|  | 505 |  | 
|---|
|  | 506 | CX1:=CX; | 
|---|
|  | 507 | CY1:=CY; | 
|---|
|  | 508 |  | 
|---|
|  | 509 | HaveImage := Bitmap <> Nil; | 
|---|
|  | 510 |  | 
|---|
|  | 511 | If HaveImage Then | 
|---|
|  | 512 | Begin | 
|---|
|  | 513 | If Align=taCenter Then | 
|---|
|  | 514 | inc(CY1,Bitmap.Height) | 
|---|
|  | 515 | Else | 
|---|
|  | 516 | inc(CX1,Bitmap.Width); | 
|---|
|  | 517 |  | 
|---|
|  | 518 | If HaveText Then | 
|---|
|  | 519 | // space between | 
|---|
|  | 520 | If Align=taCenter Then | 
|---|
|  | 521 | inc(CY1,3) | 
|---|
|  | 522 | Else | 
|---|
|  | 523 | inc(CX1,3); | 
|---|
|  | 524 | End; | 
|---|
|  | 525 |  | 
|---|
|  | 526 | Case Align Of | 
|---|
|  | 527 | taLeftJustify: | 
|---|
|  | 528 | Begin | 
|---|
|  | 529 | H:=rc.Right-rc.Left; | 
|---|
|  | 530 | rec.Left:=rc.Left+((H-CX1) Div 2); | 
|---|
|  | 531 | End; | 
|---|
|  | 532 | taRightJustify: | 
|---|
|  | 533 | Begin | 
|---|
|  | 534 | H:=rc.Right-rc.Left; | 
|---|
|  | 535 | rec.Left:=rc.Left+((H-CX1) Div 2); | 
|---|
|  | 536 | If Bitmap<>Nil Then inc(rec.Left,Bitmap.Width); | 
|---|
|  | 537 | End | 
|---|
|  | 538 | Else //taCenter | 
|---|
|  | 539 | Begin | 
|---|
|  | 540 | H:=rc.Right-rc.Left; | 
|---|
|  | 541 | rec.Left:=rc.Left+((H-CX) Div 2); | 
|---|
|  | 542 | End; | 
|---|
|  | 543 | End; //Case | 
|---|
|  | 544 |  | 
|---|
|  | 545 | If rec.Left<rc.Left+3 Then rec.Left:=rc.Left+3; | 
|---|
|  | 546 |  | 
|---|
|  | 547 | H:=rc.Top-rc.Bottom; | 
|---|
|  | 548 | rec.Bottom:=rc.Bottom+((H-CY1) Div 2); | 
|---|
|  | 549 | If rec.Bottom<rc.Bottom+3 Then rec.Bottom:=rc.Bottom+3; | 
|---|
|  | 550 | rec.Right:=rec.Left+CX-1; | 
|---|
|  | 551 | rec.Top:=rec.Bottom+CY-1; | 
|---|
|  | 552 |  | 
|---|
|  | 553 | // Draw background | 
|---|
|  | 554 | bgrc:= rc; | 
|---|
|  | 555 | If ((not Flat)Or(Hot And Enabled)) Then | 
|---|
|  | 556 | InflateRect( bgrc, | 
|---|
|  | 557 | - ( 1 + BevelWidth ), | 
|---|
|  | 558 | - ( 1 + BevelWidth ) ); | 
|---|
|  | 559 |  | 
|---|
|  | 560 | if Pressed then | 
|---|
|  | 561 | DrawBackground( bgrc, 1, -1 ) | 
|---|
|  | 562 | else | 
|---|
|  | 563 | DrawBackground( bgrc, 0, 0 ); | 
|---|
|  | 564 |  | 
|---|
|  | 565 | // Draw Bitmap | 
|---|
|  | 566 | If Bitmap<>Nil Then | 
|---|
|  | 567 | Begin | 
|---|
|  | 568 | H:=rc.Top-rc.Bottom; | 
|---|
|  | 569 | Y:=rc.Bottom+((H-CY1) Div 2); | 
|---|
|  | 570 | If Y<rc.Bottom+3 Then Y:=rc.Bottom+3; | 
|---|
|  | 571 |  | 
|---|
|  | 572 | Canvas.Pen.Color:= clBlack; | 
|---|
|  | 573 | Case Align Of | 
|---|
|  | 574 | taLeftJustify: | 
|---|
|  | 575 | Begin | 
|---|
|  | 576 | DrawMasked(Bitmap,Mask,rec.Right+3,Y); | 
|---|
|  | 577 | End; | 
|---|
|  | 578 | taRightJustify: | 
|---|
|  | 579 | Begin | 
|---|
|  | 580 | DrawMasked(Bitmap,Mask,rec.Left-3-Bitmap.Width,Y); | 
|---|
|  | 581 | End; | 
|---|
|  | 582 | Else //taCenter | 
|---|
|  | 583 | Begin | 
|---|
|  | 584 | H:=rc.Right-rc.Left; | 
|---|
|  | 585 | X:=rc.Left+((H-Bitmap.Width) Div 2); | 
|---|
|  | 586 | If X<rc.Left+3 Then X:=rc.Left+3; | 
|---|
|  | 587 | if Pressed then | 
|---|
|  | 588 | begin | 
|---|
|  | 589 | inc( X ); | 
|---|
|  | 590 | dec( Y ); | 
|---|
|  | 591 | end; | 
|---|
|  | 592 | if HaveText then | 
|---|
|  | 593 | inc( Y, 3 ); | 
|---|
|  | 594 | DrawMasked(Bitmap,Mask,X,Y+CY); | 
|---|
|  | 595 | End; | 
|---|
|  | 596 | End; //Case | 
|---|
|  | 597 |  | 
|---|
|  | 598 | Bitmap.Destroy; | 
|---|
|  | 599 | If Mask<>Nil Then Mask.Destroy; | 
|---|
|  | 600 | End; | 
|---|
|  | 601 |  | 
|---|
|  | 602 | // Draw text | 
|---|
|  | 603 | If     ( S <> '' ) | 
|---|
|  | 604 | And FShowText Then | 
|---|
|  | 605 | Begin | 
|---|
|  | 606 | Canvas.Brush.Mode:=bmTransparent; | 
|---|
|  | 607 | If not Enabled Then | 
|---|
|  | 608 | Canvas.Pen.Color:=clDkGray | 
|---|
|  | 609 | Else if Hot then | 
|---|
|  | 610 | Canvas.Pen.Color:= FHotColor | 
|---|
|  | 611 | else | 
|---|
|  | 612 | Canvas.Pen.Color:=PenColor; | 
|---|
|  | 613 |  | 
|---|
|  | 614 | if Pressed then | 
|---|
|  | 615 | Canvas.TextOut(rec.Left+1,rec.Bottom-1,S) | 
|---|
|  | 616 | else | 
|---|
|  | 617 | Canvas.TextOut(rec.Left,rec.Bottom,S); | 
|---|
|  | 618 | Canvas.Brush.Mode:=bmOpaque; | 
|---|
|  | 619 |  | 
|---|
|  | 620 | //        Canvas.ExcludeClipRect(rec); | 
|---|
|  | 621 | End; | 
|---|
|  | 622 |  | 
|---|
|  | 623 | If ((not Flat)Or(Hot And Enabled)) Then | 
|---|
|  | 624 | Begin | 
|---|
|  | 625 | // draw button outline | 
|---|
|  | 626 | Canvas.Pen.Color:= clBlack; | 
|---|
|  | 627 | Canvas.Rectangle( rc ); | 
|---|
|  | 628 | bevelrc:= rc; | 
|---|
|  | 629 | InflateRect( bevelrc, -1, -1 ); | 
|---|
|  | 630 | If BevelWidth > 1 Then | 
|---|
|  | 631 | Begin | 
|---|
|  | 632 | offs := BevelWidth-1; | 
|---|
|  | 633 | PointsArray[0] := Point(bevelrc.Left,bevelrc.Bottom); | 
|---|
|  | 634 | PointsArray[1] := Point(bevelrc.Left+offs,bevelrc.Bottom+offs); | 
|---|
|  | 635 | PointsArray[2] := Point(bevelrc.Left+offs,bevelrc.Top-offs); | 
|---|
|  | 636 | PointsArray[3] := Point(bevelrc.Right-offs,bevelrc.Top-offs); | 
|---|
|  | 637 | PointsArray[4] := Point(bevelrc.Right,bevelrc.Top); | 
|---|
|  | 638 | PointsArray[5] := Point(bevelrc.Left,bevelrc.Top); | 
|---|
|  | 639 | if Pressed then | 
|---|
|  | 640 | Canvas.Pen.color := clDkGray | 
|---|
|  | 641 | else | 
|---|
|  | 642 | Canvas.Pen.color := clWhite; | 
|---|
|  | 643 | Canvas.Polygon(PointsArray); | 
|---|
|  | 644 | PointsArray[2] := Point(bevelrc.Right-offs,bevelrc.Bottom+offs); | 
|---|
|  | 645 | PointsArray[3] := Point(bevelrc.Right-offs,bevelrc.Top-offs); | 
|---|
|  | 646 | PointsArray[4] := Point(bevelrc.Right,bevelrc.Top); | 
|---|
|  | 647 | PointsArray[5] := Point(bevelrc.Right,bevelrc.Bottom); | 
|---|
|  | 648 | if Pressed then | 
|---|
|  | 649 | Canvas.Pen.color := clWhite | 
|---|
|  | 650 | else | 
|---|
|  | 651 | Canvas.Pen.color := clDkGray; | 
|---|
|  | 652 | Canvas.Polygon(PointsArray); | 
|---|
|  | 653 | Canvas.Pen.color:=PenColor; | 
|---|
|  | 654 | End | 
|---|
|  | 655 | Else | 
|---|
|  | 656 | if Pressed then | 
|---|
|  | 657 | Canvas.ShadowedBorder(bevelrc,clDkGray,clWhite) | 
|---|
|  | 658 | else | 
|---|
|  | 659 | Canvas.ShadowedBorder(bevelrc,clWhite,clDkGray); | 
|---|
|  | 660 | End; | 
|---|
|  | 661 | End; | 
|---|
|  | 662 |  | 
|---|
|  | 663 | Type | 
|---|
|  | 664 | PHeaderItem=^THeaderItem; | 
|---|
|  | 665 | THeaderItem=Record | 
|---|
|  | 666 | Image:LongInt; | 
|---|
|  | 667 | HotImage:LongInt; | 
|---|
|  | 668 | DisabledImage:LongInt; | 
|---|
|  | 669 | Disabled:Boolean; | 
|---|
|  | 670 | End; | 
|---|
|  | 671 |  | 
|---|
|  | 672 | Const rnCoolHeaders='rnCoolHeaders'; | 
|---|
|  | 673 |  | 
|---|
|  | 674 | Procedure TCoolBar2.ReadSCUResource(Const ResName:TResourceName;Var Data;DataLen:LongInt); | 
|---|
|  | 675 | Var | 
|---|
|  | 676 | Count:^LongInt; | 
|---|
|  | 677 | Items:PHeaderItem; | 
|---|
|  | 678 | section:TCoolSection2; | 
|---|
|  | 679 | T:LongInt; | 
|---|
|  | 680 | Begin | 
|---|
|  | 681 | If ResName = rnCoolHeaders Then | 
|---|
|  | 682 | Begin | 
|---|
|  | 683 | Count:=@Data; | 
|---|
|  | 684 | Items:=@Data; | 
|---|
|  | 685 | Inc(Items,4); | 
|---|
|  | 686 | For T:=1 To Count^ Do | 
|---|
|  | 687 | Begin | 
|---|
|  | 688 | Section:=TCoolSection2(Sections[t-1]); | 
|---|
|  | 689 | section.Image:=Items^.Image; | 
|---|
|  | 690 | section.HotImage:=Items^.HotImage; | 
|---|
|  | 691 | section.DisabledImage:=Items^.DisabledImage; | 
|---|
|  | 692 | section.Disabled:=Items^.Disabled; | 
|---|
|  | 693 | Inc(Items,SizeOf(THeaderItem)); | 
|---|
|  | 694 | End; | 
|---|
|  | 695 | End | 
|---|
|  | 696 | Else Inherited ReadSCUResource(ResName,Data,DataLen); | 
|---|
|  | 697 | End; | 
|---|
|  | 698 |  | 
|---|
|  | 699 |  | 
|---|
|  | 700 | Function TCoolBar2.WriteSCUResource(Stream:TResourceStream):Boolean; | 
|---|
|  | 701 | Var MemStream:TMemoryStream; | 
|---|
|  | 702 | T:LongInt; | 
|---|
|  | 703 | Item:THeaderItem; | 
|---|
|  | 704 | section:TCoolSection2; | 
|---|
|  | 705 | Begin | 
|---|
|  | 706 | Result := Inherited WriteSCUResource(Stream); | 
|---|
|  | 707 | If Not Result Then Exit; | 
|---|
|  | 708 |  | 
|---|
|  | 709 | If Sections<>Nil Then If Sections.Count>0 Then | 
|---|
|  | 710 | Begin | 
|---|
|  | 711 | MemStream.Create; | 
|---|
|  | 712 | T:=Sections.Count; | 
|---|
|  | 713 | MemStream.Write(T,4); | 
|---|
|  | 714 | For T:=0 To Sections.Count-1 Do | 
|---|
|  | 715 | Begin | 
|---|
|  | 716 | section:=TCoolSection2(Sections[T]); | 
|---|
|  | 717 | Item.Image:=section.Image; | 
|---|
|  | 718 | Item.HotImage:=section.HotImage; | 
|---|
|  | 719 | Item.DisabledImage:=section.DisabledImage; | 
|---|
|  | 720 | Item.Disabled:=section.Disabled; | 
|---|
|  | 721 | MemStream.Write(Item,SizeOf(THeaderItem)); | 
|---|
|  | 722 | End; | 
|---|
|  | 723 |  | 
|---|
|  | 724 | Result:=Stream.NewResourceEntry(rnCoolHeaders,MemStream.Memory^,MemStream.Size); | 
|---|
|  | 725 | MemStream.Destroy; | 
|---|
|  | 726 | End; | 
|---|
|  | 727 | End; | 
|---|
|  | 728 |  | 
|---|
|  | 729 | Procedure TCoolbar2.DrawBackground( rec: TRect; | 
|---|
|  | 730 | XOffset, YOffset: longint ); | 
|---|
|  | 731 | var | 
|---|
|  | 732 | X: longint; | 
|---|
|  | 733 | Y: longint; | 
|---|
|  | 734 | DrawRect: TRect; | 
|---|
|  | 735 | SourceRect: TRect; | 
|---|
|  | 736 | BlockWidth: longint; | 
|---|
|  | 737 | BlockHeight: longint; | 
|---|
|  | 738 | BitmapX: longint; | 
|---|
|  | 739 | BitmapY: longint; | 
|---|
|  | 740 | begin | 
|---|
|  | 741 | If FBackgroundBitmap=Nil Then | 
|---|
|  | 742 | begin | 
|---|
|  | 743 | Canvas.FillRect( rec, Color ); | 
|---|
|  | 744 | exit; | 
|---|
|  | 745 | end; | 
|---|
|  | 746 |  | 
|---|
|  | 747 | Y:= rec.Bottom; | 
|---|
|  | 748 | While Y<=rec.Top Do | 
|---|
|  | 749 | Begin | 
|---|
|  | 750 | BitmapY:= ( Y - YOffset ) mod FBackGroundBitmap.Height; | 
|---|
|  | 751 | if BitmapY < 0 then | 
|---|
|  | 752 | BitmapY:= FBackGroundBitmap.Height + BitmapY; | 
|---|
|  | 753 |  | 
|---|
|  | 754 | BlockHeight:= FBackgroundBitmap.Height - BitmapY; | 
|---|
|  | 755 | if Y + BlockHeight > rec.Top then | 
|---|
|  | 756 | BlockHeight:= rec.Top - Y + 1; | 
|---|
|  | 757 |  | 
|---|
|  | 758 | X:= rec.Left; | 
|---|
|  | 759 | While X<=rec.Right Do | 
|---|
|  | 760 | Begin | 
|---|
|  | 761 | BitmapX:= ( X - XOffset ) mod FBackgroundBitmap.Width; | 
|---|
|  | 762 | if BitmapX < 0 then | 
|---|
|  | 763 | BitmapX:= FBackgroundBitmap.Width + BitmapX; | 
|---|
|  | 764 |  | 
|---|
|  | 765 | BlockWidth:= FBackgroundBitmap.Width - BitmapX; | 
|---|
|  | 766 | if X + BlockWidth > rec.Right then | 
|---|
|  | 767 | BlockWidth:= rec.Right - X + 1; | 
|---|
|  | 768 |  | 
|---|
|  | 769 | DrawRect.Left:= X; | 
|---|
|  | 770 | DrawRect.Right:= X + BlockWidth; | 
|---|
|  | 771 | DrawRect.Bottom:= Y; | 
|---|
|  | 772 | DrawRect.Top:= Y + BlockHeight; | 
|---|
|  | 773 |  | 
|---|
|  | 774 | SourceRect.Left:= BitmapX; | 
|---|
|  | 775 | SourceRect.Right:= BitmapX + BlockWidth; | 
|---|
|  | 776 | SourceRect.Bottom:= BitmapY; | 
|---|
|  | 777 | SourceRect.Top:= BitmapY + BlockHeight; | 
|---|
|  | 778 |  | 
|---|
|  | 779 | FBackgroundBitmap.PartialDraw( Canvas, | 
|---|
|  | 780 | SourceRect, | 
|---|
|  | 781 | DrawRect ); | 
|---|
|  | 782 | inc( X, BlockWidth ); | 
|---|
|  | 783 | End; | 
|---|
|  | 784 | inc( Y, BlockHeight ); | 
|---|
|  | 785 | End; | 
|---|
|  | 786 | end; | 
|---|
|  | 787 |  | 
|---|
|  | 788 | Procedure TCoolBar2.Redraw(Const rec:TRect); | 
|---|
|  | 789 | Var rc,rc2:TRect; | 
|---|
|  | 790 | FSections:TCoolSections2; | 
|---|
|  | 791 | Section:TCoolSection2; | 
|---|
|  | 792 | IsPressed:Boolean; | 
|---|
|  | 793 | t:LongInt; | 
|---|
|  | 794 | Begin | 
|---|
|  | 795 | Canvas.ClipRect:=rec; | 
|---|
|  | 796 |  | 
|---|
|  | 797 | Canvas.Pen.Color:= clDkGray; | 
|---|
|  | 798 | Canvas.Line( 0, 0, Width -1, 0 ); | 
|---|
|  | 799 | //    Canvas.Pen.Color:= cl3dLight; | 
|---|
|  | 800 | //    Canvas.Line( 0, 0, Width -1, 0 ); | 
|---|
|  | 801 |  | 
|---|
|  | 802 | FSections:=TCoolSections2(Sections); | 
|---|
|  | 803 | rc:=ClientRect; | 
|---|
|  | 804 | Inc(rc.Bottom,1); | 
|---|
|  | 805 | For T:=0 To FSections.Count-1 Do | 
|---|
|  | 806 | Begin | 
|---|
|  | 807 | Section:=TCoolSection2(FSections[T]); | 
|---|
|  | 808 | rc.Right:=rc.Left+section.Width; | 
|---|
|  | 809 | If rc.Right>Width-1 Then rc.Right:=Width-1; | 
|---|
|  | 810 |  | 
|---|
|  | 811 | IsPressed:=Section=ClickSection; | 
|---|
|  | 812 |  | 
|---|
|  | 813 | rc2:=Forms.IntersectRect(rc,rec); | 
|---|
|  | 814 | If Not Forms.IsRectEmpty(rc2) Then | 
|---|
|  | 815 | Begin | 
|---|
|  | 816 | Canvas.ClipRect:=rc2; | 
|---|
|  | 817 |  | 
|---|
|  | 818 | If ( Section.Style=hsOwnerDraw ) | 
|---|
|  | 819 | and ( OnDrawSection<>Nil ) Then | 
|---|
|  | 820 | OnDrawSection(Self,section,rc,IsPressed,Section=FActiveSection,Section.Disabled=False) | 
|---|
|  | 821 | Else | 
|---|
|  | 822 | DrawSection(section,rc,IsPressed,Section=FActiveSection,Section.Disabled=False); | 
|---|
|  | 823 | End; | 
|---|
|  | 824 |  | 
|---|
|  | 825 | // draw space between this button and next | 
|---|
|  | 826 | rc2:= rc; | 
|---|
|  | 827 | rc2.Left:= rc.Right + 1; | 
|---|
|  | 828 | rc2.Right:= rc2.Left + Spacing - 1; | 
|---|
|  | 829 | rc2:=Forms.IntersectRect(rc2,rec); | 
|---|
|  | 830 |  | 
|---|
|  | 831 | If Not Forms.IsRectEmpty(rc2) Then | 
|---|
|  | 832 | Begin | 
|---|
|  | 833 | Canvas.ClipRect:=rc2; | 
|---|
|  | 834 | DrawBackGround( rc2, 0, 0 ); | 
|---|
|  | 835 | end; | 
|---|
|  | 836 |  | 
|---|
|  | 837 | Inc(rc.Left,Section.Width+Spacing+1); | 
|---|
|  | 838 | End; | 
|---|
|  | 839 |  | 
|---|
|  | 840 | rc.Right:= Width-1; | 
|---|
|  | 841 | rc2:=Forms.IntersectRect(rc,rec); | 
|---|
|  | 842 | If Not Forms.IsRectEmpty(rc2) Then | 
|---|
|  | 843 | Begin | 
|---|
|  | 844 | inc(rc2.Right); | 
|---|
|  | 845 | Canvas.ClipRect:=rc2; | 
|---|
|  | 846 | DrawBackground( rc, 0, 0 ); | 
|---|
|  | 847 | end; | 
|---|
|  | 848 | Canvas.DeleteClipRegion; | 
|---|
|  | 849 | End; | 
|---|
|  | 850 |  | 
|---|
|  | 851 | Procedure TCoolBar2.MouseDown(Button:TMouseButton;ShiftState:TShiftState;X,Y:LongInt); | 
|---|
|  | 852 | Var T:LongInt; | 
|---|
|  | 853 | section:TCoolSection2; | 
|---|
|  | 854 | FSections:TCoolSections2; | 
|---|
|  | 855 | Begin | 
|---|
|  | 856 | TControl.MouseDown(Button,ShiftState,X,Y); | 
|---|
|  | 857 |  | 
|---|
|  | 858 | If Button <> mbLeft Then Exit; | 
|---|
|  | 859 |  | 
|---|
|  | 860 | FSections:=TCoolSections2(Sections); | 
|---|
|  | 861 | For T:=0 To FSections.Count-1 Do | 
|---|
|  | 862 | Begin | 
|---|
|  | 863 | section:=TCoolSection2(FSections[T]); | 
|---|
|  | 864 | If ((section.AllowSize)And(X>section.Right-2)And(X<section.Right+2)) Then | 
|---|
|  | 865 | Begin | 
|---|
|  | 866 | Inherited MouseDown(Button,ShiftState,X,Y); | 
|---|
|  | 867 | exit; | 
|---|
|  | 868 | End; | 
|---|
|  | 869 | End; | 
|---|
|  | 870 |  | 
|---|
|  | 871 | If Designed Then Exit; | 
|---|
|  | 872 |  | 
|---|
|  | 873 | //Test Press | 
|---|
|  | 874 | Section:=TCoolSection2(GetMouseHeader(X,Y)); | 
|---|
|  | 875 | If Section<>Nil Then If section.AllowClick Then If not Section.Disabled Then | 
|---|
|  | 876 | Inherited MouseDown(Button,ShiftState,X,Y); | 
|---|
|  | 877 | End; | 
|---|
|  | 878 |  | 
|---|
|  | 879 | Procedure TCoolBar2.MouseDblClick(Button:TMouseButton;ShiftState:TShiftState;X,Y:LongInt); | 
|---|
|  | 880 | Var section:TCoolSection2; | 
|---|
|  | 881 | Begin | 
|---|
|  | 882 | If Button=mbLeft Then | 
|---|
|  | 883 | Begin | 
|---|
|  | 884 | Section:=TCoolSection2(GetMouseHeader(X,Y)); | 
|---|
|  | 885 | If Section<>Nil Then If section.AllowClick Then If not Section.Disabled Then | 
|---|
|  | 886 | Inherited MouseDblClick(Button,ShiftState,X,Y); | 
|---|
|  | 887 | End | 
|---|
|  | 888 | Else Inherited MouseDblClick(Button,ShiftState,X,Y); | 
|---|
|  | 889 | End; | 
|---|
|  | 890 |  | 
|---|
|  | 891 | Procedure TCoolBar2.UpdateHeader(Header:THeaderSection); | 
|---|
|  | 892 | Var T:LongInt; | 
|---|
|  | 893 | rc:TRect; | 
|---|
|  | 894 | FSections:TCoolSections2; | 
|---|
|  | 895 | Begin | 
|---|
|  | 896 | //Get Rectangle For the Panel | 
|---|
|  | 897 | rc:=ClientRect; | 
|---|
|  | 898 | FSections:=TCoolSections2(Sections); | 
|---|
|  | 899 | For T:=0 To FSections.Count-1 Do | 
|---|
|  | 900 | Begin | 
|---|
|  | 901 | If FSections[T]=Header Then break | 
|---|
|  | 902 | Else Inc(rc.Left,FSections[T].Width+Spacing+1); | 
|---|
|  | 903 | End; | 
|---|
|  | 904 |  | 
|---|
|  | 905 | rc.Right:=rc.Left+Header.Width+1; | 
|---|
|  | 906 | If not Flat Then InflateRect(rc,-BevelWidth*2,-BevelWidth*2); | 
|---|
|  | 907 | InvalidateRect(rc); | 
|---|
|  | 908 | Update; | 
|---|
|  | 909 | End; | 
|---|
|  | 910 |  | 
|---|
|  | 911 |  | 
|---|
|  | 912 | Procedure TCoolBar2.MouseMove(ShiftState:TShiftState;X,Y:LongInt); | 
|---|
|  | 913 | Var | 
|---|
|  | 914 | OldActiveSection:TCoolSection2; | 
|---|
|  | 915 | Begin | 
|---|
|  | 916 | FMouseTimer.Stop; | 
|---|
|  | 917 |  | 
|---|
|  | 918 | OldActiveSection:=FActiveSection; | 
|---|
|  | 919 | FActiveSection:=TCoolSection2(GetMouseHeader(X,Y)); | 
|---|
|  | 920 |  | 
|---|
|  | 921 | if FActiveSection <> nil Then | 
|---|
|  | 922 | if FActiveSection.Disabled Then | 
|---|
|  | 923 | FActiveSection := nil; | 
|---|
|  | 924 |  | 
|---|
|  | 925 | If FActiveSection<>OldActiveSection Then | 
|---|
|  | 926 | Begin | 
|---|
|  | 927 | If FActiveSection <> nil Then | 
|---|
|  | 928 | Hint := FActiveSection.Hint | 
|---|
|  | 929 | Else | 
|---|
|  | 930 | Hint := ''; | 
|---|
|  | 931 | End; | 
|---|
|  | 932 |  | 
|---|
|  | 933 | Inherited MouseMove(ShiftState,X,Y); | 
|---|
|  | 934 |  | 
|---|
|  | 935 | If FActiveSection<>OldActiveSection Then | 
|---|
|  | 936 | Begin | 
|---|
|  | 937 | If OldActiveSection<>Nil Then UpdateHeader(OldActiveSection); | 
|---|
|  | 938 | If FActiveSection<>Nil Then UpdateHeader(FActiveSection); | 
|---|
|  | 939 | End; | 
|---|
|  | 940 |  | 
|---|
|  | 941 | If FFlat Then FMouseTimer.Start; | 
|---|
|  | 942 | End; | 
|---|
|  | 943 |  | 
|---|
|  | 944 |  | 
|---|
|  | 945 | Procedure TCoolBar2.EvFMouseTimer(Sender:TObject); | 
|---|
|  | 946 | Var | 
|---|
|  | 947 | AControl:TControl; | 
|---|
|  | 948 | OldActiveSection:TCoolSection2; | 
|---|
|  | 949 | Begin | 
|---|
|  | 950 | FMouseTimer.Stop; | 
|---|
|  | 951 |  | 
|---|
|  | 952 | AControl := Screen.GetControlFromPoint(Screen.MousePos); | 
|---|
|  | 953 |  | 
|---|
|  | 954 | If AControl <> Self Then | 
|---|
|  | 955 | Begin | 
|---|
|  | 956 | OldActiveSection:=FActiveSection; | 
|---|
|  | 957 | FActiveSection := Nil; | 
|---|
|  | 958 | If OldActiveSection<>Nil Then UpdateHeader(OldActiveSection); | 
|---|
|  | 959 | End | 
|---|
|  | 960 | Else FMouseTimer.Start; | 
|---|
|  | 961 | End; | 
|---|
|  | 962 |  | 
|---|
|  | 963 | Procedure TCoolBar2.EditSections; | 
|---|
|  | 964 | begin | 
|---|
|  | 965 | CallClassPropertyEditor( FSections ); | 
|---|
|  | 966 | end; | 
|---|
|  | 967 |  | 
|---|
|  | 968 | { | 
|---|
|  | 969 | ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» | 
|---|
|  | 970 | º                                                                           º | 
|---|
|  | 971 | º Sibyl Version 2.0                                                         º | 
|---|
|  | 972 | º                                                                           º | 
|---|
|  | 973 | º This section: TCoolSectionsPropertyEditor Class implementation            º | 
|---|
|  | 974 | º                                                                           º | 
|---|
|  | 975 | º                                                                           º | 
|---|
|  | 976 | ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍŒ | 
|---|
|  | 977 | } | 
|---|
|  | 978 |  | 
|---|
|  | 979 | Type | 
|---|
|  | 980 | TCoolSectionsPropertyEditor=Class(TClassPropertyEditor) | 
|---|
|  | 981 | Public | 
|---|
|  | 982 | Function Execute(Var ClassToEdit:TObject):TClassPropertyEditorReturn;Override; | 
|---|
|  | 983 | End; | 
|---|
|  | 984 |  | 
|---|
|  | 985 | TCoolSectionsPropEditDialog=Class(TDialog) | 
|---|
|  | 986 | Private | 
|---|
|  | 987 | FSections:TCoolSections2; | 
|---|
|  | 988 | FListBox:TListBox; | 
|---|
|  | 989 | FText:TEdit; | 
|---|
|  | 990 | FWidth:TEdit; | 
|---|
|  | 991 | FMinWidth,FMaxWidth:TEdit; | 
|---|
|  | 992 | FImage,FHotImage,FDisabledImage:TEdit; | 
|---|
|  | 993 | FStyle:TComboBox; | 
|---|
|  | 994 | FAlignment:TComboBox; | 
|---|
|  | 995 | FAllowClick:TCheckBox; | 
|---|
|  | 996 | FAllowSize:TCheckBox; | 
|---|
|  | 997 | FDisabled:TCheckBox; | 
|---|
|  | 998 | FCurrentSection:TCoolSection2; | 
|---|
|  | 999 | Protected | 
|---|
|  | 1000 | Function GetCurrentSection: TCoolSection2; | 
|---|
|  | 1001 | Procedure SetupComponent;Override; | 
|---|
|  | 1002 | Procedure RefreshListBox; | 
|---|
|  | 1003 | Procedure NewClicked(Sender:TObject); | 
|---|
|  | 1004 | Procedure DeleteClicked(Sender:TObject); | 
|---|
|  | 1005 | Procedure UpdateClicked(Sender:TObject); | 
|---|
|  | 1006 | Procedure MoveUpClicked(Sender:TObject); | 
|---|
|  | 1007 | Procedure MoveDownClicked(Sender:TObject); | 
|---|
|  | 1008 | Procedure ListItemFocus(Sender:TObject;Index:LongInt); | 
|---|
|  | 1009 | Procedure SetupShow; override; | 
|---|
|  | 1010 | Procedure StoreItem; | 
|---|
|  | 1011 | End; | 
|---|
|  | 1012 |  | 
|---|
|  | 1013 | Function TCoolSectionsPropEditDialog.GetCurrentSection: TCoolSection2; | 
|---|
|  | 1014 | begin | 
|---|
|  | 1015 | Result := FCurrentSection; | 
|---|
|  | 1016 | end; | 
|---|
|  | 1017 |  | 
|---|
|  | 1018 | {$HINTS OFF} | 
|---|
|  | 1019 |  | 
|---|
|  | 1020 | Procedure TCoolSectionsPropEditDialog.UpdateClicked(Sender:TObject); | 
|---|
|  | 1021 | Begin | 
|---|
|  | 1022 | StoreItem; | 
|---|
|  | 1023 | FSections.Update(Nil); | 
|---|
|  | 1024 | End; | 
|---|
|  | 1025 |  | 
|---|
|  | 1026 | Procedure TCoolSectionsPropEditDialog.NewClicked(Sender:TObject); | 
|---|
|  | 1027 | Var | 
|---|
|  | 1028 | Section: THeaderSection; | 
|---|
|  | 1029 | Begin | 
|---|
|  | 1030 | StoreItem; | 
|---|
|  | 1031 | Section:= FSections.Add; | 
|---|
|  | 1032 | RefreshListBox; | 
|---|
|  | 1033 | FListBox.ItemIndex:= Section.Index; | 
|---|
|  | 1034 | FText.SetFocus; | 
|---|
|  | 1035 | End; | 
|---|
|  | 1036 |  | 
|---|
|  | 1037 | Procedure TCoolSectionsPropEditDialog.RefreshListBox; | 
|---|
|  | 1038 | Var | 
|---|
|  | 1039 | Index: LongInt; | 
|---|
|  | 1040 | Section: TCoolSection2; | 
|---|
|  | 1041 | Begin | 
|---|
|  | 1042 | FListBox.BeginUpdate; | 
|---|
|  | 1043 | FListBox.Clear; | 
|---|
|  | 1044 | for Index := 0 to FSections.Count - 1 do | 
|---|
|  | 1045 | begin | 
|---|
|  | 1046 | Section := FSections[ Index ]; | 
|---|
|  | 1047 | FListBox.Items.AddObject( ToStr( Index ) | 
|---|
|  | 1048 | + ' - ' | 
|---|
|  | 1049 | + Section.Text, | 
|---|
|  | 1050 | Section ); | 
|---|
|  | 1051 | end; | 
|---|
|  | 1052 | FListBox.EndUpdate; | 
|---|
|  | 1053 |  | 
|---|
|  | 1054 | FSections.Update( Nil ); | 
|---|
|  | 1055 | end; | 
|---|
|  | 1056 |  | 
|---|
|  | 1057 | Procedure TCoolSectionsPropEditDialog.DeleteClicked(Sender:TObject); | 
|---|
|  | 1058 | Var | 
|---|
|  | 1059 | Section: THeaderSection; | 
|---|
|  | 1060 | Index: longint; | 
|---|
|  | 1061 | Begin | 
|---|
|  | 1062 | Section:= GetCurrentSection; | 
|---|
|  | 1063 | Index := Section.Index; | 
|---|
|  | 1064 | Section.Destroy; | 
|---|
|  | 1065 |  | 
|---|
|  | 1066 | FCurrentSection := nil; // so we don't crash in storeitem | 
|---|
|  | 1067 | RefreshListBox; | 
|---|
|  | 1068 |  | 
|---|
|  | 1069 | // Select the next section (now in the same position) | 
|---|
|  | 1070 | // or the previous if we deleted the last item | 
|---|
|  | 1071 | if FSections.Count > 0 then | 
|---|
|  | 1072 | begin | 
|---|
|  | 1073 | if Index < FSections.Count then | 
|---|
|  | 1074 | FListBox.ItemIndex := Index | 
|---|
|  | 1075 | else | 
|---|
|  | 1076 | FListBox.ItemIndex := Index - 1; | 
|---|
|  | 1077 | end; | 
|---|
|  | 1078 | End; | 
|---|
|  | 1079 |  | 
|---|
|  | 1080 | Procedure TCoolSectionsPropEditDialog.MoveUpClicked(Sender:TObject); | 
|---|
|  | 1081 | Var | 
|---|
|  | 1082 | Section: THeaderSection; | 
|---|
|  | 1083 | Index: longint; | 
|---|
|  | 1084 | Begin | 
|---|
|  | 1085 | StoreItem; | 
|---|
|  | 1086 |  | 
|---|
|  | 1087 | Section := GetCurrentSection; | 
|---|
|  | 1088 | If Section = nil Then | 
|---|
|  | 1089 | exit; | 
|---|
|  | 1090 |  | 
|---|
|  | 1091 | Index := Section.Index; | 
|---|
|  | 1092 | if Index <= 0 then | 
|---|
|  | 1093 | // can't move top section up | 
|---|
|  | 1094 | exit; | 
|---|
|  | 1095 | FSections.Swap( Index, Index - 1 ); | 
|---|
|  | 1096 | RefreshListBox; | 
|---|
|  | 1097 | FListBox.ItemIndex := Index - 1; | 
|---|
|  | 1098 | End; | 
|---|
|  | 1099 |  | 
|---|
|  | 1100 | Procedure TCoolSectionsPropEditDialog.MoveDownClicked(Sender:TObject); | 
|---|
|  | 1101 | Var | 
|---|
|  | 1102 | Section: THeaderSection; | 
|---|
|  | 1103 | Index: longint; | 
|---|
|  | 1104 | Begin | 
|---|
|  | 1105 | StoreItem; | 
|---|
|  | 1106 |  | 
|---|
|  | 1107 | Section := GetCurrentSection; | 
|---|
|  | 1108 | If Section = nil Then | 
|---|
|  | 1109 | exit; | 
|---|
|  | 1110 |  | 
|---|
|  | 1111 | Index := Section.Index; | 
|---|
|  | 1112 | if Index >= FSections.Count - 1 then | 
|---|
|  | 1113 | // can't move bottom section down | 
|---|
|  | 1114 | exit; | 
|---|
|  | 1115 | FSections.Swap( Index, Index + 1 ); | 
|---|
|  | 1116 | RefreshListBox; | 
|---|
|  | 1117 | FListBox.ItemIndex := Index + 1; | 
|---|
|  | 1118 | End; | 
|---|
|  | 1119 |  | 
|---|
|  | 1120 | {$HINTS ON} | 
|---|
|  | 1121 |  | 
|---|
|  | 1122 | Procedure TCoolSectionsPropEditDialog.StoreItem; | 
|---|
|  | 1123 | Var | 
|---|
|  | 1124 | c: Integer; | 
|---|
|  | 1125 | i: LongInt; | 
|---|
|  | 1126 | Section: TCoolSection2; | 
|---|
|  | 1127 | Begin | 
|---|
|  | 1128 | Section := GetCurrentSection; | 
|---|
|  | 1129 | if Section = nil then | 
|---|
|  | 1130 | exit; | 
|---|
|  | 1131 |  | 
|---|
|  | 1132 | if FText.Text <> Section.Text then | 
|---|
|  | 1133 | begin | 
|---|
|  | 1134 | // Text has changed, refresh the display | 
|---|
|  | 1135 | Section.Text:= FText.Text; | 
|---|
|  | 1136 | RefreshListBox; | 
|---|
|  | 1137 | FListBox.ItemIndex := Section.Index; | 
|---|
|  | 1138 | end; | 
|---|
|  | 1139 |  | 
|---|
|  | 1140 | VAL(FWidth.Text,i,c); | 
|---|
|  | 1141 | If c<>0 Then | 
|---|
|  | 1142 | i:=100; | 
|---|
|  | 1143 | Section.Width:=i; | 
|---|
|  | 1144 |  | 
|---|
|  | 1145 | VAL(FMinWidth.Text,i,c); | 
|---|
|  | 1146 | If c<>0 Then | 
|---|
|  | 1147 | i:=0; | 
|---|
|  | 1148 | Section.MinWidth:=i; | 
|---|
|  | 1149 |  | 
|---|
|  | 1150 | VAL(FMaxWidth.Text,i,c); | 
|---|
|  | 1151 | If c<>0 Then | 
|---|
|  | 1152 | i:=10000; | 
|---|
|  | 1153 | Section.MaxWidth:=i; | 
|---|
|  | 1154 |  | 
|---|
|  | 1155 | VAL(FImage.Text,i,c); | 
|---|
|  | 1156 | If c<>0 Then | 
|---|
|  | 1157 | i:=10000; | 
|---|
|  | 1158 | Section.Image:=i; | 
|---|
|  | 1159 |  | 
|---|
|  | 1160 | VAL(FHotImage.Text,i,c); | 
|---|
|  | 1161 | If c<>0 Then | 
|---|
|  | 1162 | i:=10000; | 
|---|
|  | 1163 | Section.HotImage:=i; | 
|---|
|  | 1164 |  | 
|---|
|  | 1165 | VAL(FDisabledImage.Text,i,c); | 
|---|
|  | 1166 | If c<>0 Then | 
|---|
|  | 1167 | i:=10000; | 
|---|
|  | 1168 | Section.DisabledImage:=i; | 
|---|
|  | 1169 |  | 
|---|
|  | 1170 | Section.Disabled:=FDisabled.Checked; | 
|---|
|  | 1171 |  | 
|---|
|  | 1172 | If FStyle.Text='OwnerDraw' Then | 
|---|
|  | 1173 | Section.Style:=hsOwnerDraw | 
|---|
|  | 1174 | Else | 
|---|
|  | 1175 | Section.Style:=hsText; | 
|---|
|  | 1176 |  | 
|---|
|  | 1177 | If FAlignment.Text='Center' Then | 
|---|
|  | 1178 | Section.Alignment:=taCenter | 
|---|
|  | 1179 | Else If FAlignment.Text='Right justify' Then | 
|---|
|  | 1180 | Section.Alignment:=taRightJustify | 
|---|
|  | 1181 | Else | 
|---|
|  | 1182 | Section.Alignment:=taLeftJustify; | 
|---|
|  | 1183 |  | 
|---|
|  | 1184 | Section.AllowClick:=FAllowClick.Checked; | 
|---|
|  | 1185 | Section.AllowSize:=FAllowSize.Checked; | 
|---|
|  | 1186 |  | 
|---|
|  | 1187 | End; | 
|---|
|  | 1188 |  | 
|---|
|  | 1189 | Procedure TCoolSectionsPropEditDialog.ListItemFocus(Sender:TObject;Index:LongInt); | 
|---|
|  | 1190 | var | 
|---|
|  | 1191 | Section: TCoolSection2; | 
|---|
|  | 1192 | Begin | 
|---|
|  | 1193 | StoreItem; | 
|---|
|  | 1194 |  | 
|---|
|  | 1195 | Section := FSections[ Index ]; | 
|---|
|  | 1196 | FCurrentSection := Section; | 
|---|
|  | 1197 |  | 
|---|
|  | 1198 | FText.Text:= Section.Text; | 
|---|
|  | 1199 | FWidth.Text:=tostr( Section.Width); | 
|---|
|  | 1200 | FMinWidth.Text:=tostr( Section.MinWidth); | 
|---|
|  | 1201 | FMaxWidth.Text:=tostr( Section.MaxWidth); | 
|---|
|  | 1202 | FImage.Text:=tostr( Section.Image); | 
|---|
|  | 1203 | FHotImage.Text:=tostr( Section.HotImage); | 
|---|
|  | 1204 | FDisabledImage.Text:=tostr( Section.DisabledImage); | 
|---|
|  | 1205 | FDisabled.Checked:= Section.Disabled; | 
|---|
|  | 1206 | If Section.Style=hsText Then | 
|---|
|  | 1207 | FStyle.Text:='Text' | 
|---|
|  | 1208 | Else | 
|---|
|  | 1209 | FStyle.Text:='OwnerDraw'; | 
|---|
|  | 1210 |  | 
|---|
|  | 1211 | Case Section.Alignment Of | 
|---|
|  | 1212 | taRightJustify: | 
|---|
|  | 1213 | FAlignment.Text:='Right justify'; | 
|---|
|  | 1214 | taCenter: | 
|---|
|  | 1215 | FAlignment.Text:='Center'; | 
|---|
|  | 1216 | Else | 
|---|
|  | 1217 | FAlignment.Text:='Left justify'; | 
|---|
|  | 1218 | End; | 
|---|
|  | 1219 |  | 
|---|
|  | 1220 | FAllowClick.Checked:= Section.AllowClick; | 
|---|
|  | 1221 | FAllowSize.Checked:= Section.AllowSize; | 
|---|
|  | 1222 | End; | 
|---|
|  | 1223 |  | 
|---|
|  | 1224 | Procedure TCoolSectionsPropEditDialog.SetupComponent; | 
|---|
|  | 1225 | Var | 
|---|
|  | 1226 | Button: TButton; | 
|---|
|  | 1227 | Begin | 
|---|
|  | 1228 | Inherited SetupComponent; | 
|---|
|  | 1229 |  | 
|---|
|  | 1230 | Caption:='CoolBar sections editor'; | 
|---|
|  | 1231 | Width:=445; | 
|---|
|  | 1232 | Height:=380; | 
|---|
|  | 1233 |  | 
|---|
|  | 1234 | InsertGroupBox(Self,10,50,180,290,'Sections'); | 
|---|
|  | 1235 | FListBox:=InsertListBox(Self,20,140,160,180,''); | 
|---|
|  | 1236 | FListBox.OnItemFocus:=ListItemFocus; | 
|---|
|  | 1237 |  | 
|---|
|  | 1238 | Button:=InsertButton(Self,20,60,70,30,'&New','New Section'); | 
|---|
|  | 1239 | Button.OnClick:=NewClicked; | 
|---|
|  | 1240 | Button:=InsertButton(Self,100,60,70,30,'&Delete','Delete Section'); | 
|---|
|  | 1241 | Button.OnClick:=DeleteClicked; | 
|---|
|  | 1242 |  | 
|---|
|  | 1243 | Button:=InsertButton(Self,100,100,70,30,'&Up','Move Section Up'); | 
|---|
|  | 1244 | Button.OnClick:=MoveUpClicked; | 
|---|
|  | 1245 | Button:=InsertButton(Self,20,100,70,30,'Do&wn','Move Section Down'); | 
|---|
|  | 1246 | Button.OnClick:=MoveDownClicked; | 
|---|
|  | 1247 |  | 
|---|
|  | 1248 | InsertGroupBox(Self,200,50,230,290,'Section Properties'); | 
|---|
|  | 1249 |  | 
|---|
|  | 1250 | InsertLabel(Self,210,290,50,20,'Text'); | 
|---|
|  | 1251 | FText:=InsertEdit(Self,280,295,140,20,'',''); | 
|---|
|  | 1252 |  | 
|---|
|  | 1253 | InsertLabel(Self,210,260,100,20,'Width'); | 
|---|
|  | 1254 | FWidth:=InsertEdit(Self,280,265,140,20,'',''); | 
|---|
|  | 1255 | FWidth.NumbersOnly:=TRUE; | 
|---|
|  | 1256 |  | 
|---|
|  | 1257 | InsertLabel(Self,210,230,60,20,'Min/Max'); | 
|---|
|  | 1258 | FMinWidth:=InsertEdit(Self,280,235,65,20,'',''); | 
|---|
|  | 1259 | FMinWidth.NumbersOnly:=TRUE; | 
|---|
|  | 1260 | FMaxWidth:=InsertEdit(Self,355,235,65,20,'',''); | 
|---|
|  | 1261 | FMaxWidth.NumbersOnly:=TRUE; | 
|---|
|  | 1262 |  | 
|---|
|  | 1263 | InsertLabel(Self,210,200,100,20,'Style'); | 
|---|
|  | 1264 | FStyle:=InsertComboBox(Self,280,205,140,20,csDropDownList); | 
|---|
|  | 1265 | FStyle.Items.Add('Text'); | 
|---|
|  | 1266 | FStyle.Items.Add('OwnerDraw'); | 
|---|
|  | 1267 |  | 
|---|
|  | 1268 | InsertLabel(Self,210,170,100,20,'Alignment'); | 
|---|
|  | 1269 | FAlignment:=InsertComboBox(Self,280,175,140,20,csDropDownList); | 
|---|
|  | 1270 | FAlignment.Items.Add('Left justify'); | 
|---|
|  | 1271 | FAlignment.Items.Add('Right justify'); | 
|---|
|  | 1272 | FAlignment.Items.Add('Center'); | 
|---|
|  | 1273 |  | 
|---|
|  | 1274 | FAllowClick:=InsertCheckBox(Self,210,135,100,20,'Allow Click',''); | 
|---|
|  | 1275 | FAllowSize:=InsertCheckBox(Self,210,115,100,20,'Allow Size',''); | 
|---|
|  | 1276 | FDisabled:=InsertCheckBox(Self,210,95,100,20,'Disabled',''); | 
|---|
|  | 1277 |  | 
|---|
|  | 1278 | InsertLabel(Self,300,133,100,20,'Image'); | 
|---|
|  | 1279 | FImage:=InsertEdit(Self,400,138,20,20,'',''); | 
|---|
|  | 1280 | FImage.NumbersOnly:=TRUE; | 
|---|
|  | 1281 |  | 
|---|
|  | 1282 | InsertLabel(Self,300,113,100,20,'HotImage'); | 
|---|
|  | 1283 | FHotImage:=InsertEdit(Self,400,118,20,20,'',''); | 
|---|
|  | 1284 | FHotImage.NumbersOnly:=TRUE; | 
|---|
|  | 1285 |  | 
|---|
|  | 1286 | InsertLabel(Self,300,93,100,20,'DisabledImage'); | 
|---|
|  | 1287 | FDisabledImage:=InsertEdit(Self,400,98,20,20,'',''); | 
|---|
|  | 1288 | FDisabledImage.NumbersOnly:=TRUE; | 
|---|
|  | 1289 |  | 
|---|
|  | 1290 | Button:=InsertButton(Self,210,60,200,30,'Update','Update Section'); | 
|---|
|  | 1291 | Button.OnClick:=UpdateClicked; | 
|---|
|  | 1292 |  | 
|---|
|  | 1293 | InsertBitBtn(Self,10,10,90,30,bkOk,'~Ok','Click here to accept'); | 
|---|
|  | 1294 | InsertBitBtn(Self,110,10,90,30,bkCancel,'~Cancel','Click here to cancel'); | 
|---|
|  | 1295 | InsertBitBtn(Self,210,10,90,30,bkHelp,'~Help','Click here to get help'); | 
|---|
|  | 1296 |  | 
|---|
|  | 1297 | FCurrentSection := nil; | 
|---|
|  | 1298 | End; | 
|---|
|  | 1299 |  | 
|---|
|  | 1300 | Procedure TCoolSectionsPropEditDialog.SetupShow; | 
|---|
|  | 1301 | begin | 
|---|
|  | 1302 | inherited SetupShow; | 
|---|
|  | 1303 | RefreshListBox; | 
|---|
|  | 1304 | If FSections.Count > 0 Then | 
|---|
|  | 1305 | FListBox.ItemIndex:= 0; | 
|---|
|  | 1306 | end; | 
|---|
|  | 1307 |  | 
|---|
|  | 1308 | Function TCoolSectionsPropertyEditor.Execute(Var ClassToEdit:TObject):TClassPropertyEditorReturn; | 
|---|
|  | 1309 | Var | 
|---|
|  | 1310 | HeaderSections: TCoolSections2; | 
|---|
|  | 1311 | FDialog: TCoolSectionsPropEditDialog; | 
|---|
|  | 1312 | SaveHeaders: TCoolSections2; | 
|---|
|  | 1313 | Begin | 
|---|
|  | 1314 | HeaderSections:=TCoolSections2(ClassToEdit); | 
|---|
|  | 1315 | If HeaderSections.HeaderControl=Nil Then | 
|---|
|  | 1316 | Begin | 
|---|
|  | 1317 | result:=peNoEditor; | 
|---|
|  | 1318 | exit; | 
|---|
|  | 1319 | End; | 
|---|
|  | 1320 |  | 
|---|
|  | 1321 | SaveHeaders.Create(Nil); | 
|---|
|  | 1322 | SaveHeaders.Assign(HeaderSections); | 
|---|
|  | 1323 |  | 
|---|
|  | 1324 | FDialog.Create(Nil); | 
|---|
|  | 1325 | FDialog.FSections:=HeaderSections; | 
|---|
|  | 1326 | FDialog.ShowModal; | 
|---|
|  | 1327 |  | 
|---|
|  | 1328 | //Modify ClassToEdit here | 
|---|
|  | 1329 | result:=peCancel; | 
|---|
|  | 1330 | Case FDialog.ModalResult Of | 
|---|
|  | 1331 | cmOk: | 
|---|
|  | 1332 | Begin | 
|---|
|  | 1333 | FDialog.StoreItem; | 
|---|
|  | 1334 | result:=peOk; | 
|---|
|  | 1335 | End; | 
|---|
|  | 1336 | Else | 
|---|
|  | 1337 | Begin | 
|---|
|  | 1338 | HeaderSections.Assign(SaveHeaders); | 
|---|
|  | 1339 | result:=peCancel; | 
|---|
|  | 1340 | End; | 
|---|
|  | 1341 | End; {Case} | 
|---|
|  | 1342 |  | 
|---|
|  | 1343 | SaveHeaders.Destroy; | 
|---|
|  | 1344 | FDialog.Destroy; | 
|---|
|  | 1345 | End; | 
|---|
|  | 1346 |  | 
|---|
|  | 1347 | Initialization | 
|---|
|  | 1348 | RegisterClasses([TCoolBar2]); | 
|---|
|  | 1349 | //Register property editor | 
|---|
|  | 1350 | AddClassPropertyEditor(TCoolSections2,TCoolSectionsPropertyEditor); | 
|---|
|  | 1351 | End. | 
|---|
|  | 1352 |  | 
|---|