Subversion Repositories SvarDOS

Rev

Rev 1332 | Rev 1334 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1332 Rev 1333
Line 38... Line 38...
38
 
38
 
39
 
39
 
40
/*****************************************************************************
40
/*****************************************************************************
41
 * global variables and definitions                                          *
41
 * global variables and definitions                                          *
42
 *****************************************************************************/
42
 *****************************************************************************/
43
#define COL_TXT        0
-
 
44
#define COL_STATUSBAR1 1
-
 
45
#define COL_STATUSBAR2 2
-
 
46
#define COL_STATUSBAR3 3
-
 
47
#define COL_SCROLLBAR  4
-
 
48
#define COL_MSG        5
-
 
49
#define COL_ERR        6
-
 
50
 
43
 
51
/* preload the mono scheme (to be overloaded at runtime if color adapter present) */
44
/* preload the mono scheme (to be overloaded at runtime if color adapter present) */
-
 
45
// 11 524
52
static unsigned char scheme[] = {0x07, 0x70, 0x70, 0xf0, 0x70, 0x70, 0xf0};
46
static unsigned char SCHEME_TEXT   = 0x07,
-
 
47
                     SCHEME_STBAR1 = 0x70,
-
 
48
                     SCHEME_STBAR2 = 0x70,
-
 
49
                     SCHEME_STBAR3 = 0xf0,
-
 
50
                     SCHEME_SCROLL = 0x70,
-
 
51
                     SCHEME_MSG    = 0x70,
-
 
52
                     SCHEME_ERR    = 0xf0;
53
 
53
 
54
static unsigned char screenw, screenh;
54
static unsigned char screenw, screenh;
55
 
55
 
56
static struct {
56
static struct {
57
    unsigned char from;
57
    unsigned char from;
Line 118... Line 118...
118
  maxlen--; /* make room for the nul terminator */
118
  maxlen--; /* make room for the nul terminator */
119
 
119
 
120
  y = screenh - 1;
120
  y = screenh - 1;
121
 
121
 
122
  /* print query string */
122
  /* print query string */
123
  x = mdr_cout_str(y, 0, query, scheme[COL_STATUSBAR3], 40);
123
  x = mdr_cout_str(y, 0, query, SCHEME_STBAR3, 40);
124
  mdr_cout_char_rep(y, x++, ' ', scheme[COL_STATUSBAR3], screenw - x);
124
  mdr_cout_char_rep(y, x++, ' ', SCHEME_STBAR3, screenw - x);
125
 
125
 
126
  for (;;) {
126
  for (;;) {
127
    mdr_cout_locate(y, x + len);
127
    mdr_cout_locate(y, x + len);
128
    k = keyb_getkey();
128
    k = keyb_getkey();
129
 
129
 
Line 134... Line 134...
134
      return;
134
      return;
135
    }
135
    }
136
 
136
 
137
    if ((k == 0x08) && (len > 0)) { /* BKSPC */
137
    if ((k == 0x08) && (len > 0)) { /* BKSPC */
138
      len--;
138
      len--;
139
      mdr_cout_char(y, x + len, ' ', scheme[COL_STATUSBAR3]);
139
      mdr_cout_char(y, x + len, ' ', SCHEME_STBAR3);
140
      continue;
140
      continue;
141
    }
141
    }
142
 
142
 
143
    if ((k <= 0xff) && (k >= ' ') && (len < maxlen)) {
143
    if ((k <= 0xff) && (k >= ' ') && (len < maxlen)) {
144
      mdr_cout_char(y, x + len, k, scheme[COL_STATUSBAR3]);
144
      mdr_cout_char(y, x + len, k, SCHEME_STBAR3);
145
      s[len++] = k;
145
      s[len++] = k;
146
    }
146
    }
147
 
147
 
148
  }
148
  }
149
}
149
}
Line 172... Line 172...
172
  while (db->cursor->prev) db->cursor = db->cursor->prev;
172
  while (db->cursor->prev) db->cursor = db->cursor->prev;
173
  db->curline = 0;
173
  db->curline = 0;
174
}
174
}
175
 
