blob: 4eb67be72d9ec653e81e7d0b4986a213417553ee [file] [log] [blame]
Bram Moolenaar843ee412004-06-30 16:16:41 +00001/* vi:set ts=8 sts=0 sw=8:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 */
8
9/*
10 * Porting to KDE(2) was done by
11 *
12 * (C) 2000 by Thomas Capricelli <orzel@freehackers.org>
13 *
14 * Please visit http://freehackers.org/kvim for other vim- or
15 * kde-related coding.
16 *
17 * $Id$
18 *
19 */
20
21#ifndef GUI_KDE_WIDGET
22#define GUI_KDE_WIDGET
23
24#if 1
25#define dbf( format, args... ) { printf( "%s" " : " format "\n" , __FUNCTION__ , ## args ); fflush(stdout); }
26#define db() { printf( "%s\n", __FUNCTION__ );fflush(stdout); }
27#else
28#define dbf(format, args... )
29#define db()
30#endif
31
32#define UNIX // prevent a warning : a symbol is defined twice in X and Qt
33
34#include <qdialog.h>
35#include <qlabel.h>
36#include <qsignalmapper.h>
37#include <qtimer.h>
38#include <qmainwindow.h>
39#include <qapplication.h>
40#include <qevent.h>
41#include <qlineedit.h>
42#include <qpainter.h>
43#include <qwidget.h>
44#include <qpopupmenu.h>
45#include <klocale.h>
46#include <kapp.h>
47#include <kcmdlineargs.h>
48#include <kaboutdata.h>
49#include <keditcl.h>
50#include <kaboutdata.h>
51#if (KDE_VERSION>=290)
52#include <kmainwindow.h>
53#else
54#include <ktmainwindow.h>
55#endif
56#include <kparts/part.h>
57#include <kurl.h>
58#include "kvim_iface.h"
59
60#undef UNIX // prevent a warning
61extern "C" {
62#include "vim.h"
63}
64
65class QPushButton;
66class QDialog;
67class QLineEdit;
68class QSignalMapper;
69class QPaintEvent;
70
Bram Moolenaar81695252004-12-29 20:58:21 +000071enum BlinkState
72{
Bram Moolenaar843ee412004-06-30 16:16:41 +000073 BLINK_NONE,
74 BLINK_ON,
75 BLINK_OFF
76};
77
78class VimWidget : public QWidget, virtual public KVim
79{
80 Q_OBJECT
81
82public:
Bram Moolenaar81695252004-12-29 20:58:21 +000083 VimWidget(QWidget *parent = 0, const char *name = 0, WFlags f = 0);
84 virtual void paintEvent(QPaintEvent *);
Bram Moolenaar843ee412004-06-30 16:16:41 +000085 void draw_string(int x, int y, QString s, int len, int flags);
86
87 /** Init the blinking time */
Bram Moolenaar81695252004-12-29 20:58:21 +000088 void set_blink_time(long, long, long);
Bram Moolenaar843ee412004-06-30 16:16:41 +000089 void start_cursor_blinking();
90 void stop_cursor_blinking();
91 void wait(long);
92#ifdef FEAT_CLIENTSERVER
93 void serverActivate(WId id);
94#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +000095#ifdef FEAT_MZSCHEME
96 void enable_mzscheme_threads();
97 void disable_mzscheme_threads();
98#endif
Bram Moolenaar843ee412004-06-30 16:16:41 +000099 void flash();
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000100
Bram Moolenaar843ee412004-06-30 16:16:41 +0000101 /** DCOP */
102 void execNormal(QString command);
103 void execInsert(QString command);
104 void execRaw(QString command);
105 void execCmd(QString command);
106 QString eval(QString expr);
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000107
Bram Moolenaar843ee412004-06-30 16:16:41 +0000108 bool wait_done;
109 BlinkState blink_state;
110 QPainter *painter;
111 QPopupMenu *menu;
Bram Moolenaar81695252004-12-29 20:58:21 +0000112 virtual void setMicroFocusHint(int x, int y, int w, int h, bool text=TRUE, QFont *f = 0)
113 {
114 QWidget::setMicroFocusHint(x, y, w, h, text, f);
115 }
Bram Moolenaar843ee412004-06-30 16:16:41 +0000116
117protected:
Bram Moolenaar81695252004-12-29 20:58:21 +0000118 virtual void keyPressEvent(QKeyEvent *);
119 virtual void mousePressEvent(QMouseEvent *);
120 virtual void mouseDoubleClickEvent(QMouseEvent *);
121 virtual void mouseReleaseEvent(QMouseEvent *);
122 virtual void mouseMoveEvent(QMouseEvent *);
123 virtual void focusInEvent(QFocusEvent *);
124 virtual void focusOutEvent(QFocusEvent *);
125 virtual void dragEnterEvent(QDragEnterEvent *);
126 virtual void dropEvent(QDropEvent *);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000127#ifdef FEAT_XIM
Bram Moolenaar81695252004-12-29 20:58:21 +0000128 virtual void imStartEvent(QIMEvent *);
129 virtual void imEndEvent(QIMEvent *);
130 virtual void imComposeEvent(QIMEvent *);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000131#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +0000132#ifdef FEAT_MZSCHEME
Bram Moolenaar81695252004-12-29 20:58:21 +0000133 virtual void timerEvent(QTimerEvent *);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +0000134#endif
Bram Moolenaar843ee412004-06-30 16:16:41 +0000135
136 /* cursor blinking stuff */
137 QTimer blink_timer;
138 long blink_wait_time, blink_on_time, blink_off_time;
139
140 /* wait for input */
141 QTimer wait_timer;
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000142
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +0000143#ifdef FEAT_MZSCHEME
144 int mzscheme_timer_id;
145#endif
Bram Moolenaar843ee412004-06-30 16:16:41 +0000146
147public slots:
148 void blink_cursor();
149 void wait_timeout();
150};
151
152class VimMainWindow : public KMainWindow
153{
154 Q_OBJECT
155
156public:
Bram Moolenaar81695252004-12-29 20:58:21 +0000157 VimMainWindow(const char *name = 0L, WFlags f = WDestructiveClose);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000158
159 /** called when the widget closes */
160// bool close(bool alsoDelete);
161 VimWidget *w;
Bram Moolenaar81695252004-12-29 20:58:21 +0000162 KEdFind *finddlg;
163 KEdReplace *repldlg;
Bram Moolenaar843ee412004-06-30 16:16:41 +0000164 int have_tearoff;
165 QTextCodec *codec;
166
167public slots:
168 void menu_activated(int dx);
Bram Moolenaar81695252004-12-29 20:58:21 +0000169 void clipboard_selection_update();
170 void clipboard_data_update();
171 void slotSearch();
172 void slotFind();
173 void slotReplace();
174 void slotReplaceAll();
Bram Moolenaar843ee412004-06-30 16:16:41 +0000175 void showAboutApplication();
176 void showAboutKDE();
177 void showBugReport();
178 void showTipOfTheDay();
179 void buffersToolbar();
180 bool isLocked();
181 void lock();
182 void unlock();
183
184protected:
Bram Moolenaar81695252004-12-29 20:58:21 +0000185 virtual void wheelEvent(QWheelEvent *);
186 virtual void resizeEvent(QResizeEvent *e);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000187
188#if defined(FEAT_SESSION)
Bram Moolenaar81695252004-12-29 20:58:21 +0000189 void saveGlobalProperties(KConfig *conf);
190 void readGlobalProperties(KConfig *conf);
Bram Moolenaar843ee412004-06-30 16:16:41 +0000191#endif
192 bool queryClose();
193 bool queryExit();
194 bool locked;
195};
196
197
198class VimDialog : public QDialog
199{
200 Q_OBJECT
201public:
Bram Moolenaar81695252004-12-29 20:58:21 +0000202 VimDialog(int type, /* type of dialog */
203 unsigned char *title, /* title of dialog */
204 unsigned char *message, /* message text */
205 unsigned char *buttons, /* names of buttons */
Bram Moolenaar843ee412004-06-30 16:16:41 +0000206 int def_but, /* default button */
207 char_u *textfield); /* input text */
208private:
209 QSignalMapper mapper;
210 QLineEdit *entry;
211 char_u *ret;
212 int butNb;
213
214protected slots:
215 void done(int);
216};
217
218
219/*
220 * QScrollBar pool
221 */
222struct GuiScrollbar;
223
224class SBPool : public QObject
225{
226 Q_OBJECT
227public:
228 SBPool(void);
229 void create(GuiScrollbar * sb, int orient);
230 void destroy(GuiScrollbar * sb);
231public slots:
232 void sbUsed(int who);
233private:
234 QSignalMapper mapper;
235};
236
Bram Moolenaar81695252004-12-29 20:58:21 +0000237class KVimUtils
238{
Bram Moolenaar843ee412004-06-30 16:16:41 +0000239public:
240 static QString convertEncodingName(QString);
241#if QT_VERSION<300
242 static bool fromString(QFont*,QString);
243 static QString toString(QFont*);
244#endif
245};
246
247extern VimMainWindow *vmw;
248extern SBPool *sbpool;
Bram Moolenaar81695252004-12-29 20:58:21 +0000249extern QString *argServerName;
250
251#define QSTR(x) \
252 (has_mbyte ? \
253 (enc_utf8 ? \
254 QString::fromUtf8((const char *)x) : \
255 QString::fromLocal8Bit((const char *)x)) : \
256 QString((const char *)x))
Bram Moolenaar843ee412004-06-30 16:16:41 +0000257
258#endif // GUI_KDE_WIDGET