blob: f2e9c3f85576ae9b90a8dc5c3c7ed45785e0681f [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
94 void flash();
95
96 /** DCOP */
97 void execNormal(QString command);
98 void execInsert(QString command);
99 void execRaw(QString command);
100 void execCmd(QString command);
101 QString eval(QString expr);
102
103 bool wait_done;
104 BlinkState blink_state;
105 QPainter *painter;
106 QPopupMenu *menu;
107
108protected:
109 virtual void keyPressEvent( QKeyEvent * );
110 virtual void mousePressEvent( QMouseEvent *);
111 virtual void mouseDoubleClickEvent( QMouseEvent *);
112 virtual void mouseReleaseEvent( QMouseEvent *);
113 virtual void mouseMoveEvent( QMouseEvent *);
114 virtual void focusInEvent( QFocusEvent * );
115 virtual void focusOutEvent( QFocusEvent * );
116 virtual void dragEnterEvent (QDragEnterEvent *);
117 virtual void dropEvent (QDropEvent *);
118#ifdef FEAT_XIM
119 virtual void imStartEvent ( QIMEvent * );
120 virtual void imEndEvent ( QIMEvent * );
121 virtual void imComposeEvent ( QIMEvent * );
122#endif
123
124 /* cursor blinking stuff */
125 QTimer blink_timer;
126 long blink_wait_time, blink_on_time, blink_off_time;
127
128 /* wait for input */
129 QTimer wait_timer;
130
131public slots:
132 void blink_cursor();
133 void wait_timeout();
134};
135
136class VimMainWindow : public KMainWindow
137{
138 Q_OBJECT
139
140public:
141 VimMainWindow ( const char *name = 0L, WFlags f = WDestructiveClose );
142
143 /** called when the widget closes */
144// bool close(bool alsoDelete);
145 VimWidget *w;
146 KEdFind *finddlg;
147 KEdReplace *repldlg;
148 int have_tearoff;
149 QTextCodec *codec;
150
151public slots:
152 void menu_activated(int dx);
153 void clipboard_selection_update();
154 void clipboard_data_update();
155 void slotSearch();
156 void slotFind();
157 void slotReplace();
158 void slotReplaceAll();
159 void showAboutApplication();
160 void showAboutKDE();
161 void showBugReport();
162 void showTipOfTheDay();
163 void buffersToolbar();
164 bool isLocked();
165 void lock();
166 void unlock();
167
168protected:
169 virtual void wheelEvent (QWheelEvent *);
170 virtual void resizeEvent ( QResizeEvent *e );
171
172#if defined(FEAT_SESSION)
173 void saveGlobalProperties (KConfig *conf);
174 void readGlobalProperties (KConfig *conf);
175#endif
176 bool queryClose();
177 bool queryExit();
178 bool locked;
179};
180
181
182class VimDialog : public QDialog
183{
184 Q_OBJECT
185public:
186 VimDialog (int type, /* type of dialog */
187 unsigned char * title, /* title of dialog */
188 unsigned char * message, /* message text */
189 unsigned char * buttons, /* names of buttons */
190 int def_but, /* default button */
191 char_u *textfield); /* input text */
192private:
193 QSignalMapper mapper;
194 QLineEdit *entry;
195 char_u *ret;
196 int butNb;
197
198protected slots:
199 void done(int);
200};
201
202
203/*
204 * QScrollBar pool
205 */
206struct GuiScrollbar;
207
208class SBPool : public QObject
209{
210 Q_OBJECT
211public:
212 SBPool(void);
213 void create(GuiScrollbar * sb, int orient);
214 void destroy(GuiScrollbar * sb);
215public slots:
216 void sbUsed(int who);
217private:
218 QSignalMapper mapper;
219};
220
221class KVimUtils {
222public:
223 static QString convertEncodingName(QString);
224#if QT_VERSION<300
225 static bool fromString(QFont*,QString);
226 static QString toString(QFont*);
227#endif
228};
229
230extern VimMainWindow *vmw;
231extern SBPool *sbpool;
232extern QString *argServerName;
233
234#endif // GUI_KDE_WIDGET