175
 
176
 
176
 
177
static void load_colorscheme(void) {
-
 
178
  scheme[COL_TXT] = 0x17;
-
 
179
  scheme[COL_STATUSBAR1] = 0x70;
-
 
180
  scheme[COL_STATUSBAR2] = 0x78;
-
 
181
  scheme[COL_STATUSBAR3] = 0xf0;
-
 
182
  scheme[COL_SCROLLBAR] = 0x70;
-
 
183
  scheme[COL_MSG] = 0xf0;
-
 
184
  scheme[COL_ERR] = 0x4f;
-
 
185
}
-
 
186
 
-
 
187
 
-
 
188
static void ui_basic(const struct file *db) {
177
static void ui_basic(const struct file *db) {
189
  const char *s = svarlang_strid(0); /* HELP */
178
  const char *s = svarlang_strid(0); /* HELP */
190
  unsigned char helpcol = screenw - (strlen(s) + 4);
179
  unsigned char helpcol = screenw - (strlen(s) + 4);
191
 
180
 
192
  /* fill status bar with background (without modflag as it is refreshed by ui_refresh) */
181
  /* fill status bar with background (without modflag as it is refreshed by ui_refresh) */
193
  mdr_cout_char_rep(screenh - 1, 1, ' ', scheme[COL_STATUSBAR1], screenw - 1);
182
  mdr_cout_char_rep(screenh - 1, 1, ' ', SCHEME_STBAR1, screenw - 1);
194
 
183
 
195
  /* filename */
184
  /* filename */
196
  {
185
  {
197
    const char *fn = db->fname;
186
    const char *fn = db->fname;
198
    if (*fn == 0) fn = svarlang_str(0, 1);
187
    if (*fn == 0) fn = svarlang_str(0, 1);
199
    mdr_cout_str(screenh - 1, 1, fn, scheme[COL_STATUSBAR1], screenw);
188
    mdr_cout_str(screenh - 1, 1, fn, SCHEME_STBAR1, screenw);
200
  }
189
  }
201
 
190
 
202
  /* eol type */
191
  /* eol type */
203
  {
192
  {
204
    const char *eoltype = "CRLF";
193
    const char *eoltype = "CRLF";
205
    if (db->lfonly) eoltype = "LF";
194
    if (db->lfonly) eoltype = "LF";
206
    mdr_cout_str(screenh - 1, helpcol - 5, eoltype, scheme[COL_STATUSBAR1], 5);
195
    mdr_cout_str(screenh - 1, helpcol - 5, eoltype, SCHEME_STBAR1, 5);
207
  }
196
  }
208
 
197
 
209
  mdr_cout_str(screenh - 1, helpcol, " F1=", scheme[COL_STATUSBAR2], 40);
198
  mdr_cout_str(screenh - 1, helpcol, " F1=", SCHEME_STBAR2, 40);
210
  mdr_cout_str(screenh - 1, helpcol + 4, s, scheme[COL_STATUSBAR2], 40);
199
  mdr_cout_str(screenh - 1, helpcol + 4, s, SCHEME_STBAR2, 40);
211
}
200
}
212
 
201
 
213
 
202
 
