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

📄 wwricheditbar.pas

📁 胜天进销存源码,国产优秀的进销存
💻 PAS
📖 第 1 页 / 共 3 页
字号:
end;

procedure TwwRichBarFrame.CopyButtonClick(Sender: TObject);
begin
   Richedit1.CopyToClipboard;
end;

procedure TwwRichBarFrame.CutButtonClick(Sender: TObject);
begin
   Richedit1.CutToClipboard;
end;

procedure TwwRichBarFrame.FindButtonClick(Sender: TObject);
begin
   richedit1.ExecuteFindDialog;
end;

procedure TwwRichBarFrame.FontNameComboCloseUp(Sender: TwwDBComboBox;
  Select: Boolean);
begin
  if not Select then exit;
  SetRichEditFontName(FontNameCombo.Text);
  RichEdit1.SetFocus;
  RefreshControls;
end;

procedure TwwRichBarFrame.FontSizeComboCloseUp(Sender: TwwDBComboBox;
  Select: Boolean);
begin
   if not Select then exit;
   if FontSizeCombo.text='' then exit;
   RichEdit1.SelAttributes.Size:= StrToInt(FontSizeCombo.Text);
   RichEdit1.SetFocus;
   RefreshControls;
end;

procedure TwwRichBarFrame.HighlightButtonClick(Sender: TObject);
begin
  with (Sender as TToolButton) do begin
     if not Down then RichEdit1.SetTextBackgroundColor(-1)
     else RichEdit1.SetTextBackgroundColor(RichEdit1.HighlightColor);
  end;
  RefreshControls;

end;

procedure TwwRichBarFrame.Initialize;
var dragButton: TwwTrackIcon;
    i: integer;
    PixelsPerInch: integer;
begin

      wwRulerPanel:= TwwRulerPanel.create(self);

      with wwRulerPanel do begin
         RichEdit:= richedit1;
         ParentColor:=true;
         Parent:=RichEditBar;
         Top:= FormatBar.Top + FormatBar.Height + 10;
         PixelsPerInch:= Screen.PixelsPerInch;

//         PixelsPerInch:= GetDeviceCaps(DC, LOGPIXELSY);

         if PixelsPerInch>96 then Height:= 27
         else Height:= 25;

         //         align:= alTop;
         BevelOuter:= bvNone;
         wwRulerPanel.RulerRect:= Rect(6, 4, wwRulerPanel.Width-6, wwRulerPanel.Height-4); //RulerHeight);
      end;


      if RichEdit1.EffectiveEditWidth = rewPrinterSize then wwRulerPanel.UpdateSize(RichEdit1)
      else wwRulerPanel.Width:=  Width;

      wwRulerPanel.RulerRect:= Rect(6, 4, wwRulerPanel.Width-6,wwRulerPanel.Height-4); //RulerHeight);


      dragButton:= TwwTrackIcon.create(self);
      dragButton.parent:= wwRulerPanel;
      dragButton.BitmapName:= 'wwRulerUp';
      dragButton.MinValue:= wwRulerPanel.RulerRect.Left -
        ((dragButton.Width) div 2);
      dragButton.MaxValue:= wwRulerPanel.RulerRect.Right-(dragButton.Width div 2);
      dragButton.Left:= dragButton.MinValue;
      dragButton.Top:= wwRulerPanel.RulerRect.Bottom - dragButton.Height + 4;
      dragButton.OnEndDrag:= wwRulerPanel.UpdateRulerProp;
      wwRulerPanel.LeftDragButton:= dragButton;

      dragButton:= TwwTrackIcon.create(self);
      dragButton.parent:= wwRulerPanel;
      dragButton.BitmapName:= 'wwRulerUp';
      dragButton.MinValue:= wwRulerPanel.RulerRect.Left -
        ((dragButton.Width) div 2);
      dragButton.MaxValue:= wwRulerPanel.RulerRect.Right-(dragButton.Width div 2);
      dragButton.Left:= dragButton.MaxValue;
      dragButton.Top:= wwRulerPanel.RulerRect.Bottom - dragButton.Height + 4;
      dragButton.OnEndDrag:= wwRulerPanel.UpdateRulerProp;
      wwRulerPanel.RightDragButton:= dragButton;

      dragButton:= TwwTrackIcon.create(self);
      dragButton.parent:= wwRulerPanel;
      dragButton.BitmapName:= 'wwRulerDown';
      dragButton.MinValue:= wwRulerPanel.RulerRect.Left -
        ((dragButton.Width) div 2);
      dragButton.MaxValue:= wwRulerPanel.RulerRect.Right-(dragButton.Width div 2);
      dragButton.Left:= dragButton.MinValue+10;
      dragButton.Top:= wwRulerPanel.RulerRect.Top -2;
      dragButton.OnEndDrag:= wwRulerPanel.UpdateRulerProp;
      wwRulerPanel.FirstLineDragButton:= dragButton;

      wwRulerPanel.Align:= alNone;

      for i:= 0 to Screen.Fonts.Count-1 do begin
         if (RichEdit1.EffectiveEditWidth=rewWindowSize) or
           (Printer.Fonts.indexOf(Screen.Fonts[i])>=0) then
            FontNameCombo.Items.Add(Screen.Fonts[i]);
      end;


      RefreshControls;

     InitColorMenu;
    FCanvas := TCanvas.Create;
