File: input_refresh.c

package info (click to toggle)
garlic 1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,516 kB
  • sloc: ansic: 52,465; makefile: 2,254
file content (135 lines) | stat: -rw-r--r-- 3,959 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* Copyright (C) 2000 Damir Zucic */

/*=============================================================================

				input_refresh.c

Purpose:
	Refresh the input window.

Input:
	(1) Pointer to GUIS structure.
	(2) Pointer to RuntimeS structure, with command strings.

Output:
	(1) Input window redrawn.
	(2) Return value.

Return value:
	(1) Positive always.

========includes:============================================================*/

#include <stdio.h>

#include <string.h>

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>

#include "defines.h"
#include "typedefs.h"

/*======refresh the input window:============================================*/

int InputRefresh_ (GUIS *guiSP, RuntimeS *runtimeSP)
{
int			comm_length, carriage_pos, the_rest;
char			left_partA[COMMSTRINGSIZE];
char			right_partA[COMMSTRINGSIZE];
int			full_left_part_width, left_part_width, max_width;
int			i;
static char		*left_partP;
int			left_part_length;
int			x0, y0, y1, y2;

/* Refresh the input window: */
XSetForeground (guiSP->displaySP, guiSP->theGCA[0],
		guiSP->input_winS.bg_colorID);
XFillRectangle (guiSP->displaySP, guiSP->input_winS.ID, guiSP->theGCA[0],
		0, 0, guiSP->input_winS.width, guiSP->input_winS.height);

/* Prepare the text color: */
XSetForeground (guiSP->displaySP, guiSP->theGCA[0],
		guiSP->output_winS.fg_colorID);

/* Draw the current message (this is often empty): */
x0 = TEXTMARGIN;
y0 = guiSP->input_winS.height -
     guiSP->input_winS.text_line_height -
     guiSP->input_winS.half_font_height;
XDrawString (guiSP->displaySP, guiSP->input_winS.ID, guiSP->theGCA[0],
	     x0, y0,
	     runtimeSP->messageA, runtimeSP->message_length);

/* Copy the command string length and carriage position: */
comm_length  = runtimeSP->command_length;
carriage_pos = runtimeSP->carriage_position;

/* Prepare the left and right part of the command string: */
strncpy (left_partA, runtimeSP->curr_commandA, carriage_pos);
left_partA[carriage_pos] = '\0';
the_rest = comm_length - carriage_pos;
strncpy (right_partA, runtimeSP->curr_commandA + carriage_pos, the_rest);
right_partA[the_rest] = '\0';

/* Prepare the left part width: */
full_left_part_width = XTextWidth (guiSP->main_winS.fontSP,
				   left_partA, carriage_pos) + TEXTMARGIN;

/* Initialize the pointer to the left part: */
left_partP = left_partA;

/* The maximal allowed width  of the left */
/* part (some space left for the cursor): */
max_width = (int) guiSP->input_winS.width - 3;

/* If the left part is too wide, skip some characters: */
if (full_left_part_width > max_width)
	{
	for (i = 0; i < COMMSTRINGSIZE - 1; i++)
		{
		left_part_width = full_left_part_width -
				  runtimeSP->left_part_widthA[i];
		if (left_part_width <= max_width)
			{
			left_partP = left_partA + i + 1;
			break;
			}
		}
	}
else left_part_width = full_left_part_width;

/* The length of the remainder: */
left_part_length = strlen (left_partP);

/* Draw the left part to the bottom of input window: */
y0 = guiSP->input_winS.height - guiSP->input_winS.half_font_height;
XDrawString (guiSP->displaySP, guiSP->input_winS.ID, guiSP->theGCA[0],
	     x0, y0, left_partP, left_part_length);

/* Draw the keyboard cursor (showing the "carriage" position): */
x0 = left_part_width + 1;
y1 = guiSP->input_winS.height -
     guiSP->input_winS.text_line_height -
     guiSP->input_winS.quarter_font_height;
y2 = guiSP->input_winS.height - 2;
XDrawLine (guiSP->displaySP, guiSP->input_winS.ID, guiSP->theGCA[0],
	   x0, y1, x0, y2);
XDrawLine (guiSP->displaySP, guiSP->input_winS.ID, guiSP->theGCA[0],
	   x0 + 1, y1, x0 + 1, y2);

/* Draw the right part of command string: */
x0 = left_part_width + 3;
XDrawString (guiSP->displaySP, guiSP->input_winS.ID, guiSP->theGCA[0],
	     x0, y0, right_partA, strlen (right_partA));

/* Return positive value on success: */
return 1;
}

/*===========================================================================*/