~ubuntu-branches/ubuntu/breezy/garlic/breezy

« back to all changes in this revision

Viewing changes to input_refresh.c

  • Committer: Bazaar Package Importer
  • Author(s): zhaoway
  • Date: 2001-04-24 07:09:13 UTC
  • Revision ID: james.westby@ubuntu.com-20010424070913-uzpupnwdfhmliebz
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 Damir Zucic */
 
2
 
 
3
/*=============================================================================
 
4
 
 
5
                                input_refresh.c
 
6
 
 
7
Purpose:
 
8
        Refresh the input window.
 
9
 
 
10
Input:
 
11
        (1) Pointer to GUIS structure.
 
12
        (2) Pointer to RuntimeS structure, with command strings.
 
13
 
 
14
Output:
 
15
        (1) Input window redrawn.
 
16
        (2) Return value.
 
17
 
 
18
Return value:
 
19
        (1) Positive always.
 
20
 
 
21
========includes:============================================================*/
 
22
 
 
23
#include <stdio.h>
 
24
 
 
25
#include <string.h>
 
26
 
 
27
#include <X11/Xlib.h>
 
28
#include <X11/Xutil.h>
 
29
#include <X11/Xos.h>
 
30
#include <X11/Xatom.h>
 
31
 
 
32
#include "defines.h"
 
33
#include "typedefs.h"
 
34
 
 
35
/*======refresh the input window:============================================*/
 
36
 
 
37
int InputRefresh_ (GUIS *guiSP, RuntimeS *runtimeSP)
 
38
{
 
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;
 
43
int                     i;
 
44
static char             *left_partP;
 
45
int                     left_part_length;
 
46
int                     x0, y0, y1, y2;
 
47
 
 
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);
 
53
 
 
54
/* Prepare the text color: */
 
55
XSetForeground (guiSP->displaySP, guiSP->theGCA[0],
 
56
                guiSP->output_winS.fg_colorID);
 
57
 
 
58
/* Draw the current message (this is often empty): */
 
59
x0 = TEXTMARGIN;
 
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],
 
64
             x0, y0,
 
65
             runtimeSP->messageA, runtimeSP->message_length);
 
66
 
 
67
/* Copy the command string length and carriage position: */
 
68
comm_length  = runtimeSP->command_length;
 
69
carriage_pos = runtimeSP->carriage_position;
 
70
 
 
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';
 
77
 
 
78
/* Prepare the left part width: */
 
79
full_left_part_width = XTextWidth (guiSP->main_winS.fontSP,
 
80
                                   left_partA, carriage_pos) + TEXTMARGIN;
 
81
 
 
82
/* Initialize the pointer to the left part: */
 
83
left_partP = left_partA;
 
84
 
 
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;
 
88
 
 
89
/* If the left part is too wide, skip some characters: */
 
90
if (full_left_part_width > max_width)
 
91
        {
 
92
        for (i = 0; i < COMMSTRINGSIZE - 1; i++)
 
93
                {
 
94
                left_part_width = full_left_part_width -
 
95
                                  runtimeSP->left_part_widthA[i];
 
96
                if (left_part_width <= max_width)
 
97
                        {
 
98
                        left_partP = left_partA + i + 1;
 
99
                        break;
 
100
                        }
 
101
                }
 
102
        }
 
103
else left_part_width = full_left_part_width;
 
104
 
 
105
/* The length of the remainder: */
 
106
left_part_length = strlen (left_partP);
 
107
 
 
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);
 
112
 
 
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],
 
120
           x0, y1, x0, y2);
 
121
XDrawLine (guiSP->displaySP, guiSP->input_winS.ID, guiSP->theGCA[0],
 
122
           x0 + 1, y1, x0 + 1, y2);
 
123
 
 
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));
 
128
 
 
129
/* Return positive value on success: */
 
130
return 1;
 
131
}
 
132
 
 
133
/*===========================================================================*/
 
134
 
 
135