summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2002-04-19 15:46:14 +0200
committerKlaus Schmidinger <vdr@tvdr.de>2002-04-19 15:46:14 +0200
commit69d32fae060c11d8fcc65561e3a67ed50b9bca9b (patch)
tree0cfe27601c44a1564047f14179c2b06ec249199b
parent982dcf09b423d42c24185f1774ea05b9f5e86d3d (diff)
downloadvdr-69d32fae060c11d8fcc65561e3a67ed50b9bca9b.tar.gz
vdr-69d32fae060c11d8fcc65561e3a67ed50b9bca9b.tar.bz2
Improved enhanced string editing
-rw-r--r--interface.h3
-rw-r--r--menu.c51
2 files changed, 30 insertions, 24 deletions
diff --git a/interface.h b/interface.h
index dbfa1bca..914a3834 100644
--- a/interface.h
+++ b/interface.h
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: interface.h 1.24 2001/09/01 15:14:50 kls Exp $
+ * $Id: interface.h 1.25 2002/04/19 13:17:15 kls Exp $
*/
#ifndef __INTERFACE_H
@@ -46,6 +46,7 @@ public:
void SetBitmap(int x, int y, const cBitmap &Bitmap);
void Flush(void);
void SetCols(int *c);
+ const int *GetCols(void) { return cols; }
eDvbFont SetFont(eDvbFont Font);
char *WrapText(const char *Text, int Width, int *Height);
void Write(int x, int y, const char *s, eDvbColor FgColor = clrWhite, eDvbColor BgColor = clrBackground);
diff --git a/menu.c b/menu.c
index 73382d83..899f60ac 100644
--- a/menu.c
+++ b/menu.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: menu.c 1.184 2002/04/16 16:11:40 kls Exp $
+ * $Id: menu.c 1.185 2002/04/19 15:46:14 kls Exp $
*/
#include "menu.h"
@@ -554,39 +554,44 @@ void cMenuEditStrItem::SetHelpKeys(void)
void cMenuEditStrItem::Set(void)
{
char buf[1000];
- int max = 30; // this indicates, how many characters fit on the screen
- // and has to be calculated on the fly (TODO)
const char *fmt = insert && newchar ? "[]%c%s" : "[%c]%s";
if (pos >= 0) {
strncpy(buf, value, pos);
snprintf(buf + pos, sizeof(buf) - pos - 2, fmt, *(value + pos), value + pos + 1);
- if (int(strlen(buf)) <= max)
- SetValue(buf);
- else if (pos + 4 <= max) {
- buf[max - 1] = '>';
- buf[max] = 0;
+ int width = Interface->Width() - Interface->GetCols()[0];
+ if (cDvbApi::PrimaryDvbApi->WidthInCells(buf) <= width) {
+ // the whole buffer fits on the screen
SetValue(buf);
+ return;
}
- else if (buf[pos + 3]) {
- buf[pos + 4 - max] = '<';
- buf[pos + 3] = '>';
- buf[pos + 4] = 0;
- SetValue(buf + pos + 4 - max);
+ width *= cDvbApi::PrimaryDvbApi->CellWidth();
+ width -= cDvbApi::PrimaryDvbApi->Width('>'); // assuming '<' and '>' have the same with
+ int w = 0;
+ int i = 0;
+ int l = strlen(buf);
+ while (i < l && w <= width)
+ w += cDvbApi::PrimaryDvbApi->Width(buf[i++]);
+ if (i >= pos + 4) {
+ // the cursor fits on the screen
+ buf[i - 1] = '>';
+ buf[i] = 0;
+ SetValue(buf);
+ return;
}
- else {
- buf[pos + 3 - max] = '<';
- SetValue(buf + pos + 3 - max);
+ // the cursor doesn't fit on the screen
+ w = 0;
+ if (buf[i = pos + 3]) {
+ buf[i] = '>';
+ buf[i + 1] = 0;
}
+ while (i >= 0 && w <= width)
+ w += cDvbApi::PrimaryDvbApi->Width(buf[i--]);
+ buf[++i] = '<';
+ SetValue(buf + i);
}
- else if (int(strlen(value)) <= max)
+ else
SetValue(value);
- else {
- strncpy(buf, value, max - 1);
- buf[max - 1] = '>';
- buf[max] = 0;
- SetValue(buf);
- }
}
char cMenuEditStrItem::Inc(char c, bool Up)