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

Delphi控件源码

开发平台:

Delphi

  1.     begin
  2.       if FRollUpState
  3.       then
  4.         begin
  5.           OldHeight := FForm.Height;
  6.           CreateRollUpForm2;
  7.         end
  8.       else
  9.         RestoreRollUpForm2;
  10.     end
  11.  else
  12.    if not FSD.FRollUpPicture.Empty
  13.    then
  14.      begin
  15.        if FRollUpState
  16.        then
  17.          begin
  18.            OldHeight := FForm.Height;
  19.            CreateRollUpForm;
  20.          end
  21.        else
  22.          RestoreRollUpForm;
  23.      end
  24.    else
  25.      FRollUpState := False;
  26.   if Assigned(FOnChangeRollUpState) then FOnChangeRollUpState(Self);
  27. end;
  28. procedure TspDynamicSkinForm.BeforeUpDateSkinControls;
  29. procedure CheckControl(C: TControl);
  30. begin
  31.   if C is TspSkinControl
  32.   then
  33.     begin
  34.       with TspSkinControl(C) do
  35.         if (Integer(SkinData) = AFSD) or (AFSD = 0)
  36.         then BeforeChangeSkinData;
  37.     end
  38.   else
  39.   if C is TspGraphicSkinControl
  40.   then
  41.     begin
  42.       with TspGraphicSkinControl(C) do
  43.         if (Integer(SkinData) = AFSD) or (AFSD = 0)
  44.         then BeforeChangeSkinData;
  45.     end;
  46. end;
  47. var
  48.   i: Integer;
  49. begin
  50.   CheckControl(WC);
  51.   for i := 0 to WC.ControlCount - 1 do
  52.   begin
  53.     if WC.Controls[i] is TWinControl
  54.     then
  55.       BeforeUpDateSkinControls(AFSD, TWinControl(WC.Controls[i]))
  56.     else
  57.       CheckControl(WC.Controls[i]);
  58.   end;
  59. end;
  60. procedure TspDynamicSkinForm.UpDateSkinControls;
  61. procedure CheckControl(C: TControl);
  62. begin
  63.   if C is TspGraphicSkinControl
  64.   then
  65.     begin
  66.       with TspGraphicSkinControl(C) do
  67.         if (Integer(SkinData) = AFSD) or (AFSD = 0) then ChangeSkinData
  68.     end
  69.   else
  70.   if C is TspSkinControl
  71.   then
  72.     begin
  73.       with TspSkinControl(C) do
  74.         if (Integer(SkinData) = AFSD) or (AFSD = 0) then ChangeSkinData
  75.     end
  76.   else
  77.     if C is TspSkinPageControl
  78.     then
  79.       begin
  80.         with TspSkinPageControl(C) do
  81.           if (Integer(SkinData) = AFSD) or (AFSD = 0) then ChangeSkinData
  82.       end
  83.     else
  84.     if C is TspSkinTabControl
  85.     then
  86.       begin
  87.         with TspSkinTabControl(C) do
  88.           if (Integer(SkinData) = AFSD) or (AFSD = 0) then ChangeSkinData
  89.       end    
  90.     else
  91.     if C is TspSkinCustomEdit
  92.     then
  93.       begin
  94.         with TspSkinCustomEdit(C) do
  95.           if (Integer(SkinData) = AFSD) or (AFSD = 0) then ChangeSkinData;
  96.       end
  97.     else
  98.     if C is TspSkinMemo
  99.     then
  100.       begin
  101.         with TspSkinMemo(C) do
  102.           if (Integer(SkinData) = AFSD) or (AFSD = 0) then ChangeSkinData;
  103.       end
  104.     else
  105.     if C is TspSkinLinkLabel
  106.     then
  107.       begin
  108.         with TspSkinLinkLabel(C) do
  109.           if (Integer(SkinData) = AFSD) or (AFSD = 0) then ChangeSkinData;
  110.       end
  111.     else
  112.     if C is TspSkinButtonLabel
  113.     then
  114.       begin
  115.         with TspSkinButtonLabel(C) do
  116.           if (Integer(SkinData) = AFSD) or (AFSD = 0) then ChangeSkinData;
  117.       end
  118.     else
  119.     if C is TspSkinStdLabel
  120.     then
  121.       begin
  122.         with TspSkinStdLabel(C) do
  123.           if (Integer(SkinData) = AFSD) or (AFSD = 0) then ChangeSkinData;
  124.       end
  125.     else
  126.     if C is TspSkinTextLabel
  127.     then
  128.       begin
  129.         with TspSkinTextLabel(C) do
  130.           if (Integer(SkinData) = AFSD) or (AFSD = 0) then ChangeSkinData;
  131.       end
  132.     else
  133.     if C is TspSkinCustomTreeView
  134.     then
  135.       begin
  136.         with TspSkinTreeView(C) do
  137.           if (Integer(SkinData) = AFSD) or (AFSD = 0) then ChangeSkinData;
  138.       end
  139.     else
  140.     if C is TspSkinCustomListView
  141.     then
  142.       begin
  143.         with TspSkinListView(C) do
  144.           if (Integer(SkinData) = AFSD) or (AFSD = 0) then ChangeSkinData;
  145.       end
  146.     else
  147.     if C is TspSkinHeaderControl
  148.     then
  149.       begin
  150.         with TspSkinHeaderControl(C) do
  151.           if (Integer(SkinData) = AFSD) or (AFSD = 0) then ChangeSkinData;
  152.       end
  153.     else
  154.     if C is TspSkinControlBar
  155.     then
  156.       begin
  157.         with TspSkinControlBar(C) do
  158.           if (Integer(SkinData) = AFSD) or (AFSD = 0) then ChangeSkinData;
  159.       end
  160.     else
  161.     if C is TspSkinSplitter
  162.     then
  163.       begin
  164.         with TspSkinSplitter(C) do
  165.           if (Integer(SkinData) = AFSD) or (AFSD = 0) then ChangeSkinData;
  166.       end
  167.     else
  168.     if C is TspSkinBevel
  169.     then
  170.       begin
  171.         with TspSkinBevel(C) do
  172.           if (Integer(SkinData) = AFSD) or (AFSD = 0) then ChangeSkinData;
  173.       end;
  174. end;
  175. var
  176.   i: Integer;
  177. begin
  178.   CheckControl(WC);
  179.   for i := 0 to WC.ControlCount - 1 do
  180.   begin
  181.     if WC.Controls[i] is TWinControl
  182.     then
  183.       UpDateSkinControls(AFSD, TWinControl(WC.Controls[i]))
  184.     else
  185.       CheckControl(WC.Controls[i]);
  186.   end;
  187. end;
  188. procedure TspDynamicSkinForm.UnLinkControlFromArea(Control: TControl);
  189. var
  190.   i, j: Integer;
  191. begin
  192.   j := -1;
  193.   for i := 0 to AreaList.Count - 1 do
  194.   begin
  195.     if PAreaInfo(AreaList.Items[i])^.Control = Control
  196.     then
  197.       begin
  198.         j := i;
  199.         Break;
  200.       end;
  201.   end;
  202.   if j <> -1
  203.   then
  204.     begin
  205.       FreeMem(PAreaInfo(AreaList.Items[i]), Sizeof(TAreaInfo));
  206.       AreaList.Delete(j);
  207.     end;
  208. end;
  209. procedure TspDynamicSkinForm.LinkControlToArea;
  210. function GetAreaRect: TRect;
  211. var
  212.   i: Integer;
  213. begin
  214.   i := FSD.GetAreaIndex(AreaName);
  215.   if i <> - 1
  216.   then
  217.     Result := TspDataSkinArea(FSD.AreaList.Items[i]).AreaRect
  218.   else
  219.     Result := NullRect;
  220. end;
  221. var
  222.   PAI: PAreaInfo;
  223.   R: TRect;
  224. begin
  225.   R := GetAreaRect;
  226.   if IsNullRect(R) then Exit;
  227.   GetMem(PAI, Sizeof(TAreaInfo));
  228.   Control.Align := alNone;
  229.   PAI^.Control := Control;
  230.   PAI^.AreaRect := R;
  231.   AreaList.Add(PAI);
  232. end;
  233. procedure TspDynamicSkinForm.ControlsToAreas;
  234. var
  235.   i: Integer;
  236.   R: TRect;
  237.   FCanScale: Boolean;
  238. begin
  239.   if AreaList.Count = 0 then Exit;
  240.   FCanScale := CanScale;
  241.   for i := 0 to AreaList.Count - 1 do
  242.   with PAreaInfo(AreaList.Items[i])^ do
  243.   begin
  244.     if FCanScale
  245.     then
  246.       R := CalcRealObjectRect(AreaRect)
  247.     else
  248.       R := AreaRect;
  249.     Control.SetBounds(R.Left, R.Top, RectWidth(R), RectHeight(R));
  250.   end;
  251. end;
  252. procedure TspDynamicSkinForm.PopupSkinMenu;
  253. var
  254.   R: TRect;
  255. begin
  256.   SkinMenuOpen;
  257.   R := Rect(P.X, P.Y, P.X, P.Y);
  258.   if MenusSkinData = nil
  259.   then
  260.     SkinMenu.Popup(nil, SkinData, 0, R, Menu.Items, False)
  261.   else
  262.     SkinMenu.Popup(nil, MenusSkinData, 0, R, Menu.Items, False);
  263. end;
  264. procedure TspDynamicSkinForm.PopupSkinMenu1;
  265. begin
  266.   SkinMenuOpen;
  267.   if MenusSkinData = nil
  268.   then
  269.     SkinMenu.Popup(nil, SkinData, 0, R, Menu.Items, PopupUp)
  270.   else
  271.     SkinMenu.Popup(nil, MenusSkinData, 0, R, Menu.Items, PopupUp);
  272. end;
  273. procedure TspDynamicSkinForm.SetMainMenu;
  274. begin
  275.   FMainMenu := Value;
  276.   if (FSD <> nil) and not FSD.Empty and
  277.      not (csDesigning in ComponentState)
  278.   then UpDateMainMenu(True);
  279. end;
  280. procedure TspDynamicSkinForm.SkinMenuOpen;
  281. begin
  282.   if not InMainMenu
  283.   then
  284.     begin
  285.       HookApp;
  286.     end;
  287.   if not InMenu
  288.   then
  289.     begin
  290.       InMenu := True;
  291.       if Assigned(FOnSkinMenuOpen) then FOnSkinMenuOpen(Self);
  292.     end;
  293. end;
  294. procedure TspDynamicSkinForm.SkinMainMenuClose;
  295. var
  296.   i: Integer;
  297. begin
  298.   InMainMenu := False;
  299.   if SkinMenu.Visible then SkinMenu.Hide;
  300.   if FMainMenuBar <> nil
  301.   then
  302.     FMainMenuBar.MenuExit
  303.   else  
  304.   for i := 0 to ObjectList.Count - 1 do
  305.     if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinMainMenuItem then
  306.     begin
  307.       with TspSkinMainMenuItem(ObjectList.Items[i]) do
  308.         if Active then
  309.         begin
  310.           MouseLeave;
  311.           Break;
  312.         end;
  313.     end;
  314.   UnHookApp;
  315.   if Assigned(FOnMainMenuExit) then FOnMainMenuExit(Self);  
  316. end;
  317. procedure TspDynamicSkinForm.SkinMenuClose2;
  318. var
  319.   i: Integer;
  320. begin
  321.   InMenu := False;
  322.   if FMainMenuBar <> nil
  323.   then
  324.     FMainMenuBar.MenuClose
  325.   else
  326.   for i := 0 to ObjectList.Count - 1 do
  327.     if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinMainMenuItem then
  328.     begin
  329.       with TspSkinMainMenuItem(ObjectList.Items[i]) do
  330.         if FDown then
  331.         begin
  332.           SetDown(False);
  333.           MouseEnter;
  334.           Break;
  335.         end;
  336.     end;
  337.   if Assigned(FOnSkinMenuClose) then FOnSkinMenuClose(Self);
  338. end;
  339. procedure TspDynamicSkinForm.SkinMenuClose;
  340. var
  341.   i: Integer;
  342. begin
  343.   InMenu := False;
  344.   for i := 0 to ObjectList.Count - 1 do
  345.     if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinMainMenuItem then
  346.     begin
  347.       with TspSkinMainMenuItem(ObjectList.Items[i]) do
  348.         if FDown then
  349.         begin
  350.           Active := False;
  351.           SetDown(False);
  352.           Break;
  353.         end;
  354.     end
  355.     else
  356.     if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinButtonObject then
  357.     begin
  358.       with TspSkinButtonObject (ObjectList.Items[i]) do
  359.         if (MenuItem <> nil) and FDown then
  360.         begin
  361.           SetDown(False);
  362.           Break;
  363.         end;
  364.     end;
  365.   UnHookApp;
  366.   if Assigned(FOnSkinMenuClose) then FOnSkinMenuClose(Self);
  367.   if InMainMenu
  368.   then
  369.     begin
  370.       InMainMenu := False;
  371.       if FMainMenuBar <> nil then FMainMenuBar.MenuExit;
  372.       if Assigned(FOnMainMenuExit) then FOnMainMenuExit(Self);
  373.     end;
  374. end;
  375. procedure TspDynamicSkinForm.CheckWindowState;
  376. begin
  377.   if (ActiveObject <> -1)
  378.   then
  379.     if TspActiveSkinObject(ObjectList.Items[ActiveObject]) is TspSkinCaptionObject
  380.     then
  381.       begin
  382.         if FRollUpState
  383.         then
  384.           RollUpState := False
  385.         else
  386.           if not FSizeAble
  387.           then
  388.             RollUpState := True
  389.           else
  390.             if WindowState = wsNormal
  391.             then WindowState := wsMaximized
  392.             else WindowState := wsNormal;
  393.       end;
  394. end;
  395. procedure TspDynamicSkinForm.CheckObjects;
  396. var
  397.   i, j: Integer;
  398.   B: Boolean;
  399. begin
  400.   if ObjectList.Count > 0 then
  401.   for i := 0 to ObjectList.Count - 1 do
  402.     if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinAnimateObject
  403.     then
  404.       with TspSkinAnimateObject(ObjectList.Items[i]) do
  405.       begin
  406.         if ButtonStyle and (Command <> cmDefault)
  407.         then
  408.           begin
  409.             if not (biRollUp in FBorderIcons) and
  410.                (Command = cmRollUp) then Enabled := False else
  411.             if not (biMaximize in FBorderIcons) and
  412.                (Command = cmMaximize) then Enabled := False else
  413.             if not (biMinimize in FBorderIcons) and
  414.                (Command = cmMinimize) then Enabled := False else
  415.             if not (biSystemMenu in FBorderIcons) and
  416.                (Command = cmSysMenu) then Enabled := False;
  417.           end;
  418.       end
  419.     else
  420.     if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinStdButtonObject
  421.     then
  422.       with TspSkinStdButtonObject(ObjectList.Items[i]) do
  423.       begin
  424.         if not (biRollUp in FBorderIcons) and (Command = cmRollUp)
  425.            then
  426.              begin
  427.                Enabled := False;
  428.                Visible := not SkinRectInAPicture;
  429.              end
  430.            else
  431.         if not (biMaximize in FBorderIcons) and (Command = cmMaximize)
  432.            then
  433.              begin
  434.                Enabled := False;
  435.                Visible := not SkinRectInAPicture;
  436.              end
  437.            else
  438.         if not (biMinimize in FBorderIcons) and (Command = cmMinimize)
  439.            then
  440.              begin
  441.                Enabled := False;
  442.                Visible := not SkinRectInAPicture;
  443.              end
  444.            else
  445.         if not (biSystemMenu in FBorderIcons) and (Command = cmSysMenu)
  446.         then
  447.           begin
  448.             Enabled := False;
  449.             Visible := not SkinRectInAPicture;
  450.           end;
  451.       end
  452.     else
  453.       if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinCaptionObject
  454.       then
  455.         with TspSkinCaptionObject(ObjectList.Items[i]) do
  456.         begin
  457.           if DefaultCaption
  458.           then FTextValue := FForm.Caption;
  459.         end;
  460.   B := False;
  461.   j := -1;
  462.   if ObjectList.Count > 0
  463.   then
  464.     for i := 0 to ObjectList.Count - 1 do
  465.       if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinCaptionObject
  466.       then
  467.         with TspSkinCaptionObject(ObjectList.Items[i]) do
  468.         if DefaultCaption
  469.         then
  470.           begin
  471.             B := True;
  472.             Break;
  473.           end
  474.         else
  475.           if j = -1 then j := i;
  476.   if (j <> -1) and not B and
  477.      (TspActiveSkinObject(ObjectList.Items[j]) is TspSkinCaptionObject)
  478.   then
  479.     with TspSkinCaptionObject(ObjectList.Items[j]) do
  480.     begin
  481.       DefaultCaption := True;
  482.       FTextValue := FForm.Caption;
  483.     end;
  484. end;
  485. function TspDynamicSkinForm.CanScale;
  486. begin
  487.   if (FSD.RBPoint.X - FSD.LTPoint.X = 0) or
  488.      (FSD.RBPoint.Y - FSD.LTPoint.Y = 0)
  489.   then
  490.     Result := False
  491.   else
  492.     Result := True;
  493. end;
  494. function TspDynamicSkinForm.GetIndex;
  495. var
  496.   i, j: Integer;
  497. begin
  498.   j := -1;
  499.   for i := 0 to ObjectList.Count - 1 do
  500.   begin
  501.     if AIDName = TspActiveSkinObject(ObjectList.Items[i]).IDName
  502.     then
  503.       begin
  504.         j := i;
  505.         Break;
  506.       end;
  507.   end;
  508.   Result := j;
  509. end;
  510. procedure TspDynamicSkinForm.UserObjectDraw;
  511. var
  512.   i: Integer;
  513. begin
  514.   i := GetIndex(AIDName);
  515.   if i <> -1
  516.   then
  517.     if TspActiveSkinObject(ObjectList.Items[i]) is TspUserObject
  518.     then
  519.       TspUserObject(ObjectList.Items[i]).Draw(FForm.Canvas, True);
  520. end;
  521. procedure TspDynamicSkinForm.SwitchChangeStateEvent;
  522. begin
  523.  if Assigned(FOnSwitchChangeStateEvent)
  524.  then FOnSwitchChangeStateEvent(IDName, State);
  525. end;
  526. procedure TspDynamicSkinForm.AnimateStart;
  527. var
  528.   i: Integer;
  529. begin
  530.   i := GetIndex(AIDName);
  531.   if i <> - 1 then
  532.   if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinAnimateObject
  533.   then
  534.     TspSkinAnimateObject(ObjectList.Items[i]).Start;
  535. end;
  536. procedure TspDynamicSkinForm.AnimateStop;
  537. var
  538.   i: Integer;
  539. begin
  540.   i := GetIndex(AIDName);
  541.   if i <> - 1 then
  542.   if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinAnimateObject
  543.   then
  544.     TspSkinAnimateObject(ObjectList.Items[i]).Stop;
  545. end;
  546. procedure TspDynamicSkinForm.TrackBarChangeValueEvent;
  547. begin
  548.  if Assigned(FOnTrackBarChangeValueEvent)
  549.  then FOnTrackBarChangeValueEvent(IDName, Value);
  550. end;
  551. procedure TspDynamicSkinForm.FrameRegulatorChangeValueEvent;
  552. begin
  553.  if Assigned(FOnFrameRegulatorChangeValueEvent)
  554.  then FOnFrameRegulatorChangeValueEvent(IDName, Value);
  555. end;
  556. function TspDynamicSkinForm.TrackBarGetValue;
  557. var
  558.   i: Integer;
  559. begin
  560.   i := GetIndex(AIDName);
  561.   if i <> -1
  562.   then
  563.     begin
  564.       if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinTrackBarObject
  565.       then
  566.         with TspSkinTrackBarObject(ObjectList.Items[i]) do Result := Value
  567.       else
  568.         Result := 0;
  569.     end
  570.   else
  571.     Result := 0;
  572. end;
  573. procedure TspDynamicSkinForm.BitLabelSetText;
  574. var
  575.   i: Integer;
  576. begin
  577.   i := GetIndex(AIDName);
  578.   if i <> - 1 then
  579.   if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinBitLabelObject
  580.   then
  581.     with TspSkinBitLabelObject(ObjectList.Items[i]) do
  582.       if FInChangeSkinData
  583.       then SetTextValue(AValue, False)
  584.       else SetTextValue(AValue, True);
  585. end;
  586. procedure TspDynamicSkinForm.GaugeSetValue;
  587. var
  588.   i: Integer;
  589. begin
  590.   i := GetIndex(AIDName);
  591.   if i <> - 1 then
  592.   if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinGaugeObject
  593.   then
  594.     with TspSkinGaugeObject(ObjectList.Items[i]) do
  595.       if FInChangeSkinData
  596.       then SimplySetValue(AValue)
  597.       else Value := AValue;
  598. end;
  599. procedure TspDynamicSkinForm.FrameGaugeSetValue;
  600. var
  601.   i: Integer;
  602. begin
  603.   i := GetIndex(AIDName);
  604.   if i <> - 1 then
  605.   if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinFrameGaugeObject
  606.   then
  607.     with TspSkinFrameGaugeObject(ObjectList.Items[i]) do
  608.       if FInChangeSkinData
  609.       then SimplySetValue(AValue)
  610.       else Value := AValue;
  611. end;
  612. procedure TspDynamicSkinForm.LabelSetText;
  613. var
  614.   i: Integer;
  615. begin
  616.   i := GetIndex(AIDName);
  617.   if i <> - 1 then
  618.   if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinLabelObject
  619.   then
  620.     with TspSkinLabelObject(ObjectList.Items[i]) do
  621.       if FInChangeSkinData
  622.       then SetTextValue(ATextValue, False)
  623.       else SetTextValue(ATextValue, True);
  624. end;
  625. function TspDynamicSkinForm.FrameRegulatorGetValue;
  626. var
  627.   i: Integer;
  628. begin
  629.   i := GetIndex(AIDName);
  630.   if i <> -1
  631.   then
  632.     begin
  633.       if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinFrameRegulatorObject
  634.       then
  635.         with TspSkinFrameRegulatorObject(ObjectList.Items[i]) do Result := Value
  636.       else
  637.         Result := 0;
  638.     end
  639.   else
  640.     Result := 0;
  641. end;
  642. procedure TspDynamicSkinForm.FrameRegulatorSetValue;
  643. var
  644.   i: Integer;
  645. begin
  646.   i := GetIndex(AIDName);
  647.   if i <> - 1 then
  648.   if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinFrameRegulatorObject
  649.   then
  650.     with TspSkinFrameRegulatorObject(ObjectList.Items[i]) do
  651.       if FInChangeSkinData
  652.       then SimplySetValue(AValue)
  653.       else Value := AValue;
  654. end;
  655. procedure TspDynamicSkinForm.TrackBarSetValue;
  656. var
  657.   i: Integer;
  658. begin
  659.   i := GetIndex(AIDName);
  660.   if i <> - 1 then
  661.   if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinTrackBarObject
  662.   then
  663.     with TspSkinTrackBarObject(ObjectList.Items[i]) do
  664.       if FInChangeSkinData
  665.       then SimplySetValue(AValue)
  666.       else Value := AValue;
  667. end;
  668. procedure TspDynamicSkinForm.DoMagnetic;
  669. var
  670.   R: TRect;
  671.   LW, TR: Integer;
  672.   P: TPoint;
  673. begin
  674.   if FForm.FormStyle <> fsMDIChild
  675.   then
  676.     SystemParametersInfo(SPI_GETWORKAREA, 0, @R, 0)
  677.   else
  678.     begin
  679.       R := GetMDIWorkArea;
  680.       P := Application.MainForm.ClientToScreen(Point(0, 0));
  681.       OffsetRect(R, P.X, P.Y);
  682.     end;
  683.   if (L < R.Left + FMagneticSize) and (L > R.Left - FMagneticSize)
  684.   then L := R.Left;
  685.   if (T < R.Top + FMagneticSize) and (T > R.Top - FMagneticSize)
  686.   then T := R.Top;
  687.   LW := L + W; TR := T + H;
  688.   if (LW > R.Right - FMagneticSize) and (LW < R.Right + FMagneticSize)
  689.   then L := R.Right - W;
  690.   if (TR > R.Bottom - FMagneticSize) and (TR < R.Bottom + FMagneticSize)
  691.   then T := R.Bottom - H;
  692. end;
  693. function TspDynamicSkinForm.InForm;
  694. var
  695.   H: HWND;
  696. begin
  697.   H := WindowFromPoint(P);
  698.   Result := H = FForm.Handle;
  699. end;
  700. function TspDynamicSkinForm.PtInMask;
  701. var
  702.   B: Boolean;
  703. begin
  704.   if PtInRect(NewMaskRectArea, P)
  705.   then
  706.     B := True
  707.   else
  708.     if P.Y <= NewMaskRectArea.Top
  709.     then
  710.       B := RMTop.Canvas.Pixels[P.X, P.Y] = BlackColor
  711.     else
  712.       if P.Y >= NewMaskRectArea.Bottom
  713.       then
  714.         B := RMBottom.Canvas.Pixels[P.X, P.Y - NewMaskRectArea.Bottom] = BlackColor
  715.       else
  716.         if P.X <= NewMaskRectArea.Left
  717.         then
  718.           B := RMLeft.Canvas.Pixels[P.X, P.Y - NewMaskRectArea.Top] = BlackColor
  719.         else
  720.           B := RMRight.Canvas.Pixels[P.X - NewMaskRectArea.Right, P.Y - NewMaskRectArea.Top] = BlackColor;
  721.   Result := B;
  722. end;
  723. procedure TspDynamicSkinForm.SetWindowState;
  724. begin
  725.   if FWindowState <> Value
  726.   then
  727.     begin
  728.       if not ((Value = wsMinimized) and (FForm = Application.MainForm))
  729.       then
  730.         FWindowState := Value;
  731.         case Value of
  732.           wsNormal: DoNormalize;
  733.           wsMaximized: DoMaximize;
  734.           wsMinimized: DoMinimize;
  735.         end;
  736.     end;
  737. end;
  738. procedure TspDynamicSkinForm.DoMinimize;
  739. var
  740.   P: TPoint;
  741. begin
  742.   if (Application.MainForm = FForm) or not FSupportNCArea
  743.   then
  744.     Application.Minimize
  745.   else
  746.     begin
  747.       if IsNullRect(OldBoundsRect)
  748.       then OldBoundsRect := FForm.BoundsRect;
  749.       P := GetMinimizeCoord;
  750.       FForm.SetBounds(P.X, P.Y, GetMinWidth, GetMinHeight);
  751.       if (FForm.FormStyle = fsMDIChild) and (FWindowState <> wsMaximized)
  752.       then
  753.         begin
  754.           SendMessage(Application.MainForm.Handle, WM_MDICHILDRESTORE, 0, 0);
  755.         end;
  756.     end;
  757. end;
  758. procedure TspDynamicSkinForm.DoMaximize;
  759. var
  760.   R: TRect;
  761.   OW, OH: Integer;
  762. begin
  763.   if IsNullRect(OldBoundsRect) then OldBoundsRect := FForm.BoundsRect;
  764.   if FForm.FormStyle = fsMDIChild
  765.   then
  766.     begin
  767.       MouseTimer.Enabled := False;
  768.       TestActive(-1, -1, False);
  769.       R := GetMDIWorkArea;
  770.       OW := FForm.Width;
  771.       OH := FForm.Height;
  772.       FForm.SetBounds(0, 0, RectWidth(R),  RectHeight(R));
  773.       if (OW = RectWidth(R)) and (OH = RectHeight(R)) then UpDateForm;
  774.       SendMessage(Application.MainForm.Handle, WM_MDICHILDMAX, 0, 0);
  775.     end
  776.   else
  777.     begin
  778.       if not FMaximizeOnFullScreen
  779.       then
  780.         SystemParametersInfo(SPI_GETWORKAREA, 0, @R, 0)
  781.       else
  782.         R := Rect(0, 0, Screen.Width, Screen.Height);
  783.       FForm.SetBounds(R.Left, R.Top, RectWidth(R), RectHeight(R));
  784.     end;
  785. end;
  786. procedure TspDynamicSkinForm.DoNormalize;
  787. var
  788.   OW, OH: Integer;
  789. begin
  790.   MaxRollUpState := False;
  791.   if FSupportNCArea
  792.   then
  793.     begin
  794.       OW := FForm.Width;
  795.       OH := FForm.Height;
  796.       FForm.SetBounds(OldBoundsRect.Left, OldBoundsRect.Top,
  797.                       RectWidth(OldBoundsRect),
  798.                       RectHeight(OldBoundsRect));
  799.       MouseTimer.Enabled := True;
  800.       if (OW = RectWidth(OldBoundsRect)) and
  801.          (OH = RectHeight(OldBoundsRect))
  802.       then
  803.         UpDateForm;
  804.       FForm.RePaint;
  805.       if (FForm.FormStyle = fsMDIChild) and (FWindowState <> wsMaximized)
  806.       then
  807.         begin
  808.           SendMessage(Application.MainForm.Handle, WM_MDICHILDRESTORE, 0, 0);
  809.         end;
  810.       OldBoundsRect := NullRect;  
  811.     end
  812.   else
  813.     begin
  814.       FForm.SetBounds(OldBoundsRect.Left,OldBoundsRect.Top,
  815.                       RectWidth(OldBoundsRect),
  816.                       RectHeight(OldBoundsRect));
  817.       OldBoundsRect := NullRect;
  818.       MouseTimer.Enabled := True;
  819.     end;
  820. end;
  821. procedure TspDynamicSkinForm.LinkMenu;
  822. var
  823.   i: Integer;
  824. begin
  825.   i := GetIndex(AIDName);
  826.   if i <> - 1 then
  827.   if (TspActiveSkinObject(ObjectList.Items[i]) is TspSkinButtonObject)
  828.   then
  829.     with TspSkinButtonObject(ObjectList.Items[i]) do
  830.     begin
  831.       MenuItem := AMenu.Items;
  832.       FPopupUp := APopupUp;
  833.     end
  834.   else
  835.   if (TspActiveSkinObject(ObjectList.Items[i]) is TspSkinAnimateObject)
  836.   then
  837.     with TspSkinAnimateObject(ObjectList.Items[i]) do
  838.       if ButtonStyle
  839.       then
  840.         begin
  841.           MenuItem := AMenu.Items;
  842.           FPopupUp := APopupUp;
  843.         end;  
  844. end;
  845. procedure TspDynamicSkinForm.CheckSize;
  846. var
  847.   CS: Boolean;
  848. begin
  849.   CS := CanScale;
  850.   if not CS
  851.   then
  852.     begin
  853.       if FForm.ClientWidth <> FSD.FPicture.Width
  854.       then FForm.ClientWidth := FSD.FPicture.Width;
  855.       if FForm.ClientHeight <> FSD.FPicture.Height
  856.       then FForm.ClientHeight := FSD.FPicture.Height;
  857.       FSizeAble := False;
  858.     end
  859.   else
  860.     if (FMinWidth = 0) or (FMinHeight = 0)
  861.     then
  862.       begin
  863.         if FForm.ClientWidth < FSD.FPicture.Width
  864.         then
  865.           FForm.ClientWidth := FSD.FPicture.Width;
  866.           if FForm.ClientHeight < FSD.FPicture.Height
  867.           then
  868.             FForm.ClientHeight := FSD.FPicture.Height;
  869.       end;
  870. end;
  871. procedure TspDynamicSkinForm.UpDateForm;
  872. begin
  873.   with FForm do
  874.   begin
  875.     if Width - 1 >= GetMinWidth
  876.     then
  877.       begin
  878.         Width := Width - 1;
  879.         Width := Width + 1;
  880.       end
  881.     else
  882.       begin
  883.         Width := Width + 1;
  884.         Width := Width - 1;
  885.       end;
  886.   end;
  887. end;
  888. procedure TspDynamicSkinForm.ChangeSkinData;
  889. var
  890.   CS: Boolean;
  891.   NotRollUp: Boolean;
  892. begin
  893.   OldActiveObject := -1;
  894.   ActiveObject := -1;
  895.   MouseCaptureObject := -1;
  896.   if (FSD = nil) or (FSD.Empty)
  897.   then
  898.     FSkinSupport := False
  899.   else
  900.     FSkinSupport := True;
  901.   if FSupportNCArea
  902.   then
  903.     begin
  904.       if FSkinSupport
  905.       then
  906.         begin
  907.           LoadObjects;
  908.           CheckObjects;
  909.         end
  910.       else
  911.         CreateNewRegion(True);
  912.       FInChangeSkinData := True;
  913.       if (FForm.Width < GetMinWidth) and (FForm.Height < GetMinHeight)
  914.       then
  915.         begin
  916.           FForm.SetBounds(FForm.Left, FForm.Top,
  917.                           GetMinWidth, GetMinHeight);
  918.         end
  919.       else
  920.       if FForm.Height < GetMinHeight then FForm.Height := GetMinHeight else
  921.       if FForm.Width < GetMinWidth then FForm.Width := GetMinWidth else
  922.       UpDateForm;
  923.       if (FRollUpState or (FWindowState = wsMinimized)) and
  924.          (FForm.Height <> GetMinHeight)
  925.       then
  926.         FForm.Height := GetMinHeight;
  927.       if (FWindowState = wsMinimized) and (FForm.Width <> GetMinWidth)
  928.       then
  929.         FForm.Width := GetMinWidth;
  930.       FFormWidth := FForm.Width;
  931.       FFormHeight := FForm.Height;
  932.       if FSkinSupport then CreateNewForm(True);
  933.       if (FForm.FormStyle = fsMDIForm)
  934.       then
  935.         begin
  936.           ReDrawWindow(FForm.ClientHandle, nil, 0, RDW_ERASE or RDW_INVALIDATE);
  937.           ResizeMDIChilds;
  938.         end
  939.       else
  940.         FForm.RePaint;
  941.       if (FForm.FormStyle = fsMDIChild) and (WindowState = wsMaximized)
  942.       then FormChangeActive(False)
  943.       else FormChangeActive(True);
  944.       MouseTimer.Enabled := True;
  945.       if Assigned(FOnChangeSkinData) then FOnChangeSkinData(Self);
  946.       FInChangeSkinData := False;
  947.     end
  948.   else
  949.     if FSkinSupport
  950.     then 
  951.     begin
  952.       CS := CanScale;
  953.       NotRollUp := FRollUpState and FSD.FRollUpPicture.Empty;
  954.       if NotRollUp
  955.       then
  956.         begin
  957.           FRollUpState := False;
  958.           RestoreRollUpForm;
  959.         end;
  960.       if not FRollUpState then CheckSize;
  961.       LoadObjects;
  962.       CheckObjects;
  963.       if not NotRollUp and FRollUpState then CreateRollUpForm;
  964.       FInChangeSkinData := True;
  965.       if Assigned(FOnChangeSkinData) then FOnChangeSkinData(Self);
  966.       if not FRollUpState then
  967.       if CS or (not CS and (FForm.ClientWidth = FSD.FPicture.Width) and
  968.         (FForm.ClientHeight = FSD.FPicture.Height))
  969.       then CreateNewForm(CS);
  970.       LinkControlsToAreas;
  971.       ControlsToAreas;
  972.       FormChangeActive(True);
  973.       FInChangeSkinData := False;
  974.       MouseTimer.Enabled := True;
  975.     end;
  976. end;
  977. procedure TspDynamicSkinForm.SetSkinData(Value: TspSkinData);
  978. begin
  979.   FSD := Value;
  980.   if (FSD <> nil) then
  981.   if not FSD.Empty and not (csDesigning in ComponentState) then ChangeSkinData;
  982.   FSysTrayMenu.SkinData := Value;
  983. end;
  984. procedure TspDynamicSkinForm.SetMenusSkinData(Value: TspSkinData);
  985. begin
  986.   FMSD := Value;
  987. end;
  988. procedure TspDynamicSkinForm.LinkControlsToAreas;
  989. var
  990.   i: Integer;
  991. begin
  992.   with FForm do
  993.   for i := 0 to ControlCount - 1 do
  994.     if Controls[i] is TspSkinControl
  995.     then
  996.       begin
  997.         if TspSkinControl(Controls[i]).AreaName <> ''
  998.         then
  999.           LinkControlToArea(TspSkinControl(Controls[i]).AreaName, Controls[i]);
  1000.       end
  1001.     else
  1002.     if Controls[i] is TspGraphicSkinControl
  1003.     then
  1004.       begin
  1005.         if TspGraphicSkinControl(Controls[i]).AreaName <> ''
  1006.         then
  1007.           LinkControlToArea(TspGraphicSkinControl(Controls[i]).AreaName, Controls[i]);
  1008.       end;
  1009. end;
  1010. procedure TspDynamicSkinForm.Notification(AComponent: TComponent;
  1011.                                           Operation: TOperation);
  1012. begin
  1013.   inherited Notification(AComponent, Operation);
  1014.   if (Operation = opRemove) and (AComponent = FSD)
  1015.   then FSD := nil else
  1016.   if (Operation = opRemove) and (AComponent = FMSD)
  1017.   then FMSD := nil else
  1018.   if (Operation = opRemove) and (AComponent = FMainMenu)
  1019.   then FMainMenu := nil else
  1020.   if (Operation = opRemove) and (AComponent = FSystemMenu)
  1021.   then FSystemMenu := nil else
  1022.   if (Operation = opRemove) and (AComponent = FMainMenuBar)
  1023.   then FMainMenuBar := nil else
  1024.   if (Operation = opRemove) and (AComponent = FTrayIcon)
  1025.   then FTrayIcon := nil;
  1026.   if (Operation = opRemove) and (AComponent = FSkinHint)
  1027.   then FSkinHint := nil;
  1028. end;
  1029. procedure TspDynamicSkinForm.UpdateMainMenu;
  1030. function DeleteMainMenuItem: Boolean;
  1031. var
  1032.   i, j: Integer;
  1033. begin
  1034.   j := -1;
  1035.   for i := ObjectList.Count - 1 downto 0 do
  1036.    if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinMainMenuItem
  1037.    then
  1038.      begin
  1039.        j := i;
  1040.        Break;
  1041.      end;
  1042.   if j <> - 1
  1043.   then
  1044.     begin
  1045.       TspSkinMainMenuItem(ObjectList.Items[j]).Free;
  1046.       ObjectList.Delete(j);
  1047.       Result := True;
  1048.     end
  1049.   else
  1050.     Result := False;
  1051. end;
  1052. var
  1053.   R: TRect;
  1054. begin
  1055.   //delete old items
  1056.   repeat
  1057.   until not DeleteMainMenuItem;
  1058.   //create new menu
  1059.   CreateMainMenu;
  1060.   R := NewMainMenuRect;
  1061.   if ARedraw
  1062.   then
  1063.     if SupportNCArea
  1064.     then
  1065.       SendMessage(FForm.Handle, WM_NCPaint, 0, 0)
  1066.     else
  1067.       InvalidateRect(FForm.Handle, @R, True);
  1068. end;
  1069. procedure TspDynamicSkinForm.CreateMainMenu;
  1070. var
  1071.   i, j: Integer;
  1072.   MMIData: TspDataSkinMainMenuItem;
  1073. begin
  1074.   if FMainMenu = nil then Exit;
  1075.   j := FSD.GetIndex('MAINMENUITEM');
  1076.   if j <> -1
  1077.   then
  1078.     begin
  1079.       MMIData := TspDataSkinMainMenuItem(FSD.ObjectList.Items[j]);
  1080.       for i := 0 to FMainMenu.Items.Count - 1 do
  1081.         if FMainMenu.Items[i].Visible
  1082.         then
  1083.           begin
  1084.             ObjectList.Add(TspSkinMainMenuItem.Create(Self, MMIData));
  1085.             with TspSkinMainMenuItem(ObjectList.Items[ObjectList.Count - 1]) do
  1086.             begin
  1087.               IDName := FMainMenu.Items[i].Name;
  1088.               Enabled := FMainMenu.Items[i].Enabled;
  1089.               MenuItem := FMainMenu.Items[i];
  1090.             end;
  1091.          end;
  1092.     end;
  1093. end;
  1094. procedure TspDynamicSkinForm.LoadDefObjects;
  1095. var
  1096.   NotNullRect: TRect;
  1097. begin
  1098.   ClearObjects;
  1099.   NotNullRect := Rect(0, 0, 1, 1);
  1100.   ObjectList.Add(TspSkinStdButtonObject.Create(Self, nil));
  1101.   with TspSkinStdButtonObject(ObjectList.Items[ObjectList.Count - 1]) do
  1102.   begin
  1103.     SkinRectInAPicture := True;
  1104.     SkinRect := NotNullRect;
  1105.     ActiveSkinRect := NotNullRect;
  1106.     DownRect := NotNullRect;
  1107.     Command := cmClose;
  1108.     IDName := 'closebutton';
  1109.   end;
  1110.   ObjectList.Add(TspSkinStdButtonObject.Create(Self, nil));
  1111.   with TspSkinStdButtonObject(ObjectList.Items[ObjectList.Count - 1]) do
  1112.   begin
  1113.     SkinRectInAPicture := True;
  1114.     SkinRect := NotNullRect;
  1115.     ActiveSkinRect := NotNullRect;
  1116.     DownRect := NotNullRect;
  1117.     Command := cmMaximize;
  1118.     IDName := 'maxbutton';
  1119.   end;
  1120.   ObjectList.Add(TspSkinStdButtonObject.Create(Self, nil));
  1121.   with TspSkinStdButtonObject(ObjectList.Items[ObjectList.Count - 1]) do
  1122.   begin
  1123.     SkinRectInAPicture := True;
  1124.     SkinRect := NotNullRect;
  1125.     ActiveSkinRect := NotNullRect;
  1126.     DownRect := NotNullRect;
  1127.     Command := cmMinimize;
  1128.     IDName := 'minbutton';
  1129.   end;
  1130.   ObjectList.Add(TspSkinStdButtonObject.Create(Self, nil));
  1131.   with TspSkinStdButtonObject(ObjectList.Items[ObjectList.Count - 1]) do
  1132.   begin
  1133.     SkinRectInAPicture := True;
  1134.     SkinRect := NotNullRect;
  1135.     ActiveSkinRect := NotNullRect;
  1136.     DownRect := NotNullRect;
  1137.     Command := cmRollUp;
  1138.     IDName := 'rollupbutton';
  1139.   end;
  1140.   ObjectList.Add(TspSkinStdButtonObject.Create(Self, nil));
  1141.   with TspSkinStdButtonObject(ObjectList.Items[ObjectList.Count - 1]) do
  1142.   begin
  1143.     SkinRectInAPicture := True;
  1144.     SkinRect := NotNullRect;
  1145.     ActiveSkinRect := NotNullRect;
  1146.     DownRect := NotNullRect;
  1147.     Command := cmSysMenu;
  1148.     IDName := 'sysmenubutton';
  1149.   end;
  1150.   CheckObjects;
  1151. end;
  1152. procedure TspDynamicSkinForm.LoadObjects;
  1153. var
  1154.   i: Integer;
  1155.   OL: TList;
  1156. begin
  1157.   ClearObjects;
  1158.   OL := FSD.ObjectList;
  1159.   for i := 0 to OL.Count - 1 do
  1160.   begin
  1161.     if (TspDataSkinObject(OL.Items[i]) is TspDataSkinMainMenuItem) or
  1162.        (TspDataSkinObject(OL.Items[i]) is TspDataSkinMenuItem) or
  1163.        (TspDataSkinObject(OL.Items[i]) is TspDataSkinMainMenuBarButton) 
  1164.     then
  1165.       begin
  1166.       end
  1167.     else
  1168.     if TspDataSkinObject(OL.Items[i]) is TspDataSkinGauge
  1169.     then
  1170.       ObjectList.Add(TspSkinGaugeObject.Create(Self, TspDataSkinGauge(OL.Items[i])))
  1171.     else
  1172.     if TspDataSkinObject(OL.Items[i]) is TspDataSkinStdButton
  1173.     then
  1174.       ObjectList.Add(TspSkinStdButtonObject.Create(Self, TspDataSkinStdButton(OL.Items[i])))
  1175.     else
  1176.     if TspDataSkinObject(OL.Items[i]) is TspDataSkinButton
  1177.     then ObjectList.Add(TspSkinButtonObject.Create(Self, TspDataSkinButton(OL.Items[i])))
  1178.     else
  1179.     if TspDataSkinObject(OL.Items[i]) is TspDataSkinCaption
  1180.     then ObjectList.Add(TspSkinCaptionObject.Create(Self, TspDataSkinCaption(OL.Items[i])))
  1181.     else
  1182.     if TspDataSkinObject(OL.Items[i]) is TspDataUserObject
  1183.     then ObjectList.Add(TspUserObject.Create(Self, TspDataUserObject(OL.Items[i])))
  1184.     else
  1185.     if TspDataSkinObject(OL.Items[i]) is TspDataSkinSwitch
  1186.     then ObjectList.Add(TspSkinSwitchObject.Create(Self, TspDataSkinSwitch(OL.Items[i])))
  1187.     else
  1188.     if TspDataSkinObject(OL.Items[i]) is TspDataSkinTrackBar
  1189.     then ObjectList.Add(TspSkinTrackBarObject.Create(Self, TspDataSkinTrackBar(OL.Items[i])))
  1190.     else
  1191.     if TspDataSkinObject(OL.Items[i]) is TspDataSkinLabel
  1192.     then ObjectList.Add(TspSkinLabelObject.Create(Self, TspDataSkinLabel(OL.Items[i])))
  1193.     else
  1194.     if TspDataSkinObject(OL.Items[i]) is TspDataSkinAnimate
  1195.     then ObjectList.Add(TspSkinAnimateObject.Create(Self, TspDataSkinAnimate(OL.Items[i])))
  1196.     else
  1197.     if TspDataSkinObject(OL.Items[i]) is TspDataSkinBitLabel
  1198.     then ObjectList.Add(TspSkinBitLabelObject.Create(Self, TspDataSkinBitLabel(OL.Items[i])))
  1199.     else
  1200.     if TspDataSkinObject(OL.Items[i]) is TspDataSkinFrameRegulatorObject
  1201.     then ObjectList.Add(TspSkinFrameRegulatorObject.Create(Self,
  1202.       TspDataSkinFrameRegulatorObject(OL.Items[i])))
  1203.     else
  1204.     if TspDataSkinObject(OL.Items[i]) is TspDataSkinFrameGaugeObject
  1205.     then ObjectList.Add(TspSkinFrameGaugeObject.Create(Self,
  1206.       TspDataSkinFrameGaugeObject(OL.Items[i])));
  1207.   end;
  1208.   CreateMainMenu;
  1209. end;
  1210. procedure TspDynamicSkinForm.ClearObjects;
  1211. var
  1212.   i: Integer;
  1213. begin
  1214.   for i := 0 to ObjectList.Count - 1 do
  1215.     TspActiveSkinObject(ObjectList.Items[i]).Free;
  1216.   ObjectList.Clear;
  1217.   for i := 0 to AreaList.Count - 1 do
  1218.     FreeMem(PAreaInfo(AreaList.Items[i]), Sizeof(TAreaInfo));
  1219.   AreaList.Clear;
  1220. end;
  1221. procedure TspDynamicSkinForm.TestActive;
  1222. var
  1223.   i: Integer;
  1224.   B: Boolean;
  1225.   ObjHint: String;
  1226. begin
  1227.   if (ObjectList.Count = 0) or (not GetFormActive and FSupportNCArea)
  1228.   then
  1229.     Exit;
  1230.   OldActiveObject := ActiveObject;
  1231.   i := -1;
  1232.   B := False;
  1233.   repeat
  1234.     Inc(i);
  1235.     with TspActiveSkinObject(ObjectList.Items[i]) do
  1236.     begin
  1237.       if CanObjectTest(RollUp) and Enabled and Visible
  1238.       then
  1239.         B := PtInRect(ObjectRect, Point(X, Y));
  1240.     end;
  1241.   until B or (i = ObjectList.Count - 1);
  1242.   if B and InFrm
  1243.   then ActiveObject := i
  1244.   else ActiveObject := -1;
  1245.   if (MouseCaptureObject <> -1) and
  1246.      (ActiveObject <> MouseCaptureObject) and (ActiveObject <> -1)
  1247.   then
  1248.     ActiveObject := -1;
  1249.   if OldActiveObject >= ObjectList.Count then OldActiveObject := -1;
  1250.   if ActiveObject >= ObjectList.Count then ActiveObject := -1;
  1251.   if (OldActiveObject <> ActiveObject)
  1252.   then
  1253.     begin
  1254.       if OldActiveObject <> - 1
  1255.       then
  1256.         begin
  1257.           if TspActiveSkinObject(ObjectList.Items[OldActiveObject]).Enabled and
  1258.              TspActiveSkinObject(ObjectList.Items[OldActiveObject]).Visible
  1259.           then TspActiveSkinObject(ObjectList.Items[OldActiveObject]).MouseLeave;
  1260.           if FShowObjectHint and (FSkinHint <> nil) and
  1261.              TspActiveSkinObject(ObjectList.Items[OldActiveObject]).Enabled and
  1262.              (TspActiveSkinObject(ObjectList.Items[OldActiveObject]).Hint <> '') and
  1263.              TspActiveSkinObject(ObjectList.Items[OldActiveObject]).Visible
  1264.           then FSkinHint.HideHint;
  1265.         end;
  1266.       if ActiveObject <> -1
  1267.       then
  1268.         begin
  1269.           if TspActiveSkinObject(ObjectList.Items[ActiveObject]).Enabled and
  1270.              TspActiveSkinObject(ObjectList.Items[ActiveObject]).Visible
  1271.           then TspActiveSkinObject(ObjectList.Items[ActiveObject]).MouseEnter;
  1272.           // show object hint
  1273.           if FShowObjectHint and (FSkinHint <> nil) and
  1274.              TspActiveSkinObject(ObjectList.Items[ActiveObject]).Enabled and
  1275.              TspActiveSkinObject(ObjectList.Items[ActiveObject]).Visible
  1276.           then
  1277.             begin
  1278.               ObjHint := TspActiveSkinObject(ObjectList.Items[ActiveObject]).Hint;
  1279.               if ObjHint <> '' then FSkinHint.ActivateHint2(ObjHint);
  1280.             end;
  1281.           //
  1282.         end;  
  1283.     end;
  1284. end;
  1285. procedure TspDynamicSkinForm.TestCursors;
  1286. var
  1287.   CurIndex: Integer;
  1288. begin
  1289.   CurIndex := 0;
  1290.   if ActiveObject = -1
  1291.   then
  1292.     begin
  1293.       if FSD.CursorIndex <> -1
  1294.       then
  1295.         CurIndex := FSD.StartCursorIndex + FSD.CursorIndex
  1296.     end
  1297.   else
  1298.     with TspActiveSkinObject(ObjectList.Items[ActiveObject]) do
  1299.     begin
  1300.       if CursorIndex <> -1
  1301.       then
  1302.         CurIndex := FSD.StartCursorIndex + CursorIndex
  1303.       else
  1304.         if FSD.CursorIndex <> -1
  1305.         then
  1306.           CurIndex := FSD.CursorIndex + FSD.StartCursorIndex;
  1307.     end;
  1308.   if FForm.Cursor <> CurIndex
  1309.   then
  1310.     FForm.Cursor := CurIndex;
  1311. end;
  1312. procedure TspDynamicSkinForm.TestMouse;
  1313. var
  1314.   P, P1: TPoint;
  1315.   B: Boolean;
  1316.   L, T: Integer;
  1317. begin
  1318.   if not FSkinSupport and not FSupportNCArea then Exit;
  1319.   if FSupportNCArea
  1320.   then
  1321.     begin
  1322.       GetCursorPos(P);
  1323.       B := InForm(P);
  1324.       if not B
  1325.       then
  1326.         begin
  1327.           TestActive(-1, -1, False);
  1328.           MouseTimer.Enabled := False;
  1329.         end
  1330.       else
  1331.         if not FSizeMove then 
  1332.         begin
  1333.           PointToNCPoint(P);
  1334.           if not PtInRect(NewClRect, P)
  1335.           then
  1336.             TestActive(P.X, P.Y, B)
  1337.           else
  1338.             if ActiveObject <> -1 then TestActive(-1, -1, True);
  1339.         end;
  1340.     end
  1341.   else
  1342.     begin
  1343.       GetCursorPos(P1);
  1344.       P := FForm.ScreenToClient(P1);
  1345.       if FIsDragging
  1346.       then
  1347.         begin
  1348.           if (P1.X <> FOLDX) or (P1.Y <> FOLDY)
  1349.           then
  1350.             begin
  1351.               L := FForm.Left + P1.X - FOldX;
  1352.               T := FForm.Top + P1.Y - FOldY;
  1353.               if FMagnetic
  1354.               then
  1355.                 begin
  1356.                   DoMagnetic(L, T, FForm.Width, FForm.Height);
  1357.                 end;
  1358.               FForm.SetBounds(L, T, FForm.Width, FForm.Height);
  1359.               FOLDX := P1.X;
  1360.               FOLDY := P1.Y;
  1361.             end;
  1362.         end
  1363.       else
  1364.         begin
  1365.           B := InForm(P1);
  1366.           if not B
  1367.           then
  1368.             begin
  1369.               TestActive(-1, -1, False);
  1370.               MouseIn := False;
  1371.               MouseTimer.Enabled := False;
  1372.             end
  1373.           else
  1374.             TestActive(P.X, P.Y, B);
  1375.          end;
  1376.       if FUseSkinCursors then TestCursors;   
  1377.     end;
  1378. end;
  1379. procedure TspDynamicSkinForm.TestAnimate;
  1380. var
  1381.   i: Integer;
  1382.   StopAnimate: Boolean;
  1383. begin
  1384.   StopAnimate := True;
  1385.   for i := 0 to ObjectList.Count  - 1 do
  1386.     if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinAnimateObject
  1387.     then
  1388.       with TspSkinAnimateObject(ObjectList.Items[i]) do
  1389.       if Active
  1390.       then
  1391.         begin
  1392.           ChangeFrame;
  1393.           StopAnimate := False;
  1394.         end;
  1395.   if StopAnimate
  1396.   then AnimateTimer.Enabled := False;
  1397. end;
  1398. procedure TspDynamicSkinForm.TestMorph;
  1399. var
  1400.   i: Integer;
  1401.   StopMorph: Boolean;
  1402. begin
  1403.   StopMorph := True;
  1404.   for i := 0 to ObjectList.Count  - 1 do
  1405.     with TspActiveSkinObject(ObjectList.Items[i]) do
  1406.     begin
  1407.       if Morphing and CanMorphing
  1408.         then
  1409.           begin
  1410.             DoMorphing;
  1411.             StopMorph := False;
  1412.           end;
  1413.     end;
  1414.   if StopMorph then MorphTimer.Enabled := False;
  1415. end;
  1416. procedure TspDynamicSkinForm.PaintEvent;
  1417. begin
  1418.   if Assigned(FOnPaintEvent) then FOnPaintEvent(IDName, Canvas, ObjectRect);
  1419. end;
  1420. procedure TspDynamicSkinForm.MouseUpEvent;
  1421. begin
  1422.   if Assigned(FOnMouseUpEvent)
  1423.   then FOnMouseUpEvent(IDName, X, Y, ObjectRect, Button);
  1424. end;
  1425. procedure TspDynamicSkinForm.MouseDownEvent;
  1426. begin
  1427.   if Assigned(FOnMouseDownEvent)
  1428.   then FOnMouseDownEvent(IDName, X, Y, ObjectRect, Button);
  1429. end;
  1430. procedure TspDynamicSkinForm.MouseMoveEvent;
  1431. begin
  1432.   if Assigned(FOnMouseMoveEvent)
  1433.   then FOnMouseMoveEvent(IDName, X, Y, ObjectRect);
  1434. end;
  1435. procedure TspDynamicSkinForm.MouseEnterEvent;
  1436. begin
  1437.   if Assigned(FOnMouseEnterEvent) then FOnMouseEnterEvent(IDName);
  1438. end;
  1439. procedure TspDynamicSkinForm.MouseLeaveEvent;
  1440. begin
  1441.   if Assigned(FOnMouseLeaveEvent) then FOnMouseLeaveEvent(IDName);
  1442. end;
  1443. procedure TspDynamicSkinForm.StartDragg;
  1444. var
  1445.   P: TPoint;
  1446. begin
  1447.   FIsDragging := True;
  1448.   P := FForm.ClientToScreen(Point(X, Y));
  1449.   FOldX := P.X;
  1450.   FOldy := P.Y;
  1451. end;
  1452. procedure TspDynamicSkinForm.EndDragg;
  1453. begin
  1454.   FIsDragging := False;
  1455. end;
  1456. procedure TspDynamicSkinForm.MouseMove;
  1457. begin
  1458.   if FSupportNCArea
  1459.   then
  1460.     begin
  1461.       if MouseCaptureObject <> -1
  1462.       then TspActiveSkinObject(ObjectList.Items[MouseCaptureObject]).MouseMove(X, Y)
  1463.       else
  1464.       if ActiveObject <> -1
  1465.       then TspActiveSkinObject(ObjectList.Items[ActiveObject]).MouseMove(X, Y);
  1466.     end
  1467.   else
  1468.     begin
  1469.       if not FIsDragging
  1470.       then
  1471.         if MouseCaptureObject <> -1
  1472.         then TspActiveSkinObject(ObjectList.Items[MouseCaptureObject]).MouseMove(X, Y)
  1473.         else
  1474.         if ActiveObject <> -1
  1475.         then TspActiveSkinObject(ObjectList.Items[ActiveObject]).MouseMove(X, Y);
  1476.     end;
  1477. end;
  1478. procedure TspDynamicSkinForm.MouseDblClick;
  1479. begin
  1480.   if (ActiveObject <> - 1) then
  1481.   with TspActiveSkinObject(ObjectList.Items[ActiveObject]) do
  1482.   begin
  1483.     DblClick;
  1484.   end;
  1485. end;
  1486. procedure TspDynamicSkinForm.MouseDown;
  1487. begin
  1488.   if FSupportNCArea
  1489.   then
  1490.     begin
  1491.       if (ActiveObject <> - 1) then 
  1492.       with TspActiveSkinObject(ObjectList.Items[ActiveObject]) do
  1493.       begin
  1494.         if not (TspActiveSkinObject(ObjectList.Items[ActiveObject]) is
  1495.           TspSkinCaptionObject)
  1496.         then SetCapture(FForm.Handle);
  1497.          MouseCaptureObject := ActiveObject;
  1498.          MouseDown(X, Y, Button);
  1499.        end
  1500.     end
  1501.   else
  1502.     begin
  1503.       FIsDragging := False;
  1504.       if (ActiveObject <> - 1)
  1505.       then
  1506.         with TspActiveSkinObject(ObjectList.Items[ActiveObject]) do
  1507.         begin
  1508.           MouseCaptureObject := ActiveObject;
  1509.           MouseDown(X, Y, Button);
  1510.         end
  1511.       else
  1512.        if (Button = mbLeft) and (FWindowState <> wsMaximized) and FDraggable
  1513.        then
  1514.         StartDragg(X, Y);
  1515.     end;
  1516. end;
  1517. procedure TspDynamicSkinForm.MouseUp;
  1518. begin
  1519.   if FSupportNCArea
  1520.   then
  1521.     begin
  1522.       if (MouseCaptureObject <> -1)
  1523.       then
  1524.         begin
  1525.           if not (TspActiveSkinObject(ObjectList.Items[MouseCaptureObject]) is
  1526.           TspSkinCaptionObject)
  1527.           then ReleaseCapture;
  1528.           TspActiveSkinObject(ObjectList.Items[MouseCaptureObject]).MouseUp(X, Y, Button);
  1529.           MouseCaptureObject := -1;
  1530.         end;
  1531.     end
  1532.   else
  1533.     begin
  1534.       EndDragg;
  1535.       if (MouseCaptureObject <> -1)
  1536.       then
  1537.         begin
  1538.           TspActiveSkinObject(ObjectList.Items[MouseCaptureObject]).MouseUp(X, Y, Button);
  1539.           MouseCaptureObject := -1;
  1540.         end;
  1541.     end;
  1542. end;
  1543. procedure TspDynamicSkinForm.CreateRealBitMap;
  1544. begin
  1545.   CreateSkinImage(FSD.LTPoint, FSD.RTPoint, FSD.LBPoint, FSD.RBPoint,
  1546.     FSD.ClRect, NewLtPoint, NewRTPoint, NewLBPoint, NewRBPoint, NewClRect,
  1547.     DestB, SourceB, Rect(0, 0, SourceB.Width, SourceB.Height), FFormWidth,
  1548.     FFormHeight, True);
  1549. end;
  1550. function TspDynamicSkinForm.CalcRealObjectRect;
  1551. var
  1552.   NewR: TRect;
  1553.   LeftTop, LeftBottom, RightTop, RightBottom: TRect;
  1554.   OffsetX, OffsetY: Integer;
  1555. function CorrectResizeRect: TRect;
  1556. var
  1557.   NR: TRect;
  1558. begin
  1559.   NR := R;
  1560.   if PtInRect(LeftTop, R.TopLeft) and
  1561.      PtInRect(RightBottom, R.BottomRight)
  1562.   then
  1563.     begin
  1564.       Inc(NR.Right, OffsetX);
  1565.       Inc(NR.Bottom, OffsetY);
  1566.     end
  1567.   else
  1568.   if PtInRect(LeftTop, R.TopLeft) and
  1569.      PtInRect(RightTop, R.BottomRight)
  1570.   then
  1571.     Inc(NR.Right, OffsetX)
  1572.   else
  1573.     if PtInRect(LeftBottom, R.TopLeft) and
  1574.        PtInRect(RightBottom, R.BottomRight)
  1575.     then
  1576.       begin
  1577.         Inc(NR.Right, OffsetX);
  1578.         OffsetRect(NR, 0, OffsetY);
  1579.       end
  1580.     else
  1581.       if PtInRect(LeftTop, R.TopLeft) and
  1582.          PtInRect(LeftBottom, R.BottomRight)
  1583.       then
  1584.         Inc(NR.Bottom, OffsetY)
  1585.       else
  1586.         if PtInRect(RightTop, R.TopLeft) and
  1587.            PtInRect(RightBottom, R.BottomRight)
  1588.         then
  1589.           begin
  1590.             OffsetRect(NR, OffsetX, 0);
  1591.             Inc(NR.Bottom, OffsetY);
  1592.           end;
  1593.   Result := NR;
  1594. end;
  1595. begin
  1596.   LeftTop := Rect(0, 0, FSD.LTPoint.X, FSD.LTPoint.Y);
  1597.   LeftBottom := Rect(0, FSD.LBPoint.Y, FSD.LBPoint.X, FSD.FPicture.Height);
  1598.   RightTop := Rect(FSD.RTPoint.X, 0, FSD.FPicture.Width, FSD.RTPoint.Y);
  1599.   RightBottom := Rect(FSD.RBPoint.X, FSD.RBPoint.Y, FSD.FPicture.Width, FSD.FPicture.Height);
  1600.   OffsetX := NewRBPoint.X - FSD.RBPoint.X;
  1601.   OffsetY := NewRBPoint.Y - FSD.RBPoint.Y;
  1602.   NewR := R;
  1603.   if RectInRect(R, LeftTop)
  1604.   then NewR := R
  1605.   else
  1606.     if RectInRect(R, RightTop)
  1607.     then OffsetRect(NewR, OffsetX, 0)
  1608.     else
  1609.       if RectInRect(R, LeftBottom)
  1610.       then OffsetRect(NewR, 0, OffsetY)
  1611.       else
  1612.         if RectInRect(R, RightBottom)
  1613.         then
  1614.           OffsetRect(NewR,  OffsetX, OffsetY)
  1615.         else
  1616.           NewR := CorrectResizeRect;
  1617.   Result := NewR;
  1618. end;
  1619. procedure TspDynamicSkinForm.CalcAllRealObjectRect;
  1620. var
  1621.   i: Integer;
  1622.   OffsetX, OffsetY, BW, BH: Integer;
  1623.   Button: TspSkinStdButtonObject;
  1624.   C: TspSkinCaptionObject;
  1625. function GetCaption: TspSkinCaptionObject;
  1626. var
  1627.   I: Integer;
  1628. begin
  1629.   Result := nil;
  1630.   for I := 0 to ObjectList.Count - 1 do
  1631.     if TspActiveSkinObject(ObjectList.Items[I]) is TspSkinCaptionObject
  1632.     then
  1633.       begin
  1634.         Result := TspSkinCaptionObject(ObjectList.Items[I]);
  1635.         Break;
  1636.       end;
  1637. end;
  1638. function GetStdButton(C: TStdCommand): TspSkinStdButtonObject;
  1639. var
  1640.   I: Integer;
  1641. begin
  1642.   Result := nil;
  1643.   for I := 0 to ObjectList.Count - 1 do
  1644.     if TspActiveSkinObject(ObjectList.Items[I]) is TspSkinStdButtonObject
  1645.     then
  1646.       with TspSkinStdButtonObject(ObjectList.Items[I]) do
  1647.         if Visible and SkinRectInAPicture and (Command = C)
  1648.         then
  1649.           begin
  1650.             Result := TspSkinStdButtonObject(ObjectList.Items[I]);
  1651.             Break;
  1652.           end;
  1653. end;
  1654. procedure SetStdButtonRect(B: TspSkinStdButtonObject);
  1655. begin
  1656.   if B <> nil
  1657.   then
  1658.     with B do
  1659.     begin
  1660.       if (Command = cmSysMenu) and Parent.ShowIcon and SkinRectInAPicture
  1661.       then
  1662.         GetIconSize(BW, BH)
  1663.       else
  1664.         begin
  1665.           BW := RectWidth(SkinRect);
  1666.           BH := RectHeight(SkinRect);
  1667.         end;
  1668.       ObjectRect := Rect(OffsetX - BW, OffsetY, OffsetX, OffsetY + BH);
  1669.       OffsetX := OffsetX - NewButtonsOffset - BW;
  1670.     end;
  1671. end;
  1672. procedure SetStdButtonRect2(B: TspSkinStdButtonObject);
  1673. begin
  1674.   if B <> nil
  1675.   then
  1676.     with B do
  1677.     begin
  1678.       if (Command = cmSysMenu) and Parent.ShowIcon and SkinRectInAPicture
  1679.       then
  1680.         GetIconSize(BW, BH)
  1681.       else
  1682.         begin
  1683.           BW := RectWidth(SkinRect);
  1684.           BH := RectHeight(SkinRect);
  1685.         end;
  1686.       ObjectRect := Rect(OffsetX, OffsetY, OffsetX + BW, OffsetY + BH);
  1687.       OffsetX := OffsetX + NewButtonsOffset + BW;
  1688.     end;
  1689. end;
  1690. procedure SetStdObjectsRect;
  1691. begin
  1692.   Button := GetStdButton(cmClose);
  1693.   SetStdButtonRect(Button);
  1694.   Button := GetStdButton(cmMaximize);
  1695.   SetStdButtonRect(Button);
  1696.   Button := GetStdButton(cmMinimize);
  1697.   SetStdButtonRect(Button);
  1698.   Button := GetStdButton(cmRollUp);
  1699.   SetStdButtonRect(Button);
  1700.   C := GetCaption;
  1701.   if IsNullRect(NewButtonsRect) and (C <> nil)
  1702.   then
  1703.     C.ObjectRect.Right := OffsetX + NewButtonsOffset;
  1704.   OffsetX := NewCaptionRect.Left;
  1705.   Button := GetStdButton(cmSysMenu);
  1706.   if Button <> nil
  1707.   then
  1708.     begin
  1709.       OffsetY := NewCaptionRect.Top;
  1710.       SetStdButtonRect2(Button);
  1711.       Button.ObjectRect.Top := OffsetY + RectHeight(NewCaptionRect) div 2  -
  1712.       BH div 2;
  1713.       Button.ObjectRect.Bottom := Button.ObjectRect.Top + BH;
  1714.       if C <> nil
  1715.       then
  1716.         C.ObjectRect.Left := OffsetX - NewButtonsOffset;
  1717.     end;
  1718. end;
  1719. procedure SetStdObjectsRect2;
  1720. begin
  1721.   Button := GetStdButton(cmClose);
  1722.   SetStdButtonRect2(Button);
  1723.   Button := GetStdButton(cmMaximize);
  1724.   SetStdButtonRect2(Button);
  1725.   Button := GetStdButton(cmMinimize);
  1726.   SetStdButtonRect2(Button);
  1727.   Button := GetStdButton(cmRollUp);
  1728.   SetStdButtonRect2(Button);
  1729.   if IsNullRect(NewButtonsRect) and NewButtonsInLeft
  1730.   then
  1731.     begin
  1732.       Button := GetStdButton(cmSysmenu);
  1733.       SetStdButtonRect2(Button);
  1734.     end;
  1735.   C := GetCaption;
  1736.   if IsNullRect(NewButtonsRect) and (C <> nil)
  1737.   then C.ObjectRect.Left := OffsetX + NewButtonsOffset;
  1738.   if not NewButtonsInLeft and not IsNullRect(NewCaptionRect)
  1739.   then
  1740.     begin
  1741.       OffsetY := NewCaptionRect.Top;
  1742.       OffsetX := NewCaptionRect.Left;
  1743.       Button := GetStdButton(cmSysMenu);
  1744.       if Button <> nil
  1745.       then
  1746.         begin
  1747.           SetStdButtonRect2(Button);
  1748.           Button.ObjectRect.Top := OffsetY + RectHeight(NewCaptionRect) div 2  -
  1749.             BH div 2;
  1750.           Button.ObjectRect.Bottom := Button.ObjectRect.Top + BH;
  1751.           if C <> nil
  1752.           then
  1753.             C.ObjectRect.Left := OffsetX - NewButtonsOffset;
  1754.         end;    
  1755.     end;
  1756. end;
  1757. begin
  1758.   for i := 0 to ObjectList.Count - 1 do
  1759.     with TspActiveSkinObject(ObjectList.Items[i]) do
  1760.       ObjectRect := CalcRealObjectRect(SkinRect);
  1761.   // caption buttons rects
  1762.   if IsNullRect(NewButtonsRect) and not IsNullRect(NewCaptionRect)
  1763.   then
  1764.     begin
  1765.       OffsetY := NewCaptionRect.Top;
  1766.       if not NewButtonsInLeft
  1767.       then
  1768.         begin
  1769.           OffsetX := NewCaptionRect.Right;
  1770.           SetStdObjectsRect;
  1771.         end
  1772.       else
  1773.         begin
  1774.           OffsetX := NewCaptionRect.Left;
  1775.           SetStdObjectsRect2;
  1776.         end;
  1777.     end
  1778.   else
  1779.   if not IsNullRect(NewButtonsRect)
  1780.   then
  1781.     begin
  1782.       OffsetY := NewButtonsRect.Top;
  1783.       if not NewButtonsInLeft
  1784.       then
  1785.         begin
  1786.           OffsetX := NewButtonsRect.Right;
  1787.           SetStdObjectsRect;
  1788.         end
  1789.       else
  1790.         begin
  1791.           OffsetX := NewButtonsRect.Left;
  1792.           SetStdObjectsRect2;
  1793.         end;
  1794.     end;
  1795.   //
  1796. end;
  1797. procedure TspDynamicSkinForm.PaintBG2(DC: HDC);
  1798. var
  1799.   C: TCanvas;
  1800.   X, Y, XCnt, YCnt: Integer;
  1801.   B: TBitMap;
  1802. begin
  1803.   if (FSD = nil) or FSD.Empty then Exit;
  1804.   C := TCanvas.Create;
  1805.   C.Handle := DC;
  1806.   B := TBitMap(FSD.FActivePictures.Items[FSD.BGPictureIndex]);
  1807.   if (FForm.ClientWidth > 0) and (FForm.ClientHeight > 0)
  1808.   then
  1809.     begin
  1810.       XCnt := FForm.ClientWidth div B.Width;
  1811.       YCnt := FForm.ClientHeight div B.Height;
  1812.       for X := 0 to XCnt do
  1813.       for Y := 0 to YCnt do
  1814.         C.Draw(X * B.Width, Y * B.Height, B);
  1815.     end;
  1816.   C.Free;
  1817. end;
  1818. procedure TspDynamicSkinForm.PaintBG(DC: HDC);
  1819. var
  1820.   C: TCanvas;
  1821.   X, Y, XCnt, YCnt, w, h,
  1822.   rw, rh, XO, YO: Integer;
  1823.   BGImage: TBitMap;
  1824.   R: TRect;
  1825. begin
  1826.   if (FSD = nil) or FSD.Empty then Exit;
  1827.   C := TCanvas.Create;
  1828.   C.Handle := DC;
  1829.   if IsNullRect(FSD.ClRect)
  1830.   then
  1831.     begin
  1832.       with C do
  1833.       begin
  1834.         Brush.Color := clBtnFace;
  1835.         R := FForm.ClientRect;
  1836.         FillRect(R);
  1837.       end;
  1838.       C.Free;
  1839.       Exit;
  1840.     end;
  1841.   BGImage := TBitMap.Create;
  1842.   if (FForm.ClientWidth > 0) and (FForm.ClientHeight > 0)
  1843.   then
  1844.     begin
  1845.       BGImage.Width := FForm.ClientWidth;
  1846.       BGImage.Height := FForm.ClientHeight;
  1847.       w := RectWidth(FSD.ClRect);
  1848.       h := RectHeight(FSD.ClRect);
  1849.       rw := BGImage.Width;
  1850.       rh := BGImage.Height;
  1851.       with BGImage.Canvas do
  1852.       begin
  1853.         XCnt := rw div w;
  1854.         YCnt := rh div h;
  1855.         for X := 0 to XCnt do
  1856.         for Y := 0 to YCnt do
  1857.         begin
  1858.           if X * w + w > rw then XO := X * W + W - rw else XO := 0;
  1859.           if Y * h + h > rh then YO := Y * h + h - rh else YO := 0;
  1860.           CopyRect(Rect(X * w, Y * h,X * w + w - XO, Y * h + h - YO),
  1861.                    FSD.FPicture.Canvas,
  1862.                    Rect(FSD.ClRect.Left, FSD.ClRect.Top,
  1863.                    FSD.ClRect.Right - XO, FSD.ClRect.Bottom - YO));
  1864.         end;
  1865.       end;
  1866.     end;
  1867.   C.Draw(0, 0, BGImage);
  1868.   BGImage.Free;
  1869.   C.Free;
  1870. end;
  1871. procedure TspDynamicSkinForm.Paint;
  1872. var
  1873.   i: Integer;
  1874.   Canvas: TCanvas;
  1875.   R: TRect;
  1876.   PW, PH: Integer;
  1877.   RealPicture: TBitMap;
  1878. begin
  1879.   if FFormWidth = 0 then FFormWidth := FForm.Width;
  1880.   if FFormheight = 0 then FFormHeight := FForm.Height;
  1881.   Canvas := TCanvas.Create;
  1882.   Canvas.Handle := DC;
  1883.   RealPicture := TBitMap.Create;
  1884.   if (FSD = nil) or (FSD.Empty)
  1885.   then
  1886.     begin
  1887.       R := FForm.ClientRect;
  1888.       with Canvas do
  1889.       begin
  1890.         Brush.Color := clBtnFace;
  1891.         Pen.Color := clBlack;
  1892.         Rectangle(R.Left, R.Top, R.Right, R.Bottom);
  1893.       end;
  1894.       Canvas.Free;
  1895.       Exit;
  1896.     end;
  1897.     with Canvas do
  1898.     begin
  1899.       if FRollUpState and not FSD.FRollUpPicture.Empty
  1900.       then
  1901.         begin
  1902.           with FSD do
  1903.           begin
  1904.             PW := FRollUpPicture.Width;
  1905.             PH := FRollUpPicture.Height;
  1906.             if RollUpRightPoint.X > RollUpLeftPoint.X
  1907.             then
  1908.               begin
  1909.                 CreateHSkinImage(
  1910.                   RollUpLeftPoint.X, PW - RollUpRightPoint.X,
  1911.                   RealPicture, FRollUpPicture,
  1912.                   Rect(0, 0, PW, PH), FForm.Width, PH);
  1913.                end
  1914.             else
  1915.               begin
  1916.                 RealPicture.Width := PW;
  1917.                 RealPicture.Height := PH;
  1918.                 RealPicture.Canvas.Draw(0, 0, FSD.FRollUpPicture);
  1919.               end;
  1920.           end;
  1921.         end
  1922.       else
  1923.       if (FSD.LTPoint.X = 0) and (FSD.LTPoint.Y = 0)
  1924.            and
  1925.          (FSD.RBPoint.X = 0) and (FSD.RBPoint.Y = 0)
  1926.       then
  1927.         begin
  1928.           RealPicture.Width := FSD.FPicture.Width;
  1929.           RealPicture.Height := FSD.FPicture.Height;
  1930.           RealPicture.Canvas.Draw(0, 0, FSD.FPicture);
  1931.         end
  1932.       else
  1933.         begin
  1934.           CreateRealBitMap(RealPicture, FSD.FPicture);
  1935.         end;
  1936.       for i := 0 to ObjectList.Count - 1 do
  1937.       with TspActiveSkinObject(ObjectList.Items[i]) do
  1938.       begin
  1939.         if (not RollUp and not FRollUpState) or (RollUp and FRollUpState)
  1940.         then
  1941.           Draw(RealPicture.Canvas, False);
  1942.       end;
  1943.       Draw(0, 0, RealPicture);
  1944.     end;
  1945.   RealPicture.Free;
  1946.   Canvas.Free;
  1947. end;
  1948. function TspDynamicSkinForm.NewDefNCHitTest;
  1949. const
  1950.   Offset = 2;
  1951. var
  1952.   CR: TRect;
  1953. begin
  1954.   if (FWindowState = wsMaximized) or FRollUpState or not FSizeAble or
  1955.      (FWindowState = wsMinimized)
  1956.   then
  1957.     with FForm do
  1958.     begin
  1959.       CR := GetDefCaptionRect;
  1960.       if PtInRect(CR, P)
  1961.       then
  1962.         Result := HTCAPTION
  1963.       else
  1964.       if PtInRect(Rect(3, GetDefCaptionHeight + 3, Width - 3, Height - 3), P)
  1965.       then
  1966.         Result := HTCLIENT
  1967.       else
  1968.         Result := HTNCACTIVE;
  1969.     end
  1970.   else
  1971.   if (ActiveObject <> -1)
  1972.   then
  1973.     begin
  1974.       Result := HTNCACTIVE;
  1975.     end
  1976.   else
  1977.   with FForm do
  1978.   if (P.X <= Offset) and (P.Y <= Offset)
  1979.   then
  1980.     Result := HTTOPLEFT
  1981.   else
  1982.   if (P.X >= Width - Offset) and (P.Y <= Offset)
  1983.   then
  1984.      Result := HTTOPRIGHT
  1985.   else
  1986.   if (P.X <= Offset) and (P.Y >= Height - Offset)
  1987.   then
  1988.     Result := HTBOTTOMLEFT
  1989.   else
  1990.   if (P.X >= Width - Offset) and (P.Y >= Height - Offset)
  1991.   then
  1992.     Result := HTBOTTOMRIGHT
  1993.   else
  1994.   if (P.X <= Offset)
  1995.   then
  1996.     Result := HTLEFT
  1997.   else
  1998.   if (P.Y <= Offset)
  1999.   then
  2000.     Result := HTTOP
  2001.   else
  2002.   if (P.X >= Width - Offset)
  2003.   then
  2004.     Result := HTRIGHT
  2005.   else
  2006.   if (P.Y >= Height - Offset)
  2007.   then
  2008.     Result := HTBOTTOM
  2009.   else
  2010.     begin
  2011.       CR := GetDefCaptionRect;
  2012.       if PtInRect(CR, P)
  2013.       then
  2014.         Result := HTCAPTION
  2015.       else
  2016.       if PtInRect(Rect(3, GetDefCaptionHeight + 3, Width - 3, Height - 3), P)
  2017.       then
  2018.         Result := HTCLIENT
  2019.       else
  2020.         Result := HTNCACTIVE;
  2021.     end
  2022. end;
  2023. function TspDynamicSkinForm.NewNCHitTest(P: TPoint): Integer;
  2024. var
  2025.   LP, TP, RP, BP: TPoint;
  2026.   CR: TRect;
  2027.   BW: Integer;
  2028. function InCaption: Boolean;
  2029. var
  2030.   i: Integer;
  2031. begin
  2032.   Result := False;
  2033.   for i := 0 to ObjectList.Count - 1 do
  2034.     if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinCaptionObject
  2035.     then
  2036.       with TspSkinCaptionObject(ObjectList.Items[i]) do
  2037.        if CanObjectTest(RollUp) and PtInRect(ObjectRect, P)
  2038.        then
  2039.          begin
  2040.            Result := True;
  2041.            Break;
  2042.          end;
  2043. end;
  2044. function CanHit: Boolean;
  2045. begin
  2046.   if FSD.FMask.Empty
  2047.   then
  2048.     begin
  2049.       Result := not (PtInRect(CR, LP) and PtInRect(CR, TP) and
  2050.                      PtInRect(CR, RP) and PtInRect(CR, BP));
  2051.     end
  2052.   else
  2053.     Result := not PtInRect(NewMaskRectArea, P) and
  2054.               not (PtInMask(LP) and PtInMask(TP) and
  2055.                    PtInMask(RP) and PtInMask(BP));
  2056. end;
  2057. begin
  2058.   if FRollUpState or (WindowState = wsMinimized)
  2059.   then
  2060.     begin
  2061.       if InCaption
  2062.       then Result := HTCAPTION
  2063.       else Result := HTNCACTIVE;
  2064.     end
  2065.   else  
  2066.   if (ActiveObject <> -1) and not InCaption and not PtInRect(NewClRect, P)
  2067.   then
  2068.     begin
  2069.       Result := HTNCACTIVE;
  2070.     end
  2071.   else
  2072.   if (WindowState = wsMaximized) or not FSizeAble
  2073.   then
  2074.     begin
  2075.       if PtInRect(NewClRect, P)
  2076.       then
  2077.         Result := HTCLIENT
  2078.       else
  2079.       if InCaption
  2080.       then Result := HTCAPTION
  2081.       else Result := HTNCACTIVE;
  2082.     end
  2083.   else
  2084.     begin
  2085.       BW := FSD.BorderW;
  2086.       LP := Point(P.X - BW, P.Y);
  2087.       TP := Point(P.X, P.Y - BW);
  2088.       RP := Point(P.X + BW, P.Y);
  2089.       BP := Point(P.X, P.Y + BW);
  2090.       CR := Rect(0, 0, FForm.Width, FForm.Height);
  2091.       if CanHit
  2092.       then
  2093.         begin
  2094.           if (P.X <= NewHitTestLtPoint.X) and (P.Y <= NewHitTestLtPoint.Y)
  2095.           then
  2096.             Result := HTTOPLEFT
  2097.           else
  2098.           if (P.X >= NewHitTestRTPoint.X) and (P.Y <= NewHitTestRTPoint.Y)
  2099.           then
  2100.             Result := HTTOPRIGHT
  2101.           else
  2102.           if (P.X <= NewHitTestLBPoint.X) and (P.Y >= NewHitTestLBPoint.Y)
  2103.           then
  2104.             Result := HTBOTTOMLEFT
  2105.           else
  2106.           if (P.X >= NewHitTestRBPoint.X) and (P.Y >= NewHitTestRBPoint.Y)
  2107.           then
  2108.             Result := HTBOTTOMRIGHT
  2109.           else
  2110.           if PtInRect(Rect(NewHitTestLTPoint.X, 0,
  2111.                NewHitTestRTPoint.X, NewClRect.Top), P)
  2112.           then
  2113.             Result := HTTOP
  2114.           else
  2115.           if PtInRect(Rect(NewHitTestLBPoint.X, NewClRect.Bottom,
  2116.                NewHitTestRBPoint.X, CR.Bottom), P)
  2117.           then
  2118.             Result := HTBOTTOM
  2119.           else
  2120.           if PtInRect(Rect(0, NewHitTestLTPoint.Y,
  2121.                NewCLRect.Left, NewHitTestLBPoint.Y), P)
  2122.           then
  2123.             Result := HTLEFT
  2124.           else
  2125.           if PtInRect(Rect(NewClRect.Right, NewHitTestRTPoint.Y,
  2126.                CR.Right, NewHitTestRBPoint.Y), P)
  2127.           then
  2128.             Result := HTRIGHT
  2129.           else
  2130.           if PtInRect(NewClRect, P)
  2131.           then
  2132.             Result := HTCLIENT
  2133.           else
  2134.             if InCaption
  2135.             then Result := HTCAPTION
  2136.             else Result := HTNCACTIVE;
  2137.         end
  2138.       else
  2139.         if PtInRect(NewClRect, P)
  2140.         then
  2141.           begin
  2142.             Result := HTCLIENT
  2143.           end  
  2144.         else
  2145.           if InCaption
  2146.           then Result := HTCAPTION
  2147.           else Result := HTNCACTIVE;
  2148.     end;
  2149. end;
  2150. function TspDynamicSkinForm.NewHitTest;
  2151. var
  2152.   LP, TP, RP, BP: TPoint;
  2153.   CR: TRect;
  2154.   BW: Integer;
  2155. function CanHit: Boolean;
  2156. begin
  2157.   if FSD.FMask.Empty
  2158.   then
  2159.     begin
  2160.       Result := not (PtInRect(CR, LP) and PtInRect(CR, TP) and
  2161.                      PtInRect(CR, RP) and PtInRect(CR, BP));
  2162.     end
  2163.   else
  2164.     Result := not PtInRect(NewMaskRectArea, P) and
  2165.               not (PtInMask(LP) and PtInMask(TP) and
  2166.                    PtInMask(RP) and PtInMask(BP));
  2167. end;
  2168. begin
  2169.   if (not FSizeable or ((WindowState = wsMaximized) or FRollUpState)) or (ActiveObject <> -1)
  2170.   then
  2171.     begin
  2172.       Result := HTCLIENT;
  2173.       Exit;
  2174.     end
  2175.   else
  2176.     if (FSD <> nil) and not FSD.Empty
  2177.     then 
  2178.     begin
  2179.       BW := FSD.BorderW;
  2180.       LP := Point(P.X - BW, P.Y);
  2181.       TP := Point(P.X, P.Y - BW);
  2182.       RP := Point(P.X + BW, P.Y);
  2183.       BP := Point(P.X, P.Y + BW);
  2184.       CR := Rect(0, 0, FForm.Width, FForm.Height);
  2185.       if CanHit
  2186.       then
  2187.         begin
  2188.           if (P.X <= NewHitTestLtPoint.X) and (P.Y <= NewHitTestLtPoint.Y)
  2189.           then
  2190.             Result := HTTOPLEFT
  2191.           else
  2192.           if (P.X >= NewHitTestRTPoint.X) and (P.Y <= NewHitTestRTPoint.Y)
  2193.           then
  2194.             Result := HTTOPRIGHT
  2195.           else
  2196.           if (P.X <= NewHitTestLBPoint.X) and (P.Y >= NewHitTestLBPoint.Y)
  2197.           then
  2198.             Result := HTBOTTOMLEFT
  2199.           else
  2200.           if (P.X >= NewHitTestRBPoint.X) and (P.Y >= NewHitTestRBPoint.Y)
  2201.           then
  2202.             Result := HTBOTTOMRIGHT
  2203.           else
  2204.           if PtInRect(Rect(NewHitTestLTPoint.X, 0,
  2205.                NewHitTestRTPoint.X, NewClRect.Top), P)
  2206.           then
  2207.             Result := HTTOP
  2208.           else
  2209.           if PtInRect(Rect(NewHitTestLBPoint.X, NewClRect.Bottom,
  2210.                NewHitTestRBPoint.X, CR.Bottom), P)
  2211.           then
  2212.             Result := HTBOTTOM
  2213.           else
  2214.           if PtInRect(Rect(0, NewHitTestLTPoint.Y,
  2215.                NewCLRect.Left, NewHitTestLBPoint.Y), P)
  2216.           then
  2217.             Result := HTLEFT
  2218.           else
  2219.           if PtInRect(Rect(NewClRect.Right, NewHitTestRTPoint.Y,
  2220.                CR.Right, NewHitTestRBPoint.Y), P)
  2221.           then
  2222.             Result := HTRIGHT
  2223.           else
  2224.             Result := HTCLIENT;
  2225.         end
  2226.       else
  2227.         Result := HTCLIENT;
  2228.     end
  2229.   else
  2230.     Result := HTCLIENT;
  2231. end;
  2232. function TspDynamicSkinForm.FindHotKeyItem;
  2233. var
  2234.   i: Integer;
  2235. begin
  2236.   Result := False;
  2237.   if FMainMenuBar <> nil
  2238.   then
  2239.     Result := FMainMenuBar.FindHotKeyItem(CharCode)
  2240.   else  
  2241.   for i := 0 to ObjectList.Count - 1 do
  2242.     if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinMainMenuItem
  2243.     then
  2244.       with TspSkinMainMenuItem(ObjectList.Items[i]) do
  2245.       begin
  2246.         if Enabled and Visible and
  2247.            IsAccel(CharCode, MenuItem.Caption)
  2248.         then
  2249.           begin
  2250.             MouseEnter;
  2251.             if (not InMenu) or (MenuItem.Count = 0) then MouseDown(0, 0, mbLeft);
  2252.             Result := True;
  2253.             Break;
  2254.           end;
  2255.       end
  2256. end;
  2257. function TspDynamicSkinForm.CanNextMainMenuItem;
  2258. var
  2259.   PW: TspSkinPopupWindow;
  2260. begin
  2261.   if SkinMenu.FPopupList.Count = 0
  2262.   then
  2263.     Result := True
  2264.   else
  2265.     with SkinMenu do
  2266.     begin
  2267.       PW := TspSkinPopupWindow(FPopupList.Items[FPopupList.Count - 1]);
  2268.       if PW.ActiveItem <> -1
  2269.       then
  2270.         begin
  2271.           if TspSkinMenuItem(PW.ItemList[PW.ActiveItem]).MenuItem.Count = 0
  2272.           then
  2273.             Result := True
  2274.           else
  2275.             Result := False;   
  2276.         end
  2277.       else
  2278.         Result := True
  2279.     end;
  2280. end;
  2281. function TspDynamicSkinForm.CanPriorMainMenuItem;
  2282. begin
  2283.   if SkinMenu.FPopupList.Count < 2 then Result := True else Result := False;
  2284. end;
  2285. procedure TspDynamicSkinForm.NextMainMenuItem;
  2286. function IsEndItem(Index: Integer): Boolean;
  2287. var
  2288.   i: Integer;
  2289. begin
  2290.   Result := True;
  2291.   if Index + 1 > ObjectList.Count - 1
  2292.   then
  2293.     Result := True
  2294.   else
  2295.   for i := Index + 1 to ObjectList.Count - 1 do
  2296.     if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinMainMenuItem
  2297.     then
  2298.       with TspSkinMainMenuItem(ObjectList.Items[i]) do
  2299.       begin
  2300.         if Enabled and Visible then Result := False;
  2301.       end
  2302. end;
  2303. var
  2304.   i, j: Integer;
  2305.   EndI: Boolean;
  2306.   FirstItem: Integer;
  2307. begin
  2308.   EndI := False;
  2309.   FirstItem := -1;
  2310.   j := -1;
  2311.   for i := 0 to ObjectList.Count - 1 do
  2312.     if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinMainMenuItem
  2313.     then
  2314.       with TspSkinMainMenuItem(ObjectList.Items[i]) do
  2315.       begin
  2316.         if Enabled and Visible
  2317.         then
  2318.           begin
  2319.             if FirstItem = -1 then FirstItem := i;
  2320.             if (Active or FDown)
  2321.             then
  2322.               begin
  2323.                 j := i;
  2324.                 MouseLeave;
  2325.                 EndI := IsEndItem(j);
  2326.                 Break;
  2327.               end;
  2328.           end;
  2329.        end;   
  2330.   if j = -1
  2331.   then
  2332.     begin
  2333.       j := FirstItem;
  2334.       if j <> -1 then
  2335.         TspSkinMainMenuItem(ObjectList.Items[j]).MouseEnter;
  2336.     end
  2337.   else
  2338.     begin
  2339.       if EndI then j := 0 else j := j + 1;
  2340.       if j < ObjectList.Count then
  2341.       for i := j to ObjectList.Count - 1 do
  2342.       if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinMainMenuItem
  2343.       then
  2344.         with TspSkinMainMenuItem(ObjectList.Items[i]) do
  2345.         begin
  2346.           if Enabled and Visible
  2347.           then
  2348.             begin
  2349.               MouseEnter;
  2350.               Break;
  2351.             end;
  2352.         end;    
  2353.     end;
  2354. end;
  2355. procedure TspDynamicSkinForm.PriorMainMenuItem;
  2356. function IsEndItem(Index: Integer): Boolean;
  2357. var
  2358.   i: Integer;
  2359. begin
  2360.   Result := True;
  2361.   if Index - 1 < 0
  2362.   then
  2363.     Result := True
  2364.   else
  2365.   for i := Index - 1 downto 0 do
  2366.     if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinMainMenuItem
  2367.     then
  2368.       with TspSkinMainMenuItem(ObjectList.Items[i]) do
  2369.       begin
  2370.         if Enabled and Visible then Result := False;
  2371.       end
  2372. end;
  2373. var
  2374.   i, j: Integer;
  2375.   EndI: Boolean;
  2376.   LastItem: Integer;
  2377. begin
  2378.   EndI := False;
  2379.   j := -1;
  2380.   LastItem := -1;
  2381.   for i := ObjectList.Count - 1 downto 0 do
  2382.     if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinMainMenuItem
  2383.     then
  2384.       with TspSkinMainMenuItem(ObjectList.Items[i]) do
  2385.       begin
  2386.         if Enabled and Visible
  2387.         then
  2388.           begin
  2389.             if LastItem = -1 then LastItem := i;
  2390.             if Active or FDown then
  2391.             begin
  2392.               j := i;
  2393.               MouseLeave;
  2394.               EndI := IsEndItem(j);
  2395.               Break;
  2396.             end;
  2397.           end;  
  2398.       end;  
  2399.   if j = -1
  2400.   then
  2401.     begin
  2402.       j := LastItem;
  2403.       if j <> -1 then
  2404.         TspSkinMainMenuItem(ObjectList.Items[j]).MouseEnter;
  2405.     end
  2406.   else
  2407.     begin
  2408.       if EndI then j := ObjectList.Count - 1 else j := j - 1;
  2409.       if j > -1 then
  2410.       for i := j downto 0 do
  2411.       if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinMainMenuItem
  2412.       then
  2413.        with TspSkinMainMenuItem(ObjectList.Items[i]) do
  2414.        begin
  2415.          if Enabled and Visible 
  2416.          then
  2417.            begin
  2418.              MouseEnter;
  2419.              Break;
  2420.            end;
  2421.        end;  
  2422.     end;
  2423. end;
  2424. procedure TspDynamicSkinForm.ActivateMenu;
  2425. var
  2426.   i: Integer;
  2427.   FirstItem: Integer;
  2428. begin
  2429.   FirstItem := -1;
  2430.   for i := 0 to ObjectList.Count - 1 do
  2431.     if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinMainMenuItem
  2432.     then
  2433.       with TspSkinMainMenuItem(ObjectList.Items[i]) do
  2434.       begin
  2435.         if FirstItem = -1 then FirstItem := i;
  2436.         if Active
  2437.         then
  2438.           begin
  2439.             FirstItem := i;
  2440.             Break;
  2441.           end;
  2442.       end;
  2443.   if FirstItem <> -1
  2444.   then
  2445.     begin
  2446.       TspSkinMainMenuItem(ObjectList.Items[FirstItem]).MouseEnter;
  2447.       InMainMenu := True;
  2448.       HookApp;
  2449.     end;
  2450.   if Assigned(FOnMainMenuEnter) then FOnMainMenuEnter(Self);      
  2451. end;
  2452. function TspDynamicSkinForm.CheckReturnKey;
  2453. var
  2454.   i: Integer;
  2455. begin
  2456.   Result := False;
  2457.   if FMainMenuBar <> nil
  2458.   then
  2459.     Result := FMainMenuBar.CheckReturnKey
  2460.   else  
  2461.   for i := 0 to ObjectList.Count - 1 do
  2462.     if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinMainMenuItem
  2463.     then
  2464.       with TspSkinMainMenuItem(ObjectList.Items[i]) do
  2465.       begin
  2466.         if (FDown and (MenuItem.Count = 0)) or
  2467.            (Active and not InMenu)
  2468.         then
  2469.           begin
  2470.             Active := False;
  2471.             MouseDown(0, 0, mbLeft);
  2472.             Result := True;
  2473.             Break;
  2474.          end;
  2475.       end;
  2476. end;
  2477. procedure TspDynamicSkinForm.FormClientWindowProcHook(var Message: TMessage);
  2478. var
  2479.   FOld: Boolean;
  2480. begin
  2481.   FOld := True;
  2482.   case Message.Msg of
  2483.     WM_NCACTIVATE:
  2484.       begin
  2485.         FOld := False;
  2486.         Message.Result := 1;
  2487.       end;
  2488.     WM_NCCALCSIZE:
  2489.       begin
  2490.         FOLd := False;
  2491.       end;
  2492.     WM_SIZE:
  2493.       begin
  2494.         Message.Result := CallWindowProc(FPrevClientProc, FForm.ClientHandle, Message.Msg,
  2495.                                  Message.wParam, Message.lParam);
  2496.         ResizeMDIChilds;
  2497.         FOld := False;
  2498.       end;
  2499.     WM_NCPAINT:
  2500.       begin
  2501.         FOld := False;
  2502.       end;
  2503.     WM_ERASEBKGND:
  2504.       begin
  2505.         FOld := False;
  2506.         if (FSD <> nil) and not FSD.Empty
  2507.         then
  2508.           begin
  2509.             if FSD.BGPictureIndex = -1
  2510.             then
  2511.               PaintBG(TWMERASEBKGND(Message).DC)
  2512.             else
  2513.               PaintBG2(TWMERASEBKGND(Message).DC);
  2514.           end
  2515.         else
  2516.           PaintMDIBGDefault(TWMERASEBKGND(Message).DC);
  2517.       end;
  2518.   end;
  2519.   if FOld
  2520.   then
  2521.     with Message do
  2522.       Result := CallWindowProc(FPrevClientProc, FForm.ClientHandle, Msg,
  2523.                                wParam, lParam);
  2524. end;
  2525. procedure TspDynamicSkinForm.FormKeyDown(Message: TMessage);
  2526. var
  2527.   DSF: TspDynamicSkinForm;
  2528. begin
  2529.   if (FForm.FormStyle = fsMDIChild)
  2530.   then
  2531.     begin
  2532.       DSF := GetDynamicSkinFormComponent(Application.MainForm);
  2533.       if DSF <> nil
  2534.       then
  2535.         begin
  2536.           if DSF.InMenu or DSF.InMainMenu or DSF.SkinMenu.Visible
  2537.           then
  2538.             begin
  2539.               DSF.FormKeyDown(Message);
  2540.               Exit;
  2541.             end;
  2542.         end;
  2543.     end;
  2544.   if InMainMenu and FindHotKeyItem(TWMKeyDown(Message).CharCode)
  2545.   then
  2546.     begin
  2547.     end
  2548.   else
  2549.   if (TWMKeyDown(Message).CharCode = VK_ESCAPE) and
  2550.      (InMainMenu and not InMenu)
  2551.   then
  2552.     SkinMainMenuClose
  2553.   else
  2554.     if (TWMKeyDown(Message).CharCode = VK_LEFT) and InMainMenu and
  2555.        CanPriorMainMenuItem
  2556.     then
  2557.       begin
  2558.         if FMainMenuBar <> nil
  2559.         then FMainMenuBar.PriorMainMenuItem
  2560.         else PriorMainMenuItem;
  2561.       end
  2562.     else
  2563.       if (TWMKeyDown(Message).CharCode = VK_RIGHT) and InMainMenu and
  2564.            CanNextMainMenuItem
  2565.       then
  2566.         begin
  2567.           if FMainMenuBar <> nil
  2568.           then FMainMenuBar.NextMainMenuItem
  2569.           else NextMainMenuItem;
  2570.         end
  2571.       else
  2572.        if TWMKeyDown(Message).CharCode = VK_RETURN
  2573.        then
  2574.          begin
  2575.            if  not CheckReturnKey
  2576.            then
  2577.              with TWMKeyDown(Message), SkinMenu do
  2578.              begin
  2579.                if Visible and (FPopupList.Count > 0)
  2580.                then
  2581.                  TspSkinPopupWindow(FPopupList.Items[FPopupList.Count - 1]).PopupKeyDown(CharCode);
  2582.              end;
  2583.           end
  2584.         else
  2585.           with TWMKeyDown(Message), SkinMenu do
  2586.           begin
  2587.             if Visible and (FPopupList.Count > 0)
  2588.             then
  2589.               TspSkinPopupWindow(FPopupList.Items[FPopupList.Count - 1]).PopupKeyDown(CharCode);
  2590.             if (CharCode = VK_ESCAPE) and (FPopupList.Count = 0)
  2591.             then
  2592.               if InMainMenu
  2593.               then
  2594.                 SkinMenuClose2
  2595.               else
  2596.                 SkinMenuClose;
  2597.           end;
  2598. end;
  2599. procedure TspDynamicSkinForm.NewAppMessage;
  2600. var
  2601.   MsgNew: TMessage;
  2602. begin
  2603.   MsgNew.WParam := Msg.WParam;
  2604.   MsgNew.LParam := Msg.LParam;
  2605.   MsgNew.Msg := Msg.message;
  2606.   case Msg.message of
  2607.     WM_KEYDOWN:
  2608.       begin
  2609.         FormKeyDown(MsgNew);
  2610.         Msg.message := 0;
  2611.         Handled := True;
  2612.       end;
  2613.   end;
  2614. end;
  2615. procedure TspDynamicSkinForm.CheckMenuVisible;
  2616. var
  2617.   DS: TspDynamicSkinForm;
  2618. begin
  2619.   if CanMenuClose(Msg)
  2620.   then
  2621.     begin
  2622.       // hide object hint
  2623.       if FShowObjectHint and (FSkinHint <> nil)
  2624.       then FSkinHint.HideHint;
  2625.       //
  2626.       if InMainMenu and not InMenu
  2627.       then
  2628.         SkinMainMenuClose
  2629.       else
  2630.       if (SkinMenu <> nil) and (SkinMenu.Visible or (InMenu))
  2631.       then
  2632.         begin
  2633.           if SkinMenu.Visible
  2634.           then SkinMenu.Hide
  2635.           else SkinMenuClose;
  2636.         end
  2637.       else
  2638.       if (FForm.FormStyle = fsMDIForm) and FForm.Visible
  2639.       then
  2640.         begin
  2641.           DS := GetMDIChildDynamicSkinFormComponent2;
  2642.           if DS <> nil then DS.CheckMenuVisible(Msg);
  2643.         end;
  2644.     end;
  2645. end;
  2646. procedure TspDynamicSkinForm.NewWndProc(var Message: TMessage);
  2647. const
  2648.   WM_SYNCPAINT = $0088;
  2649. var
  2650.   MM: PMINMAXINFO;
  2651.   Old: boolean;
  2652.   P: TPoint;
  2653.   CS: Boolean;
  2654.   L, T, i, j: Integer;
  2655.   B: Boolean;
  2656.   R: PRect;
  2657.   R1: TRect;
  2658. begin
  2659.   CheckMenuVisible(Message.Msg);
  2660.   Old := True;
  2661.   with Message do
  2662.   begin
  2663.     case Msg of
  2664.       WM_MOUSEACTIVATE:
  2665.         if (FForm.FormStyle = fsMDIChild)
  2666.         then
  2667.         begin
  2668.           if (Application.MainForm.ActiveMDIChild = FForm) and not FFormActive
  2669.            then
  2670.              begin
  2671.                FFormActive := True;
  2672.                if FWindowState = wsMaximized
  2673.                then FormChangeActive(False)
  2674.                else FormChangeActive(True);
  2675.              end;
  2676.         end;
  2677.       WM_SETTEXT:
  2678.         begin
  2679.           OldWindowProc(Message);
  2680.           if (FForm.BorderStyle <> bsNone) and
  2681.              not ((FForm.FormStyle = fsMDICHILD) and (WindowState = wsMaximized))
  2682.           then
  2683.             if FSkinSupport
  2684.             then
  2685.               SetDefaultCaptionText(FForm.Caption)
  2686.             else
  2687.               SendMessage(FForm.Handle, WM_NCPAINT, 0, 0);
  2688.             if FForm.FormStyle = fsMDIChild
  2689.             then UpDateChildCaptionInMenu(FForm);
  2690.           Old := False;
  2691.         end;
  2692.       WM_MDICHILDMAX:
  2693.       if FForm.FormStyle = fsMDIForm
  2694.       then
  2695.         begin
  2696.           FMDIChildMaximized := True;
  2697.           SendMessage(FForm.Handle, WM_NCPAINT, 0, 0);
  2698.           if FMainMenuBar <> nil then FMainMenuBar.MDIChildMaximize;
  2699.         end;
  2700.     WM_MDICHILDRESTORE:
  2701.       if FForm.FormStyle = fsMDIForm
  2702.       then
  2703.         begin
  2704.           if GetMaximizeMDIChild = nil then FMDIChildMaximized := False;
  2705.           SendMessage(FForm.Handle, WM_NCPAINT, 0, 0);
  2706.           if FMainMenuBar <> nil then FMainMenuBar.MDIChildRestore;
  2707.         end;
  2708.      WM_MDICHANGESIZE:
  2709.       if (FForm.FormStyle = fsMDICHILD) and (FWindowState = wsMaximized)
  2710.       then
  2711.         begin
  2712.           R1 := GetMDIWorkArea;
  2713.           FForm.SetBounds(0, 0, RectWidth(R1), RectHeight(R1));
  2714.         end;
  2715.       WM_SYSCOMMAND:
  2716.         begin
  2717.           if Message.WParam = SC_KEYMENU
  2718.           then
  2719.             begin
  2720.               if not InMainMenu then
  2721.               begin
  2722.                 if SkinMenu.Visible then SkinMenuClose;
  2723.                 if FMainMenuBar <> nil
  2724.                 then FMainMenuBar.MenuEnter
  2725.                 else ActivateMenu;
  2726.               end
  2727.               else
  2728.               if InMainMenu
  2729.               then
  2730.                 SkinMainMenuClose;
  2731.               Old := False;
  2732.             end;
  2733.         end;
  2734.      WM_CLOSESKINMENU:
  2735.         begin
  2736.           SkinMenuClose;
  2737.         end;
  2738.      WM_TIMER:
  2739.      if (Message.WParam = 1) and CheckW2KWXP and (FAlphaBlend or FAlphaBlendAnimation)
  2740.      then
  2741.        begin
  2742.          KillTimer(FForm.Handle, 1);
  2743.          if FAlphaBlendAnimation and not FAlphaBlend
  2744.            then J := 255 else J := FAlphaBlendValue;
  2745.          if FAlphaBlendAnimation
  2746.          then
  2747.            begin
  2748.              I := 0;
  2749.              Application.ProcessMessages;
  2750.              repeat
  2751.                Inc(i, 3);
  2752.                if I > J then I := J;
  2753.                SetAlphaBlendTransparent(FForm.Handle, i);
  2754.              until i >= J;
  2755.            end
  2756.          else
  2757.            if J <> 255
  2758.            then
  2759.              SetAlphaBlendTransparent(FForm.Handle, FAlphaBlendValue);
  2760.          if J = 255
  2761.          then
  2762.            SetWindowLong(FForm.Handle, GWL_EXSTYLE,
  2763.                                GetWindowLong(FForm.Handle, GWL_EXSTYLE) and not WS_EX_LAYERED);
  2764.        end;
  2765.       WM_SHOWWINDOW:
  2766.        begin
  2767.          if Message.wParam > 0
  2768.          then
  2769.            begin
  2770.              //
  2771.              if CheckW2KWXP and (FAlphaBlend or FAlphaBlendAnimation)
  2772.              then
  2773.                begin
  2774.                  SetWindowLong(FForm.Handle, GWL_EXSTYLE,
  2775.                                GetWindowLong(FForm.Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
  2776.                  SetAlphaBlendTransparent(FForm.Handle, 0);
  2777.                  SetTimer(FForm.Handle, 1, 1, nil);
  2778.                end;
  2779.              //
  2780.              if (FForm.FormStyle <> fsMDIForm) and FSupportNCArea
  2781.              then
  2782.                UpdateForm
  2783.              else
  2784.              if (FForm.FormStyle = fsMDIForm) and (FForm.ClientHandle <> 0) and
  2785.                 (FClientInstance = nil)
  2786.              then
  2787.                begin
  2788.                  FPrevClientProc := Pointer(GetWindowLong(FForm.ClientHandle, GWL_WNDPROC));
  2789.                  FClientInstance := MakeObjectInstance(FormClientWindowProcHook);
  2790.                  SetWindowLong(FForm.ClientHandle, GWL_WNDPROC, LongInt(FClientInstance));
  2791.                  UpDateForm;
  2792.                end;
  2793.              if FForm.FormStyle = fsMDIChild then AddChildToMenu(FForm);
  2794.              if not FSupportNCArea then ControlsToAreas;
  2795.              if FForm.Menu <> nil then FForm.Menu := nil;
  2796.            end
  2797.          else
  2798.            begin
  2799.               if FForm.FormStyle = fsMDIChild then DeleteChildFromMenu(FForm);
  2800.               if CheckW2KWXP and FAlphaBlend
  2801.               then
  2802.                 SetWindowLong(FForm.Handle, GWL_EXSTYLE,
  2803.                               GetWindowLong(FForm.Handle, GWL_EXSTYLE) and not WS_EX_LAYERED);
  2804.            end;
  2805.        end;
  2806.       WM_NCHITTEST:
  2807.         if FSupportNCArea
  2808.         then
  2809.           begin
  2810.             P.X := LoWord(lParam);
  2811.             P.Y := HiWord(lParam);
  2812.             PointToNCPoint(P);
  2813.             if FSkinSupport
  2814.             then
  2815.               Result := NewNCHitTest(P)
  2816.             else
  2817.               Result := NewDefNCHitTest(P);
  2818.             if not MouseTimer.Enabled and (Message.Result = HTNCACTIVE)
  2819.             then
  2820.               begin
  2821.                 TestActive(P.X, P.Y, True);
  2822.                 MouseTimer.Enabled := True;
  2823.               end;
  2824.             Old := False;
  2825.           end
  2826.         else
  2827.           if FSkinSupport
  2828.           then 
  2829.             begin
  2830.               P.X := LoWord(lParam);
  2831.               P.Y := HiWord(lParam);
  2832.               P := FForm.ScreenToClient(P);
  2833.               if not MouseIn
  2834.               then
  2835.                 begin
  2836.                   MouseIn := True;
  2837.                   TestActive(P.X, P.Y, True);
  2838.                   MouseTimer.Enabled := True;
  2839.                 end;
  2840.               Result := NewHitTest(P);
  2841.               Old := False;
  2842.             end
  2843.           else
  2844.             Result := HTCLIENT;
  2845.       WM_BEFORECHANGESKINDATA:
  2846.         if WParam = Integer(FSD)
  2847.         then
  2848.           begin
  2849.             FSkinSupport := False;
  2850.             MouseTimer.Enabled := False;
  2851.             MorphTimer.Enabled := False;
  2852.             AnimateTimer.Enabled := False;
  2853.             ClearObjects;
  2854.             BeforeUpDateSkinControls(WParam, FForm);
  2855.           end;
  2856.       WM_AFTERCHANGESKINDATA:
  2857.         begin
  2858.           if (WParam = Integer(FSD)) and (FForm.FormStyle = fsMDIForm)
  2859.           then
  2860.             begin
  2861.               ResizeMDIChilds;
  2862.             end;
  2863.         end;
  2864.       WM_CHANGESKINDATA:
  2865.         begin
  2866.           if WParam = Integer(FSD)
  2867.           then
  2868.             ChangeSkinData;
  2869.           UpDateSkinControls(WParam, FForm);
  2870.         end;
  2871.       WM_MOVING:
  2872.         if (WindowState = wsMaximized) and (FForm.FormStyle <> fsMDIChild)
  2873.         then
  2874.           begin
  2875.             L := FForm.Left;
  2876.             T := FForm.Top;
  2877.             PRect(Message.LParam)^.Left := L;
  2878.             PRect(Message.LParam)^.Top := T;
  2879.             PRect(Message.LParam)^.Right := L + FForm.Width;
  2880.             PRect(Message.LParam)^.Bottom := T + FForm.Height;
  2881.           end
  2882.         else
  2883.         if FMagnetic
  2884.         then
  2885.           begin
  2886.             L := PRect(Message.LParam)^.Left;
  2887.             T := PRect(Message.LParam)^.Top;
  2888.             DoMagnetic(L, T, FForm.Width, FForm.Height);
  2889.             PRect(Message.LParam)^.Left := L;
  2890.             PRect(Message.LParam)^.Top := T;
  2891.             PRect(Message.LParam)^.Right := L + FForm.Width;
  2892.             PRect(Message.LParam)^.Bottom := T + FForm.Height;
  2893.           end;
  2894.       WM_ENTERSIZEMOVE:
  2895.       if FSupportNCArea
  2896.       then
  2897.         begin
  2898.           FSizeMove := True;
  2899.           FFullDrag := GetFullDragg;
  2900.         end;
  2901.       WM_EXITSIZEMOVE:
  2902.         if FSupportNCArea
  2903.         then
  2904.           begin
  2905.             FSizeMove := False;
  2906.             if FSupportNCArea and (FSD <> nil) and not FSD.Empty
  2907.             then
  2908.               SendMessage(FForm.Handle, WM_NCPAINT, 0, 0);
  2909.          end;
  2910.       WM_SIZING:
  2911.       if FSizeMove and FFullDrag
  2912.       then
  2913.         begin
  2914.           OldWindowProc(Message);
  2915.           Old := False;
  2916.           R := PRect(LParam);
  2917.           FFormWidth := RectWidth(R^);
  2918.           FFormHeight := RectHeight(R^);
  2919.           if FSupportNCArea
  2920.           then
  2921.             begin
  2922.               if (FSD <> nil) and
  2923.                  (FForm.Width >= GetMinWidth) and
  2924.                  (FForm.Height >= GetMinHeight)
  2925.               then
  2926.                 CreateNewForm(True);
  2927.             end;
  2928.         end;
  2929.       WM_SIZE:
  2930.       if not FSizeMove or not FFullDrag
  2931.       then
  2932.         begin
  2933.           OldWindowProc(Message);
  2934.           Old := False;
  2935.           FFormWidth := FForm.Width;
  2936.           FFormHeight := FForm.Height;
  2937.           if not FSkinSupport
  2938.           then
  2939.             begin
  2940.               if FSupportNCArea
  2941.               then
  2942.                 SendMessage(FForm.Handle, WM_NCPAINT, 0, 0);
  2943.             end  
  2944.           else  
  2945.           if FSupportNCArea
  2946.           then
  2947.             begin
  2948.               if (FSD <> nil) and
  2949.                  (FFormWidth >= GetMinWidth) and
  2950.                  (FFormHeight >= GetMinHeight)
  2951.               then
  2952.                 CreateNewForm(True);
  2953.             end
  2954.           else
  2955.             begin
  2956.               if (FSD <> nil) and not FRollUpState
  2957.               then
  2958.                 begin
  2959.                   CS := CanScale;
  2960.                   if CS or (not CS and (FForm.ClientWidth = FSD.FPicture.Width)
  2961.                      and (FForm.ClientHeight = FSD.FPicture.Height))
  2962.                   then CreateNewForm(CS);
  2963.                 end;
  2964.             end;
  2965.           if FAlphaBlend and (FAlphaBlendValue <> 255) and CheckW2KWXP and
  2966.              FSupportNCArea
  2967.           then
  2968.             begin
  2969.               SendMessage(FForm.Handle, WM_NCPAINT, 0, 0);
  2970.               FForm.RePaint;
  2971.             end;
  2972.         end;
  2973.       WM_DESTROY:
  2974.       begin
  2975.         MouseTimer.Enabled := False;
  2976.         MorphTimer.Enabled := False;
  2977.         AnimateTimer.Enabled := False;
  2978.         if (FForm.FormStyle = fsMDIChild)
  2979.         then
  2980.           begin
  2981.             FWindowState := wsNormal;
  2982.             SendMessage(Application.MainForm.Handle, WM_MDICHILDRESTORE, 0, 0);
  2983.           end;  
  2984.       end;
  2985.      WM_ACTIVATE:
  2986.        begin
  2987.          FIsDragging := False;
  2988.          OldWindowProc(Message);
  2989.          if FSupportNCArea and Self.GetAutoRenderingInActiveImage
  2990.          then UpDateActiveObjects;
  2991.          if FSupportNCArea then SendMessage(FForm.Handle, WM_NCPaint, 0, 0);
  2992.          if (FForm.FormStyle = fsMDIChild) and (WindowState = wsMaximized)
  2993.          then
  2994.            FormChangeActive(False)
  2995.          else
  2996.            FormChangeActive(True);
  2997.          Old := False;
  2998.        end;
  2999.      WM_GetMinMaxInfo:
  3000.       begin
  3001.         MM := PMinMaxInfo(lParam);
  3002.         MM^.ptMinTrackSize.x := GetMinWidth;
  3003.         MM^.ptMinTrackSize.y := GetMinHeight;
  3004.         MM^.ptMaxTrackSize.x := GetMaxWidth;
  3005.         MM^.ptMaxTrackSize.y := GetMaxHeight;
  3006.       end;
  3007.      WM_NCCALCSIZE:
  3008.        begin
  3009.          Old := False;
  3010.          if FSupportNCArea and
  3011.             not ((FForm.FormStyle = fsMDIChild) and
  3012.             (WindowState = wsMaximized)) and (FForm.BorderStyle <> bsNone)
  3013.          then
  3014.            if CanNCSupport
  3015.            then
  3016.              begin
  3017.                CalcRects;
  3018.                with TWMNCCALCSIZE(Message).CalcSize_Params^.rgrc[0], FSD do
  3019.                begin
  3020.                  Inc(Left, ClRect.Left);
  3021.                  Inc(Top,  ClRect.Top);
  3022.                  Dec(Right, FPicture.Width - ClRect.Right);
  3023.                  Dec(Bottom, FPicture.Height - ClRect.Bottom);
  3024.                  if Right < Left
  3025.                  then Right := Left;
  3026.                  if Bottom < Top
  3027.                  then Bottom := Top;
  3028.                end;
  3029.              end
  3030.            else
  3031.              with TWMNCCALCSIZE(Message).CalcSize_Params^.rgrc[0] do
  3032.              begin
  3033.                Inc(Left, 3);
  3034.                Inc(Top, GetDefCaptionHeight + 3);
  3035.                Dec(Right, 3);
  3036.                Dec(Bottom, 3);
  3037.                if Right < Left then Right := Left;
  3038.                if Bottom < Top
  3039.                then Bottom := Top;
  3040.              end;
  3041.        end;
  3042.     WM_SYNCPAINT:
  3043.       if FRollUpState and FSupportNCArea
  3044.       then
  3045.         begin
  3046.           SendMessage(FForm.Handle, WM_NCPAINT, 0, 0);
  3047.            Message.Result := 0;
  3048.           Old := False;
  3049.         end;
  3050.      WM_NCPAINT:
  3051.       begin
  3052.         if (FForm.BorderStyle <> bsNone) and
  3053.             not ((FForm.FormStyle = fsMDICHILD) and (WindowState = wsMaximized))
  3054.         then
  3055.           if FSupportNCArea and FSkinSupport
  3056.           then
  3057.             PaintNCSkin
  3058.           else
  3059.           if FSupportNCArea
  3060.           then
  3061.             PaintNCDefault;
  3062.         Old := False;
  3063.       end;
  3064.     WM_NCACTIVATE:
  3065.       begin
  3066.         FFormActive := TWMNCACTIVATE(Message).Active;
  3067.         if (FForm.FormStyle = fsMDIForm) or
  3068.            (FForm.FormStyle = fsMDIChild)
  3069.         then
  3070.           OldWindowProc(Message)
  3071.         else
  3072.           Message.Result := 1;
  3073.         if not ((FForm.FormStyle = fsMDICHILD) and (WindowState = wsMaximized))
  3074.            and (FForm.BorderStyle <> bsNone)
  3075.         then
  3076.           begin
  3077.             SendMessage(FForm.Handle, WM_NCPAINT, 0, 0);
  3078.             FormChangeActive(True);
  3079.           end
  3080.         else
  3081.           FormChangeActive(False);
  3082.         if (FForm.FormStyle = fsMDIChild) and (WindowState = wsMaximized)
  3083.         then
  3084.           begin
  3085.             Application.MainForm.Perform(WM_NCPAINT, 0, 0);
  3086.           end;
  3087.         if FForm.FormStyle = fsMDIChild then  UpDateChildActiveInMenu;
  3088.         
  3089.         Old := False;
  3090.       end;
  3091.      WM_ERASEBKGND:
  3092.        begin
  3093.          if FSupportNCArea
  3094.          then
  3095.            begin
  3096.              if FSkinSupport
  3097.              then
  3098.                begin
  3099.                  if FSD.BGPictureIndex = -1
  3100.                  then
  3101.                    PaintBG(wParam)
  3102.                  else
  3103.                    PaintBG2(wParam);
  3104.                end
  3105.              else
  3106.                PaintBGDefault(wParam);
  3107.            end
  3108.          else
  3109.            Paint(wParam);
  3110.          Old := False;
  3111.        end;
  3112.     end;
  3113.     
  3114.     if Old then OldWindowProc(Message);
  3115.     case Msg of
  3116.       WM_LBUTTONDBLCLK:
  3117.         begin
  3118.           MouseDown(mbLeft, LoWord(LParam), HiWord(LParam));
  3119.           MouseDblClick;
  3120.           CheckWindowState;
  3121.         end;
  3122.       WM_RBUTTONDBLCLK: MouseDown(mbRight, LoWord(LParam), HiWord(LParam));
  3123.       WM_MOUSEMOVE:
  3124.         begin
  3125.           if not FSupportNCArea
  3126.           then MouseMove(LoWord(LParam), HiWord(LParam));
  3127.         end;
  3128.       WM_LBUTTONDOWN:
  3129.         begin
  3130.           if not FSupportNCArea
  3131.           then MouseDown(mbLeft, LoWord(LParam), HiWord(LParam));
  3132.         end;
  3133.       WM_RBUTTONDOWN:
  3134.         begin
  3135.           if not FSupportNCArea
  3136.           then MouseDown(mbRight, LoWord(LParam), HiWord(LParam));
  3137.         end;  
  3138.       WM_LBUTTONUP:
  3139.         begin
  3140.           if not FSupportNCArea
  3141.           then MouseUp(mbLeft, LoWord(LParam), HiWord(LParam))
  3142.           else MouseUp(mbLeft, -1, -1);
  3143.         end;
  3144.       WM_RBUTTONUP:
  3145.         begin
  3146.           if not FSupportNCArea
  3147.           then MouseUp(mbRight, LoWord(LParam), HiWord(LParam))
  3148.           else MouseUp(mbRight, -1, -1);
  3149.         end;
  3150.       WM_NCMOUSEMOVE:
  3151.       if FSupportNCArea then
  3152.         begin
  3153.           P.X := LoWord(lParam);
  3154.           P.Y := HiWord(lParam);
  3155.           PointToNCPoint(P);
  3156.           MouseMove(P.X, P.Y);
  3157.         end;
  3158.       WM_NCLBUTTONDBLCLK:
  3159.       if FSupportNCArea then
  3160.       begin
  3161.         P.X := LoWord(Message.lParam);
  3162.         P.Y := HiWord(Message.lParam);
  3163.         PointToNCPoint(P);
  3164.         TestActive(P.X, P.Y, True);
  3165.         MouseDown(mbLeft, P.X, P.Y);
  3166.         MouseDblClick;
  3167.         if Message.wParam = HTCAPTION
  3168.         then
  3169.           if FSizeAble and (WindowState = wsMinimized)
  3170.           then
  3171.             begin
  3172.               WindowState := wsNormal;
  3173.               MouseCaptureObject := -1;
  3174.             end
  3175.           else
  3176.           if FSizeAble and (WindowState <> wsMaximized) and not FRollUpState and
  3177.              (biMaximize in BorderIcons)
  3178.           then
  3179.             begin
  3180.               WindowState := wsMaximized;
  3181.               MouseCaptureObject := -1;
  3182.             end
  3183.           else
  3184.           if FSizeAble and (WindowState = wsMaximized) and not MaxRollUpState
  3185.           then
  3186.             begin
  3187.               WindowState := wsNormal;
  3188.               MouseCaptureObject := -1;
  3189.             end
  3190.           else
  3191.             begin
  3192.               if FRollUpState
  3193.               then
  3194.                 RollUpState := False
  3195.               else
  3196.                 RollUpState := True;
  3197.               MouseCaptureObject := -1;
  3198.             end;
  3199.       end;
  3200.       WM_NCRBUTTONDBLCLK:
  3201.       if FSupportNCArea then
  3202.         begin
  3203.           P.X := LoWord(Message.lParam);
  3204.           P.Y := HiWord(Message.lParam);
  3205.           PointToNCPoint(P);
  3206.           TestActive(P.X, P.Y, True);
  3207.           MouseDown(mbRight, P.X, P.Y);
  3208.           if wParam = HTCAPTION then MouseCaptureObject := -1;
  3209.         end;
  3210.       WM_NCLBUTTONDOWN:
  3211.       if FSupportNCArea then
  3212.         begin
  3213.           P.X := LoWord(lParam);
  3214.           P.Y := HiWord(lParam);
  3215.           PointToNCPoint(P);
  3216.           TestActive(P.X, P.Y, True);
  3217.           MouseDown(mbLeft, P.X, P.Y);
  3218.           if wParam = HTCAPTION then MouseCaptureObject := -1;
  3219.         end;
  3220.       WM_NCLBUTTONUP:
  3221.       if FSupportNCArea then
  3222.         begin
  3223.           P.X := LoWord(lParam);
  3224.           P.Y := HiWord(lParam);
  3225.           PointToNCPoint(P);
  3226.           MouseUp(mbLeft, LoWord(LParam), HiWord(LParam));
  3227.         end;
  3228.       WM_NCRBUTTONDOWN:
  3229.       if FSupportNCArea then
  3230.         begin
  3231.           P.X := LoWord(lParam);
  3232.           P.Y := HiWord(lParam);
  3233.           PointToNCPoint(P);
  3234.           TestActive(P.X, P.Y, True);
  3235.           MouseDown(mbRight, P.X, P.Y);
  3236.           if wParam = HTCAPTION
  3237.           then
  3238.             begin
  3239.               GetCursorPos(P);
  3240.               MouseCaptureObject := -1;
  3241.               TrackSystemMenu(P.X, P.Y);
  3242.             end;
  3243.         end;
  3244.       WM_NCRBUTTONUP:
  3245.       if FSupportNCArea then
  3246.         begin
  3247.           P.X := LoWord(lParam);
  3248.           P.Y := HiWord(lParam);
  3249.           PointToNCPoint(P);
  3250.           MouseUp(mbRight, P.X, P.Y);
  3251.         end;
  3252.     end;
  3253.   end;
  3254. end;
  3255. procedure TspDynamicSkinForm.CalcRects;
  3256. var
  3257.   OX, OY: Integer;
  3258. begin
  3259.   if FFormWidth = 0 then FFormWidth := FForm.Width;
  3260.   if FFormHeight = 0 then FFormHeight := FForm.Height;
  3261.   if (FSD <> nil) and not FSD.Empty then
  3262.   with FSD do
  3263.   begin
  3264.     OX := FFormWidth - FPicture.Width;
  3265.     OY := FFormHeight - FPicture.Height;
  3266.     NewLTPoint := LTPoint;
  3267.     NewRTPoint := Point(RTPoint.X + OX, RTPoint.Y);
  3268.     NewLBPoint := Point(LBPoint.X, LBPoint.Y + OY);
  3269.     NewRBPoint := Point(RBPoint.X + OX, RBPoint.Y + OY);
  3270.     NewClRect := Rect(ClRect.Left, ClRect.Top,
  3271.     ClRect.Right + OX, ClRect.Bottom + OY);
  3272.     NewCaptionRect := CaptionRect;
  3273.     if not IsNullRect(CaptionRect)
  3274.     then Inc(NewCaptionRect.Right, OX);
  3275.     NewButtonsRect := ButtonsRect;
  3276.     NewButtonsInLeft := CapButtonsInLeft;
  3277.     if not IsNullRect(ButtonsRect) and (ButtonsRect.Left > FPicture.Width div 2)
  3278.     then
  3279.       OffsetRect(NewButtonsRect, OX, 0)
  3280.     else
  3281.     if not IsNullRect(ButtonsRect) and (ButtonsRect.Left < FPicture.Width div 2)
  3282.     then
  3283.       ButtonsInLeft := True;
  3284.     NewButtonsOffset := ButtonsOffset;
  3285.     NewHitTestLTPoint := HitTestLTPoint;
  3286.     NewHitTestRTPoint := Point(HitTestRTPoint.X + OX, HitTestRTPoint.Y);
  3287.     NewHitTestLBPoint := Point(HitTestLBPoint.X, LBPoint.Y + OY);
  3288.     NewHitTestRBPoint := Point(HitTestRBPoint.X + OX, HitTestRBPoint.Y + OY);
  3289.     NewMaskRectArea := Rect(MaskRectArea.Left, MaskRectArea.Top,
  3290.     MaskRectArea.Right + OX, MaskRectArea.Bottom + OY);
  3291.     NewIconRect := Self.CalcRealObjectRect(IconRect);
  3292.     NewMainMenuRect := MainMenuRect;
  3293.     if CanScale
  3294.     then
  3295.       begin
  3296.         NewMainMenuRect.Right := MainMenuRect.Right + OX;
  3297.         if PtInRect(Rect(0, LBPoint.Y, LBPoint.X,
  3298.            FPicture.Height), MainMenuRect.TopLeft)
  3299.         then
  3300.           OffsetRect(NewMainMenuRect, 0, OY);
  3301.       end;
  3302.   end;
  3303. end;
  3304. procedure TspDynamicSkinForm.CreateNewForm;
  3305. begin
  3306.   if csDesigning in ComponentState then Exit;
  3307.   if FSD = nil then Exit;
  3308.   if FSD.Empty then Exit;
  3309.   CalcRects;
  3310.   if FCanScale then CalcAllRealObjectRect;
  3311.   CreateNewRegion(FCanScale);
  3312.   if Assigned(FOnChangeClientRect) then FOnChangeClientRect(NewClRect);
  3313.   if FSupportNCArea
  3314.   then
  3315.     begin
  3316.       if FRgn = 0
  3317.       then SendMessage(FForm.Handle, WM_NCPAINT, 0, 0);
  3318.     end
  3319.   else
  3320.     begin
  3321.       FForm.RePaint;
  3322.       ControlsToAreas;
  3323.     end;
  3324. end;
  3325. procedure TspDynamicSkinForm.CreateNewRegion;
  3326. var
  3327.   Size: Integer;
  3328.   RgnData: PRgnData;
  3329.   R1, R2, R3, R4, TempRgn: HRGN;
  3330. begin
  3331.   if (FForm.BorderStyle = bsNone) and FSupportNCArea
  3332.   then
  3333.     begin
  3334.       if FRgn <> 0
  3335.       then
  3336.         begin
  3337.           SetWindowRgn(FForm.Handle, 0, True);
  3338.           DeleteObject(FRgn);
  3339.           FRgn := 0;
  3340.         end;
  3341.     end
  3342.   else  
  3343.   if (FForm.FormStyle = fsMDIChild) and (WindowState = wsMaximized) and not FSD.FMask.Empty
  3344.   then
  3345.     begin
  3346.       if FRgn <> 0
  3347.       then
  3348.         begin
  3349.           SetWindowRgn(FForm.Handle, 0, True);
  3350.           DeleteObject(FRgn);
  3351.           FRgn := 0;
  3352.         end;
  3353.     end
  3354.   else
  3355.   if FSD.FMask.Empty and (FRgn <> 0)
  3356.   then
  3357.     begin
  3358.       SetWindowRgn(FForm.Handle, 0, True);
  3359.       DeleteObject(FRgn);
  3360.       FRgn := 0;
  3361.       RMLeft.Assign(nil);
  3362.       RMTop.Assign(nil);
  3363.       RMRight.Assign(nil);
  3364.       RMBottom.Assign(nil);
  3365.     end
  3366.   else
  3367.     if not FSD.FMask.Empty
  3368.     then
  3369.       begin
  3370.         if FCanScale
  3371.         then
  3372.           begin
  3373.             CreateSkinMask(
  3374.                FSD.LTPoint, FSD.RTPoint, FSD.LBPoint, FSD.RBPoint, FSD.MaskRectArea,
  3375.                NewLtPoint, NewRTPoint, NewLBPoint, NewRBPoint, NewMaskRectArea,
  3376.                FSD.FMask, RMTop, RMLeft, RMRight, RMBottom,
  3377.                FFormWidth, FFormHeight);
  3378.             if RMTop.Height > 0
  3379.             then
  3380.               begin
  3381.                 Size := CreateRgnFromBmp(RMTop, 0, 0, RgnData);
  3382.                 R1 := ExtCreateRegion(nil, Size, RgnData^);
  3383.                 FreeMem(RgnData, Size);
  3384.               end
  3385.             else
  3386.               R1 := 0;    
  3387.             if RMBottom.Height > 0
  3388.             then
  3389.               begin
  3390.                 Size := CreateRgnFromBmp(RMBottom, 0, NewMaskRectArea.Bottom, RgnData);
  3391.                 R2 := ExtCreateRegion(nil, Size, RgnData^);
  3392.                 FreeMem(RgnData, Size);
  3393.               end
  3394.             else
  3395.               R2 := 0;  
  3396.             if RMLeft.Width > 0
  3397.             then
  3398.               begin
  3399.                 Size := CreateRgnFromBmp(RMLeft, 0, NewMaskRectArea.Top, RgnData);
  3400.                 R3 := ExtCreateRegion(nil, Size, RgnData^);
  3401.                 FreeMem(RgnData, Size);
  3402.               end
  3403.             else
  3404.               R3 := 0;
  3405.             if RMRight.Width > 0
  3406.             then
  3407.               begin
  3408.                 Size := CreateRgnFromBmp(RMRight, NewMaskRectArea.Right, NewMaskRectArea.Top, RgnData);
  3409.                 R4 := ExtCreateRegion(nil, Size, RgnData^);
  3410.                 FreeMem(RgnData, Size);
  3411.               end
  3412.             else
  3413.               R4 := 0;    
  3414.             TempRgn := FRgn;
  3415.             FRgn := CreateRectRgn(NewMaskRectArea.Left, NewMaskRectArea.Top,
  3416.                                   NewMaskRectArea.Right, NewMaskRectArea.Bottom);
  3417.             CombineRgn(R1, R1, R2, RGN_OR);
  3418.             CombineRgn(R3, R3, R4, RGN_OR);
  3419.             CombineRgn(R3, R3, R1, RGN_OR);
  3420.             CombineRgn(FRgn, FRgn, R3, RGN_OR);
  3421.             SetWindowRgn(FForm.Handle, FRgn, True);
  3422.             if TempRgn <> 0 then DeleteObject(TempRgn);
  3423.             DeleteObject(R1);
  3424.             DeleteObject(R2);
  3425.             DeleteObject(R3);
  3426.             DeleteObject(R4);
  3427.           end
  3428.         else
  3429.           begin
  3430.             Size := CreateRgnFromBmp(FSD.FMask, 0, 0, RgnData);
  3431.             if Size <> 0
  3432.             then
  3433.               begin
  3434.                 TempRgn := FRgn;
  3435.                 FRgn := ExtCreateRegion(nil, Size, RgnData^);
  3436.                 SetWindowRgn(FForm.Handle, FRgn, True);
  3437.                 if TempRgn <> 0 then DeleteObject(TempRgn);
  3438.                 FreeMem(RgnData, Size);
  3439.               end;
  3440.           end;
  3441.       end;
  3442. end;
  3443. function TspDynamicSkinForm.GetFormActive;
  3444. begin
  3445.   if (FForm.FormStyle = fsMDIChild) or (FForm.FormStyle = fsMDIForm)
  3446.   then
  3447.     Result := FFormActive
  3448.   else
  3449.     Result := FForm.Active and (Screen.ActiveCustomForm = FForm);
  3450. end;
  3451. procedure TspDynamicSkinForm.FormChangeActive;
  3452. var
  3453.   i: Integer;
  3454.   FA: Boolean;
  3455. begin
  3456.   FA := GetFormActive;
  3457.   for i := 0 to ObjectList.Count - 1 do
  3458.     if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinCaptionObject
  3459.     then
  3460.       with TspSkinCaptionObject(ObjectList.Items[i]) do
  3461.       begin
  3462.         if AUpDate and CanObjectTest(RollUp)
  3463.         then
  3464.           begin
  3465.             if not FSupportNCArea then Active := FA;
  3466.             if not (FSupportNCArea and IsNullRect(ActiveSkinRect))
  3467.             then
  3468.               ReDraw;
  3469.           end
  3470.         else
  3471.           if Morphing then
  3472.           if FA then MorphKf := 1 else MorphKf := 0;
  3473.        end;
  3474.   if FA
  3475.   then
  3476.     begin
  3477.       if Assigned(FOnActivate) then FOnActivate(Self);
  3478.     end
  3479.   else
  3480.     begin
  3481.       if Assigned(FOnDeActivate) then FOnDeActivate(Self);
  3482.     end;
  3483. end;
  3484. procedure TspDynamicSkinForm.SetEnabled;
  3485. var
  3486.   i: Integer;
  3487. begin
  3488.   i := GetIndex(AIDName);
  3489.   if i <> -1
  3490.   then
  3491.     TspActiveSkinObject(ObjectList.Items[i]).Enabled := Value;
  3492. end;
  3493. procedure TspDynamicSkinForm.SwitchSetState;
  3494. var
  3495.   i: Integer;
  3496. begin
  3497.   i := GetIndex(AIDName);
  3498.   if i <> - 1 then
  3499.   if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinSwitchObject
  3500.   then
  3501.     with TspSkinSwitchObject(ObjectList.Items[i]) do
  3502.       if FInChangeSkinData
  3503.       then SimpleSetState(AState)
  3504.       else State := AState;
  3505. end;
  3506. function TspDynamicSkinForm.SwitchGetState;
  3507. var
  3508.   i: Integer;
  3509. begin
  3510.   i := GetIndex(AIDName);
  3511.   if i <> - 1
  3512.   then
  3513.     begin
  3514.       if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinSwitchObject
  3515.       then
  3516.         with TspSkinSwitchObject(ObjectList.Items[i]) do Result := State
  3517.       else
  3518.         Result := swOff;
  3519.     end
  3520.   else
  3521.     Result := swOff;
  3522. end;
  3523. procedure TspDynamicSkinForm.CaptionSetText;
  3524. var
  3525.   i: Integer;
  3526. begin
  3527.   i := GetIndex(AIDName);
  3528.   if i <> - 1 then
  3529.   if TspActiveSkinObject(ObjectList.Items[i]) is TspSkinCaptionObject
  3530.   then
  3531.     with TspSkinCaptionObject(ObjectList.Items[i]) do
  3532.       if FInChangeSkinData
  3533.       then SimpleSetTextValue(AText)
  3534.       else TextValue := AText;
  3535. end;
  3536. function TspDynamicSkinForm.ButtonGetDown;
  3537. var
  3538.   i: Integer;
  3539. begin
  3540.   i := GetIndex(AIDName);
  3541.   if (i <> -1) and (TspActiveSkinObject(ObjectList.Items[i]) is TspSkinButtonObject)
  3542.   then
  3543.     Result := TspSkinButtonObject(ObjectList.Items[i]).Down
  3544.   else
  3545.     Result := False;
  3546. end;
  3547. procedure TspDynamicSkinForm.ButtonSetDown;
  3548. var
  3549.   i: Integer;
  3550. begin
  3551.   i := GetIndex(AIDName);
  3552.   if (i <> -1) and (TspActiveSkinObject(ObjectList.Items[i]) is TspSkinButtonObject)
  3553.   then TspSkinButtonObject(ObjectList.Items[i]).Down := ADown;
  3554. end;
  3555. end.