diff options
Diffstat (limited to 'apps/gui/gwps-common.c')
-rw-r--r-- | apps/gui/gwps-common.c | 135 |
1 files changed, 80 insertions, 55 deletions
diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c index c96b830cf2..078e20ba44 100644 --- a/apps/gui/gwps-common.c +++ b/apps/gui/gwps-common.c | |||
@@ -81,12 +81,10 @@ void gui_wps_statusbar_draw(struct gui_wps *wps, bool force) | |||
81 | { | 81 | { |
82 | bool draw = global_settings.statusbar; | 82 | bool draw = global_settings.statusbar; |
83 | 83 | ||
84 | if(wps->data->wps_sb_tag | 84 | if (wps->data->wps_sb_tag) |
85 | && wps->data->show_sb_on_wps) | 85 | draw = wps->data->show_sb_on_wps; |
86 | draw = true; | 86 | |
87 | else if(wps->data->wps_sb_tag) | 87 | if (draw) |
88 | draw = false; | ||
89 | if(draw) | ||
90 | gui_statusbar_draw(wps->statusbar, force); | 88 | gui_statusbar_draw(wps->statusbar, force); |
91 | } | 89 | } |
92 | #else | 90 | #else |
@@ -1012,15 +1010,13 @@ static char *get_tag(struct gui_wps *gwps, | |||
1012 | } | 1010 | } |
1013 | } | 1011 | } |
1014 | #endif | 1012 | #endif |
1015 | |||
1016 | case WPS_TOKEN_BATTERY_SLEEPTIME: | 1013 | case WPS_TOKEN_BATTERY_SLEEPTIME: |
1017 | { | 1014 | { |
1018 | if (get_sleep_timer() == 0) | 1015 | if (get_sleep_timer() == 0) |
1019 | return NULL; | 1016 | return NULL; |
1020 | else | 1017 | else |
1021 | { | 1018 | { |
1022 | format_time(buf, buf_size, \ | 1019 | format_time(buf, buf_size, get_sleep_timer() * 1000); |
1023 | get_sleep_timer() * 1000); | ||
1024 | return buf; | 1020 | return buf; |
1025 | } | 1021 | } |
1026 | } | 1022 | } |
@@ -1377,6 +1373,7 @@ static bool get_line(struct gui_wps *gwps, | |||
1377 | char temp_buf[128]; | 1373 | char temp_buf[128]; |
1378 | char *buf = linebuf; /* will always point to the writing position */ | 1374 | char *buf = linebuf; /* will always point to the writing position */ |
1379 | char *linebuf_end = linebuf + linebuf_size - 1; | 1375 | char *linebuf_end = linebuf + linebuf_size - 1; |
1376 | int i, last_token_idx; | ||
1380 | bool update = false; | 1377 | bool update = false; |
1381 | 1378 | ||
1382 | /* alignment-related variables */ | 1379 | /* alignment-related variables */ |
@@ -1384,16 +1381,14 @@ static bool get_line(struct gui_wps *gwps, | |||
1384 | char* cur_align_start; | 1381 | char* cur_align_start; |
1385 | cur_align_start = buf; | 1382 | cur_align_start = buf; |
1386 | cur_align = WPS_ALIGN_LEFT; | 1383 | cur_align = WPS_ALIGN_LEFT; |
1387 | align->left = 0; | 1384 | align->left = NULL; |
1388 | align->center = 0; | 1385 | align->center = NULL; |
1389 | align->right = 0; | 1386 | align->right = NULL; |
1390 | 1387 | ||
1391 | /* start at the beginning of the current (sub)line */ | 1388 | /* Process all tokens of the desired subline */ |
1392 | int i = data->format_lines[line][subline]; | 1389 | last_token_idx = wps_last_token_index(data, line, subline); |
1393 | 1390 | for (i = wps_first_token_index(data, line, subline); | |
1394 | while (data->tokens[i].type != WPS_TOKEN_EOL | 1391 | i <= last_token_idx; i++) |
1395 | && data->tokens[i].type != WPS_TOKEN_SUBLINE_SEPARATOR | ||
1396 | && i < data->num_tokens) | ||
1397 | { | 1392 | { |
1398 | switch(data->tokens[i].type) | 1393 | switch(data->tokens[i].type) |
1399 | { | 1394 | { |
@@ -1460,8 +1455,7 @@ static bool get_line(struct gui_wps *gwps, | |||
1460 | default: | 1455 | default: |
1461 | { | 1456 | { |
1462 | /* get the value of the tag and copy it to the buffer */ | 1457 | /* get the value of the tag and copy it to the buffer */ |
1463 | char *value = get_tag(gwps, i, temp_buf, | 1458 | char *value = get_tag(gwps,i,temp_buf,sizeof(temp_buf),NULL); |
1464 | sizeof(temp_buf), NULL); | ||
1465 | if (value) | 1459 | if (value) |
1466 | { | 1460 | { |
1467 | update = true; | 1461 | update = true; |
@@ -1471,7 +1465,6 @@ static bool get_line(struct gui_wps *gwps, | |||
1471 | break; | 1465 | break; |
1472 | } | 1466 | } |
1473 | } | 1467 | } |
1474 | i++; | ||
1475 | } | 1468 | } |
1476 | 1469 | ||
1477 | /* close the current alignment */ | 1470 | /* close the current alignment */ |
@@ -1496,13 +1489,14 @@ static bool get_line(struct gui_wps *gwps, | |||
1496 | static void get_subline_timeout(struct gui_wps *gwps, int line, int subline) | 1489 | static void get_subline_timeout(struct gui_wps *gwps, int line, int subline) |
1497 | { | 1490 | { |
1498 | struct wps_data *data = gwps->data; | 1491 | struct wps_data *data = gwps->data; |
1499 | int i = data->format_lines[line][subline]; | 1492 | int i; |
1493 | int subline_idx = wps_subline_index(data, line, subline); | ||
1494 | int last_token_idx = wps_last_token_index(data, line, subline); | ||
1500 | 1495 | ||
1501 | data->time_mult[line][subline] = DEFAULT_SUBLINE_TIME_MULTIPLIER; | 1496 | data->sublines[subline_idx].time_mult = DEFAULT_SUBLINE_TIME_MULTIPLIER; |
1502 | 1497 | ||
1503 | while (data->tokens[i].type != WPS_TOKEN_EOL | 1498 | for (i = wps_first_token_index(data, line, subline); |
1504 | && data->tokens[i].type != WPS_TOKEN_SUBLINE_SEPARATOR | 1499 | i <= last_token_idx; i++) |
1505 | && i < data->num_tokens) | ||
1506 | { | 1500 | { |
1507 | switch(data->tokens[i].type) | 1501 | switch(data->tokens[i].type) |
1508 | { | 1502 | { |
@@ -1518,32 +1512,33 @@ static void get_subline_timeout(struct gui_wps *gwps, int line, int subline) | |||
1518 | break; | 1512 | break; |
1519 | 1513 | ||
1520 | case WPS_TOKEN_SUBLINE_TIMEOUT: | 1514 | case WPS_TOKEN_SUBLINE_TIMEOUT: |
1521 | data->time_mult[line][subline] = data->tokens[i].value.i; | 1515 | data->sublines[subline_idx].time_mult = data->tokens[i].value.i; |
1522 | break; | 1516 | break; |
1523 | 1517 | ||
1524 | default: | 1518 | default: |
1525 | break; | 1519 | break; |
1526 | } | 1520 | } |
1527 | i++; | ||
1528 | } | 1521 | } |
1529 | } | 1522 | } |
1530 | 1523 | ||
1531 | /* Calculate which subline should be displayed for each line */ | 1524 | /* Calculates which subline should be displayed for the specified line |
1532 | static bool get_curr_subline(struct gui_wps *gwps, int line) | 1525 | Returns true iff the subline must be refreshed */ |
1526 | static bool update_curr_subline(struct gui_wps *gwps, int line) | ||
1533 | { | 1527 | { |
1534 | struct wps_data *data = gwps->data; | 1528 | struct wps_data *data = gwps->data; |
1535 | 1529 | ||
1536 | int search, search_start; | 1530 | int search, search_start, num_sublines; |
1537 | bool reset_subline; | 1531 | bool reset_subline; |
1538 | bool new_subline_refresh; | 1532 | bool new_subline_refresh; |
1539 | bool only_one_subline; | 1533 | bool only_one_subline; |
1540 | 1534 | ||
1541 | reset_subline = (data->curr_subline[line] == SUBLINE_RESET); | 1535 | num_sublines = data->lines[line].num_sublines; |
1536 | reset_subline = (data->lines[line].curr_subline == SUBLINE_RESET); | ||
1542 | new_subline_refresh = false; | 1537 | new_subline_refresh = false; |
1543 | only_one_subline = false; | 1538 | only_one_subline = false; |
1544 | 1539 | ||
1545 | /* if time to advance to next sub-line */ | 1540 | /* if time to advance to next sub-line */ |
1546 | if (TIME_AFTER(current_tick, data->subline_expire_time[line] - 1) || | 1541 | if (TIME_AFTER(current_tick, data->lines[line].subline_expire_time - 1) || |
1547 | reset_subline) | 1542 | reset_subline) |
1548 | { | 1543 | { |
1549 | /* search all sublines until the next subline with time > 0 | 1544 | /* search all sublines until the next subline with time > 0 |
@@ -1551,43 +1546,45 @@ static bool get_curr_subline(struct gui_wps *gwps, int line) | |||
1551 | if (reset_subline) | 1546 | if (reset_subline) |
1552 | search_start = 0; | 1547 | search_start = 0; |
1553 | else | 1548 | else |
1554 | search_start = data->curr_subline[line]; | 1549 | search_start = data->lines[line].curr_subline; |
1555 | 1550 | ||
1556 | for (search = 0; search < WPS_MAX_SUBLINES; search++) | 1551 | for (search = 0; search < num_sublines; search++) |
1557 | { | 1552 | { |
1558 | data->curr_subline[line]++; | 1553 | data->lines[line].curr_subline++; |
1559 | 1554 | ||
1560 | /* wrap around if beyond last defined subline or WPS_MAX_SUBLINES */ | 1555 | /* wrap around if beyond last defined subline or WPS_MAX_SUBLINES */ |
1561 | if ((!data->format_lines[line][data->curr_subline[line]]) || | 1556 | if (data->lines[line].curr_subline == num_sublines) |
1562 | (data->curr_subline[line] == WPS_MAX_SUBLINES)) | ||
1563 | { | 1557 | { |
1564 | if (data->curr_subline[line] == 1) | 1558 | if (data->lines[line].curr_subline == 1) |
1565 | only_one_subline = true; | 1559 | only_one_subline = true; |
1566 | data->curr_subline[line] = 0; | 1560 | data->lines[line].curr_subline = 0; |
1567 | } | 1561 | } |
1568 | 1562 | ||
1569 | /* if back where we started after search or | 1563 | /* if back where we started after search or |
1570 | only one subline is defined on the line */ | 1564 | only one subline is defined on the line */ |
1571 | if (((search > 0) && (data->curr_subline[line] == search_start)) || | 1565 | if (((search > 0) && (data->lines[line].curr_subline == search_start)) || |
1572 | only_one_subline) | 1566 | only_one_subline) |
1573 | { | 1567 | { |
1574 | /* no other subline with a time > 0 exists */ | 1568 | /* no other subline with a time > 0 exists */ |
1575 | data->subline_expire_time[line] = (reset_subline? | 1569 | data->lines[line].subline_expire_time = (reset_subline ? |
1576 | current_tick : data->subline_expire_time[line]) + 100 * HZ; | 1570 | current_tick : data->lines[line].subline_expire_time) + 100 * HZ; |
1577 | break; | 1571 | break; |
1578 | } | 1572 | } |
1579 | else | 1573 | else |
1580 | { | 1574 | { |
1581 | /* get initial time multiplier for this subline */ | 1575 | /* get initial time multiplier for this subline */ |
1582 | get_subline_timeout(gwps, line, data->curr_subline[line]); | 1576 | get_subline_timeout(gwps, line, data->lines[line].curr_subline); |
1577 | |||
1578 | int subline_idx = wps_subline_index(data, line, | ||
1579 | data->lines[line].curr_subline); | ||
1583 | 1580 | ||
1584 | /* only use this subline if subline time > 0 */ | 1581 | /* only use this subline if subline time > 0 */ |
1585 | if (data->time_mult[line][data->curr_subline[line]] > 0) | 1582 | if (data->sublines[subline_idx].time_mult > 0) |
1586 | { | 1583 | { |
1587 | new_subline_refresh = true; | 1584 | new_subline_refresh = true; |
1588 | data->subline_expire_time[line] = (reset_subline ? | 1585 | data->lines[line].subline_expire_time = (reset_subline ? |
1589 | current_tick : data->subline_expire_time[line]) + | 1586 | current_tick : data->lines[line].subline_expire_time) + |
1590 | BASE_SUBLINE_TIME * data->time_mult[line][data->curr_subline[line]]; | 1587 | BASE_SUBLINE_TIME * data->sublines[subline_idx].time_mult; |
1591 | break; | 1588 | break; |
1592 | } | 1589 | } |
1593 | } | 1590 | } |
@@ -1779,7 +1776,7 @@ bool gui_wps_refresh(struct gui_wps *gwps, | |||
1779 | if(!gwps || !data || !state || !display) | 1776 | if(!gwps || !data || !state || !display) |
1780 | return false; | 1777 | return false; |
1781 | 1778 | ||
1782 | int line, i; | 1779 | int line, i, subline_idx; |
1783 | unsigned char flags; | 1780 | unsigned char flags; |
1784 | char linebuf[MAX_PATH]; | 1781 | char linebuf[MAX_PATH]; |
1785 | 1782 | ||
@@ -1814,7 +1811,7 @@ bool gui_wps_refresh(struct gui_wps *gwps, | |||
1814 | { | 1811 | { |
1815 | for (i = 0; i < data->num_lines; i++) | 1812 | for (i = 0; i < data->num_lines; i++) |
1816 | { | 1813 | { |
1817 | data->curr_subline[i] = SUBLINE_RESET; | 1814 | data->lines[i].curr_subline = SUBLINE_RESET; |
1818 | } | 1815 | } |
1819 | } | 1816 | } |
1820 | 1817 | ||
@@ -1840,15 +1837,16 @@ bool gui_wps_refresh(struct gui_wps *gwps, | |||
1840 | update_line = false; | 1837 | update_line = false; |
1841 | 1838 | ||
1842 | /* get current subline for the line */ | 1839 | /* get current subline for the line */ |
1843 | new_subline_refresh = get_curr_subline(gwps, line); | 1840 | new_subline_refresh = update_curr_subline(gwps, line); |
1844 | 1841 | ||
1845 | flags = data->line_type[line][data->curr_subline[line]]; | 1842 | subline_idx = wps_subline_index(data, line, data->lines[line].curr_subline); |
1843 | flags = data->sublines[subline_idx].line_type; | ||
1846 | 1844 | ||
1847 | if (refresh_mode == WPS_REFRESH_ALL || flags & refresh_mode | 1845 | if (refresh_mode == WPS_REFRESH_ALL || (flags & refresh_mode) |
1848 | || new_subline_refresh) | 1846 | || new_subline_refresh) |
1849 | { | 1847 | { |
1850 | /* get_line tells us if we need to update the line */ | 1848 | /* get_line tells us if we need to update the line */ |
1851 | update_line = get_line(gwps, line, data->curr_subline[line], | 1849 | update_line = get_line(gwps, line, data->lines[line].curr_subline, |
1852 | &align, linebuf, sizeof(linebuf)); | 1850 | &align, linebuf, sizeof(linebuf)); |
1853 | } | 1851 | } |
1854 | 1852 | ||
@@ -1947,3 +1945,30 @@ bool gui_wps_refresh(struct gui_wps *gwps, | |||
1947 | 1945 | ||
1948 | return true; | 1946 | return true; |
1949 | } | 1947 | } |
1948 | |||
1949 | int wps_subline_index(struct wps_data *data, int line, int subline) | ||
1950 | { | ||
1951 | return data->lines[line].first_subline_idx + subline; | ||
1952 | } | ||
1953 | |||
1954 | int wps_first_token_index(struct wps_data *data, int line, int subline) | ||
1955 | { | ||
1956 | int first_subline_idx = data->lines[line].first_subline_idx; | ||
1957 | return data->sublines[first_subline_idx + subline].first_token_idx; | ||
1958 | } | ||
1959 | |||
1960 | int wps_last_token_index(struct wps_data *data, int line, int subline) | ||
1961 | { | ||
1962 | int first_subline_idx = data->lines[line].first_subline_idx; | ||
1963 | int idx = first_subline_idx + subline; | ||
1964 | if (idx < data->num_sublines - 1) | ||
1965 | { | ||
1966 | /* This subline ends where the next begins */ | ||
1967 | return data->sublines[idx+1].first_token_idx - 1; | ||
1968 | } | ||
1969 | else | ||
1970 | { | ||
1971 | /* The last subline goes to the end */ | ||
1972 | return data->num_tokens - 1; | ||
1973 | } | ||
1974 | } | ||