Skip to content

Commit 1dff01e

Browse files
From Ilka:
enable the Print command in the TCanvas File menu via a proper print dialog. The user can specify his prefered print command and printer via the new Print.Command and Print.Printer rootrc resources. Examples are provided in system.rootrc. git-svn-id: http://root.cern.ch/svn/root/trunk@10783 27541ba8-7e3a-0410-8455-c3a389f83636
1 parent 7d7cc91 commit 1dff01e

File tree

5 files changed

+121
-12
lines changed

5 files changed

+121
-12
lines changed

gui/inc/TRootCanvas.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @(#)root/gui:$Name: $:$Id: TRootCanvas.h,v 1.14 2004/05/10 12:09:45 brun Exp $
1+
// @(#)root/gui:$Name: $:$Id: TRootCanvas.h,v 1.15 2004/09/08 08:13:11 brun Exp $
22
// Author: Fons Rademakers 15/01/98
33

44
/*************************************************************************
@@ -108,6 +108,7 @@ friend class TRootContainer;
108108
UInt_t GetCheight() const;
109109
void Iconify() { IconifyWindow(); }
110110
Int_t InitWindow();
111+
void PrintCanvas();
111112
void SetWindowPosition(Int_t x, Int_t y);
112113
void SetWindowSize(UInt_t w, UInt_t h);
113114
void SetWindowTitle(const char *newTitle);

gui/src/TGTextEdit.cxx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @(#)root/gui:$Name: $:$Id: TGTextEdit.cxx,v 1.25 2004/02/18 16:17:33 rdm Exp $
1+
// @(#)root/gui:$Name: $:$Id: TGTextEdit.cxx,v 1.26 2004/06/14 10:28:51 rdm Exp $
22
// Author: Fons Rademakers 3/7/2000
33

44
/*************************************************************************
@@ -1101,7 +1101,7 @@ Bool_t TGTextEdit::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
11011101
break;
11021102
case kM_FILE_PRINT:
11031103
{
1104-
Int_t ret;
1104+
Int_t ret = 0;
11051105
if (!gPrinter) {
11061106
gPrinter = StrDup("892_2_cor"); // use gEnv
11071107
gPrintCommand = StrDup("xprint");

gui/src/TGTextEditDialogs.cxx

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @(#)root/gui:$Name: $:$Id: TGTextEditDialogs.cxx,v 1.6 2004/02/18 20:13:43 brun Exp $
1+
// @(#)root/gui:$Name: $:$Id: TGTextEditDialogs.cxx,v 1.7 2004/09/13 09:10:56 rdm Exp $
22
// Author: Fons Rademakers 10/7/2000
33

44
/*************************************************************************
@@ -36,6 +36,7 @@
3636
#include "TGLabel.h"
3737
#include "TGTextEntry.h"
3838
#include "TGIcon.h"
39+
#include "TGMsgBox.h"
3940

4041
#include <stdlib.h>
4142

@@ -295,8 +296,8 @@ TGPrintDialog::TGPrintDialog(const TGWindow *p, const TGWindow *main,
295296
AddFrame(fF1, fL21);
296297

297298

298-
fLPrintCommand = new TGLabel(fF3, new TGHotString("Print &command:"));
299-
fBPrintCommand = new TGTextBuffer(20);
299+
fLPrintCommand = new TGLabel(fF3, new TGHotString("Print command:"));
300+
fBPrintCommand = new TGTextBuffer(50);
300301
fBPrintCommand->AddText(0, *printProg);
301302
fPrintCommandEntry = new TGTextEntry(fF3, fBPrintCommand);
302303
fPrintCommandEntry->Associate(this);
@@ -307,7 +308,7 @@ TGPrintDialog::TGPrintDialog(const TGWindow *p, const TGWindow *main,
307308
fF3->AddFrame(fLPrintCommand, fL5);
308309
fF3->AddFrame(fPrintCommandEntry, fL6);
309310

310-
fLPrinter = new TGLabel(fF4, new TGHotString("&Printer:"));
311+
fLPrinter = new TGLabel(fF4, new TGHotString("Printer:"));
311312
fBPrinter = new TGTextBuffer(20);
312313
fBPrinter->AddText(0, *printerName);
313314
fPrinterEntry = new TGTextEntry(fF4, fBPrinter);
@@ -379,7 +380,7 @@ Bool_t TGPrintDialog::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
379380
{
380381
// Process print dialog widget messages.
381382

382-
const char *string;
383+
const char *string, *txt;
383384

384385
switch (GET_MSG(msg)) {
385386
case kC_COMMAND:
@@ -389,14 +390,22 @@ Bool_t TGPrintDialog::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
389390
case 1:
390391
*fRetCode = kTRUE;
391392
string = fBPrinter->GetString();
392-
delete *fPrinter;
393+
delete [] *fPrinter;
393394
*fPrinter = new char[strlen(string)+1];
394395
strcpy(*fPrinter, string);
395396

396397
string = fBPrintCommand->GetString();
397-
delete *fPrintCommand;
398+
delete [] *fPrintCommand;
398399
*fPrintCommand = new char[strlen(string)+1];
399400
strcpy(*fPrintCommand, string);
401+
402+
if (fBPrintCommand->GetTextLength() == 0) {
403+
txt = "Please provide print command or use \"Cancel\"";
404+
new TGMsgBox(fClient->GetRoot(), GetMainFrame(),
405+
"Missing Print Parameters", txt, kMBIconExclamation,
406+
kMBOk);
407+
return kTRUE;
408+
}
400409
CloseWindow();
401410
break;
402411
case 2:

gui/src/TRootCanvas.cxx

+60-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @(#)root/gui:$Name: $:$Id: TRootCanvas.cxx,v 1.64 2004/12/07 01:38:14 rdm Exp $
1+
// @(#)root/gui:$Name: $:$Id: TRootCanvas.cxx,v 1.65 2004/12/10 12:54:17 brun Exp $
22
// Author: Fons Rademakers 15/01/98
33

44
/*************************************************************************
@@ -31,6 +31,7 @@
3131
#include "TGWidget.h"
3232
#include "TGFileDialog.h"
3333
#include "TGStatusBar.h"
34+
#include "TGTextEditDialogs.h"
3435
#include "TROOT.h"
3536
#include "TSystem.h"
3637
#include "TCanvas.h"
@@ -165,6 +166,7 @@ static ToolBarData_t gToolBarData[] = {
165166
{ "newcanvas.xpm", "New", kFALSE, kFileNewCanvas, NULL },
166167
{ "open.xpm", "Open", kFALSE, kFileOpen, NULL },
167168
{ "save.xpm", "Save As", kFALSE, kFileSaveAs, NULL },
169+
{ "printer.xpm", "Print", kFALSE, kFilePrint, NULL },
168170
{ "", "", kFALSE, -1, NULL },
169171
{ "interrupt.xpm", "Interrupt", kFALSE, kOptionInterrupt,NULL },
170172
{ "refresh2.xpm", "Refresh", kFALSE, kOptionRefresh, NULL },
@@ -826,7 +828,7 @@ Bool_t TRootCanvas::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
826828
fCanvas->SaveAs(".jpg");
827829
break;
828830
case kFilePrint:
829-
fCanvas->Print();
831+
PrintCanvas();
830832
break;
831833
case kFileCloseCanvas:
832834
if (!fEditor && (TVirtualPadEditor::GetPadEditor(kFALSE) != 0))
@@ -1179,6 +1181,62 @@ void TRootCanvas::FitCanvas()
11791181
}
11801182
}
11811183

1184+
1185+
//______________________________________________________________________________
1186+
void TRootCanvas::PrintCanvas()
1187+
{
1188+
// Print the canvas.
1189+
1190+
Int_t ret = 0;
1191+
Bool_t pname = kTRUE;
1192+
char *printer, *printCmd;
1193+
static TString sprinter, sprintCmd;
1194+
1195+
if (sprinter == "")
1196+
printer = StrDup(gEnv->GetValue("Print.Printer", ""));
1197+
else
1198+
printer = StrDup(sprinter);
1199+
if (sprintCmd == "")
1200+
#ifndef WIN32
1201+
printCmd = StrDup(gEnv->GetValue("Print.Command", ""));
1202+
#else
1203+
printCmd = StrDup(gEnv->GetValue("Print.Command", "start AcroRd32.exe /p"));
1204+
#endif
1205+
else
1206+
printCmd = StrDup(sprintCmd);
1207+
1208+
new TGPrintDialog(fClient->GetDefaultRoot(), this, 400, 150,
1209+
&printer, &printCmd, &ret);
1210+
if (ret) {
1211+
sprinter = printer;
1212+
sprintCmd = printCmd;
1213+
1214+
if (sprinter == "")
1215+
pname = kFALSE;
1216+
1217+
TString fn = gSystem->ConcatFileName(gSystem->TempDirectory(), "rootprintFile01.pdf");
1218+
fCanvas->Print(fn);
1219+
1220+
TString cmd = sprintCmd;
1221+
if (cmd.Contains("%p"))
1222+
cmd.ReplaceAll("%p", sprinter);
1223+
else if (pname) {
1224+
cmd += " "; cmd += sprinter; cmd += " ";
1225+
}
1226+
1227+
if (cmd.Contains("%f"))
1228+
cmd.ReplaceAll("%f", fn);
1229+
else {
1230+
cmd += " "; cmd += fn; cmd += " ";
1231+
}
1232+
1233+
gSystem->Exec(cmd);
1234+
gSystem->Unlink(fn);
1235+
}
1236+
delete [] printer;
1237+
delete [] printCmd;
1238+
}
1239+
11821240
//______________________________________________________________________________
11831241
void TRootCanvas::ShowMenuBar(Bool_t show)
11841242
{

icons/printer.xpm

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* XPM */
2+
static char *printer[]={
3+
"16 16 22 1",
4+
". c None",
5+
"# c #000000",
6+
"l c #003e00",
7+
"n c #00f100",
8+
"m c #00f900",
9+
"j c #040404",
10+
"t c #080808",
11+
"i c #081408",
12+
"h c #0b0b0b",
13+
"q c #0c0c0c",
14+
"p c #131313",
15+
"g c #140c14",
16+
"d c #141414",
17+
"s c #191919",
18+
"f c #1c1c1c",
19+
"a c #232323",
20+
"e c #999199",
21+
"o c #a7a7a7",
22+
"r c #bfbfbf",
23+
"k c #cfcfcf",
24+
"b c #fbfbfb",
25+
"c c #ffffff",
26+
"................",
27+
"................",
28+
"....########a...",
29+
"...abcccccccca..",
30+
"...#cccccccccd..",
31+
".a#ccccccccc#ea.",
32+
"fe#cccccccccgeh.",
33+
"###########i##jh",
34+
"#kkkkkkkk#lmn#oj",
35+
"#kkkkkkkk#####o#",
36+
"#kkkkkkkkdkkk#o#",
37+
"#p############oj",
38+
"qrkrrrrrrrrrr#hh",
39+
"#sj###########t.",
40+
"................",
41+
"................"};

0 commit comments

Comments
 (0)