214
static void ui_msg(const char *msg1, const char *msg2, unsigned char attr) {
203
static void ui_msg(const char *msg1, const char *msg2, unsigned char attr) {
215
  unsigned short x, y, msglen, i;
204
  unsigned short x, y, msglen, i;
Line 238... Line 227...
238
#define MAXLINLEN 35
227
#define MAXLINLEN 35
239
  unsigned short i, offset;
228
  unsigned short i, offset;
240
  offset = (screenw - MAXLINLEN + 2) >> 1;
229
  offset = (screenw - MAXLINLEN + 2) >> 1;
241
  mdr_cout_cursor_hide();
230
  mdr_cout_cursor_hide();
242
  for (i = 2; i <= 15; i++) {
231
  for (i = 2; i <= 15; i++) {
243
    mdr_cout_char_rep(i, offset - 2, ' ', scheme[COL_STATUSBAR1], MAXLINLEN + 2);
232
    mdr_cout_char_rep(i, offset - 2, ' ', SCHEME_STBAR1, MAXLINLEN + 2);
244
  }
233
  }
245
 
234
 
246
  mdr_cout_str(3, offset, svarlang_str(0, 0), scheme[COL_STATUSBAR1], MAXLINLEN);
235
  mdr_cout_str(3, offset, svarlang_str(0, 0), SCHEME_STBAR1, MAXLINLEN);
247
  for (i = 0; i <= 4; i++) {
236
  for (i = 0; i <= 4; i++) {
248
    mdr_cout_str(5 + i, offset, svarlang_str(8, i), scheme[COL_STATUSBAR1], MAXLINLEN);
237
    mdr_cout_str(5 + i, offset, svarlang_str(8, i), SCHEME_STBAR1, MAXLINLEN);
249
  }
238
  }
250
  mdr_cout_str(5 + 1 + i, offset, svarlang_str(8, 10), scheme[COL_STATUSBAR1], MAXLINLEN);
239
  mdr_cout_str(5 + 1 + i, offset, svarlang_str(8, 10), SCHEME_STBAR1, MAXLINLEN);
251
 
240
 
252
  /* Press any key */
241
  /* Press any key */
253
  mdr_cout_str(14, offset, svarlang_str(8, 11), scheme[COL_STATUSBAR1], MAXLINLEN);
242
  mdr_cout_str(14, offset, svarlang_str(8, 11), SCHEME_STBAR1, MAXLINLEN);
254
 
243
 
255
  keyb_getkey();
244
  keyb_getkey();
256
  mdr_cout_cursor_show();
245
  mdr_cout_cursor_show();
257
#undef MAXLINLEN
246
#undef MAXLINLEN
258
}
247
}
Line 285... Line 274...
285
      if (l->len - db->xoffset < screenw) {
274
      if (l->len - db->xoffset < screenw) {
286
        limit = l->len;
275
        limit = l->len;
287
      } else {
276
      } else {
288
        limit = db->xoffset + screenw - 1;
277
        limit = db->xoffset + screenw - 1;
289
      }
278
      }
290
      for (i = db->xoffset; i < limit; i++) mdr_cout_char(y, x++, l->payload[i], scheme[COL_TXT]);
279
      for (i = db->xoffset; i < limit; i++) mdr_cout_char(y, x++, l->payload[i], SCHEME_TEXT);
291
    }
280
    }
292
 
281
 
293
    /* write empty spaces until end of line */
282
    /* write empty spaces until end of line */
294
    if (x < screenw - 1) mdr_cout_char_rep(y, x, ' ', scheme[COL_TXT], screenw - 1 - x);
283
    if (x < screenw - 1) mdr_cout_char_rep(y, x, ' ', SCHEME_TEXT, screenw - 1 - x);
295
 
284
 
296
#ifdef DBG_REFRESH
285
#ifdef DBG_REFRESH
297
    mdr_cout_char(y, 0, m, scheme[COL_STATUSBAR1]);
286
    mdr_cout_char(y, 0, m, SCHEME_STBAR1);
298
#endif
287
#endif
299
 
288
 
300
    if (y == screenh - 2) break;
289
    if (y == screenh - 2) break;
301
  }
290
  }
302
 
291
 
303
  /* fill all lines below if empty (and they need to be redrawn) */
292
  /* fill all lines below if empty (and they need to be redrawn) */
304
  if (l == NULL) {
293
  if (l == NULL) {
305
    while ((y < screenh - 1) && (y < uidirty.to)) {
294
    while ((y < screenh - 1) && (y < uidirty.to)) {
306
      mdr_cout_char_rep(y++, 0, ' ', scheme[COL_TXT], screenw - 1);
295
      mdr_cout_char_rep(y++, 0, ' ', SCHEME_TEXT, screenw - 1);
307
    }
296
    }
308
  }
297
  }
309
 
298
 
310
  /* "file changed" flag */
299
  /* "file changed" flag */
