printform.pas 4.27 KB
Newer Older
mse1's avatar
mse1 committed
1
unit printform;
mse1's avatar
mse1 committed
2
{$ifdef FPC}{$mode objfpc}{$h+}{$endif}
mse1's avatar
mse1 committed
3 4 5
interface
uses
 msegui,mseclasses,mseforms,msesimplewidgets,msepostscriptprinter,mseprinter,
6
 msedataedits,msethreadcomp,msegraphedits,msestrings,msegraphics,msestat,
mse1's avatar
mse1 committed
7
 msestatfile,msetypes,mseglob;
mse1's avatar
mse1 committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

type
 tprintfo = class(tmseform)
   ok: tbutton;
   cancel: tbutton;
   printer: tpostscriptprinter;
   linenum: tbooleanedit;
   fontsize: trealedit;
   colorset: tbooleanedit;
   rotate: tbooleanedit;
   titlefont: tstringedit;
   sourcefont: tstringedit;
   tpageorientationselector1: tpageorientationselector;
   tpagesizeselector1: tpagesizeselector;
   tstatfile1: tstatfile;
23
   pages: tstringedit;
mse1's avatar
mse1 committed
24 25 26 27 28 29 30 31
   procedure pronpagestart(const sender: tprinter);
   procedure printidle(var again: Boolean);
   procedure runonexecute(const sender: TObject);
   procedure cancelexec(const sender: TObject);
   procedure sourcefosetvalue(const sender: TObject; var avalue: msestring;
                  var accept: Boolean);
   procedure titlefosetvalue(const sender: TObject; var avalue: msestring;
                   var accept: Boolean);
32 33
   procedure pagessetvalue(const sender: TObject; var avalue: msestring;
                   var accept: Boolean);
mse1's avatar
mse1 committed
34 35 36 37 38 39 40 41 42 43 44
  protected
   run,started: boolean;
   rowindex: integer;
   font1: tfont;
 end;
 
procedure print;

implementation
uses
 printform_mfm,main,sourceform,msestream,msesys,msegraphutils,msedrawtext,
mse1's avatar
mse1 committed
45 46
 msesettings,msereal,msewidgets,sysutils,projectoptionsform,mserichstring,
 mseguiglob;
mse1's avatar
mse1 committed
47 48 49 50 51 52 53

procedure tprintfo.printidle(var again: Boolean);
begin
 try
  with printer,canvas do begin
   if run then begin
    if not started then begin
54
     pagesstring:= self.pages.value;
mse1's avatar
mse1 committed
55
     started:= true;
mse1's avatar
mse1 committed
56
     beginprint(getprintcommand);
mse1's avatar
mse1 committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
     if colorset.value then begin
      colorspace:= cos_rgb;
     end
     else begin
      colorspace:= cos_gray;
     end;
     if rotate.value then begin
      printorientation:= pao_landscape;
     end
     else begin
      printorientation:= pao_portrait;
     end;      
     font.name:= sourcefont.value;
     font.height:= round(fontsize.value);
     headerheight:= round(fontsize.value*5/3);
     if linenum.value then begin
73
      indentx:= round(4*fontsize.value);
mse1's avatar
mse1 committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
     end;
     font1.assign(font);
     font1.name:= titlefont.value;
    end;
    with sourcefo.activepage.edit do begin
     if rowindex >= datalist.count then begin
      run:= false;
      self.window.modalresult:= mr_ok;
     end
     else begin
      if linenum.value then begin
       drawtext(inttostr(linenumber+1),makerect(0,liney,round(3*fontsize.value),0),
                             [tf_right],font1);
      end;
      writeln(expandtabs(richlines[rowindex],projectoptions.tabstops));
      inc(rowindex);
      again:= true;
     end;
    end;
   end;
  end;
 except
  run:= false;
  window.modalresult:= mr_exception;
  raise;
 end;
end;

procedure print;
var
 fo1: tprintfo;
begin
 fo1:= tprintfo.create(nil);
 fo1.font1:= tfont.create;
 try
  fo1.show(true);
 finally
  fo1.font1.free;
  fo1.free;
 end;
end;

procedure tprintfo.pronpagestart(const sender: tprinter);
begin
 with sender.canvas do begin
  save;
  font.name:= titlefont.value;
  drawtext(sourcefo.activepage.filepath,makerect(0,0,clientsize.cx-
                          round(10*fontsize.value),0),[tf_ellipseleft]);
  drawtext('Page '+inttostr(pagenumber+1),makerect(clientsize.cx,0,0,0),
                  [tf_right]);
  restore;
 end;
end;

procedure tprintfo.runonexecute(const sender: TObject);
begin
 if window.candefocus then begin
  run:= true;
  ok.enabled:= false;
 end;
end;

procedure tprintfo.cancelexec(const sender: TObject);
begin
 if run then begin
  if askyesno('Do you wish to cancel printing?') then begin
   run:= false;
   window.modalresult:= mr_cancel;
  end;
 end
 else begin
  window.modalresult:= mr_cancel;
 end;
end;

procedure tprintfo.sourcefosetvalue(const sender: TObject; var avalue: msestring;
        var accept: Boolean);
begin
 if avalue = '' then begin
  avalue:= defaultsourceprintfont;
 end;
end;

procedure tprintfo.titlefosetvalue(const sender: TObject; var avalue: msestring;
           var accept: Boolean);
begin
 if avalue = '' then begin
  avalue:= defaulttitleprintfont;
 end;
end;

166 167 168 169 170 171
procedure tprintfo.pagessetvalue(const sender: TObject; var avalue: msestring;
               var accept: Boolean);
begin
 stringtopages(avalue);
end;

mse1's avatar
mse1 committed
172
end.