diff options
| -rw-r--r-- | boxes.c | 110 |
1 files changed, 44 insertions, 66 deletions
| @@ -495,10 +495,9 @@ char *borderCharsCurrent[][6] = | |||
| 495 | 495 | ||
| 496 | typedef struct _box box; | 496 | typedef struct _box box; |
| 497 | typedef struct _view view; | 497 | typedef struct _view view; |
| 498 | typedef struct _event event; | ||
| 499 | 498 | ||
| 500 | typedef void (*boxFunction) (box *box); | 499 | typedef void (*boxFunction) (box *box); |
| 501 | typedef void (*eventHandler) (view *view, event *event); | 500 | typedef void (*eventHandler) (view *view); |
| 502 | 501 | ||
| 503 | struct function | 502 | struct function |
| 504 | { | 503 | { |
| @@ -535,26 +534,6 @@ struct borderWidget | |||
| 535 | char *text, *command; | 534 | char *text, *command; |
| 536 | }; | 535 | }; |
| 537 | 536 | ||
| 538 | // TODO - No idea if we will actually need this. | ||
| 539 | struct _event | ||
| 540 | { | ||
| 541 | struct function *function; | ||
| 542 | uint16_t X, Y; // Current cursor position, or position of mouse click. | ||
| 543 | char type; | ||
| 544 | union | ||
| 545 | { | ||
| 546 | struct keyCommand *key; // keystroke / mouse click | ||
| 547 | struct item *item; // menu | ||
| 548 | struct borderWidget widget; // border widget click | ||
| 549 | int time; // timer | ||
| 550 | struct // scroll contents | ||
| 551 | { | ||
| 552 | int X, Y; | ||
| 553 | } scroll; | ||
| 554 | // TODO - might need events for - leave box, enter box. Could use a new event type "command with arguments"? | ||
| 555 | }; | ||
| 556 | }; | ||
| 557 | |||
| 558 | // TODO - a generic "part of text", and what is used to define them. | 537 | // TODO - a generic "part of text", and what is used to define them. |
| 559 | // For instance - word, line, paragraph, section. | 538 | // For instance - word, line, paragraph, section. |
| 560 | // Each context can have a collection of these. | 539 | // Each context can have a collection of these. |
| @@ -683,7 +662,7 @@ static box *currentBox; | |||
| 683 | static view *commandLine; | 662 | static view *commandLine; |
| 684 | static int commandMode; | 663 | static int commandMode; |
| 685 | 664 | ||
| 686 | void doCommand(struct function *functions, char *command, view *view, event *event) | 665 | void doCommand(struct function *functions, char *command, view *view) |
| 687 | { | 666 | { |
| 688 | if (command) | 667 | if (command) |
| 689 | { | 668 | { |
| @@ -694,7 +673,7 @@ void doCommand(struct function *functions, char *command, view *view, event *eve | |||
| 694 | if (strcmp(functions[i].name, command) == 0) | 673 | if (strcmp(functions[i].name, command) == 0) |
| 695 | { | 674 | { |
| 696 | if (functions[i].handler); | 675 | if (functions[i].handler); |
| 697 | functions[i].handler(view, event); | 676 | functions[i].handler(view); |
| 698 | break; | 677 | break; |
| 699 | } | 678 | } |
| 700 | } | 679 | } |
| @@ -1416,7 +1395,7 @@ void calcBoxes(box *box) | |||
| 1416 | // Later we might use a dirty box flag to deal with this, if it's not too much of a complication. | 1395 | // Later we might use a dirty box flag to deal with this, if it's not too much of a complication. |
| 1417 | } | 1396 | } |
| 1418 | 1397 | ||
| 1419 | void deleteBox(view *view, event *event) | 1398 | void deleteBox(view *view) |
| 1420 | { | 1399 | { |
| 1421 | box *box = view->box; | 1400 | box *box = view->box; |
| 1422 | 1401 | ||
| @@ -1501,9 +1480,9 @@ void splitBox(box *box, float split) | |||
| 1501 | if (box->parent) | 1480 | if (box->parent) |
| 1502 | { | 1481 | { |
| 1503 | if (box == box->parent->sub1) | 1482 | if (box == box->parent->sub1) |
| 1504 | deleteBox(box->parent->sub2->view, NULL); | 1483 | deleteBox(box->parent->sub2->view); |
| 1505 | else | 1484 | else |
| 1506 | deleteBox(box->parent->sub1->view, NULL); | 1485 | deleteBox(box->parent->sub1->view); |
| 1507 | } | 1486 | } |
| 1508 | return; | 1487 | return; |
| 1509 | } | 1488 | } |
| @@ -1512,7 +1491,7 @@ void splitBox(box *box, float split) | |||
| 1512 | } | 1491 | } |
| 1513 | else // User meant to delete this, zero split. | 1492 | else // User meant to delete this, zero split. |
| 1514 | { | 1493 | { |
| 1515 | deleteBox(box->view, NULL); | 1494 | deleteBox(box->view); |
| 1516 | return; | 1495 | return; |
| 1517 | } | 1496 | } |
| 1518 | if (box->flags & BOX_HSPLIT) | 1497 | if (box->flags & BOX_HSPLIT) |
| @@ -1582,7 +1561,7 @@ void splitBox(box *box, float split) | |||
| 1582 | 1561 | ||
| 1583 | // TODO - Might be better to just have a double linked list of boxes, and traverse that instead. | 1562 | // TODO - Might be better to just have a double linked list of boxes, and traverse that instead. |
| 1584 | // Except that leaves a problem when deleting boxes, could end up with a blank space. | 1563 | // Except that leaves a problem when deleting boxes, could end up with a blank space. |
| 1585 | void switchBoxes(view *view, event *event) | 1564 | void switchBoxes(view *view) |
| 1586 | { | 1565 | { |
| 1587 | box *box = view->box; | 1566 | box *box = view->box; |
| 1588 | 1567 | ||
| @@ -1627,19 +1606,19 @@ void switchBoxes(view *view, event *event) | |||
| 1627 | // How to deal with the various argument needs? | 1606 | // How to deal with the various argument needs? |
| 1628 | // Might be where we can re use the toybox argument stuff. | 1607 | // Might be where we can re use the toybox argument stuff. |
| 1629 | 1608 | ||
| 1630 | void halveBoxHorizontally(view *view, event *event) | 1609 | void halveBoxHorizontally(view *view) |
| 1631 | { | 1610 | { |
| 1632 | view->box->flags |= BOX_HSPLIT; | 1611 | view->box->flags |= BOX_HSPLIT; |
| 1633 | splitBox(view->box, 0.5); | 1612 | splitBox(view->box, 0.5); |
| 1634 | } | 1613 | } |
| 1635 | 1614 | ||
| 1636 | void halveBoxVertically(view *view, event *event) | 1615 | void halveBoxVertically(view *view) |
| 1637 | { | 1616 | { |
| 1638 | view->box->flags &= ~BOX_HSPLIT; | 1617 | view->box->flags &= ~BOX_HSPLIT; |
| 1639 | splitBox(view->box, 0.5); | 1618 | splitBox(view->box, 0.5); |
| 1640 | } | 1619 | } |
| 1641 | 1620 | ||
| 1642 | void switchMode(view *view, event *event) | 1621 | void switchMode(view *view) |
| 1643 | { | 1622 | { |
| 1644 | currentBox->view->mode++; | 1623 | currentBox->view->mode++; |
| 1645 | // Assumes that modes will always have a key mapping, which I think is a safe bet. | 1624 | // Assumes that modes will always have a key mapping, which I think is a safe bet. |
| @@ -1648,48 +1627,48 @@ void switchMode(view *view, event *event) | |||
| 1648 | commandMode = currentBox->view->content->context->modes[currentBox->view->mode].flags & 1; | 1627 | commandMode = currentBox->view->content->context->modes[currentBox->view->mode].flags & 1; |
| 1649 | } | 1628 | } |
| 1650 | 1629 | ||
| 1651 | void leftChar(view *view, event *event) | 1630 | void leftChar(view *view) |
| 1652 | { | 1631 | { |
| 1653 | moveCursorRelative(view, -1, 0, 0, 0); | 1632 | moveCursorRelative(view, -1, 0, 0, 0); |
| 1654 | } | 1633 | } |
| 1655 | 1634 | ||
| 1656 | void rightChar(view *view, event *event) | 1635 | void rightChar(view *view) |
| 1657 | { | 1636 | { |
| 1658 | moveCursorRelative(view, 1, 0, 0, 0); | 1637 | moveCursorRelative(view, 1, 0, 0, 0); |
| 1659 | } | 1638 | } |
| 1660 | 1639 | ||
| 1661 | void upLine(view *view, event *event) | 1640 | void upLine(view *view) |
| 1662 | { | 1641 | { |
| 1663 | moveCursorRelative(view, 0, -1, 0, 0); | 1642 | moveCursorRelative(view, 0, -1, 0, 0); |
| 1664 | } | 1643 | } |
| 1665 | 1644 | ||
| 1666 | void downLine(view *view, event *event) | 1645 | void downLine(view *view) |
| 1667 | { | 1646 | { |
| 1668 | moveCursorRelative(view, 0, 1, 0, 0); | 1647 | moveCursorRelative(view, 0, 1, 0, 0); |
| 1669 | } | 1648 | } |
| 1670 | 1649 | ||
| 1671 | void upPage(view *view, event *event) | 1650 | void upPage(view *view) |
| 1672 | { | 1651 | { |
| 1673 | moveCursorRelative(view, 0, 0 - (view->H - 1), 0, 0 - (view->H - 1)); | 1652 | moveCursorRelative(view, 0, 0 - (view->H - 1), 0, 0 - (view->H - 1)); |
| 1674 | } | 1653 | } |
| 1675 | 1654 | ||
| 1676 | void downPage(view *view, event *event) | 1655 | void downPage(view *view) |
| 1677 | { | 1656 | { |
| 1678 | moveCursorRelative(view, 0, view->H - 1, 0, view->H - 1); | 1657 | moveCursorRelative(view, 0, view->H - 1, 0, view->H - 1); |
| 1679 | } | 1658 | } |
| 1680 | 1659 | ||
| 1681 | void endOfLine(view *view, event *event) | 1660 | void endOfLine(view *view) |
| 1682 | { | 1661 | { |
| 1683 | moveCursorAbsolute(view, strlen(view->prompt) + view->oW, view->cY, 0, 0); | 1662 | moveCursorAbsolute(view, strlen(view->prompt) + view->oW, view->cY, 0, 0); |
| 1684 | } | 1663 | } |
| 1685 | 1664 | ||
| 1686 | void startOfLine(view *view, event *event) | 1665 | void startOfLine(view *view) |
| 1687 | { | 1666 | { |
| 1688 | // TODO - add the advanced editing "smart home". | 1667 | // TODO - add the advanced editing "smart home". |
| 1689 | moveCursorAbsolute(view, strlen(view->prompt), view->cY, 0, 0); | 1668 | moveCursorAbsolute(view, strlen(view->prompt), view->cY, 0, 0); |
| 1690 | } | 1669 | } |
| 1691 | 1670 | ||
| 1692 | void splitLine(view *view, event *event) | 1671 | void splitLine(view *view) |
| 1693 | { | 1672 | { |
| 1694 | // TODO - should move this into mooshLines(). | 1673 | // TODO - should move this into mooshLines(). |
| 1695 | addLine(view->content, view->line, &(view->line->line[view->iX]), 0); | 1674 | addLine(view->content, view->line, &(view->line->line[view->iX]), 0); |
| @@ -1699,7 +1678,7 @@ void splitLine(view *view, event *event) | |||
| 1699 | drawBox(view->box); | 1678 | drawBox(view->box); |
| 1700 | } | 1679 | } |
| 1701 | 1680 | ||
| 1702 | void deleteChar(view *view, event *event) | 1681 | void deleteChar(view *view) |
| 1703 | { | 1682 | { |
| 1704 | // TODO - should move this into mooshLines(). | 1683 | // TODO - should move this into mooshLines(). |
| 1705 | // If we are at the end of the line, then join this and the next line. | 1684 | // If we are at the end of the line, then join this and the next line. |
| @@ -1720,25 +1699,25 @@ void deleteChar(view *view, event *event) | |||
| 1720 | mooshStrings(view->line, NULL, view->iX, 1, !TT.overWriteMode); | 1699 | mooshStrings(view->line, NULL, view->iX, 1, !TT.overWriteMode); |
| 1721 | } | 1700 | } |
| 1722 | 1701 | ||
| 1723 | void backSpaceChar(view *view, event *event) | 1702 | void backSpaceChar(view *view) |
| 1724 | { | 1703 | { |
| 1725 | if (moveCursorRelative(view, -1, 0, 0, 0)) | 1704 | if (moveCursorRelative(view, -1, 0, 0, 0)) |
| 1726 | deleteChar(view, event); | 1705 | deleteChar(view); |
| 1727 | } | 1706 | } |
| 1728 | 1707 | ||
| 1729 | void saveContent(view *view, event *event) | 1708 | void saveContent(view *view) |
| 1730 | { | 1709 | { |
| 1731 | saveFile(view->content); | 1710 | saveFile(view->content); |
| 1732 | } | 1711 | } |
| 1733 | 1712 | ||
| 1734 | void executeLine(view *view, event *event) | 1713 | void executeLine(view *view) |
| 1735 | { | 1714 | { |
| 1736 | struct line *result = view->line; | 1715 | struct line *result = view->line; |
| 1737 | 1716 | ||
| 1738 | // Don't bother doing much if there's nothing on this line. | 1717 | // Don't bother doing much if there's nothing on this line. |
| 1739 | if (result->line[0]) | 1718 | if (result->line[0]) |
| 1740 | { | 1719 | { |
| 1741 | doCommand(currentBox->view->content->context->commands, result->line, currentBox->view, event); | 1720 | doCommand(currentBox->view->content->context->commands, result->line, currentBox->view); |
| 1742 | // If we are not at the end of the history contents. | 1721 | // If we are not at the end of the history contents. |
| 1743 | if (&(view->content->lines) != result->next) | 1722 | if (&(view->content->lines) != result->next) |
| 1744 | { | 1723 | { |
| @@ -1764,20 +1743,20 @@ void executeLine(view *view, event *event) | |||
| 1764 | // Make sure there is one blank line at the end. | 1743 | // Make sure there is one blank line at the end. |
| 1765 | if ('\0' != view->line->line[0]) | 1744 | if ('\0' != view->line->line[0]) |
| 1766 | { | 1745 | { |
| 1767 | endOfLine(view, event); | 1746 | endOfLine(view); |
| 1768 | splitLine(view, event); | 1747 | splitLine(view); |
| 1769 | } | 1748 | } |
| 1770 | } | 1749 | } |
| 1771 | 1750 | ||
| 1772 | saveFile(view->content); | 1751 | saveFile(view->content); |
| 1773 | } | 1752 | } |
| 1774 | 1753 | ||
| 1775 | void quit(view *view, event *event) | 1754 | void quit(view *view) |
| 1776 | { | 1755 | { |
| 1777 | TT.stillRunning = 0; | 1756 | TT.stillRunning = 0; |
| 1778 | } | 1757 | } |
| 1779 | 1758 | ||
| 1780 | void nop(box *box, event *event) | 1759 | void nop(box *box) |
| 1781 | { | 1760 | { |
| 1782 | // 'tis a nop, don't actually do anything. | 1761 | // 'tis a nop, don't actually do anything. |
| 1783 | } | 1762 | } |
| @@ -1799,7 +1778,7 @@ static void lineChar(long extra, char *buffer) | |||
| 1799 | } | 1778 | } |
| 1800 | 1779 | ||
| 1801 | // TODO - should merge this and the real one. Note that when doing scripts and such, might want to turn off the line update until finished. | 1780 | // TODO - should merge this and the real one. Note that when doing scripts and such, might want to turn off the line update until finished. |
| 1802 | static struct keyCommand * lineCommand(long extra, char *command, event *event) | 1781 | static struct keyCommand * lineCommand(long extra, char *command) |
| 1803 | { | 1782 | { |
| 1804 | struct _view *view = (struct _view *) extra; // Though we pretty much stomp on this straight away. | 1783 | struct _view *view = (struct _view *) extra; // Though we pretty much stomp on this straight away. |
| 1805 | int y, len; | 1784 | int y, len; |
| @@ -1808,7 +1787,7 @@ static struct keyCommand * lineCommand(long extra, char *command, event *event) | |||
| 1808 | if (commandMode) view = commandLine; | 1787 | if (commandMode) view = commandLine; |
| 1809 | else view = currentBox->view; | 1788 | else view = currentBox->view; |
| 1810 | 1789 | ||
| 1811 | doCommand(view->content->context->commands, command, view, event); | 1790 | doCommand(view->content->context->commands, command, view); |
| 1812 | 1791 | ||
| 1813 | // Coz things might change out from under us, find the current view. Again | 1792 | // Coz things might change out from under us, find the current view. Again |
| 1814 | if (commandMode) view = commandLine; | 1793 | if (commandMode) view = commandLine; |
| @@ -1843,11 +1822,11 @@ The response from a terminal size check command includes a prefix, a suffix, wit | |||
| 1843 | 1822 | ||
| 1844 | Mouse events are likely similar. | 1823 | Mouse events are likely similar. |
| 1845 | */ | 1824 | */ |
| 1846 | void editLine(long extra, void (*lineChar)(long extra, char *buffer), struct keyCommand * (*lineCommand)(long extra, char *command, event *event)) | 1825 | void editLine(long extra, void (*lineChar)(long extra, char *buffer), struct keyCommand * (*lineCommand)(long extra, char *command)) |
| 1847 | { | 1826 | { |
| 1848 | struct pollfd pollfds[1]; | 1827 | struct pollfd pollfds[1]; |
| 1849 | // Get the initial command set, and trigger the first cursor move. | 1828 | // Get the initial command set, and trigger the first cursor move. |
| 1850 | struct keyCommand *ourKeys = lineCommand(extra, "", NULL); | 1829 | struct keyCommand *ourKeys = lineCommand(extra, ""); |
| 1851 | char buffer[20]; | 1830 | char buffer[20]; |
| 1852 | char command[20]; | 1831 | char command[20]; |
| 1853 | int pollcount = 1; | 1832 | int pollcount = 1; |
| @@ -1984,8 +1963,7 @@ void editLine(long extra, void (*lineChar)(long extra, char *buffer), struct key | |||
| 1984 | } | 1963 | } |
| 1985 | if (found) | 1964 | if (found) |
| 1986 | { | 1965 | { |
| 1987 | // That last argument, an event pointer, should be the original raw keystrokes, though by this time that's been cleared. | 1966 | ourKeys = lineCommand(extra, found); |
| 1988 | ourKeys = lineCommand(extra, found, NULL); | ||
| 1989 | command[0] = 0; | 1967 | command[0] = 0; |
| 1990 | } | 1968 | } |
| 1991 | } | 1969 | } |
| @@ -2479,20 +2457,20 @@ struct context simpleNano = | |||
| 2479 | // Vi needs extra variables and functions. | 2457 | // Vi needs extra variables and functions. |
| 2480 | static int viTempExMode; | 2458 | static int viTempExMode; |
| 2481 | 2459 | ||
| 2482 | void viMode(view *view, event *event) | 2460 | void viMode(view *view) |
| 2483 | { | 2461 | { |
| 2484 | currentBox->view->mode = 0; | 2462 | currentBox->view->mode = 0; |
| 2485 | commandMode = 0; | 2463 | commandMode = 0; |
| 2486 | viTempExMode = 0; | 2464 | viTempExMode = 0; |
| 2487 | } | 2465 | } |
| 2488 | 2466 | ||
| 2489 | void viInsertMode(view *view, event *event) | 2467 | void viInsertMode(view *view) |
| 2490 | { | 2468 | { |
| 2491 | currentBox->view->mode = 1; | 2469 | currentBox->view->mode = 1; |
| 2492 | commandMode = 0; | 2470 | commandMode = 0; |
| 2493 | } | 2471 | } |
| 2494 | 2472 | ||
| 2495 | void viExMode(view *view, event *event) | 2473 | void viExMode(view *view) |
| 2496 | { | 2474 | { |
| 2497 | currentBox->view->mode = 2; | 2475 | currentBox->view->mode = 2; |
| 2498 | commandMode = 1; | 2476 | commandMode = 1; |
| @@ -2502,18 +2480,18 @@ void viExMode(view *view, event *event) | |||
| 2502 | strcpy(commandLine->prompt, ":"); | 2480 | strcpy(commandLine->prompt, ":"); |
| 2503 | } | 2481 | } |
| 2504 | 2482 | ||
| 2505 | void viBackSpaceChar(view *view, event *event) | 2483 | void viBackSpaceChar(view *view) |
| 2506 | { | 2484 | { |
| 2507 | if ((2 == currentBox->view->mode) && (0 == view->cX) && viTempExMode) | 2485 | if ((2 == currentBox->view->mode) && (0 == view->cX) && viTempExMode) |
| 2508 | viMode(view, event); | 2486 | viMode(view); |
| 2509 | else | 2487 | else |
| 2510 | backSpaceChar(view, event); | 2488 | backSpaceChar(view); |
| 2511 | } | 2489 | } |
| 2512 | 2490 | ||
| 2513 | void viStartOfNextLine(view *view, event *event) | 2491 | void viStartOfNextLine(view *view) |
| 2514 | { | 2492 | { |
| 2515 | startOfLine(view, event); | 2493 | startOfLine(view); |
| 2516 | downLine(view, event); | 2494 | downLine(view); |
| 2517 | } | 2495 | } |
| 2518 | 2496 | ||
| 2519 | // TODO - ex uses "shortest unique string" to match commands, should implement that, and do it for the other contexts to. | 2497 | // TODO - ex uses "shortest unique string" to match commands, should implement that, and do it for the other contexts to. |
