1
/* Copyright (C) 2000 Damir Zucic */
3
/*=============================================================================
8
Refresh the input window.
11
(1) Pointer to GUIS structure.
12
(2) Pointer to RuntimeS structure, with command strings.
15
(1) Input window redrawn.
21
========includes:============================================================*/
28
#include <X11/Xutil.h>
30
#include <X11/Xatom.h>
35
/*======refresh the input window:============================================*/
37
int InputRefresh_ (GUIS *guiSP, RuntimeS *runtimeSP)
39
int comm_length, carriage_pos, the_rest;
40
char left_partA[COMMSTRINGSIZE];
41
char right_partA[COMMSTRINGSIZE];
42
int full_left_part_width, left_part_width, max_width;
44
static char *left_partP;
48
/* Refresh the input window: */
49
XSetForeground (guiSP->displaySP, guiSP->theGCA[0],
50
guiSP->input_winS.bg_colorID);
51
XFillRectangle (guiSP->displaySP, guiSP->input_winS.ID, guiSP->theGCA[0],
52
0, 0, guiSP->input_winS.width, guiSP->input_winS.height);
54
/* Prepare the text color: */
55
XSetForeground (guiSP->displaySP, guiSP->theGCA[0],
56
guiSP->output_winS.fg_colorID);
58
/* Draw the current message (this is often empty): */
60
y0 = guiSP->input_winS.height -
61
guiSP->input_winS.text_line_height -
62
guiSP->input_winS.half_font_height;
63
XDrawString (guiSP->displaySP, guiSP->input_winS.ID, guiSP->theGCA[0],
65
runtimeSP->messageA, runtimeSP->message_length);
67
/* Copy the command string length and carriage position: */
68
comm_length = runtimeSP->command_length;
69
carriage_pos = runtimeSP->carriage_position;
71
/* Prepare the left and right part of the command string: */
72
strncpy (left_partA, runtimeSP->curr_commandA, carriage_pos);
73
left_partA[carriage_pos] = '\0';
74
the_rest = comm_length - carriage_pos;
75
strncpy (right_partA, runtimeSP->curr_commandA + carriage_pos, the_rest);
76
right_partA[the_rest] = '\0';
78
/* Prepare the left part width: */
79
full_left_part_width = XTextWidth (guiSP->main_winS.fontSP,
80
left_partA, carriage_pos) + TEXTMARGIN;
82
/* Initialize the pointer to the left part: */
83
left_partP = left_partA;
85
/* The maximal allowed width of the left */
86
/* part (some space left for the cursor): */
87
max_width = (int) guiSP->input_winS.width - 3;
89
/* If the left part is too wide, skip some characters: */
90
if (full_left_part_width > max_width)
92
for (i = 0; i < COMMSTRINGSIZE - 1; i++)
94
left_part_width = full_left_part_width -
95
runtimeSP->left_part_widthA[i];
96
if (left_part_width <= max_width)
98
left_partP = left_partA + i + 1;
103
else left_part_width = full_left_part_width;
105
/* The length of the remainder: */
106
left_part_length = strlen (left_partP);
108
/* Draw the left part to the bottom of input window: */
109
y0 = guiSP->input_winS.height - guiSP->input_winS.half_font_height;
110
XDrawString (guiSP->displaySP, guiSP->input_winS.ID, guiSP->theGCA[0],
111
x0, y0, left_partP, left_part_length);
113
/* Draw the keyboard cursor (showing the "carriage" position): */
114
x0 = left_part_width + 1;
115
y1 = guiSP->input_winS.height -
116
guiSP->input_winS.text_line_height -
117
guiSP->input_winS.quarter_font_height;
118
y2 = guiSP->input_winS.height - 2;
119
XDrawLine (guiSP->displaySP, guiSP->input_winS.ID, guiSP->theGCA[0],
121
XDrawLine (guiSP->displaySP, guiSP->input_winS.ID, guiSP->theGCA[0],
122
x0 + 1, y1, x0 + 1, y2);
124
/* Draw the right part of command string: */
125
x0 = left_part_width + 3;
126
XDrawString (guiSP->displaySP, guiSP->input_winS.ID, guiSP->theGCA[0],
127
x0, y0, right_partA, strlen (right_partA));
129
/* Return positive value on success: */
133
/*===========================================================================*/