// // Copyright 2002 Perforce Software. All rights reserved. // // This file is part of Perforce - the FAST SCM System. // // p4wPrintPane: // Displays the result of the p4 print command on the // file browser page. #include <p4wp4.h> #include "p4wStrBuf.h" #include "p4wHtml.h" #include "p4wPane.h" #include "p4wPrintPane.h" p4wPrintPane::p4wPrintPane( p4wView & ParentView, p4wRequest & Request ) : p4wPane( ParentView, Request ), fSeenData(0), linecounter(1), fJSauto(0) { const StrPtr *lno = fRequest.GetStateArg( "lno" ); bShowLineNo = ( lno && *lno == "y" ) ? 1 : 0; } p4wPrintPane::~p4wPrintPane() { } void p4wPrintPane::Begin() { // // Begin the pane. p4wHtml htm; htm.comment( "BEGIN PRINT PANE" ); fRequest << htm; } void p4wPrintPane::RenderBinary( char *data, int len ) { renderData( data ); } void p4wPrintPane::RenderText( char *data ) { renderData( data ); } void p4wPrintPane::renderData( char *data ) { if( !fSeenData ) { fSeenData = 1; // // Start the table. The table is just a box // that encloses the text startTable(); } if( !PageLimitExceeded() ) { StrBuf buf; buf.Set(p4wStrBuf().EscapeHTML( StrRef(data), Unicode() )); char *p = buf.Text(); char *q = p + buf.Length() ; while (p < q) { if (*p == '\r') { if (*(p+1) != '\n') *p = '\n'; else { strcpy(p, p+1); q--; } } if (*p == '\n' && !fJSauto) fRequest << "</a>"; fRequest << *p; if (*p++ == '\n') { char buf2[128]; ++linecounter; if (!fJSauto) { if (bShowLineNo) { sprintf(buf2, "%5d.\t", linecounter); fRequest << buf2; sprintf(buf2, "<a name=\"%d\">", linecounter); } else sprintf(buf2, "<a name=\"%d\" title=\"ln:%d\">", linecounter, linecounter); fRequest << buf2; } } } } } void p4wPrintPane::End() { // // End the pane. p4wHtml htm; if( fSeenData ) { if (!fJSauto) htm << "</a><a name=\"end\"></a>"; htm.endUnformatted(); if (fJSauto) { htm << "<script language=\"javascript\" src=\""; htm << fRequest.GetJavaScriptViewPath() << "\">"; htm << "</script>" << crlf; htm << "<script language=\"javascript\">jsCustomView('code', '"; StrBuf depotPath; depotPath << fRequest.GetDepotPath(); StrBuf depotFile; char *p; if ((p = strrchr(depotPath.Text(), '/')) || (p = strrchr(depotPath.Text(), '\\'))) depotFile << p+1; StrBuf depotExt; if (p = strrchr(depotPath.Text(), '.')) depotExt << p + 1; htm << depotPath.Text(); htm << "', '"; htm << depotFile.Text(); htm << "', '"; htm << depotExt.Text(); htm << "')"; htm << "</script>" << crlf; } htm.endCol(); htm.endTRow(); htm.endTable(); htm.endCol(); htm.endTRow(); htm.endTable(); } else { htm.beginTRow(); htm.beginCol(); htm.text( " File not found, or file is empty." ); htm.endCol(); htm.endTRow(); } htm.comment( "END PRINT PANE" ); fRequest << htm; } void p4wPrintPane::startTable() { // // Set flags for custom JS hook int bJSlink = 0; if (fRequest.GetJavaScriptViewName().Length()) bJSlink = 1; else if (fRequest.GetJavaScriptViewPath().Length()) fJSauto = 1; // // Start the table which encloses the text in a box p4wHtml htm; p4wURL urlMaker; StrBuf clearIcon; urlMaker.ConstructURL( clearIcon, "/clearpixelIcon", AC_ICON, NULL ); htm.beginTRow(); htm.beginCol(); htm.icon( clearIcon.Text(), "10", "10", "", 1 ); htm.linebreak(); htm.icon( clearIcon.Text(), "1", "10", "", 1 ); htm.beginSpan("fSmaller"); if (!fJSauto) { AllCommands ac = fRequest.GetCmd(); StrBuf path; path.Set( fRequest.GetReturnURL( ac ).Text() ); StrBuf base; StrBuf url; StrBuf dyn; StrBufDict args; if (!bShowLineNo) { fRequest.UseNewBase( base, NULL, "lno", "y" ); fRequest.UseNewBase( base, base.Text(), "path", path.Text() ); urlMaker.ConstructURL( url, base.Text(), ac, &args, fRequest.GetUnicode() ); dyn.Set(fRequest.GetDynURL()); char *p = strchr(dyn.Text(), '&'); if (p) url << p; htm.beginLink(url.Text()); htm << "Show line numbers"; htm.endLink(); // htm.text(" or Hover your mouse over a line to see its line number."); } else { fRequest.UseNewBase( base, NULL, "lno", NULL ); fRequest.UseNewBase( base, base.Text(), "path", path.Text() ); urlMaker.ConstructURL( url, base.Text(), ac, &args, fRequest.GetUnicode() ); dyn.Set(fRequest.GetDynURL()); char *p = strchr(dyn.Text(), '&'); if (p) url << p; htm.beginLink(url.Text()); htm << "Hide line numbers"; htm.endLink(); } } if (bJSlink) { StrBuf depotPath; depotPath << fRequest.GetDepotPath(); StrBuf depotFile; char *p; if ((p = strrchr(depotPath.Text(), '/')) || (p = strrchr(depotPath.Text(), '\\'))) depotFile << p+1; StrBuf depotExt; if (p = strrchr(depotPath.Text(), '.')) depotExt << p + 1; htm << "<script language=\"javascript\" src=\""; htm << fRequest.GetJavaScriptViewPath() << "\">"; htm << "</script>" << crlf; htm << " "; htm << "<a href=\"javascript:jsCustomView('code', '"; htm << depotPath.Text(); htm << "', '"; htm << depotFile.Text(); htm << "', '"; htm << depotExt.Text(); htm << "')\">"; htm << fRequest.GetJavaScriptViewName(); htm.endLink(); } htm.endSpan(); htm.endCol(); htm.endTRow(); htm.beginTRow(); htm.beginCol(); htm.beginTable( "0", "100%", "8", "1", "#7F7F7F" ); htm.beginTRow( NULL, NULL, "#FFFFFF" ); htm.beginCol(); htm.beginTable( "0", NULL, bShowLineNo ? "0" : "2", "0", "#FFFFFF" ); htm.beginTRow(); htm.beginCol(0,0,0,0,0,0,0,0,"pre"); htm.beginUnformatted(0, "code"); if (!fJSauto) { if (bShowLineNo) { htm << " 1.\t"; htm << "<a name=\"1\">"; } else htm << "<a name=\"1\" title=\"ln:1\">"; } fRequest << htm; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 12234 | Matt Attaway |
Rejigger P4Web project in preparation for official sunsetting The bin directory contains the last official builds of P4Web from the Perforce download site. P4Web is soon to be completely sunsetted; these builds are here for folks who don't want to build their own. To better handle the archived builds the source code has been moved into a separate src directory. |
||
//guest/perforce_software/p4web/Panes/p4wPrintPane.cpp | |||||
#1 | 8914 | Matt Attaway | Initial add of the P4Web source code |