PageRenderTime 54ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/mckToolbarEditor.inc

http://github.com/rofl0r/KOL
Pascal | 913 lines | 712 code | 48 blank | 153 comment | 79 complexity | 68b21fdba10dad5d14c808522842b670 MD5 | raw file
  1. type
  2. TfmToolbarEditor = class(TForm)
  3. private
  4. lvButtons: TListView;
  5. btnAdd: TButton;
  6. btnDelete: TButton;
  7. btnUp: TButton;
  8. btnDown: TButton;
  9. btnPicture: TButton;
  10. chkSeparator: TCheckBox;
  11. btnOK: TButton;
  12. {$IFDEF VER90}
  13. opDialog1: TOpenDialog;
  14. {$ELSE}
  15. opDialog1: TOpenPictureDialog;
  16. {$ENDIF}
  17. ilImages: TImageList;
  18. chkStayOnTop: TCheckBox;
  19. chkDropDown: TCheckBox;
  20. {procedure lvButtonsSelectItem(Sender: TObject; Item: TListItem;
  21. Selected: Boolean);}
  22. procedure btnAddClick(Sender: TObject);
  23. procedure btnDeleteClick(Sender: TObject);
  24. procedure btnUpClick(Sender: TObject);
  25. procedure btnDownClick(Sender: TObject);
  26. procedure chkSeparatorClick(Sender: TObject);
  27. procedure lvButtonsEdited(Sender: TObject; Item: TListItem;
  28. var S: String);
  29. procedure btnPictureClick(Sender: TObject);
  30. procedure FormShow(Sender: TObject);
  31. procedure btnOKClick(Sender: TObject);
  32. //procedure btnCancelClick(Sender: TObject);
  33. procedure FormKeyDown(Sender: TObject; var Key: Word;
  34. Shift: TShiftState);
  35. procedure FormClose(Sender: TObject; var Action: TCloseAction);
  36. procedure FormDestroy(Sender: TObject);
  37. procedure chkStayOnTopClick(Sender: TObject);
  38. procedure chkDropDownClick(Sender: TObject);
  39. private
  40. { Private declarations }
  41. CanCancel: Boolean;
  42. FToolbar: TComponent;
  43. procedure AdjustButtons;
  44. procedure SetToolbar(const Value: TComponent);
  45. procedure lvButtonsChange(Sender: TObject; Item: TListItem; Change: TItemChange);
  46. //function SeparatorsCount: Integer;
  47. procedure AssembleBitmap;
  48. procedure AssembleButtons;
  49. procedure SelectTB;
  50. public
  51. { Public declarations }
  52. Bitmap: TBitmap;
  53. ButtonCaptions: String;
  54. constructor Create( AOwner: TComponent ); override;
  55. destructor Destroy; override;
  56. property ToolbarControl: TComponent read FToolbar write SetToolbar;
  57. procedure MakeActive( SelectAny: Boolean );
  58. procedure RefreshItems;
  59. procedure ApplyImages;
  60. end;
  61. var
  62. fmToolbarEditor: TfmToolbarEditor;
  63. implementation
  64. uses
  65. mirror, mckCtrls, mckObjs;
  66. procedure TfmToolbarEditor.AdjustButtons;
  67. var LI: TListItem;
  68. Bt: TKOLToolbarButton;
  69. begin
  70. LI := lvButtons.Selected;
  71. if LI = nil then
  72. begin
  73. btnAdd.Enabled := lvButtons.Items.Count = 0;
  74. btnDelete.Enabled := FALSE;
  75. btnUp.Enabled := FALSE;
  76. btnDown.Enabled := FALSE;
  77. btnPicture.Enabled := FALSE;
  78. if chkSeparator.Checked then
  79. chkSeparator.Checked := FALSE;
  80. chkSeparator.Enabled := FALSE;
  81. btnOK.Enabled := TRUE;
  82. chkDropDown.Enabled := FALSE;
  83. //btnCancel.Enabled := CanCancel;
  84. end
  85. else
  86. begin
  87. btnAdd.Enabled := TRUE;
  88. btnDelete.Enabled := TRUE;
  89. btnUp.Enabled := LI.Index > 0;
  90. btnDown.Enabled := LI.Index < lvButtons.Items.Count - 1;
  91. btnPicture.Enabled := TRUE;
  92. chkSeparator.Enabled := TRUE;
  93. if chkSeparator.Checked <> (LI.Caption = '-') then
  94. chkSeparator.Checked := LI.Caption = '-';
  95. btnOK.Enabled := TRUE;
  96. chkDropDown.Enabled := TRUE;
  97. Bt := LI.Data;
  98. chkDropDown.Checked := Bt.DropDown;
  99. //btnCancel.Enabled := CanCancel;
  100. end;
  101. end;
  102. constructor TfmToolbarEditor.Create(AOwner: TComponent);
  103. begin
  104. CreateNew(AOwner);
  105. BorderIcons := [biSystemMenu];
  106. BorderStyle := bsDialog;
  107. Caption := 'fmToolbarEditor';
  108. ClientHeight := 281;
  109. ClientWidth := 277;
  110. Color := clBtnFace;
  111. //Font.Charset := DEFAULT_CHARSET;
  112. Font.Color := clWindowText;
  113. Font.Height := -11;
  114. Font.Name := 'MS Sans Serif';
  115. Font.Style := [];
  116. KeyPreview := True;
  117. //OldCreateOrder = False
  118. Scaled := False;
  119. OnShow := FormShow;
  120. OnClose := FormClose;
  121. OnDestroy := FormDestroy;
  122. OnKeyDown := FormKeyDown;
  123. //PixelsPerInch = 96
  124. //TextHeight = 13
  125. ilImages := TImageList.Create( Self );
  126. lvButtons := TListView.Create( Self );
  127. lvButtons.Parent := Self;
  128. lvButtons.Left := 6;
  129. lvButtons.Top := 8;
  130. lvButtons.Width := 163;
  131. lvButtons.Height := 265;
  132. lvButtons.MultiSelect := FALSE;
  133. lvButtons.Columns.Add;
  134. lvButtons.Columns[ 0 ].Caption := 'Buttons';
  135. lvButtons.Columns[ 0 ].Width := -2;
  136. lvButtons.HideSelection := False;
  137. {$IFNDEF VER90}
  138. lvButtons.RowSelect := TRUE;
  139. {$ENDIF}
  140. lvButtons.ShowColumnHeaders := False;
  141. lvButtons.SmallImages := ilImages;
  142. //lvButtons.TabOrder := 0;
  143. lvButtons.ViewStyle := vsReport;
  144. lvButtons.OnEdited := lvButtonsEdited;
  145. //lvButtons.OnSelectItem := lvButtonsSelectItem;
  146. lvButtons.OnChange := lvButtonsChange;
  147. btnOK := TButton.Create( Self );
  148. btnOK.Parent := Self;
  149. btnOK.Left := 180;
  150. btnOK.Top := 9;
  151. btnOK.Width := 89;
  152. btnOK.Height := 25;
  153. btnOK.Caption := 'Apply';
  154. //btnOK.TabOrder := 1;
  155. btnOK.OnClick := btnOKClick;
  156. chkStayOnTop := TCheckBox.Create( Self );
  157. chkStayOnTop.Parent := Self;
  158. chkStayOnTop.Left := 180;
  159. chkStayOnTop.Top := 40;
  160. chkStayOnTop.Width := 89;
  161. chkStayOnTop.Height := 17;
  162. chkStayOnTop.Caption := 'Stay on top';
  163. //chkStayOnTop.TabOrder := 2;
  164. chkStayOnTop.OnClick := chkStayOnTopClick;
  165. btnAdd := TButton.Create( Self );
  166. btnAdd.Parent := Self;
  167. btnAdd.Left := 180;
  168. btnAdd.Top := 80;
  169. btnAdd.Width := 89;
  170. btnAdd.Height := 25;
  171. btnAdd.Caption := 'Add';
  172. //btnAdd.TabOrder := 3;
  173. btnAdd.OnClick := btnAddClick;
  174. btnDelete := TButton.Create( Self );
  175. btnDelete.Parent := Self;
  176. btnDelete.Left := 180;
  177. btnDelete.Top := 112;
  178. btnDelete.Width := 89;
  179. btnDelete.Height := 25;
  180. btnDelete.Caption := 'Delete';
  181. //btnDelete.TabOrder := 4;
  182. btnDelete.OnClick := btnDeleteClick;
  183. btnUp := TButton.Create( Self );
  184. btnUp.Parent := Self;
  185. btnUp.Left := 180;
  186. btnUp.Top := 152;
  187. btnUp.Width := 41;
  188. btnUp.Height := 25;
  189. btnUp.Caption := 'Up';
  190. //btnUp.TabOrder := 5;
  191. btnUp.OnClick := btnUpClick;
  192. btnDown := TButton.Create( Self );
  193. btnDown.Parent := Self;
  194. btnDown.Left := 228;
  195. btnDown.Top := 152;
  196. btnDown.Width := 41;
  197. btnDown.Height := 25;
  198. btnDown.Caption := 'Down';
  199. //btnDown.TabOrder := 6;
  200. btnDown.OnClick := btnDownClick;
  201. btnPicture := TButton.Create( Self );
  202. btnPicture.Parent := Self;
  203. btnPicture.Left := 180;
  204. btnPicture.Top := 192;
  205. btnPicture.Width := 89;
  206. btnPicture.Height := 25;
  207. btnPicture.Caption := 'Picture';
  208. //btnPicture.TabOrder := 7;
  209. btnPicture.OnClick := btnPictureClick;
  210. btnPicture.Visible := FALSE;
  211. chkSeparator := TCheckBox.Create( Self );
  212. chkSeparator.Parent := Self;
  213. chkSeparator.Left := 180;
  214. chkSeparator.Top := 227;
  215. chkSeparator.Width := 89;
  216. chkSeparator.Height := 17;
  217. chkSeparator.Caption := 'Separator';
  218. //chkSeparator.TabOrder := 8;
  219. chkSeparator.OnClick := chkSeparatorClick;
  220. chkDropDown := TCheckBox.Create( Self );
  221. chkDropDown.Parent := Self;
  222. chkDropDown.Left := 180;
  223. chkDropDown.Top := 255;
  224. chkDropDown.Width := 89;
  225. chkDropDown.Height := 17;
  226. chkDropDown.Caption := 'DropDown';
  227. //chkDropDown.TabOrder := 9;
  228. chkDropDown.OnClick := chkDropDownClick;
  229. {$IFDEF VER90}
  230. opDialog1 := TOpenDialog.Create( Self );
  231. {$ELSE}
  232. opDialog1 := TOpenPictureDialog.Create( Self );
  233. {$ENDIF}
  234. opDialog1.DefaultExt := 'bmp';
  235. {$IFDEF VER90}
  236. opDialog1.Filter := 'All available image files|*.bmp;*.ico;*.wmf';
  237. {$ENDIF}
  238. opDialog1.Options := [ofHideReadOnly, ofPathMustExist, ofFileMustExist
  239. {$IFNDEF VER90}{$IFNDEF VER100}, ofEnableSizing{$ENDIF}{$ENDIF} ];
  240. opDialog1.Title := 'Open picture';
  241. CanCancel := TRUE;
  242. Bitmap := TBitmap.Create;
  243. end;
  244. procedure TfmToolbarEditor.lvButtonsChange(Sender: TObject; Item: TListItem; Change: TItemChange);
  245. begin
  246. MakeActive( FALSE );
  247. AdjustButtons;
  248. end;
  249. procedure TfmToolbarEditor.btnAddClick(Sender: TObject);
  250. var LI: TListItem;
  251. Bt: TKOLToolbarButton;
  252. Toolbar: TKOLToolbar;
  253. I: Integer;
  254. S: String;
  255. begin
  256. if ToolbarControl = nil then Exit;
  257. if not( ToolbarControl is TKOLToolbar ) then Exit;
  258. Toolbar := ToolbarControl as TKOLToolbar;
  259. LI := lvButtons.Selected;
  260. if LI = nil then
  261. begin
  262. Bt := TKOLToolbarButton.Create( Toolbar );
  263. LI := lvButtons.Items.Add;
  264. LI.Data := Bt;
  265. end
  266. else
  267. begin
  268. if LI.Index >= lvButtons.Items.Count then
  269. Bt := TKOLToolbarButton.Create( Toolbar )
  270. else
  271. begin
  272. Bt := TKOLToolbarButton.Create( Toolbar );
  273. Toolbar.Items.Move( lvButtons.Items.Count, LI.Index + 1 );
  274. end;
  275. LI := lvButtons.Items.Insert( LI.Index + 1 );
  276. LI.Data := Bt;
  277. end;
  278. if ToolbarControl <> nil then
  279. if ToolbarControl.Owner is TForm then
  280. for I := 1 to MaxInt do
  281. begin
  282. S := 'TB' + IntToStr( I );
  283. if (ToolbarControl.Owner as TForm).FindComponent( S ) = nil then
  284. if ToolbarControl.FindComponent( S ) = nil then
  285. begin
  286. Bt.Name := S;
  287. break;
  288. end;
  289. end;
  290. Bt.imgIndex := Toolbar.MaxImgIndex;
  291. LI.ImageIndex := -1;
  292. AssembleButtons;
  293. lvButtons.Selected := nil;
  294. lvButtons.Selected := LI;
  295. lvButtons.ItemFocused := LI;
  296. LI.MakeVisible( FALSE );
  297. LI.EditCaption;
  298. end;
  299. procedure TfmToolbarEditor.btnDeleteClick(Sender: TObject);
  300. var LI: TListItem;
  301. J: Integer;
  302. Bt: TKOLToolbarButton;
  303. begin
  304. LI := lvButtons.Selected;
  305. if LI <> nil then
  306. begin
  307. J := LI.Index;
  308. Bt := LI.Data;
  309. Bt.Free;
  310. LI.Free;
  311. if J >= lvButtons.Items.Count then
  312. Dec( J );
  313. if J >= 0 then
  314. begin
  315. lvButtons.Selected := lvButtons.Items[ J ];
  316. lvButtons.ItemFocused := lvButtons.Selected;
  317. end;
  318. AssembleButtons;
  319. end;
  320. AdjustButtons;
  321. if lvButtons.Items.Count = 0 then
  322. SelectTB;
  323. end;
  324. procedure TfmToolbarEditor.btnUpClick(Sender: TObject);
  325. var LI, LI1: TListItem;
  326. I: Integer;
  327. Toolbar: TKOLToolbar;
  328. begin
  329. if ToolbarControl = nil then Exit;
  330. if not(ToolbarControl is TKOLToolbar) then Exit;
  331. Toolbar := ToolbarControl as TKOLToolbar;
  332. LI := lvButtons.Selected;
  333. if LI = nil then Exit;
  334. I := LI.Index - 1;
  335. LI1 := lvButtons.Items.Insert( I );
  336. LI1.Caption := LI.Caption;
  337. LI1.Data := LI.Data;
  338. Toolbar.Items.Move( I + 1, I );
  339. LI.Free;
  340. lvButtons.Selected := LI1;
  341. lvButtons.ItemFocused := LI1;
  342. AssembleButtons;
  343. end;
  344. procedure TfmToolbarEditor.btnDownClick(Sender: TObject);
  345. var LI, LI1: TListItem;
  346. Toolbar: TKOLToolbar;
  347. begin
  348. if ToolbarControl = nil then Exit;
  349. if not(ToolbarControl is TKOLToolbar) then Exit;
  350. Toolbar := ToolbarControl as TKOLToolbar;
  351. LI := lvButtons.Selected;
  352. if LI = nil then Exit;
  353. Toolbar.Items.Move( LI.Index, LI.Index + 1 );
  354. LI1 := lvButtons.Items.Insert( LI.Index + 2 );
  355. LI1.Caption := LI.Caption;
  356. LI1.Data := LI.Data;
  357. LI.Free;
  358. lvButtons.Selected := LI1;
  359. lvButtons.ItemFocused := LI1;
  360. AssembleButtons;
  361. end;
  362. procedure TfmToolbarEditor.chkSeparatorClick(Sender: TObject);
  363. var LI: TListItem;
  364. Bmp: TBitmap;
  365. I: Integer;
  366. Bt: TKOLToolbarButton;
  367. Toolbar: TKOLToolbar;
  368. begin
  369. LI := lvButtons.Selected;
  370. if LI = nil then Exit;
  371. Bt := LI.Data;
  372. if chkSeparator.Checked then
  373. begin
  374. if LI.Caption <> '-' then
  375. begin
  376. Bt.separator := TRUE;
  377. LI.Caption := '-';
  378. I := LI.ImageIndex;
  379. Bmp := TBitmap.Create;
  380. try
  381. Bmp.Width := Bitmap.Width - Bitmap.Height;
  382. Bmp.Height := Bitmap.Height;
  383. Bmp.Canvas.Brush.Color := Bitmap.Canvas.Pixels[ 0, Bmp.Height - 1 ];
  384. Bmp.Canvas.FillRect( Rect( 0, 0, Bmp.Width, Bmp.Height ) );
  385. Bmp.Canvas.CopyRect( Rect( 0, 0, I * Bmp.Height, Bmp.Height ),
  386. Bitmap.Canvas,
  387. Rect( 0, 0, I * Bmp.Height, Bmp.Height ) );
  388. Bmp.Canvas.CopyRect( Rect( I * Bmp.Height, 0, Bmp.Width, Bmp.Height ),
  389. Bitmap.Canvas,
  390. Rect( (I + 1) * Bmp.Height, 0, Bitmap.Width, Bmp.Height ) );
  391. Bitmap.Free;
  392. Bitmap := Bmp;
  393. Bmp := nil;
  394. finally
  395. Bmp.Free;
  396. end;
  397. end;
  398. end
  399. else
  400. begin
  401. if LI.Caption = '-' then
  402. LI.Caption := '';
  403. Bt.separator := FALSE;
  404. I := LI.ImageIndex;
  405. Bmp := TBitmap.Create;
  406. try
  407. Bmp.Width := Bitmap.Width + Bitmap.Height;
  408. Bmp.Height := Bitmap.Height;
  409. Bmp.Canvas.Brush.Color := Bitmap.Canvas.Pixels[ 0, Bmp.Height - 1 ];
  410. Bmp.Canvas.FillRect( Rect( 0, 0, Bmp.Width, Bmp.Height ) );
  411. Bmp.Canvas.CopyRect( Rect( 0, 0, I * Bmp.Height, Bmp.Height ),
  412. Bitmap.Canvas,
  413. Rect( 0, 0, I * Bmp.Height, Bmp.Height ) );
  414. Bmp.Canvas.CopyRect( Rect( (I + 1) * Bmp.Height, 0, Bmp.Width, Bmp.Height ),
  415. Bitmap.Canvas,
  416. Rect( I * Bmp.Height, 0, Bitmap.Width, Bmp.Height ) );
  417. Bitmap.Free;
  418. Bitmap := Bmp;
  419. Bmp := nil;
  420. finally
  421. Bmp.Free;
  422. end;
  423. end;
  424. if ToolbarControl = nil then Exit;
  425. Toolbar := ToolbarControl as TKOLToolbar;
  426. Toolbar.Items2buttons;
  427. end;
  428. procedure TfmToolbarEditor.lvButtonsEdited(Sender: TObject;
  429. Item: TListItem; var S: String);
  430. var Bt: TKOLToolbarButton;
  431. begin
  432. chkSeparator.Checked := S = '-';
  433. Bt := Item.Data;
  434. Bt.Caption := S;
  435. end;
  436. procedure TfmToolbarEditor.btnPictureClick(Sender: TObject);
  437. begin
  438. end;
  439. (*var LI: TListItem;
  440. Pic: TPicture;
  441. Bmp, Bmp2: TBitmap;
  442. ImgIdx: Integer;
  443. Toolbar: TKOLToolbar;
  444. begin
  445. LI := lvButtons.Selected;
  446. if LI = nil then Exit;
  447. ImgIdx := ButtonImgIdx( LI.Index );
  448. if opDialog1.Execute then
  449. begin
  450. Pic := TPicture.Create;
  451. Bmp := TBitmap.Create;
  452. Bmp2 := TBitmap.Create;
  453. try
  454. Pic.LoadFromFile( opDialog1.Filename );
  455. if not Pic.Graphic.Empty then
  456. begin
  457. if lvButtons.Items.Count = 1 then
  458. begin
  459. Bitmap.Width := 0;
  460. Bitmap.Height := 0;
  461. end;
  462. if (Bitmap.Height = 0) or (Bitmap.Width = 0) then
  463. begin
  464. Bitmap.Height := Pic.Graphic.Height;
  465. end;
  466. if Bitmap.Width < Bitmap.Height * (ImgIdx + 1) then
  467. begin
  468. Bmp2.Height := Bitmap.Height;
  469. Bmp2.Width := Bitmap.Height * (ImgIdx + 1);
  470. Bmp2.Canvas.Brush.Color := Bitmap.Canvas.Pixels[ 0, Bmp2.Height-1 ];
  471. Bmp2.Canvas.FillRect( Rect( 0, 0, Bmp2.Width, Bmp2.Height ) );
  472. Bmp2.Canvas.CopyRect( Rect( 0, 0, Bitmap.Width, Bitmap.Height ),
  473. Bitmap.Canvas,
  474. Rect( 0, 0, Bitmap.Width, Bitmap.Height ) );
  475. Bitmap.Free;
  476. Bitmap := Bmp2;
  477. Bmp2 := TBitmap.Create;
  478. end;
  479. Bmp2.Width := Bitmap.Height;
  480. Bmp2.Height := Bitmap.Height;
  481. Bmp2.Canvas.Brush.Color := Bitmap.Canvas.Pixels[ 0, Bitmap.Height - 1 ];
  482. Bmp2.Canvas.FillRect( Rect( 0, 0, Bmp2.Width, Bmp2.Height ) );
  483. Bmp.Width := Pic.Graphic.Width;
  484. Bmp.Height := Pic.Graphic.Height;
  485. Bmp.Canvas.Brush.Color := Bitmap.Canvas.Pixels[ 0, Bitmap.Height - 1 ];
  486. Bmp.Canvas.FillRect( Rect( 0, 0, Bmp.Width, Bmp.Height ) );
  487. Bmp.Canvas.Draw( 0, 0, Pic.Graphic );
  488. {$IFNDEF VER90}
  489. Bmp.TransparentColor := Bmp.Canvas.Pixels[ 0, Bmp.Height - 1 ];
  490. Bmp.Transparent := TRUE;
  491. {$ENDIF}
  492. Bmp2.Canvas.StretchDraw( Rect( 0, 0, Bmp2.Width, Bmp2.Height ), Bmp );
  493. Bitmap.Canvas.CopyRect( Rect( ImgIdx * Bitmap.Height, 0, (ImgIdx + 1) * Bitmap.Height, Bitmap.Height ),
  494. Bmp2.Canvas,
  495. Rect( 0, 0, Bmp2.Width, Bmp2.Height ) );
  496. end;
  497. finally
  498. Pic.Free;
  499. Bmp.Free;
  500. Bmp2.Free;
  501. end;
  502. end;
  503. ApplyImages;
  504. if ToolbarControl <> nil then
  505. if ToolbarControl is TKOLToolbar then
  506. begin
  507. Toolbar := ToolbarControl as TKOLToolbar;
  508. Toolbar.bitmap.Assign( Bitmap );
  509. Toolbar.bitmap2ItemPictures;
  510. end;
  511. end;*)
  512. destructor TfmToolbarEditor.Destroy;
  513. begin
  514. Bitmap.Free;
  515. inherited;
  516. end;
  517. procedure TfmToolbarEditor.FormShow(Sender: TObject);
  518. var I: Integer;
  519. LI: TListItem;
  520. Bt: TKOLToolbarButton;
  521. Toolbar: TKOLToolbar;
  522. begin
  523. lvButtons.Items.BeginUpdate;
  524. TRY
  525. lvButtons.Items.Clear;
  526. if ToolbarControl <> nil then
  527. if ToolbarControl is TKOLToolbar then
  528. begin
  529. Toolbar := ToolbarControl as TKOLToolbar;
  530. for I := 0 to Toolbar.Items.Count-1 do
  531. begin
  532. LI := lvButtons.Items.Add;
  533. Bt := Toolbar.Items[ I ];
  534. LI.Data := Bt;
  535. LI.Caption := Bt.caption;
  536. end;
  537. end;
  538. ApplyImages;
  539. FINALLY
  540. lvButtons.Items.EndUpdate;
  541. END;
  542. end;
  543. procedure TfmToolbarEditor.ApplyImages;
  544. var I, J: Integer;
  545. Bmp: TBitmap;
  546. W, H, H1: Integer;
  547. Bt: TKOLToolbarButton;
  548. TranColor: TColor;
  549. begin
  550. ilImages.Clear;
  551. W := 0;
  552. H := 0;
  553. TranColor := clNone;
  554. for I := 0 to lvButtons.Items.Count-1 do
  555. begin
  556. Bt := lvButtons.Items[ I ].Data;
  557. if Bt = nil then continue;
  558. if Bt.HasPicture then
  559. begin
  560. if Bt.picture.Width > W then
  561. W := Bt.picture.Width;
  562. if Bt.picture.Height > H then
  563. H := Bt.picture.Height;
  564. if TranColor = clNone then
  565. begin
  566. Bmp := TBitmap.Create;
  567. TRY
  568. Bmp.Assign( Bt.picture.Graphic );
  569. TranColor := Bmp.Canvas.Pixels[ 0, Bmp.Height - 1 ];
  570. FINALLY
  571. Bmp.Free;
  572. END;
  573. end;
  574. end;
  575. end;
  576. if W * H > 0 then
  577. begin
  578. ilImages.Width := W;
  579. ilImages.Height := H;
  580. Bmp := TBitmap.Create;
  581. try
  582. Bmp.Width := W;
  583. Bmp.Height := H;
  584. for I := 0 to lvButtons.Items.Count - 1 do
  585. begin
  586. Bt := lvButtons.Items[ I ].Data;
  587. if TranColor <> clNone then
  588. begin
  589. Bmp.Canvas.Brush.Color := TranColor;
  590. Bmp.Canvas.FillRect( Rect( 0, 0, Bmp.Width, Bmp.Height ) );
  591. end;
  592. if (Bt <> nil) and Bt.HasPicture then
  593. Bmp.Canvas.Draw( 0, 0, Bt.picture.Graphic );
  594. if Bt.HasPicture and (Bt.picture.Height > 0) then
  595. begin
  596. H1 := Bt.picture.Height;
  597. J := ilImages.AddMasked( Bmp, Bmp.Canvas.Pixels[ 0, H1 - 1 ] );
  598. lvButtons.Items[ I ].ImageIndex := J;
  599. end
  600. else
  601. lvButtons.Items[ I ].ImageIndex := -1;
  602. end;
  603. finally
  604. Bmp.Free;
  605. end;
  606. end
  607. else
  608. begin
  609. ilImages.Width := 16;
  610. ilImages.Height := 16;
  611. for I := 0 to lvButtons.Items.Count - 1 do
  612. lvButtons.Items[ I ].ImageIndex := -1;
  613. end;
  614. end;
  615. procedure TfmToolbarEditor.btnOKClick(Sender: TObject);
  616. var I: Integer;
  617. S: String;
  618. LI: TListItem;
  619. Tb: TKOLToolbar;
  620. Bt: TKOLToolbarButton;
  621. begin
  622. S := '';
  623. for I := 0 to lvButtons.Items.Count - 1 do
  624. begin
  625. LI := lvButtons.Items[ I ];
  626. if S <> '' then
  627. S := S + #1;
  628. Bt := LI.Data;
  629. //if LI.Data <> nil then
  630. if Bt.checked then
  631. S := S + '^';
  632. S := S + LI.Caption;
  633. end;
  634. ButtonCaptions := S;
  635. if ToolbarControl <> nil then
  636. begin
  637. Tb := ToolbarControl as TKOLToolbar;
  638. Tb.Bitmap.Assign( Bitmap );
  639. if (Bitmap.Width > 0) and (Bitmap.Height > 0) then
  640. begin
  641. I := 22;
  642. if Bitmap.Height > I - 4 then
  643. I := Bitmap.Height + 4;
  644. Tb.Height := I;
  645. end;
  646. Tb.buttons := ButtonCaptions;
  647. Tb.Change;
  648. end;
  649. //Close;
  650. end;
  651. {procedure TfmToolbarEditor.btnCancelClick(Sender: TObject);
  652. begin
  653. Close;
  654. end;}
  655. procedure TfmToolbarEditor.FormKeyDown(Sender: TObject; var Key: Word;
  656. Shift: TShiftState);
  657. begin
  658. case Key of
  659. VK_INSERT: btnAdd.Click;
  660. VK_DELETE: if not lvButtons.IsEditing then btnDelete.Click;
  661. VK_RETURN: if (ActiveControl = lvButtons) and not lvButtons.IsEditing and
  662. (lvButtons.Selected <> nil) then
  663. lvButtons.Selected.EditCaption;
  664. VK_UP: if (GetKeyState( VK_CONTROL ) < 0) then
  665. btnUp.Click
  666. else Exit;
  667. VK_DOWN: if (GetKeyState( VK_CONTROL ) < 0) then
  668. btnDown.Click
  669. else Exit;
  670. else Exit;
  671. end;
  672. Key := 0;
  673. end;
  674. procedure TfmToolbarEditor.SetToolbar(const Value: TComponent);
  675. var Tb: TKOLToolbar;
  676. begin
  677. FToolbar := Value;
  678. Tb := Value as TKOLToolbar;
  679. Caption := Tb.Name + ' buttons';
  680. ButtonCaptions := Tb.buttons;
  681. Bitmap.Assign( Tb.Bitmap );
  682. end;
  683. procedure TfmToolbarEditor.FormClose(Sender: TObject;
  684. var Action: TCloseAction);
  685. begin
  686. Rpt( 'Closing KOLToolbar form' );
  687. SelectTB;
  688. modalResult := mrOK;
  689. end;
  690. procedure TfmToolbarEditor.MakeActive( SelectAny: Boolean );
  691. var F: TForm;
  692. D: IDesigner;
  693. FD: IFormDesigner;
  694. Bt: TKOLToolbarButton;
  695. begin
  696. if lvButtons.Items.Count > 0 then
  697. if lvButtons.Selected = nil then
  698. if SelectAny then
  699. lvButtons.Selected := lvButtons.Items[ 0 ];
  700. if lvButtons.Selected <> nil then
  701. begin
  702. Bt := lvButtons.Selected.Data;
  703. F := (ToolbarControl as TKOLToolbar).Owner as TForm;
  704. if F <> nil then
  705. begin
  706. //*///////////////////////////////////////////////////////
  707. {$IFDEF _D6orHigher} //
  708. F.Designer.QueryInterface(IFormDesigner,D); //
  709. {$ELSE} //
  710. //*///////////////////////////////////////////////////////
  711. D := F.Designer;
  712. //*///////////////////////////////////////////////////////
  713. {$ENDIF} //
  714. //*///////////////////////////////////////////////////////
  715. if D <> nil then
  716. if QueryFormDesigner( D, FD ) then
  717. begin
  718. RemoveSelection( FD );
  719. FD.SelectComponent( Bt );
  720. end;
  721. end;
  722. end;
  723. AdjustButtons;
  724. end;
  725. procedure TfmToolbarEditor.FormDestroy(Sender: TObject);
  726. var Tb: TKOLToolbar;
  727. begin
  728. if ToolbarControl <> nil then
  729. begin
  730. Tb := ToolbarControl as TKOLToolbar;
  731. Tb.ActiveDesign := nil;
  732. end;
  733. //Bitmap.Free;
  734. end;
  735. procedure TfmToolbarEditor.chkStayOnTopClick(Sender: TObject);
  736. begin
  737. if chkStayOnTop.Checked then
  738. FormStyle := fsStayOnTop
  739. else
  740. FormStyle := fsNormal;
  741. end;
  742. procedure TfmToolbarEditor.chkDropDownClick(Sender: TObject);
  743. var LI: TListItem;
  744. Bt: TKOLToolbarButton;
  745. begin
  746. LI := lvButtons.Selected;
  747. if LI = nil then Exit;
  748. Bt := LI.Data;
  749. Bt.DropDown := chkDropDown.Checked;
  750. end;
  751. {function TfmToolbarEditor.SeparatorsCount: Integer;
  752. var I: Integer;
  753. begin
  754. Result := 0;
  755. for I := 0 to lvButtons.Items.Count-1 do
  756. begin
  757. if lvButtons.Items[ I ].Caption = '-' then
  758. Inc( Result );
  759. end;
  760. end;}
  761. {function TfmToolbarEditor.ButtonImgIdx(BtnIdx: Integer): Integer;
  762. var I: Integer;
  763. begin
  764. Result := 0;
  765. for I := 0 to BtnIdx - 1 do
  766. if lvButtons.Items[ I ].Caption <> '-' then
  767. Inc( Result );
  768. end;}
  769. procedure TfmToolbarEditor.RefreshItems;
  770. var I: Integer;
  771. LI: TListItem;
  772. Bt: TKOLToolbarButton;
  773. begin
  774. for I := 0 to lvButtons.Items.Count-1 do
  775. begin
  776. LI := lvButtons.Items[ I ];
  777. Bt := LI.Data;
  778. if Bt <> nil then
  779. begin
  780. if LI.Caption <> Bt.Caption then
  781. begin
  782. lvButtons.OnChange := nil;
  783. LI.Caption := Bt.caption;
  784. lvButtons.OnChange := lvButtonsChange;
  785. end;
  786. if lvButtons.Selected = LI then
  787. begin
  788. {ShowMessage( 'Bt.caption=' + Bt.caption +
  789. ' Bt.checked=' + IntToStr( Integer( Bt.checked ) ) +
  790. ' Bt.dropdown=' + IntToStr( Integer( Bt.dropdown ) ) +
  791. ' chkSeparator.Checked=' + IntToStr( Integer( chkSeparator.Checked ) ) +
  792. ' chkDropDown.Checked=' + IntToStr( Integer( chkDropDown.Checked ) ) );}
  793. if chkSeparator.Checked <> Bt.separator then
  794. begin
  795. chkSeparator.OnClick := nil;
  796. chkSeparator.Checked := Bt.separator;
  797. chkSeparator.OnClick := chkSeparatorClick;
  798. end;
  799. if chkDropDown.Checked <> Bt.dropdown then
  800. begin
  801. chkDropDown.OnClick := nil;
  802. chkDropDown.Checked := Bt.dropdown;
  803. chkDropDown.OnClick := chkDropDownClick;
  804. end;
  805. end;
  806. end;
  807. end;
  808. //ApplyImages;
  809. end;
  810. procedure TfmToolbarEditor.AssembleBitmap;
  811. var Toolbar: TKOLToolbar;
  812. begin
  813. if ToolbarControl = nil then Exit;
  814. if not( ToolbarControl is TKOLToolbar ) then Exit;
  815. Toolbar := ToolbarControl as TKOLToolbar;
  816. Toolbar.AssembleBitmap;
  817. end;
  818. procedure TfmToolbarEditor.AssembleButtons;
  819. var Toolbar: TKOLToolbar;
  820. begin
  821. if ToolbarControl = nil then Exit;
  822. if not( ToolbarControl is TKOLToolbar ) then Exit;
  823. Toolbar := ToolbarControl as TKOLToolbar;
  824. Toolbar.Items2buttons;
  825. AssembleBitmap;
  826. end;
  827. procedure TfmToolbarEditor.SelectTB;
  828. var F: TForm;
  829. D: IDesigner;
  830. FD: IFormDesigner;
  831. begin
  832. if ToolbarControl <> nil then
  833. begin
  834. F := (ToolbarControl as TKOLToolbar).Owner as TForm;
  835. if F <> nil then
  836. begin
  837. Rpt( 'Form found: ' + F.Name );
  838. //*///////////////////////////////////////////////////////
  839. {$IFDEF _D6orHigher} //
  840. F.Designer.QueryInterface(IFormDesigner,D); //
  841. {$ELSE} //
  842. //*///////////////////////////////////////////////////////
  843. D := F.Designer;
  844. //*///////////////////////////////////////////////////////
  845. {$ENDIF} //
  846. //*///////////////////////////////////////////////////////
  847. if D <> nil then
  848. begin
  849. Rpt( 'IDesigner interface returned' );
  850. if QueryFormDesigner( D, FD ) then
  851. begin
  852. Rpt( 'IFormDesigner interface quered' );
  853. try
  854. RemoveSelection( FD );
  855. FD.SelectComponent( ToolbarControl );
  856. except
  857. Rpt( 'EXCEPTION *** Could not clear selection!' )
  858. end;
  859. end;
  860. end;
  861. end;
  862. end;
  863. end;