aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/view.h
blob: 882a33cb564fcc07972e7f94b61329c92b550726 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * Copyright (C) 2012-2024 Robin Haberkorn
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#pragma once

#include <glib.h>

#include <Scintilla.h>

#include "sciteco.h"

/**
 * @interface teco_view_t
 * Interface for all SciTECO views.
 *
 * Methods that must still be implemented in the user-interface
 * layer are marked with the \@pure tag.
 */
typedef struct teco_view_t teco_view_t;

/** @pure @static @memberof teco_view_t */
teco_view_t *teco_view_new(void);

void teco_view_setup(teco_view_t *ctx);

/** @pure @memberof teco_view_t */
sptr_t teco_view_ssm(teco_view_t *ctx, unsigned int iMessage, uptr_t wParam, sptr_t lParam);

/** @memberof teco_view_t */
void undo__teco_view_ssm(teco_view_t *, unsigned int, uptr_t, sptr_t);

void teco_view_set_representations(teco_view_t *ctx);

/** @memberof teco_view_t */
static inline void
teco_view_set_scintilla_undo(teco_view_t *ctx, gboolean state)
{
	teco_view_ssm(ctx, SCI_EMPTYUNDOBUFFER, 0, 0);
	teco_view_ssm(ctx, SCI_SETUNDOCOLLECTION, state, 0);
}

gboolean teco_view_load_from_channel(teco_view_t *ctx, GIOChannel *channel, GError **error);
gboolean teco_view_load_from_file(teco_view_t *ctx, const gchar *filename, GError **error);

/** @memberof teco_view_t */
#define teco_view_load(CTX, FROM, ERROR) \
	(_Generic((FROM), GIOChannel *  : teco_view_load_from_channel, \
	                  const gchar * : teco_view_load_from_file)((CTX), (FROM), (ERROR)))

gboolean teco_view_save_to_channel(teco_view_t *ctx, GIOChannel *channel, GError **error);
gboolean teco_view_save_to_file(teco_view_t *ctx, const gchar *filename, GError **error);

/** @memberof teco_view_t */
#define teco_view_save(CTX, TO, ERROR) \
	(_Generic((TO), GIOChannel *  : teco_view_save_to_channel, \
	                const gchar * : teco_view_save_to_file)((CTX), (TO), (ERROR)))

/** @pure @memberof teco_view_t */
void teco_view_free(teco_view_t *ctx);

gssize teco_view_glyphs2bytes(teco_view_t *ctx, teco_int_t pos);
teco_int_t teco_view_bytes2glyphs(teco_view_t *ctx, gsize pos);
gssize teco_view_glyphs2bytes_relative(teco_view_t *ctx, gsize pos, teco_int_t n);

teco_int_t teco_view_get_character(teco_view_t *ctx, gsize pos, gsize len);