📄 scintillagtk.cxx
字号:
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
//Platform::DebugPrintf("Draw %p %0d,%0d %0d,%0d\n", widget, area->x, area->y, area->width, area->height);
PRectangle rcPaint(area->x, area->y, area->x + area->width, area->y + area->height);
sciThis->SyncPaint(rcPaint);
if (GTK_WIDGET_DRAWABLE(PWidget(sciThis->wMain))) {
DrawChild(PWidget(sciThis->scrollbarh), area);
DrawChild(PWidget(sciThis->scrollbarv), area);
}
#ifdef INTERNATIONAL_INPUT
Point pt = sciThis->LocationFromPosition(sciThis->currentPos);
pt.y += sciThis->vs.lineHeight - 2;
if (pt.x < 0) pt.x = 0;
if (pt.y < 0) pt.y = 0;
CursorMoved(widget, pt.x, pt.y, sciThis);
#endif
}
gint ScintillaGTK::ExposeTextThis(GtkWidget * /*widget*/, GdkEventExpose *ose) {
paintState = painting;
rcPaint.left = ose->area.x;
rcPaint.top = ose->area.y;
rcPaint.right = ose->area.x + ose->area.width;
rcPaint.bottom = ose->area.y + ose->area.height;
PRectangle rcClient = GetClientRectangle();
paintingAllText = rcPaint.Contains(rcClient);
Surface *surfaceWindow = Surface::Allocate();
if (surfaceWindow) {
surfaceWindow->Init(PWidget(wText)->window, PWidget(wText));
Paint(surfaceWindow, rcPaint);
surfaceWindow->Release();
delete surfaceWindow;
}
if (paintState == paintAbandoned) {
// Painting area was insufficient to cover new styling or brace highlight positions
FullPaint();
}
paintState = notPainting;
return FALSE;
}
gint ScintillaGTK::ExposeText(GtkWidget *widget, GdkEventExpose *ose, ScintillaGTK *sciThis) {
return sciThis->ExposeTextThis(widget, ose);
}
gint ScintillaGTK::ExposeMain(GtkWidget *widget, GdkEventExpose *ose) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
//Platform::DebugPrintf("Expose Main %0d,%0d %0d,%0d\n",
//ose->area.x, ose->area.y, ose->area.width, ose->area.height);
return sciThis->Expose(widget, ose);
}
gint ScintillaGTK::Expose(GtkWidget *, GdkEventExpose *ose) {
//fprintf(stderr, "Expose %0d,%0d %0d,%0d\n",
//ose->area.x, ose->area.y, ose->area.width, ose->area.height);
#if GTK_MAJOR_VERSION < 2
paintState = painting;
rcPaint.left = ose->area.x;
rcPaint.top = ose->area.y;
rcPaint.right = ose->area.x + ose->area.width;
rcPaint.bottom = ose->area.y + ose->area.height;
PRectangle rcClient = GetClientRectangle();
paintingAllText = rcPaint.Contains(rcClient);
Surface *surfaceWindow = Surface::Allocate();
if (surfaceWindow) {
surfaceWindow->Init(PWidget(wMain)->window, PWidget(wMain));
// Fill the corner between the scrollbars
if (verticalScrollBarVisible) {
if (horizontalScrollBarVisible && (wrapState == eWrapNone)) {
PRectangle rcCorner = wMain.GetClientPosition();
rcCorner.left = rcCorner.right - scrollBarWidth + 1;
rcCorner.top = rcCorner.bottom - scrollBarHeight + 1;
//fprintf(stderr, "Corner %0d,%0d %0d,%0d\n",
//rcCorner.left, rcCorner.top, rcCorner.right, rcCorner.bottom);
surfaceWindow->FillRectangle(rcCorner,
vs.styles[STYLE_LINENUMBER].back.allocated);
}
}
//Paint(surfaceWindow, rcPaint);
surfaceWindow->Release();
delete surfaceWindow;
}
if (paintState == paintAbandoned) {
// Painting area was insufficient to cover new styling or brace highlight positions
FullPaint();
}
paintState = notPainting;
#else
// For GTK+ 2, the text is painted in ExposeText
gtk_container_propagate_expose(
GTK_CONTAINER(PWidget(wMain)), PWidget(scrollbarh), ose);
gtk_container_propagate_expose(
GTK_CONTAINER(PWidget(wMain)), PWidget(scrollbarv), ose);
#endif
return FALSE;
}
void ScintillaGTK::ScrollSignal(GtkAdjustment *adj, ScintillaGTK *sciThis) {
sciThis->ScrollTo(static_cast<int>(adj->value), false);
}
void ScintillaGTK::ScrollHSignal(GtkAdjustment *adj, ScintillaGTK *sciThis) {
sciThis->HorizontalScrollTo(static_cast<int>(adj->value * 2));
}
void ScintillaGTK::SelectionReceived(GtkWidget *widget,
GtkSelectionData *selection_data, guint) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
//Platform::DebugPrintf("Selection received\n");
sciThis->ReceivedSelection(selection_data);
}
void ScintillaGTK::SelectionGet(GtkWidget *widget,
GtkSelectionData *selection_data, guint info, guint) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
//Platform::DebugPrintf("Selection get\n");
sciThis->GetSelection(selection_data, info, &sciThis->copyText);
}
gint ScintillaGTK::SelectionClear(GtkWidget *widget, GdkEventSelection *selection_event) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
//Platform::DebugPrintf("Selection clear\n");
sciThis->UnclaimSelection(selection_event);
return gtk_selection_clear(widget, selection_event);
}
#if GTK_MAJOR_VERSION < 2
gint ScintillaGTK::SelectionNotify(GtkWidget *widget, GdkEventSelection *selection_event) {
//Platform::DebugPrintf("Selection notify\n");
return gtk_selection_notify(widget, selection_event);
}
#endif
void ScintillaGTK::DragBegin(GtkWidget *, GdkDragContext *) {
//Platform::DebugPrintf("DragBegin\n");
}
gboolean ScintillaGTK::DragMotion(GtkWidget *widget, GdkDragContext *context,
gint x, gint y, guint dragtime) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
//Platform::DebugPrintf("DragMotion %d %d %x %x %x\n", x, y,
// context->actions, context->suggested_action, sciThis);
Point npt(x, y);
sciThis->inDragDrop = true;
sciThis->SetDragPosition(sciThis->PositionFromLocation(npt));
gdk_drag_status(context, context->suggested_action, dragtime);
return FALSE;
}
void ScintillaGTK::DragLeave(GtkWidget *widget, GdkDragContext * /*context*/, guint) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
sciThis->SetDragPosition(invalidPosition);
//Platform::DebugPrintf("DragLeave %x\n", sciThis);
}
void ScintillaGTK::DragEnd(GtkWidget *widget, GdkDragContext * /*context*/) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
// If drag did not result in drop here or elsewhere
if (!sciThis->dragWasDropped)
sciThis->SetEmptySelection(sciThis->posDrag);
sciThis->SetDragPosition(invalidPosition);
//Platform::DebugPrintf("DragEnd %x %d\n", sciThis, sciThis->dragWasDropped);
}
gboolean ScintillaGTK::Drop(GtkWidget *widget, GdkDragContext * /*context*/,
gint, gint, guint) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
//Platform::DebugPrintf("Drop %x\n", sciThis);
sciThis->SetDragPosition(invalidPosition);
return FALSE;
}
void ScintillaGTK::DragDataReceived(GtkWidget *widget, GdkDragContext * /*context*/,
gint, gint, GtkSelectionData *selection_data, guint /*info*/, guint) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
sciThis->ReceivedDrop(selection_data);
sciThis->SetDragPosition(invalidPosition);
}
void ScintillaGTK::DragDataGet(GtkWidget *widget, GdkDragContext *context,
GtkSelectionData *selection_data, guint info, guint) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
sciThis->dragWasDropped = true;
if (sciThis->currentPos != sciThis->anchor) {
sciThis->GetSelection(selection_data, info, &sciThis->drag);
}
if (context->action == GDK_ACTION_MOVE) {
int selStart = sciThis->SelectionStart();
int selEnd = sciThis->SelectionEnd();
if (sciThis->posDrop > selStart) {
if (sciThis->posDrop > selEnd)
sciThis->posDrop = sciThis->posDrop - (selEnd - selStart);
else
sciThis->posDrop = selStart;
sciThis->posDrop = sciThis->pdoc->ClampPositionIntoDocument(sciThis->posDrop);
}
sciThis->ClearSelection();
}
sciThis->SetDragPosition(invalidPosition);
}
int ScintillaGTK::TimeOut(ScintillaGTK *sciThis) {
sciThis->Tick();
return 1;
}
void ScintillaGTK::PopUpCB(ScintillaGTK *sciThis, guint action, GtkWidget *) {
if (action) {
sciThis->Command(action);
}
}
gint ScintillaGTK::PressCT(GtkWidget *widget, GdkEventButton *event, ScintillaGTK *sciThis) {
if (event->window != widget->window)
return FALSE;
if (event->type != GDK_BUTTON_PRESS)
return FALSE;
Point pt;
pt.x = int(event->x);
pt.y = int(event->y);
sciThis->ct.MouseClick(pt);
sciThis->CallTipClick();
#if GTK_MAJOR_VERSION >= 2
return TRUE;
#else
return FALSE;
#endif
}
gint ScintillaGTK::ExposeCT(GtkWidget *widget, GdkEventExpose * /*ose*/, CallTip *ctip) {
Surface *surfaceWindow = Surface::Allocate();
if (surfaceWindow) {
surfaceWindow->Init(widget->window, widget);
ctip->PaintCT(surfaceWindow);
surfaceWindow->Release();
delete surfaceWindow;
}
return TRUE;
}
sptr_t ScintillaGTK::DirectFunction(
ScintillaGTK *sciThis, unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
return sciThis->WndProc(iMessage, wParam, lParam);
}
sptr_t scintilla_send_message(ScintillaObject *sci, unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
ScintillaGTK *psci = reinterpret_cast<ScintillaGTK *>(sci->pscin);
return psci->WndProc(iMessage, wParam, lParam);
}
static void scintilla_class_init (ScintillaClass *klass);
static void scintilla_init (ScintillaObject *sci);
extern void Platform_Initialise();
extern void Platform_Finalise();
guint scintilla_get_type() {
static guint scintilla_type = 0;
if (!scintilla_type) {
Platform_Initialise();
static GtkTypeInfo scintilla_info = {
"Scintilla",
sizeof (ScintillaObject),
sizeof (ScintillaClass),
(GtkClassInitFunc) scintilla_class_init,
(GtkObjectInitFunc) scintilla_init,
(gpointer) NULL,
(gpointer) NULL,
0
};
scintilla_type = gtk_type_unique(gtk_container_get_type(), &scintilla_info);
}
return scintilla_type;
}
void ScintillaGTK::ClassInit(GtkObjectClass* object_class, GtkWidgetClass *widget_class) {
// Define default signal handlers for the class: Could move more
// of the signal handlers here (those that currently attached to wDraw
// in Initialise() may require coordinate translation?)
object_class->destroy = Destroy;
widget_class->size_request = SizeRequest;
widget_class->size_allocate = SizeAllocate;
widget_class->expose_event = ExposeMain;
#if GTK_MAJOR_VERSION < 2
widget_class->draw = Draw;
#endif
widget_class->motion_notify_event = Motion;
widget_class->button_press_event = Press;
widget_class->button_release_event = MouseRelease;
#if PLAT_GTK_WIN32 || (GTK_MAJOR_VERSION >= 2)
widget_class->scroll_event = ScrollEvent;
#endif
widget_class->key_press_event = KeyPress;
widget_class->key_release_event = KeyRelease;
widget_class->focus_in_event = FocusIn;
widget_class->focus_out_event = FocusOut;
widget_class->selection_received = SelectionReceived;
widget_class->selection_get = SelectionGet;
widget_class->selection_clear_event = SelectionClear;
#if GTK_MAJOR_VERSION < 2
widget_class->selection_notify_event = SelectionNotify;
#endif
widget_class->drag_data_received = DragDataReceived;
widget_class->drag_motion = DragMotion;
widget_class->drag_leave = DragLeave;
widget_class->drag_end = DragEnd;
widget_class->drag_drop = Drop;
widget_class->drag_data_get = DragDataGet;
widget_class->realize = Realize;
widget_class->unrealize = UnRealize;
widget_class->map = Map;
widget_class->unmap = UnMap;
}
#if GTK_MAJOR_VERSION < 2
#define GTK_CLASS_TYPE(c) (c->type)
#define SIG_MARSHAL gtk_marshal_NONE__INT_POINTER
#define MARSHAL_ARGUMENTS GTK_TYPE_INT, GTK_TYPE_POINTER
#else
#define SIG_MARSHAL gtk_marshal_NONE__INT_INT
#define MARSHAL_ARGUMENTS GTK_TYPE_INT, GTK_TYPE_INT
#endif
static void scintilla_class_init(ScintillaClass *klass) {
GtkObjectClass *object_class = (GtkObjectClass*) klass;
GtkWidgetClass *widget_class = (GtkWidgetClass*) klass;
parent_class = (GtkWidgetClass*) gtk_type_class(gtk_container_get_type());
scintilla_signals[COMMAND_SIGNAL] = gtk_signal_new(
"command",
GTK_RUN_LAST,
GTK_CLASS_TYPE(object_class),
GTK_SIGNAL_OFFSET(ScintillaClass, command),
SIG_MARSHAL,
GTK_TYPE_NONE,
2, MARSHAL_ARGUMENTS);
scintilla_signals[NOTIFY_SIGNAL] = gtk_signal_new(
SCINTILLA_NOTIFY,
GTK_RUN_LAST,
GTK_CLASS_TYPE(object_class),
GTK_SIGNAL_OFFSET(ScintillaClass, notify),
SIG_MARSHAL,
GTK_TYPE_NONE,
2, MARSHAL_ARGUMENTS);
#if GTK_MAJOR_VERSION < 2
gtk_object_class_add_signals(object_class,
reinterpret_cast<unsigned int *>(scintilla_signals), LAST_SIGNAL);
#endif
klass->command = NULL;
klass->notify = NULL;
ScintillaGTK::ClassInit(object_class, widget_class);
}
static void scintilla_init(ScintillaObject *sci) {
GTK_WIDGET_SET_FLAGS(sci, GTK_CAN_FOCUS);
sci->pscin = new ScintillaGTK(sci);
}
GtkWidget* scintilla_new() {
return GTK_WIDGET(gtk_type_new(scintilla_get_type()));
}
void scintilla_set_id(ScintillaObject *sci, int id) {
ScintillaGTK *psci = reinterpret_cast<ScintillaGTK *>(sci->pscin);
psci->ctrlID = id;
}
void scintilla_release_resources(void) {
Platform_Finalise();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -