MMBmpDlg.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:33k
- {========================================================================}
- {= (c) 1995-98 SwiftSoft Ronald Dittrich =}
- {========================================================================}
- {= All Rights Reserved =}
- {========================================================================}
- {= D 01099 Dresden = Fax.: +49 (0)351-8037944 =}
- {= Loewenstr.7a = info@swiftsoft.de =}
- {========================================================================}
- {= Actual versions on http://www.swiftsoft.de/mmtools.html =}
- {========================================================================}
- {= This code is for reference purposes only and may not be copied or =}
- {= distributed in any format electronic or otherwise except one copy =}
- {= for backup purposes. =}
- {= =}
- {= No Delphi Component Kit or Component individually or in a collection=}
- {= subclassed or otherwise from the code in this unit, or associated =}
- {= .pas, .dfm, .dcu, .asm or .obj files may be sold or distributed =}
- {= without express permission from SwiftSoft. =}
- {= =}
- {= For more licence informations please refer to the associated =}
- {= HelpFile. =}
- {========================================================================}
- {= $Date: 08.04.98 - 05:23:31 $ =}
- {========================================================================}
- unit MMBmpDlg;
- {$I COMPILER.INC}
- interface
- uses
- Windows,
- Messages,
- SysUtils,
- Classes,
- Graphics,
- Controls,
- Forms,
- Dialogs,
- StdCtrls,
- ExtCtrls,
- Clipbrd,
- Menus,
- MMObj,
- MMUtils,
- MMBmpLst,
- MMFill,
- MMCstDlg,
- MMBmpBtn;
- type
- TWMSizing = record
- Msg : Cardinal;
- fwSide: Longint;
- lpRect: PRect;
- Result: Longint;
- end;
- TMMUpdateMode = (umUp,umDown,umDelete);
- type
- TMMBitmapListEditor = class(TForm)
- MainMenu1: TMainMenu;
- File1: TMenuItem;
- Edit1: TMenuItem;
- About1: TMenuItem;
- Bevel1: TBevel;
- Panel1: TPanel;
- Bevel2: TBevel;
- Panel2: TPanel;
- ClientPanel: TPanel;
- ListHeader: THeader;
- Bevel3: TBevel;
- Panel4: TPanel;
- ListBox: TListBox;
- Bevel4: TBevel;
- menLoad: TMenuItem;
- menSave: TMenuItem;
- N1: TMenuItem;
- Exit1: TMenuItem;
- PicOpenDialog: TMMPictureOpenDialog;
- OpenDialog: TOpenDialog;
- SaveDialog: TSaveDialog;
- menCut: TMenuItem;
- menCopy: TMenuItem;
- menPaste: TMenuItem;
- menDelete: TMenuItem;
- N2: TMenuItem;
- menUp: TMenuItem;
- menDown: TMenuItem;
- N3: TMenuItem;
- menClear: TMenuItem;
- N4: TMenuItem;
- menAddList: TMenuItem;
- N5: TMenuItem;
- menSaveBMP: TMenuItem;
- PicSaveDialog: TMMPictureSaveDialog;
- MMBitmapList1: TMMBitmapList;
- btnAdd: TMMBitmapButton;
- btnAddMultiple: TMMBitmapButton;
- btnDelete: TMMBitmapButton;
- btnClear: TMMBitmapButton;
- btnUp: TMMBitmapButton;
- btnDown: TMMBitmapButton;
- btnLoad: TMMBitmapButton;
- btnSave: TMMBitmapButton;
- btnCut: TMMBitmapButton;
- btnCopy: TMMBitmapButton;
- btnPaste: TMMBitmapButton;
- btnHelp: TMMBitmapButton;
- bnOK: TMMBitmapButton;
- btnReplace: TMMBitmapButton;
- menReplace: TMenuItem;
- ButtonTimer: TTimer;
- procedure btnOKClick(Sender: TObject);
- procedure About1Click(Sender: TObject);
- procedure menLoadClick(Sender: TObject);
- procedure menSaveClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure ListBoxDrawItem(Control: TWinControl; Index: Integer;
- Rect: TRect; State: TOwnerDrawState);
- procedure ListHeaderSized(Sender: TObject; ASection, AWidth: Integer);
- procedure btnClearClick(Sender: TObject);
- procedure btnDeleteClick(Sender: TObject);
- procedure btnAddClick(Sender: TObject);
- procedure btnAddMultiClick(Sender: TObject);
- procedure btnUpClick(Sender: TObject);
- procedure btnDownClick(Sender: TObject);
- procedure btnCutClick(Sender: TObject);
- procedure btnCopyClick(Sender: TObject);
- procedure btnPasteClick(Sender: TObject);
- procedure menAddListClick(Sender: TObject);
- procedure ListBoxDblClick(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure menSaveBMPClick(Sender: TObject);
- procedure PreviewKeyPress(Sender: TObject; var Key: Char);
- procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
- procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
- procedure FormResize(Sender: TObject);
- procedure btnReplaceClick(Sender: TObject);
- procedure ButtonTimerTimer(Sender: TObject);
- procedure btnMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- procedure btnMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- private
- FBitmaplist: TMMBitmapList;
- FOrigList : TMMBitmapList;
- FUpdateIDs : Boolean;
- procedure BitmapListChanged(Sender: TObject);
- procedure SetBitmapList(List: TMMBitmapList);
- procedure UpdateListBox(Index: integer);
- procedure UpdateControls;
- procedure WMSizing(var Msg: TWMSizing); message WM_SIZING;
- procedure WMGetMinMaxInfo(Var Msg: TWMGetMinMaxInfo); message WM_GETMINMAXINFO;
- procedure UpdateBitmapIDs(Index: integer; Mode: TMMUpdateMode);
- public
- property BitmapList: TMMBitmapList read FBitmapList write SetBitmapList;
- end;
- var
- MMBitmapListEditor: TMMBitmapListEditor;
- implementation
- {$R *.DFM}
- uses
- TypInfo,
- MMAbout;
- {== TMMBitmapListEditor =======================================================}
- procedure TMMBitmapListEditor.FormCreate(Sender: TObject);
- begin
- {$IFDEF BUILD_ACTIVEX}
- MMBitmapList1.Left := -50;
- SetDesigning(False);
- {$ENDIF}
- FUpdateIDs := False;
- Icon.Handle := LoadResIcon(icoMMTools);
- FBitmapList := TMMBitmapList.Create(Self);
- FBitmapList.OnChange := BitmapListChanged;
- UpdateControls;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.FormDestroy(Sender: TObject);
- begin
- FBitmapList.Free;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- if (ModalResult = mrOK) and (FOrigList <> nil) then
- begin
- FOrigList.Assign(FBitmapList)
- end;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.SetBitmapList(List: TMMBitmapList);
- begin
- FOrigList := List;
- FBitmapList.Assign(List);
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.UpdateBitmapIDs(Index: integer; Mode: TMMUpdateMode);
- var
- Comps: TStringList;
- Form: TCustomForm;
- i,idx,Value: integer;
- PropInfo: PPropInfo;
- nGlyphs: integer;
- begin
- if FUpdateIDs then
- begin
- Form := TCustomForm(FOrigList.Owner);
- if (Form <> nil) then
- begin
- Comps := TStringList.Create;
- for i := 0 to Form.ComponentCount-1 do
- begin
- PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'NumGlyphs');
- if (PropInfo <> nil) then
- begin
- Value := GetOrdProp(Form.Components[i], PropInfo);
- Comps.AddObject(Form.Components[i].Name+' NumGlyphs',Pointer(Value));
- end;
- PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'NumThumbGlyphs');
- if (PropInfo <> nil) then
- begin
- Value := GetOrdProp(Form.Components[i], PropInfo);
- Comps.AddObject(Form.Components[i].Name+' NumThumbGlyphs',Pointer(Value));
- end;
- end;
- //FOrigList.Assign(FBitmapList);
- case Mode of
- umUp: begin
- for i := 0 to Form.ComponentCount-1 do
- begin
- PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapList');
- if (PropInfo <> nil) then
- begin
- if Pointer(GetOrdProp(Form.Components[i], PropInfo)) = Pointer(FOrigList) then
- begin
- PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapIndex');
- if (PropInfo <> nil) then
- begin
- Value := GetOrdProp(Form.Components[i], PropInfo);
- if (Value = Index) then
- SetOrdProp(Form.Components[i],PropInfo,Index-1)
- else if (Value = Index-1) then
- SetOrdProp(Form.Components[i],PropInfo,Index);
- end;
- PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapThumbIndex');
- if (PropInfo <> nil) then
- begin
- Value := GetOrdProp(Form.Components[i], PropInfo);
- if (Value = Index) then
- SetOrdProp(Form.Components[i],PropInfo,Index-1)
- else if (Value = Index-1) then
- SetOrdProp(Form.Components[i],PropInfo,Index);
- end;
- PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapBackIndex');
- if (PropInfo <> nil) then
- begin
- Value := GetOrdProp(Form.Components[i], PropInfo);
- if (Value = Index) then
- SetOrdProp(Form.Components[i],PropInfo,Index-1)
- else if (Value = Index-1) then
- SetOrdProp(Form.Components[i],PropInfo,Index);
- end;
- end;
- end;
- end;
- end;
- umDown: begin
- for i := 0 to Form.ComponentCount-1 do
- begin
- PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapList');
- if (PropInfo <> nil) then
- begin
- if Pointer(GetOrdProp(Form.Components[i], PropInfo)) = Pointer(FOrigList) then
- begin
- PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapIndex');
- if (PropInfo <> nil) then
- begin
- Value := GetOrdProp(Form.Components[i], PropInfo);
- if (Value = Index) then
- SetOrdProp(Form.Components[i],PropInfo,Index+1)
- else if (Value = Index+1) then
- SetOrdProp(Form.Components[i],PropInfo,Index);
- end;
- PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapThumbIndex');
- if (PropInfo <> nil) then
- begin
- Value := GetOrdProp(Form.Components[i], PropInfo);
- if (Value = Index) then
- SetOrdProp(Form.Components[i],PropInfo,Index+1)
- else if (Value = Index+1) then
- SetOrdProp(Form.Components[i],PropInfo,Index);
- end;
- PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapBackIndex');
- if (PropInfo <> nil) then
- begin
- Value := GetOrdProp(Form.Components[i], PropInfo);
- if (Value = Index) then
- SetOrdProp(Form.Components[i],PropInfo,Index+1)
- else if (Value = Index+1) then
- SetOrdProp(Form.Components[i],PropInfo,Index);
- end;
- end;
- end;
- end;
- end;
- umDelete: begin
- for i := 0 to Form.ComponentCount-1 do
- begin
- PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapList');
- if (PropInfo <> nil) then
- begin
- if Pointer(GetOrdProp(Form.Components[i], PropInfo)) = Pointer(FOrigList) then
- begin
- PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapIndex');
- if (PropInfo <> nil) then
- begin
- Value := GetOrdProp(Form.Components[i], PropInfo);
- if (Value > Index) then
- SetOrdProp(Form.Components[i],PropInfo,Value-1);
- end;
- PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapThumbIndex');
- if (PropInfo <> nil) then
- begin
- Value := GetOrdProp(Form.Components[i], PropInfo);
- if (Value > Index) then
- SetOrdProp(Form.Components[i],PropInfo,Value-1);
- end;
- PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapBackIndex');
- if (PropInfo <> nil) then
- begin
- Value := GetOrdProp(Form.Components[i], PropInfo);
- if (Value > Index) then
- SetOrdProp(Form.Components[i],PropInfo,Value-1);
- end;
- end;
- end;
- end;
- end;
- end;
- for i := 0 to Form.ComponentCount-1 do
- begin
- PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'NumGlyphs');
- if (PropInfo <> nil) then
- begin
- idx := Comps.IndexOf(Form.Components[i].Name+' NumGlyphs');
- if (idx >= 0) then
- begin
- SetOrdProp(Form.Components[i], PropInfo, integer(Comps.Objects[idx]));
- end;
- end;
- PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'NumThumbGlyphs');
- if (PropInfo <> nil) then
- begin
- idx := Comps.IndexOf(Form.Components[i].Name+' NumThumbGlyphs');
- if (idx >= 0) then
- begin
- SetOrdProp(Form.Components[i], PropInfo, integer(Comps.Objects[idx]));
- end;
- end;
- end;
- Comps.Free;
- end;
- end;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.BitmapListChanged(Sender: TObject);
- begin
- UpdateListBox(ListBox.ItemIndex);
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.UpdateListBox(Index: integer);
- var
- i: integer;
- function GetRefCount(idx: integer): integer;
- var
- Form: TCustomForm;
- i: integer;
- PropInfo: PPropInfo;
- begin
- Result := 0;
- if FUpdateIDs then
- begin
- Form := TCustomForm(FOrigList.Owner);
- if (Form <> nil) then
- begin
- for i := 0 to Form.ComponentCount-1 do
- begin
- PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapList');
- if (PropInfo <> nil) then
- begin
- if Pointer(GetOrdProp(Form.Components[i], PropInfo)) = Pointer(FOrigList) then
- begin
- PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapIndex');
- if (PropInfo <> nil) then
- begin
- if (GetOrdProp(Form.Components[i], PropInfo) = Idx) then inc(Result);
- end;
- PropInfo := GetPropInfo(Form.Components[i].ClassInfo,'BitmapThumbIndex');
- if (PropInfo <> nil) then
- begin
- if (GetOrdProp(Form.Components[i], PropInfo) = Idx) then inc(Result);
- end;
- end;
- end;
- end;
- end;
- end;
- end;
- begin
- ListBox.Items.BeginUpdate;
- try
- ListBox.Clear;
- for i := 0 to FBitmapList.Count-1 do
- begin
- ListBox.Items.AddObject(IntToStr(i),Pointer(GetRefCount(i)));
- end;
- if (Index < 0) then
- Index := 0;
- if (Index >= ListBox.Items.Count) then
- Index := ListBox.Items.Count-1;
- if (Index < ListBox.Items.Count) then
- ListBox.ItemIndex := Index;
- UpdateControls;
- finally
- ListBox.Items.EndUpdate;
- end;
- end;
- {-- TFindMarkerForm -----------------------------------------------------}
- procedure TMMBitmapListEditor.ListBoxDrawItem(Control: TWinControl;
- Index: Integer; Rect: TRect;
- State: TOwnerDrawState);
- var
- R: TRect;
- S: string;
- C: array[0..255] of Char;
- X,Y,iWidth,iHeight,W: integer;
- Factor: Double;
- begin
- with ListBox.Canvas do
- begin
- FillRect(Rect);
- inc(Rect.Top);
- dec(Rect.Bottom);
- R := Rect;
- { draw the ID }
- S := ListBox.Items[Index];
- R.Right := ListHeader.SectionWidth[0];
- X := (R.Left + ((R.Right-R.Left) div 2)) - TextWidth(S) div 2;
- Y := (R.Top + ((R.Bottom-R.Top) div 2)) - TextHeight(S) div 2;
- ExtTextOut(ListBox.Canvas.Handle, X, Y, ETO_CLIPPED or
- ETO_OPAQUE, @R, StrPCopy(C, S), Length(S), nil);
- R.Left := R.Right;
- R.Right := Rect.Right;
- { draw the RefCount }
- S := IntToStr(integer(ListBox.Items.Objects[Index]));
- R.Right := ListHeader.SectionWidth[0]+ListHeader.SectionWidth[1];
- X := (R.Left + ((R.Right-R.Left) div 2)) - TextWidth(S) div 2;
- Y := (R.Top + ((R.Bottom-R.Top) div 2)) - TextHeight(S) div 2;
- ExtTextOut(ListBox.Canvas.Handle, X, Y, ETO_CLIPPED or
- ETO_OPAQUE, @R, StrPCopy(C, S), Length(S), nil);
- R.Left := R.Right;
- R.Right := Rect.Right;
- inc(R.Top);
- dec(R.Bottom);
- iWidth := FBitmapList.Items[index].Width;
- iHeight := FBitmapList.Items[index].Height;
- if (iWidth < (R.Right-R.Left)) and
- (iHeight < (R.Bottom-R.Top)) then
- begin
- R.Right := R.Left+iWidth;
- R.Top := R.Top + (((R.Bottom-R.Top)-iHeight) div 2);
- R.Bottom:= R.Top + iHeight;
- end
- else
- begin
- if (iWidth <= iHeight) then
- begin
- if (iHeight > R.Bottom-R.Top) then
- begin
- Factor := (R.Bottom - R.Top)/iHeight;
- iWidth := Trunc(iWidth * Factor);
- iHeight := R.Bottom-R.Top;
- end;
- Factor := Min(R.Bottom-R.Top,iHeight)/iHeight;
- iWidth := Trunc(iWidth * Factor);
- if (iWidth > R.Right-R.Left) then
- begin
- Factor := (R.Right - R.Left)/iWidth;
- iHeight := Trunc(iHeight * Factor);
- iWidth := R.Right-R.Left;
- R.Top := R.Top + (((R.Bottom-R.Top)-iHeight) div 2);
- R.Bottom := R.Top + iHeight;
- end;
- R.Right := R.Left + iWidth;
- end
- else
- begin
- if (iHeight > R.Bottom-R.Top) then
- begin
- Factor := (R.Bottom - R.Top)/iHeight;
- iWidth := Trunc(iWidth * Factor);
- iHeight := R.Bottom-R.Top;
- end;
- W := Min(R.Right-R.Left,iWidth);
- Factor := W/iWidth;
- iHeight := Trunc(iHeight * Factor);
- R.Top := R.Top + (((R.Bottom-R.Top)-iHeight) div 2);
- R.Bottom := R.Top + iHeight;
- R.Right := R.Left+W;
- end
- end;
- StretchDraw(R, FBitmapList.Items[index]);
- UpdateControls;
- end;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.ListHeaderSized(Sender: TObject; ASection, AWidth: Integer);
- begin
- ListBox.Invalidate;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.UpdateControls;
- begin
- with ListBox do
- begin
- btnDelete.Enabled := (FBitmapList.Count > 0) and (ListBox.ItemIndex >= 0);
- menDelete.Enabled := btnDelete.Enabled;
- btnClear.Enabled := (FBitmapList.Count > 0);
- menClear.Enabled := btnClear.Enabled;
- btnSave.Enabled := btnClear.Enabled;
- menSave.Enabled := btnSave.Enabled;
- btnUp.Enabled := (Items.Count > 0) and (ItemIndex > 0);
- menUp.Enabled := btnUp.Enabled;
- btnDown.Enabled := (Items.Count > 0) and (ItemIndex < Items.Count-1);
- menDown.Enabled := btnDown.Enabled;
- btnCut.Enabled := btnDelete.Enabled;
- menCut.Enabled := btnCut.Enabled;
- btnCopy.Enabled := btnDelete.Enabled;
- menCopy.Enabled := btnCopy.Enabled;
- menSaveBMP.Enabled:= btnCopy.Enabled;
- btnPaste.Enabled := Clipboard.HasFormat(CF_BITMAP);
- menPaste.Enabled := btnPaste.Enabled;
- btnReplace.Enabled:= btnPaste.Enabled and (ListBox.ItemIndex >= 0) and (ListBox.Items.Count > 0);
- menReplace.Enabled:= btnReplace.Enabled;
- end;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.btnOKClick(Sender: TObject);
- begin
- ModalResult := mrOK;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.About1Click(Sender: TObject);
- begin
- Show_AboutBox(0);
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.menLoadClick(Sender: TObject);
- begin
- if OpenDialog.Execute then
- FBitmapList.LoadFromFile(OpenDialog.FileName);
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.menSaveClick(Sender: TObject);
- var
- S: string;
- begin
- if SaveDialog.Execute then
- begin
- S := ChangeFileExt(SaveDialog.FileName,'.~bm');
- DeleteFile(S);
- RenameFile(SaveDialog.FileName,S);
- FBitmapList.SaveToFile(SaveDialog.FileName);
- end;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.menAddListClick(Sender: TObject);
- begin
- if OpenDialog.Execute then
- FBitmapList.AddListFromFile(OpenDialog.FileName);
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.menSaveBMPClick(Sender: TObject);
- begin
- if PicSaveDialog.Execute then
- begin
- FBitmapList[ListBox.ItemIndex].SaveToFile(PicSaveDialog.FileName);
- end;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.btnAddClick(Sender: TObject);
- begin
- PicOpenDialog.Options := PicOpenDialog.Options - [ofAllowMultiSelect];
- if PicOpenDialog.Execute then
- begin
- FBitmapList.AddFromFile(PicOpenDialog.FileName);
- end;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.btnAddMultiClick(Sender: TObject);
- var
- i: integer;
- begin
- PicOpenDialog.Options := PicOpenDialog.Options + [ofAllowMultiSelect];
- if PicOpenDialog.Execute then
- begin
- ListBox.Items.BeginUpdate;
- try
- for i := 0 to PicOpenDialog.Files.Count-1 do
- FBitmapList.AddFromFile(PicOpenDialog.Files[i]);
- finally
- ListBox.Items.EndUpdate;
- end;
- end;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.btnClearClick(Sender: TObject);
- begin
- FBitmapList.Clear;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.btnDeleteClick(Sender: TObject);
- begin
- if btnDelete.Enabled then
- begin
- FBitmapList.Delete(ListBox.ItemIndex);
- UpdateBitmapIDs(ListBox.ItemIndex,umDelete);
- end;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.btnUpClick(Sender: TObject);
- begin
- if (ListBox.ItemIndex > 0) then
- begin
- FBitmapList.Move(ListBox.ItemIndex,ListBox.ItemIndex-1);
- UpdateBitmapIDs(ListBox.ItemIndex,umUp);
- ListBox.ItemIndex := ListBox.ItemIndex-1;
- end
- else ButtonTimer.Enabled := False;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.btnDownClick(Sender: TObject);
- begin
- if (ListBox.ItemIndex < ListBox.Items.Count-1) then
- begin
- FBitmapList.Move(ListBox.ItemIndex,ListBox.ItemIndex+1);
- UpdateBitmapIDs(ListBox.ItemIndex,umDown);
- ListBox.ItemIndex := ListBox.ItemIndex+1;
- end
- else ButtonTimer.Enabled := False;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.btnCutClick(Sender: TObject);
- begin
- btnCopyClick(nil);
- btnDeleteClick(nil);
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.btnCopyClick(Sender: TObject);
- begin
- Clipboard.Assign(FBitmapList.Items[ListBox.ItemIndex]);
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.btnPasteClick(Sender: TObject);
- var
- BMP: TBitmap;
- idx: integer;
- begin
- BMP := TBitmap.Create;
- try
- idx := ListBox.ItemIndex;
- BMP.Assign(Clipboard);
- FBitmapList.Insert(idx,BMP)
- finally
- BMP.Free;
- end;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.btnReplaceClick(Sender: TObject);
- var
- BMP: TBitmap;
- idx: integer;
- begin
- BMP := TBitmap.Create;
- try
- idx := ListBox.ItemIndex;
- BMP.Assign(Clipboard);
- FBitmapList.Delete(idx);
- FBitmapList.Insert(idx,BMP)
- finally
- BMP.Free;
- end;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.ListBoxDblClick(Sender: TObject);
- var
- Form: TForm;
- Panel: TPanel;
- Image: TImage;
- begin
- Panel := nil;
- Image := nil;
- Form := TForm.Create(Self);
- with Form do
- try
- BorderStyle := bsSizeToolWin;
- Caption := 'Preview';
- Position := poScreenCenter;
- PixelsPerInch := 96;
- ClientWidth := FBitmapList.Items[ListBox.ItemIndex].Width+10;
- ClientHeight := FBitmapList.Items[ListBox.ItemIndex].Height+10;
- OnKeyPress := PreviewKeyPress;
- Panel := TPanel.Create(Form);
- Panel.Parent := Form;
- Panel.Align := alClient;
- Panel.BevelOuter := bvNone;
- Panel.BorderWidth := 5;
- Panel.Color := clWindow;
- Image := TImage.Create(Panel);
- Image.Parent := Panel;
- Image.Align := alClient;
- Image.AutoSize := True;
- Image.Center := True;
- Image.Stretch := True;
- Image.Picture.Bitmap := FBitmapList.Items[ListBox.ItemIndex];
- ShowModal;
- finally
- Image.Free;
- Panel.Free;
- Form.Free;
- end;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.PreviewKeyPress(Sender: TObject; var Key: Char);
- begin
- if Key = #27 then TForm(Sender).Close;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.WMSizing(var Msg: TWMSizing);
- function CalcMaxItems(aHeight: integer): integer;
- begin
- // liefert die f黵 aHeight maximal m鰃lichen Tracks
- Result := Max((aHeight-NonClientHeight-MenuHeight-ClientPanel.Top-ListHeader.Height-2) div ListBox.ItemHeight,1);
- end;
- function CalcClientHeight(NumItems: integer): integer;
- begin
- // liefert die ben鰐igte ClientH鰄e f黵 NumTracks
- Result := ((NumItems*ListBox.ItemHeight)+NonClientHeight+MenuHeight+ClientPanel.Top+ListHeader.Height+2);
- end;
- begin
- // The WM_SIZING message is sent to a window that the user is resizing.
- // By processing this message, an application can monitor the size and
- // position of the drag rectangle and, if needed, change its size or
- // position.
- with Msg.lpRect^ do
- case Msg.fwSide of
- WMSZ_BOTTOM, // Bottom edge
- WMSZ_BOTTOMLEFT, // Bottom-left corner
- WMSZ_BOTTOMRIGHT: // Bottom-right corner
- Bottom := Top + CalcClientHeight(CalcMaxItems(Bottom-Top));
- WMSZ_TOP, // Top edge
- WMSZ_TOPLEFT, // Top-left corner
- WMSZ_TOPRIGHT: // Top-right corner
- Top := Bottom - CalcClientHeight(CalcMaxItems(Bottom-Top));
- end;
- Msg.Result := 1; // Tell windows you have changed sizing
- inherited;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.WMGetMinMaxInfo(Var Msg: TWMGetMinMaxInfo);
- begin
- // Steuert die Maximal und Minimal H鰄e/Breite des Formulars
- if not (csLoading in ComponentState) then
- with Msg.MinMaxInfo^ do
- begin
- // Minimum width
- ptMinTrackSize.X := 290;
- end;
- Msg.Result := 0; // Tell windows you have changed minmaxinfo
- inherited;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.FormResize(Sender: TObject);
- begin
- ListBox.Invalidate;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
- begin
- if (ListBox.ItemIndex <= 0) then
- begin
- btnPaste.Enabled := Clipboard.HasFormat(CF_BITMAP);
- menPaste.Enabled := btnPaste.Enabled;
- btnReplace.Enabled:= btnPaste.Enabled and (ListBox.ItemIndex >= 0) and (ListBox.Items.Count > 0);
- menReplace.Enabled:= btnReplace.Enabled;
- end;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
- begin
- if (Key = VK_DELETE) then btnDeleteClick(nil);
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.ButtonTimerTimer(Sender: TObject);
- begin
- ButtonTimer.Interval := 50;
- TMMBitmapButton(ButtonTimer.Tag).OnClick(nil);
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.btnMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- begin
- ButtonTimer.Tag := integer(Sender);
- ButtonTimer.Interval := 400;
- ButtonTimer.Enabled := True;
- end;
- {-- TMMBitmapListEditor -------------------------------------------------------}
- procedure TMMBitmapListEditor.btnMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- begin
- ButtonTimer.Enabled := False;
- end;
- end.