311
  {
300
  {
312
    char flg = ' ';
301
    char flg = ' ';
313
    if (db->modflag) flg = '*';
302
    if (db->modflag) flg = '*';
314
    mdr_cout_char(screenh - 1, 0, flg, scheme[COL_STATUSBAR1]);
303
    mdr_cout_char(screenh - 1, 0, flg, SCHEME_STBAR1);
315
  }
304
  }
316
 
305
 
317
  /* scroll bar */
306
  /* scroll bar */
318
  for (y = 0; y < (screenh - 1); y++) {
307
  for (y = 0; y < (screenh - 1); y++) {
319
    mdr_cout_char(y, screenw - 1, SCROLL_CURSOR, scheme[COL_SCROLLBAR]);
308
    mdr_cout_char(y, screenw - 1, SCROLL_CURSOR, SCHEME_SCROLL);
320
  }
309
  }
321
 
310
 
322
  /* scroll cursor */
311
  /* scroll cursor */
323
  if (db->totlines >= screenh) {
312
  if (db->totlines >= screenh) {
324
    unsigned short topline = db->curline - db->cursorposy;
313
    unsigned short topline = db->curline - db->cursorposy;
Line 328... Line 317...
328
      col = topline / (totlines / (screenh - 1));
317
      col = topline / (totlines / (screenh - 1));
329
    } else {
318
    } else {
330
      col = topline * (screenh - 1) / totlines;
319
      col = topline * (screenh - 1) / totlines;
331
    }
320
    }
332
    if (col >= screenh - 1) col = screenh - 2;
321
    if (col >= screenh - 1) col = screenh - 2;
333
    mdr_cout_char(col, screenw - 1, ' ', scheme[COL_SCROLLBAR]);
322
    mdr_cout_char(col, screenw - 1, ' ', SCHEME_SCROLL);
334
  }
323
  }
335
}
324
}
336
 
325
 
337
 
326
 
338
static void check_cursor_not_after_eol(struct file *db) {
327
static void check_cursor_not_after_eol(struct file *db) {
Line 693... Line 682...
693
 
682
 
694
  /* load file */
683
  /* load file */
695
  db = loadfile(fname);
684
  db = loadfile(fname);
696
  if (db == NULL) return(1);
685
  if (db == NULL) return(1);
697
 
686
 
698
  if (mdr_cout_init(&screenw, &screenh)) load_colorscheme();
687
  if (mdr_cout_init(&screenw, &screenh)) {
-
 
688
    /* load color scheme if mdr_cout_init returns a color flag */
-
 
689
    SCHEME_TEXT = 0x17;
-
 
690
    SCHEME_STBAR1 = 0x70;
-
 
691
    SCHEME_STBAR2 = 0x78;
-
 
692
    SCHEME_STBAR3 = 0xf0;
-
 
693
    SCHEME_SCROLL = 0x70;
-
 
694
    SCHEME_MSG = 0xf0;
-
 
695
    SCHEME_ERR = 0x4f;
-
 
696
  }
699
  ui_basic(db);
697
  ui_basic(db);
700
 
698
 
701
  for (;;) {
699
  for (;;) {
702
    int k;
700
    int k;
703
 
701
 
Line 719... Line 717...
719
        ddd[3] = '/';
717
        ddd[3] = '/';
720
        ddd[4] = '0' + db->totlines / 100;
718
        ddd[4] = '0' + db->totlines / 100;
721
        ddd[5] = '0' + (db->totlines % 100) / 10;
719
        ddd[5] = '0' + (db->totlines % 100) / 10;
722
        ddd[6] = '0' + (db->totlines % 10);
720
        ddd[6] = '0' + (db->totlines % 10);
723
        ddd[7] = 0;
721
        ddd[7] = 0;
724
        mdr_cout_str(screenh - 1, 40, ddd, scheme[COL_STATUSBAR1], sizeof(ddd));
722
        mdr_cout_str(screenh - 1, 40, ddd, SCHEME_STBAR1, sizeof(ddd));
725
      }
723
      }
726
#endif
724
#endif
727
 
725
 
728
    k = keyb_getkey();
726
    k = keyb_getkey();
729
 
727
 
Line 752... Line 750...
752
       cursor_eol(db);
750
       cursor_eol(db);
753
 
751
 
754
    } else if (k == 0x1B) { /* ESC */
752
    } else if (k == 0x1B) { /* ESC */
755
      if (db->modflag == 0) break;
753
      if (db->modflag == 0) break;
756
      /* if file has been modified then ask for confirmation */
754
      /* if file has been modified then ask for confirmation */
757
      ui_msg(svarlang_str(0,4), svarlang_str(0,5), scheme[COL_MSG]);
755
      ui_msg(svarlang_str(0,4), svarlang_str(0,5), SCHEME_MSG);
758
      if (keyb_getkey() == '\r') break;
756
      if (keyb_getkey() == '\r') break;
759
 
757
 
760
    } else if (k == 0x0D) { /* ENTER */
758
    } else if (k == 0x0D) { /* ENTER */
761
      unsigned short off = db->xoffset + db->cursorposx;
759
      unsigned short off = db->xoffset + db->cursorposx;
762
      /* add a new line */
760
      /* add a new line */
Line 807... Line 805...
807
        saveres = savefile(db, NULL);
805
        saveres = savefile(db, NULL);
808
      }
806
      }
