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

📄 wwrich.pas

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

procedure TwwRichEditForm.StatusBar1Click(Sender: TObject);
begin
   StatusBar.visible:= not StatusBar.visible;
   StatusBar1.checked:= StatusBar.visible;
   FormResize(self);
end;

procedure TwwRichEditForm.Exit1Click(Sender: TObject);
begin
   ModalResult:= mrCancel;
end;

procedure TwwRichEditForm.SaveExit1Click(Sender: TObject);
var DoDefault: boolean;
begin
  DoDefault:= True;
  if Assigned(OrigRichEdit.OnMenuSaveAndExitClick) then
     OrigRichEdit.OnMenuSaveAndExitClick(self, RichEdit1, DoDefault);
  if not DoDefault then exit;

  ModalResult:= mrOK;
end;

procedure TwwRichEditForm.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
var answer: integer;
begin
   if ModalResult=mrOK then exit;

   if (reoNoConfirmation in OrigRichEdit.EditorOptions) then
      ModalResult:= mrOK
   else if RichEdit1.modified and (not RichEdit1.ReadOnly) then { 2/24/99 - No message if readonly }
   begin
      answer:= MessageDlg(wwInternational.UserMessages.RichEditExitWarning,
                 mtConfirmation, [mbYes, mbNo, mbCancel], 0);
      if (answer = mrYes) then begin
         ModalResult:= mrOK;
      end
      else if (answer = mrNo) then begin
         ModalResult:= mrCancel;
      end
      else CanClose:= False;
   end
   else ModalResult:= mrCancel;

end;

procedure TwwRichEditForm.Tabs1Click(Sender: TObject);
begin
   richedit1.executeTabDialog;
end;

procedure TwwRichEditForm.FormResize(Sender: TObject);
var RichEditTop, RichEditHeight, RulerPanelTop: integer;
    frameOffset: word;//integer;
begin
   RichEdit1.SkipPaint:= True;

   // Vista support
   frameOffset:=GetSystemMetrics(sm_cxframe) * 2;

   try try
      if (richedit1.EffectiveEditWidth <> rewPrinterSize) then
      begin
         //RulerPanel.Width:=  Width - 8;
         RulerPanel.Width:=  Width - frameOffset;
         TwwRulerPanel(RulerPanel).RulerRect:= Rect(6, 4, RulerPanel.Width-6, RulerPanel.Height-4);
      end;

      StatusBar.Panels[0].width:= Width - wwAdjustPixels(90, PixelsPerInch) - frameOffset;

      RichEditTop:= 0;
      RulerPanelTop:= 0;
      if FormatBar.visible then begin
         RichEditTop:= RichEditTop + FormatBar.Height+2;
         RulerPanelTop:= RichEditTop;
      end;
      if ToolBar.visible then begin
         RichEditTop:= RichEditTop + ToolBar.Height+2;
         RulerPanelTop:= RichEditTop;
      end;
      if RulerPanel.visible then begin
         RichEditTop:= RichEditTop + RulerPanel.Height+2;
         RulerBevel.Top:= RulerPanelTop;
         RulerPanel.Top:= RulerPanelTop + 2;
      end;


      if StatusBar.visible then
         RichEditHeight:= ClientHeight - StatusBar.Height - RichEditTop
      else RichEditHeight:= ClientHeight - RichEditTop;

      // Vista support
      SetWindowPos (RichEdit1.Handle, 0, RichEdit1.Left, RichEditTop,
             Width - frameOffset, RichEditHeight, SWP_NOACTIVATE);

//   RichEdit1.Top := RichEditTop;
//   RichEdit1.Width:= Width - 8;
//   RichEdit1.Height:= RichEditHeight;

      TwwRulerPanel(RulerPanel).RightDragButton.MaxValue:=
        TwwRulerPanel(RulerPanel).RulerRect.Right-(TwwRulerPanel(RulerPanel).RightDragButton.Width div 2);
      TwwRulerPanel(RulerPanel).UpdateDragIcons;

      if StatusBar.visible then
      begin
         StatusBar.Top:= richedit1.top + RicheditHeight;
         StatusBar.Width:= richedit1.Width;
      end;

   finally
      richedit1.setEditRect;  { Call after sizing richedit }

      { Allows vertical scrollbars to appear when unmaximizing form }
      if richedit1.EffectiveEditWidth = rewPrinterSize then
      begin
         richedit1.width:= richedit1.width + 1;
         richedit1.width:= richedit1.width - 1;
      end;

      richedit1.SkipPaint:= False;
      richedit1.invalidate;
   end
   except
      richedit1.SkipPaint:= False;
      ShowMessage('Error in resize');
   end;

end;


procedure GetPrinter(var DeviceMode, DeviceNames: THandle);
var
  Device, Driver, Port: array[0..79] of char;
  DevNames: PDevNames;
  Offset: PChar;
