umain.pas 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. unit umain;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, BCComboBox,
  6. BCListBox, LCLType, BCSamples, BGRAThemeRadioButton, BGRAColorTheme, Types;
  7. type
  8. { TForm1 }
  9. TForm1 = class(TForm)
  10. BCComboBox1: TBCComboBox;
  11. BGRAColorTheme1: TBGRAColorTheme;
  12. Button1: TButton;
  13. CheckOnSameForm: TCheckBox;
  14. Label1: TLabel;
  15. Label2: TLabel;
  16. RadioCustom: TBGRAThemeRadioButton;
  17. RadioFlash: TBGRAThemeRadioButton;
  18. RadioWin7: TBGRAThemeRadioButton;
  19. RadioDefault: TBGRAThemeRadioButton;
  20. procedure BCComboBox1Change(Sender: TObject);
  21. procedure Button1Click(Sender: TObject);
  22. procedure CheckOnSameFormChange(Sender: TObject);
  23. procedure FormCreate(Sender: TObject);
  24. procedure RadioButtonChange(Sender: TObject);
  25. private
  26. procedure OnBCComboBoxDrawItem(Control: TWinControl; Index: integer;
  27. ARect: TRect; State: TOwnerDrawState);
  28. public
  29. procedure ApplyFlashStyle;
  30. procedure ApplyWin7Style;
  31. procedure ApplyCustomStyle;
  32. procedure ApplyDefaultStyle;
  33. procedure UpdateStyle;
  34. end;
  35. var
  36. Form1: TForm1;
  37. implementation
  38. {$R *.lfm}
  39. { TForm1 }
  40. procedure TForm1.FormCreate(Sender: TObject);
  41. begin
  42. // Style drop down
  43. //UpdateStyle;
  44. end;
  45. procedure TForm1.RadioButtonChange(Sender: TObject);
  46. begin
  47. UpdateStyle;
  48. end;
  49. procedure TForm1.BCComboBox1Change(Sender: TObject);
  50. begin
  51. Label1.Caption := 'Changed to '+BCComboBox1.Text;
  52. end;
  53. procedure TForm1.Button1Click(Sender: TObject);
  54. var f: TForm1;
  55. begin
  56. Hide;
  57. f := TForm1.Create(nil);
  58. f.Button1.Visible := false;
  59. try
  60. f.ShowModal;
  61. finally
  62. f.Free;
  63. end;
  64. Close;
  65. end;
  66. procedure TForm1.CheckOnSameFormChange(Sender: TObject);
  67. begin
  68. BCComboBox1.DropDownOnSameForm:= not BCComboBox1.DropDownOnSameForm;
  69. end;
  70. procedure TForm1.OnBCComboBoxDrawItem(Control: TWinControl; Index: integer;
  71. ARect: TRect; State: TOwnerDrawState);
  72. var
  73. aCanvas: TCanvas;
  74. s: String;
  75. begin
  76. aCanvas := BCComboBox1.Canvas;
  77. s := BCComboBox1.Items[Index];
  78. // selected item
  79. if odChecked in State then s := '√ '+s;
  80. if odSelected in State then
  81. aCanvas.Brush.Color := clBlack
  82. else
  83. if odChecked in State then
  84. aCanvas.Brush.Color := $505050
  85. else
  86. aCanvas.Brush.Color := clGray;
  87. aCanvas.Font.Color := clWhite;
  88. aCanvas.FillRect(ARect);
  89. // mouse over
  90. if odSelected in State then
  91. begin
  92. aCanvas.Pen.Style := psSolid;
  93. aCanvas.Pen.Color := clRed;
  94. aCanvas.Rectangle(ARect);
  95. end;
  96. // vertically centered text
  97. aCanvas.TextRect(ARect, 15, ARect.Top +
  98. (ARect.Height - aCanvas.GetTextHeight(s)) div 2, s);
  99. end;
  100. procedure TForm1.ApplyFlashStyle;
  101. var
  102. prevFontHeight: Integer;
  103. begin
  104. prevFontHeight := BCCombobox1.StateNormal.FontEx.Height;
  105. StyleButtonsSample(BCComboBox1.Button, TBCSampleStyle.ssFlashPlayer);
  106. BCCombobox1.StateNormal.FontEx.Height := prevFontHeight;
  107. BCCombobox1.StateHover.FontEx.Height := prevFontHeight;
  108. BCCombobox1.StateClicked.FontEx.Height := prevFontHeight;
  109. BCComboBox1.DropDownColor := $606060;
  110. BCComboBox1.DropDownFontColor := $c0c0c0;
  111. BCComboBox1.DropDownBorderSize:= 2;
  112. BCComboBox1.DropDownBorderColor:= $404040;
  113. BCComboBox1.DropDownHighlight := $FC992E;
  114. BCComboBox1.DropDownFontHighlight := clWhite;
  115. BCComboBox1.OnDrawItem := nil;
  116. end;
  117. procedure TForm1.ApplyWin7Style;
  118. var
  119. prevFontHeight: Integer;
  120. begin
  121. prevFontHeight := BCCombobox1.StateNormal.FontEx.Height;
  122. StyleButtonsSample(BCComboBox1.Button, TBCSampleStyle.ssWindows7);
  123. BCCombobox1.StateNormal.FontEx.Height := prevFontHeight;
  124. BCCombobox1.StateHover.FontEx.Height := prevFontHeight;
  125. BCCombobox1.StateClicked.FontEx.Height := prevFontHeight;
  126. BCComboBox1.DropDownColor := clWhite;
  127. BCComboBox1.DropDownFontColor := clBlack;
  128. BCComboBox1.DropDownBorderSize:= 1;
  129. BCComboBox1.DropDownBorderColor:= clBlack;
  130. BCComboBox1.DropDownHighlight := $FC992E;
  131. BCComboBox1.DropDownFontHighlight := clWhite;
  132. BCComboBox1.OnDrawItem := nil;
  133. end;
  134. procedure TForm1.ApplyCustomStyle;
  135. var
  136. prevFontHeight: Integer;
  137. begin
  138. prevFontHeight := BCCombobox1.StateNormal.FontEx.Height;
  139. StyleButtonsSample(BCComboBox1.Button, TBCSampleStyle.ssMacOSXLion);
  140. BCCombobox1.StateNormal.FontEx.Height := prevFontHeight;
  141. BCCombobox1.StateHover.FontEx.Height := prevFontHeight;
  142. BCCombobox1.StateClicked.FontEx.Height := prevFontHeight;
  143. BCComboBox1.DropDownColor := clGray;
  144. BCComboBox1.DropDownBorderSize:= 3;
  145. BCComboBox1.DropDownBorderColor:= clGreen;
  146. BCComboBox1.OnDrawItem := @OnBCComboBoxDrawItem;
  147. Canvas.Font.Height := BCComboBox1.StateNormal.FontEx.Height;
  148. BCComboBox1.ItemHeight := 2*Canvas.GetTextHeight('aq');
  149. end;
  150. procedure TForm1.ApplyDefaultStyle;
  151. var
  152. prevFontHeight: Integer;
  153. begin
  154. prevFontHeight := BCCombobox1.StateNormal.FontEx.Height;
  155. StyleButtonsSample(BCComboBox1.Button, TBCSampleStyle.ssDefault);
  156. BCCombobox1.StateNormal.FontEx.Height := prevFontHeight;
  157. BCCombobox1.StateHover.FontEx.Height := prevFontHeight;
  158. BCCombobox1.StateClicked.FontEx.Height := prevFontHeight;
  159. BCComboBox1.DropDownBorderColor := $00400000;
  160. BCComboBox1.DropDownBorderSize:= 1;
  161. BCComboBox1.DropDownColor := $00804040;
  162. BCComboBox1.DropDownFontColor := $00FFE6E6;
  163. BCComboBox1.DropDownFontHighlight := clWhite;
  164. BCComboBox1.DropDownHighlight := $00FF8000;
  165. BCComboBox1.OnDrawItem := nil;
  166. end;
  167. procedure TForm1.UpdateStyle;
  168. begin
  169. if RadioWin7.Checked then ApplyWin7Style
  170. else if RadioFlash.Checked then ApplyFlashStyle
  171. else if RadioCustom.Checked then ApplyCustomStyle
  172. else ApplyDefaultStyle;
  173. end;
  174. end.