THE ODDBALLS THAT MAKE IT COMPLETE?! XFrame Misc & X — XGraph, XSpreadsheet and 2 More, Hand-Drawn in X11!

The last 4 widgets — XGraph, XSpreadsheet and the two remaining oddballs — hand-drawn X11 classes that close out the 194-widget XFrame library. Full API and working examples for each.

THE ODDBALLS THAT MAKE IT COMPLETE?! XFrame Misc & X — XGraph, XSpreadsheet and 2 More, Hand-Drawn in X11!
All 194 XFrame widgets — contact sheet

Every library has a junk drawer — the handful of pieces that fit nowhere else and yet, somehow, hold the whole thing together. This is that drawer. And it turns out to be the most interesting one in the entire library.

XFrame is a pure X11/Xlib hand-drawn C++17 widget library — NOT GTK, despite the Gtk* names, and not Qt, and not any toolkit at all. Every widget is drawn by hand with raw Xlib calls. This is article 19 of a 9-part series documenting all 194 widgets in the library, and it is the last group: the four widgets that refused to fit into Windows & Dialogs, Containers, Buttons, Display, Text & Entry, Choosers, Views & Lists, or Menus & Toolbars. Four widgets, and two of them — XGraph and XSpreadsheet — are the only custom X-prefixed widgets in the whole set, a hand-drawn chart and a full spreadsheet with a formula engine, modelled on no GTK or Lazarus control at all. The other two are just as essential: a transparent event-catching box and the application metadata holder.

Every widget below comes with its full API and a working example, exactly as documented in the repo at github.com/cnmcdee/CWidgets. Nothing here is invented — the body of this article is the documentation itself, converted as-is, including every honest "unclear from the header" note where the header left something open. This is the group that closes out the series: 194 widgets, nine articles, one library drawn entirely by hand.

CWidgets Documentation

XFrame — a pure X11/Xlib hand-drawn C++17 widget library. Every widget is drawn by hand with raw Xlib calls. There is no GTK here, no Qt, no toolkit at all — despite the Gtk* names. The Gtk* components recreate the look of GTK widgets as standalone X11 classes; the T* components are the same idea in Lazarus/Delphi style; plus XGraph and XSpreadsheet.

Start with the project README for the repo layout, build instructions, and test status. This index documents the widget API itself: the contract every widget shares, then one page per section with every widget in it.

Contents

Section Widgets Page
Windows & Dialogs 28 windows-dialogs.md
Containers & Layout 34 containers-layout.md
Buttons 24 buttons.md
Display 33 display.md
Text & Entry 28 text-entry.md
Choosers 10 choosers.md
Views & Lists 17 views-lists.md
Menus & Toolbars 16 menus-toolbars.md
Misc / X 4 misc-x.md
Total 194

Section assignment is defined in tools/sections.py and verified by tools/sections.py itself (run it: python3 tools/sections.py) — every widget belongs to exactly one section.

The shared widget contract

This is the part that is the same for all 194 widgets (verified by inspection across all 194 headers: every member below exists in every header). Each section page therefore lists only what is specific to each widget — constructor, widget-specific methods, signals — and does not repeat this contract.

Construction

Every widget has the identical constructor:

<Name>(Display* display, int screen, Window window, GC gc,
       SStyle_Manager* styles, int x, int y, int width, int height)
  • display, screen, window, gc — the X connection and the window the widget draws into, from XOpenDisplay / XCreateSimpleWindow / DefaultGC.
  • styles — an SStyle_Manager (from core/xframe_core.h) holding the named styles. Register at least a "default" style with add_style_ex(...) and activate it with set_active_style_byName(...) before constructing widgets.
  • x, y, width, height — the widget's initial bounds in window coordinates.

Geometry

void set_bounds(int x, int y, int width, int height);
int  width();    // x2_ - x1_
int  height();   // y2_ - y1_
bool contains(int x, int y);  // false when not visible

Visibility and enabled state

void set_visible(bool v);
bool get_visible();
void set_enabled(bool e);
bool get_enabled();

A disabled widget still draws, but greyed out (text colour forced to grey) and its event handlers refuse input. An invisible widget does not draw and contains() returns false for it.

Style

void   set_style_name(std::string s);  // "" = the manager's active style
SStyle style();                        // styles_->resolve(style_name_)

Drawing

void draw();

