5 * $Log: tableVisi.h,v $
6 * Revision 1.5 1995/12/22 22:43:08 tamches
11 * Revision 1.4 1995/12/19 00:44:39 tamches
12 * changeUnitsLabel now takes in a string &, not char *
14 * Revision 1.3 1995/12/03 21:09:27 newhall
15 * changed units labeling to match type of data being displayed
17 * Revision 1.2 1995/11/08 21:47:04 tamches
18 * removed some unused members
20 * Revision 1.1 1995/11/04 00:45:19 tamches
21 * First version of new table visi
25 #ifndef _TABLE_VISI_H_
26 #define _TABLE_VISI_H_
42 vector<tvMetric> metrics;
44 vector<unsigned> indirectMetrics; // for sorting
45 vector<unsigned> indirectFoci; // for sorting
46 vector< vector<tvCell> > cells; // array[metrics] of array[foci]
47 bool focusLongNameMode;
49 char conversionString[100]; // e.g. "%.5g" if numSigFigs is currently 5
52 enum selection {rowOnly, colOnly, cell, none};
55 selection theSelection;
56 // The value of "theSelection" guides how to interpret the following 2 vrbles;
57 // in particular, one or both may be undefined. Question: should these be
58 // in sorted or "real" order. Currently, it's sorted.
62 Tk_Window theTkWindow;
63 Display *theDisplay; // needed only in the destructor
64 Pixmap offscreenPixmap;
65 XColor *backgroundColor; // for erasing the offscreen pixmap...
66 GC backgroundGC; // ...same
67 XColor *highlightedBackgroundColor; // for drawing selected cells...
68 GC highlightedBackgroundGC; // ...same
70 int offset_x, offset_y; // <= 0
71 int all_cells_width, all_cells_height; // # pixels needed in horiz, vert sb's
73 XFontStruct *metricNameFont, *metricUnitsFont, *focusNameFont, *cellFont;
74 unsigned maxFocusNamePixWidth; // max of foci[].getNamePixWidth()
76 XColor *lineColor; GC lineColorGC;
77 XColor *metricNameColor; GC metricNameGC;
78 XColor *metricUnitsColor; GC metricUnitsGC;
79 XColor *focusNameColor; GC focusNameGC;
80 XColor *cellColor; GC cellGC;
84 void updateConversionString();
85 void double2string(char *, double) const;
87 XFontStruct *myXLoadQueryFont(const string &fontName) const;
88 XColor *myTkGetColor(Tcl_Interp *, const string &colorName) const;
89 void resizeScrollbars(Tcl_Interp *);
90 bool adjustHorizSBOffset(Tcl_Interp *interp);
91 bool adjustVertSBOffset(Tcl_Interp *interp);
93 // private metric helper functions
94 void drawMetricNames(Drawable) const;
95 void drawMetricVertLine(Drawable, int x) const;
96 unsigned getMetricAreaPixHeight() const;
97 unsigned getMetricNameBaseline() const; // assumes 0 is top y coord of metric area
98 unsigned getMetricUnitsBaseline() const; // assumes 0 is top y coord of metric area
99 bool xpix2col(int x, unsigned &theColumn) const;
100 // sets theColumn and returns true iff the pixel is within some column.
101 // note that x should _not_ be adjusted for scrollbar; we take care of that
102 int metric2xpix(unsigned theColumn) const;
103 // returns the x coord where this column starts. Do not adjust for the
104 // scrollbar; we do that for you.
106 // private focus helper functions
107 void drawFocusNames(Drawable) const;
108 void drawFocusHorizLine(Drawable, int y) const;
109 unsigned getFocusLinePixHeight() const;
110 unsigned getVertPixFocusTop2Baseline() const;
111 unsigned getHorizPixBeforeFocusName() const {return 3;}
112 unsigned getFocusAreaPixWidth() const;
113 bool ypix2row(int y, unsigned &theRow) const;
114 // sets therow and returns true iff the y coord is w/in some row.
115 // note that y should _not_ be adjusted for scrollbar; we take care of that.
116 int focus2ypix(unsigned theRow) const;
117 // returns the y coord where this row starts. Do not adjust for the scrollbar;
118 // we do that for you.
120 // private cell helper functions
121 void drawCells(Drawable) const;
122 void drawCells1Col(Drawable, int middle_x, int top_y,
123 const vector<tvCell> &thisMetricCells) const;
124 unsigned getVertPixCellTop2Baseline() const;
126 // helper function for drawing
127 void drawHighlightBackground(Drawable) const;
129 // helper functions for sorting
130 void sortMetrics(int left, int right);
131 int partitionMetrics(int left, int right);
133 void sortFoci(int left, int right);
134 void sortFociByValues(const vector<tvCell> &theMetricColumn, int left, int right);
135 int partitionFoci(int left, int right);
136 int partitionFociByValues(const vector<tvCell> &, int left, int right);
139 tableVisi(Tcl_Interp *interp,
141 const string &metricNameFontName,
142 const string &metricUnitsFontName,
143 const string &focusFontName,
144 const string &cellFontName,
145 const string &iLineColorName,
146 const string &iMetricColorName,
147 const string &iMetricUnitsColorName,
148 const string &iFocusColorName,
149 const string &cellColorName,
150 const string &backgroundColorName,
151 const string &highlightedBackgroundColorName,
157 void resize(Tcl_Interp *); // does not redraw
159 void draw(bool xsynch) const;
161 unsigned getNumMetrics() const {return metrics.size();}
162 unsigned getNumFoci() const {return foci.size();}
164 void clearMetrics(Tcl_Interp *interp);
165 void clearFoci(Tcl_Interp *interp);
167 void addMetric(unsigned iVisiLibMetId,
168 const string &metricName, const string &metricUnits);
169 void addFocus(unsigned iVisiLibFocusId, const string &focusName);
170 void changeUnitsLabel(unsigned which, const string &new_name);
172 // The following routines should be followed by a call to resize(), in order
173 // to make the scrollbars, etc. coherent again:
174 void deleteMetric(unsigned theColumn); // theColumn is in sorted order
175 void deleteFocus(unsigned theRow); // theRow is in sorted order
177 void sortMetrics(); // may change selectedCol, as appropriate.
178 void unsortMetrics(); // may change selectedCol, as appropriate.
180 void sortFoci(); // may change selectedRow, as appropriate
181 bool sortFociByValues(); // may change selectedRow, as appropriate
182 // If a column (metric) is selected, sort all foci according to that col.
183 // Returns true iff successful (if exactly 1 metric col was selected)
184 void unsortFoci(); // may change selectedRow, as appopriate
186 bool setFocusNameMode(Tcl_Interp *interp, bool longNameMode);
187 // returns true iff any changes
189 bool setSigFigs(unsigned);
190 // returns true iff any changes. Can change column widths.
192 void invalidateCell(unsigned theMetric, unsigned theFocus);
193 // theMetric and theFocus are _not_ in sorted order; they're the real thing
194 void setCellValidData(unsigned theMetric, unsigned theFocus, double data);
195 // theMetric and theFocus are _not_ in sorted order; they're the real thing
197 int get_offset_x() const {return offset_y;}
198 int get_offset_y() const {return offset_y;}
200 int get_total_cell_x_pix() const {return all_cells_width;}
201 int get_total_cell_y_pix() const {return all_cells_height;}
203 int get_visible_x_pix() const {return Tk_Width(theTkWindow);}
204 int get_visible_y_pix() const {return Tk_Height(theTkWindow);}
206 bool adjustHorizSBOffset(Tcl_Interp *, float newFirst);
207 bool adjustVertSBOffset(Tcl_Interp *, float newFirst);
209 bool processClick(int x, int y);
210 // make a row, col, or cell selection or unselection, based on coords relative
211 // to the upper-left pixel of the table (i.e. _not_ adjusted for scrollbar
212 // settings; we do that for you)
213 // returns true iff any changes were made, in which case outside code should
214 // probably launch a redraw operation...
215 selection getSelection() const {return theSelection;}
216 unsigned getSelectedMetId() const {
217 assert(theSelection == cell || theSelection == colOnly);
218 return col2MetId(selectedCol);
220 unsigned getSelectedCol() const {
221 assert(theSelection == cell || theSelection == colOnly);
225 unsigned getSelectedResId() const {
226 assert(theSelection == cell || theSelection == rowOnly);
227 return row2ResId(selectedRow);
229 unsigned getSelectedRow() const {
230 assert(theSelection == cell || theSelection == rowOnly);
234 unsigned col2MetId(unsigned col) const {
235 return metrics[indirectMetrics[col]].getVisiLibId();
237 unsigned row2ResId(unsigned row) const {
238 return foci[indirectFoci[row]].getVisiLibId();
241 unsigned metric2MetId(unsigned theMetric) const {
242 return metrics[theMetric].getVisiLibId();
244 unsigned focus2ResId(unsigned theFocus) const {
245 return foci[theFocus].getVisiLibId();
248 void deleteSelection();