1 #ifndef _KVI_CONTROLCODES_H_
2 #define _KVI_CONTROLCODES_H_
3 //=============================================================================
4 //
5 //   File : KviControlCodes.h
6 //   Creation date : Thu Jun 29 2000 21:06:55 CEST by Szymon Stefanek
7 //
8 //   This file is part of the KVIrc IRC client distribution
9 //   Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net)
10 //   Copyright (C) 2011 Elvio Basello (hellvis69 at gmail dot com)
11 //
12 //   This program is FREE software. You can redistribute it and/or
13 //   modify it under the terms of the GNU General Public License
14 //   as published by the Free Software Foundation; either version 2
15 //   of the License, or (at your option) any later version.
16 //
17 //   This program is distributed in the HOPE that it will be USEFUL,
18 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
19 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 //   See the GNU General Public License for more details.
21 //
22 //   You should have received a copy of the GNU General Public License
23 //   along with this program. If not, write to the Free Software Foundation,
24 //   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 //
26 //=============================================================================
27 
28 //
29 // This file contains non-customizable standards
30 //
31 // Better to not touch this :)
32 //
33 
34 /**
35 * \file KviControlCodes.h
36 * \author Szymon Stefanek
37 * \brief This file holds the text control codes
38 *
39 * It was originally named KviMircCntrl
40 */
41 
42 #include "kvi_settings.h"
43 #include "KviCString.h"
44 
45 #define KVI_MIRCCOLOR_MAX 15
46 #define KVI_EXTCOLOR_MAX 98
47 
48 // ASCII Stuff: the following defines are meant to be escape sequences
49 //              that can go through an IRC connection
50 
51 // The following table is a 30-minute analysis of the escape characters commonly used over the IRC protocol...
52 // created when looking for a good placement for the CRYPT escape char in KVirc.
53 // I guess that the best chars to be used were FS,GS,RS,US,DC1,DC2,DC3,DC4...they have the "less defined"
54 // meaning as ASCII control chars.
55 // mmmh... :)
56 
57 // ASCII                              IRC Meaning
58 // 000 NUL Null                       (Cannot be assigned)
59 // 001 SOH Start of heading           ( CTCP Escape: only beginning of the message )
60 // 002 STX Start of text              ( Bold text )
61 // 003 ETX End of text                ( Color text escape sequence )
62 // 004 EOT End of transmission        ( Assigned internally (escape) )
63 // 005 ENQ Enquiry (WRU: Who are you) ( Assigned internally (unescape) )
64 // 006 ACK Acknowledge                (Not so good, but can be used as last resource)
65 // 007 BEL Bell                       ( Recognized as bell by terminals and IRCII ) (Used also by some IRC servers)
66 // 008 BS  Backspace                  (Should not be assigned: terminal control)
67 // 009 HT  Horizontal tabulation      (Should not be assigned: terminal control)
68 // 010 LF  Line feed                  (Should not be assigned: terminal control)
69 // 011 VT  Vertical tabulation        (Should not be assigned: terminal control)
70 // 012 FF  Form feed                  (Should not be assigned: terminal control)
71 // 013 CR  Carriage return            (Should not be assigned: terminal control)
72 // 014 SO  Shift out                  (Should not be assigned: terminal control)
73 // 015 SI  Shift in                   ( Resets Bold,Color,Underline and Reverse ) (Conflicting with terminal control)
74 // 016 DLE Data link escape           (Decent, can be assigned)
75 // 017 DC1 Device control 1           (Good to be assigned)
76 // 018 DC2 Device control 2           (Good to be assigned)
77 // 019 DC3 Device control 3           (Good to be assigned)
78 // 020 DC4 Device control 4           (Good to be assigned)
79 // 021 NAK Negative acknowledge       (Not so good, but could be used as last resource)
80 // 022 SYN Synchronous idle           ( Reverse text )
81 // 023 ETB End of transmission block  (Decent, can be assigned)
82 // 024 CAN Cancel                     (Should not be assigned: terminal control)
83 // 025 EM  End of medium              (Decent, can be assigned)
84 // 026 SUB Substitute                 (Should not be assigned: terminal control)
85 // 027 ESC Escape                     (Should not be assigned: terminal control)
86 // 028 FS  File separator             (Excellent, should be used as first candidate)
87 // 029 GS  Group separator            ( ICONS Escape: beginning of a word )
88 // 030 RS  Record separator           ( CRYPT Escape: only beginning of the message )
89 // 031 US  Unit separator             ( Underline text )
90 
91 //
92 // mIrc control codes
93 //
94 //31 (0001 1111) US (Unit separator)
95 //2  (0000 0010) STX (Start of text)
96 //15 (0000 1111) SI (Shift in)
97 //22 (0001 0110) SYN (Synchronous idle)
98 //3  (0000 0011) ETX (End of text)
99 
100 // FIXME: Recent versions of mIrc use 29 as Italic text escape.
101 //        This collides with our icon escape and creates a backward compatibility problem if we want to follow mIrc.
102 
103 //
104 // Irc control codes
105 //
106 //1 (0000 0001) SOH (Start of heading)
107 
108 //
109 // KVirc added control codes
110 //
111 //30 (0001 1110) RS (Record separator)
112 //29 (0001 1101) GS (Group separator)
113 
114 /**
115 * \namespace KviControlCodes
116 * \brief Holds all text control code KVIrc uses
117 */
118 namespace KviControlCodes
119 {
120 	/**
121 	* \enum Color
122 	* \brief Contains mIRC color codes
123 	*/
124 	enum Color
125 	{
126 		White = 0,         /**< White */
127 		Black = 1,         /**< Black */
128 		DarkBlue = 2,      /**< Dark blue */
129 		DarkGreen = 3,     /**< Dark green */
130 		Red = 4,           /**< Red */
131 		DarkRed = 5,       /**< Dark red */
132 		DarkViolet = 6,    /**< Dark violet */
133 		Orange = 7,        /**< Orange */
134 		Yellow = 8,        /**< Yellow */
135 		LightGreen = 9,    /**< Light green */
136 		BlueMarine = 10,   /**< Blue marine */
137 		LightBlue = 11,    /**< Light blue */
138 		Blue = 12,         /**< Blue */
139 		LightViolet = 13,  /**< Light violet */
140 		DarkGray = 14,     /**< Dark gray */
141 		LightGray = 15,    /**< Light gray */
142 		Transparent = 100, /**< Transparent, non standard color code for KviIrcView */
143 		NoChange = 101     /**< No change, non standard color code for KviIrcView */
144 	};
145 
146 	/**
147 	* \enum Control
148 	* \brief Contains mIRC control codes
149 	*/
150 	enum Control
151 	{
152 		CTCP = 0x01,        /**< CTCP, IRC control code */
153 		Bold = 0x02,        /**< Bold */
154 		Color = 0x03,       /**< Color */
155 		Escape = 0x04,      /**< Escape, totally artificial and internal to KviIrcView */
156 		UnEscape = 0x05,    /**< Unescape, totally artificial and internal to KviIrcView */
157 		UnIcon = 0x06,      /**< Unicon, totally artificial and internal to KviIrcView */
158 		ArbitraryBreak = UnIcon, /**< Arbitrary block break, totally artificial and internal to KviIrcView */
159 		Reset = 0x0f,       /**< Reset */
160 		Reverse = 0x16,     /**< Reverse */
161 		Icon = 0x1c,        /**< Icon, KVIrc control code */
162 		Italic = 0x1d,      /**< Italic */
163 		CryptEscape = 0x1e, /**< Crypt escape, KVIrc control code */
164 		Underline = 0x1f    /**< Underline */
165 	};
166 
167 	/**
168 	* \brief Removes control bytes from the given string
169 	* \param szData The string to clean
170 	* \return QString
171 	*/
172 	KVILIB_API QString stripControlBytes(const QString & szData);
173 
174 	KVILIB_API const kvi_wchar_t * getColorBytesW(const kvi_wchar_t * pwData, unsigned char * pcByte1, unsigned char * pcByte2);
175 
176 	KVILIB_API unsigned int getUnicodeColorBytes(const QString & szData, unsigned int iChar, unsigned char * pcByte1, unsigned char * pcByte2);
177 #if 0
178 	extern KVILIB_API const char * getColorBytes(const char * pcData, unsigned char * pcByte1, unsigned char * pcByte2);
179 	inline const QChar * getUnicodeColorBytes(const QChar * pData, unsigned char * pcByte1, unsigned char * pcByte2)
180 		{ return (QChar *)getColorBytesW((const kvi_wchar_t *)pData,pcByte1,pcByte2); }
181 #endif
182 
183 	KVILIB_API kvi_u32_t getExtendedColor(int index);
184 }
185 
186 #endif //_KVI_CONTROLCODES_H_
187