begin
  Printer.GetPrinter(Device, Driver, Port, DeviceMode);
  if DeviceMode <> 0 then
  begin
    DeviceNames := GlobalAlloc(GHND, SizeOf(TDevNames) +
     StrLen(Device) + StrLen(Driver) + StrLen(Port) + 3);
    DevNames := PDevNames(GlobalLock(DeviceNames));
    try
      Offset := PChar(DevNames) + SizeOf(TDevnames);
      with DevNames^ do
      begin
        wDriverOffset := Longint(Offset) - Longint(DevNames);
        Offset := StrECopy(Offset, Driver) + 1;
        wDeviceOffset := Longint(Offset) - Longint(DevNames);
        Offset := StrECopy(Offset, Device) + 1;
        wOutputOffset := Longint(Offset) - Longint(DevNames);;
        StrCopy(Offset, Port);
      end;
    finally
      GlobalUnlock(DeviceNames);
    end;
  end;
end;

function CopyData(Handle: THandle): THandle;
var
  Src, Dest: PChar;
  Size: Integer;
begin
  if Handle <> 0 then
  begin
    Size := GlobalSize(Handle);
    Result := GlobalAlloc(GHND, Size);
    if Result <> 0 then
      try
        Src := GlobalLock(Handle);
        Dest := GlobalLock(Result);
        if (Src <> nil) and (Dest <> nil) then Move(Src^, Dest^, Size);
      finally
        GlobalUnlock(Handle);
        GlobalUnlock(Result);
      end
  end
  else Result := 0;
end;

procedure SetPrinter(DeviceMode, DeviceNames: THandle);
var
  DevNames: PDevNames;
begin
  DevNames := PDevNames(GlobalLock(DeviceNames));
  try
    with DevNames^ do begin
      Printer.SetPrinter(PChar(DevNames) + wDeviceOffset,
        PChar(DevNames) + wDriverOffset,
        PChar(DevNames) + wOutputOffset, DeviceMode);
    end;
  finally
    GlobalUnlock(DeviceNames);
    GlobalFree(DeviceNames);
  end;
end;


{procedure SetPrinterDev(DevMode: PDeviceMode; DeviceMode, DeviceNames: THandle);
var
  DevNames: PDevNames;
  FPrinterHandle: THandle;
begin
  DevNames := PDevNames(GlobalLock(DeviceNames));
  try
    with DevNames^ do begin
      if OpenPrinter(PChar(DevNames) + wDeviceOffset, FPrinterHandle, nil) then
      begin
         ShowMessage(inttostr(DocumentProperties(Application.handle, FPrinterHandle, PChar(DevNames) + wDeviceOffset,
            PDevMode(Nil)^, DevMode^, DM_IN_BUFFER)));
         if FPrinterHandle <> 0 then ClosePrinter(FPrinterHandle);
      end;
    end;
  finally
    GlobalUnlock(DeviceNames);
  end;
end;
}

{Center PageSetup Dialog }
function PageSetupHook(Wnd: HWnd; Msg: UINT; WParam: WPARAM; LParam: LPARAM): UINT; stdcall;
  procedure CenterWindow(Wnd: HWnd);
  var Rect: TRect;
  begin
    GetWindowRect(Wnd, Rect);
    SetWindowPos(Wnd, 0,
      (GetSystemMetrics(SM_CXSCREEN) - Rect.Right + Rect.Left) div 2,
      (GetSystemMetrics(SM_CYSCREEN) - Rect.Bottom + Rect.Top) div 3,
      0, 0, SWP_NOACTIVATE or SWP_NOSIZE or SWP_NOZORDER);
  end;
begin
  Result := 0;
// 6/13/01 - Remove obsolete functions
  case Msg of
    WM_INITDIALOG:
      begin
//        Subclass3DDlg(Wnd, CTL3D_ALL);
//        SetAutoSubClass(True);
        CenterWindow(Wnd);
      end;
//    WM_DESTROY:
//      SetAutoSubClass(False);
  end;
end;

{ TCommonDialog }
Function TwwPageSetupDialog.execute: boolean;
var setup: TPageSetupDlg;
    hOrigDeviceMode: THandle;
    hDeviceMode: THandle;
    DeviceMode : PDeviceMode;
    tempOrientation : TPrinterOrientation;
    tempPrintPageSize: integer;