Draws the widget into its window with the resolved style. Returns immediately when the widget is not visible. Call it after construction and again after any handled event (the standard demo loop clears the window and redraws on every handled event).

Events

Every widget implements the same four handlers. Each returns true when it handled the event (the demo loop then clears and redraws) and false otherwise:

bool on_button_press(int x, int y, unsigned int button);   // button 1 = left
bool on_button_release(int x, int y, unsigned int button);
bool on_motion(int x, int y);
bool on_key(KeySym key, const char* str);

Typical behaviour: on_button_press sets pressed_/focused_ when the click lands inside the widget; on_button_release fires the widget's callback if the release is still inside; on_key fires the callback on Return/Space when the widget has focus. on_motion is a no-op on most widgets — only a few headers carry hover state, and the test suite found only 12 of 194 demos show a visible hover response. Do not assume a widget reacts to hover unless its section page says so.

Signals

Widgets expose their callbacks as public std::function members, e.g.:

std::function<void()> on_click;   // the most common signal (85 widgets)

Assign them like any member:

widget.on_click = [] { printf("clicked\n"); };

Signal names and signatures vary by widget — on_change, on_response, on_toggled, on_value_changed, on_selection_changed, on_color_changed, on_page_selected, ... — with payloads such as void(int), void(std::string), void(bool), void(double), void(Srgb), void(TTreeNode&). The exact name and signature for each widget are listed on its section page. Never guess a signal name: if it is not in the header, it does not exist.

Minimal program skeleton

Every demo in components/<Name>/main_<Name>.cpp follows this shape (shown here for GtkButton — the section pages trim it further per widget):

#include "GtkButton.h"
#include <cstdio>

int main() {
    Display* display = XOpenDisplay(nullptr);
    if (!display) return 1;
    int screen = DefaultScreen(display);
    Window window = XCreateSimpleWindow(display, RootWindow(display, screen),
        100, 100, 800, 600, 1,
        BlackPixel(display, screen), WhitePixel(display, screen));
    XStoreName(display, window, "GtkButton - XFrame demo");
    XSelectInput(display, window, ExposureMask | KeyPressMask |
        StructureNotifyMask | ButtonPressMask | ButtonReleaseMask |
        PointerMotionMask);
    Atom wmDelete = XInternAtom(display, "WM_DELETE_WINDOW", False);
    XSetWMProtocols(display, window, &wmDelete, 1);
    XMapWindow(display, window);

    GC gc = DefaultGC(display, screen);
    SStyle_Manager styles(display, window, screen, gc);
    styles.add_style_ex("default", Srgb{225, 225, 225}, Srgb{120, 120, 120},
        Srgb{60, 60, 60}, Srgb{20, 20, 20}, 6, 1,
        "-misc-fixed-medium-r-normal--13-*");
    styles.set_active_style_byName("default");

    GtkButton widget(display, screen, window, gc, &styles, 40, 40, 340, 200);
    widget.on_click = [] { printf("clicked\n"); };
    widget.draw();

    bool running = true;
    while (running) {
        XEvent event;
        XNextEvent(display, &event);
        bool handled = false;
        switch (event.type) {
        case Expose:        handled = true; break;
        case ButtonPress:   handled = widget.on_button_press(
                                event.xbutton.x, event.xbutton.y,
                                event.xbutton.button); break;
        case ButtonRelease: handled = widget.on_button_release(
                                event.xbutton.x, event.xbutton.y,
                                event.xbutton.button); break;
        case MotionNotify:  handled = widget.on_motion(
                                event.xmotion.x, event.xmotion.y); break;
        case KeyPress: {
            char buffer[32];
            KeySym key = 0;
            int n = XLookupString(&event.xkey, buffer, sizeof(buffer) - 1,
                                  &key, nullptr);
            buffer[n] = 0;
            handled = widget.on_key(key, buffer);
            break;
        }
        case ClientMessage:
            if ((Atom)event.xclient.data.l[0] == wmDelete) running = false;
            break;
        }
        if (handled) {
            XClearWindow(display, window);
            widget.draw();
            XFlush(display);
        }
    }
    XCloseDisplay(display);
    return 0;
}

