1 /**************************************************************************
2 ** (c) Copyright 1999, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
6 ** FILE NAME : table.cpp
7 ** SYSTEM NAME : AXE - Andromeda X-windows Encapsulation
8 ** VERSION NUMBER : $Revision: 1.1 $
10 ** DESCRIPTION : Implementation of table_view class
15 ***************************************************************************
16 ** ADMINISTRATIVE INFORMATION *
17 ********************************
18 ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
19 ** CREATION DATE : Aug 26, 1999
20 ** LAST UPDATE : Aug 26, 1999
22 **************************************************************************/
24 /*****************************
26 Revision 1.1 2002-07-25 08:01:27 arjen
27 First checkin, AXE release 0.2
29 *****************************/
31 static const char *RCSID = "$Id: table.cpp,v 1.1 2002-07-25 08:01:27 arjen Exp $";
35 void table_view::redraw(void)
39 unsigned desired_height;
40 unsigned font_height = 20; // For the time being...
43 g.SetLineAttributes(2);
44 XDrawLine(stddpy, ID(), g, 0, 20, w, 20);
46 // Determine if we need the scrollbar
48 desired_height = (nr_rows + 1) * font_height;
49 if (desired_height > h)
51 unsigned visible_rows;
53 visible_rows = (h - font_height) / font_height;
54 Vscroll->SetSizes(nr_rows, visible_rows);
55 Vscroll->Move(w-18, font_height+1);
56 Vscroll->Resize(16, h - font_height - 2);
61 // All rows fit in the window
68 g.SetLineAttributes(0);
70 for (i = 0; i < nr_columns; i++)
73 XDrawLine(stddpy, ID(), g, x, 0, x, h);
77 g.SetLineAttributes(0, LineOnOffDash);
78 XSetDashes(stddpy, g, 0, "\001\001", 2);
79 for (j = 0; j < nr_rows && (unsigned)y < h; j++)
82 XDrawLine(stddpy, ID(), g, 0, y, w, y);
87 g.SetFont(header_font);
88 x = 2; // small margin
89 for (i = 0; i < nr_columns; i++)
91 if ((char *)(Head[i].title))
93 XDrawString(stddpy, ID(), g, x, 15, Head[i].title, ~Head[i].title);
98 // Draw the cells, depending on the scroll position.
100 g.SetFont(cell_font);
102 for (i = *Vscroll; i < nr_rows && (unsigned)y < h; i++)
105 for (j = 0; j < nr_columns; j++)
107 XClearArea(stddpy, ID(), x, y - 14, Head[j].width - 2,
108 font_height -2, False);
109 if (i == selected_row)
111 XFillRectangle(stddpy, ID(), g, x, y - 14, Head[j].width - 2,
113 g.SetForeground(stddpy.White());
115 if ((char *)(Cells[i][j]))
117 int text_x, text_width;
119 text_width = cell_font.TextWidth(Cells[i][j]);
120 switch (Head[j].alignment)
126 text_x = x + (Head[j].width - text_width) / 2;
129 text_x = x + Head[j].width - text_width - 4;
132 XDrawString(stddpy, ID(), g, text_x, y, Cells[i][j], ~Cells[i][j]);
134 g.SetForeground(stddpy.Black());
141 int table_view::EV_ButtonPress(XButtonEvent ev)
143 unsigned font_height = 20; // Should be obtained from cell_font
146 if ((unsigned)ev.y > font_height)
150 selected = (ev.y - font_height) / font_height + *Vscroll;
151 if (selected < nr_rows)
153 selected_row = selected;
155 ParentMessage(TABLE_ROW_SELECT);
161 void table_view::ChildMessage(win_message &msg)
163 if (msg.msg_id == SCROLL_POSITIONED)