⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dialogresourceform.pas

📁 學習資料網上下載
💻 PAS
📖 第 1 页 / 共 2 页
字号:
 *----------------------------------------------------------------------*)
procedure TfmDialogResource.FillPropertyBox(info: TControlInfo; reset : boolean);
var
  kind : TPropertyKind;
  i, j : Integer;
  prop : TPropertyListProperty;
  propName : string;
  idx : Integer;
  val : Variant;
begin

  case tcPropertyKind.TabIndex of       // Get the property kind
    1 : kind := pkStyle;
    2 : kind := pkExtended
    else
      kind := pkGeneral
  end;

  idx := PropertyListBox1.SelectedPropertyNo;

  PropertyListBox1.Properties.Clear;
  PropertyListBox1.Properties.BeginUpdate;
  try
    for i := 0 to info.PropertyCount [kind] - 1 do
    begin
                                        // Add each property.

      prop := TPropertyListProperty (PropertyListBox1.Properties.Add);
      propName := info.PropertyName [kind, i];
      prop.PropertyName := propName;
      val := info.PropertyValue [kind, i];
      prop.Enabled := not VarIsEmpty (val);

      case info.PropertyType [kind, i] of
        ptString  : prop.PropertyType := cmpPropertyListBox.ptString;
        ptInteger : prop.PropertyType := cmpPropertyListBox.ptInteger;
        ptBoolean : prop.PropertyType := cmpPropertyListBox.ptBoolean;
        ptSpecial :
          begin
            prop.PropertyType := cmpPropertyListBox.ptSpecial;
            prop.OnSpecialButtonClick := DoSpecialButtonClick
          end;

        ptEnum    :
          begin
                                        // Add enumerated property values
            prop.PropertyType := cmpPropertyListBox.ptEnum;
            prop.EnumValues.Clear;
            prop.EnumValues.BeginUpdate;
            try
              for j := 0 to info.PropertyEnumCount [kind, i] - 1 do
                prop.EnumValues.Add (info.PropertyEnumName [kind, i, j])
            finally
              prop.EnumValues.EndUpdate
            end
          end
      end;
                                        // Set the property value
      if not VarIsEmpty (val) then
        prop.PropertyValue := val
    end
  finally
    PropertyListBox1.Properties.EndUpdate
  end;

  if reset then
                                        // Select first property
    PropertyListBox1.SelectedPropertyNo := 0
  else
    PropertyListBox1.SelectedPropertyNo := idx;
end;

(*----------------------------------------------------------------------*
 | TfmDialogResource.tcPropertyKindChange                               |
 |                                                                      |
 | A different propery tab has been selected.  Display the appropriate  |
 | properties.                                                          |
 *----------------------------------------------------------------------*)
procedure TfmDialogResource.tcPropertyKindChange(Sender: TObject);
var
  info : TControlInfo;
begin
  info := DialogEditor1.SelectedControl;

  FillPropertyBox (info, True)
end;

(*----------------------------------------------------------------------*
 | TfmDialogResource.SaveResource                                       |
 |                                                                      |
 | Get and save a new resource template from the editor.                |
 *----------------------------------------------------------------------*)
procedure TfmDialogResource.SaveResource(const undoDetails: string);
begin
  AddUndoEntry (undoDetails);

  fDetails.Data.Clear;
  DialogEditor1.SaveToStream (fDetails.Data);
end;

(*----------------------------------------------------------------------*
 | TfmDialogResource.DialogEditor1ControlResize                         |
 |                                                                      |
 | Update the display when a control is resized by dragging             |
 *----------------------------------------------------------------------*)
procedure TfmDialogResource.DialogEditor1ControlResize(Sender: TObject;
  ctrlInfo: TControlInfo; newRect: TRect);
begin
  FillPropertyBox (ctrlInfo, False);
  SaveResource (rstResize);
end;

(*----------------------------------------------------------------------*
 | TfmDialogResource.DialogEditor1ControlPropertyChange                 |
 |                                                                      |
 | Update the property display when a control property changes          |
 | 'magically' - eg, when setting Show Maximize Box, automagically      |
 | changes 'Show System Menu'                                           |
 *----------------------------------------------------------------------*)
procedure TfmDialogResource.DialogEditor1ControlPropertyChange(
  Sender: TObject; ctrlInfo: TControlInfo);
begin
  FillPropertyBox (ctrlInfo, False);
end;

procedure TfmDialogResource.FormShow(Sender: TObject);
var
  i : Integer;
  dc : TDropControl;
  ic : TControlInfoClass;
