Update Scintilla to version 3.7.3
[geany-mirror.git] / scintilla / gtk / ScintillaGTK.h
blob6f69661f272bf3dc9fa5e0bacc098246381bb62b
1 // Scintilla source code edit control
2 // ScintillaGTK.h - GTK+ specific subclass of ScintillaBase
3 // Copyright 1998-2004 by Neil Hodgson <neilh@scintilla.org>
4 // The License.txt file describes the conditions under which this software may be distributed.
6 #ifndef SCINTILLAGTK_H
7 #define SCINTILLAGTK_H
9 #ifdef SCI_NAMESPACE
10 namespace Scintilla {
11 #endif
13 class ScintillaGTKAccessible;
15 #define OBJECT_CLASS GObjectClass
17 class ScintillaGTK : public ScintillaBase {
18 friend class ScintillaGTKAccessible;
20 _ScintillaObject *sci;
21 Window wText;
22 Window scrollbarv;
23 Window scrollbarh;
24 GtkAdjustment *adjustmentv;
25 GtkAdjustment *adjustmenth;
26 int verticalScrollBarWidth;
27 int horizontalScrollBarHeight;
29 SelectionText primary;
31 GdkEventButton *evbtn;
32 bool capturedMouse;
33 bool dragWasDropped;
34 int lastKey;
35 int rectangularSelectionModifier;
37 GtkWidgetClass *parentClass;
39 static GdkAtom atomClipboard;
40 static GdkAtom atomUTF8;
41 static GdkAtom atomString;
42 static GdkAtom atomUriList;
43 static GdkAtom atomDROPFILES_DND;
44 GdkAtom atomSought;
46 #if PLAT_GTK_WIN32
47 CLIPFORMAT cfColumnSelect;
48 #endif
50 Window wPreedit;
51 Window wPreeditDraw;
52 GtkIMContext *im_context;
53 PangoScript lastNonCommonScript;
55 // Wheel mouse support
56 unsigned int linesPerScroll;
57 GTimeVal lastWheelMouseTime;
58 gint lastWheelMouseDirection;
59 gint wheelMouseIntensity;
60 gdouble smoothScrollY;
61 gdouble smoothScrollX;
63 #if GTK_CHECK_VERSION(3,0,0)
64 cairo_rectangle_list_t *rgnUpdate;
65 #else
66 GdkRegion *rgnUpdate;
67 #endif
68 bool repaintFullWindow;
70 guint styleIdleID;
71 AtkObject *accessible;
73 // Private so ScintillaGTK objects can not be copied
74 ScintillaGTK(const ScintillaGTK &);
75 ScintillaGTK &operator=(const ScintillaGTK &);
77 public:
78 explicit ScintillaGTK(_ScintillaObject *sci_);
79 virtual ~ScintillaGTK();
80 static ScintillaGTK *FromWidget(GtkWidget *widget);
81 static void ClassInit(OBJECT_CLASS* object_class, GtkWidgetClass *widget_class, GtkContainerClass *container_class);
82 private:
83 virtual void Initialise();
84 virtual void Finalise();
85 virtual bool AbandonPaint();
86 virtual void DisplayCursor(Window::Cursor c);
87 virtual bool DragThreshold(Point ptStart, Point ptNow);
88 virtual void StartDrag();
89 int TargetAsUTF8(char *text);
90 int EncodedFromUTF8(char *utf8, char *encoded) const;
91 virtual bool ValidCodePage(int codePage) const;
92 public: // Public for scintilla_send_message
93 virtual sptr_t WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
94 private:
95 virtual sptr_t DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
96 struct TimeThunk {
97 TickReason reason;
98 ScintillaGTK *scintilla;
99 guint timer;
100 TimeThunk() : reason(tickCaret), scintilla(NULL), timer(0) {}
102 TimeThunk timers[tickDwell+1];
103 virtual bool FineTickerAvailable();
104 virtual bool FineTickerRunning(TickReason reason);
105 virtual void FineTickerStart(TickReason reason, int millis, int tolerance);
106 virtual void FineTickerCancel(TickReason reason);
107 virtual bool SetIdle(bool on);
108 virtual void SetMouseCapture(bool on);
109 virtual bool HaveMouseCapture();
110 virtual bool PaintContains(PRectangle rc);
111 void FullPaint();
112 virtual PRectangle GetClientRectangle() const;
113 virtual void ScrollText(int linesToMove);
114 virtual void SetVerticalScrollPos();
115 virtual void SetHorizontalScrollPos();
116 virtual bool ModifyScrollBars(int nMax, int nPage);
117 void ReconfigureScrollBars();
118 virtual void NotifyChange();
119 virtual void NotifyFocus(bool focus);
120 virtual void NotifyParent(SCNotification scn);
121 void NotifyKey(int key, int modifiers);
122 void NotifyURIDropped(const char *list);
123 const char *CharacterSetID() const;
124 virtual CaseFolder *CaseFolderForEncoding();
125 virtual std::string CaseMapString(const std::string &s, int caseMapping);
126 virtual int KeyDefault(int key, int modifiers);
127 virtual void CopyToClipboard(const SelectionText &selectedText);
128 virtual void Copy();
129 virtual void Paste();
130 virtual void CreateCallTipWindow(PRectangle rc);
131 virtual void AddToPopUp(const char *label, int cmd = 0, bool enabled = true);
132 bool OwnPrimarySelection();
133 virtual void ClaimSelection();
134 void GetGtkSelectionText(GtkSelectionData *selectionData, SelectionText &selText);
135 void ReceivedSelection(GtkSelectionData *selection_data);
136 void ReceivedDrop(GtkSelectionData *selection_data);
137 static void GetSelection(GtkSelectionData *selection_data, guint info, SelectionText *selected);
138 void StoreOnClipboard(SelectionText *clipText);
139 static void ClipboardGetSelection(GtkClipboard* clip, GtkSelectionData *selection_data, guint info, void *data);
140 static void ClipboardClearSelection(GtkClipboard* clip, void *data);
142 void UnclaimSelection(GdkEventSelection *selection_event);
143 void Resize(int width, int height);
145 // Callback functions
146 void RealizeThis(GtkWidget *widget);
147 static void Realize(GtkWidget *widget);
148 void UnRealizeThis(GtkWidget *widget);
149 static void UnRealize(GtkWidget *widget);
150 void MapThis();
151 static void Map(GtkWidget *widget);
152 void UnMapThis();
153 static void UnMap(GtkWidget *widget);
154 gint FocusInThis(GtkWidget *widget);
155 static gint FocusIn(GtkWidget *widget, GdkEventFocus *event);
156 gint FocusOutThis(GtkWidget *widget);
157 static gint FocusOut(GtkWidget *widget, GdkEventFocus *event);
158 static void SizeRequest(GtkWidget *widget, GtkRequisition *requisition);
159 #if GTK_CHECK_VERSION(3,0,0)
160 static void GetPreferredWidth(GtkWidget *widget, gint *minimalWidth, gint *naturalWidth);
161 static void GetPreferredHeight(GtkWidget *widget, gint *minimalHeight, gint *naturalHeight);
162 #endif
163 static void SizeAllocate(GtkWidget *widget, GtkAllocation *allocation);
164 #if GTK_CHECK_VERSION(3,0,0)
165 gboolean DrawTextThis(cairo_t *cr);
166 static gboolean DrawText(GtkWidget *widget, cairo_t *cr, ScintillaGTK *sciThis);
167 gboolean DrawThis(cairo_t *cr);
168 static gboolean DrawMain(GtkWidget *widget, cairo_t *cr);
169 #else
170 gboolean ExposeTextThis(GtkWidget *widget, GdkEventExpose *ose);
171 static gboolean ExposeText(GtkWidget *widget, GdkEventExpose *ose, ScintillaGTK *sciThis);
172 gboolean Expose(GtkWidget *widget, GdkEventExpose *ose);
173 static gboolean ExposeMain(GtkWidget *widget, GdkEventExpose *ose);
174 #endif
175 void ForAll(GtkCallback callback, gpointer callback_data);
176 static void MainForAll(GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data);
178 static void ScrollSignal(GtkAdjustment *adj, ScintillaGTK *sciThis);
179 static void ScrollHSignal(GtkAdjustment *adj, ScintillaGTK *sciThis);
180 gint PressThis(GdkEventButton *event);
181 static gint Press(GtkWidget *widget, GdkEventButton *event);
182 static gint MouseRelease(GtkWidget *widget, GdkEventButton *event);
183 static gint ScrollEvent(GtkWidget *widget, GdkEventScroll *event);
184 static gint Motion(GtkWidget *widget, GdkEventMotion *event);
185 gboolean KeyThis(GdkEventKey *event);
186 static gboolean KeyPress(GtkWidget *widget, GdkEventKey *event);
187 static gboolean KeyRelease(GtkWidget *widget, GdkEventKey *event);
188 #if GTK_CHECK_VERSION(3,0,0)
189 gboolean DrawPreeditThis(GtkWidget *widget, cairo_t *cr);
190 static gboolean DrawPreedit(GtkWidget *widget, cairo_t *cr, ScintillaGTK *sciThis);
191 #else
192 gboolean ExposePreeditThis(GtkWidget *widget, GdkEventExpose *ose);
193 static gboolean ExposePreedit(GtkWidget *widget, GdkEventExpose *ose, ScintillaGTK *sciThis);
194 #endif
195 AtkObject* GetAccessibleThis(GtkWidget *widget);
196 static AtkObject* GetAccessible(GtkWidget *widget);
198 bool KoreanIME();
199 void CommitThis(char *str);
200 static void Commit(GtkIMContext *context, char *str, ScintillaGTK *sciThis);
201 void PreeditChangedInlineThis();
202 void PreeditChangedWindowedThis();
203 static void PreeditChanged(GtkIMContext *context, ScintillaGTK *sciThis);
204 void MoveImeCarets(int pos);
205 void DrawImeIndicator(int indicator, int len);
206 void SetCandidateWindowPos();
208 static void StyleSetText(GtkWidget *widget, GtkStyle *previous, void*);
209 static void RealizeText(GtkWidget *widget, void*);
210 static void Dispose(GObject *object);
211 static void Destroy(GObject *object);
212 static void SelectionReceived(GtkWidget *widget, GtkSelectionData *selection_data,
213 guint time);
214 static void SelectionGet(GtkWidget *widget, GtkSelectionData *selection_data,
215 guint info, guint time);
216 static gint SelectionClear(GtkWidget *widget, GdkEventSelection *selection_event);
217 gboolean DragMotionThis(GdkDragContext *context, gint x, gint y, guint dragtime);
218 static gboolean DragMotion(GtkWidget *widget, GdkDragContext *context,
219 gint x, gint y, guint dragtime);
220 static void DragLeave(GtkWidget *widget, GdkDragContext *context,
221 guint time);
222 static void DragEnd(GtkWidget *widget, GdkDragContext *context);
223 static gboolean Drop(GtkWidget *widget, GdkDragContext *context,
224 gint x, gint y, guint time);
225 static void DragDataReceived(GtkWidget *widget, GdkDragContext *context,
226 gint x, gint y, GtkSelectionData *selection_data, guint info, guint time);
227 static void DragDataGet(GtkWidget *widget, GdkDragContext *context,
228 GtkSelectionData *selection_data, guint info, guint time);
229 static gboolean TimeOut(gpointer ptt);
230 static gboolean IdleCallback(gpointer pSci);
231 static gboolean StyleIdle(gpointer pSci);
232 virtual void IdleWork();
233 virtual void QueueIdleWork(WorkNeeded::workItems items, int upTo);
234 virtual void SetDocPointer(Document *document);
235 static void PopUpCB(GtkMenuItem *menuItem, ScintillaGTK *sciThis);
237 #if GTK_CHECK_VERSION(3,0,0)
238 static gboolean DrawCT(GtkWidget *widget, cairo_t *cr, CallTip *ctip);
239 #else
240 static gboolean ExposeCT(GtkWidget *widget, GdkEventExpose *ose, CallTip *ct);
241 #endif
242 static gboolean PressCT(GtkWidget *widget, GdkEventButton *event, ScintillaGTK *sciThis);
244 static sptr_t DirectFunction(sptr_t ptr,
245 unsigned int iMessage, uptr_t wParam, sptr_t lParam);
248 // helper class to watch a GObject lifetime and get notified when it dies
249 class GObjectWatcher {
250 GObject *weakRef;
252 void WeakNotifyThis(GObject *obj G_GNUC_UNUSED) {
253 PLATFORM_ASSERT(obj == weakRef);
255 Destroyed();
256 weakRef = 0;
259 static void WeakNotify(gpointer data, GObject *obj) {
260 static_cast<GObjectWatcher*>(data)->WeakNotifyThis(obj);
263 public:
264 GObjectWatcher(GObject *obj) :
265 weakRef(obj) {
266 g_object_weak_ref(weakRef, WeakNotify, this);
269 virtual ~GObjectWatcher() {
270 if (weakRef) {
271 g_object_weak_unref(weakRef, WeakNotify, this);
275 virtual void Destroyed() {}
277 bool IsDestroyed() const {
278 return weakRef != 0;
282 std::string ConvertText(const char *s, size_t len, const char *charSetDest,
283 const char *charSetSource, bool transliterations, bool silent=false);
285 #ifdef SCI_NAMESPACE
287 #endif
289 #endif