aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile10
-rw-r--r--src/lua_interface.c336
-rw-r--r--src/textadept.c206
-rw-r--r--src/textadept.h53
4 files changed, 293 insertions, 312 deletions
diff --git a/src/Makefile b/src/Makefile
index c0c6b80f..e7680839 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -4,9 +4,9 @@
INCLUDEDIRS=-Iscintilla-st/include -Ilua/include -Igcocoadialog
ifdef DEBUG
-CXXFLAGS=-DDEBUG -g -DGTK -DSCI_LEXER -W -Wall -Wno-sign-compare
+CXXFLAGS=-DDEBUG -g -DGTK -DSCI_LEXER -W -Wall
else
-CXXFLAGS=-DNDEBUG -O -DGTK -DSCI_LEXER -W -Wall -Wno-sign-compare
+CXXFLAGS=-DNDEBUG -O -DGTK -DSCI_LEXER -W -Wall -Wno-sign-compare -Wno-unused
endif
GTKFLAGS=$(shell pkg-config --cflags gtk+-2.0)
GTKLIBS=$(shell pkg-config --libs gtk+-2.0 gthread-2.0)
@@ -22,11 +22,11 @@ LUA_OBJS = lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \
all: textadept
.c.o:
- g++ $(GTKFLAGS) $(INCLUDEDIRS) $(CXXFLAGS) -c $< -o $@
+ gcc $(GTKFLAGS) $(INCLUDEDIRS) $(CXXFLAGS) -c $< -o $@
$(LUA_OBJS): lua/src/*.c
- gcc $(INCLUDEDIRS) -DLUA_USE_LINUX $(CXXFLAGS) -c lua/src/*.c
+ gcc $(INCLUDEDIRS) -DLUA_USE_LINUX -c lua/src/*.c
gcocoadialog.o: gcocoadialog/gcocoadialog.c
- gcc $(GTKFLAGS) $(INCLUDEDIRS) $(CXXFLAGS) -c gcocoadialog/gcocoadialog.c
+ gcc $(GTKFLAGS) $(INCLUDEDIRS) -c gcocoadialog/gcocoadialog.c
textadept:\
textadept.o lua_interface.o $(LUA_OBJS) gcocoadialog.o \
scintilla-st/gtk/LexLPeg.o scintilla-st/bin/scintilla.a
diff --git a/src/lua_interface.c b/src/lua_interface.c
index 03d782ca..5b680956 100644
--- a/src/lua_interface.c
+++ b/src/lua_interface.c
@@ -17,8 +17,7 @@
lua_pushnil(l); \
lua_rawset(l, -3); \
}
-#define l_todocpointer(l, i) static_cast<sptr_t>(lua_tonumber(l, i))
-#define l_togtkwidget(l, i) reinterpret_cast<GtkWidget*>(lua_touserdata(l, i))
+#define l_togtkwidget(l, i) (GtkWidget *)lua_touserdata(l, i)
#define l_mt(l, k, i, ni) { \
if (luaL_newmetatable(l, k)) { \
l_cfunc(l, i, "__index"); \
@@ -32,7 +31,7 @@ using namespace Scintilla;
#endif
lua_State *lua;
-bool closing = false;
+int closing = FALSE;
static int tVOID = 0, /*tINT = 1,*/ tLENGTH = 2, /*tPOSITION = 3,*/
/*tCOLOUR = 4,*/ tBOOL = 5, tKEYMOD = 6, tSTRING = 7,
@@ -43,48 +42,28 @@ static void warn(const char *s) {
printf("Warning: %s\n", s);
}
-static int l_buffer_mt_index(lua_State *lua),
- l_buffer_mt_newindex(lua_State *lua),
- l_bufferp_mt_index(lua_State *lua),
- l_bufferp_mt_newindex(lua_State *lua),
- l_view_mt_index(lua_State *lua),
- l_view_mt_newindex(lua_State *lua),
- l_ta_mt_index(lua_State *lua),
- l_ta_mt_newindex(lua_State *lua),
- l_pm_mt_index(lua_State *lua),
- l_pm_mt_newindex(lua_State *lua),
- l_find_mt_index(lua_State *lua),
- l_find_mt_newindex(lua_State *lua),
- l_ce_mt_index(lua_State *lua),
- l_ce_mt_newindex(lua_State *lua);
-
-static int l_cf_buffer_delete(lua_State *lua),
- l_cf_buffer_text_range(lua_State *lua),
- l_cf_view_focus(lua_State *lua),
- l_cf_view_split(lua_State *lua),
- l_cf_view_unsplit(lua_State *lua),
- l_cf_ta_buffer_new(lua_State *lua),
- l_cf_ta_dialog(lua_State *lua),
- l_cf_ta_get_split_table(lua_State *lua),
- l_cf_ta_goto_window(lua_State *lua),
- l_cf_view_goto_buffer(lua_State *lua),
- l_cf_ta_gtkmenu(lua_State *lua),
- l_cf_ta_iconv(lua_State *lua),
- l_cf_ta_reset(lua_State *lua),
- l_cf_ta_quit(lua_State *lua),
- l_cf_pm_activate(lua_State *lua),
- l_cf_pm_add_browser(lua_State *lua),
- l_cf_pm_clear(lua_State *lua),
- l_cf_pm_fill(lua_State *lua),
- l_cf_pm_focus(lua_State *lua),
- l_cf_pm_show_context_menu(lua_State *lua),
- l_cf_find_focus(lua_State *lua),
- l_cf_find_next(lua_State *lua),
- l_cf_find_prev(lua_State *lua),
- l_cf_find_replace(lua_State *lua),
- l_cf_find_replace_all(lua_State *lua),
- l_cf_ce_focus(lua_State *lua),
- l_cf_ce_show_completions(lua_State *lua);
+static int l_buffer_mt_index(lua_State *), l_buffer_mt_newindex(lua_State *),
+ l_bufferp_mt_index(lua_State *), l_bufferp_mt_newindex(lua_State *),
+ l_view_mt_index(lua_State *), l_view_mt_newindex(lua_State *),
+ l_ta_mt_index(lua_State *), l_ta_mt_newindex(lua_State *),
+ l_pm_mt_index(lua_State *), l_pm_mt_newindex(lua_State *),
+ l_find_mt_index(lua_State *), l_find_mt_newindex(lua_State *),
+ l_ce_mt_index(lua_State *), l_ce_mt_newindex(lua_State *);
+
+static int l_cf_buffer_delete(lua_State *), l_cf_buffer_text_range(lua_State *),
+ l_cf_view_focus(lua_State *), l_cf_view_split(lua_State *),
+ l_cf_view_unsplit(lua_State *), l_cf_ta_buffer_new(lua_State *),
+ l_cf_ta_dialog(lua_State *), l_cf_ta_get_split_table(lua_State *),
+ l_cf_ta_goto_window(lua_State *), l_cf_view_goto_buffer(lua_State *),
+ l_cf_ta_gtkmenu(lua_State *), l_cf_ta_iconv(lua_State *),
+ l_cf_ta_reset(lua_State *), l_cf_ta_quit(lua_State *),
+ l_cf_pm_activate(lua_State *), l_cf_pm_add_browser(lua_State *),
+ l_cf_pm_clear(lua_State *), l_cf_pm_fill(lua_State *),
+ l_cf_pm_focus(lua_State *), l_cf_pm_show_context_menu(lua_State *),
+ l_cf_find_focus(lua_State *), l_cf_find_next(lua_State *),
+ l_cf_find_prev(lua_State *), l_cf_find_replace(lua_State *),
+ l_cf_find_replace_all(lua_State *), l_cf_ce_focus(lua_State *),
+ l_cf_ce_show_completions(lua_State *);
/**
* Inits or re-inits the Lua State.
@@ -94,11 +73,12 @@ static int l_cf_buffer_delete(lua_State *lua),
* @param argv The array of command line parameters.
* @param reinit Flag indicating whether or not to reinitialize the Lua State.
*/
-bool l_init(int argc, char **argv, bool reinit) {
+int l_init(int argc, char **argv, int reinit) {
if (!reinit) {
lua = lua_open();
lua_newtable(lua);
- for (int i = 0; i < argc; i++) {
+ int i;
+ for (i = 0; i < argc; i++) {
lua_pushstring(lua, argv[i]);
lua_rawseti(lua, -2, i);
}
@@ -172,19 +152,19 @@ bool l_init(int argc, char **argv, bool reinit) {
l_archive(lua, "buffer_functions");
l_archive(lua, "buffer_properties");
lua_pop(lua, 1); // textadept
- return true;
+ return TRUE;
}
lua_close(lua);
- return false;
+ return FALSE;
}
/**
* Loads and runs a given Lua script.
* @param script_file The path of the Lua script relative to textadept_home.
*/
-bool l_load_script(const char *script_file) {
+int l_load_script(const char *script_file) {
char *script = g_strconcat(textadept_home, "/", script_file, NULL);
- bool retval = luaL_dofile(lua, script) == 0;
+ int retval = luaL_dofile(lua, script) == 0;
if (!retval) {
const char *errmsg = lua_tostring(lua, -1);
lua_settop(lua, 0);
@@ -222,7 +202,7 @@ static GtkWidget *l_checkview(lua_State *lua, int narg) {
void l_add_scintilla_window(GtkWidget *editor) {
lua_getfield(lua, LUA_REGISTRYINDEX, "views");
lua_newtable(lua);
- lua_pushlightuserdata(lua, const_cast<GtkWidget*>(editor));
+ lua_pushlightuserdata(lua, (GtkWidget *)editor);
lua_setfield(lua, -2, "widget_pointer");
l_cfunc(lua, l_cf_view_split, "split");
l_cfunc(lua, l_cf_view_unsplit, "unsplit");
@@ -252,18 +232,18 @@ void l_remove_scintilla_window(GtkWidget *editor) {
* @param editor The currently focused Scintilla window.
* @param n The index of the window in the 'views' table to focus.
* @param absolute Flag indicating whether or not the index specified in 'views'
- * is absolute. If false, focuses the window relative to the currently focused
+ * is absolute. If FALSE, focuses the window relative to the currently focused
* window for the given index.
* Throws an error if the view does not exist.
*/
-void l_goto_scintilla_window(GtkWidget *editor, int n, bool absolute) {
+void l_goto_scintilla_window(GtkWidget *editor, int n, int absolute) {
lua_getfield(lua, LUA_REGISTRYINDEX, "views");
if (!absolute) {
unsigned int idx = 1;
lua_pushnil(lua);
while (lua_next(lua, -2))
if (editor == l_checkview(lua, -1)) {
- idx = static_cast<int>(lua_tointeger(lua, -2));
+ idx = lua_tointeger(lua, -2);
lua_pop(lua, 2); // key and value
break;
} else lua_pop(lua, 1); // value
@@ -313,7 +293,7 @@ static sptr_t l_checkdocpointer(lua_State *lua, int narg) {
lua_pushstring(lua, "doc_pointer");
lua_rawget(lua, (narg > 0) ? narg : narg - 1);
luaL_argcheck(lua, lua_isnumber(lua, -1), narg, "Buffer expected");
- sptr_t doc = l_todocpointer(lua, -1);
+ sptr_t doc = lua_tointeger(lua, -1);
lua_pop(lua, 1); // doc_pointer
return doc;
}
@@ -348,8 +328,8 @@ void l_remove_scintilla_buffer(sptr_t doc) {
lua_pushnil(lua);
while (lua_next(lua, -2)) {
GtkWidget *editor = l_checkview(lua, -1);
- sptr_t that_doc = SS(SCINTILLA(editor), SCI_GETDOCPOINTER);
- if (that_doc == doc) l_goto_scintilla_buffer(editor, -1, false);
+ sptr_t that_doc = SS(editor, SCI_GETDOCPOINTER, 0, 0);
+ if (that_doc == doc) l_goto_scintilla_buffer(editor, -1, FALSE);
lua_pop(lua, 1); // value
}
lua_pop(lua, 1); // views
@@ -373,7 +353,7 @@ unsigned int l_get_docpointer_index(sptr_t doc) {
lua_pushnil(lua);
while (lua_next(lua, -2))
if (doc == l_checkdocpointer(lua, -1)) {
- idx = static_cast<int>(lua_tointeger(lua, -2));
+ idx = lua_tointeger(lua, -2);
lua_pop(lua, 2); // key and value
break;
} else lua_pop(lua, 1); // value
@@ -389,15 +369,14 @@ unsigned int l_get_docpointer_index(sptr_t doc) {
* @param editor The Scintilla window to change the document of.
* @param n The index of the document in 'buffers' to focus.
* @param absolute Flag indicating whether or not the index specified in 'views'
- * is absolute. If false, focuses the document relative to the currently
+ * is absolute. If FALSE, focuses the document relative to the currently
* focused document for the given index.
* Throws an error if the buffer does not exist.
*/
-void l_goto_scintilla_buffer(GtkWidget *editor, int n, bool absolute) {
+void l_goto_scintilla_buffer(GtkWidget *editor, int n, int absolute) {
lua_getfield(lua, LUA_REGISTRYINDEX, "buffers");
- ScintillaObject *sci = SCINTILLA(editor);
if (!absolute) {
- sptr_t doc = SS(sci, SCI_GETDOCPOINTER);
+ sptr_t doc = SS(editor, SCI_GETDOCPOINTER, 0, 0);
unsigned int idx = l_get_docpointer_index(doc);
idx += n;
if (idx > lua_objlen(lua, -1))
@@ -412,8 +391,8 @@ void l_goto_scintilla_buffer(GtkWidget *editor, int n, bool absolute) {
}
sptr_t doc = l_checkdocpointer(lua, -1);
if (!closing) l_handle_event("buffer_before_switch", -1);
- SS(sci, SCI_SETDOCPOINTER, 0, doc);
- l_set_buffer_global(sci);
+ SS(editor, SCI_SETDOCPOINTER, 0, doc);
+ l_set_buffer_global(editor);
if (!closing) l_handle_event("buffer_after_switch", -1);
lua_pop(lua, 2); // buffer table and buffers
}
@@ -421,10 +400,10 @@ void l_goto_scintilla_buffer(GtkWidget *editor, int n, bool absolute) {
/**
* Sets the global 'buffer' variable to be the document in the specified
* Scintilla object.
- * @param sci The Scintilla object whose buffer is to be 'buffer'.
+ * @param editor The Scintilla widget housing the buffer to be 'buffer'.
*/
-void l_set_buffer_global(ScintillaObject *sci) {
- sptr_t doc = SS(sci, SCI_GETDOCPOINTER);
+void l_set_buffer_global(GtkWidget *editor) {
+ sptr_t doc = SS(editor, SCI_GETDOCPOINTER, 0, 0);
lua_getfield(lua, LUA_REGISTRYINDEX, "buffers");
lua_pushnil(lua);
while (lua_next(lua, -2))
@@ -442,7 +421,7 @@ void l_set_buffer_global(ScintillaObject *sci) {
* and deletes the last Scintilla window before closing the state.
*/
void l_close() {
- closing = true;
+ closing = TRUE;
while (unsplit_window(focused_editor)) ; // need space to fix compiler warning
lua_getfield(lua, LUA_REGISTRYINDEX, "buffers");
lua_pushnil(lua);
@@ -480,7 +459,7 @@ static void clear_table(lua_State *lua, int abs_index) {
* @param table The table in 'textadept' to check for key in.
* @param key String key to check for in table.
*/
-bool l_ista2function(const char *table, const char *key) {
+int l_ista2function(const char *table, const char *key) {
lua_getglobal(lua, "textadept");
if (lua_istable(lua, -1)) {
lua_getfield(lua, -1, table);
@@ -488,11 +467,11 @@ bool l_ista2function(const char *table, const char *key) {
if (lua_istable(lua, -1)) {
lua_getfield(lua, -1, key);
lua_remove(lua, -2); // table
- if (lua_isfunction(lua, -1)) return true;
+ if (lua_isfunction(lua, -1)) return TRUE;
lua_pop(lua, 1); // non-function
} else lua_pop(lua, 1); // non-table
} else lua_pop(lua, 1); // textadept
- return false;
+ return FALSE;
}
/**
@@ -503,13 +482,13 @@ bool l_ista2function(const char *table, const char *key) {
* @param nargs The number of arguments to pass to the Lua function to call.
* @param retn Optional number of expected return values. Defaults to 0.
* @param keep_return Optional flag indicating whether or not to keep the return
- * values at the top of the stack. If false, discards the return values.
- * Defaults to false.
+ * values at the top of the stack. If FALSE, discards the return values.
+ * Defaults to FALSE.
*/
-static bool l_call_function(int nargs, int retn=0, bool keep_return=false) {
+static int l_call_function(int nargs, int retn, int keep_return) {
int ret = lua_pcall(lua, nargs, retn, 0);
if (ret == 0) {
- bool result = (retn > 0) ? lua_toboolean(lua, -1) == 1 : true;
+ int result = (retn > 0) ? lua_toboolean(lua, -1) == 1 : TRUE;
if (retn > 0 && !keep_return) lua_pop(lua, retn); // retn
return result;
} else {
@@ -519,7 +498,7 @@ static bool l_call_function(int nargs, int retn=0, bool keep_return=false) {
printf("Lua Error: %s\n", lua_tostring(lua, -1));
lua_settop(lua, 0);
}
- return false;
+ return FALSE;
}
/**
@@ -530,7 +509,7 @@ static bool l_call_function(int nargs, int retn=0, bool keep_return=false) {
*/
static int l_rawgeti_int(lua_State *lua, int index, int n) {
lua_rawgeti(lua, index, n);
- int ret = static_cast<int>(lua_tointeger(lua, -1));
+ int ret = lua_tointeger(lua, -1);
lua_pop(lua, 1); // integer
return ret;
}
@@ -556,7 +535,7 @@ static const char *l_rawget_str(lua_State *lua, int index, const char *k) {
* @param callback A GCallback associated with each menu item.
* @param submenu Flag indicating whether or not this menu is a submenu.
*/
-GtkWidget *l_create_gtkmenu(lua_State *lua, GCallback callback, bool submenu) {
+GtkWidget *l_create_gtkmenu(lua_State *lua, GCallback callback, int submenu) {
GtkWidget *menu = gtk_menu_new(), *menu_item = 0, *submenu_root = 0;
const char *label;
lua_getfield(lua, -1, "title");
@@ -570,17 +549,17 @@ GtkWidget *l_create_gtkmenu(lua_State *lua, GCallback callback, bool submenu) {
while (lua_next(lua, -2)) {
if (lua_istable(lua, -1)) {
lua_getfield(lua, -1, "title");
- bool is_submenu = !lua_isnil(lua, -1);
+ int is_submenu = !lua_isnil(lua, -1);
lua_pop(lua, 1); // title
if (is_submenu)
gtk_menu_shell_append(GTK_MENU_SHELL(menu),
- l_create_gtkmenu(lua, callback, true));
+ l_create_gtkmenu(lua, callback, TRUE));
else
if (lua_objlen(lua, -1) == 2) {
lua_rawgeti(lua, -1, 1);
lua_rawgeti(lua, -2, 2);
label = lua_tostring(lua, -2);
- int menu_id = static_cast<int>(lua_tointeger(lua, -1));
+ int menu_id = lua_tointeger(lua, -1);
lua_pop(lua, 2); // label and id
if (label) {
if (g_str_has_prefix(label, "gtk-"))
@@ -590,7 +569,7 @@ GtkWidget *l_create_gtkmenu(lua_State *lua, GCallback callback, bool submenu) {
else
menu_item = gtk_menu_item_new_with_mnemonic(label);
g_signal_connect(menu_item, "activate", callback,
- reinterpret_cast<gpointer>(menu_id));
+ GINT_TO_POINTER(menu_id));
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
}
} else warn("gtkmenu: { 'menu label', id_number } expected");
@@ -608,17 +587,17 @@ GtkWidget *l_create_gtkmenu(lua_State *lua, GCallback callback, bool submenu) {
* @param arg_idx The initial stack index to start converting at. It is
* incremented as parameters are read from the stack.
*/
-static long l_toscintillaparam(lua_State *lua, int type, int &arg_idx) {
+static long l_toscintillaparam(lua_State *lua, int type, int *arg_idx) {
if (type == tSTRING)
- return reinterpret_cast<long>(lua_tostring(lua, arg_idx++));
+ return (long)lua_tostring(lua, (*arg_idx)++);
else if (type == tBOOL)
- return lua_toboolean(lua, arg_idx++);
+ return lua_toboolean(lua, (*arg_idx)++);
else if (type == tKEYMOD)
- return (static_cast<int>(luaL_checkinteger(lua, arg_idx++)) & 0xFFFF) |
- ((static_cast<int>(luaL_checkinteger(lua, arg_idx++)) &
+ return (luaL_checkinteger(lua, (*arg_idx)++) & 0xFFFF) |
+ ((luaL_checkinteger(lua, (*arg_idx)++) &
(SCMOD_SHIFT | SCMOD_CTRL | SCMOD_ALT)) << 16);
else if (type > tVOID && type < tBOOL)
- return luaL_checklong(lua, arg_idx++);
+ return luaL_checklong(lua, (*arg_idx)++);
else
return 0;
}
@@ -631,8 +610,7 @@ static long l_toscintillaparam(lua_State *lua, int type, int &arg_idx) {
* @param narg The relative stack position of the buffer table.
*/
static void l_check_focused_buffer(lua_State *lua, int narg) {
- ScintillaObject *sci = SCINTILLA(focused_editor);
- sptr_t cur_doc = SS(sci, SCI_GETDOCPOINTER);
+ sptr_t cur_doc = SS(focused_editor, SCI_GETDOCPOINTER, 0, 0);
luaL_argcheck(lua, cur_doc == l_checkdocpointer(lua, narg), 1,
"the indexed Buffer is not the focused one");
}
@@ -646,8 +624,8 @@ static void l_check_focused_buffer(lua_State *lua, int narg) {
* list should contain Lua types followed by the data of that type to pass.
* The list is terminated by a -1.
*/
-bool l_handle_event(const char *s, ...) {
- if (!l_ista2function("events", "handle")) return false;
+int l_handle_event(const char *s, ...) {
+ if (!l_ista2function("events", "handle")) return FALSE;
lua_pushstring(lua, s);
int n = 1;
va_list ap;
@@ -658,13 +636,13 @@ bool l_handle_event(const char *s, ...) {
if (type == LUA_TNIL)
lua_pushnil(lua);
else if (type == LUA_TBOOLEAN)
- lua_pushboolean(lua, reinterpret_cast<long>(arg));
+ lua_pushboolean(lua, (long)arg);
else if (type == LUA_TNUMBER)
- lua_pushinteger(lua, reinterpret_cast<long>(arg));
+ lua_pushinteger(lua, (long)arg);
else if (type == LUA_TSTRING)
- lua_pushstring(lua, reinterpret_cast<char*>(arg));
+ lua_pushstring(lua, (char *)arg);
else if (type == LUA_TLIGHTUSERDATA || type == LUA_TTABLE) {
- long ref = reinterpret_cast<long>(arg);
+ long ref = (long)arg;
lua_rawgeti(lua, LUA_REGISTRYINDEX, ref);
luaL_unref(lua, LUA_REGISTRYINDEX, ref);
} else warn("events.handle: ignored invalid argument type");
@@ -672,7 +650,7 @@ bool l_handle_event(const char *s, ...) {
type = va_arg(ap, int);
}
va_end(ap);
- return l_call_function(n, 1);
+ return l_call_function(n, 1, FALSE);
}
#define l_pushscninteger(i, n) { \
@@ -684,7 +662,7 @@ bool l_handle_event(const char *s, ...) {
* Handles a Scintilla notification.
* @param n The Scintilla notification struct.
*/
-void l_handle_scnnotification(SCNotification *n) {
+void l_handle_scnnotification(struct SCNotification *n) {
if (!l_ista2function("events", "notification")) return;
lua_newtable(lua);
l_pushscninteger(n->nmhdr.code, "code");
@@ -697,15 +675,15 @@ void l_handle_scnnotification(SCNotification *n) {
l_pushscninteger(n->length, "length");
l_pushscninteger(n->linesAdded, "lines_added");
l_pushscninteger(n->message, "message");
- l_pushscninteger(static_cast<int>(n->wParam), "wParam");
- l_pushscninteger(static_cast<int>(n->lParam), "lParam");
+ l_pushscninteger(n->wParam, "wParam");
+ l_pushscninteger(n->lParam, "lParam");
l_pushscninteger(n->line, "line");
l_pushscninteger(n->foldLevelNow, "fold_level_now");
l_pushscninteger(n->foldLevelPrev, "fold_level_prev");
l_pushscninteger(n->margin, "margin");
l_pushscninteger(n->x, "x");
l_pushscninteger(n->y, "y");
- l_call_function(1);
+ l_call_function(1, 0, FALSE);
}
/**
@@ -721,7 +699,7 @@ void l_ta_popup_context_menu(GdkEventButton *event) {
gtk_widget_show_all(menu);
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
event ? event->button : 0,
- gdk_event_get_time(reinterpret_cast<GdkEvent*>(event)));
+ gdk_event_get_time((GdkEvent *)event));
} else if (!lua_isnil(lua, -1))
warn("textadept.context_menu: gtkmenu expected");
lua_pop(lua, 1); // textadept.context_menu
@@ -771,7 +749,7 @@ void l_pm_popup_context_menu(GdkEventButton *event) {
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(pm_view));
if (gtk_tree_selection_get_selected(sel, NULL, &iter))
path = gtk_tree_model_get_path(model, &iter);
- lua_pushlightuserdata(lua, const_cast<GdkEventButton*>(event));
+ lua_pushlightuserdata(lua, (GdkEventButton *)event);
int ref = luaL_ref(lua, LUA_REGISTRYINDEX);
l_handle_event("pm_context_menu_request", LUA_TTABLE,
l_pm_pathtableref(GTK_TREE_STORE(model), path),
@@ -784,43 +762,42 @@ void l_pm_popup_context_menu(GdkEventButton *event) {
/**
* Calls Scintilla with appropriate parameters and returs appropriate values.
* @param lua The Lua State.
- * @param sci The Scintilla object to call.
+ * @param editor The Scintilla window to call.
* @param msg The integer message index to call Scintilla with.
* @param p1_type The Lua type of p1, the Scintilla w parameter.
* @param p2_type The Lua type of p2, the Scintilla l parameter.
* @param rt_type The Lua type of the Scintilla return parameter.
* @param arg The index on the Lua stack where arguments to Scintilla begin.
*/
-static int l_call_scintilla(lua_State *lua, ScintillaObject *sci, int msg,
+static int l_call_scintilla(lua_State *lua, GtkWidget *editor, int msg,
int p1_type, int p2_type, int rt_type, int arg) {
long params[2] = {0, 0};
- int params_needed = 2, len = 0;
- bool string_return = false;
+ int params_needed = 2, len = 0, string_return = FALSE;
char *return_string = 0;
// Set the w and l parameters appropriately for Scintilla.
if (p1_type == tLENGTH && p2_type == tSTRING) {
- params[0] = static_cast<long>(lua_strlen(lua, arg));
- params[1] = reinterpret_cast<long>(lua_tostring(lua, arg));
+ params[0] = (long)lua_strlen(lua, arg);
+ params[1] = (long)lua_tostring(lua, arg);
params_needed = 0;
} else if (p2_type == tSTRINGRESULT) {
- string_return = true;
+ string_return = TRUE;
params_needed = (p1_type == tLENGTH) ? 0 : 1;
}
- if (params_needed > 0) params[0] = l_toscintillaparam(lua, p1_type, arg);
- if (params_needed > 1) params[1] = l_toscintillaparam(lua, p2_type, arg);
+ if (params_needed > 0) params[0] = l_toscintillaparam(lua, p1_type, &arg);
+ if (params_needed > 1) params[1] = l_toscintillaparam(lua, p2_type, &arg);
if (string_return) { // if a string return, create a buffer for it
- len = SS(sci, msg, params[0], 0);
+ len = SS(editor, msg, params[0], 0);
if (p1_type == tLENGTH) params[0] = len;
- return_string = reinterpret_cast<char*>(malloc(len + 1));
+ return_string = malloc(len + 1);
return_string[len] = '\0';
if (msg == SCI_GETTEXT || msg == SCI_GETSELTEXT || msg == SCI_GETCURLINE)
len--; // Scintilla appends '\0' for these messages; compensate
- params[1] = reinterpret_cast<long>(return_string);
+ params[1] = (long)return_string;
}
// Send the message to Scintilla and return the appropriate values.
- int result = SS(sci, msg, params[0], params[1]);
+ int result = SS(editor, msg, params[0], params[1]);
arg = lua_gettop(lua);
if (string_return) lua_pushlstring(lua, return_string, len);
if (rt_type == tBOOL) lua_pushboolean(lua, result);
@@ -835,15 +812,13 @@ static int l_call_scintilla(lua_State *lua, ScintillaObject *sci, int msg,
* @see l_buffer_mt_index
*/
static int l_call_buffer_function(lua_State *lua) {
- int sci_idx = lua_upvalueindex(1); // closure from __index
- ScintillaObject *sci =
- reinterpret_cast<ScintillaObject*>(lua_touserdata(lua, sci_idx));
+ GtkWidget *editor = l_togtkwidget(lua, lua_upvalueindex(1));
int buffer_func_table_idx = lua_upvalueindex(2);
int msg = l_rawgeti_int(lua, buffer_func_table_idx, 1);
int rt_type = l_rawgeti_int(lua, buffer_func_table_idx, 2);
int p1_type = l_rawgeti_int(lua, buffer_func_table_idx, 3);
int p2_type = l_rawgeti_int(lua, buffer_func_table_idx, 4);
- return l_call_scintilla(lua, sci, msg, p1_type, p2_type, rt_type, 2);
+ return l_call_scintilla(lua, editor, msg, p1_type, p2_type, rt_type, 2);
}
/**
@@ -855,7 +830,6 @@ static int l_call_buffer_function(lua_State *lua) {
* @param lua The Lua State.
*/
static int l_buffer_mt_index(lua_State *lua) {
- ScintillaObject *sci = SCINTILLA(focused_editor);
const char *key = luaL_checkstring(lua, 2);
lua_getfield(lua, LUA_REGISTRYINDEX, "buffer_functions");
@@ -864,7 +838,7 @@ static int l_buffer_mt_index(lua_State *lua) {
if (lua_istable(lua, -1)) {
l_check_focused_buffer(lua, 1);
// Of the form { msg, rt_type, p1_type, p2_type }
- lua_pushlightuserdata(lua, const_cast<ScintillaObject*>(sci));
+ lua_pushlightuserdata(lua, (GtkWidget *)focused_editor);
l_insert(lua, -1); // shift buffer_functions down
lua_pushcclosure(lua, l_call_buffer_function, 2);
return 1;
@@ -880,7 +854,7 @@ static int l_buffer_mt_index(lua_State *lua) {
int rt_type = l_rawgeti_int(lua, -1, 3);
int p1_type = l_rawgeti_int(lua, -1, 4);
if (p1_type != tVOID) { // indexible property
- sptr_t doc = SS(sci, SCI_GETDOCPOINTER);
+ sptr_t doc = SS(focused_editor, SCI_GETDOCPOINTER, 0, 0);
lua_newtable(lua);
lua_pushstring(lua, key);
lua_setfield(lua, -2, "property");
@@ -888,7 +862,8 @@ static int l_buffer_mt_index(lua_State *lua) {
lua_setfield(lua, -2, "doc_pointer");
l_mt(lua, "_bufferp_mt", l_bufferp_mt_index, l_bufferp_mt_newindex);
return 1;
- } else return l_call_scintilla(lua, sci, msg, p1_type, tVOID, rt_type, 2);
+ } else return l_call_scintilla(lua, focused_editor, msg, p1_type, tVOID,
+ rt_type, 2);
} else lua_pop(lua, 1); // non-table
lua_rawget(lua, 1);
@@ -907,8 +882,6 @@ static int l_buffer_mt_index(lua_State *lua) {
* getter and setter properties, it is 2 because the index is an argument.
*/
static int l_bufferp_mt_(lua_State *lua, int n, const char *prop, int arg) {
- ScintillaObject *sci = SCINTILLA(focused_editor);
-
lua_getfield(lua, LUA_REGISTRYINDEX, "buffer_properties");
lua_getfield(lua, -1, prop);
lua_remove(lua, -2); // ta_buffer_properties
@@ -926,7 +899,8 @@ static int l_bufferp_mt_(lua_State *lua, int n, const char *prop, int arg) {
}
luaL_argcheck(lua, msg != 0, arg,
(n == 1) ? "write-only property" : "read-only property");
- return l_call_scintilla(lua, sci, msg, p1_type, p2_type, rt_type, arg);
+ return l_call_scintilla(lua, focused_editor, msg, p1_type, p2_type, rt_type,
+ arg);
} else lua_pop(lua, 1); // non-table
(lua_gettop(lua) > 2) ? lua_rawset(lua, 1) : lua_rawget(lua, 1);
@@ -948,7 +922,7 @@ static int l_bufferp_mt_newindex(lua_State *lua) {
static int l_view_mt_index(lua_State *lua) {
const char *key = lua_tostring(lua, 2);
if (streq(key, "doc_pointer"))
- lua_pushinteger(lua, SS(SCINTILLA(l_checkview(lua, 1)), SCI_GETDOCPOINTER));
+ lua_pushinteger(lua, SS(l_checkview(lua, 1), SCI_GETDOCPOINTER, 0, 0));
else if (streq(key, "size")) {
GtkWidget *editor = l_checkview(lua, 1);
if (GTK_IS_PANED(gtk_widget_get_parent(editor))) {
@@ -964,7 +938,7 @@ static int l_view_mt_newindex(lua_State *lua) {
const char *key = lua_tostring(lua, 2);
if (streq(key, "size")) {
GtkWidget *pane = gtk_widget_get_parent(l_checkview(lua, 1));
- int size = static_cast<int>(luaL_checkinteger(lua, 3));
+ int size = luaL_checkinteger(lua, 3);
if (size < 0) size = 0;
if (GTK_IS_PANED(pane)) gtk_paned_set_position(GTK_PANED(pane), size);
} else lua_rawset(lua, 1);
@@ -979,7 +953,7 @@ static int l_ta_mt_index(lua_State *lua) {
else if (streq(key, "title"))
lua_pushstring(lua, gtk_window_get_title(GTK_WINDOW(window)));
else if (streq(key, "focused_doc_pointer"))
- lua_pushinteger(lua, SS(SCINTILLA(focused_editor), SCI_GETDOCPOINTER));
+ lua_pushinteger(lua, SS(focused_editor, SCI_GETDOCPOINTER, 0, 0));
else if (streq(key, "clipboard_text")) {
char *text =
gtk_clipboard_wait_for_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
@@ -1007,9 +981,9 @@ static int l_ta_mt_newindex(lua_State *lua) {
else if (streq(key, "title"))
gtk_window_set_title(GTK_WINDOW(window), lua_tostring(lua, 3));
else if (streq(key, "statusbar_text"))
- set_statusbar_text(lua_tostring(lua, 3), false);
+ set_statusbar_text(lua_tostring(lua, 3), FALSE);
else if (streq(key, "docstatusbar_text"))
- set_statusbar_text(lua_tostring(lua, 3), true);
+ set_statusbar_text(lua_tostring(lua, 3), TRUE);
else if (streq(key, "focused_doc_pointer") || streq(key, "clipboard_text"))
luaL_argerror(lua, 3, "read-only property");
else if (streq(key, "menubar")) {
@@ -1028,8 +1002,8 @@ static int l_ta_mt_newindex(lua_State *lua) {
"{ width, height } table expected");
lua_rawgeti(lua, 3, 1);
lua_rawgeti(lua, 3, 2);
- int width = static_cast<int>(lua_tointeger(lua, -2));
- int height = static_cast<int>(lua_tointeger(lua, -1));
+ int width = lua_tointeger(lua, -2);
+ int height = lua_tointeger(lua, -1);
lua_pop(lua, 2); // width, height
if (width > 0 && height > 0)
gtk_window_resize(GTK_WINDOW(window), width, height);
@@ -1070,7 +1044,8 @@ static int l_pm_mt_newindex(lua_State *lua) {
luaL_argcheck(lua, path, 3, "bad path");
int *indices = gtk_tree_path_get_indices(path);
GtkTreePath *ipath = gtk_tree_path_new_from_indices(indices[0], -1);
- for (int i = 1; i < gtk_tree_path_get_depth(path); i++)
+ int i;
+ for (i = 1; i < gtk_tree_path_get_depth(path); i++)
if (gtk_tree_view_row_expanded(GTK_TREE_VIEW(pm_view), ipath) ||
gtk_tree_view_expand_row(GTK_TREE_VIEW(pm_view), ipath, FALSE))
gtk_tree_path_append_index(ipath, indices[i]);
@@ -1150,16 +1125,16 @@ static int l_cf_buffer_delete(lua_State *lua) {
sptr_t doc = l_checkdocpointer(lua, 1);
lua_getfield(lua, LUA_REGISTRYINDEX, "buffers");
if (lua_objlen(lua, -1) > 1)
- l_goto_scintilla_buffer(focused_editor, -1, false);
+ l_goto_scintilla_buffer(focused_editor, -1, FALSE);
else
- new_scintilla_buffer(SCINTILLA(focused_editor), true, true);
+ new_scintilla_buffer(focused_editor, TRUE, TRUE);
remove_scintilla_buffer(doc);
l_handle_event("buffer_deleted", -1);
return 0;
}
static int l_cf_ta_buffer_new(lua_State *lua) {
- new_scintilla_buffer(SCINTILLA(focused_editor), true, true);
+ new_scintilla_buffer(focused_editor, TRUE, TRUE);
lua_getfield(lua, LUA_REGISTRYINDEX, "buffers");
lua_rawgeti(lua, -1, lua_objlen(lua, -1));
return 1;
@@ -1168,17 +1143,16 @@ static int l_cf_ta_buffer_new(lua_State *lua) {
static int l_cf_buffer_text_range(lua_State *lua) {
l_check_focused_buffer(lua, 1);
#ifndef MAC
- TextRange tr;
+ struct TextRange tr;
#else
Scintilla::TextRange tr;
#endif
tr.chrg.cpMin = luaL_checkinteger(lua, 2);
tr.chrg.cpMax = luaL_checkinteger(lua, 3);
int length = tr.chrg.cpMax - tr.chrg.cpMin;
- char *text = reinterpret_cast<char*>(malloc(sizeof(char) * length + 1));
+ char *text = malloc(length + 1);
tr.lpstrText = text;
- SS(SCINTILLA(focused_editor), SCI_GETTEXTRANGE, 0,
- reinterpret_cast<long>(&tr));
+ SS(focused_editor, SCI_GETTEXTRANGE, 0, (long)(&tr));
lua_pushlstring(lua, text, length);
g_free(text);
return 1;
@@ -1193,7 +1167,7 @@ static int l_cf_view_focus(lua_State *lua) {
static int l_cf_view_split(lua_State *lua) {
GtkWidget *editor = l_checkview(lua, 1);
- bool vertical = true;
+ int vertical = TRUE;
if (lua_gettop(lua) > 1) vertical = lua_toboolean(lua, 2) == 1;
split_window(editor, vertical);
lua_pushvalue(lua, 1); // old view
@@ -1209,11 +1183,11 @@ static int l_cf_view_unsplit(lua_State *lua) {
#define child1(p) gtk_paned_get_child1(GTK_PANED(p))
#define child2(p) gtk_paned_get_child2(GTK_PANED(p))
-#define editor_dpi(e) \
- l_get_docpointer_index(SS(SCINTILLA(e), SCI_GETDOCPOINTER))
+#define editor_dpi(editor) \
+ l_get_docpointer_index(SS(editor, SCI_GETDOCPOINTER, 0, 0))
void l_create_entry(lua_State *lua, GtkWidget *c1, GtkWidget *c2,
- bool vertical) {
+ int vertical) {
lua_newtable(lua);
if (GTK_IS_PANED(c1))
l_create_entry(lua, child1(c1), child2(c1), GTK_IS_HPANED(c1) == 1);
@@ -1243,9 +1217,9 @@ static int l_cf_ta_get_split_table(lua_State *lua) {
return 1;
}
-static int l_cf_ta_goto_(lua_State *lua, GtkWidget *editor, bool buffer) {
- int n = static_cast<int>(luaL_checkinteger(lua, 1));
- bool absolute = (lua_gettop(lua) > 1) ? lua_toboolean(lua, 2) == 1 : true;
+static int l_cf_ta_goto_(lua_State *lua, GtkWidget *editor, int buffer) {
+ int n = luaL_checkinteger(lua, 1);
+ int absolute = (lua_gettop(lua) > 1) ? lua_toboolean(lua, 2) == 1 : TRUE;
buffer ? l_goto_scintilla_buffer(editor, n, absolute)
: l_goto_scintilla_window(editor, n, absolute);
return 0;
@@ -1255,13 +1229,13 @@ static int l_cf_ta_goto_(lua_State *lua, GtkWidget *editor, bool buffer) {
// to handlers will not throw 'indexed buffer is not the focused one' error.
static int l_cf_view_goto_buffer(lua_State *lua) {
GtkWidget *editor = l_checkview(lua, 1);
- bool switch_focus = editor != focused_editor;
+ int switch_focus = editor != focused_editor;
GtkWidget *orig_focused_editor = focused_editor;
- if (switch_focus) SS(SCINTILLA(editor), SCI_SETFOCUS, true);
+ if (switch_focus) SS(editor, SCI_SETFOCUS, TRUE, 0);
lua_remove(lua, 1); // view table
- l_cf_ta_goto_(lua, editor, true);
+ l_cf_ta_goto_(lua, editor, TRUE);
if (switch_focus) {
- SS(SCINTILLA(editor), SCI_SETFOCUS, false);
+ SS(editor, SCI_SETFOCUS, FALSE, 0);
gtk_widget_grab_focus(orig_focused_editor);
}
return 0;
@@ -1269,9 +1243,9 @@ static int l_cf_view_goto_buffer(lua_State *lua) {
static int l_cf_ta_dialog(lua_State *lua) {
GCDialogType type = gcocoadialog_type(luaL_checkstring(lua, 1));
- int argc = lua_gettop(lua) - 1;
- const char **argv = static_cast<const char**>(malloc(argc * sizeof(char *)));
- for (int i = 0; i < argc; i++) argv[i] = luaL_checkstring(lua, i + 2);
+ int i, argc = lua_gettop(lua) - 1;
+ const char **argv = malloc(argc * sizeof(char *));
+ for (i = 0; i < argc; i++) argv[i] = luaL_checkstring(lua, i + 2);
char *out = gcocoadialog(type, argc, argv);
lua_pushstring(lua, out);
free(out);
@@ -1280,17 +1254,17 @@ static int l_cf_ta_dialog(lua_State *lua) {
}
static int l_cf_ta_goto_window(lua_State *lua) {
- return l_cf_ta_goto_(lua, focused_editor, false);
+ return l_cf_ta_goto_(lua, focused_editor, FALSE);
}
-static void t_menu_activate(GtkWidget *, gpointer id) {
+static void t_menu_activate(GtkWidget *menu, gpointer id) {
l_handle_event("menu_clicked", LUA_TNUMBER, GPOINTER_TO_INT(id), -1);
}
static int l_cf_ta_gtkmenu(lua_State *lua) {
luaL_checktype(lua, 1, LUA_TTABLE);
- GtkWidget *menu = l_create_gtkmenu(lua, G_CALLBACK(t_menu_activate), false);
- lua_pushlightuserdata(lua, const_cast<GtkWidget*>(menu));
+ GtkWidget *menu = l_create_gtkmenu(lua, G_CALLBACK(t_menu_activate), FALSE);
+ lua_pushlightuserdata(lua, (GtkWidget *)menu);
return 1;
}
@@ -1301,35 +1275,35 @@ static int l_cf_ta_iconv(lua_State *lua) {
const char *from = luaL_checkstring(lua, 3);
char *converted = g_convert(text, text_len, to, from, NULL, &conv_len, NULL);
if (converted) {
- lua_pushlstring(lua, const_cast<char*>(converted), conv_len);
+ lua_pushlstring(lua, converted, conv_len);
g_free(converted);
} else luaL_error(lua, "Conversion failed");
return 1;
}
-static int l_cf_ta_quit(lua_State *) {
+static int l_cf_ta_quit(lua_State *lua) {
GdkEventAny event;
event.type = GDK_DELETE;
event.window = window->window;
event.send_event = TRUE;
- gdk_event_put(reinterpret_cast<GdkEvent*>(&event));
+ gdk_event_put((GdkEvent *)(&event));
return 0;
}
static int l_cf_ta_reset(lua_State *lua) {
l_handle_event("resetting", -1);
- l_init(0, NULL, true);
- lua_pushboolean(lua, true);
+ l_init(0, NULL, TRUE);
+ lua_pushboolean(lua, TRUE);
lua_setglobal(lua, "RESETTING");
l_load_script("init.lua");
lua_pushnil(lua);
lua_setglobal(lua, "RESETTING");
l_set_view_global(focused_editor);
- l_set_buffer_global(SCINTILLA(focused_editor));
+ l_set_buffer_global(focused_editor);
return 0;
}
-static int l_cf_pm_activate(lua_State *) {
+static int l_cf_pm_activate(lua_State *lua) {
g_signal_emit_by_name(G_OBJECT(pm_entry), "activate");
return 0;
}
@@ -1340,7 +1314,7 @@ static int l_cf_pm_add_browser(lua_State *lua) {
return 0;
}
-static int l_cf_pm_clear(lua_State *) {
+static int l_cf_pm_clear(lua_State *lua) {
gtk_tree_store_clear(
GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(pm_view))));
return 0;
@@ -1385,14 +1359,14 @@ static int l_cf_pm_fill(lua_State *lua) {
char *item;
gtk_tree_model_iter_nth_child(model, &child, initial_iter_p, 0);
gtk_tree_model_get(model, &child, 1, &item, -1);
- if (strcmp(reinterpret_cast<const char*>(item), "\0dummy") == 0)
+ if (strcmp((const char *)item, "\0dummy") == 0)
gtk_tree_store_remove(store, &child);
g_free(item);
}
return 0;
}
-static void pm_menu_activate(GtkWidget *, gpointer id) {
+static void pm_menu_activate(GtkWidget *menu, gpointer id) {
GtkTreePath *path = NULL;
GtkTreeIter iter;
GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(pm_view));
@@ -1409,49 +1383,49 @@ static int l_cf_pm_show_context_menu(lua_State *lua) {
GdkEventButton *event = NULL;
if (lua_gettop(lua) > 1) {
if (lua_isuserdata(lua, 2))
- event = reinterpret_cast<GdkEventButton*>(lua_touserdata(lua, 2));
+ event = (GdkEventButton *)lua_touserdata(lua, 2);
lua_pop(lua, 1); // userdata
}
luaL_checktype(lua, 1, LUA_TTABLE);
- GtkWidget *menu = l_create_gtkmenu(lua, G_CALLBACK(pm_menu_activate), false);
+ GtkWidget *menu = l_create_gtkmenu(lua, G_CALLBACK(pm_menu_activate), FALSE);
gtk_widget_show_all(menu);
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
event ? event->button : 0,
- gdk_event_get_time(reinterpret_cast<GdkEvent*>(event)));
+ gdk_event_get_time((GdkEvent *)event));
return 0;
}
-static int l_cf_pm_focus(lua_State *) {
+static int l_cf_pm_focus(lua_State *lua) {
pm_toggle_focus();
return 0;
}
-static int l_cf_find_focus(lua_State *) {
+static int l_cf_find_focus(lua_State *lua) {
find_toggle_focus();
return 0;
}
-static int l_cf_find_next(lua_State *) {
+static int l_cf_find_next(lua_State *lua) {
g_signal_emit_by_name(G_OBJECT(fnext_button), "clicked");
return 0;
}
-static int l_cf_find_prev(lua_State *) {
+static int l_cf_find_prev(lua_State *lua) {
g_signal_emit_by_name(G_OBJECT(fprev_button), "clicked");
return 0;
}
-static int l_cf_find_replace(lua_State *) {
+static int l_cf_find_replace(lua_State *lua) {
g_signal_emit_by_name(G_OBJECT(r_button), "clicked");
return 0;
}
-static int l_cf_find_replace_all(lua_State *) {
+static int l_cf_find_replace_all(lua_State *lua) {
g_signal_emit_by_name(G_OBJECT(ra_button), "clicked");
return 0;
}
-static int l_cf_ce_focus(lua_State *) {
+static int l_cf_ce_focus(lua_State *lua) {
ce_toggle_focus();
return 0;
}
diff --git a/src/textadept.c b/src/textadept.c
index dafb6549..0f52e16c 100644
--- a/src/textadept.c
+++ b/src/textadept.c
@@ -21,16 +21,16 @@ using namespace Scintilla;
GtkWidget *window, *focused_editor, *menubar, *statusbar, *docstatusbar;
char *textadept_home;
-static void s_notification(GtkWidget *, gint, gpointer lParam, gpointer);
-static void s_command(GtkWidget *editor, gint wParam, gpointer, gpointer);
-static gbool s_keypress(GtkWidget *, GdkEventKey *event, gpointer);
-static gbool s_buttonpress(GtkWidget *, GdkEventButton *event, gpointer);
+static void s_notification(GtkWidget *, gint, gpointer, gpointer);
+static void s_command(GtkWidget *, gint, gpointer, gpointer);
+static gbool s_keypress(GtkWidget *, GdkEventKey *, gpointer);
+static gbool s_buttonpress(GtkWidget *, GdkEventButton *, gpointer);
static gbool w_focus(GtkWidget *, GdkEventFocus *, gpointer);
-static gbool w_keypress(GtkWidget *, GdkEventKey *event, gpointer);
+static gbool w_keypress(GtkWidget *, GdkEventKey *, gpointer);
static gbool w_exit(GtkWidget *, GdkEventAny *, gpointer);
#ifdef MAC
-static OSErr w_ae_open(const AppleEvent *event, AppleEvent *, long);
-static OSErr w_ae_quit(const AppleEvent *event, AppleEvent *, long);
+static OSErr w_ae_open(const AppleEvent *, AppleEvent *, long);
+static OSErr w_ae_quit(const AppleEvent *, AppleEvent *, long);
#endif
// Project Manager
@@ -38,20 +38,20 @@ GtkWidget *pm_view, *pm_entry, *pm_container;
GtkWidget *pm_create_ui();
GtkTreeStore *pm_store;
-static int pm_search_equal_func(GtkTreeModel *model, int col, const char *key,
- GtkTreeIter *iter, gpointer);
-static int pm_sort_iter_compare_func(GtkTreeModel *model, GtkTreeIter *a,
- GtkTreeIter *b, gpointer);
+static int pm_search_equal_func(GtkTreeModel *, int, const char *,
+ GtkTreeIter *, gpointer);
+static int pm_sort_iter_compare_func(GtkTreeModel *, GtkTreeIter *,
+ GtkTreeIter *, gpointer);
static void pm_entry_activated(GtkWidget *, gpointer);
static void pm_entry_changed(GtkComboBoxEntry *, gpointer);
-static gbool pm_keypress(GtkWidget *, GdkEventKey *event, gpointer);
-static void pm_row_expanded(GtkTreeView *, GtkTreeIter *, GtkTreePath *path,
+static gbool pm_keypress(GtkWidget *, GdkEventKey *, gpointer);
+static void pm_row_expanded(GtkTreeView *, GtkTreeIter *, GtkTreePath *,
gpointer);
-static void pm_row_collapsed(GtkTreeView *, GtkTreeIter *iter, GtkTreePath *,
+static void pm_row_collapsed(GtkTreeView *, GtkTreeIter *, GtkTreePath *,
gpointer);
-static void pm_row_activated(GtkTreeView *view, GtkTreePath *path,
+static void pm_row_activated(GtkTreeView *, GtkTreePath *,
GtkTreeViewColumn *, gpointer);
-static gbool pm_buttonpress(GtkTreeView *, GdkEventButton *event, gpointer);
+static gbool pm_buttonpress(GtkTreeView *, GdkEventButton *, gpointer);
static gbool pm_popup_menu(GtkWidget *, gpointer);
// Find/Replace
@@ -61,8 +61,8 @@ GtkWidget *findbox, *find_entry, *replace_entry, *fnext_button, *fprev_button,
GtkWidget *find_create_ui();
GtkListStore *find_store, *repl_store;
-static void find_button_clicked(GtkWidget *button, gpointer);
-static gbool find_entry_keypress(GtkWidget *, GdkEventKey *event, gpointer);
+static void find_button_clicked(GtkWidget *, gpointer);
+static gbool find_entry_keypress(GtkWidget *, GdkEventKey *, gpointer);
// Command Entry
GtkWidget *command_entry;
@@ -71,10 +71,10 @@ GtkEntryCompletion *command_entry_completion;
static int cec_match_func(GtkEntryCompletion *, const char *, GtkTreeIter *,
gpointer);
-static gbool cec_match_selected(GtkEntryCompletion *, GtkTreeModel *model,
- GtkTreeIter *iter, gpointer);
-static void c_activated(GtkWidget *widget, gpointer);
-static gbool c_keypress(GtkWidget *, GdkEventKey *event, gpointer);
+static gbool cec_match_selected(GtkEntryCompletion *, GtkTreeModel *,
+ GtkTreeIter *, gpointer);
+static void c_activated(GtkWidget *, gpointer);
+static gbool c_keypress(GtkWidget *, GdkEventKey *, gpointer);
/**
* Runs Textadept in Linux or Mac.
@@ -85,13 +85,17 @@ static gbool c_keypress(GtkWidget *, GdkEventKey *event, gpointer);
*/
int main(int argc, char **argv) {
#if !(WIN32 || MAC)
- textadept_home = g_file_read_link("/proc/self/exe", NULL);
+ textadept_home = malloc(FILENAME_MAX);
+ sprintf(textadept_home, "/proc/%i/exe", getpid());
+ readlink(textadept_home, textadept_home, FILENAME_MAX);
+ char *last_slash = strrchr(textadept_home, '/');
+ if (last_slash) *last_slash = '\0';
#elif MAC
CFBundleRef bundle = CFBundleGetMainBundle();
if (bundle) {
const char *bundle_path = CFURL_TO_STR(CFBundleCopyBundleURL(bundle));
textadept_home = g_strconcat(bundle_path, "/Contents/Resources/", NULL);
- } else textadept_home = static_cast<char*>(calloc(1, 1));
+ } else textadept_home = calloc(1, 1);
// GTK-OSX does not parse ~/.gtkrc-2.0; parse it manually
char *user_home = g_strconcat(getenv("HOME"), "/.gtkrc-2.0", NULL);
gtk_rc_parse(user_home);
@@ -100,7 +104,7 @@ int main(int argc, char **argv) {
char *last_slash = strrchr(textadept_home, G_DIR_SEPARATOR);
if (last_slash) *last_slash = '\0';
gtk_init(&argc, &argv);
- if (!l_init(argc, argv, false)) return 1;
+ if (!l_init(argc, argv, FALSE)) return 1;
create_ui();
l_load_script("init.lua");
gtk_main();
@@ -113,8 +117,9 @@ int main(int argc, char **argv) {
* Runs Textadept in Windows.
* @see main
*/
-int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR lpCmdLine, int) {
- textadept_home = static_cast<char*>(malloc(FILENAME_MAX));
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
+ LPSTR lpCmdLine, int nCmdShow) {
+ textadept_home = malloc(FILENAME_MAX);
GetModuleFileName(0, textadept_home, FILENAME_MAX);
return main(1, &lpCmdLine);
}
@@ -136,7 +141,8 @@ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR lpCmdLine, int) {
void create_ui() {
GList *icon_list = NULL;
const char *icons[] = { "16x16", "32x32", "48x48", "64x64", "128x128" };
- for (int i = 0; i < 5; i++) {
+ int i;
+ for (i = 0; i < 5; i++) {
char *icon_file =
g_strconcat(textadept_home, "/core/images/ta_", icons[i], ".png", NULL);
GdkPixbuf *pb = gdk_pixbuf_new_from_file(icon_file, NULL);
@@ -144,7 +150,7 @@ void create_ui() {
g_free(icon_file);
}
gtk_window_set_default_icon_list(icon_list);
- g_list_foreach(icon_list, reinterpret_cast<GFunc>(g_object_unref), NULL);
+ g_list_foreach(icon_list, (GFunc)g_object_unref, NULL);
g_list_free(icon_list);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
@@ -155,9 +161,9 @@ void create_ui() {
#ifdef MAC
AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
- NewAEEventHandlerUPP(w_ae_open), 0, false);
+ NewAEEventHandlerUPP(w_ae_open), 0, FALSE);
AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
- NewAEEventHandlerUPP(w_ae_quit), 0, false);
+ NewAEEventHandlerUPP(w_ae_quit), 0, FALSE);
#endif
GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
@@ -175,7 +181,7 @@ void create_ui() {
GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
gtk_paned_add2(GTK_PANED(pane), hbox);
- GtkWidget *editor = new_scintilla_window(NULL);
+ GtkWidget *editor = new_scintilla_window(0);
gtk_box_pack_start(GTK_BOX(hbox), editor, TRUE, TRUE, 0);
GtkWidget *find = find_create_ui();
@@ -235,7 +241,7 @@ void create_ui() {
GtkWidget *new_scintilla_window(sptr_t buffer_id) {
GtkWidget *editor = scintilla_new();
gtk_widget_set_size_request(editor, 1, 1); // minimum size
- SS(SCINTILLA(editor), SCI_USEPOPUP, 0, 0);
+ SS(editor, SCI_USEPOPUP, 0, 0);
signal(editor, SCINTILLA_NOTIFY, s_notification);
signal(editor, "command", s_command);
signal(editor, "key-press-event", s_keypress);
@@ -244,9 +250,9 @@ GtkWidget *new_scintilla_window(sptr_t buffer_id) {
gtk_widget_grab_focus(editor);
focused_editor = editor;
if (buffer_id) {
- SS(SCINTILLA(editor), SCI_SETDOCPOINTER, 0, buffer_id);
- new_scintilla_buffer(SCINTILLA(editor), false, false);
- } else new_scintilla_buffer(SCINTILLA(editor), false, true);
+ SS(editor, SCI_SETDOCPOINTER, 0, buffer_id);
+ new_scintilla_buffer(editor, FALSE, FALSE);
+ } else new_scintilla_buffer(editor, FALSE, TRUE);
l_set_view_global(editor);
l_handle_event("view_new", -1);
return editor;
@@ -267,29 +273,29 @@ void remove_scintilla_window(GtkWidget *editor) {
* The buffer's default properties are set via 'set_default_buffer_properties',
* but the default style is set here.
* Generates a 'buffer_new' event.
- * @param sci The ScintillaObject to associate the buffer with.
- * @param create Flag indicating whether or not to create a buffer. If false,
- * the ScintillaObject already has a buffer associated with it (typically
+ * @param editor The Scintilla window to associate the buffer with.
+ * @param create Flag indicating whether or not to create a buffer. If FALSE,
+ * the Scintilla window already has a buffer associated with it (typically
* because new_scintilla_window was passed a non-NULL buffer_id).
* @param addref Flag indicating whether or not to add a reference to the buffer
- * in the ScintillaObject when create is false. This is necessary for creating
- * Scintilla windows in split views. If a buffer appears in two separate
- * Scintilla windows, that buffer should have multiple references so when one
- * Scintilla window closes, the buffer is not deleted because its reference
- * count is not zero.
+ * in the Scintilla window when create is FALSE. This is necessary for
+ * creating Scintilla windows in split views. If a buffer appears in two
+ * separate Scintilla windows, that buffer should have multiple references so
+ * when one Scintilla window closes, the buffer is not deleted because its
+ * reference count is not zero.
* @see l_add_scintilla_buffer
*/
-void new_scintilla_buffer(ScintillaObject *sci, bool create, bool addref) {
+void new_scintilla_buffer(GtkWidget *editor, int create, int addref) {
sptr_t doc;
- doc = SS(sci, SCI_GETDOCPOINTER);
+ doc = SS(editor, SCI_GETDOCPOINTER, 0, 0);
if (create) { // create the new document
- doc = SS(sci, SCI_CREATEDOCUMENT);
- l_goto_scintilla_buffer(focused_editor, l_add_scintilla_buffer(doc), true);
+ doc = SS(editor, SCI_CREATEDOCUMENT, 0, 0);
+ l_goto_scintilla_buffer(focused_editor, l_add_scintilla_buffer(doc), TRUE);
} else if (addref) {
l_add_scintilla_buffer(doc);
- SS(sci, SCI_ADDREFDOCUMENT, 0, doc);
+ SS(editor, SCI_ADDREFDOCUMENT, 0, doc);
}
- l_set_buffer_global(sci);
+ l_set_buffer_global(editor);
l_handle_event("buffer_new", -1);
l_handle_event("update_ui", -1); // update document status
}
@@ -301,7 +307,7 @@ void new_scintilla_buffer(ScintillaObject *sci, bool create, bool addref) {
*/
void remove_scintilla_buffer(sptr_t doc) {
l_remove_scintilla_buffer(doc);
- SS(SCINTILLA(focused_editor), SCI_RELEASEDOCUMENT, 0, doc);
+ SS(focused_editor, SCI_RELEASEDOCUMENT, 0, doc);
}
/**
@@ -311,15 +317,15 @@ void remove_scintilla_buffer(sptr_t doc) {
* @param vertical Flag indicating whether to split the window vertically or
* horozontally.
*/
-void split_window(GtkWidget *editor, bool vertical) {
+void split_window(GtkWidget *editor, int vertical) {
g_object_ref(editor);
- int first_line = SS(SCINTILLA(editor), SCI_GETFIRSTVISIBLELINE);
- int current_pos = SS(SCINTILLA(editor), SCI_GETCURRENTPOS);
- int anchor = SS(SCINTILLA(editor), SCI_GETANCHOR);
+ int first_line = SS(editor, SCI_GETFIRSTVISIBLELINE, 0, 0);
+ int current_pos = SS(editor, SCI_GETCURRENTPOS, 0, 0);
+ int anchor = SS(editor, SCI_GETANCHOR, 0, 0);
int middle =
(vertical ? editor->allocation.width : editor->allocation.height) / 2;
- sptr_t curdoc = SS(SCINTILLA(editor), SCI_GETDOCPOINTER);
+ sptr_t curdoc = SS(editor, SCI_GETDOCPOINTER, 0, 0);
GtkWidget *neweditor = new_scintilla_window(curdoc);
GtkWidget *parent = gtk_widget_get_parent(editor);
gtk_container_remove(GTK_CONTAINER(parent), editor);
@@ -331,9 +337,9 @@ void split_window(GtkWidget *editor, bool vertical) {
gtk_widget_show_all(pane);
gtk_widget_grab_focus(neweditor);
- SS(SCINTILLA(neweditor), SCI_SETSEL, anchor, current_pos);
- int new_first_line = SS(SCINTILLA(neweditor), SCI_GETFIRSTVISIBLELINE);
- SS(SCINTILLA(neweditor), SCI_LINESCROLL, first_line - new_first_line);
+ SS(neweditor, SCI_SETSEL, anchor, current_pos);
+ int new_first_line = SS(neweditor, SCI_GETFIRSTVISIBLELINE, 0, 0);
+ SS(neweditor, SCI_LINESCROLL, first_line - new_first_line, 0);
g_object_unref(editor);
}
@@ -359,9 +365,9 @@ void remove_scintilla_windows_in_pane(GtkWidget *pane) {
* @see remove_scintilla_windows_in_pane
* @see remove_scintilla_window
*/
-bool unsplit_window(GtkWidget *editor) {
+int unsplit_window(GtkWidget *editor) {
GtkWidget *pane = gtk_widget_get_parent(editor);
- if (!GTK_IS_PANED(pane)) return false;
+ if (!GTK_IS_PANED(pane)) return FALSE;
GtkWidget *other = gtk_paned_get_child1(GTK_PANED(pane));
if (other == editor) other = gtk_paned_get_child2(GTK_PANED(pane));
g_object_ref(editor);
@@ -382,7 +388,7 @@ bool unsplit_window(GtkWidget *editor) {
gtk_widget_grab_focus(GTK_WIDGET(editor));
g_object_unref(editor);
g_object_unref(other);
- return true;
+ return TRUE;
}
/**
@@ -409,7 +415,7 @@ void set_menubar(GtkWidget *new_menubar) {
* @param docbar Flag indicating whether or not the statusbar text is for the
* docstatusbar.
*/
-void set_statusbar_text(const char *text, bool docbar) {
+void set_statusbar_text(const char *text, int docbar) {
GtkWidget *bar = docbar ? docstatusbar : statusbar;
if (!bar) return; // this is sometimes called before a bar is available
gtk_statusbar_pop(GTK_STATUSBAR(bar), 0);
@@ -428,15 +434,16 @@ static void switch_to_view(GtkWidget *editor) {
l_handle_event("view_before_switch", -1);
focused_editor = editor;
l_set_view_global(editor);
- l_set_buffer_global(SCINTILLA(editor));
+ l_set_buffer_global(editor);
l_handle_event("view_after_switch", -1);
}
/**
* Signal for a Scintilla notification.
*/
-static void s_notification(GtkWidget *editor, gint, gpointer lParam, gpointer) {
- SCNotification *n = reinterpret_cast<SCNotification*>(lParam);
+static void s_notification(GtkWidget *editor, gint wParam, gpointer lParam,
+ gpointer udata) {
+ struct SCNotification *n = (struct SCNotification *)lParam;
if (focused_editor != editor &&
(n->nmhdr.code == SCN_URIDROPPED || n->nmhdr.code == SCN_SAVEPOINTLEFT))
switch_to_view(editor);
@@ -447,7 +454,8 @@ static void s_notification(GtkWidget *editor, gint, gpointer lParam, gpointer) {
* Signal for a Scintilla command.
* Currently handles SCEN_SETFOCUS.
*/
-static void s_command(GtkWidget *editor, gint wParam, gpointer, gpointer) {
+static void s_command(GtkWidget *editor, gint wParam, gpointer lParam,
+ gpointer udata) {
if (wParam >> 16 == SCEN_SETFOCUS) switch_to_view(editor);
}
@@ -455,7 +463,7 @@ static void s_command(GtkWidget *editor, gint wParam, gpointer, gpointer) {
* Signal for a Scintilla keypress.
* Collects the modifier states as flags and calls Lua to handle the keypress.
*/
-static gbool s_keypress(GtkWidget *, GdkEventKey *event, gpointer) {
+static gbool s_keypress(GtkWidget *editor, GdkEventKey *event, gpointer udata) {
return l_handle_event("keypress",
LUA_TNUMBER, event->keyval,
LUA_TBOOLEAN, event->state & GDK_SHIFT_MASK,
@@ -473,7 +481,8 @@ static gbool s_keypress(GtkWidget *, GdkEventKey *event, gpointer) {
* If it is a right-click, popup a context menu.
* @see l_ta_popup_context_menu
*/
-static gbool s_buttonpress(GtkWidget *, GdkEventButton *event, gpointer) {
+static gbool s_buttonpress(GtkWidget *editor, GdkEventButton *event,
+ gpointer udata) {
if (event->type != GDK_BUTTON_PRESS || event->button != 3) return FALSE;
l_ta_popup_context_menu(event);
return TRUE;
@@ -482,7 +491,7 @@ static gbool s_buttonpress(GtkWidget *, GdkEventButton *event, gpointer) {
/**
* Signal for a Textadept window focus change.
*/
-static gbool w_focus(GtkWidget *, GdkEventFocus *, gpointer) {
+static gbool w_focus(GtkWidget *window, GdkEventFocus *event, gpointer udata) {
if (focused_editor && !GTK_WIDGET_HAS_FOCUS(focused_editor))
gtk_widget_grab_focus(focused_editor);
return FALSE;
@@ -493,7 +502,7 @@ static gbool w_focus(GtkWidget *, GdkEventFocus *, gpointer) {
* Currently handled keypresses:
* - Escape - hides the search frame if it's open.
*/
-static gbool w_keypress(GtkWidget *, GdkEventKey *event, gpointer) {
+static gbool w_keypress(GtkWidget *window, GdkEventKey *event, gpointer udata) {
if (event->keyval == 0xff1b && GTK_WIDGET_VISIBLE(findbox) &&
!GTK_WIDGET_HAS_FOCUS(command_entry)) {
gtk_widget_hide(findbox);
@@ -508,7 +517,7 @@ static gbool w_keypress(GtkWidget *, GdkEventKey *event, gpointer) {
* Generates a 'quit' event.
* @see l_close
*/
-static gbool w_exit(GtkWidget *, GdkEventAny *, gpointer) {
+static gbool w_exit(GtkWidget *window, GdkEventAny *event, gpointer udata) {
if (!l_handle_event("quit", -1)) return TRUE;
l_close();
scintilla_release_resources();
@@ -526,7 +535,8 @@ static OSErr w_ae_open(const AppleEvent *event, AppleEvent *, long) {
if (AEGetParamDesc(event, keyDirectObject, typeAEList, &file_list) == noErr) {
long count = 0;
AECountItems(&file_list, &count);
- for (int i = 1; i <= count; i++) {
+ int i;
+ for (i = 1; i <= count; i++) {
FSRef fsref;
AEGetNthPtr(&file_list, i, typeFSRef, NULL, NULL, &fsref, sizeof(FSRef),
NULL);
@@ -630,10 +640,10 @@ void pm_toggle_focus() {
* @param iter The GtkTreeIter for each tree node being compared.
*/
static int pm_search_equal_func(GtkTreeModel *model, int col, const char *key,
- GtkTreeIter *iter, gpointer) {
+ GtkTreeIter *iter, gpointer udata) {
const char *text;
gtk_tree_model_get(model, iter, col, &text, -1);
- return strstr(text, key) == NULL; // false is really a match like strcmp
+ return strstr(text, key) == NULL; // FALSE is really a match like strcmp
}
/**
@@ -643,7 +653,7 @@ static int pm_search_equal_func(GtkTreeModel *model, int col, const char *key,
* @param b The GtkTreeIter for the other tree node being compared.
*/
static int pm_sort_iter_compare_func(GtkTreeModel *model, GtkTreeIter *a,
- GtkTreeIter *b, gpointer) {
+ GtkTreeIter *b, gpointer udata) {
char *a_text, *b_text;
gtk_tree_model_get(model, a, 1, &a_text, -1);
gtk_tree_model_get(model, b, 1, &b_text, -1);
@@ -667,7 +677,7 @@ static int pm_sort_iter_compare_func(GtkTreeModel *model, GtkTreeIter *a,
* Signal for the activation of the Project Manager entry.
* Requests contents for the Project Manager.
*/
-static void pm_entry_activated(GtkWidget *, gpointer) {
+static void pm_entry_activated(GtkWidget *entry, gpointer udata) {
l_handle_event("pm_contents_request", LUA_TTABLE,
l_pm_pathtableref(pm_store, NULL), LUA_TNIL, 0, -1);
}
@@ -676,7 +686,7 @@ static void pm_entry_activated(GtkWidget *, gpointer) {
* Signal for a change of the text in the Project Manager entry.
* Requests contents for the Project Manager.
*/
-static void pm_entry_changed(GtkComboBoxEntry *, gpointer) {
+static void pm_entry_changed(GtkComboBoxEntry *entry, gpointer udata) {
l_handle_event("pm_contents_request", LUA_TTABLE,
l_pm_pathtableref(pm_store, NULL), LUA_TNIL, 0, -1);
}
@@ -686,7 +696,7 @@ static void pm_entry_changed(GtkComboBoxEntry *, gpointer) {
* Currently handled keypresses:
* - Escape - Refocuses the Scintilla view.
*/
-static gbool pm_keypress(GtkWidget *, GdkEventKey *event, gpointer) {
+static gbool pm_keypress(GtkWidget *pm, GdkEventKey *event, gpointer udata) {
if (event->keyval == 0xff1b) {
gtk_widget_grab_focus(focused_editor);
return TRUE;
@@ -699,8 +709,8 @@ static gbool pm_keypress(GtkWidget *, GdkEventKey *event, gpointer) {
* Since a parent is given a dummy child by default in order to indicate that
* it is a parent, that dummy child is removed.
*/
-static void pm_row_expanded(GtkTreeView *, GtkTreeIter *, GtkTreePath *path,
- gpointer) {
+static void pm_row_expanded(GtkTreeView *view, GtkTreeIter *iter,
+ GtkTreePath *path, gpointer udata) {
char *path_str = gtk_tree_path_to_string(path);
l_handle_event("pm_contents_request", LUA_TTABLE,
l_pm_pathtableref(pm_store, path), LUA_TSTRING, path_str, -1);
@@ -713,8 +723,8 @@ static void pm_row_expanded(GtkTreeView *, GtkTreeIter *, GtkTreePath *path,
* Re-adds a dummy child to indicate this parent is still a parent. It will be
* removed when the parent is re-opened.
*/
-static void pm_row_collapsed(GtkTreeView *, GtkTreeIter *iter, GtkTreePath *,
- gpointer) {
+static void pm_row_collapsed(GtkTreeView *view, GtkTreeIter *iter,
+ GtkTreePath *path, gpointer udata) {
GtkTreeIter child;
gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(pm_store), &child, iter, 0);
while (gtk_tree_model_iter_has_child(GTK_TREE_MODEL(pm_store), iter))
@@ -730,7 +740,7 @@ static void pm_row_collapsed(GtkTreeView *, GtkTreeIter *iter, GtkTreePath *,
* collapsed. If the node is not a parent at all, a Lua action is performed.
*/
static void pm_row_activated(GtkTreeView *view, GtkTreePath *path,
- GtkTreeViewColumn *, gpointer) {
+ GtkTreeViewColumn *column, gpointer udata) {
if (!gtk_tree_view_expand_row(view, path, FALSE))
if (!gtk_tree_view_collapse_row(view, path))
l_handle_event("pm_item_selected", LUA_TTABLE,
@@ -742,7 +752,8 @@ static void pm_row_activated(GtkTreeView *view, GtkTreePath *path,
* If it is a right-click, popup a context menu for the selected item.
* @see l_pm_popup_context_menu
*/
-static gbool pm_buttonpress(GtkTreeView *, GdkEventButton *event, gpointer) {
+static gbool pm_buttonpress(GtkTreeView *view, GdkEventButton *event,
+ gpointer udata) {
if (event->type != GDK_BUTTON_PRESS || event->button != 3) return FALSE;
l_pm_popup_context_menu(event);
return TRUE;
@@ -753,7 +764,7 @@ static gbool pm_buttonpress(GtkTreeView *, GdkEventButton *event, gpointer) {
* Typically Shift+F10 activates this event.
* @see l_pm_popup_context_menu
*/
-static gbool pm_popup_menu(GtkWidget *, gpointer) {
+static gbool pm_popup_menu(GtkWidget *view, gpointer udata) {
l_pm_popup_context_menu(NULL);
return TRUE;
}
@@ -762,8 +773,8 @@ static gbool pm_popup_menu(GtkWidget *, gpointer) {
#define attach(w, x1, x2, y1, y2, xo, yo, xp, yp) \
gtk_table_attach(GTK_TABLE(findbox), w, x1, x2, y1, y2, xo, yo, xp, yp)
-#define ao_expand static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL)
-#define ao_normal static_cast<GtkAttachOptions>(GTK_SHRINK | GTK_FILL)
+#define ao_expand (GtkAttachOptions)(GTK_EXPAND | GTK_FILL)
+#define ao_normal (GtkAttachOptions)(GTK_SHRINK | GTK_FILL)
/**
* Creates the Find/Replace text frame.
@@ -875,7 +886,7 @@ static void find_add_to_history(const char *text, GtkListStore *store) {
* Signal for a Find frame button click.
* Performs the appropriate action depending on the button clicked.
*/
-static void find_button_clicked(GtkWidget *button, gpointer) {
+static void find_button_clicked(GtkWidget *button, gpointer udata) {
const char *find_text = gtk_entry_get_text(GTK_ENTRY(find_entry));
const char *repl_text = gtk_entry_get_text(GTK_ENTRY(replace_entry));
if (strlen(find_text) == 0) return;
@@ -897,7 +908,8 @@ static void find_button_clicked(GtkWidget *button, gpointer) {
/**
* Signal for a Find entry keypress.
*/
-static gbool find_entry_keypress(GtkWidget *, GdkEventKey *event, gpointer) {
+static gbool find_entry_keypress(GtkWidget *entry, GdkEventKey *event,
+ gpointer udata) {
return l_handle_event("find_keypress", LUA_TNUMBER, event->keyval, -1);
}
@@ -927,8 +939,8 @@ void ce_toggle_focus() {
* results from a call to Lua to make a list of possible completions. Therefore,
* every item in the list is valid.
*/
-static int cec_match_func(GtkEntryCompletion *, const char *, GtkTreeIter *,
- gpointer) {
+static int cec_match_func(GtkEntryCompletion *entry, const char *key,
+ GtkTreeIter *iter, gpointer udata) {
return 1;
}
@@ -937,8 +949,8 @@ static int cec_match_func(GtkEntryCompletion *, const char *, GtkTreeIter *,
* The last word at the cursor is replaced with the completion. A word consists
* of any alphanumeric character or underscore.
*/
-static gbool cec_match_selected(GtkEntryCompletion *, GtkTreeModel *model,
- GtkTreeIter *iter, gpointer) {
+static gbool cec_match_selected(GtkEntryCompletion *entry, GtkTreeModel *model,
+ GtkTreeIter *iter, gpointer udata) {
const char *entry_text = gtk_entry_get_text(GTK_ENTRY(command_entry));
const char *p = entry_text + strlen(entry_text) - 1;
while ((*p >= 'A' && *p <= 'Z') || (*p >= 'a' && *p <= 'z') ||
@@ -964,16 +976,16 @@ static gbool cec_match_selected(GtkEntryCompletion *, GtkTreeModel *model,
/**
* Signal for the 'enter' key being pressed in the Command Entry.
*/
-static void c_activated(GtkWidget *widget, gpointer) {
+static void c_activated(GtkWidget *entry, gpointer udata) {
l_handle_event("command_entry_command", LUA_TSTRING,
- gtk_entry_get_text(GTK_ENTRY(widget)), -1);
+ gtk_entry_get_text(GTK_ENTRY(entry)), -1);
ce_toggle_focus();
}
/**
* Signal for a keypress inside the Command Entry.
*/
-static gbool c_keypress(GtkWidget *, GdkEventKey *event, gpointer) {
+static gbool c_keypress(GtkWidget *entry, GdkEventKey *event, gpointer udata) {
return l_handle_event("command_entry_keypress", LUA_TNUMBER, event->keyval,
-1);
}
diff --git a/src/textadept.h b/src/textadept.h
index 1a5e60e1..0fd0487b 100644
--- a/src/textadept.h
+++ b/src/textadept.h
@@ -14,12 +14,10 @@
#include <SciLexer.h>
#include <ScintillaWidget.h>
-extern "C" {
#include <gcocoadialog.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
-}
#ifdef MAC
using namespace Scintilla;
@@ -32,43 +30,40 @@ extern GtkWidget *window, *focused_editor, *command_entry, *pm_container,
*match_case_opt, *whole_word_opt, *lua_opt, *in_files_opt;
extern char *textadept_home;
-static long SS(ScintillaObject *sci, unsigned int msg, unsigned long wParam=0,
- long lParam=0) {
- return scintilla_send_message(sci, msg, wParam, lParam);
-}
+#define SS(editor, m, w, l) scintilla_send_message(SCINTILLA(editor), m, w, l)
// textadept.c
void create_ui();
-GtkWidget *new_scintilla_window(sptr_t default_id);
-void remove_scintilla_window(GtkWidget *editor);
-void new_scintilla_buffer(ScintillaObject *sci, bool create, bool addref);
-void remove_scintilla_buffer(sptr_t doc);
-void split_window(GtkWidget *editor, bool vertical);
-bool unsplit_window(GtkWidget *editor);
-void set_menubar(GtkWidget *menubar);
-void set_statusbar_text(const char *text, bool docbar);
+GtkWidget *new_scintilla_window(sptr_t);
+void remove_scintilla_window(GtkWidget *);
+void new_scintilla_buffer(GtkWidget *, int, int);
+void remove_scintilla_buffer(sptr_t);
+void split_window(GtkWidget *, int);
+int unsplit_window(GtkWidget *);
+void set_menubar(GtkWidget *);
+void set_statusbar_text(const char *, int);
void pm_toggle_focus();
void find_toggle_focus();
void ce_toggle_focus();
// lua_interface.c
-bool l_init(int argc, char **argv, bool reinit);
+int l_init(int, char **, int);
void l_close();
-bool l_load_script(const char *script_file);
-void l_add_scintilla_window(GtkWidget *editor);
-void l_remove_scintilla_window(GtkWidget *editor);
-void l_goto_scintilla_window(GtkWidget *editor, int n, bool absolute);
-void l_set_view_global(GtkWidget *editor);
-int l_add_scintilla_buffer(sptr_t doc);
-void l_remove_scintilla_buffer(sptr_t doc);
-void l_goto_scintilla_buffer(GtkWidget *editor, int n, bool absolute);
-void l_set_buffer_global(ScintillaObject *sci);
+int l_load_script(const char *);
+void l_add_scintilla_window(GtkWidget *);
+void l_remove_scintilla_window(GtkWidget *);
+void l_goto_scintilla_window(GtkWidget *, int, int);
+void l_set_view_global(GtkWidget *);
+int l_add_scintilla_buffer(sptr_t);
+void l_remove_scintilla_buffer(sptr_t);
+void l_goto_scintilla_buffer(GtkWidget *, int, int);
+void l_set_buffer_global(GtkWidget *);
-bool l_handle_event(const char *e, ...);
-void l_handle_scnnotification(SCNotification *n);
-void l_ta_popup_context_menu(GdkEventButton *event);
+int l_handle_event(const char *, ...);
+void l_handle_scnnotification(struct SCNotification *);
+void l_ta_popup_context_menu(GdkEventButton *);
-int l_pm_pathtableref(GtkTreeStore *store, GtkTreePath *path);
-void l_pm_popup_context_menu(GdkEventButton *event);
+int l_pm_pathtableref(GtkTreeStore *, GtkTreePath *);
+void l_pm_popup_context_menu(GdkEventButton *);
#endif