end;

procedure TwwRichBarFrame.ItalicButtonClick(Sender: TObject);
begin
  RichEdit1.SetStyleAttribute(fsItalic, not TempDown);
  RefreshControls;
end;

procedure TwwRichBarFrame.JustifyButtonClick(Sender: TObject);
begin
   richedit1.SetParaFormat([rpoAlignment],
      wwInternational.RichEdit.ParagraphDialog.AlignJustify,
      False, 0, 0, 0, 0, nil, 0, 0, 0, 0);
   RefreshControls;
end;

procedure TwwRichBarFrame.LeftButtonClick(Sender: TObject);
begin
  richedit1.Paragraph.Alignment:= taLeftJustify;
  RefreshControls;

end;

procedure TwwRichBarFrame.LoadButtonClick(Sender: TObject);
begin

  if OpenDialog1.Execute then
  begin
    RichEdit1.Lines.LoadFromFile(OpenDialog1.FileName);
    RichEdit1.SetFocus;
  end;


end;

procedure TwwRichBarFrame.NewButtonClick(Sender: TObject);
begin
   if MessageDlg(wwInternational.UserMessages.RichEditClearWarning,
                 mtConfirmation, [mbOK, mbCancel], 0)  <> mrOK then exit;
   richedit1.clear;
   richedit1.modified:= True;
end;

procedure TwwRichBarFrame.PasteButtonClick(Sender: TObject);
begin
   Richedit1.PasteFromClipboard;
end;

procedure TwwRichBarFrame.PrintButtonClick(Sender: TObject);
begin
   printdialog1.collate:= True;
   if printdialog1.execute then
   begin
         richedit1.Print(RichEdit1.PrintJobName);
   end

end;

procedure TwwRichBarFrame.SaveAsButtonClick(Sender: TObject);
begin
  if SaveDialog1.Execute then
  begin
    if FileExists(SaveDialog1.FileName) then
      if MessageDlg(Format('OK to overwrite %s', [SaveDialog1.FileName]),
        mtConfirmation, mbYesNoCancel, 0) <> idYes then Exit;
    if savedialog1.filterindex=2 then { 6/8/00 - Save as plain text }
    begin
      RichEdit1.plaintext:=true;
      RichEdit1.Lines.SaveToFile(SaveDialog1.FileName);
      RichEdit1.plaintext:=false;
    end
    else
      RichEdit1.Lines.SaveToFile(SaveDialog1.FileName);
  end;

end;

Procedure TwwRichBarFrame.SetRichEditFontName(Value: string);
var Format: TCharFormat;
begin
  if RichEdit1.selAttributes.Name=Value then exit;
  FillChar(Format, SizeOf(TCharFormat), 0);
  Format.cbSize := SizeOf(TCharFormat);
  with Format do
  begin
    dwMask:= CFM_FACE OR CFM_CHARSET;
    StrPLCopy(szFaceName, Value, SizeOf(szFaceName));
    bCharSet := RichEdit1.GetCharSetOfFontName(Value);
  end;
  SendMessage(RichEdit1.Handle, EM_SETCHARFORMAT, SCF_SELECTION, LPARAM(@Format));
end;

procedure TwwRichBarFrame.SpellButtonClick(Sender: TObject);
begin
   richedit1.MSWordSpellChecker;
end;

procedure TwwRichBarFrame.PrintPreviewButtonClick(Sender: TObject);
begin
  RichEdit1.PrintPreview;
end;

procedure TwwRichBarFrame.UnderlineButtonClick(Sender: TObject);
begin
  RichEdit1.SetStyleAttribute(fsUnderline, not TempDown);
  RefreshControls;

end;

procedure TwwRichBarFrame.UndoButtonClick(Sender: TObject);
begin
    SendMessage(RichEdit1.Handle, EM_UNDO, 0, 0);
    RefreshControls;

end;



function DrawText(Canvas: TCanvas;
   AText: string; ARect: TRect; Style: Integer): TRect;
const
  DT_DISABLED = $80000;
begin
  with Canvas do begin
  // Used by DrawText API Function when "Item" has focus.
  SetBkColor(Handle, ColorToRGB(Brush.Color));
  SetTextColor(Handle, ColorToRGB(Font.Color));

  Refresh;
  if (Style and DT_DISABLED <> 0) and (Style and DT_CALCRECT = 0) then
  begin
    Font.Color := clBtnHighlight;
    OffSetRect(ARect, 1, 1);
    Windows.DrawText(Handle, PChar(AText), Length(AText), ARect, Style);
    SetBkMode(Handle, TRANSPARENT);
    OffSetRect(ARect, -1, -1);
    Font.Color := clBtnShadow;
  end;
  Windows.DrawTextEx(Handle, PChar(AText), Length(AText), ARect, Style, nil);
  result := ARect;
  end;