Build a single example (from the repo root, with the header's component directory on the include path):

g++ -std=c++17 -I components/GtkButton example.cpp -lX11 -o example

Or build the shipped demo instead — components/<Name>/CMakeLists.txt builds it standalone, and the top-level build builds all 194 (see the README).

Tools

  • Selector palette — palette/ builds cwidgets_palette (part of the top-level build). A pure X11/XFrame window listing all 194 widgets in their 9 sections, each with its 16x16 icon. Click (or Up/Down + Enter) to select; the selection is written to the shared selection file (/tmp/cwidgets-selection.txt) for the layout tool. Self-test: 194/194 selections OK.
  • Layout window — layout/ builds cwidgets_layout. Instantiates the real widget classes via the generated factory in common/registry.h (generated by tools/gen_registry.py — do not edit by hand). Click to place the selected widget, drag to move, Delete to remove, s to save/load the layout, q to quit. Double-click a placed widget for 8 orange resize handles (corners + edges); drag a handle to resize live; Escape dismisses the handles, Delete removes the widget.
  • Icons — icons/<Name>.ico, one real 16x16 ICO per widget, purpose-drawn glyphs generated by tools/gen_icons.py (70 glyph kinds, section accent colours — not downscaled screenshots). Verified by tools/verify_icons.py: 194/194 parse as 16x16, all non-blank.

Test status

Tested Nov 26, 2026 on the VPS (Debian 12, g++ 12.2, Xvfb) with the autonomous driver test-driver/run_tests.py: all 194 demos build with 0 warnings (-Wall -Wextra); 193 draw (GtkInvisible is non-visual by design); 125 show a visible click response (the rest are display-only by design); all 194 survive keypresses and exit cleanly; zero crashes, zero hangs. Full table: test-results/results.md. Palette self-test 194/194; layout placement 194/194, draw 194/194, all 194 alive at once (test-results/palette_layout_results.csv).

License

MIT — see LICENSE. Copyright (c) 2026 cnmcdee.

Misc / X

Everything that fits nowhere else: a transparent event catcher, the application metadata holder, and the two custom X-prefixed widgets — a chart and a spreadsheet — that are not modelled on any GTK or Lazarus control.

Every widget here shares the common XFrame widget API — same constructor, set_bounds/draw/event handlers, visible/enabled state. The shared contract is documented in docs/index.md (written by the coordinator). Each subsection below lists only what is specific to that widget.

GtkEventBox

A transparent event-catching box. By default it draws nothing at all — it exists to receive mouse and keyboard events over an area (for example over a child widget) and report them. With a visible window it draws a pale box with its text; in design-time mode it draws a marker box instead.

Constructor: GtkEventBox(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height)

API (widget-specific methods/properties/signals ONLY — skip the common ones): - set_text(std::string t) / get_text() — the text drawn when the window is visible - set_above_child(bool a) / get_above_child() — whether the box receives events before its child does - set_visible_window(bool v) / get_visible_window() — whether the box draws a visible background (pale fill + outline + centred text) - set_design_time(bool d) — design-time mode: draws a marker box so the box can be seen in a designer - get_last_event() — description of the most recent event the box received - get_event_count() — how many events the box has received - signal on_click (std::function<void()>) — fires on a click in the box

Example:

#include "GtkEventBox.h"
#include <cstdio>
#include <string>
#include <vector>

int main()
{
    Display* display = XOpenDisplay(nullptr);
    if (!display) { return 1; }
    int screen = DefaultScreen(display);
    XID Xid = RootWindow(display, screen);
    Window window = XCreateSimpleWindow(display, Xid, 100, 100, 800, 600, 1, BlackPixel(display, screen), WhitePixel(display, screen));
    XStoreName(display, window, "GtkEventBox - XFrame demo");
    XSelectInput(display, window, ExposureMask | KeyPressMask | StructureNotifyMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
    Atom deleteWindowMessage = XInternAtom(display, "WM_DELETE_WINDOW", False);
    XSetWMProtocols(display, window, &deleteWindowMessage, 1);
    XMapWindow(display, window);
    GC gc = DefaultGC(display, screen);
    SStyle_Manager styles(display, window, screen, gc);
    styles.add_style_ex("default", Srgb{225, 225, 225}, Srgb{120, 120, 120}, Srgb{60, 60, 60}, Srgb{20, 20, 20}, 6, 1, "-misc-fixed-medium-r-normal--13-*");
    styles.set_active_style_byName("default");
    GtkEventBox widget(display, screen, window, gc, &styles, 40, 40, 340, 200);
    widget.set_text("EventBox");
    widget.set_visible_window(true);
    widget.on_click = []{ std::printf("clicked\n"); };
    widget.draw();
    bool running = true;
    while (running)
    {
        XEvent event;
        XNextEvent(display, &event);
        bool handled = false;
        switch (event.type)
        {
        case Expose:
            handled = true;
            break;
        case ButtonPress:
            handled = widget.on_button_press(event.xbutton.x, event.xbutton.y, event.xbutton.button);
            break;
        case ButtonRelease:
            handled = widget.on_button_release(event.xbutton.x, event.xbutton.y, event.xbutton.button);
            break;
        case MotionNotify:
            handled = widget.on_motion(event.xmotion.x, event.xmotion.y);
            break;
        case KeyPress:
        {
            char buffer[32];
            KeySym key = 0;
            int n = XLookupString(&event.xkey, buffer, (int)sizeof(buffer) - 1, &key, nullptr);
            buffer[n] = 0;
            handled = widget.on_key(key, buffer);
            break;
        }
        case ClientMessage:
            if ((Atom)event.xclient.data.l[0] == deleteWindowMessage)
            {
                running = false;
            }
            break;
        }
        if (handled)
        {
            XClearWindow(display, window);
            widget.draw();
            XFlush(display);
        }
    }
    XCloseDisplay(display);
    return 0;
}

Notes: With both visible_window and design_time off, draw() paints nothing — the widget is invisible but still receives events.

TApplicationProperties

Application metadata with a visual badge — not a non-visual component, despite the name. It draws a round "i" badge plus a "<title> v<version>" label, and holds the application's title, version, hint text and help file. handle_exception() records an exception and fires on_exception.

Constructor: TApplicationProperties(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height)

API (widget-specific methods/properties/signals ONLY — skip the common ones): - set_text(std::string t) / get_text() — the widget text - set_title(std::string t) / get_title() — the application title shown in the badge label - set_version(std::string v) / get_version() — the application version (drawn as "v" + version) - set_hint(std::string h) / get_hint() — the hint text - set_help_file(std::string f) / get_help_file() — the help file path - set_show_main_form(bool s) / get_show_main_form() — whether the main form is shown - set_show_hint(bool s) / get_show_hint() — whether hints are shown - handle_exception(const std::string& message) — record an exception: it is counted, remembered as the last exception, and on_exception fires with the message - get_exception_count() — how many exceptions have been recorded - get_last_exception() — the most recent exception message - signal on_click (std::function<void()>) — fires on a click on the badge - signal on_exception (std::function<void(const std::string&)>) — fires with the exception message when handle_exception() is called - signal on_minimize (std::function<void()>) — declared on the widget - signal on_restore (std::function<void()>) — declared on the widget

Example:

#include "TApplicationProperties.h"
#include <cstdio>
#include <string>
#include <vector>

int main()
{
    Display* display = XOpenDisplay(nullptr);
    if (!display) { return 1; }
    int screen = DefaultScreen(display);
    XID Xid = RootWindow(display, screen);
    Window window = XCreateSimpleWindow(display, Xid, 100, 100, 800, 600, 1, BlackPixel(display, screen), WhitePixel(display, screen));
    XStoreName(display, window, "TApplicationProperties - XFrame demo");
    XSelectInput(display, window, ExposureMask | KeyPressMask | StructureNotifyMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
    Atom deleteWindowMessage = XInternAtom(display, "WM_DELETE_WINDOW", False);
    XSetWMProtocols(display, window, &deleteWindowMessage, 1);
    XMapWindow(display, window);
    GC gc = DefaultGC(display, screen);
    SStyle_Manager styles(display, window, screen, gc);
    styles.add_style_ex("default", Srgb{225, 225, 225}, Srgb{120, 120, 120}, Srgb{60, 60, 60}, Srgb{20, 20, 20}, 6, 1, "-misc-fixed-medium-r-normal--13-*");
    styles.set_active_style_byName("default");
    TApplicationProperties widget(display, screen, window, gc, &styles, 40, 40, 340, 200);
    widget.set_title("Demo App");
    widget.set_version("1.0");
    widget.set_hint("A demo application");
    widget.on_exception = [](const std::string& m){ std::printf("exception: %s\n", m.c_str()); };
    widget.draw();
    bool running = true;
    while (running)
    {
        XEvent event;
        XNextEvent(display, &event);
        bool handled = false;
        switch (event.type)
        {
        case Expose:
            handled = true;
            break;
        case ButtonPress:
            handled = widget.on_button_press(event.xbutton.x, event.xbutton.y, event.xbutton.button);
            break;
        case ButtonRelease:
            handled = widget.on_button_release(event.xbutton.x, event.xbutton.y, event.xbutton.button);
            break;
        case MotionNotify:
            handled = widget.on_motion(event.xmotion.x, event.xmotion.y);
            break;
        case KeyPress:
        {
            char buffer[32];
            KeySym key = 0;
            int n = XLookupString(&event.xkey, buffer, (int)sizeof(buffer) - 1, &key, nullptr);
            buffer[n] = 0;
            handled = widget.on_key(key, buffer);
            break;
        }
        case ClientMessage:
            if ((Atom)event.xclient.data.l[0] == deleteWindowMessage)
            {
                running = false;
            }
            break;
        }
        if (handled)
        {
            XClearWindow(display, window);
            widget.draw();
            XFlush(display);
        }
    }
    XCloseDisplay(display);
    return 0;
}

Notes: The on_minimize and on_restore signals are declared but no call site for either appears in the header — nothing in the widget fires them, so it is unclear from the header how the host is meant to trigger them.

XGraph

A chart widget — one of the two custom X-prefixed widgets, not modelled on a GTK or Lazarus control. It draws a white plot area with a grid and axes, and plots line series, OHLC bars or candlesticks. The view pans and zooms: zoom_at() zooms around a point in the view, reset_view() restores the full range, and on_view_change reports the new view.

Constructor: XGraph(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height)

API (widget-specific methods/properties/signals ONLY — skip the common ones): - set_text(std::string t) / get_text() — the widget text - item_count() — total number of data points across all series - clear_series() — removes all series - add_line_series(const std::string& name, Srgb color, const std::vector<double>& values) — adds a line series (kind 0) - add_ohlc_series(const std::string& name, Srgb color, const std::vector<XGraphBar>& bars, bool candlesticks = false) — adds an OHLC bar series (kind 1) or a candlestick series (kind 2); each XGraphBar is { double open, high, low, close; } - set_series_kind(int index, int kind) — change a series kind: 0 = line, 1 = OHLC bars, 2 = candlesticks - set_series_up_down(int index, Srgb up, Srgb down) — up / down colours for a candlestick series - series_count() — number of series - set_x_labels(const std::vector<std::string>& labels) — labels for the x axis, one per item - set_y_range(double lo, double hi) — fixed y range (turns auto-y off) - set_auto_y(bool on) — automatic y range from the visible data (on by default) - reset_view() — show the whole series again - get_view_first() / get_view_count() — first visible item index / number of visible items - zoom_at(double factor, double frac_x) — zoom by a factor around a fractional position in the view - effective_count() — number of items the view covers after zooming - y_range(double& lo, double& hi) — the y range actually being drawn - plot_x() / plot_y() / plot_w() / plot_h() — the plot area rectangle in pixels - item_w() — pixel width of one item - x_at(double index) / x_center(int i) — pixel x for an item index - y_at(double v, double lo, double hi) — pixel y for a value - value_at_y(int y, double lo, double hi) — value for a pixel y - fire_view_change() — fire on_view_change() with the current view - static double nice_step(double range, int target) — a "nice" axis step for a range (used by draw() for the grid lines) - static std::string fmt(double v) — formats a value for the axis labels (used by draw()) - signal on_view_change (std::function<void(double, double)>) — fires with (first visible index, visible count) when the view changes

Example:

#include "XGraph.h"
#include <cstdio>
#include <string>
#include <vector>

int main()
{
    Display* display = XOpenDisplay(nullptr);
    if (!display) { return 1; }
    int screen = DefaultScreen(display);
    XID Xid = RootWindow(display, screen);
    Window window = XCreateSimpleWindow(display, Xid, 100, 100, 800, 600, 1, BlackPixel(display, screen), WhitePixel(display, screen));
    XStoreName(display, window, "XGraph - XFrame demo");
    XSelectInput(display, window, ExposureMask | KeyPressMask | StructureNotifyMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
    Atom deleteWindowMessage = XInternAtom(display, "WM_DELETE_WINDOW", False);
    XSetWMProtocols(display, window, &deleteWindowMessage, 1);
    XMapWindow(display, window);
    GC gc = DefaultGC(display, screen);
    SStyle_Manager styles(display, window, screen, gc);
    styles.add_style_ex("default", Srgb{225, 225, 225}, Srgb{120, 120, 120}, Srgb{60, 60, 60}, Srgb{20, 20, 20}, 6, 1, "-misc-fixed-medium-r-normal--13-*");
    styles.set_active_style_byName("default");
    XGraph widget(display, screen, window, gc, &styles, 20, 20, 720, 480);
    widget.add_line_series("Price", Srgb{70, 110, 180}, std::vector<double>{1.0, 2.0, 1.5, 3.0, 2.5});
    widget.set_x_labels(std::vector<std::string>{"Mon", "Tue", "Wed", "Thu", "Fri"});
    widget.set_auto_y(true);
    widget.on_view_change = [](double a, double b){ std::printf("view %f %f\n", a, b); };
    widget.draw();
    bool running = true;
    while (running)
    {
        XEvent event;
        XNextEvent(display, &event);
        bool handled = false;
        switch (event.type)
        {
        case Expose:
            handled = true;
            break;
        case ButtonPress:
            handled = widget.on_button_press(event.xbutton.x, event.xbutton.y, event.xbutton.button);
            break;
        case ButtonRelease:
            handled = widget.on_button_release(event.xbutton.x, event.xbutton.y, event.xbutton.button);
            break;
        case MotionNotify:
            handled = widget.on_motion(event.xmotion.x, event.xmotion.y);
            break;
        case KeyPress:
        {
            char buffer[32];
            KeySym key = 0;
            int n = XLookupString(&event.xkey, buffer, (int)sizeof(buffer) - 1, &key, nullptr);
            buffer[n] = 0;
            handled = widget.on_key(key, buffer);
            break;
        }
        case ClientMessage:
            if ((Atom)event.xclient.data.l[0] == deleteWindowMessage)
            {
                running = false;
            }
            break;
        }
        if (handled)
        {
            XClearWindow(display, window);
            widget.draw();
            XFlush(display);
        }
    }
    XCloseDisplay(display);
    return 0;
}

Notes: Series kinds are plain ints (0 / 1 / 2) — there are no named constants in the header. Panning and zooming come from mouse / key input handled by the widget; the host can drive the same view with zoom_at() and reset_view().

XSpreadsheet

A spreadsheet widget — the other custom X-prefixed widget. It draws a grid with a frozen row-number column, a header row, an active cell and a selection, and it evaluates formulas. Cells hold text, numbers or formulas starting with '='; the formula engine supports + - * / ( ), A1 cell references and SUM / AVG / MIN / MAX / COUNT over ranges like A1:B9. The constructor pre-fills a sample sheet with values, a formula column and totals.

Constructor: XSpreadsheet(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height)

API (widget-specific methods/properties/signals ONLY — skip the common ones): - set_text(std::string t) / get_text() — the widget text - set_size(int cols, int rows) — resize the sheet (default 12 columns x 40 rows) - get_cols() / get_rows() — sheet size - set_col_width(int col, int w) / get_col_width(int col) — width of one column - set_frozen_rows(int n) / set_frozen_cols(int n) — frozen rows / columns (1 column is frozen by default, for the row numbers; 0 rows frozen by default) - set_cell_text(int col, int row, const std::string& text) / get_cell_text(int col, int row) — the raw text of a cell (a formula when it starts with '=') - get_cell_value(int col, int row) — the computed numeric value of a cell - get_cell_display(int col, int row) — the text as drawn (computed value for formulas) - get_active_col() / get_active_row() — the active cell - set_active_cell(int col, int row) — make a cell active - sort_by_column(int col, bool ascending = true) — sort the rows by one column - copy_selection() — the selected range as tab-separated text - get_clipboard() — the last copied text - recalculate() — re-evaluate every formula - eval_cell(int col, int row, std::set<long>& visiting, std::set<long>& done) — evaluate one cell (formula-engine entry point; the visiting / done sets are cycle detection) - skip_spaces(const std::string& s, size_t& pos) / parse_expr(...) / parse_term(...) / parse_factor(...) / apply_function(...) — the formula parser internals; public, but not part of the normal API - col_left(int col) / row_top(int row) — pixel position of a column / row - visible_cols(int& first, int& last) / visible_rows(int& first, int& last) — which columns / rows are on screen - cell_at(int x, int y, int& col, int& row) — cell under a point - ensure_visible(int col, int row) — scroll so a cell is visible - begin_edit(bool replace) / commit_edit() / cancel_edit() — start / finish / abandon editing the active cell - static std::string col_name(int col) — column letters for an index ("A", "B", ...) - static std::string format_number(double v) — formats a numeric cell for display - static bool parse_ref(const std::string& s, size_t& pos, int& col, int& row) — parse an A1-style cell reference out of a formula string - signal on_cell_change (std::function<void(int, int)>) — fires with (column, row) when a cell's text changes - signal on_select_cell (std::function<void(int, int)>) — fires with (column, row) when the active cell changes

Example:

#include "XSpreadsheet.h"
#include <cstdio>
#include <string>
#include <vector>

int main()
{
    Display* display = XOpenDisplay(nullptr);
    if (!display) { return 1; }
    int screen = DefaultScreen(display);
    XID Xid = RootWindow(display, screen);
    Window window = XCreateSimpleWindow(display, Xid, 100, 100, 800, 600, 1, BlackPixel(display, screen), WhitePixel(display, screen));
    XStoreName(display, window, "XSpreadsheet - XFrame demo");
    XSelectInput(display, window, ExposureMask | KeyPressMask | StructureNotifyMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
    Atom deleteWindowMessage = XInternAtom(display, "WM_DELETE_WINDOW", False);
    XSetWMProtocols(display, window, &deleteWindowMessage, 1);
    XMapWindow(display, window);
    GC gc = DefaultGC(display, screen);
    SStyle_Manager styles(display, window, screen, gc);
    styles.add_style_ex("default", Srgb{225, 225, 225}, Srgb{120, 120, 120}, Srgb{60, 60, 60}, Srgb{20, 20, 20}, 6, 1, "-misc-fixed-medium-r-normal--13-*");
    styles.set_active_style_byName("default");
    XSpreadsheet widget(display, screen, window, gc, &styles, 20, 20, 720, 480);
    widget.set_size(6, 10);
    widget.set_cell_text(0, 0, "Item");
    widget.set_cell_text(0, 1, "10");
    widget.set_cell_text(0, 2, "20");
    widget.set_cell_text(0, 3, "=SUM(A2:A3)");
    widget.set_active_cell(0, 3);
    widget.on_cell_change = [](int c, int r){ std::printf("cell %d,%d\n", c, r); };
    widget.draw();
    bool running = true;
    while (running)
    {
        XEvent event;
        XNextEvent(display, &event);
        bool handled = false;
        switch (event.type)
        {
        case Expose:
            handled = true;
            break;
        case ButtonPress:
            handled = widget.on_button_press(event.xbutton.x, event.xbutton.y, event.xbutton.button);
            break;
        case ButtonRelease:
            handled = widget.on_button_release(event.xbutton.x, event.xbutton.y, event.xbutton.button);
            break;
        case MotionNotify:
            handled = widget.on_motion(event.xmotion.x, event.xmotion.y);
            break;
        case KeyPress:
        {
            char buffer[32];
            KeySym key = 0;
            int n = XLookupString(&event.xkey, buffer, (int)sizeof(buffer) - 1, &key, nullptr);
            buffer[n] = 0;
            handled = widget.on_key(key, buffer);
            break;
        }
        case ClientMessage:
            if ((Atom)event.xclient.data.l[0] == deleteWindowMessage)
            {
                running = false;
            }
            break;
        }
        if (handled)
        {
            XClearWindow(display, window);
            widget.draw();
            XFlush(display);
        }
    }
    XCloseDisplay(display);
    return 0;
}

Notes: Columns and rows are 0-based in the API; the drawn row numbers start at 1. The constructor's sample sheet has a formula column and totals — call set_size() to start from a rebuilt grid. A failed formula (bad reference, circular reference, parse failure) marks the cell as an error and evaluates to 0.0; the exact text drawn for an error cell is unclear from the header.

That's All 194

With these four, the series is complete: 194 widgets, nine articles, every one with its full API and a working example. The whole library lives at github.com/cnmcdee/CWidgets, and the full documentation — the shared widget contract plus all nine section pages — is in the repo at docs/index.md.

One article still follows: the combined IDE, bringing the designer, palette, layout and the stepping GDB debugger together into a single application. Stay tuned.