begin
  inherited;
  Ruler1.Left := DialogEditor1.Left + DialogEditor1.Margin;
  Ruler2.Top := DialogEditor1.Top + DialogEditor1.Margin - Panel3.Height;
  Ruler1.Width := DialogEditor1.Width - 2 * DialogEditor1.Margin;
  Ruler2.Height := DialogEditor1.Height - 2 * DialogEditor1.Margin;
  fPCWidth := pnlPalette.Width;
  pnlPalette.ManualDock (SizingPageControl1, Nil, alNone);

  for i := 0 to ToolBar1.ButtonCount - 1 do
  begin
    dc := TDropControl (ToolBar1.Buttons [i].Tag);

    if dc <> drNone then
    begin
      ic := GetControlInfoClass (dc);
      if Assigned (ic) then
        ToolBar1.Buttons [i].Hint := ic.GetDescription
      else
        ToolBar1.Buttons [i].ShowHint := False
    end
    else
      ToolBar1.Buttons [i].ShowHint := False
  end;
end;

procedure TfmDialogResource.SizingPageControl1UnDock(Sender: TObject;
  Client: TControl; NewTarget: TWinControl; var Allow: Boolean);
begin
  if SizingPageControl1.PageCount = 1 then
    SizingPageControl1.Width := 0;
end;

procedure TfmDialogResource.SizingPageControl1DockDrop(Sender: TObject;
  Source: TDragDockObject; X, Y: Integer);
var
  i : Integer;
begin
  with SizingPageControl1 do
  begin
    for i := 0 to PageCount - 1 do
      Pages [i].Caption := TPanel (Pages [i].Controls [0]).Caption;

    Width := fPCWidth + 8;      // Restore the width to it's original setting
                                // - we've got at least one tab.
  end
end;

procedure TfmDialogResource.ToolButton2Click(Sender: TObject);
begin
  DialogEditor1.DropControl := TDropControl ((Sender as TToolButton).Tag)
end;

procedure TfmDialogResource.DialogEditor1DesignModeDropControl(
  sender: TObject; x, y: Integer; ctrl: TControlInfo);
var
  idx : Integer;
begin
  idx := cbControls.Items.AddObject (GetInfoDescription (ctrl), ctrl);
  cbControls.ItemIndex := idx;
  SaveResource (rstAddControl);
  ToolButton1.Down := True;
  DialogEditor1.SelectedControl := ctrl
end;

function TfmDialogResource.GetCanDelete: Boolean;
begin
  Result := Assigned (DialogEditor1.SelectedControl);
end;

procedure TfmDialogResource.EditDelete;
begin
  DialogEditor1.DeleteControl (DialogEditor1.SelectedControl);
end;

procedure TfmDialogResource.DialogEditor1DeleteControl(Sender: TObject;
  ctrl: TControlInfo);
var
  i : Integer;
begin
  i := 0;
  while i < cbControls.Items.Count do
    if cbControls.Items.Objects [i] = ctrl then
      cbControls.Items.Delete (i)
    else
      Inc (i);

  SaveResource (rstDeleteControl)
end;

procedure TfmDialogResource.ToolButton1Click(Sender: TObject);
begin
  DialogEditor1.DropControl := drNone
end;

procedure TfmDialogResource.DialogEditor1GetControlImage(Sender: TObject;
  tp: Integer; const id: string; var Handle: HGDIOBJ);
var
  details : TResourceDetails;
  picture : TPicture;
  resType : Integer;
begin
  if tp = IMAGE_ICON then
    resType := Integer (RT_GROUP_ICON)
  else
    if tp = IMAGE_BITMAP then
      resType := Integer (RT_BITMAP)
    else
      resType := 0;

  details := fDetails.Parent.FindResource (IntToStr (resType), id, fDetails.ResourceLanguage);
  if Assigned (details) then
  begin
    picture := TPicture.Create;
    try
      if details is TIconGroupResourceDetails then
      begin
        TIconGroupResourceDetails (details).GetImage (picture);
        Handle := TExIcon (picture.graphic).ReleaseHandle
      end
      else
        if details is TBitmapResourceDetails then
        begin
          TBitmapResourceDetails (details).GetImage (picture);
          Handle := TBitmap (picture.Graphic).ReleaseHandle
        end
    finally
      picture.Free
    end
  end
end;

procedure TfmDialogResource.DoSpecialButtonClick(Sender: TObject);
var
  prop : TPropertyListProperty;
  st : string;
begin
  prop := TPropertyListProperty (Sender);

  st := prop.PropertyName;

  if st = 'Font' then
  begin
    FontDialog1.Font.Handle := DialogEditor1.FontHandle;
    if FontDialog1.Execute then
    begin
      DialogEditor1.SetTemplateFont (FontDialog1.Font);
      SaveResource (rstSetFont);
      DialogEditor1.ResourceTemplate := fDetails.Data.Memory;
    end
  end
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -