aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/document.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/document.h')
-rw-r--r--src/document.h99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/document.h b/src/document.h
new file mode 100644
index 0000000..2ef71ba
--- /dev/null
+++ b/src/document.h
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2012-2013 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/>.
+ */
+
+#ifndef __DOCUMENT_H
+#define __DOCUMENT_H
+
+#include <glib.h>
+
+#include <Scintilla.h>
+
+#include "sciteco.h"
+#include "interface.h"
+#include "undo.h"
+
+/*
+ * Classes
+ */
+
+/*
+ * NOTE: The only reason this is called TECODocument
+ * is to prevent a nameclash with Scintilla which
+ * does not use a proper namespace for its public
+ * symbols...
+ */
+class TECODocument {
+ typedef const void *SciDoc;
+ SciDoc doc;
+
+ /* updated/restored only when required */
+ gint dot;
+ gint first_line;
+ gint xoffset;
+
+public:
+ TECODocument() : doc(NULL)
+ {
+ reset();
+ }
+ virtual ~TECODocument()
+ {
+ if (is_initialized())
+ interface.ssm(SCI_RELEASEDOCUMENT, 0, (sptr_t)doc);
+ }
+
+ inline bool
+ is_initialized(void)
+ {
+ return doc != NULL;
+ }
+
+ void edit(void);
+ void undo_edit(void);
+
+ void update(void);
+ inline void
+ update(const TECODocument &from)
+ {
+ dot = from.dot;
+ first_line = from.first_line;
+ xoffset = from.xoffset;
+ }
+
+ inline void
+ reset(void)
+ {
+ dot = first_line = xoffset = 0;
+ }
+ inline void
+ undo_reset(void)
+ {
+ undo.push_var(dot);
+ undo.push_var(first_line);
+ undo.push_var(xoffset);
+ }
+
+ void exchange(TECODocument &other);
+ inline void
+ undo_exchange(void)
+ {
+ undo.push_var(doc);
+ undo_reset();
+ }
+};
+
+#endif