end;


procedure TwwRichEditBar.WMCommand(var Message: TWMCommand);
var item: TMenuItem;
begin
   inherited;
   if (Message.NotifyCode = 0) and (RichEditBarFrame.PopupMenu1<>nil) then
   begin
      item:= RichEditBarFrame.PopupMenu1.FindItem(Message.itemID, fkCommand);
      if item<>nil then Item.Click;
   end
end;

procedure TwwRichEditBar.WMMeasureItem(var Message: TWMMeasureItem);
var Item: TMenuItem;
  function GetMenuFont: HFONT;
  var
    NonClientMetrics: TNonClientMetrics;
  begin
    NonClientMetrics.cbSize := sizeof(NonClientMetrics);
    if SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, @NonClientMetrics, 0) then
      Result := CreateFontIndirect(NonClientMetrics.lfMenuFont)
    else
      Result := GetStockObject(SYSTEM_FONT);
  end;
const
  VertPadding = 2;
  HorzPadding = 5;
begin
  inherited;
  if Message.MeasureItemStruct^.CtlType <> ODT_MENU then Exit;
  with Message.MeasureItemStruct^ do
  begin
    Item := TMenuItem(itemData);
    FCanvas.Handle := GetDC(0);
    FCanvas.Font.Handle := GetMenuFont;
    itemHeight := FCanvas.TextHeight(Item.Caption) + VertPadding;
    itemWidth := FCanvas.TextWidth(Item.Caption) + HorzPadding + ColorBoxWidth;
    FCanvas.Font.Handle := 0;
    ReleaseDC(0, FCanvas.Handle);
    FCanvas.Handle := 0;
  end;
end;

procedure TwwRichEditBar.WMDrawItem(var Message: TWMDrawItem);
const
  VertMargin = 2;
  HorzMargin = 3;
var
  Item: TMenuItem;
  ColorRect: TRect;
begin
  inherited;
  if Message.DrawItemStruct^.CtlType <> ODT_MENU then Exit;
  with Message.DrawItemStruct^ do
  begin
    FCanvas.Handle := hDC;
    Item := TMenuItem(ItemData);
    if ODS_SELECTED and itemState <> 0 then begin
      FCanvas.Brush.Color := clHighlight;
      FCanvas.Pen.Color := clHighlightText;
      FCanvas.Pen.Color := clBlack;
      FCanvas.Font.Color := clHighlightText;
    end else begin
      FCanvas.Brush.Color := clBtnFace;
      FCanvas.Pen.Color := clWindowText;
      FCanvas.Font.Color := clWindowText
    end;
    FCanvas.FillRect(rcItem);

    ColorRect := Rect(rcItem.Left + HorzMargin, rcItem.Top + VertMargin, rcItem.Left + HorzMargin + ColorBoxWidth, rcItem.Bottom - VertMargin);
    DrawText(FCanvas, Item.Caption, Rect(ColorRect.Right + 1 * HorzMargin, rcItem.Top, rcItem.Right, rcItem.Bottom), DT_VCENTER or DT_SINGLELINE);

    FCanvas.Brush.Color := Item.Tag;
    FCanvas.Rectangle(ColorRect.Left, ColorRect.Top, ColorRect.Right, ColorRect.Bottom);

    FCanvas.Handle := 0;
  end;
end;

Procedure TwwRichEditBar.RichEditBarFrameNeeded;
begin
   if RichEditBarFrame=nil then
   begin
     RichEditBarFrame:= TwwRichBarFrame.create(self);
     RichEdit1.Parent:= RichEditBarFrame.RichEditBar;
     RichEditBarFrame.RichEdit1:= self.RichEdit1;
     RichEditBarFrame.Initialize;
     RichEditBarFrame.RichEditBar.parent:= self;
     RichEditbarFrame.RichEditBar.Align:= alClient;
     RichEdit1.OnSelectionChange:= RichEditSelectionChange;
   end;

end;

procedure TwwRichEditBar.CreateWnd;
begin
   inherited CreateWnd;
   RichEditBarFrameneeded;
   UpdateControlPositions;
//   RichEditBarFrame.ResizeBar;

end;

procedure TwwRichEditBar.DestroyHandle;
begin
  inherited DestroyHandle;
end;

procedure TwwRichEditBar.Resize;
begin
   inherited Resize;
   if (RichEditBarFrame<>nil) then
      RichEditBarFrame.ResizeBar;
end;

procedure TwwRichEditBar.SetOptions(val: TwwRichEditBarOptions);
begin
   FOptions:=val;
   if (RichEditBarFrame<>nil) then
      UpdateControlPositions;

end;

end.

⌨️ 快捷键说明

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