SkinCtrls.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:456k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1.           Result := CorrectResizeRect;
  2.       end;
  3.     2:
  4.       begin
  5.         if (R.Left <= LTPt.X) and (R.Right >= RTPt.X)
  6.         then
  7.           Inc(Result.Right, XO)
  8.         else
  9.         if (R.Left >= RTPt.X) and (R.Right > RTPt.X)
  10.         then
  11.           OffsetRect(Result, XO, 0);
  12.       end;
  13.      3:
  14.       begin
  15.         if (R.Top <= LTPt.Y) and (R.Bottom >= LBPt.Y)
  16.         then
  17.           Inc(Result.Bottom, YO)
  18.         else
  19.           if (R.Top >= LBPt.Y) and (R.Bottom > LBPt.X)
  20.           then
  21.             OffsetRect(Result, 0, YO);
  22.       end;
  23.   end;
  24. end;
  25. procedure TspSkinCustomControl.GetSkinData;
  26. begin
  27.   inherited;
  28.   if FIndex <> -1
  29.   then
  30.     if TspDataSkinControl(FSD.CtrlList.Items[FIndex]) is TspDataSkinCustomControl
  31.     then
  32.       with TspDataSkinCustomControl(FSD.CtrlList.Items[FIndex]) do
  33.       begin
  34.         LTPt := LTPoint;
  35.         RTPt := RTPoint;
  36.         LBPt := LBPoint;
  37.         RBPt := RBPoint;
  38.         Self.SkinRect := SkinRect;
  39.         Self.ClRect := ClRect;
  40.         Self.CursorIndex := CursorIndex;
  41.         if (PictureIndex <> -1) and (PictureIndex < FSD.FActivePictures.Count)
  42.         then
  43.           Picture := TBitMap(FSD.FActivePictures.Items[PictureIndex])
  44.         else
  45.           Picture := nil;
  46.         if (MaskPictureIndex <> -1) and (MaskPictureIndex < FSD.FActivePictures.Count)
  47.         then
  48.           MaskPicture := TBitMap(FSD.FActivePictures.Items[MaskPictureIndex])
  49.         else
  50.           MaskPicture := nil;
  51.         ResizeMode := GetResizeMode;
  52.       end
  53.     else
  54.       begin
  55.         ResizeMode := 0;
  56.         Picture := nil;
  57.         MaskPicture := nil;
  58.       end;
  59. end;
  60. procedure TspSkinCustomControl.CreateControlRegion;
  61. var
  62.   TempRgn: HRGN;
  63.   Offset: Integer;
  64. begin
  65.   TempRgn := FRgn;
  66.   case ResizeMode of
  67.     0:
  68.       CreateSkinSimplyRegion(FRgn, MaskPicture);
  69.     1:
  70.       CreateSkinRegion
  71.        (FRgn, LTPt, RTPt, LBPt, RBPt, ClRect,
  72.         NewLtPoint, NewRTPoint, NewLBPoint, NewRBPoint, NewClRect,
  73.         MaskPicture, Width, Height);
  74.     2:
  75.       begin
  76.         Offset := Width - RectWidth(SkinRect);
  77.         CreateSkinRegion(FRgn,
  78.           LTPt, RTPt, LTPt, RTPt, ClRect,
  79.           LTPt, Point(RTPt.X + Offset, RTPt.Y),
  80.           LTPt, Point(RTPt.X + Offset, RTPt.Y), NewClRect,
  81.           MaskPicture, Width, Height);
  82.       end;
  83.     3:
  84.       begin
  85.         Offset := Height - RectHeight(SkinRect);
  86.         CreateSkinRegion(FRgn,
  87.           LTPt, LTPt, LBPt, LBPt, ClRect,
  88.           LTPt, LTPt,
  89.           Point(LBPt.X, LBPt.Y + Offset),
  90.           Point(LBPt.X, LBPt.Y + Offset), NewClRect,
  91.           MaskPicture, Width, Height);
  92.       end;
  93.   end;
  94.   SetWindowRgn(Handle, FRgn, True);
  95.   if TempRgn <> 0 then DeleteObject(TempRgn);
  96. end;
  97. procedure TspSkinCustomControl.SetControlRegion;
  98. begin
  99.   if ((MaskPicture = nil) or (FIndex = -1)) and (FRgn <> 0)
  100.   then
  101.     begin
  102.       SetWindowRgn(Handle, 0, True);
  103.       DeleteObject(FRgn);
  104.       FRgn := 0;
  105.     end
  106.   else
  107.     if (MaskPicture <> nil) and (FIndex <> -1)
  108.     then CreateControlRegion;
  109. end;
  110. //=========== TspSkinButton ===============
  111. constructor TspSkinButton.Create;
  112. begin
  113.   inherited;
  114.   RepeatTimer := nil;
  115.   FRepeatMode := False;
  116.   FRepeatInterval := 100;
  117.   FActive := False;
  118.   FSkinDataName := 'button';
  119.   FCanFocused := True;
  120.   TabStop := True;
  121.   FDown := False;
  122.   FMouseDown := False;
  123.   FMouseIn := False;
  124.   Width := 75;
  125.   Height := 25;
  126.   FGroupIndex := 0;
  127.   FGlyph := TBitMap.Create;
  128.   FNumGlyphs := 2;
  129.   FMargin := -1;
  130.   FSpacing := 1;
  131.   FLayout := blGlyphLeft;
  132.   FMorphKf := 0;
  133.   MorphTimer := nil;
  134.   Morphing := False;
  135.   FMorphKf := 0;
  136.   FAllowAllUp := False;
  137.   FAllowAllUpCheck := False;
  138. end;
  139. destructor TspSkinButton.Destroy;
  140. begin
  141.   FGlyph.Free;
  142.   StopMorph;
  143.   inherited;
  144. end;
  145. procedure TspSkinButton.RepeatTimerProc;
  146. begin
  147.   ButtonClick;
  148. end;
  149. procedure TspSkinButton.StartRepeat;
  150. begin
  151.   if RepeatTimer <> nil then RepeatTimer.Free;
  152.   RepeatTimer := TTimer.Create(Self);
  153.   RepeatTimer.Enabled := False;
  154.   RepeatTimer.OnTimer := RepeatTimerProc;
  155.   RepeatTimer.Interval := FRepeatInterval;
  156.   RepeatTimer.Enabled := True;
  157. end;
  158. procedure TspSkinButton.StopRepeat;
  159. begin
  160.   RepeatTimer.Enabled := False;
  161.   RepeatTimer.Free;
  162.   RepeatTimer := nil;
  163. end;
  164. procedure TspSkinButton.CreateWnd;
  165. begin
  166.   inherited CreateWnd;
  167.   FActive := FDefault;
  168. end;
  169. procedure TspSkinButton.CMEnabledChanged;
  170. begin
  171.   inherited;
  172.   if Morphing
  173.   then
  174.     begin
  175.       StopMorph;
  176.       FMorphKf := 0;
  177.     end;
  178.   FMouseIn := False;
  179.   RePaint;
  180. end;
  181. procedure TspSkinButton.StartMorph;
  182. begin
  183.   if MorphTimer <> nil then Exit;
  184.   MorphTimer := TTimer.Create(Self);
  185.   MorphTimer.Interval := MorphTimerInterval;
  186.   MorphTimer.OnTimer := DoMorph;
  187.   MorphTimer.Enabled := True;
  188. end;
  189. procedure TspSkinButton.StopMorph;
  190. begin
  191.   if MorphTimer = nil then Exit;
  192.   MorphTimer.Free;
  193.   MorphTimer := nil;
  194. end;
  195. procedure TspSkinButton.CMDialogKey(var Message: TCMDialogKey);
  196. begin
  197.   with Message do
  198.    if FActive and (CharCode = VK_RETURN) and Enabled
  199.    then
  200.      begin
  201.        ButtonClick;
  202.        Result := 1;
  203.      end
  204.    else
  205.    if (CharCode = VK_ESCAPE) and FCancel and FCanFocused and
  206.       (KeyDataToShiftState(Message.KeyData) = []) and CanFocus
  207.    then
  208.      begin
  209.        ButtonClick;
  210.        Result := 1;
  211.      end
  212.    else
  213.      inherited;
  214. end;
  215. procedure TspSkinButton.CMFocusChanged(var Message: TCMFocusChanged);
  216. begin
  217.   with Message do
  218.    if Sender is TspSkinButton then
  219.       FActive := Sender = Self
  220.    else
  221.      FActive := FDefault;
  222.   if FCanFocused and FDefault
  223.   then
  224.     if (Message.Sender <> Self) and (Message.Sender is TspSkinButton)
  225.     then
  226.       begin
  227.         FMouseIn := False;
  228.         ReDrawControl;
  229.       end
  230.     else
  231.     if (Message.Sender <> Self) and not (Message.Sender is TspSkinButton)
  232.     then
  233.       begin
  234.         FMouseIn := True;
  235.         if Morphing then FMorphKf := 1;
  236.         RePaint;
  237.       end;
  238.   inherited;
  239. end;
  240. procedure TspSkinButton.ButtonClick;
  241. var
  242.   Form: TCustomForm;
  243. begin
  244.   if FCanFocused
  245.   then
  246.     begin
  247.       Form := GetParentForm(Self);
  248.       if Form <> nil then Form.ModalResult := ModalResult;
  249.     end;
  250.   if Assigned(FOnClick) then FOnClick(Self);
  251. end;
  252. procedure TspSkinButton.SetDefault(Value: Boolean);
  253. var
  254.   Form: TCustomForm;
  255. begin
  256.   FDefault := Value;
  257.   if HandleAllocated and FCanFocused and not (csDesigning in ComponentState)
  258.   then
  259.     begin
  260.       Form := GetParentForm(Self);
  261.       if Form <> nil then
  262.         Form.Perform(CM_FOCUSCHANGED, 0, Longint(Form.ActiveControl));
  263.     end;
  264. end;
  265. procedure TspSkinButton.ChangeSkinData;
  266. begin
  267.   StopMorph;
  268.   inherited;
  269.   if Morphing and (FIndex <> -1) and (IsFocused or FMouseIn)
  270.   then
  271.     FMorphKf := 1;
  272. end;
  273. procedure TspSkinButton.SetGroupIndex;
  274. begin
  275.   FGroupIndex := Value;
  276.   if FGroupIndex <> 0 then CanFocused := False;
  277. end;
  278. function TspSkinButton.IsFocused;
  279. begin
  280.   Result := Focused and FCanFocused;
  281. end;
  282. procedure TspSkinButton.CMDialogChar;
  283. begin
  284.   with Message do
  285.     if IsAccel(CharCode, Caption) and CanFocus and FCanFocused
  286.     then
  287.       begin
  288.         SetFocus;
  289.         ButtonClick;
  290.         Result := 1;
  291.       end
  292.     else
  293.      inherited;
  294. end;
  295. procedure TspSkinButton.SetCanFocused;
  296. begin
  297.   FCanFocused := Value;
  298.   if (csDesigning in ComponentState) and not
  299.      (csLoading in ComponentState)
  300.   then
  301.     TabStop := FCanFocused;
  302. end;
  303. procedure TspSkinButton.WMSETFOCUS;
  304. begin
  305.   inherited;
  306.   if FCanFocused then ReDrawControl;
  307. end;
  308. procedure TspSkinButton.WMKILLFOCUS;
  309. begin
  310.   inherited;
  311.   if FCanFocused then ReDrawControl;
  312. end;
  313. procedure TspSkinButton.WndProc(var Message: TMessage);
  314. begin
  315.   if FCanFocused then
  316.   case Message.Msg of
  317.     WM_KEYDOWN:
  318.       if TWMKEYDOWN(Message).CharCode = VK_SPACE
  319.       then
  320.         begin
  321.           Down := True;
  322.           if FRepeatMode then ButtonClick;
  323.         end
  324.       else
  325.       if TWMKEYDOWN(Message).CharCode = VK_RETURN
  326.       then
  327.         begin
  328.           ButtonClick;
  329.         end;
  330.     WM_KEYUP:
  331.       if TWMKEYUP(Message).CharCode = VK_SPACE
  332.       then
  333.         begin
  334.           Down := False;
  335.           ButtonClick;
  336.         end;
  337.     WM_LBUTTONDOWN, WM_LBUTTONDBLCLK:
  338.       if not (csDesigning in ComponentState) and not Focused then
  339.       begin
  340.         FClicksDisabled := True;
  341.         Windows.SetFocus(Handle);
  342.         FClicksDisabled := False;
  343.         if not Focused then Exit;
  344.       end;
  345.     CN_COMMAND:
  346.       if FClicksDisabled then Exit;
  347.   end;
  348.   inherited WndProc(Message);
  349. end;
  350. procedure TspSkinButton.ActionChange(Sender: TObject; CheckDefaults: Boolean);
  351.   procedure CopyImage(ImageList: TCustomImageList; Index: Integer);
  352.   begin
  353.     with FGlyph do
  354.     begin
  355.       Width := ImageList.Width;
  356.       Height := ImageList.Height;
  357.       Canvas.Brush.Color := clFuchsia;
  358.       Canvas.FillRect(Rect(0, 0, Width, Height));
  359.       ImageList.Draw(Canvas, 0, 0, Index);
  360.     end;
  361.   end;
  362. begin
  363.   inherited ActionChange(Sender, CheckDefaults);
  364.   if Sender is TCustomAction then
  365.     with TCustomAction(Sender) do
  366.     begin
  367.       if (FGlyph.Empty) and (ActionList <> nil) and (ActionList.Images <> nil) and
  368.         (ImageIndex >= 0) and (ImageIndex < ActionList.Images.Count) then
  369.       begin
  370.         CopyImage(ActionList.Images, ImageIndex);
  371.         RePaint;
  372.       end;
  373.     end;
  374. end;
  375. procedure TspSkinButton.ReDrawControl;
  376. begin
  377.   if Morphing and (FIndex <> -1)
  378.   then StartMorph
  379.   else RePaint;
  380. end;
  381. procedure TspSkinButton.DoMorph;
  382. begin
  383.   if (FIndex = -1) or not Morphing
  384.   then
  385.     begin
  386.       if (FMouseIn or IsFocused) then FMorphKf := 1 else FMorphKf := 0;
  387.       StopMorph;
  388.     end
  389.   else
  390.   if (FMouseIn or IsFocused) and (FMorphKf < 1)
  391.   then
  392.     begin
  393.       FMorphKf := FMorphKf + 0.1;
  394.       RePaint;
  395.     end
  396.   else
  397.   if not (FMouseIn or IsFocused) and (FMorphKf > 0)
  398.   then
  399.     begin
  400.       FMorphKf := FMorphKf - 0.1;
  401.       RePaint;
  402.     end
  403.   else
  404.     begin
  405.       if (FMouseIn or IsFocused) then FMorphKf := 1 else FMorphKf := 0;
  406.       StopMorph;
  407.       RePaint;
  408.     end;
  409. end;
  410. procedure TspSkinButton.SetLayout;
  411. begin
  412.   if FLayout <> Value
  413.   then
  414.     begin
  415.       FLayout := Value;
  416.       RePaint;
  417.     end;  
  418. end;
  419. procedure TspSkinButton.SetSpacing;
  420. begin
  421.   if Value <> FSpacing
  422.   then
  423.     begin
  424.       FSpacing := Value;
  425.       RePaint;
  426.     end;
  427. end;
  428. procedure TspSkinButton.SetMargin;
  429. begin
  430.   if (Value <> FMargin) and (Value >= -1)
  431.   then
  432.     begin
  433.       FMargin := Value;
  434.       RePaint;
  435.     end;
  436. end;
  437. procedure TspSkinButton.SetDown;
  438. begin
  439.   FDown := Value;
  440.   if Morphing
  441.   then
  442.      begin
  443.        FMorphKf := 1;
  444.        if not FDown then StartMorph else StopMorph; 
  445.      end;
  446.   RePaint;
  447.   if (GroupIndex <> 0) and FDown and not FAllowAllUp then DoAllUp;
  448. end;
  449. procedure TspSkinButton.DoAllUp;
  450. var
  451.   PC: TWinControl;
  452.   i: Integer;
  453. begin
  454.   if Parent = nil then Exit;
  455.   PC := TWinControl(Parent);
  456.   for i := 0 to PC.ControlCount - 1 do
  457.    if (PC.Controls[i] is TspSkinButton) and
  458.       (PC.Controls[i] <> Self)
  459.    then
  460.      with TspSkinButton(PC.Controls[i]) do
  461.        if (GroupIndex = Self.GroupIndex) and
  462.           (GroupIndex <> 0) and FDown
  463.        then
  464.          Down := False;
  465. end;
  466. procedure TspSkinButton.SetGlyph;
  467. begin
  468.   FGlyph.Assign(Value);
  469.   RePaint;
  470. end;
  471. procedure TspSkinButton.SetNumGlyphs;
  472. begin
  473.   FNumGlyphs := Value;
  474.   RePaint;
  475. end;
  476. procedure TspSkinButton.GetSkinData;
  477. begin
  478.   inherited;
  479.   if FIndex <> -1
  480.   then
  481.     begin
  482.       if TspDataSkinControl(FSD.CtrlList.Items[FIndex]) is TspDataSkinButtonControl
  483.       then
  484.         with TspDataSkinButtonControl(FSD.CtrlList.Items[FIndex]) do
  485.         begin
  486.           Self.FontName := FontName;
  487.           Self.FontColor := FontColor;
  488.           Self.ActiveFontColor := ActiveFontColor;
  489.           Self.DownFontColor := DownFontColor;
  490.           Self.FontStyle := FontStyle;
  491.           Self.FontHeight := FontHeight;
  492.           Self.ActiveSkinRect := ActiveSkinRect;
  493.           Self.DownSkinRect := DownSkinRect;
  494.           Self.Morphing := Morphing;
  495.           Self.MorphKind := MorphKind;
  496.           if IsNullRect(ActiveSkinRect) then Self.ActiveSkinRect := SkinRect;
  497.           if IsNullRect(DownSkinRect) then Self.DownSkinRect := Self.ActiveSkinRect;
  498.           Self.DisabledSkinRect := DisabledSkinRect;
  499.           Self.DisabledFontColor := DisabledFontColor;
  500.         end;
  501.    end
  502.  else
  503.    begin
  504.      Morphing := False;
  505.    end;
  506. end;
  507. procedure TspSkinButton.CreateButtonImage(B: TBitMap; R: TRect;
  508.   ADown, AMouseIn: Boolean);
  509. function GetGlyphNum: Integer;
  510. begin
  511.   if ADown and AMouseIn and (FNumGlyphs > 2)
  512.   then
  513.     Result := 3
  514.   else
  515.   if AMouseIn and (FNumGlyphs > 3)
  516.   then
  517.     Result := 4
  518.   else
  519.     if not Enabled and (FNumGlyphs > 1)
  520.     then
  521.       Result := 2
  522.     else
  523.       Result := 1;
  524. end;
  525. begin
  526.   CreateSkinControlImage(B, Picture, R);
  527.   if not FUseSkinFont
  528.   then
  529.     B.Canvas.Font.Assign(FDefaultFont)
  530.   else
  531.     with B.Canvas.Font do
  532.     begin
  533.       Name := FontName;
  534.       Height := FontHeight;
  535.       Style := FontStyle;
  536.       CharSet := FDefaultFont.Charset;
  537.     end;
  538.   with B.Canvas.Font do
  539.   begin
  540.     if not Enabled
  541.     then
  542.       Color := DisabledFontColor
  543.     else
  544.     if ADown and AMouseIn
  545.     then
  546.       Color := DownFontColor
  547.     else
  548.       if AMouseIn
  549.       then Color := ActiveFontColor
  550.       else Color := FontColor;
  551.   end;
  552.   DrawGlyphAndText(B.Canvas,
  553.     NewClRect, FMargin, FSpacing, FLayout,
  554.     Caption, FGlyph, FNumGlyphs, GetGlyphNum,  ADown and AMouseIn);
  555. end;
  556. procedure TspSkinButton.CreateControlDefaultImage;
  557. var
  558.   R: TRect;
  559.   IsDown: Boolean;
  560. begin
  561.   inherited;
  562.   IsDown := False;
  563.   R := ClientRect;
  564.   B.Canvas.Font.Assign(FDefaultFont);
  565.   if not Enabled then B.Canvas.Font.Color := clBtnShadow;
  566.   if FDown and (((FMouseIn or (IsFocused and not FMouseDown)) and
  567.      (GroupIndex = 0)) or (GroupIndex  <> 0))
  568.   then
  569.     begin
  570.       Frame3D(B.Canvas, R, SP_XP_BTNFRAMECOLOR, SP_XP_BTNFRAMECOLOR, 1);
  571.       B.Canvas.Brush.Color := SP_XP_BTNDOWNCOLOR;
  572.       B.Canvas.FillRect(R);
  573.       IsDown := True;
  574.     end
  575.   else
  576.     if FMouseIn or IsFocused
  577.     then
  578.       begin
  579.         Frame3D(B.Canvas, R, SP_XP_BTNFRAMECOLOR, SP_XP_BTNFRAMECOLOR, 1);
  580.         B.Canvas.Brush.Color := SP_XP_BTNACTIVECOLOR;
  581.         B.Canvas.FillRect(R);
  582.       end
  583.     else
  584.       begin
  585.         Frame3D(B.Canvas, R, clBtnShadow, clBtnShadow, 1);
  586.         B.Canvas.Brush.Color := clBtnFace;
  587.         B.Canvas.FillRect(R);
  588.       end;
  589.   DrawGlyphAndText(B.Canvas,
  590.     ClientRect, FMargin, FSpacing, FLayout,
  591.     Caption, FGlyph, FNumGlyphs, 1, IsDown);
  592. end;
  593. procedure TspSkinButton.CreateControlSkinImage;
  594. begin
  595. end;
  596. procedure TspSkinButton.Paint;
  597. var
  598.   PBuffer, APBuffer, PIBuffer: TspEffectBmp;
  599.   ParentImage, Buffer, ABuffer: TBitMap;
  600.   kf: Double;
  601. begin
  602.   GetSkinData;
  603.   if FIndex = -1
  604.   then
  605.     inherited
  606.   else
  607.     begin
  608.       Buffer := TBitMap.Create;
  609.       Buffer.Width := Width;
  610.       Buffer.Height := Height;
  611.       ParentImage := nil;
  612.       if FAlphaBlend
  613.       then
  614.         begin
  615.           ParentImage := TBitMap.Create;
  616.           ParentImage.Width := Width;
  617.           ParentImage.Height := Height;
  618.           GetParentImage(Self, ParentImage.Canvas);
  619.           PIBuffer := TspEffectBmp.CreateFromhWnd(ParentImage.Handle);
  620.           kf := 1 - FAlphaBlendValue / 255;
  621.         end;
  622.       if Morphing and (FMorphKf <> 1) and (FMorphKf <> 0) and Enabled
  623.       then
  624.         begin
  625.           ABuffer := TBitMap.Create;
  626.           ABuffer.Width := Width;
  627.           ABuffer.Height := Height;
  628.           CreateButtonImage(Buffer, SkinRect, False, False);
  629.           CreateButtonImage(ABuffer, ActiveSkinRect, False, True);
  630.           PBuffer := TspEffectBmp.CreateFromhWnd(Buffer.Handle);
  631.           APBuffer := TspEffectBmp.CreateFromhWnd(ABuffer.Handle);
  632.           case MorphKind of
  633.             mkDefault: PBuffer.Morph(APBuffer, FMorphKf);
  634.             mkGradient: PBuffer.MorphGrad(APBuffer, FMorphKf);
  635.             mkLeftGradient: PBuffer.MorphLeftGrad(APBuffer, FMorphKf);
  636.             mkRightGradient: PBuffer.MorphRightGrad(APBuffer, FMorphKf);
  637.             mkLeftSlide: PBuffer.MorphLeftSlide(APBuffer, FMorphKf);
  638.             mkRightSlide: PBuffer.MorphRightSlide(APBuffer, FMorphKf);
  639.             mkPush: PBuffer.MorphPush(APBuffer, FMorphKf);
  640.           end;
  641.           if FAlphaBlend then PBuffer.Morph(PIBuffer, Kf);
  642.           PBuffer.Draw(Canvas.Handle, 0, 0);
  643.           PBuffer.Free;
  644.           APBuffer.Free;
  645.           ABuffer.Free;
  646.         end
  647.       else
  648.         begin
  649.           if (not Enabled) and not IsNullRect(DisabledSkinRect)
  650.           then
  651.             CreateButtonImage(Buffer, DisabledSkinRect, False, False)
  652.           else
  653.           if FDown and (((FMouseIn or (IsFocused and not FMouseDown)) and
  654.             (GroupIndex = 0)) or (GroupIndex  <> 0))
  655.           then
  656.             CreateButtonImage(Buffer, DownSkinRect, True, True)
  657.           else
  658.             if (IsFocused or FMouseIn) or (not (IsFocused or FMouseIn) and
  659.                 Morphing and (FMorphKf = 1))
  660.             then
  661.               CreateButtonImage(Buffer, ActiveSkinRect, False, True)
  662.             else
  663.               CreateButtonImage(Buffer, SkinRect, False, False);
  664.           if FAlphaBlend
  665.           then
  666.             begin
  667.               PBuffer := TspEffectBmp.CreateFromhWnd(Buffer.Handle);
  668.               PBuffer.Morph(PIBuffer, Kf);
  669.               PBuffer.Draw(Canvas.Handle, 0, 0);
  670.               PBuffer.Free;
  671.              end
  672.           else
  673.             Canvas.Draw(0, 0, Buffer);
  674.         end;
  675.       if FAlphaBlend
  676.       then
  677.         begin
  678.           PIBuffer.Free;
  679.           ParentImage.Free;
  680.         end;
  681.       Buffer.Free;
  682.     end;
  683. end;
  684. procedure TspSkinButton.CMTextChanged;
  685. begin
  686.   if (FIndex <> -1) or
  687.      (csDesigning in ComponentState) or DrawDefault
  688.   then
  689.     RePaint;
  690. end;
  691. procedure TspSkinButton.CMMouseEnter(var Message: TMessage);
  692. var
  693.   CanPaint: Boolean;
  694. begin
  695.   inherited;
  696.   FMouseIn := True;
  697.   if GroupIndex <> 0
  698.   then
  699.     CanPaint := not FDown
  700.   else
  701.     CanPaint := not IsFocused or FDown;
  702.   if CanPaint
  703.   then
  704.     begin
  705.       if FDown
  706.       then
  707.         begin
  708.           if Morphing then FMorphKf := 1; 
  709.           RePaint;
  710.         end  
  711.       else
  712.         ReDrawControl;
  713.     end;
  714.   if FDown and FRepeatMode and (GroupIndex = 0) then StartRepeat;
  715. end;
  716. procedure TspSkinButton.CMMouseLeave(var Message: TMessage);
  717. var
  718.   CanPaint: Boolean;
  719. begin
  720.   inherited;
  721.   if not (FCanFocused and FDefault and FActive and not Focused)
  722.   then
  723.     FMouseIn := False;
  724.   if GroupIndex <> 0
  725.   then
  726.     CanPaint := not FDown
  727.   else
  728.     CanPaint := not IsFocused or FDown;
  729.   if CanPaint
  730.   then ReDrawControl;
  731.   if FDown and FRepeatMode and (GroupIndex = 0) then StopRepeat;
  732. end;
  733. procedure TspSkinButton.MouseDown;
  734. begin
  735.   inherited;
  736.   if Button = mbLeft
  737.   then
  738.     begin
  739.       FMouseDown := True;
  740.       if not FDown
  741.       then
  742.         begin
  743.           FMouseIn := True;
  744.           Down := True;
  745.           if FRepeatMode and (GroupIndex = 0)
  746.           then
  747.             StartRepeat
  748.           else
  749.             if (GroupIndex <> 0) then ButtonClick;
  750.           FAllowAllUpCheck := False;
  751.         end
  752.       else
  753.         if (GroupIndex <> 0) then FAllowAllUpCheck := True;
  754.     end;
  755. end;
  756. procedure TspSkinButton.MouseUp;
  757. begin
  758.   if Button = mbLeft
  759.   then
  760.     begin
  761.       FMouseDown := False;
  762.       if GroupIndex = 0
  763.       then
  764.         begin
  765.           if FMouseIn
  766.           then
  767.             begin
  768.               Down := False;
  769.               if FRepeatMode then StopRepeat;
  770.               ButtonClick;
  771.             end
  772.             else
  773.               begin
  774.                 FDown := False;
  775.                 if FRepeatMode and (RepeatTimer <> nil) then StopRepeat;
  776.               end;
  777.         end
  778.       else
  779.         if (GroupIndex <> 0) and FDown and FAllowAllUp and
  780.            FAllowAllUpCheck and FMouseIn
  781.         then
  782.           begin
  783.             Down := False;
  784.             ButtonClick;
  785.           end;  
  786.     end;
  787.   inherited;
  788. end;
  789. //==============TspSkinMenuButton==========//
  790. constructor TspSkinMenuButton.Create;
  791. begin
  792.   inherited;
  793.   FSkinDataName := 'toolmenubutton';
  794.   FTrackButtonMode := False;
  795.   FMenuTracked := False;
  796.   FSkinPopupMenu := nil;
  797. end;
  798. destructor TspSkinMenuButton.Destroy;
  799. begin
  800.   inherited;
  801. end;
  802. procedure TspSkinMenuButton.CreateButtonImage;
  803. begin
  804.   if FMenuTracked and FTrackButtonMode and
  805.      not IsNullRect(TrackButtonRect) and not IsNullRect(DownSkinRect)
  806.   then
  807.     begin
  808.       inherited CreateButtonImage(B, ActiveSkinRect, False, True);
  809.       R := TrackButtonRect;
  810.       OffsetRect(R, DownSkinRect.Left, DownSkinRect.Top);
  811.         B.Canvas.CopyRect(GetNewTrackButtonRect, Picture.Canvas,
  812.        R);
  813.     end
  814.   else
  815.     inherited;
  816. end;
  817. procedure TspSkinMenuButton.CreateControlDefaultImage;
  818. var
  819.   R, R1: TRect;
  820.   isDown: Boolean;
  821. begin
  822.   IsDown := False;
  823.   if FTrackButtonMode
  824.   then
  825.     begin
  826.       R := Rect(0, 0, Width - 15, Height);
  827.       R1 := Rect(Width - 15, 0, Width, Height);
  828.       if FMenuTracked
  829.       then
  830.         begin
  831.           Frame3D(B.Canvas, R, SP_XP_BTNFRAMECOLOR, SP_XP_BTNFRAMECOLOR, 1);
  832.           B.Canvas.Brush.Color := SP_XP_BTNACTIVECOLOR;
  833.           B.Canvas.FillRect(R);
  834.           Frame3D(B.Canvas, R1, SP_XP_BTNFRAMECOLOR, SP_XP_BTNFRAMECOLOR, 1);
  835.           B.Canvas.Brush.Color := SP_XP_BTNDOWNCOLOR;
  836.           B.Canvas.FillRect(R1);
  837.         end
  838.       else
  839.         begin
  840.           if FDown and FMouseIn
  841.           then
  842.             begin
  843.               Frame3D(B.Canvas, R, SP_XP_BTNFRAMECOLOR, SP_XP_BTNFRAMECOLOR, 1);
  844.               B.Canvas.Brush.Color := SP_XP_BTNDOWNCOLOR;
  845.               B.Canvas.FillRect(R);
  846.               Frame3D(B.Canvas, R1, SP_XP_BTNFRAMECOLOR, SP_XP_BTNFRAMECOLOR, 1);
  847.               B.Canvas.Brush.Color := SP_XP_BTNDOWNCOLOR;
  848.               B.Canvas.FillRect(R1);
  849.               isDown := True;
  850.             end
  851.           else
  852.           if FMouseIn or IsFocused
  853.           then
  854.             begin
  855.               Frame3D(B.Canvas, R, SP_XP_BTNFRAMECOLOR, SP_XP_BTNFRAMECOLOR, 1);
  856.               B.Canvas.Brush.Color := SP_XP_BTNACTIVECOLOR;
  857.               B.Canvas.FillRect(R);
  858.               Frame3D(B.Canvas, R1, SP_XP_BTNFRAMECOLOR, SP_XP_BTNFRAMECOLOR, 1);
  859.               B.Canvas.Brush.Color := SP_XP_BTNACTIVECOLOR;
  860.               B.Canvas.FillRect(R1);
  861.             end
  862.           else
  863.             begin
  864.               Frame3D(B.Canvas, R, clBtnShadow, clBtnShadow, 1);
  865.               B.Canvas.Brush.Color := clBtnFace;
  866.               B.Canvas.FillRect(R);
  867.               Frame3D(B.Canvas, R1, clBtnShadow, clBtnShadow, 1);
  868.               B.Canvas.Brush.Color := clBtnFace;
  869.               B.Canvas.FillRect(R1);
  870.             end;
  871.         end;
  872.     end
  873.   else
  874.     begin
  875.       R := Rect(0, 0, Width, Height);
  876.       if FDown and FMouseIn
  877.       then
  878.         begin
  879.           Frame3D(B.Canvas, R, SP_XP_BTNFRAMECOLOR, SP_XP_BTNFRAMECOLOR, 1);
  880.           B.Canvas.Brush.Color := SP_XP_BTNDOWNCOLOR;
  881.           B.Canvas.FillRect(R);
  882.         end
  883.       else
  884.         if FMouseIn or IsFocused
  885.         then
  886.           begin
  887.             Frame3D(B.Canvas, R, SP_XP_BTNFRAMECOLOR, SP_XP_BTNFRAMECOLOR, 1);
  888.             B.Canvas.Brush.Color := SP_XP_BTNACTIVECOLOR;
  889.             B.Canvas.FillRect(R);
  890.           end
  891.        else
  892.          begin
  893.            Frame3D(B.Canvas, R, clBtnShadow, clBtnShadow, 1);
  894.            B.Canvas.Brush.Color := clBtnFace;
  895.            B.Canvas.FillRect(R);
  896.          end;
  897.     end;
  898.   R := ClientRect;
  899.   Dec(R.Right, 15);
  900.   B.Canvas.Font.Assign(FDefaultFont);
  901.   if not Enabled then B.Canvas.Font.Color := clBtnShadow;
  902.   DrawGlyphAndText(B.Canvas, R, FMargin, FSpacing, FLayout,
  903.                   Caption, FGlyph, FNumGlyphs, 1,  isDown);
  904.   R.Left := Width - 15;
  905.   Inc(R.Right, 15);
  906.   if (FDown and FMouseIn) or FMenuTracked
  907.   then
  908.     begin
  909.       Inc(R.Top, 2);
  910.       Inc(R.Left, 2);
  911.     end;
  912.   DrawTrackArrowImage(B.Canvas, R, clBtnText);
  913. end;
  914. procedure TspSkinMenuButton.CMDialogChar;
  915. begin
  916.   if not FTrackButtonMode and CanMenuTrack(0, 0)
  917.   then
  918.     begin
  919.       with Message do
  920.       if IsAccel(CharCode, Caption) and CanFocus and FCanFocused
  921.       then
  922.         begin
  923.           SetFocus;
  924.           FMenuTracked := True;
  925.           Down := True;
  926.           TrackMenu;
  927.           Result := 1;
  928.         end
  929.       else
  930.         inherited;
  931.     end
  932.   else
  933.     inherited;  
  934. end;
  935. procedure TspSkinMenuButton.WndProc;
  936. var
  937.   FOld: Boolean;
  938. begin
  939.   FOld := True;
  940.   if FCanFocused then
  941.   case Message.Msg of
  942.     WM_KEYDOWN:
  943.       if TWMKEYDOWN(Message).CharCode = VK_SPACE
  944.       then
  945.         begin
  946.           if not FTrackButtonMode and CanMenuTrack(0, 0)
  947.           then
  948.             begin
  949.               FMenuTracked := True;
  950.               Down := True;
  951.               TrackMenu;
  952.               FOld := False;
  953.             end;
  954.         end;
  955.     WM_KEYUP:
  956.       if (TWMKEYUP(Message).CharCode = VK_SPACE) and not FMenuTracked
  957.       then
  958.         begin
  959.           Down := False;
  960.           if Assigned(FOnClick) then FOnClick(Self);
  961.           FOld := False;
  962.         end
  963.       else
  964.       if (TWMKEYUP(Message).CharCode = VK_RETURN) and not FMenuTracked
  965.       then
  966.         begin
  967.           if Assigned(FOnClick) then FOnClick(Self);
  968.         end
  969.    end;
  970.   if FOld then inherited;
  971. end;
  972. function TspSkinMenuButton.GetNewTrackButtonRect;
  973. var
  974.   RM, Off: Integer;
  975.   R: TRect;
  976. begin
  977.   RM := GetResizeMode;
  978.   R := TrackButtonRect;
  979.   case RM of
  980.     2:
  981.       begin
  982.         Off := Width - RectWidth(SkinRect);
  983.         OffsetRect(R, Off, 0);
  984.       end;
  985.     3:
  986.       begin
  987.         Off := Height - RectHeight(SkinRect);
  988.         OffsetRect(R, 0, Off);
  989.       end;
  990.   end;
  991.   Result := R;
  992. end;
  993. function TspSkinMenuButton.CanMenuTrack;
  994. var
  995.   R: TRect;
  996. begin
  997.   if FSkinPopupMenu = nil
  998.   then
  999.     begin
  1000.       Result := False;
  1001.       Exit;
  1002.     end
  1003.   else
  1004.     begin
  1005.       if not FTrackButtonMode
  1006.       then
  1007.         Result := True
  1008.       else
  1009.         begin
  1010.           if FIndex <> -1
  1011.           then R := GetNewTrackButtonRect
  1012.           else R := Rect(Width - 15, 0, Width, Height);
  1013.           Result := PointInRect(R, Point(X, Y));
  1014.         end;
  1015.     end
  1016. end;
  1017. procedure TspSkinMenuButton.WMCLOSESKINMENU;
  1018. begin
  1019.   FMenuTracked := False;
  1020.   Down := False;
  1021.   if Assigned(FOnHideTrackMenu) then FOnHideTrackMenu(Self);
  1022. end;
  1023. procedure TspSkinMenuButton.TrackMenu;
  1024. var
  1025.   R: TRect;
  1026.   P: TPoint;
  1027. begin
  1028.   if FSkinPopupMenu = nil then Exit;
  1029.   if Morphing then FMorphKf := 1;
  1030.   P := ClientToScreen(Point(0, 0));
  1031.   R := Rect(P.X, P.Y, P.X + Width, P.Y + Height);
  1032.   FSkinPopupMenu.PopupFromRect2(Self, R, False);
  1033.   if Assigned(FOnShowTrackMenu) then FOnShowTrackMenu(Self); 
  1034. end;
  1035. procedure TspSkinMenuButton.Notification;
  1036. begin
  1037.   inherited Notification(AComponent, Operation);
  1038.   if (Operation = opRemove) and (AComponent = FSkinPopupMenu)
  1039.   then FSkinPopupMenu := nil;
  1040. end;
  1041. procedure TspSkinMenuButton.CMMouseEnter(var Message: TMessage);
  1042. begin
  1043.   if not FMenuTracked then inherited else FMouseIn := True;
  1044. end;
  1045. procedure TspSkinMenuButton.CMMouseLeave(var Message: TMessage);
  1046. begin
  1047.   if not FMenuTracked then inherited else FMouseIn := False;
  1048. end;
  1049. procedure TspSkinMenuButton.GetSkinData;
  1050. begin
  1051.   inherited;
  1052.   if FIndex <> -1
  1053.   then
  1054.     if TspDataSkinControl(FSD.CtrlList.Items[FIndex]) is TspDataSkinMenuButtonControl
  1055.     then
  1056.       with TspDataSkinMenuButtonControl(FSD.CtrlList.Items[FIndex]) do
  1057.       begin
  1058.         Self.TrackButtonRect := TrackButtonRect;
  1059.       end;
  1060. end;
  1061. procedure TspSkinMenuButton.SetTrackButtonMode;
  1062. begin
  1063.   FTrackButtonMode := Value;
  1064.   if FIndex = - 1 then RePaint;
  1065. end;
  1066. procedure TspSkinMenuButton.MouseDown;
  1067. begin
  1068.   if Button <> mbLeft
  1069.   then
  1070.     begin
  1071.       inherited;
  1072.       Exit;
  1073.     end;
  1074.   FMenuTracked := CanMenuTrack(X, Y);
  1075.   if FMenuTracked
  1076.   then
  1077.     begin
  1078.       if not FDown then Down := True;
  1079.       TrackMenu;
  1080.     end
  1081.   else
  1082.     inherited;
  1083. end;
  1084. procedure TspSkinMenuButton.MouseUp;
  1085. begin
  1086.   if not FMenuTracked then inherited;
  1087. end;
  1088. //=========== TspSkinPanel ================
  1089. constructor TspSkinPanel.Create;
  1090. begin
  1091.   inherited Create(AOwner);
  1092.   ControlStyle := [csAcceptsControls, csCaptureMouse, csClickEvents,
  1093.     csSetCaption, csOpaque, csDoubleClicks, csReplicatable];
  1094.   FGlyph := TBitMap.Create;
  1095.   FSpacing := 2;
  1096.   FNumGlyphs := 1;
  1097.   Width := 185;
  1098.   Height := 41;
  1099.   NewClRect := NullRect;
  1100.   FRollUpMode := False;
  1101.   FCaptionMode := False;
  1102.   FOldHeight := -1;
  1103.   FSkinDataName := 'panel';
  1104.   BGPictureIndex := -1;
  1105.   FDefaultCaptionHeight := 22;
  1106.   FAutoEnabledControls := True;
  1107.   FCheckedMode := False;
  1108. end;
  1109. destructor TspSkinPanel.Destroy;
  1110. begin
  1111.   FGlyph.Free;
  1112.   inherited;
  1113. end;
  1114. procedure TspSkinPanel.SkinDrawCheckImage(X, Y: Integer; Cnvs: TCanvas; IR: TRect; DestCnvs: TCanvas);
  1115. var
  1116.   B: TBitMap;
  1117. begin
  1118.   B := TBitMap.Create;
  1119.   B.Width := RectWidth(IR);
  1120.   B.Height := RectHeight(IR);
  1121.   B.Canvas.CopyRect(Rect(0, 0, B.Width, B.Height), Cnvs, IR);
  1122.   B.Transparent := True;
  1123.   DestCnvs.Draw(X, Y, B);
  1124.   B.Free;
  1125. end;
  1126. procedure TspSkinPanel.SetCheckedMode;
  1127. begin
  1128.   FCheckedMode := Value;
  1129.   RePaint;
  1130. end;
  1131. procedure TspSkinPanel.SetChecked;
  1132. var
  1133.   i: Integer;
  1134. begin
  1135.   FChecked := Value;
  1136.   if FCheckedMode then RePaint;
  1137.   if FAutoEnabledControls and FCheckedMode
  1138.   then
  1139.     begin
  1140.       for i := 0 to ControlCount -1 do
  1141.         Controls[i].Enabled := FChecked;
  1142.     end;
  1143.   if Assigned(FOnChecked) then FOnChecked(Self);
  1144. end;
  1145. procedure TspSkinPanel.ShowControls;
  1146. var
  1147.   i: Integer;
  1148. begin
  1149.   if VisibleControls = nil then Exit;
  1150.   for i := 0 to VisibleControls.Count - 1 do
  1151.     TControl(VisibleControls.Items[i]).Visible := True;
  1152.   VisibleControls.Clear;
  1153.   VisibleControls.Free;
  1154.   VisibleControls := nil;
  1155. end;
  1156. procedure TspSkinPanel.HideControls;
  1157. var
  1158.   i: Integer;
  1159. begin
  1160.   if VisibleControls <> nil then VisibleControls.Free;
  1161.   VisibleControls := TList.Create;
  1162.   VisibleControls.Clear;
  1163.   for i := 0 to ControlCount - 1 do
  1164.   begin
  1165.     if Controls[i].Visible
  1166.     then
  1167.       begin
  1168.         VisibleControls.Add(Controls[i]);
  1169.         Controls[i].Visible := False;
  1170.       end;
  1171.   end;
  1172. end;
  1173. procedure TspSkinPanel.SetNumGlyphs;
  1174. begin
  1175.   FNumGlyphs := Value;
  1176.   RePaint;
  1177. end;
  1178. procedure TspSkinPanel.SetGlyph;
  1179. begin
  1180.   FGlyph.Assign(Value);
  1181.   RePaint;
  1182. end;
  1183. procedure TspSkinPanel.SetSpacing;
  1184. begin
  1185.   FSpacing := Value;
  1186.   RePaint;
  1187. end;
  1188. procedure TspSkinPanel.SetDefaultAlignment(Value: TAlignment);
  1189. begin
  1190.   FDefaultAlignment := Value;
  1191.   if (FIndex = -1) and FCaptionMode then RePaint;
  1192. end;
  1193. procedure TspSkinPanel.SetDefaultCaptionHeight;
  1194. begin
  1195.   FDefaultCaptionHeight := Value;
  1196.   if (FIndex = -1) and FCaptionMode
  1197.   then
  1198.     begin
  1199.       RePaint;
  1200.       ReAlign;
  1201.     end
  1202. end;
  1203. procedure TspSkinPanel.SetBorderStyle;
  1204. begin
  1205.   FBorderStyle := Value;
  1206.   if FIndex = -1
  1207.   then
  1208.     begin
  1209.       RePaint;
  1210.       ReAlign;
  1211.     end;
  1212. end;
  1213. procedure TspSkinPanel.SetRollUpMode(Value: Boolean);
  1214. begin
  1215.   FRollUpMode := Value;
  1216.   if (FIndex = -1) and CaptionMode then RePaint;
  1217. end;
  1218. procedure TsPSkinPanel.CreateControlDefaultImage;
  1219. function GetGlyphTextWidth: Integer;
  1220. begin
  1221.   Result := B.Canvas.TextWidth(Caption);
  1222.   if not FGlyph.Empty then Result := Result + FGlyph.Width div FNumGlyphs + FSpacing;
  1223. end;
  1224. var
  1225.   R, CR: TRect;
  1226.   TX, TY, CS: Integer;
  1227.   GX, GY: Integer;
  1228.   GlyphNum: Integer;
  1229. begin
  1230.   inherited;
  1231.   R := Rect(0, 0, Width, Height);
  1232.   case FBorderStyle of
  1233.     bvLowered:
  1234.       Frame3D(B.Canvas, R, clBtnShadow, clBtnHighLight, 1);
  1235.     bvRaised:
  1236.       Frame3D(B.Canvas, R, clBtnHighLight, clBtnShadow, 1);
  1237.     bvFrame:
  1238.       Frame3D(B.Canvas, R, clBtnShadow, clBtnShadow, 1);
  1239.   end;
  1240.   if FCaptionMode
  1241.   then
  1242.     begin
  1243.       if FBorderStyle = bvFrame
  1244.       then
  1245.         begin
  1246.           R := Rect(0, 0, Width, FDefaultCaptionHeight);
  1247.           Frame3D(B.Canvas, R, clBtnShadow, clBtnShadow, 1);
  1248.           Frame3D(B.Canvas, R, clBtnHighLight, clBtnFace, 1);
  1249.         end
  1250.       else
  1251.         begin
  1252.           R := Rect(1, 1, Width - 1, FDefaultCaptionHeight);
  1253.           Frame3D(B.Canvas, R, clBtnShadow, clBtnHighLight, 1);
  1254.           Frame3D(B.Canvas, R, clBtnHighLight, clBtnShadow, 1);
  1255.         end;
  1256.       if FCheckedMode
  1257.       then
  1258.         Inc(R.Left, 20);
  1259.       if RollUpMode
  1260.       then
  1261.         Dec(R.Right, 10);
  1262.       with B.Canvas do
  1263.       begin
  1264.         Font.Assign(FDefaultFont);
  1265.         TY := R.Top + RectHeight(R) div 2 - TextHeight(Caption) div 2;
  1266.         TX := R.Left + 2;
  1267.         case FDefaultAlignment of
  1268.           taCenter: TX := TX + RectWidth(R) div 2 - GetGlyphTextWidth div 2;
  1269.           taRightJustify: TX := R.Right - GetGlyphTextWidth;
  1270.         end;
  1271.         if FCheckedMode
  1272.         then
  1273.           begin
  1274.             CS := 14;
  1275.             CR.Left := 5;
  1276.             CR.Top := R.Top + RectHeight(R) div 2 - CS div 2;
  1277.             CR.Right := CR.Left + CS;
  1278.             CR.Bottom := CR.Top + CS;
  1279.             Frame3D(B.Canvas, CR, clBtnShadow, clBtnShadow, 1);
  1280.             if FChecked then DrawCheckImage(B.Canvas, CR.Left + 3, CR.Top + 2,
  1281.             clBtnText);
  1282.           end;
  1283.         if not FGlyph.Empty
  1284.         then
  1285.           begin
  1286.             GY := R.Top + RectHeight(R) div 2 - FGlyph.Height div 2;
  1287.             GX := TX;
  1288.             TX := GX + FGlyph.Width div FNumGlyphs + FSpacing;
  1289.             GlyphNum := 1;
  1290.             if not Enabled and (NumGlyphs = 2) then GlyphNum := 2;
  1291.           end;
  1292.         Brush.Style := bsClear;
  1293.         TextRect(R, TX, TY, Caption);
  1294.         if not FGlyph.Empty
  1295.         then DrawGlyph(B.Canvas, GX, GY, FGlyph, NumGlyphs, GlyphNum);
  1296.       end;
  1297.       if FRollUpMode
  1298.       then
  1299.         begin
  1300.           R.Left := R.Right;
  1301.           R.Right := R.Left + 10;
  1302.           if FRollUpState
  1303.           then DrawArrowImage(B.Canvas, R, clBtnText, 4)
  1304.           else DrawArrowImage(B.Canvas, R, clBtnText, 3);
  1305.         end;
  1306.   end;
  1307. end;
  1308. procedure TspSkinPanel.MouseUp;
  1309. begin
  1310.   if (FRollUpMode or FCheckedMode) and FCaptionMode and (Button = mbLeft)
  1311.   then
  1312.     begin
  1313.       if ((FIndex <> -1) and (PointInRect(NewCaptionRect, Point(X, Y)) or
  1314.                               PointInRect(NewRollUpMarkerRect, Point(X, Y))))
  1315.          or
  1316.          ((FIndex = -1) and PointInRect(Rect(1, 1, Width - 1, FDefaultCaptionHeight),
  1317.            Point(X, Y)))
  1318.       then
  1319.         begin
  1320.           if CheckedMode
  1321.           then
  1322.             Checked := not Checked;
  1323.           if RollUpMode
  1324.           then
  1325.             RollUpState := not FRollUpState;
  1326.         end;
  1327.     end;
  1328.   inherited;
  1329. end;
  1330. procedure TspSkinPanel.DoRollUp(ARollUp: Boolean);
  1331. begin
  1332.   if FIndex <> -1
  1333.   then
  1334.     begin
  1335.       if ARollUp
  1336.       then
  1337.         begin
  1338.           FOldHeight := Height;
  1339.           HideControls;
  1340.           Height := NewClRect.Top + (Height - NewClRect.Bottom);
  1341.         end
  1342.       else
  1343.         if FOldHeight <> -1
  1344.         then
  1345.           begin
  1346.             Height := FOldHeight;
  1347.             ShowControls;
  1348.           end;
  1349.     end
  1350.   else
  1351.     begin
  1352.       if ARollUp
  1353.       then
  1354.         begin
  1355.           FOldHeight := Height;
  1356.           HideControls;
  1357.           Height := FDEfaultCaptionHeight + 1;
  1358.           ShowControls;
  1359.         end
  1360.       else
  1361.         if FOldHeight <> -1
  1362.         then
  1363.           begin
  1364.             Height := FOldHeight;
  1365.             ShowControls;
  1366.           end;  
  1367.     end;
  1368. end;
  1369. procedure TspSkinPanel.SetRollUpState;
  1370. begin
  1371.   if FRollUpMode
  1372.   then
  1373.     begin
  1374.       FRollUpState := Value;
  1375.       DoRollUp(FRollUpState);
  1376.     end
  1377.   else
  1378.     FRollUpState := False;
  1379. end;
  1380. procedure TspSkinPanel.SetCaptionMode;
  1381. begin
  1382.   FCaptionMode := Value;
  1383.   RePaint;
  1384.   ReAlign;
  1385. end;
  1386. procedure TspSkinPanel.SetBounds;
  1387. begin
  1388.   inherited;
  1389.   if FIndex = -1 then RePaint;
  1390. end;
  1391. procedure TspSkinPanel.SetAlphaBlend;
  1392. begin
  1393.   FAlphaBlend := AValue;
  1394.   RePaint;
  1395. end;
  1396. procedure TspSkinPanel.SetAlphaBlendValue;
  1397. begin
  1398.   FAlphaBlendValue := AValue;
  1399.   RePaint;
  1400. end;
  1401. procedure TspSkinPanel.GetSkinData;
  1402. begin
  1403.   inherited;
  1404.   BGPictureIndex := -1;
  1405.   if FIndex <> -1
  1406.   then
  1407.     if TspDataSkinControl(FSD.CtrlList.Items[FIndex]) is TspDataSkinPanelControl
  1408.     then
  1409.       with TspDataSkinPanelControl(FSD.CtrlList.Items[FIndex]) do
  1410.       begin
  1411.         Self.CaptionRect := CaptionRect;
  1412.         Self.Alignment := Alignment;
  1413.         Self.FontName := FontName;
  1414.         Self.FontColor := FontColor;
  1415.         Self.FontStyle := FontStyle;
  1416.         Self.FontHeight := FontHeight;
  1417.         Self.RollUpMarkerRect := RollUpMarkerRect;
  1418.         Self.RestoreMarkerRect := RestoreMarkerRect;
  1419.         Self.BGPictureIndex := BGPictureIndex;
  1420.         Self.CheckImageRect := CheckImageRect;
  1421.         Self.UnCheckImageRect := UnCheckImageRect; 
  1422.       end;
  1423. end;
  1424. procedure TspSkinPanel.AdjustClientRect(var Rect: TRect);
  1425. begin
  1426.   inherited AdjustClientRect(Rect);
  1427.   if (FIndex <> -1) and not (csDesigning in ComponentState)
  1428.   then
  1429.     begin
  1430.       if BGPictureIndex = -1 then Rect := NewClRect;
  1431.     end
  1432.   else
  1433.     begin
  1434.       if FBorderStyle <> bvNone then InflateRect(Rect, -1, -1);
  1435.       if FCaptionMode then Rect.Top := Rect.Top + FDefaultCaptionHeight;
  1436.     end;
  1437. end;
  1438. procedure TspSkinPanel.CreateControlSkinImage;
  1439. function GetGlyphTextWidth: Integer;
  1440. begin
  1441.   Result := B.Canvas.TextWidth(Caption);
  1442.   if not FGlyph.Empty then Result := Result + FGlyph.Width div FNumGlyphs + FSpacing;
  1443. end;
  1444. procedure DrawCaption;
  1445. var
  1446.   TX, TY, GX, GY, CW, CH: Integer;
  1447.   GlyphNum: Integer;
  1448.   CR, CapRect: TRect;
  1449. begin
  1450.   CapRect := NewCaptionRect;
  1451.   if FCheckedMode
  1452.   then
  1453.     begin
  1454.       CW := RectWidth(CheckImageRect);
  1455.       CH := RectHeight(CheckImageRect);
  1456.       CR.Left := CapRect.Left;
  1457.       CR.Top := CapRect.Top + RectHeight(CapRect) div 2 - CH div 2;
  1458.       CR.Right := CR.Left + CW;
  1459.       CR.Bottom := CR.Top + CH;
  1460.       if FChecked
  1461.       then
  1462.         SkinDrawCheckImage(CR.Left, CR.Top, Picture.Canvas, CheckImageRect, B.Canvas)
  1463.       else
  1464.         SkinDrawCheckImage(CR.Left, CR.Top, Picture.Canvas, UnCheckImageRect, B.Canvas);
  1465.       Inc(CapRect.Left, CW + 2);
  1466.     end;
  1467.   with B.Canvas do
  1468.   begin
  1469.     if FUseSkinFont
  1470.     then
  1471.       begin
  1472.         Font.Name := FontName;
  1473.         Font.Height := FontHeight;
  1474.         Font.Style := FontStyle;
  1475.         Font.CharSet := FDefaultFont.Charset;
  1476.       end
  1477.     else
  1478.       Font.Assign(FDefaultFont);    
  1479.     Font.Color := FontColor;
  1480.     TY := CapRect.Top +
  1481.       RectHeight(CapRect) div 2 - TextHeight(Caption) div 2;
  1482.     TX := CapRect.Left;
  1483.     case Alignment of
  1484.       taCenter: TX := TX +
  1485.         RectWidth(CapRect) div 2 - GetGlyphTextWidth div 2;
  1486.       taRightJustify: TX := CapRect.Right - GetGlyphTextWidth;
  1487.     end;
  1488.     Brush.Style := bsClear;
  1489.     if not FGlyph.Empty
  1490.     then
  1491.       begin
  1492.         GY := CapRect.Top + RectHeight(CapRect) div 2 - FGlyph.Height div 2;
  1493.         GX := TX;
  1494.         TX := GX + FGlyph.Width div FNumGlyphs + FSpacing;
  1495.         GlyphNum := 1;
  1496.         if not Enabled and (NumGlyphs = 2) then GlyphNum := 2;
  1497.        end;
  1498.     TextRect(CapRect, TX, TY, Caption);
  1499.     if not FGlyph.Empty
  1500.     then DrawGlyph(B.Canvas, GX, GY, FGlyph, NumGlyphs, GlyphNum);
  1501.   end;
  1502. end;
  1503. var
  1504.   X, Y, XCnt, YCnt, XO, YO, w, h, w1, h1: Integer;
  1505. begin
  1506.   if (BorderStyle = bvNone) and (ResizeMode = 1) and not CaptionMode
  1507.   then
  1508.     with B.Canvas do
  1509.     begin
  1510.       w1 := Width;
  1511.       h1 := Height;
  1512.       w := RectWidth(ClRect);
  1513.       h := RectHeight(ClRect);
  1514.       XCnt := w1 div w;
  1515.       YCnt := h1 div h;
  1516.       for X := 0 to XCnt do
  1517.       for Y := 0 to YCnt do
  1518.       begin
  1519.         if X * w + w > w1 then XO := X * w + w - w1 else XO := 0;
  1520.         if Y * h + h > h1 then YO := Y * h + h - h1 else YO := 0;
  1521.         CopyRect(Rect(X * w, Y * h, X * w + w - XO, Y * h + h - YO),
  1522.                  Picture.Canvas,
  1523.                  Rect(SkinRect.Left + ClRect.Left, SkinRect.Top + ClRect.Top,
  1524.                  SkinRect.Left + ClRect.Right - XO,
  1525.                  SkinRect.Top + ClRect.Bottom - YO));
  1526.       end;           
  1527.     end
  1528.   else
  1529.     begin
  1530.       inherited;
  1531.       if ResizeMode > 0
  1532.       then NewCaptionRect := GetNewRect(CaptionRect)
  1533.       else NewCaptionRect := CaptionRect;
  1534.       if (Caption <> '') and not IsNullRect(CaptionRect)
  1535.       then DrawCaption;
  1536.       if not IsNullRect(RollUpMarkerRect) and FRollUpMode
  1537.       then
  1538.         begin
  1539.           if ResizeMode > 0
  1540.           then NewRollUpMarkerRect := GetNewRect(RollUpMarkerRect)
  1541.           else NewRollUpMarkerRect := RollUpMarkerRect;
  1542.           if FRollUpState and not IsNullRect(RestoreMarkerRect) then
  1543.             B.Canvas.CopyRect(NewRollUpMarkerRect, Picture.Canvas,
  1544.             RestoreMarkerRect);
  1545.         end;
  1546.     end;
  1547. end;
  1548. procedure TspSkinPanel.Paint;
  1549. var
  1550.   RealPicture: TBitMap;
  1551.   X, Y, XCnt, YCnt: Integer;
  1552. begin
  1553.   GetSkinData;
  1554.   if FIndex =-1
  1555.   then
  1556.     inherited
  1557.   else
  1558.   if BGPictureIndex <> -1
  1559.   then
  1560.     begin
  1561.       RealPicture := TBitMap(FSD.FActivePictures.Items[BGPictureIndex]);
  1562.       if (Width > 0) and (Height > 0)
  1563.       then
  1564.         begin
  1565.           XCnt := Width div RealPicture.Width;
  1566.           YCnt := Height div RealPicture.Height;
  1567.           for X := 0 to XCnt do
  1568.           for Y := 0 to YCnt do
  1569.           Canvas.Draw(X * RealPicture.Width, Y * RealPicture.Height, RealPicture);
  1570.         end;
  1571.     end
  1572.   else
  1573.     inherited;
  1574. end;
  1575. procedure TspSkinPanel.ChangeSkinData;
  1576. var
  1577.   TempOldHeight: Integer;
  1578. begin
  1579.   inherited;
  1580.   if FRollUpState
  1581.   then
  1582.     begin
  1583.       TempOldHeight := FOldHeight;
  1584.       DoRollUp(True);
  1585.       FOldHeight := TempOldHeight;
  1586.     end
  1587.   else
  1588.     ReAlign;
  1589. end;
  1590. procedure TspSkinPanel.CMTextChanged;
  1591. begin
  1592.   if FCaptionMode then RePaint;
  1593. end;
  1594. procedure TspSkinPanel.CreateParams(var Params: TCreateParams);
  1595. begin
  1596.   inherited CreateParams(Params);
  1597.   with Params do
  1598.   begin
  1599.     WindowClass.style := WindowClass.style and not (CS_HREDRAW or CS_VREDRAW);
  1600.   end;
  1601. end;
  1602. constructor TspSkinGroupBox.Create;
  1603. begin
  1604.   inherited;
  1605.   FSkinDataName := 'groupbox';
  1606.   CaptionMode := True;
  1607. end;
  1608. //=========== TspSkinCheckRadioBox ===============
  1609. constructor TspSkinCheckRadioBox.Create;
  1610. begin
  1611.   inherited;
  1612.   FCanFocused := False;
  1613.   TabStop := False;
  1614.   FMouseIn := False;
  1615.   Width := 150;
  1616.   Height := 25;
  1617.   FGroupIndex := 0;
  1618.   FMorphKf := 0;
  1619.   MorphTimer := nil;
  1620.   FSkinDataName := 'checkbox';
  1621.   FFlat := False;
  1622. end;
  1623. destructor TspSkinCheckRadioBox.Destroy;
  1624. begin
  1625.   StopMorph;
  1626.   inherited;
  1627. end;
  1628. procedure TspSkinCheckRadioBox.WMMOVE;
  1629. begin
  1630.   inherited;
  1631.   Invalidate;
  1632. end;
  1633. procedure TspSkinCheckRadioBox.SkinDrawCheckImage(X, Y: Integer; Cnvs: TCanvas; IR: TRect; DestCnvs: TCanvas);
  1634. var
  1635.   B: TBitMap;
  1636. begin
  1637.   B := TBitMap.Create;
  1638.   B.Width := RectWidth(IR);
  1639.   B.Height := RectHeight(IR);
  1640.   B.Canvas.CopyRect(Rect(0, 0, B.Width, B.Height), Cnvs, IR);
  1641.   B.Transparent := True;
  1642.   DestCnvs.Draw(X, Y, B);
  1643.   B.Free;
  1644. end;
  1645. procedure TspSkinCheckRadioBox.SetFlat;
  1646. begin
  1647.   FFlat := Value;
  1648.   RePaint;
  1649. end;
  1650. procedure TspSkinCheckRadioBox.StartMorph;
  1651. begin
  1652.   if MorphTimer <> nil then Exit;
  1653.   MorphTimer := TTimer.Create(Self);
  1654.   MorphTimer.Interval := MorphTimerInterval;
  1655.   MorphTimer.OnTimer := DoMorph;
  1656.   MorphTimer.Enabled := True;
  1657. end;
  1658. procedure TspSkinCheckRadioBox.StopMorph;
  1659. begin
  1660.   if MorphTimer = nil then Exit;
  1661.   MorphTimer.Enabled := False;
  1662.   MorphTimer.Free;
  1663.   MorphTimer := nil;
  1664. end;
  1665. procedure TspSkinCheckRadioBox.Paint;
  1666. var
  1667.   PBuffer, APBuffer, PIBuffer: TspEffectBmp;
  1668.   ParentImage, Buffer, ABuffer: TBitMap;
  1669.   kf: Double;
  1670.   TR, IR: TRect;
  1671.   IX, IY: Integer;
  1672.   C: TColor;
  1673. begin
  1674.   GetSkinData;
  1675.   if FFlat
  1676.   then
  1677.     begin
  1678.       Buffer := TBitMap.Create;
  1679.       Buffer.Width := Width;
  1680.       Buffer.Height := Height;
  1681.       GetParentImage2(Self, Buffer.Canvas);
  1682.       if FIndex = -1
  1683.       then
  1684.         with Buffer.Canvas do
  1685.         begin
  1686.           IR := Rect(3, Height div 2 - 7, 17, Height div 2 + 7);
  1687.           // draw caption
  1688.           TR := Rect(0, 0, 0, 0);
  1689.           Font := DefaultFont;
  1690.           if not Enabled then Font.Color := clBtnShadow;
  1691.           Brush.Style := bsClear;
  1692.           DrawText(Buffer.Canvas.Handle, PChar(Caption), Length(Caption), TR,
  1693.              DT_CALCRECT);
  1694.           OffsetRect(TR, 22, Height div 2 - RectHeight(TR) div 2);
  1695.           if TR.Right > Width - 2 then TR.Right := Width - 2;
  1696.           SPDrawText(Buffer.Canvas, Caption, TR);
  1697.           // draw glyph
  1698.           if FMouseIn
  1699.           then
  1700.             Frame3D(Buffer.Canvas, IR, SP_XP_BTNFRAMECOLOR, SP_XP_BTNFRAMECOLOR, 1)
  1701.           else
  1702.             Frame3D(Buffer.Canvas, IR, clbtnShadow, clbtnShadow, 1);
  1703.           Pen.Color := clBlack;
  1704.           if FChecked
  1705.           then
  1706.             begin
  1707.               if Enabled then C := clBlack else C := clBtnShadow;
  1708.               if FRadio
  1709.               then DrawRadioImage(Buffer.Canvas, 7, Height div 2 - 3, C)
  1710.               else DrawCheckImage(Buffer.Canvas, 7, Height div 2 - 4, C);
  1711.             end;
  1712.           // draw focus
  1713.           InflateRect(TR, 2, 1);
  1714.           Inc(TR.Right, 1 );
  1715.           Brush.Style := bsSolid;
  1716.           Brush.Color := clBtnFace;
  1717.           if IsFocused then DrawFocusRect(TR);
  1718.         end
  1719.       else
  1720.         with Buffer.Canvas do
  1721.         begin
  1722.           // draw glyph
  1723.           IX := 3;
  1724.           IY := Height div 2 - RectHeight(CheckImageRect) div 2;
  1725.           if not Enabled
  1726.           then
  1727.             begin
  1728.               if FChecked
  1729.               then
  1730.                 SkinDrawCheckImage(IX, IY, Picture.Canvas, UnEnabledCheckImageRect, Buffer.Canvas)
  1731.               else
  1732.                 SkinDrawCheckImage(IX, IY, Picture.Canvas, UnEnabledUnCheckImageRect, Buffer.Canvas);
  1733.             end
  1734.           else
  1735.           if FMouseIn
  1736.           then
  1737.             begin
  1738.               if FChecked
  1739.               then
  1740.                 SkinDrawCheckImage(IX, IY, Picture.Canvas, ActiveCheckImageRect, Buffer.Canvas)
  1741.               else
  1742.                 SkinDrawCheckImage(IX, IY, Picture.Canvas, ActiveUnCheckImageRect, Buffer.Canvas);
  1743.             end
  1744.           else
  1745.             begin
  1746.               if FChecked
  1747.               then
  1748.                 SkinDrawCheckImage(IX, IY, Picture.Canvas, CheckImageRect, Buffer.Canvas)
  1749.               else
  1750.                 SkinDrawCheckImage(IX, IY, Picture.Canvas, UnCheckImageRect, Buffer.Canvas);
  1751.             end;
  1752.           // draw caption
  1753.           if FUseSkinFont
  1754.           then
  1755.             begin
  1756.               Font.Name := FontName;
  1757.               Font.Height := FontHeight;
  1758.               Font.Style := FontStyle;
  1759.               Font.CharSet := FDefaultFont.Charset;
  1760.             end
  1761.           else
  1762.             Font.Assign(FDefaultFont);
  1763.           if not Enabled
  1764.           then Font.Color := UnEnabledFontColor
  1765.           else Font.Color := FrameFontColor;
  1766.           TR := Rect(0, 0, 0, 0);
  1767.           DrawText(Buffer.Canvas.Handle, PChar(Caption), Length(Caption), TR,
  1768.              DT_CALCRECT);
  1769.           OffsetRect(TR, IX + RectWidth(CheckIMageRect) + 4, Height div 2 - RectHeight(TR) div 2);
  1770.           if TR.Right > Width - 2 then TR.Right := Width - 2;
  1771.           Brush.Style := bsClear;
  1772.           SPDrawText(Buffer.Canvas, Caption, TR);
  1773.           // drawfocus
  1774.           InflateRect(TR, 2, 1);
  1775.           Inc(TR.Right, 1 );
  1776.           Brush.Style := bsSolid;
  1777.           if IsFocused then DrawFocusRect(TR);
  1778.         end;
  1779.       Self.Canvas.Draw(0, 0, Buffer);
  1780.       Buffer.Free;
  1781.     end
  1782.   else
  1783.   if FIndex = -1
  1784.   then
  1785.     inherited
  1786.   else
  1787.     begin
  1788.       Buffer := TBitMap.Create;
  1789.       Buffer.Width := Width;
  1790.       Buffer.Height := Height;
  1791.       if FAlphaBlend
  1792.       then
  1793.         begin
  1794.           ParentImage := TBitMap.Create;
  1795.           ParentImage.Width := Width;
  1796.           ParentImage.Height := Height;
  1797.           GetParentImage(Self, ParentImage.Canvas);
  1798.           PIBuffer := TspEffectBmp.CreateFromhWnd(ParentImage.Handle);
  1799.           kf := 1 - FAlphaBlendValue / 255;
  1800.         end;
  1801.       if Morphing and (FMorphKf <> 1) and (FMorphKf <> 0)
  1802.       then
  1803.         begin
  1804.           ABuffer := TBitMap.Create;
  1805.           CreateImage(Buffer, SkinRect, False);
  1806.           CreateImage(ABuffer, ActiveSkinRect, True);
  1807.           PBuffer := TspEffectBmp.CreateFromhWnd(Buffer.Handle);
  1808.           APBuffer := TspEffectBmp.CreateFromhWnd(ABuffer.Handle);
  1809.           case MorphKind of
  1810.             mkDefault: PBuffer.Morph(APBuffer, FMorphKf);
  1811.             mkGradient: PBuffer.MorphGrad(APBuffer, FMorphKf);
  1812.             mkLeftGradient: PBuffer.MorphLeftGrad(APBuffer, FMorphKf);
  1813.             mkRightGradient: PBuffer.MorphRightGrad(APBuffer, FMorphKf);
  1814.             mkLeftSlide: PBuffer.MorphLeftSlide(APBuffer, FMorphKf);
  1815.             mkRightSlide: PBuffer.MorphRightSlide(APBuffer, FMorphKf);
  1816.             mkPush: PBuffer.MorphPush(APBuffer, FMorphKf);
  1817.           end;
  1818.           if FAlphaBlend then PBuffer.Morph(PIBuffer, Kf);
  1819.           PBuffer.Draw(Canvas.Handle, 0, 0);
  1820.           PBuffer.Free;
  1821.           APBuffer.Free;
  1822.           ABuffer.Free;
  1823.         end
  1824.       else
  1825.         begin
  1826.           if FMouseIn or IsFocused
  1827.           then CreateImage(Buffer, ActiveSkinRect, FMouseIn or IsFocused)
  1828.           else CreateImage(Buffer, SkinRect, FMouseIn or IsFocused);
  1829.           if FAlphaBlend
  1830.           then
  1831.             begin
  1832.               PBuffer := TspEffectBmp.CreateFromhWnd(Buffer.Handle);
  1833.               PBuffer.Morph(PIBuffer, Kf);
  1834.               PBuffer.Draw(Canvas.Handle, 0, 0);
  1835.               PBuffer.Free;
  1836.              end
  1837.           else
  1838.             Canvas.Draw(0, 0, Buffer);
  1839.         end;
  1840.       if FAlphaBlend
  1841.       then
  1842.         begin
  1843.           PIBuffer.Free;
  1844.           ParentImage.Free;
  1845.         end;
  1846.       Buffer.Free;
  1847.     end;
  1848. end;
  1849. function TspSkinCheckRadioBox.IsFocused;
  1850. begin
  1851.   Result := Focused and FCanFocused;
  1852. end;
  1853. procedure TspSkinCheckRadioBox.SetCheckState;
  1854. begin
  1855.   if FRadio
  1856.   then
  1857.     begin
  1858.       if not Checked
  1859.       then
  1860.         Checked := True
  1861.     end
  1862.   else
  1863.     Checked := not FChecked;
  1864. end;
  1865. procedure TspSkinCheckRadioBox.CMDialogChar;
  1866. begin
  1867.   with Message do
  1868.     if IsAccel(CharCode, Caption) and CanFocus and FCanFocused
  1869.     then
  1870.       begin
  1871.         SetFocus;
  1872.         SetCheckState;
  1873.         Result := 1;
  1874.       end
  1875.     else
  1876.      inherited;
  1877. end;
  1878. procedure TspSkinCheckRadioBox.SetCanFocused;
  1879. begin
  1880.   FCanFocused := Value;
  1881.   if FCanFocused then TabStop := True else TabStop := False;
  1882. end;
  1883. procedure TspSkinCheckRadioBox.WMSETFOCUS;
  1884. begin
  1885.   inherited;
  1886.   if FCanFocused then ReDrawControl;
  1887. end;
  1888. procedure TspSkinCheckRadioBox.WMKILLFOCUS;
  1889. begin
  1890.   inherited;
  1891.   if FCanFocused then ReDrawControl;
  1892. end;
  1893. procedure TspSkinCheckRadioBox.WndProc(var Message: TMessage);
  1894. begin
  1895.   if FCanFocused then
  1896.   case Message.Msg of
  1897.     WM_KEYUP:
  1898.       if IsFocused then
  1899.         with TWMKeyUp(Message) do
  1900.         begin
  1901.           if CharCode = VK_SPACE then SetCheckState;
  1902.         end;
  1903.     WM_LBUTTONDOWN, WM_LBUTTONDBLCLK:
  1904.       if not (csDesigning in ComponentState) and not Focused then
  1905.       begin
  1906.         FClicksDisabled := True;
  1907.         Windows.SetFocus(Handle);
  1908.         FClicksDisabled := False;
  1909.         if not Focused then Exit;
  1910.       end;
  1911.     CN_COMMAND:
  1912.       if FClicksDisabled then Exit;
  1913.   end;
  1914.   inherited WndProc(Message);
  1915. end;
  1916. procedure TspSkinCheckRadioBox.ActionChange(Sender: TObject; CheckDefaults: Boolean);
  1917. begin
  1918.   inherited ActionChange(Sender, CheckDefaults);
  1919.   if Sender is TCustomAction then
  1920.     with TCustomAction(Sender) do
  1921.     begin
  1922.       if not CheckDefaults or (Self.Checked = False) then
  1923.         Self.Checked := Checked;
  1924.     end;
  1925. end;
  1926. procedure TspSkinCheckRadioBox.SetRadio;
  1927. begin
  1928.   FRadio := Value;
  1929.   if ((FIndex = -1) and FDrawDefault) or
  1930.      (csDesigning in ComponentState)
  1931.   then
  1932.     RePaint;
  1933.   if (csDesigning in ComponentState) and not
  1934.      (csLoading in ComponentState)
  1935.   then
  1936.     begin
  1937.       if FRadio
  1938.       then
  1939.         begin
  1940.           FSkinDataName := 'radiobox';
  1941.           FGroupIndex := 1;
  1942.         end
  1943.       else
  1944.         begin
  1945.           FSkinDataName := 'checkbox';
  1946.           FGroupIndex := 0;
  1947.         end;
  1948.     end;
  1949. end;
  1950. procedure TspSkinCheckRadioBox.CalcSize;
  1951. var
  1952.   NewCIArea: TRect;
  1953.   Offset: Integer;
  1954.   CIW, CIH: Integer;
  1955. begin
  1956.   if FFlat then Exit;
  1957.   inherited;
  1958.   Offset := W - RectWidth(SkinRect);
  1959.   NewTextArea := TextArea;
  1960.   Inc(NewTextArea.Right, Offset);
  1961.   NewCIArea := CheckImageArea;
  1962.   if CheckImageArea.Right > TextArea.Right
  1963.   then
  1964.     OffsetRect(NewCIArea, Offset, 0);
  1965.   CIW := RectWidth(CheckImageRect);
  1966.   CIH := RectHeight(CheckImageRect);
  1967.   CIRect.Left := NewCIArea.Left + RectWidth(NewCIArea) div 2 - CIW div 2;
  1968.   CIRect.Top := NewCIArea.Top + RectHeight(NewCIArea) div 2 - CIH div 2;
  1969.   CIRect.Right := CIRect.Left + CIW;
  1970.   CIRect.Bottom := CIRect.Top + CIH;
  1971. end;
  1972. procedure TspSkinCheckRadioBox.SetChecked;
  1973. begin
  1974.   FChecked := Value;
  1975.   RePaint;
  1976.   if FChecked and (GroupIndex <> 0) then UnCheckAll;
  1977.   if (FRadio and FChecked) or not FRadio
  1978.   then
  1979.     if Assigned(FOnClick) then FOnClick(Self);
  1980. end;
  1981. procedure TspSkinCheckRadioBox.ReDrawControl;
  1982. begin
  1983.   if Morphing and (FIndex <> -1)
  1984.   then StartMorph
  1985.   else RePaint;
  1986. end;
  1987. procedure TspSkinCheckRadioBox.DoMorph;
  1988. begin
  1989.   if (FIndex = -1) or not Morphing
  1990.   then
  1991.     begin
  1992.       if (FMouseIn or IsFocused) then FMorphKf := 1 else FMorphKf := 0;
  1993.       StopMorph;
  1994.     end
  1995.   else
  1996.   if (FMouseIn or IsFocused) and (FMorphKf < 1)
  1997.   then
  1998.     begin
  1999.       FMorphKf := FMorphKf + 0.1;
  2000.       RePaint;
  2001.     end
  2002.   else
  2003.   if (not FMouseIn and not IsFocused) and (FMorphKf > 0)
  2004.   then
  2005.     begin
  2006.       FMorphKf := FMorphKf - 0.1;
  2007.       RePaint;
  2008.     end
  2009.   else
  2010.     begin
  2011.       if (FMouseIn or IsFocused) then FMorphKf := 1 else FMorphKf := 0;
  2012.       StopMorph;
  2013.       RePaint;
  2014.     end;
  2015. end;
  2016. procedure TspSkinCheckRadioBox.UnCheckAll;
  2017. var
  2018.   PC: TWinControl;
  2019.   i: Integer;
  2020. begin
  2021.   if Parent = nil then Exit;
  2022.   PC := TWinControl(Parent);
  2023.   for i := 0 to PC.ControlCount - 1 do
  2024.    if (PC.Controls[i] is TspSkinCheckRadioBox) and
  2025.       (PC.Controls[i] <> Self)
  2026.    then
  2027.      with TspSkinCheckRadioBox(PC.Controls[i]) do
  2028.        if (GroupIndex = Self.GroupIndex) and
  2029.           (GroupIndex <> 0) and Checked
  2030.        then
  2031.          Checked := False;
  2032. end;
  2033. procedure TspSkinCheckRadioBox.ChangeSkinData;
  2034. begin
  2035.   if FFlat
  2036.   then
  2037.     begin
  2038.       GetSkinData;
  2039.       RePaint;
  2040.     end
  2041.   else
  2042.     begin
  2043.       StopMorph;
  2044.       inherited;
  2045.       if Morphing and (FIndex <> -1) and (IsFocused or FMouseIn)
  2046.       then
  2047.         FMorphKf := 1;
  2048.     end;
  2049. end;
  2050. procedure TspSkinCheckRadioBox.GetSkinData;
  2051. begin
  2052.   inherited;
  2053.   if FIndex <> -1
  2054.   then
  2055.     begin
  2056.       if TspDataSkinControl(FSD.CtrlList.Items[FIndex]) is TspDataSkinCheckRadioControl
  2057.       then
  2058.         with TspDataSkinCheckRadioControl(FSD.CtrlList.Items[FIndex]) do
  2059.         begin
  2060.           Self.FontName := FontName;
  2061.           Self.FontColor := FontColor;
  2062.           Self.ActiveFontColor := ActiveFontColor;
  2063.           Self.FrameFontColor := FrameFontColor;
  2064.           Self.UnEnabledFontColor := UnEnabledFontColor;
  2065.           Self.FontStyle := FontStyle;
  2066.           Self.FontHeight := FontHeight;
  2067.           Self.ActiveSkinRect := ActiveSkinRect;
  2068.           Self.Morphing := Morphing;
  2069.           Self.MorphKind := MorphKind;
  2070.           if IsNullRect(ActiveSkinRect) then Self.ActiveSkinRect := SkinRect;
  2071.           Self.CheckImageArea := CheckImageArea;
  2072.           Self.TextArea := TextArea;
  2073.           Self.CheckImageRect := CheckImageRect;
  2074.           Self.UnCheckImageRect := UnCheckImageRect;
  2075.           Self.ActiveCheckImageRect := ActiveCheckImageRect;
  2076.           Self.UnEnabledCheckImageRect := UnEnabledCheckImageRect;
  2077.           Self.UnEnabledUnCheckImageRect := UnEnabledUnCheckImageRect;
  2078.           if IsNullRect(UnEnabledCheckImageRect)
  2079.           then
  2080.             Self.UnEnabledCheckImageRect := CheckImageRect;
  2081.           if IsNullRect(UnEnabledUnCheckImageRect)
  2082.           then
  2083.             Self.UnEnabledUnCheckImageRect := UnCheckImageRect;
  2084.           if IsNullRect(ActiveCheckImageRect)
  2085.           then
  2086.             Self.ActiveCheckImageRect := CheckImageRect;
  2087.           Self.ActiveUnCheckImageRect := ActiveUnCheckImageRect;
  2088.           if IsNullRect(ActiveUnCheckImageRect)
  2089.           then
  2090.             Self.ActiveUnCheckImageRect := UnCheckImageRect;
  2091.           Self.Morphing := Morphing;
  2092.           Self.MorphKind := MorphKind;
  2093.           if FFlat
  2094.           then
  2095.             begin
  2096.               Self.Morphing := False;
  2097.               MaskPicture := nil;
  2098.             end;
  2099.         end;
  2100.      end
  2101.    else
  2102.      begin
  2103.        Morphing := False;
  2104.        FMorphKf := 0;
  2105.      end;
  2106. end;
  2107. procedure TspSkinCheckRadioBox.CreateImage;
  2108. var
  2109.   IX, IY: Integer;
  2110. begin
  2111.   CreateSkinControlImage(B, Picture, R);
  2112.   with B.Canvas do
  2113.   begin
  2114.     IX := CIRect.Left;
  2115.     IY := CIRect.Top + RectHeight(CIRect) div 2 - RectHeight(CheckImageRect) div 2;
  2116.     if not Enabled
  2117.     then
  2118.       begin
  2119.         if FChecked
  2120.         then
  2121.           SkinDrawCheckImage(IX, IY, Picture.Canvas, UnEnabledCheckImageRect, B.Canvas)
  2122.         else
  2123.           SkinDrawCheckImage(IX, IY, Picture.Canvas, UnEnabledUnCheckImageRect, B.Canvas);
  2124.       end
  2125.     else
  2126.     if FMouseIn
  2127.     then
  2128.       begin
  2129.         if FChecked
  2130.         then
  2131.           SkinDrawCheckImage(IX, IY, Picture.Canvas, ActiveCheckImageRect, B.Canvas)
  2132.         else
  2133.           SkinDrawCheckImage(IX, IY, Picture.Canvas, ActiveUnCheckImageRect, B.Canvas);
  2134.       end
  2135.     else
  2136.       begin
  2137.         if FChecked
  2138.         then
  2139.           SkinDrawCheckImage(IX, IY, Picture.Canvas, CheckImageRect, B.Canvas)
  2140.         else
  2141.           SkinDrawCheckImage(IX, IY, Picture.Canvas, UnCheckImageRect, B.Canvas);
  2142.       end;
  2143.     if FUseSkinFont
  2144.     then
  2145.       begin
  2146.         Font.Name := FontName;
  2147.         Font.Height := FontHeight;
  2148.         Font.Style := FontStyle;
  2149.         Font.CharSet := FDefaultFont.Charset;
  2150.       end
  2151.     else
  2152.       Font.Assign(FDefaultFont);
  2153.     if AMouseIn
  2154.     then Font.Color := ActiveFontColor
  2155.     else Font.Color := FontColor;
  2156.     if not Self.Enabled then Font.Color := UnEnabledFontColor;
  2157.     Brush.Style := bsClear;
  2158.   end;
  2159.   SPDrawText(B.Canvas, Caption, NewTextArea);
  2160. end;
  2161. procedure TspSkinCheckRadioBox.CreateControlDefaultImage(B: TBitMap);
  2162. var
  2163.   R, IR, TR: TRect;
  2164.   C: TColor;
  2165. begin
  2166.   inherited;
  2167.   if isFocused or FMouseIn
  2168.   then
  2169.     begin
  2170.       R := ClientRect;
  2171.       Frame3D(B.Canvas, R, clbtnShadow, clbtnShadow, 1);
  2172.     end;
  2173.   with B.Canvas do
  2174.   begin
  2175.     Font.Assign(DefaultFont);
  2176.     if not Enabled then Font.Color := clBtnShadow;
  2177.     Pen.Color := clBlack;
  2178.     Brush.Style := bsClear;
  2179.     IR := Rect(3, Height div 2 - 7, 17, Height div 2 + 7);
  2180.     TR := Rect(19, 0, Width, Height);
  2181.     SPDrawText(B.Canvas, Caption, TR);
  2182.   end;
  2183.   if FMouseIn
  2184.   then
  2185.     Frame3D(B.Canvas, IR, SP_XP_BTNFRAMECOLOR, SP_XP_BTNFRAMECOLOR, 1)
  2186.   else
  2187.     Frame3D(B.Canvas, IR, clbtnShadow, clbtnShadow, 1);
  2188.   if FChecked
  2189.   then
  2190.     begin
  2191.       if Enabled then C := clBlack else C := clBtnShadow; 
  2192.       if FRadio
  2193.       then DrawRadioImage(B.Canvas, 7, Height div 2 - 3, C)
  2194.       else DrawCheckImage(B.Canvas, 7, Height div 2 - 4, C);
  2195.     end;
  2196. end;
  2197. procedure TspSkinCheckRadioBox.CMTextChanged;
  2198. begin
  2199.   if (FIndex <> -1) or
  2200.      (csDesigning in ComponentState) or DrawDefault
  2201.   then
  2202.     RePaint;
  2203. end;
  2204. procedure TspSkinCheckRadioBox.CMMouseEnter(var Message: TMessage);
  2205. begin
  2206.   inherited;
  2207.   FMouseIn := True;
  2208.   ReDrawControl;
  2209. end;
  2210. procedure TspSkinCheckRadioBox.CMMouseLeave(var Message: TMessage);
  2211. begin
  2212.   inherited;
  2213.   FMouseIn := False;
  2214.   ReDrawControl;
  2215. end;
  2216. procedure TspSkinCheckRadioBox.MouseDown;
  2217. begin
  2218.   if not FMouseIn
  2219.   then
  2220.     begin
  2221.       FMouseIn := True;
  2222.       RedrawControl;
  2223.     end;
  2224.   inherited;
  2225. end;
  2226. procedure TspSkinCheckRadioBox.MouseUp;
  2227. begin
  2228.   inherited;
  2229.   if (Button = mbLeft) and FMouseIn then SetCheckState;
  2230. end;
  2231. constructor TspSkinGauge.Create;
  2232. begin
  2233.   inherited;
  2234.   FMinValue := 0;
  2235.   FMaxValue := 100;
  2236.   FValue := 50;
  2237.   FVertical := False;
  2238.   Width := 100;
  2239.   Height := 20;
  2240.   BeginOffset := 0;
  2241.   EndOffset := 0;
  2242.   FProgressText := '';
  2243.   FShowPercent := False;
  2244.   FShowProgressText := False;
  2245.   FTextAlphaBlend := False;
  2246.   FTextAlphaBlendValue := 200;
  2247.   FSkinDataName := 'gauge';
  2248. end;
  2249. procedure TspSkinGauge.SetTextAlphaBlendValue;
  2250. begin
  2251.   FTextAlphaBlendValue := Value;
  2252.   if (FIndex <> -1) and FTextAlphaBlend and
  2253.      (FShowProgressText or FShowPercent)
  2254.   then
  2255.     RePaint;
  2256. end;
  2257. procedure TspSkinGauge.SetTextAlphaBlend;
  2258. begin
  2259.   FTextAlphaBlend := Value;
  2260.   if (FIndex <> -1) and (FShowProgressText or FShowPercent)
  2261.   then
  2262.     RePaint;
  2263. end;
  2264. procedure TspSkinGauge.DrawProgressText;
  2265. var
  2266.   Percent: Integer;
  2267.   S: String;
  2268.   TX, TY: Integer;
  2269.   F: TLogFont;
  2270. begin
  2271.   if (FIndex = -1)
  2272.   then
  2273.     C.Font.Assign(FDefaultFont)
  2274.   else
  2275.   if (FIndex <> -1) and not FUseSkinFont
  2276.   then
  2277.     begin    
  2278.       C.Font.Assign(FDefaultFont);
  2279.       C.Font.Color := FontColor;
  2280.     end
  2281.   else
  2282.     with C do
  2283.     begin
  2284.       Font.Name := FontName;
  2285.       Font.Height := FontHeight;
  2286.       Font.Style := FontStyle;
  2287.       Font.Color := FontColor;
  2288.       Font.CharSet := FDefaultFont.Charset;
  2289.     end;
  2290.   Percent := Round((FValue - FMinValue) / (FMaxValue - FMinValue) * 100);
  2291.   S := '';
  2292.   if FShowProgressText then S := S + FProgressText;
  2293.   if FShowPercent then S := S + IntToStr(Percent) + '%';
  2294.   if S = '' then Exit;
  2295.   with C do
  2296.   begin
  2297.     if FVertical
  2298.     then
  2299.       begin
  2300.         GetObject(Font.Handle, SizeOf(F), @F);
  2301.         F.lfEscapement := round(900);
  2302.         Font.Handle := CreateFontIndirect(F);
  2303.         TX := Width div 2 - TextHeight(S) div 2;
  2304.         TY := Height div 2 + TextWidth(S) div 2;
  2305.       end
  2306.     else
  2307.       begin
  2308.         TX := Width div 2 - TextWidth(S) div 2;
  2309.         TY := Height div 2 - TextHeight(S) div 2;
  2310.       end;
  2311.     Brush.Style := bsClear;
  2312.     TextOut(TX, TY, S);
  2313.   end;
  2314. end;
  2315. procedure TspSkinGauge.SetShowProgressText;
  2316. begin
  2317.   FShowProgressText := Value;
  2318.   RePaint;
  2319. end;
  2320. procedure TspSkinGauge.SetShowPercent;
  2321. begin
  2322.   FShowPercent := Value;
  2323.   RePaint;
  2324. end;
  2325. procedure TspSkinGauge.SetProgressText;
  2326. begin
  2327.   FProgressText := Value;
  2328.   RePaint;
  2329. end;
  2330. function TspSkinGauge.CalcProgressRect;
  2331. var
  2332.   kf: Double;
  2333.   Offset: Integer;
  2334. begin
  2335.   if FMinValue = FMaxValue
  2336.   then
  2337.     Kf := 0
  2338.   else
  2339.     kf := (FValue - FMinValue) / (FMaxValue - FMinValue);
  2340.   if FVertical
  2341.   then
  2342.     begin
  2343.       Offset := Round(RectHeight(R) * kf);
  2344.       R.Top := R.Bottom - Offset;
  2345.       Result := R;
  2346.     end
  2347.   else
  2348.     begin
  2349.       Offset := Round(RectWidth(R) * kf);
  2350.       R.Right := R.Left + Offset;
  2351.       Result := R;
  2352.     end;
  2353. end;
  2354. procedure TspSkinGauge.CalcSize;
  2355. var
  2356.   Offset: Integer;
  2357. begin
  2358.   inherited;
  2359.   if ResizeMode > 0
  2360.   then
  2361.     begin
  2362.       if FVertical
  2363.       then
  2364.         begin
  2365.           Offset := H - RectHeight(SkinRect);
  2366.           NewProgressArea := ProgressArea;
  2367.           Inc(NewProgressArea.Bottom, Offset);
  2368.         end
  2369.       else
  2370.         begin
  2371.           Offset := W - RectWidth(SkinRect);
  2372.           NewProgressArea := ProgressArea;
  2373.           Inc(NewProgressArea.Right, Offset);
  2374.         end
  2375.     end
  2376.   else
  2377.     NewProgressArea := ProgressArea;
  2378. end;
  2379. procedure TspSkinGauge.CreateControlSkinImage;
  2380. var
  2381.   PR, PR1, PR2: TRect;
  2382.   i, Cnt, Off: Integer;
  2383.   w1, w2: Integer;
  2384.   B1: TBitMap;
  2385.   EB1, EB2: TspEffectBmp;
  2386.   kf: Double;
  2387. begin
  2388.   inherited;
  2389.   with B.Canvas do
  2390.   begin
  2391.     PR := CalcProgressRect(NewProgressArea, FVertical);
  2392.     if FVertical
  2393.     then
  2394.       begin
  2395.         if RectHeight(PR) - BeginOffset - EndOffset > 0
  2396.         then
  2397.           begin
  2398.             PR1 := PR;
  2399.             Inc(PR1.Top, BeginOffset);
  2400.             Dec(PR1.Bottom, EndOffset);
  2401.             PR2 := ProgressRect;
  2402.             Inc(PR2.Top, BeginOffset);
  2403.             Dec(PR2.Bottom, EndOffset);
  2404.             w1 := RectHeight(PR1);
  2405.             w2 := RectHeight(PR2);
  2406.             if w2 = 0 then Exit;
  2407.             Cnt := w1 div w2;
  2408.             for i := 0 to Cnt do
  2409.             begin
  2410.               if i * w2 + w2 > w1 then Off := i * w2 + w2 - w1 else Off := 0;
  2411.                 CopyRect(Rect(PR1.Left, PR1.Bottom - (i * w2 + w2 - Off),
  2412.                               PR1.Right, PR1.Bottom - i * w2),
  2413.                          Picture.Canvas,
  2414.                          Rect(PR2.Left, PR2.Top + Off,
  2415.                               PR2.Right, PR2.Bottom));
  2416.             end;
  2417.           end;
  2418.         if RectHeight(PR) >= BeginOffset + EndOffset
  2419.         then
  2420.           begin
  2421.             CopyRect(Rect(PR.Left, PR.Top,
  2422.                      PR.Right, PR.Top + BeginOffset),
  2423.                    Picture.Canvas,
  2424.                    Rect(ProgressRect.Left, ProgressRect.Top,
  2425.                    ProgressRect.Right, ProgressRect.Top + BeginOffset));
  2426.             CopyRect(Rect(PR.Left, PR.Bottom - EndOffset,
  2427.                      PR.Right, PR.Bottom),
  2428.                    Picture.Canvas,
  2429.                    Rect(ProgressRect.Left, ProgressRect.Bottom - EndOffset,
  2430.                    ProgressRect.Right, ProgressRect.Bottom));
  2431.           end;
  2432.       end
  2433.     else
  2434.       begin
  2435.         if RectWidth(PR) - BeginOffset - EndOffset > 0
  2436.         then
  2437.           begin
  2438.             PR1 := PR;
  2439.             Inc(PR1.Left, BeginOffset);
  2440.             Dec(PR1.Right, EndOffset);
  2441.             PR2 := ProgressRect;
  2442.             Inc(PR2.Left, BeginOffset);
  2443.             Dec(PR2.Right, EndOffset);
  2444.             w1 := RectWidth(PR1);
  2445.             w2 := RectWidth(PR2);
  2446.             if w2 = 0 then Exit;
  2447.             Cnt := w1 div w2;
  2448.             for i := 0 to Cnt do
  2449.             begin
  2450.               if i * w2 + w2 > w1 then Off := i * w2 + w2 - w1 else Off := 0;
  2451.                 CopyRect(Rect(PR1.Left + i * w2, PR1.Top,
  2452.                          PR1.Left + i * w2 + w2 - Off, PR1.Bottom),
  2453.                      Picture.Canvas,
  2454.                      Rect(PR2.Left, PR2.Top, PR2.Right - Off, PR2.Bottom));
  2455.             end;
  2456.           end;
  2457.         if RectWidth(PR) >= BeginOffset + EndOffset
  2458.         then
  2459.           begin
  2460.             CopyRect(Rect(PR.Left, PR.Top,
  2461.                      PR.Left + BeginOffset, PR.Bottom),
  2462.                    Picture.Canvas,
  2463.                    Rect(ProgressRect.Left, ProgressRect.Top,
  2464.                    ProgressRect.Left + BeginOffset, ProgressRect.Bottom));
  2465.             CopyRect(Rect(PR.Right - EndOffset, PR.Top,
  2466.                      PR.Right, PR.Bottom),
  2467.                    Picture.Canvas,
  2468.                    Rect(ProgressRect.Right - EndOffset, ProgressRect.Top,
  2469.                    ProgressRect.Right, ProgressRect.Bottom));
  2470.           end;
  2471.       end;
  2472.   end;
  2473.   if FTextAlphaBlend and (FShowProgressText or FShowPercent)
  2474.   then
  2475.     begin
  2476.       B1 := TBitMap.Create;
  2477.       B1.Width := B.Width;
  2478.       B1.Height := B.Height;
  2479.       B1.Canvas.CopyRect(Rect(0, 0, B.Width, B.Height), B.Canvas,
  2480.                          Rect(0, 0, B.Width, B.Height));
  2481.       DrawProgressText(B.Canvas);
  2482.       EB1 := TspEffectBmp.CreateFromhWnd(B.Handle);
  2483.       EB2 := TspEffectBmp.CreateFromhWnd(B1.Handle);
  2484.       kf := 1 - FTextAlphaBlendValue / 255;
  2485.       EB1.Morph(EB2, kf);
  2486.       EB1.Draw(B.Canvas.Handle, 0, 0);
  2487.       EB1.Free;
  2488.       EB2.Free;
  2489.       B1.Free;
  2490.     end
  2491.   else
  2492.     DrawProgressText(B.Canvas);
  2493. end;
  2494. procedure TspSkinGauge.CreateImage;
  2495. begin
  2496.   CreateSkinControlImage(B, Picture, SkinRect);
  2497. end;
  2498. procedure TspSkinGauge.CreateControlDefaultImage(B: TBitMap);
  2499. var
  2500.   R, PR: TRect;
  2501. begin
  2502.   R := ClientRect;
  2503.   B.Canvas.Brush.Color := clWindow;
  2504.   B.Canvas.FillRect(R);
  2505.   Frame3D(B.Canvas, R, clbtnShadow, clbtnShadow, 1);
  2506.   R := Rect(1, 1, Width - 1, Height - 1);
  2507.   PR := CalcProgressRect(R, FVertical);
  2508.   if not IsNullRect(PR)
  2509.   then
  2510.     begin
  2511.       B.Canvas.Brush.Color := SP_XP_BTNACTIVECOLOR;
  2512.       B.Canvas.FillRect(PR);
  2513.     end;
  2514.   DrawProgressText(B.Canvas);
  2515. end;
  2516. procedure TspSkinGauge.SetVertical;
  2517. begin
  2518.   FVertical:= AValue;
  2519.   RePaint;
  2520.   if (csDesigning in ComponentState) and not
  2521.      (csLoading in ComponentState)
  2522.   then
  2523.     begin
  2524.       if FVertical
  2525.       then FSkinDataName := 'vgauge'
  2526.       else FSkinDataName := 'gauge';
  2527.     end;
  2528. end;
  2529. procedure TspSkinGauge.SetMinValue;
  2530. begin
  2531.   FMinValue := AValue;
  2532.   if FValue < FMinValue then FValue := FMinValue;
  2533.   RePaint;
  2534. end;
  2535. procedure TspSkinGauge.SetMaxValue;
  2536. begin
  2537.   FMaxValue := AValue;
  2538.   if FValue > FMaxValue then FValue := FMaxValue;
  2539.   RePaint;
  2540. end;
  2541. procedure TspSkinGauge.SetValue;
  2542. begin
  2543.   if AValue > FMaxValue
  2544.   then AValue := FMaxValue else
  2545.   if AValue < FMinValue
  2546.   then AValue := FMinValue;
  2547.   if AValue <> FValue
  2548.   then
  2549.     begin
  2550.       FValue := AValue;
  2551.       RePaint;
  2552.     end;
  2553. end;
  2554. procedure TspSkinGauge.GetSkinData;
  2555. begin
  2556.   inherited;
  2557.   if FIndex <> -1
  2558.   then
  2559.     if TspDataSkinControl(FSD.CtrlList.Items[FIndex]) is TspDataSkinGaugeControl
  2560.     then
  2561.       with TspDataSkinGaugeControl(FSD.CtrlList.Items[FIndex]) do
  2562.       begin
  2563.         Self.FVertical := Vertical;
  2564.         Self.ProgressRect := ProgressRect;
  2565.         Self.ProgressArea := ProgressArea;
  2566.         Self.BeginOffset := BeginOffset;
  2567.         Self.EndOffset := EndOffset;
  2568.         Self.FontName := FontName;
  2569.         Self.FontStyle := FontStyle;
  2570.         Self.FontHeight := FontHeight;
  2571.         Self.FontColor := FontColor;
  2572.       end;
  2573. end;
  2574. constructor TspSkinTrackBar.Create;
  2575. begin
  2576.   inherited;
  2577.   FCanFocused := False;
  2578.   TabStop := False;
  2579.   FMinValue := 0;
  2580.   FMaxValue := 100;
  2581.   FValue := 50;
  2582.   FVertical := False;
  2583.   Width := 100;
  2584.   Height := 20;
  2585.   FMouseSupport := True;
  2586.   FDown := False;
  2587.   FSkinDataName := 'htrackbar';
  2588. end;
  2589. procedure TspSkinTrackBar.KeyDown;
  2590. begin
  2591.   inherited KeyDown(Key, Shift);
  2592.   if FCanFocused then
  2593.   case Key of
  2594.     VK_UP, VK_RIGHT: Value := Value + 1;
  2595.     VK_DOWN, VK_LEFT: Value := Value - 1;
  2596.   end;
  2597. end;
  2598. procedure TspSkinTrackBar.WMMOUSEWHEEL;
  2599. begin
  2600.   if IsFocused
  2601.   then
  2602.     if Vertical
  2603.     then
  2604.       begin
  2605.         if Message.WParam > 0
  2606.         then
  2607.           Value := Value + 1
  2608.         else
  2609.           Value := Value - 1;
  2610.       end
  2611.     else
  2612.       begin
  2613.         if Message.WParam > 0
  2614.         then
  2615.           Value := Value - 1
  2616.         else
  2617.           Value := Value + 1;
  2618.       end;
  2619. end;
  2620. procedure TspSkinTrackBar.CMWantSpecialKey(var Msg: TCMWantSpecialKey);
  2621. begin
  2622.   inherited;
  2623.   if FCanFocused then 
  2624.   case Msg.CharCode of
  2625.     VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT: Msg.Result := 1;
  2626.   end;
  2627. end;
  2628. function TspSkinTrackBar.IsFocused;
  2629. begin
  2630.   Result := Focused and FCanFocused;
  2631. end;
  2632. procedure TspSkinTrackBar.SetCanFocused;
  2633. begin
  2634.   FCanFocused := Value;
  2635.   if FCanFocused then TabStop := True else TabStop := False;
  2636. end;
  2637. procedure TspSkinTrackBar.WMSETFOCUS;
  2638. begin
  2639.   inherited;
  2640.   if FCanFocused then RePaint;
  2641. end;
  2642. procedure TspSkinTrackBar.WMKILLFOCUS;
  2643. begin
  2644.   inherited;
  2645.   if FCanFocused then RePaint;
  2646. end;
  2647. procedure TspSkinTrackBar.WndProc(var Message: TMessage);
  2648. begin
  2649.   if FCanFocused then
  2650.   case Message.Msg of
  2651.     WM_LBUTTONDOWN, WM_LBUTTONDBLCLK:
  2652.       if not (csDesigning in ComponentState) and not Focused then
  2653.       begin
  2654.         FClicksDisabled := True;
  2655.         Windows.SetFocus(Handle);
  2656.         FClicksDisabled := False;
  2657.         if not Focused then Exit;
  2658.       end;
  2659.     CN_COMMAND:
  2660.       if FClicksDisabled then Exit;
  2661.   end;
  2662.   inherited WndProc(Message);
  2663. end;
  2664. function TspSkinTrackBar.CalcValue;
  2665. var
  2666.   kf: Double;
  2667. begin
  2668.   if (Offset2 - Offset1) <= 0
  2669.   then kf := 0
  2670.   else kf := AOffset / (Offset2 - Offset1);
  2671.   if kf > 1 then kf := 1 else
  2672.   if kf < 0 then kf := 0;
  2673.   Result := FMinValue + Round((FMaxValue - FMinValue) * kf);
  2674. end;
  2675. function TspSkinTrackBar.CalcButtonRect;
  2676. var
  2677.   kf: Double;
  2678.   BW, BH: Integer;
  2679. begin
  2680.   if FMinValue = FMaxValue
  2681.   then
  2682.     Kf := 0
  2683.   else
  2684.     kf := (FValue - FMinValue) / (FMaxValue - FMinValue);
  2685.   if FIndex = -1
  2686.   then
  2687.     begin
  2688.       if FVertical
  2689.       then
  2690.         begin
  2691.           BW := Width - 4;
  2692.           BH := BW div 2;
  2693.         end
  2694.       else
  2695.         begin
  2696.           BH := Height - 4;
  2697.           BW := BH div 2;
  2698.          end;
  2699.     end
  2700.   else
  2701.     begin
  2702.       BW := RectWidth(ButtonRect);
  2703.       BH := RectHeight(ButtonRect);
  2704.     end;
  2705.   if FVertical
  2706.   then
  2707.     begin
  2708.       Offset1 := R.Top + BH div 2;
  2709.       Offset2 := R.Bottom - BH div 2;
  2710.       BOffset := Round((Offset2 - Offset1) * Kf);
  2711.       Result := Rect(R.Left + RectWidth(R) div 2 - BW div 2,
  2712.        Offset2 - BOffset - BH div 2,
  2713.        R.Left + RectWidth(R) div 2 - BW div 2 + BW,
  2714.        Offset2 - BOffset - BH div 2 + BH);
  2715.     end
  2716.   else
  2717.     begin
  2718.       Offset1 := R.Left + BW div 2;
  2719.       Offset2 := R.Right - BW div 2;
  2720.       BOffset := Round((Offset2 - Offset1) * kf);
  2721.       Result := Rect(Offset1 + BOffset - BW div 2,
  2722.         R.Top + RectHeight(R) div 2 - BH div 2,
  2723.         Offset1 + BOffset - BW div 2 + BW,
  2724.         R.Top + RectHeight(R) div 2 - BH div 2 + BH);
  2725.     end;
  2726. end;
  2727. procedure TspSkinTrackBar.CalcSize;
  2728. var
  2729.   Offset: Integer;
  2730. begin
  2731.   inherited;
  2732.   if ResizeMode > 0
  2733.   then
  2734.     begin
  2735.       if FVertical
  2736.       then
  2737.         begin
  2738.           Offset := H - RectHeight(SkinRect);
  2739.           NewTrackArea := TrackArea;
  2740.           Inc(NewTrackArea.Bottom, Offset);
  2741.         end
  2742.       else
  2743.         begin
  2744.           Offset := W - RectWidth(SkinRect);
  2745.           NewTrackArea := TrackArea;
  2746.           Inc(NewTrackArea.Right, Offset);
  2747.         end
  2748.     end
  2749.   else
  2750.     NewTrackArea := TrackArea;
  2751. end;
  2752. procedure TspSkinTrackBar.CreateControlSkinImage;
  2753. var
  2754.   B1, B2: TBitMap;
  2755.   EB1, EB2: TspEffectBmp;
  2756.   kf: Double;
  2757. begin
  2758.   inherited;
  2759.   BR := CalcButtonRect(NewTrackArea, FVertical);
  2760.   if FAlphaBlend
  2761.   then
  2762.     begin
  2763.       //
  2764.       B1 := TBitMap.Create;
  2765.       B1.Width := RectWidth(BR);
  2766.       B1.Height := RectHeight(BR);
  2767.       with B1.Canvas do
  2768.       if FDown or IsFocused
  2769.       then
  2770.         CopyRect(Rect(0, 0, B1.Width, B1.Height),
  2771.            Picture.Canvas, ActiveButtonRect)
  2772.       else
  2773.         CopyRect(Rect(0, 0, B1.Width, B1.Height),
  2774.            Picture.Canvas, ButtonRect);
  2775.       //
  2776.       B2 := TBitMap.Create;
  2777.       B2.Width := RectWidth(BR);
  2778.       B2.Height := RectHeight(BR);
  2779.       B2.Canvas.CopyRect(Rect(0, 0, B2.Width, B2.Height), B.Canvas, BR);
  2780.       //
  2781.       EB1 := TspEffectBmp.CreateFromhWnd(B1.Handle);
  2782.       EB2 := TspEffectBmp.CreateFromhWnd(B2.Handle);
  2783.       kf := 1 - FAlphaBlendValue / 255;
  2784.       EB1.Morph(EB2, Kf);
  2785.       EB1.Draw(B1.Canvas.Handle, 0, 0);
  2786.       B.Canvas.Draw(BR.Left, BR.Top, B1);
  2787.       //
  2788.       EB1.Free;
  2789.       EB2.Free;
  2790.       B1.Free;
  2791.       B2.Free;
  2792.     end
  2793.   else
  2794.     with B.Canvas do
  2795.     begin
  2796.       if FDown or IsFocused
  2797.       then
  2798.         CopyRect(BR, Picture.Canvas, ActiveButtonRect)
  2799.       else
  2800.         CopyRect(BR, Picture.Canvas, ButtonRect);
  2801.     end;
  2802. end;
  2803. procedure TspSkinTrackBar.CreateImage;
  2804. begin
  2805.   CreateSkinControlImage(B, Picture, SkinRect);
  2806. end;
  2807. procedure TspSkinTrackBar.MouseDown;
  2808. begin
  2809.   inherited;
  2810.   if FMouseSupport and
  2811.      PtInRect(Rect(BR.Left, BR.Top, BR.Right + 1, BR.Bottom + 1), Point(X, Y))
  2812.   then
  2813.     begin
  2814.       if FVertical then OMPos := Y else OMPos := X;
  2815.       OldBOffset := BOffset;
  2816.       FDown := True;
  2817.       RePaint;
  2818.     end;
  2819. end;
  2820. procedure TspSkinTrackBar.MouseUp;
  2821. begin
  2822.   inherited;
  2823.   if FMouseSupport and FDown
  2824.   then
  2825.     begin
  2826.       FDown := False;
  2827.       RePaint;
  2828.     end;
  2829. end;
  2830. procedure TspSkinTrackBar.MouseMove;
  2831. var
  2832.   Off: Integer;
  2833. begin
  2834.   if FMouseSupport and FDown
  2835.   then
  2836.     begin
  2837.       if Vertical
  2838.       then
  2839.         begin
  2840.           Off := OMPos - Y;
  2841.           Off := OldBOffset + Off;
  2842.         end
  2843.       else
  2844.         begin
  2845.           Off := X - OMPos;
  2846.           Off := OldBOffset + Off;
  2847.         end;
  2848.       Value := CalcValue(Off);
  2849.     end;
  2850.   inherited;  
  2851. end;
  2852. procedure TspSkinTrackBar.CreateControlDefaultImage;
  2853. var
  2854.   R, LR, BR1: TRect;
  2855. begin
  2856.   inherited;
  2857.   R := ClientRect;
  2858.   Frame3D(B.Canvas, R, clbtnShadow, clbtnShadow, 1);
  2859.   R := Rect(2, 2, Width - 2, Height - 2);
  2860.   if FVertical
  2861.   then
  2862.     LR := Rect(Width div 2 - 1, 4, Width div 2 + 1, Height - 4)
  2863.   else
  2864.     LR := Rect(4, Height div 2 - 1, Width - 4, Height div 2 + 1);
  2865.   BR := CalcButtonRect(R, FVertical);
  2866.   Frame3D(B.Canvas, LR, clbtnShadow, clBtnHighLight, 1);
  2867.   with B.Canvas do
  2868.   begin
  2869.     Brush.Style := bsSolid;
  2870.     Brush.Color := clBtnFace;
  2871.     FillRect(BR);
  2872.   end;
  2873.   BR1 := BR;
  2874.   with B.Canvas do
  2875.   begin
  2876.     Brush.Style := bsSolid;
  2877.     if FDown
  2878.     then
  2879.       begin
  2880.         Frame3D(B.Canvas, BR1, SP_XP_BTNFRAMECOLOR, SP_XP_BTNFRAMECOLOR, 1);
  2881.         Brush.Color := SP_XP_BTNDOWNCOLOR;
  2882.         FillRect(BR1);
  2883.       end
  2884.     else
  2885.     if IsFocused
  2886.     then
  2887.       begin
  2888.         Frame3D(B.Canvas, BR1, SP_XP_BTNFRAMECOLOR, SP_XP_BTNFRAMECOLOR, 1);
  2889.         Brush.Color := SP_XP_BTNACTIVECOLOR;
  2890.         FillRect(BR1);
  2891.       end
  2892.     else
  2893.       begin
  2894.         Frame3D(B.Canvas, BR1, clBtnShadow, clBtnShadow, 1);
  2895.         Brush.Color := clBtnFace;
  2896.         FillRect(BR1);
  2897.       end;
  2898.   end;
  2899. end;
  2900. procedure TspSkinTrackBar.SetVertical;
  2901. begin
  2902.   FVertical:= AValue;
  2903.   RePaint;
  2904.   if (csDesigning in ComponentState) and not
  2905.      (csLoading in ComponentState)
  2906.   then
  2907.     begin
  2908.       if FVertical
  2909.       then FSkinDataName := 'trackbar'
  2910.       else FSkinDataName := 'htrackbar';
  2911.     end;
  2912. end;
  2913. procedure TspSkinTrackBar.SetMinValue;
  2914. begin
  2915.   FMinValue := AValue;
  2916.   if FValue < FMinValue then FValue := FMinValue;
  2917.   RePaint;
  2918. end;
  2919. procedure TspSkinTrackBar.SetMaxValue;
  2920. begin
  2921.   FMaxValue := AValue;
  2922.   if FValue > FMaxValue then FValue := FMaxValue;
  2923.   RePaint;
  2924. end;
  2925. procedure TspSkinTrackBar.SetValue;
  2926. begin
  2927.   if AValue > MaxValue then AValue := MaxValue else
  2928.     if AValue < MinValue then AValue := MinValue;
  2929.   if AValue <> FValue
  2930.   then
  2931.     begin
  2932.       FValue := AValue;
  2933.       RePaint;
  2934.       if Assigned(FOnChange) then FOnChange(Self);
  2935.     end;
  2936. end;
  2937. procedure TspSkinTrackBar.GetSkinData;
  2938. begin
  2939.   inherited;
  2940.   if FIndex <> -1
  2941.   then
  2942.     if TspDataSkinControl(FSD.CtrlList.Items[FIndex]) is TspDataSkinTrackBarControl
  2943.     then
  2944.       with TspDataSkinTrackBarControl(FSD.CtrlList.Items[FIndex]) do
  2945.       begin
  2946.         Self.FVertical := Vertical;
  2947.         Self.ButtonRect := ButtonRect;
  2948.         if IsNullRect(ActiveButtonRect)
  2949.         then
  2950.           Self.ActiveButtonRect := ButtonRect
  2951.         else
  2952.           Self.ActiveButtonRect := ActiveButtonRect;
  2953.         Self.TrackArea := TrackArea;
  2954.       end;
  2955. end;
  2956. constructor TspSkinStdLabel.Create;
  2957. begin
  2958.   inherited;
  2959.   Transparent := True;
  2960.   FSD := nil;
  2961.   FSkinDataName := 'stdlabel';
  2962.   FDefaultFont := TFont.Create;
  2963.   FUseSkinFont := True;
  2964. end;
  2965. destructor TspSkinStdLabel.Destroy;
  2966. begin
  2967.   FDefaultFont.Free;
  2968.   inherited;
  2969. end;
  2970. procedure TspSkinStdLabel.DoDrawText(var Rect: TRect; Flags: Longint);
  2971. var
  2972.   Text: string;
  2973. begin
  2974.   GetSkinData;
  2975.   Text := GetLabelText;
  2976.   if (Flags and DT_CALCRECT <> 0) and ((Text = '') or ShowAccelChar and
  2977.     (Text[1] = '&') and (Text[2] = #0)) then Text := Text + ' ';
  2978.   if not ShowAccelChar then Flags := Flags or DT_NOPREFIX;
  2979.   Flags := DrawTextBiDiModeFlags(Flags);
  2980.   if FIndex <> -1
  2981.   then
  2982.     with Canvas.Font do
  2983.     begin
  2984.       if FUseSkinFont
  2985.       then
  2986.         begin
  2987.           Name := FontName;
  2988.           Style := FontStyle;
  2989.           Height := FontHeight;
  2990.         end
  2991.       else
  2992.         Canvas.Font := Self.Font;
  2993.       Color := FontColor;
  2994.     end
  2995.   else
  2996.     if FUseSkinFont
  2997.     then
  2998.       Canvas.Font := DefaultFont
  2999.     else
  3000.       Canvas.Font := Self.Font;
  3001.   if not Enabled then
  3002.   begin
  3003.     OffsetRect(Rect, 1, 1);
  3004.     Canvas.Font.Color := clBtnHighlight;
  3005.     DrawText(Canvas.Handle, PChar(Text), Length(Text), Rect, Flags);
  3006.     OffsetRect(Rect, -1, -1);
  3007.     Canvas.Font.Color := clBtnShadow;
  3008.     DrawText(Canvas.Handle, PChar(Text), Length(Text), Rect, Flags);
  3009.   end
  3010.   else
  3011.     DrawText(Canvas.Handle, PChar(Text), Length(Text), Rect, Flags);
  3012. end;
  3013. procedure TspSkinStdLabel.SetDefaultFont;
  3014. begin
  3015.   FDefaultFont.Assign(Value);
  3016. end;
  3017. procedure TspSkinStdLabel.Notification;
  3018. begin
  3019.   inherited Notification(AComponent, Operation);
  3020.   if (Operation = opRemove) and (AComponent = FSD) then FSD := nil;
  3021. end;
  3022. procedure TspSkinStdLabel.GetSkinData;
  3023. begin
  3024.   if (FSD = nil) or FSD.Empty
  3025.   then
  3026.     FIndex := -1
  3027.   else
  3028.     FIndex := FSD.GetControlIndex(FSkinDataName);
  3029.   if (FIndex <> -1)
  3030.   then
  3031.     if TspDataSkinControl(FSD.CtrlList.Items[FIndex]) is TspDataSkinStdLabelControl
  3032.     then
  3033.       with TspDataSkinStdLabelControl(FSD.CtrlList.Items[FIndex]) do
  3034.       begin
  3035.         Self.FontName := FontName;
  3036.         Self.FontColor := FontColor;
  3037.         Self.FontStyle := FontStyle;
  3038.         Self.FontHeight := FontHeight;
  3039.       end
  3040. end;
  3041. procedure TspSkinStdLabel.ChangeSkinData;
  3042. begin
  3043.   GetSkinData;
  3044.   RePaint;
  3045. end;
  3046. procedure TspSkinStdLabel.SetSkinData;
  3047. begin
  3048.   FSD := Value;
  3049.   if (FSD <> nil) then ChangeSkinData;
  3050. end;
  3051. constructor TspSkinBitLabel.Create;
  3052. begin
  3053.   inherited;
  3054.   Symbols := nil;
  3055.   Width := 100;
  3056.   Height := 20;
  3057.   FSkinDataName := 'bitlabel';
  3058. end;
  3059. function TspSkinBitLabel.GetFixWidth;
  3060. var
  3061.   LO, RO: Integer;
  3062. begin
  3063.   LO := ClRect.Left;
  3064.   RO := RectWidth(SkinRect) - ClRect.Right;
  3065.   Result := SymbolWidth * FFixLength + LO + RO;
  3066. end;
  3067. procedure TspSkinBitLabel.SetFixLength;
  3068. begin
  3069.   FFixLength := Value;
  3070.   if FFixLength > 0
  3071.   then
  3072.     begin
  3073.       FAutoSize := False;
  3074.       if FIndex <> -1
  3075.       then
  3076.         Width := GetFixWidth;
  3077.     end;
  3078. end;
  3079. procedure TspSkinBitLabel.CMTextChanged(var Message: TMessage);
  3080. begin
  3081.   if FAutoSize then AdjustBounds;
  3082.   RePaint;
  3083. end;
  3084. procedure TspSkinBitLabel.AdjustBounds;
  3085. var
  3086.   Offset: Integer;
  3087. begin
  3088.   if Align <> alNone then Exit;
  3089.   if FIndex = -1
  3090.   then Offset := 0
  3091.   else Offset := Length(Caption) * SymbolWidth - RectWidth(NewClRect);
  3092.   if Offset <> 0 then Width := Width + Offset;
  3093. end;
  3094. procedure TspSkinBitLabel.CalcSize;
  3095. var
  3096.   Offset: Integer;
  3097. begin
  3098.   inherited;
  3099.   if FFixLength > 0
  3100.   then
  3101.     begin
  3102.       if FIndex <> -1
  3103.       then
  3104.         W := GetFixWidth;
  3105.     end
  3106.   else
  3107.     begin
  3108.       if FIndex = -1
  3109.       then Offset := 0
  3110.       else Offset := Length(Caption) * SymbolWidth - RectWidth(NewClRect);
  3111.       if (Offset > 0) or FAutoSize then W := W + Offset;
  3112.     end;  
  3113. end;
  3114. procedure TspSkinBitLabel.CreateControlDefaultImage;
  3115. begin
  3116.   inherited;
  3117.   with B.Canvas do
  3118.   begin
  3119.     Brush.Style := bsClear;
  3120.     TextRect(Rect(1, 1, Width - 1, Height - 1), 2,
  3121.              Height div 2 - TextHeight(Caption) div 2,
  3122.              Caption);
  3123.   end;
  3124. end;
  3125. procedure TspSkinBitLabel.PaintLabel;
  3126. begin
  3127.   CreateSkinControlImage(B, Picture, SkinRect);
  3128. end;
  3129. procedure TspSkinBitLabel.GetSkinData;
  3130. begin
  3131.   inherited;
  3132.   if FIndex <> -1
  3133.   then
  3134.     if TspDataSkinControl(FSD.CtrlList.Items[FIndex]) is TspDataSkinBitLabelControl
  3135.     then
  3136.       begin
  3137.         with TspDataSkinBitLabelControl(FSD.CtrlList.Items[FIndex]) do
  3138.         begin
  3139.           Self.SkinTextRect := SkinTextRect;
  3140.           Self.SymbolWidth := SymbolWidth;
  3141.           Self.SymbolHeight := SymbolHeight;
  3142.           Self.Symbols := Symbols;
  3143.         end;
  3144.       end;
  3145. end;
  3146. procedure TspSkinBitLabel.CreateControlSkinImage;
  3147. var
  3148.   SymbolX, SymbolY: Integer;
  3149.   i: Integer;
  3150.   XO: Integer;
  3151.   LO, RO: Integer;
  3152. procedure GetSymbolPos(Ch: Char);
  3153. var
  3154.   i, j: Integer;
  3155. begin
  3156.   SymbolX := -1;
  3157.   SymbolY := -1;
  3158.   for i := 0 to Symbols.Count - 1 do
  3159.   begin
  3160.     j := Pos(Ch, Symbols[i]);
  3161.     if j <> 0
  3162.     then
  3163.       begin
  3164.         SymbolX := j - 1;
  3165.         SymbolY := i;
  3166.         Exit;
  3167.       end;
  3168.   end;
  3169. end;
  3170. begin
  3171.   inherited;
  3172.   LO := ClRect.Left;
  3173.   RO := RectWidth(SkinRect) - ClRect.Right;
  3174.   with B.Canvas do
  3175.   begin
  3176.     for i := 1 to Length(Caption) do
  3177.     begin
  3178.       if (i * SymbolWidth) > B.Width
  3179.       then XO := i * SymbolWidth - B.Width - LO - RO
  3180.       else XO := 0;
  3181.       GetSymbolPos(Caption[i]);
  3182.       if SymbolX <> -1
  3183.       then
  3184.         begin
  3185.           CopyRect(
  3186.             Rect(LO + (i - 1) * SymbolWidth, NewClRect.Top, LO + i * SymbolWidth - XO, NewClRect.Top + SymbolHeight),
  3187.             Picture.Canvas,
  3188.             Rect(SkinTextRect.Left + SymbolX * SymbolWidth,
  3189.                  SkinTextRect.Top + SymbolY * SymbolHeight,
  3190.                  SkinTextRect.Left + (SymbolX + 1) * SymbolWidth - XO,
  3191.                  SkinTextRect.Top + (SymbolY + 1) * SymbolHeight));
  3192.           if XO > 0 then Break;
  3193.         end;
  3194.     end;
  3195.   end;
  3196. end;
  3197. procedure TspSkinBitLabel.SetAutoSizeX;
  3198. begin
  3199.   FAutoSize := Value;
  3200.   AdjustBounds;
  3201.   RePaint;
  3202. end;
  3203. constructor TspSkinLabel.Create;
  3204. begin
  3205.   inherited;
  3206.   Width := 75;
  3207.   Height := 21;
  3208.   FAutoSize := False;
  3209.   FSkinDataName := 'label';
  3210. end;
  3211. procedure TspSkinLabel.SetBorderStyle;
  3212. begin
  3213.   FBorderStyle := Value;
  3214.   if FIndex = -1
  3215.   then
  3216.     begin
  3217.       RePaint;
  3218.       ReAlign;
  3219.     end;
  3220. end;
  3221. procedure TspSkinLabel.GetSkinData;
  3222. begin
  3223.   inherited;
  3224.   if FIndex <> -1
  3225.   then
  3226.     if TspDataSkinControl(FSD.CtrlList.Items[FIndex]) is TspDataSkinLabelControl
  3227.     then
  3228.       with TspDataSkinLabelControl(FSD.CtrlList.Items[FIndex]) do
  3229.       begin
  3230.         Self.FontName := FontName;
  3231.         Self.FontColor := FontColor;
  3232.         Self.FontStyle := FontStyle;
  3233.         Self.FontHeight := FontHeight;
  3234.         if ResizeMode = 0 then FAutoSize := False;
  3235.       end;
  3236. end;
  3237. procedure TspSkinLabel.DrawLabelText;
  3238. var
  3239.   TX, TY: Integer;
  3240. begin
  3241.   with Cnvs do
  3242.   begin
  3243.     if FIndex <> -1
  3244.     then
  3245.       begin
  3246.         Font.Name := FontName;
  3247.         Font.Style := FontStyle;
  3248.         Font.Height := FontHeight;
  3249.         Font.Color := FontColor;
  3250.       end
  3251.     else
  3252.       Font.Assign(DefaultFont);
  3253.     TY := R.Top + RectHeight(R) div 2 - TextHeight(Caption) div 2;
  3254.     TX := R.Left;
  3255.     case FAlignment of
  3256.       taRightJustify: TX := R.Right - TextWidth(Caption);
  3257.       taCenter: TX := R.Left + RectWidth(R) div 2 - TextWidth(Caption) div 2;
  3258.     end;
  3259.     Brush.Style := bsClear;
  3260.     TextOut(TX, TY, Caption);
  3261.   end;
  3262. end;
  3263. procedure TspSkinLabel.CreateControlDefaultImage;
  3264. var
  3265.   R: TRect;
  3266. begin
  3267.   inherited;
  3268.   R := ClientRect;
  3269.   case FBorderStyle of
  3270.     bvLowered:
  3271.       Frame3D(B.Canvas, R, clBtnShadow, clBtnHighLight, 1);
  3272.     bvRaised:
  3273.       Frame3D(B.Canvas, R, clBtnHighLight, clBtnShadow, 1);
  3274.     bvFrame:
  3275.       Frame3D(B.Canvas, R, clBtnShadow, clBtnShadow, 1);
  3276.   end;
  3277.   DrawLabelText(B.Canvas, Rect(2, 2, Width - 2, Height - 2));
  3278. end;
  3279. procedure TspSkinLabel.CreateControlSkinImage;
  3280. begin
  3281.   inherited;
  3282.   DrawLabelText(B.Canvas, NewClRect);
  3283. end;
  3284. procedure TspSkinLabel.PaintLabel;
  3285. begin
  3286.   CreateSkinControlImage(B, Picture, SkinRect);
  3287. end;
  3288. procedure TspSkinLabel.CalcSize;
  3289. var
  3290.   Offset: Integer;
  3291. begin
  3292.   inherited;
  3293.   Offset := CalcWidthOffset;
  3294.   if (Offset > 0) or FAutoSize then W := W + Offset; 
  3295. end;
  3296. function TspSkinLabel.CalcWidthOffset;
  3297. begin
  3298.   with Canvas do
  3299.   begin
  3300.     Font.Name := FontName;
  3301.     Font.Height := FontHeight;
  3302.     Font.Style := FontStyle;
  3303.     if ResizeMode = 0
  3304.     then
  3305.       Result := 0
  3306.     else
  3307.       Result := TextWidth(Caption) - RectWidth(NewClRect);
  3308.    end;
  3309. end;
  3310. procedure TspSkinLabel.AdjustBounds;
  3311. var
  3312.   Offset: Integer;
  3313.   tw: Integer;
  3314. begin
  3315.   if Align <> alNone then Exit;
  3316.   if FIndex = -1
  3317.   then
  3318.     begin
  3319.       tw := Canvas.TextWidth(Caption);
  3320.       Offset := tw - (Width - 4);
  3321.     end
  3322.   else
  3323.     Offset := CalcWidthOffset;
  3324.   if Offset <> 0 then Width := Width + Offset;
  3325. end;
  3326. procedure TspSkinLabel.SetAlignment(Value: TAlignment);
  3327. begin
  3328.   if FAlignment <> Value
  3329.   then
  3330.     begin
  3331.       FAlignment := Value;
  3332.       RePaint;
  3333.     end;
  3334. end;
  3335. procedure TspSkinLabel.SetAutoSizeX(Value: Boolean);
  3336. begin
  3337.   FAutoSize := Value;
  3338.   if FAutoSize then AdjustBounds; 
  3339. end;
  3340. procedure TspSkinLabel.CMTextChanged(var Message: TMessage);
  3341. begin
  3342.   if FAutoSize then AdjustBounds;
  3343.   RePaint;
  3344. end;
  3345. //============ TspSkinScrollBar ===============
  3346. const
  3347.   SBUTTONW = 16;
  3348.   BUTCOUNT = 3;
  3349.   THUMB = 0;
  3350.   UPBUTTON = 1;
  3351.   DOWNBUTTON = 2;
  3352. constructor TspSkinScrollBar.Create;
  3353. begin
  3354.   inherited;
  3355.   FCanFocused := False;
  3356.   TabStop := False;
  3357.   FMin := 0;
  3358.   FMax := 100;
  3359.   FPosition := 0;
  3360.   FSmallChange := 1;
  3361.   FLargeChange := 1;
  3362.   FPageSize := 0;
  3363.   WaitMode := False;
  3364.   TimerMode := 0;
  3365.   ActiveButton := -1;
  3366.   OldActiveButton := -1;
  3367.   CaptureButton := -1;
  3368.   FOnChange := nil;
  3369.   Width := 200;
  3370.   Height := 20;
  3371.   FBothMarkerWidth := 0;
  3372.   FBothMarkerWidth := 0;
  3373.   FNormalSkinDataName := '';
  3374.   FBothSkinDataName := 'bothhscrollbar';
  3375. end;
  3376. procedure TspSkinScrollBar.SetBoth(Value: Boolean);
  3377. begin
  3378.   if FBoth <> Value
  3379.   then
  3380.     begin
  3381.       FBoth := Value;
  3382.       if not (csDesigning in ComponentState)
  3383.       then
  3384.         if FBoth
  3385.         then
  3386.           begin
  3387.             FNormalSkinDataName := SkinDataName;
  3388.             SkinDataName := FBothSkinDataName;
  3389.           end
  3390.         else
  3391.           if FNormalSkinDataName <> ''
  3392.           then
  3393.             SkinDataName := FNormalSkinDataName;
  3394.         if FIndex = -1
  3395.         then
  3396.           RePaint
  3397.         else
  3398.          ChangeSkinData;
  3399.     end;
  3400. end;
  3401. procedure TspSkinScrollBar.CMEnabledChanged;
  3402. begin
  3403.   inherited;
  3404.   RePaint;
  3405. end;
  3406. procedure TspSkinScrollBar.SetBothMarkerWidth;
  3407. begin
  3408.   if Value >= 0
  3409.   then
  3410.     begin
  3411.       FBothMarkerWidth := Value;
  3412.       if FIndex = -1 then RePaint;
  3413.     end;
  3414. end;
  3415. procedure TspSkinScrollBar.KeyDown;
  3416. begin
  3417.   inherited KeyDown(Key, Shift);
  3418.   if FCanFocused then 
  3419.   case Key of
  3420.     VK_DOWN, VK_RIGHT: Position := Position + FSmallChange;
  3421.     VK_UP, VK_LEFT: Position := Position - FSmallChange;
  3422.   end;
  3423. end;
  3424. procedure TspSkinScrollBar.WMMOUSEWHEEL;
  3425. begin
  3426.   if IsFocused
  3427.   then
  3428.     if Message.WParam > 0
  3429.     then
  3430.       Position := FPosition - FSmallChange
  3431.     else
  3432.       Position := FPosition + FSmallChange;
  3433. end;
  3434. procedure TspSkinScrollBar.CMWantSpecialKey(var Msg: TCMWantSpecialKey);
  3435. begin
  3436.   inherited;
  3437.   if FCanFocused then 
  3438.   case Msg.CharCode of
  3439.     VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT: Msg.Result := 1;
  3440.   end;
  3441. end;
  3442. function TspSkinScrollBar.IsFocused;
  3443. begin
  3444.   Result := Focused and FCanFocused;
  3445. end;
  3446. procedure TspSkinScrollBar.SetCanFocused;
  3447. begin
  3448.   FCanFocused := Value;
  3449.   if FCanFocused then TabStop := True else TabStop := False;
  3450. end;
  3451. procedure TspSkinScrollBar.WMSETFOCUS;
  3452. begin
  3453.   inherited;
  3454.   if FCanFocused then RePaint;
  3455. end;
  3456. procedure TspSkinScrollBar.WMKILLFOCUS;
  3457. begin
  3458.   inherited;
  3459.   if FCanFocused then RePaint;
  3460. end;
  3461. procedure TspSkinScrollBar.WndProc(var Message: TMessage);
  3462. begin
  3463.   if FCanFocused then
  3464.   case Message.Msg of
  3465.     WM_LBUTTONDOWN, WM_LBUTTONDBLCLK:
  3466.       if not (csDesigning in ComponentState) and not Focused then
  3467.       begin
  3468.         FClicksDisabled := True;
  3469.         Windows.SetFocus(Handle);
  3470.         FClicksDisabled := False;
  3471.         if not Focused then Exit;
  3472.       end;
  3473.     CN_COMMAND:
  3474.       if FClicksDisabled then Exit;
  3475.   end;
  3476.   inherited WndProc(Message);
  3477. end;
  3478. procedure TspSkinScrollBar.GetSkinData;
  3479. begin
  3480.   inherited;
  3481.   if FIndex <> -1
  3482.   then
  3483.     if TspDataSkinControl(FSD.CtrlList.Items[FIndex]) is TspDataSkinScrollBarControl
  3484.     then
  3485.       with TspDataSkinScrollBarControl(FSD.CtrlList.Items[FIndex]) do
  3486.       begin
  3487.         Self.TrackArea := TrackArea;
  3488.         Self.UpButtonRect := UpButtonRect;
  3489.         Self.ActiveUpButtonRect := ActiveUpButtonRect;
  3490.         Self.DownUpButtonRect := DownUpButtonRect;
  3491.         if IsNullRect(Self.DownUpButtonRect)
  3492.         then
  3493.           Self.DownUpButtonRect := Self.ActiveUpButtonRect;
  3494.         Self.DownButtonRect := DownButtonRect;
  3495.         Self.ActiveDownButtonRect := ActiveDownButtonRect;
  3496.         Self.DownDownButtonRect := DownDownButtonRect;
  3497.         if IsNullRect(Self.DownDownButtonRect)
  3498.         then
  3499.           Self.DownDownButtonRect := Self.ActiveDownButtonRect;
  3500.         Self.ThumbRect := ThumbRect;
  3501.         Self.ActiveThumbRect := ActiveThumbRect;
  3502.         if IsNullRect(Self.ActiveThumbRect)
  3503.         then
  3504.           Self.ActiveThumbRect := Self.ThumbRect;
  3505.         Self.DownThumbRect := DownThumbRect;
  3506.         if IsNullRect(Self.DownThumbRect)
  3507.         then
  3508.           Self.DownThumbRect := Self.ActiveThumbRect;
  3509.         Self.ThumbOffset1 := ThumbOffset1;
  3510.         Self.ThumbOffset2 := ThumbOffset2;
  3511.         Self.GlyphRect := GlyphRect;
  3512.         Self.ActiveGlyphRect := ActiveGlyphRect;
  3513.         if isNullRect(ActiveGlyphRect)
  3514.         then Self.ActiveGlyphRect := GlyphRect;
  3515.         Self.DownGlyphRect := DownGlyphRect;
  3516.         if isNullRect(DownGlyphRect)
  3517.         then Self.DownGlyphRect := Self.ActiveGlyphRect;
  3518.       end;
  3519. end;
  3520. procedure TspSkinScrollBar.CalcSize;
  3521. begin
  3522.   inherited;
  3523.   CalcRects;
  3524. end;
  3525. procedure TspSkinScrollBar.SetPageSize;
  3526. begin
  3527.   if AValue + FPosition <= FMax - FMin + 1
  3528.   then
  3529.     FPageSize := AValue;
  3530.   RePaint;
  3531. end;
  3532. procedure TspSkinScrollBar.StopTimer;
  3533. begin
  3534.   KillTimer(Handle, 1);
  3535.   TimerMode := 0;
  3536. end;
  3537. procedure TspSkinScrollBar.TestActive(X, Y: Integer);
  3538. var
  3539.   i, j: Integer;
  3540. begin
  3541.   j := -1;
  3542.   OldActiveButton := ActiveButton;
  3543.   for i := 0 to BUTCOUNT - 1 do
  3544.   begin
  3545.     if PtInRect(Buttons[i].R, Point(X, Y))
  3546.     then
  3547.       begin
  3548.         j := i;
  3549.         Break;
  3550.       end;
  3551.   end;
  3552.   ActiveButton := j;
  3553.   if (CaptureButton <> -1) and
  3554.      (ActiveButton <> CaptureButton) and (ActiveButton <> -1)
  3555.   then
  3556.     ActiveButton := -1;
  3557.   if (OldActiveButton <> ActiveButton)
  3558.   then
  3559.     begin
  3560.       if OldActiveButton <> - 1
  3561.       then
  3562.         ButtonLeave(OldActiveButton);
  3563.       if ActiveButton <> -1
  3564.       then
  3565.         ButtonEnter(ActiveButton);
  3566.     end;
  3567. end;
  3568. procedure TspSkinScrollBar.CreateControlSkinImage;
  3569. var
  3570.   i: Integer;
  3571. begin
  3572.   inherited;
  3573.   CalcRects;
  3574.   for i := 1 to BUTCOUNT - 1 do DrawButton(B.Canvas, i);
  3575.   if Enabled then 
  3576.   DrawButton(B.Canvas, THUMB);
  3577. end;
  3578. procedure TspSkinScrollBar.DrawButton;
  3579. var
  3580.   R1, R2: TRect;
  3581.   C: TColor;
  3582.   ThumbB: TBitMap;
  3583.   B1: TBitMap;
  3584.   EB1, EB2: TspEffectBmp;
  3585.   kf: Double;
  3586. begin
  3587.   if FIndex = -1
  3588.   then
  3589.   with Buttons[i] do
  3590.   begin
  3591.     if FIndex = -1
  3592.     then
  3593.       with Buttons[i] do
  3594.       begin
  3595.         R1 := R;
  3596.         with Cnvs do
  3597.         begin
  3598.           if (Down and MouseIn) or ((i = THUMB) and (Down or IsFocused))
  3599.           then
  3600.             begin
  3601.               Frame3D(Cnvs, R1, SP_XP_BTNFRAMECOLOR, SP_XP_BTNFRAMECOLOR, 1);
  3602.               Brush.Color := SP_XP_BTNDOWNCOLOR;
  3603.               FillRect(R1);
  3604.             end
  3605.           else
  3606.             if MouseIn
  3607.             then
  3608.               begin
  3609.                 Frame3D(Cnvs, R1, SP_XP_BTNFRAMECOLOR, SP_XP_BTNFRAMECOLOR, 1);
  3610.                 Brush.Color := SP_XP_BTNACTIVECOLOR;
  3611.                 FillRect(R1);
  3612.               end
  3613.              else
  3614.                begin
  3615.                  Frame3D(Cnvs, R1, clBtnShadow, clBtnShadow, 1);
  3616.                  Brush.Color := clBtnFace;
  3617.                  FillRect(R1);
  3618.                end;
  3619.         end;
  3620.      C := clBlack;
  3621.      case i of
  3622.        DOWNBUTTON:
  3623.          case Kind of
  3624.            sbHorizontal:
  3625.              DrawArrowImage(Cnvs, R1, C, 1);
  3626.            sbVertical:
  3627.              DrawArrowImage(Cnvs, R1, C, 3);
  3628.           end;
  3629.         UPBUTTON:
  3630.           case Kind of
  3631.             sbHorizontal:
  3632.               DrawArrowImage(Cnvs, R1, C, 2);
  3633.             sbVertical:
  3634.               DrawArrowImage(Cnvs, R1, C, 4);
  3635.           end;
  3636.         end;
  3637.       end
  3638.     end
  3639.   else
  3640.     begin
  3641.       if I = THUMB
  3642.       then
  3643.         with Buttons[THUMB] do
  3644.         begin
  3645.           if Down or IsFocused
  3646.           then R1 := DownThumbRect
  3647.           else if MouseIn then R1 := ActiveThumbRect
  3648.           else R1 := ThumbRect;
  3649.           ThumbB := TBitMap.Create;
  3650.           ThumbB.Width := RectWidth(R);
  3651.           ThumbB.Height := RectHeight(R);
  3652.           if FPageSize = 0
  3653.           then
  3654.             ThumbB.Canvas.CopyRect(Rect(0, 0, ThumbB.Width, ThumbB.Height), Picture.Canvas, R1)
  3655.           else
  3656.             case Kind of
  3657.               sbHorizontal:
  3658.                 CreateHSkinImage(ThumbOffset1, ThumbOffset2, ThumbB, Picture, R1,
  3659.                   ThumbB.Width, ThumbB.Height);
  3660.               sbVertical:
  3661.                 CreateVSkinImage(ThumbOffset1, ThumbOffset2, ThumbB, Picture, R1,
  3662.                   ThumbB.Width, ThumbB.Height);
  3663.             end;
  3664.           // draw glyph
  3665.           if Down or IsFocused
  3666.           then R1 := DownGlyphRect
  3667.           else if MouseIn then R1 := ActiveGlyphRect
  3668.           else R1 := GlyphRect;
  3669.           if not IsNullRect(R1)
  3670.           then
  3671.             begin
  3672.               R2 := Rect(ThumbB.Width div 2 - RectWidth(R1) div 2,
  3673.                          ThumbB.Height div 2 - RectHeight(R1) div 2,
  3674.                          ThumbB.Width div 2 - RectWidth(R1) div 2 + RectWidth(R1),
  3675.                          ThumbB.Height div 2 - RectHeight(R1) div 2 + RectHeight(R1));
  3676.               ThumbB.Canvas.CopyRect(R2, Picture.Canvas, R1)
  3677.             end;
  3678.           //
  3679.           if FAlphaBlend
  3680.           then
  3681.             begin
  3682.               B1 := TBitMap.Create;
  3683.               B1.Width := ThumbB.Width;
  3684.               B1.Height := ThumbB.Height;
  3685.               B1.Canvas.CopyRect(Rect(0, 0, B1.Width - 1, B1.Height),
  3686.                                  Cnvs, R);
  3687.               EB1 := TspEffectBmp.CreateFromhWnd(ThumbB.Handle);
  3688.               EB2 := TspEffectBmp.CreateFromhWnd(B1.Handle);
  3689.               kf := 1 - FAlphaBlendValue / 255;
  3690.               EB1.Morph(EB2, Kf);
  3691.               EB1.Draw(ThumbB.Canvas.Handle, 0, 0);
  3692.               EB1.Free;
  3693.               EB2.Free;
  3694.               B1.Free;
  3695.             end;
  3696.           Cnvs.Draw(R.Left, R.Top, ThumbB);
  3697.           ThumbB.Free;
  3698.         end
  3699.       else
  3700.         begin
  3701.           R1 := NullRect;
  3702.           case I of
  3703.             UPBUTTON:
  3704.             with Buttons[UPBUTTON] do
  3705.             begin
  3706.               if Down and MouseIn
  3707.               then R1 := DownUpButtonRect
  3708.               else if MouseIn then R1 := ActiveUpButtonRect;
  3709.             end;
  3710.             DOWNBUTTON:
  3711.             with Buttons[DOWNBUTTON] do
  3712.             begin
  3713.               if Down and MouseIn
  3714.               then R1 := DownDownButtonRect
  3715.               else if MouseIn then R1 := ActiveDownButtonRect;
  3716.             end
  3717.           end;
  3718.           if not IsNullRect(R1)
  3719.           then
  3720.             Cnvs.CopyRect(Buttons[i].R, Picture.Canvas, R1);
  3721.         end;
  3722.     end;
  3723. end;
  3724. procedure TspSkinScrollBar.CalcRects;
  3725. var
  3726.   Kf: Double;
  3727.   i, j, k, XMin, XMax: Integer;
  3728.   Offset: Integer;
  3729.   ThumbW, ThumbH: Integer;
  3730.   NewWidth: Integer;
  3731. begin
  3732.   if FMin = FMax
  3733.   then Kf := 0
  3734.   else kf := (FPosition - FMin) / (FMax - FMin);
  3735.   if FIndex = -1
  3736.   then
  3737.     begin
  3738.       ThumbW := SBUTTONW;
  3739.       if FBoth
  3740.       then
  3741.         NewWidth := Width - BothMarkerWidth
  3742.       else
  3743.         NewWidth := Width;
  3744.       case FKind of
  3745.         sbHorizontal:
  3746.           begin
  3747.             Buttons[DOWNBUTTON].R := Rect(1, 1, 1 + SBUTTONW, Height - 1);
  3748.             Buttons[UPBUTTON].R := Rect(NewWidth - SBUTTONW - 1, 1, NewWidth - 1, Height - 1);
  3749.             NewTrackArea := Rect(SBUTTONW + 1, 1, NewWidth - SBUTTONW - 1, Height - 1);
  3750.             if FPageSize = 0
  3751.             then
  3752.               begin
  3753.                 Offset1 := NewTrackArea.Left + ThumbW div 2;
  3754.                 Offset2 := NewTrackArea.Right - ThumbW div 2;
  3755.                 BOffset := Round((Offset2 - Offset1) * kf);
  3756.                 Buttons[THUMB].R :=
  3757.                  Rect(Offset1 + BOffset - ThumbW div 2, NewTrackArea.Top,
  3758.                      Offset1 + BOffset + ThumbW div 2, NewTrackArea.Bottom);
  3759.               end
  3760.             else
  3761.               begin
  3762.                 i := RectWidth(NewTrackArea);
  3763.                 j := FMax - FMin + 1;
  3764.                 if j = 0 then kf := 0 else kf := FPageSize / j;
  3765.                 j := Round(i * kf);
  3766.                 if j < ThumbW then j := ThumbW;
  3767.                 XMin := FMin;
  3768.                 XMax := FMax - FPageSize + 1;
  3769.                 if XMax > XMin
  3770.                 then
  3771.                   kf := (FPosition - XMin) / (XMax - XMin)
  3772.                 else
  3773.                   kf := 1;
  3774.                 Offset1 := NewTrackArea.Left + j div 2;
  3775.                 Offset2 := NewTrackArea.Right - j div 2;
  3776.                 BOffset := Round((Offset2 - Offset1) * kf);
  3777.                 Buttons[THUMB].R :=
  3778.                  Rect(Offset1 + BOffset - j div 2, NewTrackArea.Top,
  3779.                      Offset1 + BOffset + j div 2, NewTrackArea.Bottom);
  3780.               end;
  3781.           end;
  3782.         sbVertical:
  3783.           begin
  3784.             Buttons[DOWNBUTTON].R := Rect(1, 1, Width - 1, 1 + SBUTTONW);
  3785.             Buttons[UPBUTTON].R := Rect(1, Height - SBUTTONW - 1, Width - 1, Height - 1);
  3786.             NewTrackArea := Rect(1, SBUTTONW + 1, Width - 1, Height - SBUTTONW - 1);
  3787.             if PageSize = 0
  3788.             then
  3789.               begin
  3790.                 Offset1 := NewTrackArea.Top + ThumbW div 2;
  3791.                 Offset2 := NewTrackArea.Bottom - ThumbW div 2;
  3792.                 BOffset := Round((Offset2 - Offset1) * kf);
  3793.                 Buttons[THUMB].R :=
  3794.                   Rect(NewTrackArea.Left, Offset1 + BOffset - ThumbW div 2,
  3795.                        NewTrackArea.Right, Offset1 + BOffset + ThumbW div 2);
  3796.               end
  3797.             else
  3798.               begin
  3799.                 i := RectHeight(NewTrackArea);
  3800.                 j := FMax - FMin + 1;
  3801.                 if j = 0 then kf := 0 else kf := FPageSize / j;
  3802.                 j := Round(i * kf);
  3803.                 if j < ThumbW then j := ThumbW;
  3804.                 XMin := FMin;
  3805.                 XMax := FMax - FPageSize + 1;
  3806.                 if XMax - XMin > 0
  3807.                 then
  3808.                   kf := (FPosition - XMin) / (XMax - XMin)
  3809.                 else
  3810.                   kf := 1;
  3811.                 Offset1 := NewTrackArea.Top + j div 2;
  3812.                 Offset2 := NewTrackArea.Bottom - j div 2;
  3813.                 BOffset := Round((Offset2 - Offset1) * kf);
  3814.                 Buttons[THUMB].R :=
  3815.                   Rect(NewTrackArea.Left, Offset1 + BOffset - j div 2,
  3816.                       NewTrackArea.Right, Offset1 + BOffset + j div 2);
  3817.              end;
  3818.           end;
  3819.       end;
  3820.     end
  3821.    else
  3822.      begin
  3823.        ThumbW := RectWidth(ThumbRect);
  3824.        ThumbH := RectHeight(ThumbRect);
  3825.        case FKind of
  3826.          sbHorizontal:
  3827.            begin
  3828.              Offset := Width - RectWidth(SkinRect);
  3829.              NewTrackArea := TrackArea;
  3830.              Inc(NewTrackArea.Right, Offset);
  3831.              Buttons[UPBUTTON].R := UpButtonRect;
  3832.              Buttons[DOWNBUTTON].R := DownButtonRect;
  3833.              //
  3834.              if UpButtonRect.Left > RTPt.X
  3835.              then
  3836.                OffsetRect(Buttons[UPBUTTON].R, Offset, 0);
  3837.              if DownButtonRect.Left > RTPt.X
  3838.              then
  3839.                OffsetRect(Buttons[DOWNBUTTON].R, Offset, 0);
  3840.              if FPageSize = 0
  3841.              then
  3842.                begin
  3843.                  Offset1 := NewTrackArea.Left + ThumbW div 2;
  3844.                  Offset2 := NewTrackArea.Right - ThumbW div 2;
  3845.                  BOffset := Round((Offset2 - Offset1) * kf);
  3846.                  Buttons[THUMB].R :=
  3847.                    Rect(Offset1 + BOffset - ThumbW div 2,
  3848.                         NewTrackArea.Top + RectHeight(NewTrackArea) div 2 - ThumbH div 2,
  3849.                         Offset1 + BOffset + ThumbW div 2,
  3850.                         NewTrackArea.Top + RectHeight(NewTrackArea) div 2 - ThumbH div 2 + ThumbH);
  3851.                end
  3852.              else
  3853.                begin
  3854.                  i := RectWidth(NewTrackArea);
  3855.                  j := FMax - FMin + 1;
  3856.                  if j = 0 then kf := 0 else kf := FPageSize / j;
  3857.                  j := Round(i * kf);
  3858.                  if j < ThumbW then j := ThumbW;
  3859.                  XMin := FMin;
  3860.                  XMax := FMax - FPageSize + 1;
  3861.                  if XMax - XMin = 0
  3862.                  then
  3863.                    kf := 0
  3864.                  else
  3865.                    kf := (FPosition - XMin) / (XMax - XMin);
  3866.                  Offset1 := NewTrackArea.Left + j div 2;
  3867.                  Offset2 := NewTrackArea.Right - j div 2;
  3868.                  BOffset := Round((Offset2 - Offset1) * kf);
  3869.                  Buttons[THUMB].R :=
  3870.                  Rect(Offset1 + BOffset - j div 2,
  3871.                       NewTrackArea.Top + RectHeight(NewTrackArea) div 2 - ThumbH div 2,
  3872.                       Offset1 + BOffset + j div 2,
  3873.                       NewTrackArea.Top + RectHeight(NewTrackArea) div 2 - ThumbH div 2 +
  3874.                       ThumbH);
  3875.               end;
  3876.            end;
  3877.          sbVertical:
  3878.            begin
  3879.              Offset := Height - RectHeight(SkinRect);
  3880.              NewTrackArea := TrackArea;
  3881.              Inc(NewTrackArea.Bottom, Offset);
  3882.              Buttons[UPBUTTON].R := UpButtonRect;
  3883.              Buttons[DOWNBUTTON].R := DownButtonRect;
  3884.              if UpButtonRect.Top > LBPt.Y
  3885.              then
  3886.                OffsetRect(Buttons[UPBUTTON].R, 0, Offset);
  3887.              if DownButtonRect.Top > LBPt.Y
  3888.              then
  3889.                OffsetRect(Buttons[DOWNBUTTON].R, 0, Offset);
  3890.              if PageSize = 0
  3891.              then
  3892.               begin
  3893.                 Offset1 := NewTrackArea.Top + ThumbH div 2;
  3894.                 Offset2 := NewTrackArea.Bottom - ThumbH div 2;
  3895.                 BOffset := Round((Offset2 - Offset1) * kf);
  3896.                 Buttons[THUMB].R :=
  3897.                   Rect(NewTrackArea.Left + RectWidth(NewTrackArea) div 2 -
  3898.                        ThumbW div 2,
  3899.                        Offset1 + BOffset - ThumbH div 2,
  3900.                        NewTrackArea.Left + RectWidth(NewTrackArea) div 2 -
  3901.                        ThumbW div 2 + ThumbW,
  3902.                        Offset1 + BOffset + ThumbH div 2);
  3903.               end
  3904.              else
  3905.                begin
  3906.                  i := RectHeight(NewTrackArea);
  3907.                  j := FMax - FMin + 1;
  3908.                  if j = 0 then kf := 0 else kf := FPageSize / j;
  3909.                  j := Round(i * kf);
  3910.                  if j < ThumbH then j := ThumbH;
  3911.                  XMin := FMin;
  3912.                  XMax := FMax - FPageSize + 1;
  3913.                  if XMax - XMin <= 0
  3914.                  then
  3915.                    kf := 0
  3916.                  else
  3917.                    kf := (FPosition - XMin) / (XMax - XMin);
  3918.                  Offset1 := NewTrackArea.Top + j div 2;
  3919.                  Offset2 := NewTrackArea.Bottom - j div 2;
  3920.                  BOffset := Round((Offset2 - Offset1) * kf);
  3921.                  Buttons[THUMB].R :=
  3922.                    Rect(NewTrackArea.Left + RectWidth(NewTrackArea) div 2 -
  3923.                         ThumbW div 2,
  3924.                         Offset1 + BOffset - j div 2,
  3925.                         NewTrackArea.Left + RectWidth(NewTrackArea) div 2 -
  3926.                         ThumbW div 2 + ThumbW,
  3927.                         Offset1 + BOffset + j div 2);
  3928.                end;
  3929.            end;
  3930.        end;
  3931.      end;
  3932. end;
  3933. procedure TspSkinScrollBar.SetKind;
  3934. begin
  3935.   if AValue <> FKind
  3936.   then
  3937.     begin
  3938.       FKind := AValue;
  3939.       RePaint;
  3940.     end;
  3941.   if (csDesigning in ComponentState) and not
  3942.      (csLoading in ComponentState)
  3943.   then
  3944.     begin
  3945.       if FKind = sbVertical
  3946.       then FSkinDataName := 'vscrollbar'
  3947.       else FSkinDataName := 'hscrollbar';
  3948.     end;
  3949. end;
  3950. procedure TspSkinScrollBar.SimplySetPosition;
  3951. var
  3952.   TempValue: Integer;
  3953. begin
  3954.   if FPageSize = 0
  3955.   then
  3956.     begin
  3957.       if AValue < FMin then TempValue := FMin else
  3958.       if AValue > FMax then TempValue := FMax else
  3959.       TempValue := AValue;
  3960.     end
  3961.   else
  3962.     begin
  3963.       if AValue < FMin then TempValue := FMin else
  3964.       if AValue > FMax - FPageSize + 1 then
  3965.       TempValue := FMax - FPageSize + 1  else
  3966.       TempValue := AValue;
  3967.     end;
  3968.   if TempValue <> FPosition
  3969.   then
  3970.     begin
  3971.       FPosition := TempValue;
  3972.       RePaint;
  3973.    end;
  3974. end;
  3975. procedure TspSkinScrollBar.SetPosition;
  3976. var
  3977.   TempValue: Integer;
  3978. begin
  3979.   if FPageSize = 0
  3980.   then
  3981.     begin
  3982.       if AValue < FMin then TempValue := FMin else
  3983.       if AValue > FMax then TempValue := FMax else
  3984.       TempValue := AValue;
  3985.     end
  3986.   else
  3987.     begin
  3988.       if AValue < FMin then TempValue := FMin else
  3989.       if AValue > FMax - FPageSize + 1 then
  3990.       TempValue := FMax - FPageSize + 1  else
  3991.       TempValue := AValue;
  3992.     end;
  3993.   if TempValue <> FPosition
  3994.   then
  3995.     begin
  3996.       FPosition := TempValue;
  3997.       RePaint;
  3998.       if Assigned(FOnChange) then FOnChange(Self);
  3999.     end;
  4000. end;
  4001. procedure TspSkinScrollBar.SetRange;
  4002. begin
  4003.   FMin := AMin;
  4004.   FMax := AMax;
  4005.   FPageSize := APageSize;
  4006.   if FPageSize = 0
  4007.   then
  4008.     begin
  4009.       if APosition < FMin then FPosition := FMin else
  4010.       if APosition > FMax then FPosition := FMax else
  4011.       FPosition := APosition;
  4012.     end
  4013.   else
  4014.     begin
  4015.       if APosition < FMin then FPosition := FMin else
  4016.       if APosition > FMax - FPageSize + 1 then
  4017.       FPosition := FMax - FPageSize + 1  else