Skip to content

Commit

Permalink
Use active Scintilla namespace and fix name clashes.
Browse files Browse the repository at this point in the history
  • Loading branch information
orbitalquark committed Mar 15, 2018
1 parent d98a25a commit 7e49120
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 34 deletions.
38 changes: 19 additions & 19 deletions ScintillaCurses.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
#define wcwidth(_) 1 // TODO: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
#endif

using namespace Scintilla;

// Font handling.

/**
Expand Down Expand Up @@ -879,7 +881,7 @@ void Platform::Assert(const char *c, const char *file, int line) {
class ScintillaCurses : public ScintillaBase {
Surface *sur; // window surface to draw on
int width, height; // window dimensions
void (*callback)(Scintilla *, int, void *, void *); // SCNotification callback
void (*callback)(void *, int, void *, void *); // SCNotification callback
int scrollBarVPos, scrollBarHPos; // positions of the scroll bars
int scrollBarHeight, scrollBarWidth; // height and width of the scroll bars
SelectionText clipboard; // current clipboard text
Expand Down Expand Up @@ -920,8 +922,8 @@ class ScintillaCurses : public ScintillaBase {
* necessary. When the `WINDOW` is created, it will initially be full-screen.
* @param callback_ Callback function for Scintilla notifications.
*/
ScintillaCurses(void (*callback_)(Scintilla *, int, void *, void *)) :
width(0), height(0), scrollBarHeight(1), scrollBarWidth(1) {
ScintillaCurses(void (*callback_)(void *, int, void *, void *)) :
width(0), height(0), scrollBarHeight(1), scrollBarWidth(1) {
callback = callback_;
sur = Surface::Allocate(SC_TECHNOLOGY_DEFAULT);

Expand Down Expand Up @@ -1056,7 +1058,7 @@ class ScintillaCurses : public ScintillaBase {
/** Send Scintilla notifications to the parent. */
void NotifyParent(SCNotification scn) {
if (callback)
(*callback)(reinterpret_cast<Scintilla *>(this), 0, (void *)&scn, 0);
(*callback)(reinterpret_cast<void *>(this), 0, (void *)&scn, 0);
}
/**
* Handles an unconsumed key.
Expand Down Expand Up @@ -1398,24 +1400,22 @@ class ScintillaCurses : public ScintillaBase {

// Link with C. Documentation in Scintilla.h.
extern "C" {
Scintilla *scintilla_new(void (*callback)(Scintilla *, int, void *, void *)) {
return reinterpret_cast<Scintilla *>(new ScintillaCurses(callback));
void *scintilla_new(void (*callback)(void *, int, void *, void *)) {
return reinterpret_cast<void *>(new ScintillaCurses(callback));
}
WINDOW *scintilla_get_window(Scintilla *sci) {
WINDOW *scintilla_get_window(void *sci) {
return reinterpret_cast<ScintillaCurses *>(sci)->GetWINDOW();
}
sptr_t scintilla_send_message(Scintilla *sci, unsigned int iMessage,
uptr_t wParam, sptr_t lParam) {
sptr_t scintilla_send_message(void *sci, unsigned int iMessage, uptr_t wParam,
sptr_t lParam) {
return reinterpret_cast<ScintillaCurses *>(sci)->WndProc(iMessage, wParam,
lParam);
lParam);
}
void scintilla_send_key(Scintilla *sci, int key, bool shift, bool ctrl,
bool alt) {
void scintilla_send_key(void *sci, int key, bool shift, bool ctrl, bool alt) {
reinterpret_cast<ScintillaCurses *>(sci)->KeyPress(key, shift, ctrl, alt);
}
bool scintilla_send_mouse(Scintilla *sci, int event, unsigned int time,
int button, int y, int x, bool shift, bool ctrl,
bool alt) {
bool scintilla_send_mouse(void *sci, int event, unsigned int time, int button,
int y, int x, bool shift, bool ctrl, bool alt) {
ScintillaCurses *scicurses = reinterpret_cast<ScintillaCurses *>(sci);
WINDOW *w = scicurses->GetWINDOW();
int begy = getbegy(w), begx = getbegx(w);
Expand All @@ -1432,16 +1432,16 @@ bool scintilla_send_mouse(Scintilla *sci, int event, unsigned int time,
return (scicurses->MouseRelease(time, y, x, ctrl), true);
return false;
}
int scintilla_get_clipboard(Scintilla *sci, char *buffer) {
int scintilla_get_clipboard(void *sci, char *buffer) {
return reinterpret_cast<ScintillaCurses *>(sci)->GetClipboard(buffer);
}
void scintilla_noutrefresh(Scintilla *sci) {
void scintilla_noutrefresh(void *sci) {
reinterpret_cast<ScintillaCurses *>(sci)->NoutRefresh();
}
void scintilla_refresh(Scintilla *sci) {
void scintilla_refresh(void *sci) {
reinterpret_cast<ScintillaCurses *>(sci)->Refresh();
}
void scintilla_delete(Scintilla *sci) {
void scintilla_delete(void *sci) {
delete reinterpret_cast<ScintillaCurses *>(sci);
}
}
27 changes: 12 additions & 15 deletions ScintillaCurses.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@
extern "C" {
#endif

typedef void *Scintilla;
/**
* Creates a new Scintilla window.
* Curses does not have to be initialized before calling this function.
* @param callback A callback function for Scintilla notifications.
*/
Scintilla *scintilla_new(void (*callback)(Scintilla *sci, int iMessage,
void *wParam, void *lParam));
void *scintilla_new(void (*callback)(void *sci, int iMessage, void *wParam,
void *lParam));
/**
* Returns the curses `WINDOW` associated with the given Scintilla window.
* Curses must have been initialized prior to calling this function.
* @param sci The Scintilla window returned by `scintilla_new()`.
* @return curses `WINDOW`.
*/
WINDOW *scintilla_get_window(Scintilla *sci);
WINDOW *scintilla_get_window(void *sci);
/**
* Sends the given message with parameters to the given Scintilla window.
* Curses does not have to be initialized before calling this function.
Expand All @@ -33,8 +32,8 @@ WINDOW *scintilla_get_window(Scintilla *sci);
* @param wParam The first parameter.
* @param lParam The second parameter.
*/
sptr_t scintilla_send_message(Scintilla *sci, unsigned int iMessage,
uptr_t wParam, sptr_t lParam);
sptr_t scintilla_send_message(void *sci, unsigned int iMessage, uptr_t wParam,
sptr_t lParam);
/**
* Sends the specified key to the given Scintilla window for processing.
* If it is not consumed, an SCNotification will be emitted.
Expand All @@ -47,8 +46,7 @@ sptr_t scintilla_send_message(Scintilla *sci, unsigned int iMessage,
* pressed.
* @param alt Flag indicating whether or not the alt modifier key is pressed.
*/
void scintilla_send_key(Scintilla *sci, int key, bool shift, bool ctrl,
bool alt);
void scintilla_send_key(void *sci, int key, bool shift, bool ctrl, bool alt);
/**
* Sends the specified mouse event to the given Scintilla window for processing.
* Curses must have been initialized prior to calling this function.
Expand All @@ -66,9 +64,8 @@ void scintilla_send_key(Scintilla *sci, int key, bool shift, bool ctrl,
* @param alt Flag indicating whether or not the alt modifier key is pressed.
* @return whether or not Scintilla handled the mouse event
*/
bool scintilla_send_mouse(Scintilla *sci, int event, unsigned int time,
int button, int y, int x, bool shift, bool ctrl,
bool alt);
bool scintilla_send_mouse(void *sci, int event, unsigned int time, int button,
int y, int x, bool shift, bool ctrl, bool alt);
/**
* Copies the text of Scintilla's internal clipboard, not the primary and/or
* secondary X selections, into the given buffer and returns the size of the
Expand All @@ -81,29 +78,29 @@ bool scintilla_send_mouse(Scintilla *sci, int event, unsigned int time,
* @param buffer The buffer to copy clipboard text to.
* @return size of the clipboard text.
*/
int scintilla_get_clipboard(Scintilla *sci, char *buffer);
int scintilla_get_clipboard(void *sci, char *buffer);
/**
* Refreshes the Scintilla window on the virtual screen.
* This should be done along with the normal curses `noutrefresh()`, as the
* virtual screen is updated when calling this function.
* Curses must have been initialized prior to calling this function.
* @param sci The Scintilla window returned by `scintilla_new()`.
*/
void scintilla_noutrefresh(Scintilla *sci);
void scintilla_noutrefresh(void *sci);
/**
* Refreshes the Scintilla window on the physical screen.
* This should be done along with the normal curses `refresh()`, as the physical
* screen is updated when calling this function.
* Curses must have been initialized prior to calling this function.
* @param sci The Scintilla window returned by `scintilla_new()`.
*/
void scintilla_refresh(Scintilla *sci);
void scintilla_refresh(void *sci);
/**
* Deletes the given Scintilla window.
* Curses must have been initialized prior to calling this function.
* @param sci The Scintilla window returned by `scintilla_new()`.
*/
void scintilla_delete(Scintilla *sci);
void scintilla_delete(void *sci);

/**
* Returns the curses `COLOR_PAIR` for the given curses foreground and
Expand Down
2 changes: 2 additions & 0 deletions jinx/jinx.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#define SSM(m, w, l) scintilla_send_message(sci, m, w, l)

typedef void Scintilla;

void scnotification(Scintilla *view, int msg, void *lParam, void *wParam) {
//struct SCNotification *scn = (struct SCNotification *)lParam;
//printw("SCNotification received: %i", scn->nmhdr.code);
Expand Down

0 comments on commit 7e49120

Please sign in to comment.