begin
  FillChar(setup, SizeOf(TPageSetupDlg), 0);
  with Setup do begin
     lStructSize := SizeOf(TPageSetupDlg);
     hWndOwner := Application.Handle;
     {$ifdef wwDelphi3Up}
     hInstance := SysInit.HInstance;
     {$else}
     hInstance := System.HInstance;
     {$endif}
     GetPrinter(hOrigDeviceMode, hDevNames);
     hDeviceMode := CopyData(hOrigDeviceMode);
     hDevMode:= hDeviceMode;  { 4/18/98 - This important line previously omitted!  }
     lpfnPageSetupHook := PageSetupHook;

     flags:= PSD_MARGINS or PSD_ENABLEPAGESETUPHOOK;
     if richedit1.EffectiveEditwidth=rewWindowSize then flags:= flags or PSD_DISABLEPAPER;

     with RichEdit1 do begin
        if MeasurementUnits=muInches then
           flags:= flags or PSD_INTHOUSANDTHSOFINCHES
        else flags:= flags or PSD_INHUNDREDTHSOFMILLIMETERS;
        rtMargin.left:= Trunc(PrintMargins.left*1000);
        rtMargin.top:= Trunc(PrintMargins.top*1000);
        rtMargin.right:= Trunc(PrintMargins.right*1000);
        rtMargin.bottom:= Trunc(PrintMargins.bottom*1000);
        if richedit1.EffectiveEditwidth=rewPrinterSize then
        begin
           DeviceMode := GlobalLock(hDeviceMode);
           DeviceMode.dmPaperSize:= PrintPageSize;
           GlobalUnlock(hDeviceMode);
        end
     end;
     Result := TaskModalDialog(@PageSetupDlg, setup);
     if Result then with RichEdit1 do begin
        PrintMargins.Left:=  rtMargin.left /1000;
        PrintMargins.right:= rtMargin.right / 1000;
        PrintMargins.top:= rtMargin.top / 1000;
        Printmargins.bottom:= rtMargin.bottom / 1000;

//        DeviceMode := GlobalLock(hDeviceMode);  { Set printer attributes }
        DeviceMode := GlobalLock(hDevMode);  { Set printer attributes }
        tempPrintPageSize:= DeviceMode.dmPaperSize;
        if DeviceMode.dmOrientation=DMORIENT_LANDSCAPE then
           tempOrientation:= poLandscape
        else tempOrientation:= poPortrait;
//        GlobalUnlock(hDeviceMode);
        GlobalUnlock(hDevMode);

//        SetPrinter(hDeviceMode, hDevNames);  { Choose printer }
        SetPrinter(hDevMode, hDevNames);  { Choose printer }
        Printer.orientation:= tempOrientation;
        PrintPageSize:= tempPrintPageSize;
        UpdatePrinter;
     end
     else begin
       if hDeviceMode <> 0 then GlobalFree(hDeviceMode);
       if hDevNames <> 0 then GlobalFree(hDevNames);
     end;

  end;
end;

procedure TwwRichEditForm.PageSetup1Click(Sender: TObject);
begin
   with TwwPageSetupDialog.create(self) do
   begin
      RichEdit1:= self.RichEdit1;
      if Execute then
      begin
         if RichEdit1.EffectiveEditWidth = rewPrinterSize then
         begin
            TwwRulerPanel(RulerPanel).UpdateSize(RichEdit1);
            TwwRulerPanel(RulerPanel).UpdateDragIcons;
            RulerPanel.UpdateRulerProp(RulerPanel.RightDragButton);
         end
         else self.RichEdit1.SetEditRect;
      end;
      Free;
   end
end;


procedure TwwRichEditForm.Load1Click(Sender: TObject);
var DoDefault: boolean;
begin
  DoDefault:= True;
  if Assigned(OrigRichEdit.OnMenuLoadClick) then
     OrigRichEdit.OnMenuLoadClick(self, RichEdit1, DoDefault);
  if not DoDefault then exit;

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

procedure TwwRichEditForm.SaveAs1Click(Sender: TObject);
var DoDefault: boolean;
begin
  DoDefault:= True;
  if Assigned(OrigRichEdit.OnMenuSaveAsClick) then
     OrigRichEdit.OnMenuSaveAsClick(self, RichEdit1, DoDefault);
  if not DoDefault then exit;

  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 TwwRichEditForm.NewButtonClick(Sender: TObject);
begin
   if MessageDlg(wwInternational.UserMessages.RichEditClearWarning,
                 mtConfirmation, [mbOK, mbCancel], 0)  <> mrOK then exit;

   richedit1.clear;
   richedit1.modified:= True;
end;

procedure TwwRichEditForm.LoadButton1Click(Sender: TObject);
begin
   Load1Click(Sender);
end;

procedure TwwRichEditForm.SaveAsButtonClick(Sender: TObject);
begin
   SaveAs1Click(Sender);
end;

procedure TwwRichEditForm.PrintButtonClick(Sender: TObject);
begin
    Print1Click(Sender);
end;

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

procedure TwwRichEditForm.FindButtonClick(Sender: TObject);
begin
   Find1Click(Sender);
end;

procedure TwwRichEditForm.CutButtonClick(Sender: TObject);
begin
  Cut1Click(Sender);
end;

⌨️ 快捷键说明

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