809
 
807
 
810
      if (saveres == 0) {
808
      if (saveres == 0) {
811
        db->modflag = 0;
809
        db->modflag = 0;
812
        ui_msg(svarlang_str(0, 2), NULL, scheme[COL_MSG]);
810
        ui_msg(svarlang_str(0, 2), NULL, SCHEME_MSG);
813
        mdr_bios_tickswait(11); /* 11 ticks is about 600 ms */
811
        mdr_bios_tickswait(11); /* 11 ticks is about 600 ms */
814
      } else {
812
      } else {
815
        ui_msg(svarlang_str(0, 3), NULL, scheme[COL_ERR]);
813
        ui_msg(svarlang_str(0, 3), NULL, SCHEME_ERR);
816
        mdr_bios_tickswait(36); /* 2s */
814
        mdr_bios_tickswait(36); /* 2s */
817
      }
815
      }
818
 
816
 
819
      ui_basic(db);
817
      ui_basic(db);
820
      ui_refresh(db);
818
      ui_refresh(db);
Line 854... Line 852...
854
          break;
852
          break;
855
        }
853
        }
856
        if ((db->cursorposx == 0) && (db->xoffset == 0)) break;
854
        if ((db->cursorposx == 0) && (db->xoffset == 0)) break;
857
      }
855
      }
858
 
856
 
-
 
857
#ifdef DBG_UNHKEYS
859
    } else { /* UNHANDLED KEY - TODO IGNORE THIS IN PRODUCTION RELEASE */
858
    } else { /* UNHANDLED KEY - TODO IGNORE THIS IN PRODUCTION RELEASE */
860
      char buff[4];
859
      char buff[4];
861
      const char *HEX = "0123456789ABCDEF";
860
      const char *HEX = "0123456789ABCDEF";
862
      buff[0] = HEX[(k >> 8) & 15];
861
      buff[0] = HEX[(k >> 8) & 15];
863
      buff[1] = HEX[(k >> 4) & 15];
862
      buff[1] = HEX[(k >> 4) & 15];
864
      buff[2] = HEX[k & 15];
863
      buff[2] = HEX[k & 15];
865
      mdr_cout_str(screenh - 1, 0, "UNHANDLED KEY: 0x", scheme[COL_STATUSBAR1], 17);
864
      mdr_cout_str(screenh - 1, 0, "UNHANDLED KEY: 0x", SCHEME_STBAR1, 17);
866
      mdr_cout_str(screenh - 1, 17, buff, scheme[COL_STATUSBAR1], 3);
865
      mdr_cout_str(screenh - 1, 17, buff, SCHEME_STBAR1, 3);
867
      keyb_getkey();
866
      keyb_getkey();
868
      break;
867
      break;
-
 
868
#endif
869
    }
869
    }
870
  }
870
  }
871
 
871
 
872
  mdr_cout_close();
872
  mdr_cout_close();
873
 
873