📄 ceditor.cpp
字号:
/*************************************************************************** CEditor.cpp (c) 2000-2003 Beno顃 Minisini <gambas@users.sourceforge.net> WIDGET 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 1, or (at your option) any later version. WIDGET 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 WIDGET program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.***************************************************************************/#define __CEDITOR_CPP#include "main.h"#include <qobject.h>#include <qpalette.h>#include "qeditor.h"#include "CEditor.h"static long EVENT_Change; /* text has changed */static long EVENT_Cursor; /* cursor has moved */DECLARE_EVENT(EVENT_Scroll);static void look_pos(QEditor *wid, int *line, int *col){ if (*line == -1) *line = wid->numLines(); if (*col == -1) *col = wid->lineLength(*line);}static QString purge(QString & s){ QString r; QChar c; uint i; bool space = false; char wait = 0; for (i = 0; i < s.length(); i++) { c = s[i]; switch(wait) { case 0: if (space) c = ' '; else if (c == '"') wait = '"'; else if (c == '\'') space = true; break; case '"': if (c == '"') wait = 0; else c = ' '; break; } r += c; } s = r; return s;}static void *analyze_symbol = 0;static void *analyze_type = 0;static void *analyze_pos = 0;static void analyze(QString &s){ ColorDataArray data; GB_ARRAY garray, tarray, parray; uint i, n, pos, len, p; char *str; QEditorRow::analyze(s, data); n = 0; for (i = 0; i < data.count(); i++) { if (data[i].state != QEditorRow::Normal) n++; } //n = data.count() >> 1; GB.Array.New(&garray, GB_T_STRING, n); GB.Array.New(&tarray, GB_T_INTEGER, n); GB.Array.New(&parray, GB_T_INTEGER, n); pos = 0; i = 0; for (p = 0; p < data.count(); p++) { len = data[p].len; if (data[p].state != QEditorRow::Normal) { GB.NewString(&str, TO_UTF8(s.mid(pos, len)), 0); *((char **)GB.Array.Get(garray, i)) = str; *((int *)GB.Array.Get(tarray, i)) = data[p].state; *((int *)GB.Array.Get(parray, i)) = pos; i++; } pos += len; } GB.Unref(&analyze_symbol); analyze_symbol = garray; GB.Ref(garray); GB.Unref(&analyze_type); analyze_type = tarray; GB.Ref(tarray); GB.Unref(&analyze_pos); analyze_pos = parray; GB.Ref(parray);}BEGIN_METHOD(CEDITOR_new, GB_OBJECT parent) QEditor *wid = new QEditor(QT.GetContainer(VARG(parent))); QObject::connect(wid, SIGNAL(textChanged()), &CEditor::manager, SLOT(changed())); QObject::connect(wid, SIGNAL(cursorMoved()), &CEditor::manager, SLOT(moved())); QObject::connect(wid, SIGNAL(contentsMoving(int, int)), &CEditor::manager, SLOT(scrolled(int, int))); QT.InitWidget(wid, _object); wid->show();END_METHODBEGIN_METHOD_VOID(CEDITOR_exit) GB.Unref(&analyze_symbol); GB.Unref(&analyze_type); GB.Unref(&analyze_pos);END_METHODBEGIN_PROPERTY(CEDITOR_text) if (READ_PROPERTY) GB.ReturnNewZeroString(TO_UTF8(WIDGET->text())); else { WIDGET->setText(QSTRING_PROP()); WIDGET->setEdited(false); }END_PROPERTYBEGIN_PROPERTY(CEDITOR_length) GB.ReturnInteger(WIDGET->length());END_PROPERTYBEGIN_PROPERTY(CEDITOR_line) int line, col; WIDGET->cursorPosition(&line, &col); if (READ_PROPERTY) GB.ReturnInteger(line); else { line = VPROP(GB_INTEGER); look_pos(WIDGET, &line, &col); WIDGET->setCursorPosition(line, col); }END_PROPERTYBEGIN_PROPERTY(CEDITOR_column) int line, col; WIDGET->getCursorPosition(&line, &col); if (READ_PROPERTY) GB.ReturnInteger(col); else { col = VPROP(GB_INTEGER); look_pos(WIDGET, &line, &col); WIDGET->setCursorPosition(line, col); }END_PROPERTYBEGIN_METHOD(CEDITOR_goto, GB_INTEGER line; GB_INTEGER col) WIDGET->setCursorPosition(VARG(line), VARG(col));END_METHODBEGIN_METHOD_VOID(CEDITOR_ensure_visible) int line, col; WIDGET->getCursorPosition(&line, &col); WIDGET->ensureLineVisible(line);END_METHODBEGIN_PROPERTY(CEDITOR_pos) int line, col; if (READ_PROPERTY) { WIDGET->getCursorPosition(&line, &col); GB.ReturnInteger(WIDGET->toPos(line, col)); } else { WIDGET->fromPos(VPROP(GB_INTEGER), &line, &col); WIDGET->setCursorPosition(line, col); }END_PROPERTYBEGIN_PROPERTY(CEDITOR_lines) RETURN_SELF();END_PROPERTYBEGIN_PROPERTY(CEDITOR_line_count) GB.ReturnInteger((long)WIDGET->numLines());END_PROPERTYBEGIN_METHOD(CEDITOR_line_get, GB_INTEGER line) long line = VARG(line); if (line < 0 || line >= WIDGET->numLines()) GB.ReturnNull(); else GB.ReturnNewZeroString(TO_UTF8(WIDGET->textLine(line)));END_METHODBEGIN_METHOD(CEDITOR_line_put, GB_STRING text; GB_INTEGER line) long line = VARG(line); QString s; if (line >= 0 && line < WIDGET->numLines()) { s = QSTRING_PROP(); WIDGET->setTextLine(line, s); }END_METHODBEGIN_METHOD(CEDITOR_purge_line, GB_INTEGER line) long line = VARG(line); QString s; if (line < 0 || line >= WIDGET->numLines()) GB.ReturnNull(); else { s = WIDGET->textLine(line); GB.ReturnNewZeroString(TO_UTF8(purge(s))); }END_METHODBEGIN_METHOD(CEDITOR_analyze, GB_STRING text) QString s = QSTRING_ARG(text); analyze(s); GB.ReturnObject(analyze_symbol);END_METHODBEGIN_PROPERTY(CEDITOR_analyze_symbols) GB.ReturnObject(analyze_symbol);END_PROPERTYBEGIN_PROPERTY(CEDITOR_analyze_types) GB.ReturnObject(analyze_type);END_PROPERTYBEGIN_PROPERTY(CEDITOR_analyze_positions) GB.ReturnObject(analyze_pos);END_PROPERTYBEGIN_METHOD(CEDITOR_line_get_flag, GB_INTEGER line; GB_INTEGER flag) long line = VARG(line); if (line >= 0 && line < WIDGET->numLines()) GB.ReturnBoolean(WIDGET->lineType(line) & (1 << VARG(flag))); else GB.ReturnBoolean(false);END_METHODBEGIN_METHOD(CEDITOR_line_set_flag, GB_INTEGER line; GB_INTEGER flag; GB_BOOLEAN value) long line = VARG(line); if (line >= 0 && line < WIDGET->numLines()) { long flag = WIDGET->lineType(line); if (VARG(value)) WIDGET->setLineType(line, flag | (1 << VARG(flag)) ); else WIDGET->setLineType(line, flag & ~(1 << VARG(flag)) ); }END_METHODBEGIN_METHOD_VOID(CEDITOR_clear) WIDGET->clear();END_METHODBEGIN_METHOD(CEDITOR_insert, GB_STRING text) WIDGET->insert(QSTRING_ARG(text));END_METHOD/*************************************************************************** .GambasEditor.Selection***************************************************************************/BEGIN_PROPERTY(CEDITOR_sel_text) if (READ_PROPERTY) GB.ReturnNewZeroString(TO_UTF8(WIDGET->markedText())); else WIDGET->insert(QSTRING_PROP());END_PROPERTYBEGIN_PROPERTY(CEDITOR_sel_length) long start, length; WIDGET->getSelection(&start, &length); GB.ReturnInteger(length);END_PROPERTYBEGIN_PROPERTY(CEDITOR_sel_start) long start, length; WIDGET->getSelection(&start, &length); GB.ReturnInteger(start);END_PROPERTYBEGIN_METHOD_VOID(CEDITOR_sel_clear) WIDGET->deselect();END_METHOD// BEGIN_METHOD_VOID(CEDITOR_sel_all)//// WIDGET->selectAll();//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -