|
|
1.1 ! root 1: /* $Id: PreviewFormUnit.cpp,v 1.4 2005/10/12 08:25:03 rswindell Exp $ */ ! 2: ! 3: /**************************************************************************** ! 4: * @format.tab-size 4 (Plain Text/Source Code File Header) * ! 5: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * ! 6: * * ! 7: * Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html * ! 8: * * ! 9: * This program is free software; you can redistribute it and/or * ! 10: * modify it under the terms of the GNU General Public License * ! 11: * as published by the Free Software Foundation; either version 2 * ! 12: * of the License, or (at your option) any later version. * ! 13: * See the GNU General Public License for more details: gpl.txt or * ! 14: * http://www.fsf.org/copyleft/gpl.html * ! 15: * * ! 16: * Anonymous FTP access to the most recent released source is available at * ! 17: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * ! 18: * * ! 19: * Anonymous CVS access to the development source and modification history * ! 20: * is available at cvs.synchro.net:/cvsroot/sbbs, example: * ! 21: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login * ! 22: * (just hit return, no password is necessary) * ! 23: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src * ! 24: * * ! 25: * For Synchronet coding style and modification guidelines, see * ! 26: * http://www.synchro.net/source.html * ! 27: * * ! 28: * You are encouraged to submit any modifications (preferably in Unix diff * ! 29: * format) via e-mail to [email protected] * ! 30: * * ! 31: * Note: If this box doesn't appear square, then you need to fix your tabs. * ! 32: ****************************************************************************/ ! 33: ! 34: //--------------------------------------------------------------------------- ! 35: ! 36: #include <vcl.h> ! 37: #pragma hdrstop ! 38: ! 39: #include "MainFormUnit.h" ! 40: #include "PreviewFormUnit.h" ! 41: //--------------------------------------------------------------------------- ! 42: #pragma package(smart_init) ! 43: #pragma resource "*.dfm" ! 44: TPreviewForm *PreviewForm; ! 45: //--------------------------------------------------------------------------- ! 46: __fastcall TPreviewForm::TPreviewForm(TComponent* Owner) ! 47: : TForm(Owner) ! 48: { ! 49: Width=MainForm->SpyTerminalWidth; ! 50: Height=MainForm->SpyTerminalHeight; ! 51: Terminal = new TEmulVT(this); ! 52: Terminal->Parent=this; ! 53: Terminal->Align=alClient; ! 54: Terminal->Rows=MAX_ROW; ! 55: Terminal->Font=MainForm->SpyTerminalFont; ! 56: Terminal->AutoWrap=true; ! 57: ActiveControl=Terminal; ! 58: } ! 59: //--------------------------------------------------------------------------- ! 60: __fastcall TPreviewForm::~TPreviewForm() ! 61: { ! 62: delete Terminal; ! 63: } ! 64: ! 65: ! 66: #define ANSI_ESC "\x1b[" ! 67: ! 68: //--------------------------------------------------------------------------- ! 69: void __fastcall TPreviewForm::FormShow(TObject *Sender) ! 70: { ! 71: char str[128]; ! 72: ! 73: Caption="Previewing " + Filename.UpperCase(); ! 74: ! 75: Terminal->Clear(); ! 76: ! 77: FILE* fp=fopen(Filename.c_str(),"rb"); ! 78: ! 79: if(fp==NULL) ! 80: return; ! 81: ! 82: int ch; ! 83: while(!feof(fp)) { ! 84: ch=fgetc(fp); ! 85: if(ch==EOF) ! 86: break; ! 87: if(ch==1) { /* ctrl-a */ ! 88: ch=fgetc(fp); ! 89: if(ch==EOF) ! 90: break; ! 91: switch(toupper(ch)) { ! 92: case 'A': ! 93: sprintf(str,"\1"); ! 94: break; ! 95: case '<': ! 96: sprintf(str,"\b"); ! 97: break; ! 98: case '>': ! 99: sprintf(str,ANSI_ESC"K"); ! 100: break; ! 101: case '[': ! 102: sprintf(str,"\r"); ! 103: break; ! 104: case ']': ! 105: sprintf(str,"\n"); ! 106: break; ! 107: case 'L': ! 108: sprintf(str,ANSI_ESC"2J"); ! 109: break; ! 110: case '-': ! 111: case '_': ! 112: case 'N': ! 113: sprintf(str,ANSI_ESC"0m"); ! 114: break; ! 115: case 'H': ! 116: sprintf(str,ANSI_ESC"1m"); ! 117: break; ! 118: case 'I': ! 119: sprintf(str,ANSI_ESC"5m"); ! 120: break; ! 121: case 'K': ! 122: sprintf(str,ANSI_ESC"30m"); ! 123: break; ! 124: case 'R': ! 125: sprintf(str,ANSI_ESC"31m"); ! 126: break; ! 127: case 'G': ! 128: sprintf(str,ANSI_ESC"32m"); ! 129: break; ! 130: case 'Y': ! 131: sprintf(str,ANSI_ESC"33m"); ! 132: break; ! 133: case 'B': ! 134: sprintf(str,ANSI_ESC"34m"); ! 135: break; ! 136: case 'M': ! 137: sprintf(str,ANSI_ESC"35m"); ! 138: break; ! 139: case 'C': ! 140: sprintf(str,ANSI_ESC"36m"); ! 141: break; ! 142: case 'W': ! 143: sprintf(str,ANSI_ESC"37m"); ! 144: break; ! 145: case '0': ! 146: sprintf(str,ANSI_ESC"40m"); ! 147: break; ! 148: case '1': ! 149: sprintf(str,ANSI_ESC"41m"); ! 150: break; ! 151: case '2': ! 152: sprintf(str,ANSI_ESC"42m"); ! 153: break; ! 154: case '3': ! 155: sprintf(str,ANSI_ESC"43m"); ! 156: break; ! 157: case '4': ! 158: sprintf(str,ANSI_ESC"44m"); ! 159: break; ! 160: case '5': ! 161: sprintf(str,ANSI_ESC"45m"); ! 162: break; ! 163: case '6': ! 164: sprintf(str,ANSI_ESC"46m"); ! 165: break; ! 166: case '7': ! 167: sprintf(str,ANSI_ESC"47m"); ! 168: break; ! 169: case '.': ! 170: case ',': ! 171: case ';': ! 172: /* ignore delay codes */ ! 173: continue; ! 174: default: ! 175: if(ch>=0x7f) /* move cursor right x columns */ ! 176: sprintf(str,ANSI_ESC"%uC",ch-0x7f); ! 177: else ! 178: sprintf(str,"\1%c",ch); ! 179: break; ! 180: } ! 181: Terminal->WriteBuffer(str,strlen(str)); ! 182: } ! 183: else ! 184: Terminal->WriteBuffer(&ch,1); ! 185: } ! 186: fclose(fp); ! 187: } ! 188: //--------------------------------------------------------------------------- ! 189: void __fastcall TPreviewForm::FormClose(TObject *Sender, ! 190: TCloseAction &Action) ! 191: { ! 192: MainForm->SpyTerminalWidth=Width; ! 193: MainForm->SpyTerminalHeight=Height; ! 194: ! 195: } ! 196: //--------------------------------------------------------------------------- ! 197: void __fastcall TPreviewForm::ChangeFontMenuItemClick(TObject *Sender) ! 198: { ! 199: TFontDialog *FontDialog=new TFontDialog(this); ! 200: ! 201: FontDialog->Font=MainForm->SpyTerminalFont; ! 202: FontDialog->Execute(); ! 203: MainForm->SpyTerminalFont->Assign(FontDialog->Font); ! 204: Terminal->Font=MainForm->SpyTerminalFont; ! 205: delete FontDialog; ! 206: Terminal->UpdateScreen(); ! 207: } ! 208: //--------------------------------------------------------------------------- ! 209:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.