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

Delphi控件源码

开发平台:

Delphi

  1. {========================================================================}
  2. {=                (c) 1995-98 SwiftSoft Ronald Dittrich                 =}
  3. {========================================================================}
  4. {=                          All Rights Reserved                         =}
  5. {========================================================================}
  6. {=  D 01099 Dresden             = Fax.: +49 (0)351-8037944              =}
  7. {=  Loewenstr.7a                = info@swiftsoft.de                     =}
  8. {========================================================================}
  9. {=  Actual versions on http://www.swiftsoft.de/mmtools.html             =}
  10. {========================================================================}
  11. {=  This code is for reference purposes only and may not be copied or   =}
  12. {=  distributed in any format electronic or otherwise except one copy   =}
  13. {=  for backup purposes.                                                =}
  14. {=                                                                      =}
  15. {=  No Delphi Component Kit or Component individually or in a collection=}
  16. {=  subclassed or otherwise from the code in this unit, or associated   =}
  17. {=  .pas, .dfm, .dcu, .asm or .obj files may be sold or distributed     =}
  18. {=  without express permission from SwiftSoft.                          =}
  19. {=                                                                      =}
  20. {=  For more licence informations please refer to the associated        =}
  21. {=  HelpFile.                                                           =}
  22. {========================================================================}
  23. {=  $Date: 08.04.98 - 05:23:31 $                                        =}
  24. {========================================================================}
  25. unit MMBmpDlg;
  26. {$I COMPILER.INC}
  27. interface
  28. uses
  29.   Windows,
  30.   Messages,
  31.   SysUtils,
  32.   Classes,
  33.   Graphics,
  34.   Controls,
  35.   Forms,
  36.   Dialogs,
  37.   StdCtrls,
  38.   ExtCtrls,
  39.   Clipbrd,
  40.   Menus,
  41.   MMObj,
  42.   MMUtils,
  43.   MMBmpLst,
  44.   MMFill,
  45.   MMCstDlg,
  46.   MMBmpBtn;
  47. type
  48.   TWMSizing = record
  49.      Msg   : Cardinal;
  50.      fwSide: Longint;
  51.      lpRect: PRect;
  52.      Result: Longint;
  53.   end;
  54.   TMMUpdateMode = (umUp,umDown,umDelete);
  55. type
  56.   TMMBitmapListEditor = class(TForm)
  57.     MainMenu1: TMainMenu;
  58.     File1: TMenuItem;
  59.     Edit1: TMenuItem;
  60.     About1: TMenuItem;
  61.     Bevel1: TBevel;
  62.     Panel1: TPanel;
  63.     Bevel2: TBevel;
  64.     Panel2: TPanel;
  65.     ClientPanel: TPanel;
  66.     ListHeader: THeader;
  67.     Bevel3: TBevel;
  68.     Panel4: TPanel;
  69.     ListBox: TListBox;
  70.     Bevel4: TBevel;
  71.     menLoad: TMenuItem;
  72.     menSave: TMenuItem;
  73.     N1: TMenuItem;
  74.     Exit1: TMenuItem;
  75.     PicOpenDialog: TMMPictureOpenDialog;
  76.     OpenDialog: TOpenDialog;
  77.     SaveDialog: TSaveDialog;
  78.     menCut: TMenuItem;
  79.     menCopy: TMenuItem;
  80.     menPaste: TMenuItem;
  81.     menDelete: TMenuItem;
  82.     N2: TMenuItem;
  83.     menUp: TMenuItem;
  84.     menDown: TMenuItem;
  85.     N3: TMenuItem;
  86.     menClear: TMenuItem;
  87.     N4: TMenuItem;
  88.     menAddList: TMenuItem;
  89.     N5: TMenuItem;
  90.     menSaveBMP: TMenuItem;
  91.     PicSaveDialog: TMMPictureSaveDialog;
  92.     MMBitmapList1: TMMBitmapList;
  93.     btnAdd: TMMBitmapButton;
  94.     btnAddMultiple: TMMBitmapButton;
  95.     btnDelete: TMMBitmapButton;
  96.     btnClear: TMMBitmapButton;
  97.     btnUp: TMMBitmapButton;
  98.     btnDown: TMMBitmapButton;
  99.     btnLoad: TMMBitmapButton;
  100.     btnSave: TMMBitmapButton;
  101.     btnCut: TMMBitmapButton;
  102.     btnCopy: TMMBitmapButton;
  103.     btnPaste: TMMBitmapButton;
  104.     btnHelp: TMMBitmapButton;
  105.     bnOK: TMMBitmapButton;
  106.     btnReplace: TMMBitmapButton;
  107.     menReplace: TMenuItem;
  108.     ButtonTimer: TTimer;
  109.     procedure btnOKClick(Sender: TObject);
  110.     procedure About1Click(Sender: TObject);
  111.     procedure menLoadClick(Sender: TObject);
  112.     procedure menSaveClick(Sender: TObject);
  113.     procedure FormCreate(Sender: TObject);
  114.     procedure FormDestroy(Sender: TObject);
  115.     procedure ListBoxDrawItem(Control: TWinControl; Index: Integer;
  116.                               Rect: TRect; State: TOwnerDrawState);
  117.     procedure ListHeaderSized(Sender: TObject; ASection, AWidth: Integer);
  118.     procedure btnClearClick(Sender: TObject);
  119.     procedure btnDeleteClick(Sender: TObject);
  120.     procedure btnAddClick(Sender: TObject);
  121.     procedure btnAddMultiClick(Sender: TObject);
  122.     procedure btnUpClick(Sender: TObject);
  123.     procedure btnDownClick(Sender: TObject);
  124.     procedure btnCutClick(Sender: TObject);
  125.     procedure btnCopyClick(Sender: TObject);
  126.     procedure btnPasteClick(Sender: TObject);
  127.     procedure menAddListClick(Sender: TObject);
  128.     procedure ListBoxDblClick(Sender: TObject);
  129.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  130.     procedure menSaveBMPClick(Sender: TObject);
  131.     procedure PreviewKeyPress(Sender: TObject; var Key: Char);
  132.     procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  133.     procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  134.     procedure FormResize(Sender: TObject);
  135.     procedure btnReplaceClick(Sender: TObject);
  136.     procedure ButtonTimerTimer(Sender: TObject);
  137.     procedure btnMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  138.     procedure btnMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  139.   private
  140.     FBitmaplist: TMMBitmapList;
  141.     FOrigList  : TMMBitmapList;
  142.     FUpdateIDs : Boolean;
  143.     procedure BitmapListChanged(Sender: TObject);
  144.     procedure SetBitmapList(List: TMMBitmapList);
  145.     procedure UpdateListBox(Index: integer);
  146.     procedure UpdateControls;
  147.     procedure WMSizing(var Msg: TWMSizing); message WM_SIZING;
  148.     procedure WMGetMinMaxInfo(Var Msg: TWMGetMinMaxInfo); message WM_GETMINMAXINFO;
  149.     procedure UpdateBitmapIDs(Index: integer; Mode: TMMUpdateMode);
  150.   public
  151.     property BitmapList: TMMBitmapList read FBitmapList write SetBitmapList;
  152.   end;
  153. var
  154.   MMBitmapListEditor: TMMBitmapListEditor;
  155. implementation
  156. {$R *.DFM}
  157. uses
  158.     TypInfo,
  159.     MMAbout;
  160. {== TMMBitmapListEditor =======================================================}
  161. procedure TMMBitmapListEditor.FormCreate(Sender: TObject);
  162. begin
  163.    {$IFDEF BUILD_ACTIVEX}
  164.    MMBitmapList1.Left := -50;
  165.    SetDesigning(False);
  166.    {$ENDIF}
  167.    FUpdateIDs  := False;
  168.    Icon.Handle := LoadResIcon(icoMMTools);
  169.    FBitmapList := TMMBitmapList.Create(Self);
  170.    FBitmapList.OnChange := BitmapListChanged;
  171.    UpdateControls;
  172. end;
  173. {-- TMMBitmapListEditor -------------------------------------------------------}
  174. procedure TMMBitmapListEditor.FormDestroy(Sender: TObject);
  175. begin
  176.    FBitmapList.Free;
  177. end;
  178. {-- TMMBitmapListEditor -------------------------------------------------------}
  179. procedure TMMBitmapListEditor.FormClose(Sender: TObject; var Action: TCloseAction);
  180. begin
  181.    if (ModalResult = mrOK) and (FOrigList <> nil) then
  182.    begin
  183.       FOrigList.Assign(FBitmapList)
  184.    end;
  185. end;
  186. {-- TMMBitmapListEditor -------------------------------------------------------}
  187. procedure TMMBitmapListEditor.SetBitmapList(List: TMMBitmapList);
  188. begin
  189.    FOrigList := List;
  190.    FBitmapList.Assign(List);
  191. end;
  192. {-- TMMBitmapListEditor -------------------------------------------------------}
  193. procedure TMMBitmapListEditor.UpdateBitmapIDs(Index: integer; Mode: TMMUpdateMode);
  194. var
  195.    Comps: TStringList;
  196.    Form: TCustomForm;
  197.    i,idx,Value: integer;
  198.    PropInfo: PPropInfo;
  199.    nGlyphs: integer;
  200. begin
  201.    if FUpdateIDs then
  202.    begin
  203.       Form := TCustomForm(FOrigList.Owner);
  204.       if (Form <> nil) then
  205.       begin
  206.          Comps := TStringList.Create;
  207.          for i := 0 to Form.ComponentCount-1 do
  208.          begin
  209.             PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'NumGlyphs');
  210.             if (PropInfo <> nil) then
  211.             begin
  212.                Value := GetOrdProp(Form.Components[i], PropInfo);
  213.                Comps.AddObject(Form.Components[i].Name+' NumGlyphs',Pointer(Value));
  214.             end;
  215.             PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'NumThumbGlyphs');
  216.             if (PropInfo <> nil) then
  217.             begin
  218.                Value := GetOrdProp(Form.Components[i], PropInfo);
  219.                Comps.AddObject(Form.Components[i].Name+' NumThumbGlyphs',Pointer(Value));
  220.             end;
  221.          end;
  222.          //FOrigList.Assign(FBitmapList);
  223.          case Mode of
  224.               umUp: begin
  225.                        for i := 0 to Form.ComponentCount-1 do
  226.                        begin
  227.                           PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapList');
  228.                           if (PropInfo <> nil) then
  229.                           begin
  230.                              if Pointer(GetOrdProp(Form.Components[i], PropInfo)) = Pointer(FOrigList) then
  231.                              begin
  232.                                 PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapIndex');
  233.                                 if (PropInfo <> nil) then
  234.                                 begin
  235.                                    Value := GetOrdProp(Form.Components[i], PropInfo);
  236.                                    if (Value = Index) then
  237.                                       SetOrdProp(Form.Components[i],PropInfo,Index-1)
  238.                                    else if (Value = Index-1) then
  239.                                        SetOrdProp(Form.Components[i],PropInfo,Index);
  240.                                 end;
  241.                                 PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapThumbIndex');
  242.                                 if (PropInfo <> nil) then
  243.                                 begin
  244.                                    Value := GetOrdProp(Form.Components[i], PropInfo);
  245.                                    if (Value = Index) then
  246.                                       SetOrdProp(Form.Components[i],PropInfo,Index-1)
  247.                                    else if (Value = Index-1) then
  248.                                        SetOrdProp(Form.Components[i],PropInfo,Index);
  249.                                 end;
  250.                                 PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapBackIndex');
  251.                                 if (PropInfo <> nil) then
  252.                                 begin
  253.                                    Value := GetOrdProp(Form.Components[i], PropInfo);
  254.                                    if (Value = Index) then
  255.                                       SetOrdProp(Form.Components[i],PropInfo,Index-1)
  256.                                    else if (Value = Index-1) then
  257.                                        SetOrdProp(Form.Components[i],PropInfo,Index);
  258.                                 end;
  259.                              end;
  260.                           end;
  261.                        end;
  262.                     end;
  263.             umDown: begin
  264.                        for i := 0 to Form.ComponentCount-1 do
  265.                        begin
  266.                           PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapList');
  267.                           if (PropInfo <> nil) then
  268.                           begin
  269.                              if Pointer(GetOrdProp(Form.Components[i], PropInfo)) = Pointer(FOrigList) then
  270.                              begin
  271.                                 PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapIndex');
  272.                                 if (PropInfo <> nil) then
  273.                                 begin
  274.                                    Value := GetOrdProp(Form.Components[i], PropInfo);
  275.                                    if (Value = Index) then
  276.                                        SetOrdProp(Form.Components[i],PropInfo,Index+1)
  277.                                    else if (Value = Index+1) then
  278.                                        SetOrdProp(Form.Components[i],PropInfo,Index);
  279.                                 end;
  280.                                 PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapThumbIndex');
  281.                                 if (PropInfo <> nil) then
  282.                                 begin
  283.                                    Value := GetOrdProp(Form.Components[i], PropInfo);
  284.                                    if (Value = Index) then
  285.                                        SetOrdProp(Form.Components[i],PropInfo,Index+1)
  286.                                    else if (Value = Index+1) then
  287.                                        SetOrdProp(Form.Components[i],PropInfo,Index);
  288.                                 end;
  289.                                 PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapBackIndex');
  290.                                 if (PropInfo <> nil) then
  291.                                 begin
  292.                                    Value := GetOrdProp(Form.Components[i], PropInfo);
  293.                                    if (Value = Index) then
  294.                                        SetOrdProp(Form.Components[i],PropInfo,Index+1)
  295.                                    else if (Value = Index+1) then
  296.                                        SetOrdProp(Form.Components[i],PropInfo,Index);
  297.                                 end;
  298.                              end;
  299.                           end;
  300.                        end;
  301.                     end;
  302.           umDelete: begin
  303.                        for i := 0 to Form.ComponentCount-1 do
  304.                        begin
  305.                           PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapList');
  306.                           if (PropInfo <> nil) then
  307.                           begin
  308.                              if Pointer(GetOrdProp(Form.Components[i], PropInfo)) = Pointer(FOrigList) then
  309.                              begin
  310.                                 PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapIndex');
  311.                                 if (PropInfo <> nil) then
  312.                                 begin
  313.                                    Value := GetOrdProp(Form.Components[i], PropInfo);
  314.                                    if (Value > Index) then
  315.                                        SetOrdProp(Form.Components[i],PropInfo,Value-1);
  316.                                 end;
  317.                                 PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapThumbIndex');
  318.                                 if (PropInfo <> nil) then
  319.                                 begin
  320.                                    Value := GetOrdProp(Form.Components[i], PropInfo);
  321.                                    if (Value > Index) then
  322.                                        SetOrdProp(Form.Components[i],PropInfo,Value-1);
  323.                                 end;
  324.                                 PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapBackIndex');
  325.                                 if (PropInfo <> nil) then
  326.                                 begin
  327.                                    Value := GetOrdProp(Form.Components[i], PropInfo);
  328.                                    if (Value > Index) then
  329.                                        SetOrdProp(Form.Components[i],PropInfo,Value-1);
  330.                                 end;
  331.                              end;
  332.                           end;
  333.                        end;
  334.                     end;
  335.          end;
  336.          for i := 0 to Form.ComponentCount-1 do
  337.          begin
  338.             PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'NumGlyphs');
  339.             if (PropInfo <> nil) then
  340.             begin
  341.                idx := Comps.IndexOf(Form.Components[i].Name+' NumGlyphs');
  342.                if (idx >= 0) then
  343.                begin
  344.                   SetOrdProp(Form.Components[i], PropInfo, integer(Comps.Objects[idx]));
  345.                end;
  346.             end;
  347.             PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'NumThumbGlyphs');
  348.             if (PropInfo <> nil) then
  349.             begin
  350.                idx := Comps.IndexOf(Form.Components[i].Name+' NumThumbGlyphs');
  351.                if (idx >= 0) then
  352.                begin
  353.                   SetOrdProp(Form.Components[i], PropInfo, integer(Comps.Objects[idx]));
  354.                end;
  355.             end;
  356.          end;
  357.          Comps.Free;
  358.       end;
  359.    end;
  360. end;
  361. {-- TMMBitmapListEditor -------------------------------------------------------}
  362. procedure TMMBitmapListEditor.BitmapListChanged(Sender: TObject);
  363. begin
  364.    UpdateListBox(ListBox.ItemIndex);
  365. end;
  366. {-- TMMBitmapListEditor -------------------------------------------------------}
  367. procedure TMMBitmapListEditor.UpdateListBox(Index: integer);
  368. var
  369.    i: integer;
  370.    function GetRefCount(idx: integer): integer;
  371.    var
  372.       Form: TCustomForm;
  373.       i: integer;
  374.       PropInfo: PPropInfo;
  375.    begin
  376.       Result := 0;
  377.       if FUpdateIDs then
  378.       begin
  379.          Form := TCustomForm(FOrigList.Owner);
  380.          if (Form <> nil) then
  381.          begin
  382.             for i := 0 to Form.ComponentCount-1 do
  383.             begin
  384.                PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapList');
  385.                if (PropInfo <> nil) then
  386.                begin
  387.                   if Pointer(GetOrdProp(Form.Components[i], PropInfo)) = Pointer(FOrigList) then
  388.                   begin
  389.                      PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapIndex');
  390.                      if (PropInfo <> nil) then
  391.                      begin
  392.                         if (GetOrdProp(Form.Components[i], PropInfo) = Idx) then inc(Result);
  393.                      end;
  394.                      PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapThumbIndex');
  395.                      if (PropInfo <> nil) then
  396.                      begin
  397.                         if (GetOrdProp(Form.Components[i], PropInfo) = Idx) then inc(Result);
  398.                      end;
  399.                   end;
  400.                end;
  401.             end;
  402.          end;
  403.       end;
  404.    end;
  405. begin
  406.    ListBox.Items.BeginUpdate;
  407.    try
  408.       ListBox.Clear;
  409.       for i := 0 to FBitmapList.Count-1 do
  410.       begin
  411.          ListBox.Items.AddObject(IntToStr(i),Pointer(GetRefCount(i)));
  412.       end;
  413.       if (Index < 0) then
  414.           Index := 0;
  415.       if (Index >= ListBox.Items.Count) then
  416.           Index := ListBox.Items.Count-1;
  417.       if (Index < ListBox.Items.Count) then
  418.           ListBox.ItemIndex := Index;
  419.       UpdateControls;
  420.    finally
  421.       ListBox.Items.EndUpdate;
  422.    end;
  423. end;
  424. {-- TFindMarkerForm -----------------------------------------------------}
  425. procedure TMMBitmapListEditor.ListBoxDrawItem(Control: TWinControl;
  426.                                               Index: Integer; Rect: TRect;
  427.                                               State: TOwnerDrawState);
  428. var
  429.   R: TRect;
  430.   S: string;
  431.   C: array[0..255] of Char;
  432.   X,Y,iWidth,iHeight,W: integer;
  433.   Factor: Double;
  434. begin
  435.    with ListBox.Canvas do
  436.    begin
  437.       FillRect(Rect);
  438.       inc(Rect.Top);
  439.       dec(Rect.Bottom);
  440.       R := Rect;
  441.       { draw the ID }
  442.       S := ListBox.Items[Index];
  443.       R.Right := ListHeader.SectionWidth[0];
  444.       X := (R.Left + ((R.Right-R.Left) div 2)) - TextWidth(S) div 2;
  445.       Y := (R.Top + ((R.Bottom-R.Top) div 2)) - TextHeight(S) div 2;
  446.       ExtTextOut(ListBox.Canvas.Handle, X, Y, ETO_CLIPPED or
  447.                  ETO_OPAQUE, @R, StrPCopy(C, S), Length(S), nil);
  448.       R.Left := R.Right;
  449.       R.Right := Rect.Right;
  450.       { draw the RefCount }
  451.       S := IntToStr(integer(ListBox.Items.Objects[Index]));
  452.       R.Right := ListHeader.SectionWidth[0]+ListHeader.SectionWidth[1];
  453.       X := (R.Left + ((R.Right-R.Left) div 2)) - TextWidth(S) div 2;
  454.       Y := (R.Top + ((R.Bottom-R.Top) div 2)) - TextHeight(S) div 2;
  455.       ExtTextOut(ListBox.Canvas.Handle, X, Y, ETO_CLIPPED or
  456.                  ETO_OPAQUE, @R, StrPCopy(C, S), Length(S), nil);
  457.       R.Left := R.Right;
  458.       R.Right := Rect.Right;
  459.       inc(R.Top);
  460.       dec(R.Bottom);
  461.       iWidth  := FBitmapList.Items[index].Width;
  462.       iHeight := FBitmapList.Items[index].Height;
  463.       if (iWidth < (R.Right-R.Left)) and
  464.          (iHeight < (R.Bottom-R.Top)) then
  465.       begin
  466.          R.Right := R.Left+iWidth;
  467.          R.Top   := R.Top + (((R.Bottom-R.Top)-iHeight) div 2);
  468.          R.Bottom:= R.Top + iHeight;
  469.       end
  470.       else
  471.       begin
  472.          if (iWidth <= iHeight) then
  473.          begin
  474.             if (iHeight > R.Bottom-R.Top) then
  475.             begin
  476.                Factor  := (R.Bottom - R.Top)/iHeight;
  477.                iWidth  := Trunc(iWidth * Factor);
  478.                iHeight := R.Bottom-R.Top;
  479.             end;
  480.             Factor  := Min(R.Bottom-R.Top,iHeight)/iHeight;
  481.             iWidth  := Trunc(iWidth * Factor);
  482.             if (iWidth > R.Right-R.Left) then
  483.             begin
  484.                Factor  := (R.Right - R.Left)/iWidth;
  485.                iHeight := Trunc(iHeight * Factor);
  486.                iWidth  := R.Right-R.Left;
  487.                R.Top    := R.Top + (((R.Bottom-R.Top)-iHeight) div 2);
  488.                R.Bottom := R.Top + iHeight;
  489.             end;
  490.             R.Right  := R.Left + iWidth;
  491.          end
  492.          else
  493.          begin
  494.             if (iHeight > R.Bottom-R.Top) then
  495.             begin
  496.                Factor  := (R.Bottom - R.Top)/iHeight;
  497.                iWidth  := Trunc(iWidth * Factor);
  498.                iHeight := R.Bottom-R.Top;
  499.             end;
  500.             W := Min(R.Right-R.Left,iWidth);
  501.             Factor   := W/iWidth;
  502.             iHeight  := Trunc(iHeight * Factor);
  503.             R.Top    := R.Top + (((R.Bottom-R.Top)-iHeight) div 2);
  504.             R.Bottom := R.Top + iHeight;
  505.             R.Right := R.Left+W;
  506.          end
  507.       end;
  508.       StretchDraw(R, FBitmapList.Items[index]);
  509.       UpdateControls;
  510.    end;
  511. end;
  512. {-- TMMBitmapListEditor -------------------------------------------------------}
  513. procedure TMMBitmapListEditor.ListHeaderSized(Sender: TObject; ASection, AWidth: Integer);
  514. begin
  515.    ListBox.Invalidate;
  516. end;
  517. {-- TMMBitmapListEditor -------------------------------------------------------}
  518. procedure TMMBitmapListEditor.UpdateControls;
  519. begin
  520.    with ListBox do
  521.    begin
  522.       btnDelete.Enabled := (FBitmapList.Count > 0) and (ListBox.ItemIndex >= 0);
  523.       menDelete.Enabled := btnDelete.Enabled;
  524.       btnClear.Enabled  := (FBitmapList.Count > 0);
  525.       menClear.Enabled  := btnClear.Enabled;
  526.       btnSave.Enabled   := btnClear.Enabled;
  527.       menSave.Enabled   := btnSave.Enabled;
  528.       btnUp.Enabled     := (Items.Count > 0) and (ItemIndex > 0);
  529.       menUp.Enabled     := btnUp.Enabled;
  530.       btnDown.Enabled   := (Items.Count > 0) and (ItemIndex < Items.Count-1);
  531.       menDown.Enabled   := btnDown.Enabled;
  532.       btnCut.Enabled    := btnDelete.Enabled;
  533.       menCut.Enabled    := btnCut.Enabled;
  534.       btnCopy.Enabled   := btnDelete.Enabled;
  535.       menCopy.Enabled   := btnCopy.Enabled;
  536.       menSaveBMP.Enabled:= btnCopy.Enabled;
  537.       btnPaste.Enabled  := Clipboard.HasFormat(CF_BITMAP);
  538.       menPaste.Enabled  := btnPaste.Enabled;
  539.       btnReplace.Enabled:= btnPaste.Enabled and (ListBox.ItemIndex >= 0) and (ListBox.Items.Count > 0);
  540.       menReplace.Enabled:= btnReplace.Enabled;
  541.    end;
  542. end;
  543. {-- TMMBitmapListEditor -------------------------------------------------------}
  544. procedure TMMBitmapListEditor.btnOKClick(Sender: TObject);
  545. begin
  546.    ModalResult := mrOK;
  547. end;
  548. {-- TMMBitmapListEditor -------------------------------------------------------}
  549. procedure TMMBitmapListEditor.About1Click(Sender: TObject);
  550. begin
  551.    Show_AboutBox(0);
  552. end;
  553. {-- TMMBitmapListEditor -------------------------------------------------------}
  554. procedure TMMBitmapListEditor.menLoadClick(Sender: TObject);
  555. begin
  556.    if OpenDialog.Execute then
  557.       FBitmapList.LoadFromFile(OpenDialog.FileName);
  558. end;
  559. {-- TMMBitmapListEditor -------------------------------------------------------}
  560. procedure TMMBitmapListEditor.menSaveClick(Sender: TObject);
  561. var
  562.    S: string;
  563. begin
  564.    if SaveDialog.Execute then
  565.    begin
  566.       S := ChangeFileExt(SaveDialog.FileName,'.~bm');
  567.       DeleteFile(S);
  568.       RenameFile(SaveDialog.FileName,S);
  569.       FBitmapList.SaveToFile(SaveDialog.FileName);
  570.    end;
  571. end;
  572. {-- TMMBitmapListEditor -------------------------------------------------------}
  573. procedure TMMBitmapListEditor.menAddListClick(Sender: TObject);
  574. begin
  575.    if OpenDialog.Execute then
  576.       FBitmapList.AddListFromFile(OpenDialog.FileName);
  577. end;
  578. {-- TMMBitmapListEditor -------------------------------------------------------}
  579. procedure TMMBitmapListEditor.menSaveBMPClick(Sender: TObject);
  580. begin
  581.    if PicSaveDialog.Execute then
  582.    begin
  583.       FBitmapList[ListBox.ItemIndex].SaveToFile(PicSaveDialog.FileName);
  584.    end;
  585. end;
  586. {-- TMMBitmapListEditor -------------------------------------------------------}
  587. procedure TMMBitmapListEditor.btnAddClick(Sender: TObject);
  588. begin
  589.    PicOpenDialog.Options := PicOpenDialog.Options - [ofAllowMultiSelect];
  590.    if PicOpenDialog.Execute then
  591.    begin
  592.       FBitmapList.AddFromFile(PicOpenDialog.FileName);
  593.    end;
  594. end;
  595. {-- TMMBitmapListEditor -------------------------------------------------------}
  596. procedure TMMBitmapListEditor.btnAddMultiClick(Sender: TObject);
  597. var
  598.    i: integer;
  599. begin
  600.    PicOpenDialog.Options := PicOpenDialog.Options + [ofAllowMultiSelect];
  601.    if PicOpenDialog.Execute then
  602.    begin
  603.       ListBox.Items.BeginUpdate;
  604.       try
  605.          for i := 0 to PicOpenDialog.Files.Count-1 do
  606.              FBitmapList.AddFromFile(PicOpenDialog.Files[i]);
  607.       finally
  608.          ListBox.Items.EndUpdate;
  609.       end;
  610.    end;
  611. end;
  612. {-- TMMBitmapListEditor -------------------------------------------------------}
  613. procedure TMMBitmapListEditor.btnClearClick(Sender: TObject);
  614. begin
  615.    FBitmapList.Clear;
  616. end;
  617. {-- TMMBitmapListEditor -------------------------------------------------------}
  618. procedure TMMBitmapListEditor.btnDeleteClick(Sender: TObject);
  619. begin
  620.    if btnDelete.Enabled then
  621.    begin
  622.       FBitmapList.Delete(ListBox.ItemIndex);
  623.       UpdateBitmapIDs(ListBox.ItemIndex,umDelete);
  624.    end;
  625. end;
  626. {-- TMMBitmapListEditor -------------------------------------------------------}
  627. procedure TMMBitmapListEditor.btnUpClick(Sender: TObject);
  628. begin
  629.    if (ListBox.ItemIndex > 0) then
  630.    begin
  631.       FBitmapList.Move(ListBox.ItemIndex,ListBox.ItemIndex-1);
  632.       UpdateBitmapIDs(ListBox.ItemIndex,umUp);
  633.       ListBox.ItemIndex := ListBox.ItemIndex-1;
  634.    end
  635.    else ButtonTimer.Enabled := False;
  636. end;
  637. {-- TMMBitmapListEditor -------------------------------------------------------}
  638. procedure TMMBitmapListEditor.btnDownClick(Sender: TObject);
  639. begin
  640.    if (ListBox.ItemIndex < ListBox.Items.Count-1) then
  641.    begin
  642.       FBitmapList.Move(ListBox.ItemIndex,ListBox.ItemIndex+1);
  643.       UpdateBitmapIDs(ListBox.ItemIndex,umDown);
  644.       ListBox.ItemIndex := ListBox.ItemIndex+1;
  645.    end
  646.    else ButtonTimer.Enabled := False;
  647. end;
  648. {-- TMMBitmapListEditor -------------------------------------------------------}
  649. procedure TMMBitmapListEditor.btnCutClick(Sender: TObject);
  650. begin
  651.    btnCopyClick(nil);
  652.    btnDeleteClick(nil);
  653. end;
  654. {-- TMMBitmapListEditor -------------------------------------------------------}
  655. procedure TMMBitmapListEditor.btnCopyClick(Sender: TObject);
  656. begin
  657.    Clipboard.Assign(FBitmapList.Items[ListBox.ItemIndex]);
  658. end;
  659. {-- TMMBitmapListEditor -------------------------------------------------------}
  660. procedure TMMBitmapListEditor.btnPasteClick(Sender: TObject);
  661. var
  662.    BMP: TBitmap;
  663.    idx: integer;
  664. begin
  665.    BMP := TBitmap.Create;
  666.    try
  667.       idx := ListBox.ItemIndex;
  668.       BMP.Assign(Clipboard);
  669.       FBitmapList.Insert(idx,BMP)
  670.    finally
  671.       BMP.Free;
  672.    end;
  673. end;
  674. {-- TMMBitmapListEditor -------------------------------------------------------}
  675. procedure TMMBitmapListEditor.btnReplaceClick(Sender: TObject);
  676. var
  677.    BMP: TBitmap;
  678.    idx: integer;
  679. begin
  680.    BMP := TBitmap.Create;
  681.    try
  682.       idx := ListBox.ItemIndex;
  683.       BMP.Assign(Clipboard);
  684.       FBitmapList.Delete(idx);
  685.       FBitmapList.Insert(idx,BMP)
  686.    finally
  687.       BMP.Free;
  688.    end;
  689. end;
  690. {-- TMMBitmapListEditor -------------------------------------------------------}
  691. procedure TMMBitmapListEditor.ListBoxDblClick(Sender: TObject);
  692. var
  693.    Form: TForm;
  694.    Panel: TPanel;
  695.    Image: TImage;
  696. begin
  697.    Panel := nil;
  698.    Image := nil;
  699.    Form  := TForm.Create(Self);
  700.    with Form do
  701.    try
  702.       BorderStyle   := bsSizeToolWin;
  703.       Caption       := 'Preview';
  704.       Position      := poScreenCenter;
  705.       PixelsPerInch := 96;
  706.       ClientWidth   := FBitmapList.Items[ListBox.ItemIndex].Width+10;
  707.       ClientHeight  := FBitmapList.Items[ListBox.ItemIndex].Height+10;
  708.       OnKeyPress    := PreviewKeyPress;
  709.       Panel := TPanel.Create(Form);
  710.       Panel.Parent      := Form;
  711.       Panel.Align       := alClient;
  712.       Panel.BevelOuter  := bvNone;
  713.       Panel.BorderWidth := 5;
  714.       Panel.Color       := clWindow;
  715.       Image := TImage.Create(Panel);
  716.       Image.Parent         := Panel;
  717.       Image.Align          := alClient;
  718.       Image.AutoSize       := True;
  719.       Image.Center         := True;
  720.       Image.Stretch        := True;
  721.       Image.Picture.Bitmap := FBitmapList.Items[ListBox.ItemIndex];
  722.       ShowModal;
  723.    finally
  724.       Image.Free;
  725.       Panel.Free;
  726.       Form.Free;
  727.    end;
  728. end;
  729. {-- TMMBitmapListEditor -------------------------------------------------------}
  730. procedure TMMBitmapListEditor.PreviewKeyPress(Sender: TObject; var Key: Char);
  731. begin
  732.   if Key = #27 then TForm(Sender).Close;
  733. end;
  734. {-- TMMBitmapListEditor -------------------------------------------------------}
  735. procedure TMMBitmapListEditor.WMSizing(var Msg: TWMSizing);
  736.    function CalcMaxItems(aHeight: integer): integer;
  737.    begin
  738.       // liefert die f黵 aHeight maximal m鰃lichen Tracks
  739.       Result := Max((aHeight-NonClientHeight-MenuHeight-ClientPanel.Top-ListHeader.Height-2) div ListBox.ItemHeight,1);
  740.    end;
  741.    function CalcClientHeight(NumItems: integer): integer;
  742.    begin
  743.       // liefert die ben鰐igte ClientH鰄e f黵 NumTracks
  744.       Result := ((NumItems*ListBox.ItemHeight)+NonClientHeight+MenuHeight+ClientPanel.Top+ListHeader.Height+2);
  745.    end;
  746. begin
  747.    // The WM_SIZING message is sent to a window that the user is resizing.
  748.    // By processing this message, an application can monitor the size and
  749.    // position of the drag rectangle and, if needed, change its size or
  750.    // position.
  751.    with Msg.lpRect^ do
  752.    case Msg.fwSide of
  753.       WMSZ_BOTTOM,              // Bottom edge
  754.       WMSZ_BOTTOMLEFT,         // Bottom-left corner
  755.       WMSZ_BOTTOMRIGHT:         // Bottom-right corner
  756.         Bottom := Top + CalcClientHeight(CalcMaxItems(Bottom-Top));
  757.       WMSZ_TOP,                 // Top edge
  758.       WMSZ_TOPLEFT,             // Top-left corner
  759.       WMSZ_TOPRIGHT:         // Top-right corner
  760.         Top := Bottom - CalcClientHeight(CalcMaxItems(Bottom-Top));
  761.    end;
  762.    Msg.Result := 1;       // Tell windows you have changed sizing
  763.    inherited;
  764. end;
  765. {-- TMMBitmapListEditor -------------------------------------------------------}
  766. procedure TMMBitmapListEditor.WMGetMinMaxInfo(Var Msg: TWMGetMinMaxInfo);
  767. begin
  768.    // Steuert die Maximal und Minimal H鰄e/Breite des Formulars
  769.    if not (csLoading in ComponentState) then
  770.    with Msg.MinMaxInfo^ do
  771.    begin
  772.       // Minimum width
  773.       ptMinTrackSize.X := 290;
  774.    end;
  775.    Msg.Result := 0;       // Tell windows you have changed minmaxinfo
  776.    inherited;
  777. end;
  778. {-- TMMBitmapListEditor -------------------------------------------------------}
  779. procedure TMMBitmapListEditor.FormResize(Sender: TObject);
  780. begin
  781.    ListBox.Invalidate;
  782. end;
  783. {-- TMMBitmapListEditor -------------------------------------------------------}
  784. procedure TMMBitmapListEditor.FormMouseMove(Sender: TObject;  Shift: TShiftState; X, Y: Integer);
  785. begin
  786.    if (ListBox.ItemIndex <= 0) then
  787.    begin
  788.       btnPaste.Enabled  := Clipboard.HasFormat(CF_BITMAP);
  789.       menPaste.Enabled  := btnPaste.Enabled;
  790.       btnReplace.Enabled:= btnPaste.Enabled and (ListBox.ItemIndex >= 0) and (ListBox.Items.Count > 0);
  791.       menReplace.Enabled:= btnReplace.Enabled;
  792.    end;
  793. end;
  794. {-- TMMBitmapListEditor -------------------------------------------------------}
  795. procedure TMMBitmapListEditor.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  796. begin
  797.    if (Key = VK_DELETE) then btnDeleteClick(nil);
  798. end;
  799. {-- TMMBitmapListEditor -------------------------------------------------------}
  800. procedure TMMBitmapListEditor.ButtonTimerTimer(Sender: TObject);
  801. begin
  802.    ButtonTimer.Interval := 50;
  803.    TMMBitmapButton(ButtonTimer.Tag).OnClick(nil);
  804. end;
  805. {-- TMMBitmapListEditor -------------------------------------------------------}
  806. procedure TMMBitmapListEditor.btnMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  807. begin
  808.    ButtonTimer.Tag := integer(Sender);
  809.    ButtonTimer.Interval := 400;
  810.    ButtonTimer.Enabled := True;
  811. end;
  812. {-- TMMBitmapListEditor -------------------------------------------------------}
  813. procedure TMMBitmapListEditor.btnMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  814. begin
  815.    ButtonTimer.Enabled := False;
  816. end;
  817. end.