forked from Lephenixnoir/hex-editor
60 lines
1.8 KiB
C
60 lines
1.8 KiB
C
// heditor: A hexadecimal editor widget
|
|
//
|
|
// This widget basically holds a view for a data source. The controller is the
|
|
// source API.
|
|
|
|
#pragma once
|
|
#include "source.h"
|
|
#include <justui/defs.h>
|
|
#include <justui/jwidget.h>
|
|
#include <gint/display.h>
|
|
|
|
/* heditor: Hexadecimal editor
|
|
|
|
Events:
|
|
* HEDITOR_CHANGED when the view changes due to scroll or a file change. This
|
|
does *not* include cursor changes that don't scroll. */
|
|
typedef struct {
|
|
jwidget widget;
|
|
|
|
/* Current data source. We don't own the source */
|
|
source_t *source;
|
|
/* Current scroll offset, in bytes */
|
|
int scroll;
|
|
/* Current cursor position in source, in bytes */
|
|
int cursor;
|
|
/* Current insertion mode (false=overwrite, true=insert) */
|
|
bool insert;
|
|
/* Number of visible lines */
|
|
int8_t visible_lines;
|
|
/* Number of bytes printed per line */
|
|
int8_t bytes_per_line;
|
|
/* Additional spacing between lines, in pixels */
|
|
int8_t line_spacing;
|
|
/* Rendering font */
|
|
font_t const *font;
|
|
|
|
} heditor;
|
|
|
|
/* Type IDs */
|
|
extern uint16_t HEDITOR_CHANGED;
|
|
|
|
/* heditor_create(): Create a new editor
|
|
Initially there is no data source, so most features are disabled. */
|
|
heditor *heditor_create(jwidget *parent);
|
|
|
|
/* Switch the source. The old source is not freed by the editor. */
|
|
void heditor_set_source(heditor *e, source_t *source);
|
|
|
|
/* Scroll to the requested cursor position. */
|
|
bool heditor_move_to(heditor *e, int offset);
|
|
|
|
/* Change the insertion mode; true for insertion, false for overwrite. If the
|
|
source doesn't support insertion, this function is a no-op. */
|
|
void heditor_set_insert_mode(heditor *e, bool insert);
|
|
|
|
/* Trivial properties */
|
|
void heditor_set_font(heditor *e, font_t const *font);
|
|
void heditor_set_line_spacing(heditor *e, int line_spacig);
|
|
void heditor_set_bytes_per_lines(heditor *e, int bytes_per_line);
|