blob: 39102daa52be600dca28cfc72dad2a05081346ce [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
71enum BlinkState {
72 BLINK_NONE,
73 BLINK_ON,
74 BLINK_OFF
75};
76
77class VimWidget : public QWidget, virtual public KVim
78{
79 Q_OBJECT
80
81public:
82 VimWidget( QWidget *parent=0, const char *name=0, WFlags f=0 );
83 virtual void paintEvent( QPaintEvent *);
84 void draw_string(int x, int y, QString s, int len, int flags);
85
86 /** Init the blinking time */
87 void set_blink_time( long, long, long );
88 void start_cursor_blinking();
89 void stop_cursor_blinking();
90 void wait(long);
91#ifdef FEAT_CLIENTSERVER
92 void serverActivate(WId id);
93#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +000094#ifdef FEAT_MZSCHEME
95 void enable_mzscheme_threads();
96 void disable_mzscheme_threads();
97#endif
Bram Moolenaar843ee412004-06-30 16:16:41 +000098 void flash();
Bram Moolenaar5eb86f92004-07-26 12:53:41 +000099
Bram Moolenaar843ee412004-06-30 16:16:41 +0000100 /** DCOP */
101 void execNormal(QString command);
102 void execInsert(QString command);
103 void execRaw(QString command);
104 void execCmd(QString command);
105 QString eval(QString expr);
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000106
Bram Moolenaar843ee412004-06-30 16:16:41 +0000107 bool wait_done;
108 BlinkState blink_state;
109 QPainter *painter;
110 QPopupMenu *menu;
111
112protected:
113 virtual void keyPressEvent( QKeyEvent * );
114 virtual void mousePressEvent( QMouseEvent *);
115 virtual void mouseDoubleClickEvent( QMouseEvent *);
116 virtual void mouseReleaseEvent( QMouseEvent *);
117 virtual void mouseMoveEvent( QMouseEvent *);
118 virtual void focusInEvent( QFocusEvent * );
119 virtual void focusOutEvent( QFocusEvent * );
120 virtual void dragEnterEvent (QDragEnterEvent *);
121 virtual void dropEvent (QDropEvent *);
122#ifdef FEAT_XIM
123 virtual void imStartEvent ( QIMEvent * );
124 virtual void imEndEvent ( QIMEvent * );
125 virtual void imComposeEvent ( QIMEvent * );
126#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +0000127#ifdef FEAT_MZSCHEME
128 virtual void timerEvent( QTimerEvent * );
129#endif
Bram Moolenaar843ee412004-06-30 16:16:41 +0000130
131 /* cursor blinking stuff */
132 QTimer blink_timer;
133 long blink_wait_time, blink_on_time, blink_off_time;
134
135 /* wait for input */
136 QTimer wait_timer;
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000137
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +0000138#ifdef FEAT_MZSCHEME
139 int mzscheme_timer_id;
140#endif
Bram Moolenaar843ee412004-06-30 16:16:41 +0000141
142public slots:
143 void blink_cursor();
144 void wait_timeout();
145};
146
147class VimMainWindow : public KMainWindow
148{
149 Q_OBJECT
150
151public:
152 VimMainWindow ( const char *name = 0L, WFlags f = WDestructiveClose );
153
154 /** called when the widget closes */
155// bool close(bool alsoDelete);
156 VimWidget *w;
157 KEdFind *finddlg;
158 KEdReplace *repldlg;
159 int have_tearoff;
160 QTextCodec *codec;
161
162public slots:
163 void menu_activated(int dx);
164 void clipboard_selection_update();
165 void clipboard_data_update();
166 void slotSearch();
167 void slotFind();
168 void slotReplace();
169 void slotReplaceAll();
170 void showAboutApplication();
171 void showAboutKDE();
172 void showBugReport();
173 void showTipOfTheDay();
174 void buffersToolbar();
175 bool isLocked();
176 void lock();
177 void unlock();
178
179protected:
180 virtual void wheelEvent (QWheelEvent *);
181 virtual void resizeEvent ( QResizeEvent *e );
182
183#if defined(FEAT_SESSION)
184 void saveGlobalProperties (KConfig *conf);
185 void readGlobalProperties (KConfig *conf);
186#endif
187 bool queryClose();
188 bool queryExit();
189 bool locked;
190};
191
192
193class VimDialog : public QDialog
194{
195 Q_OBJECT
196public:
197 VimDialog (int type, /* type of dialog */
198 unsigned char * title, /* title of dialog */
199 unsigned char * message, /* message text */
200 unsigned char * buttons, /* names of buttons */
201 int def_but, /* default button */
202 char_u *textfield); /* input text */
203private:
204 QSignalMapper mapper;
205 QLineEdit *entry;
206 char_u *ret;
207 int butNb;
208
209protected slots:
210 void done(int);
211};
212
213
214/*
215 * QScrollBar pool
216 */
217struct GuiScrollbar;
218
219class SBPool : public QObject
220{
221 Q_OBJECT
222public:
223 SBPool(void);
224 void create(GuiScrollbar * sb, int orient);
225 void destroy(GuiScrollbar * sb);
226public slots:
227 void sbUsed(int who);
228private:
229 QSignalMapper mapper;
230};
231
232class KVimUtils {
233public:
234 static QString convertEncodingName(QString);
235#if QT_VERSION<300
236 static bool fromString(QFont*,QString);
237 static QString toString(QFont*);
238#endif
239};
240
241extern VimMainWindow *vmw;
242extern SBPool *sbpool;
243extern QString *argServerName;
244
245#endif // GUI_KDE_WIDGET