]> git.saurik.com Git - wxWidgets.git/blob - utils/tex2rtf/src/table.cpp
compilation fix for genericTreeCtrl-only stuff
[wxWidgets.git] / utils / tex2rtf / src / table.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: table.cpp
3 // Purpose: Utilities for manipulating tables
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/01/99
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/wx.h"
25 #endif
26
27
28 #include <wx/hash.h>
29
30 #ifdef new
31 #undef new
32 #endif
33
34 #if wxUSE_IOSTREAMH
35 #include <iostream.h>
36 #include <fstream.h>
37 #else
38 #include <iostream>
39 #include <fstream>
40 #endif
41
42 #include <ctype.h>
43 #include "tex2any.h"
44 #include "table.h"
45
46 ColumnData TableData[40];
47 bool inTabular = FALSE;
48
49 bool startRows = FALSE;
50 bool tableVerticalLineLeft = FALSE;
51 bool tableVerticalLineRight = FALSE;
52 int noColumns = 0; // Current number of columns in table
53 int ruleTop = 0;
54 int ruleBottom = 0;
55 int currentRowNumber = 0;
56
57 /*
58 * Parse table argument
59 *
60 */
61
62 bool ParseTableArgument(char *value)
63 {
64 noColumns = 0;
65 int i = 0;
66 int len = strlen(value);
67 bool isBorder = FALSE;
68 while (i < len)
69 {
70 int ch = value[i];
71 if (ch == '|')
72 {
73 i ++;
74 isBorder = TRUE;
75 }
76 else if (ch == 'l')
77 {
78 TableData[noColumns].leftBorder = isBorder;
79 TableData[noColumns].rightBorder = FALSE;
80 TableData[noColumns].justification = 'l';
81 TableData[noColumns].width = 2000; // Estimate
82 TableData[noColumns].absWidth = FALSE;
83 // TableData[noColumns].spacing = ??
84 noColumns ++;
85 i ++;
86 isBorder = FALSE;
87 }
88 else if (ch == 'c')
89 {
90 TableData[noColumns].leftBorder = isBorder;
91 TableData[noColumns].rightBorder = FALSE;
92 TableData[noColumns].justification = 'c';
93 TableData[noColumns].width = defaultTableColumnWidth; // Estimate
94 TableData[noColumns].absWidth = FALSE;
95 // TableData[noColumns].spacing = ??
96 noColumns ++;
97 i ++;
98 isBorder = FALSE;
99 }
100 else if (ch == 'r')
101 {
102 TableData[noColumns].leftBorder = isBorder;
103 TableData[noColumns].rightBorder = FALSE;
104 TableData[noColumns].justification = 'r';
105 TableData[noColumns].width = 2000; // Estimate
106 TableData[noColumns].absWidth = FALSE;
107 // TableData[noColumns].spacing = ??
108 noColumns ++;
109 i ++;
110 isBorder = FALSE;
111 }
112 else if (ch == 'p')
113 {
114 i ++;
115 int j = 0;
116 char numberBuf[50];
117 ch = value[i];
118 if (ch == '{')
119 {
120 i++;
121 ch = value[i];
122 }
123
124 while ((i < len) && (isdigit(ch) || ch == '.'))
125 {
126 numberBuf[j] = ch;
127 j ++;
128 i ++;
129 ch = value[i];
130 }
131 // Assume we have 2 characters for units
132 numberBuf[j] = value[i];
133 j ++; i++;
134 numberBuf[j] = value[i];
135 j ++; i++;
136 numberBuf[j] = 0;
137 if (value[i] == '}') i++;
138
139 TableData[noColumns].leftBorder = isBorder;
140 TableData[noColumns].rightBorder = FALSE;
141 TableData[noColumns].justification = 'l';
142 TableData[noColumns].width = 20*ParseUnitArgument(numberBuf);
143 TableData[noColumns].absWidth = TRUE;
144 // TableData[noColumns].spacing = ??
145 noColumns ++;
146 isBorder = FALSE;
147 }
148 else
149 {
150 char *buf = new char[strlen(value) + 80];
151 sprintf(buf, "Tabular first argument \"%s\" too complex!", value);
152 OnError(buf);
153 delete[] buf;
154 return FALSE;
155 }
156 }
157 if (isBorder)
158 TableData[noColumns-1].rightBorder = TRUE;
159 return TRUE;
160 }