Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 1 | /* 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 |
| 61 | extern "C" { |
| 62 | #include "vim.h" |
| 63 | } |
| 64 | |
| 65 | class QPushButton; |
| 66 | class QDialog; |
| 67 | class QLineEdit; |
| 68 | class QSignalMapper; |
| 69 | class QPaintEvent; |
| 70 | |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 71 | enum BlinkState |
| 72 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 73 | BLINK_NONE, |
| 74 | BLINK_ON, |
| 75 | BLINK_OFF |
| 76 | }; |
| 77 | |
| 78 | class VimWidget : public QWidget, virtual public KVim |
| 79 | { |
| 80 | Q_OBJECT |
| 81 | |
| 82 | public: |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 83 | VimWidget(QWidget *parent = 0, const char *name = 0, WFlags f = 0); |
| 84 | virtual void paintEvent(QPaintEvent *); |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 85 | void draw_string(int x, int y, QString s, int len, int flags); |
| 86 | |
| 87 | /** Init the blinking time */ |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 88 | void set_blink_time(long, long, long); |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 89 | 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 Moolenaar | 2df6dcc | 2004-07-12 15:53:54 +0000 | [diff] [blame] | 95 | #ifdef FEAT_MZSCHEME |
| 96 | void enable_mzscheme_threads(); |
| 97 | void disable_mzscheme_threads(); |
| 98 | #endif |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 99 | void flash(); |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 100 | |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 101 | /** 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 Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 107 | |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 108 | bool wait_done; |
| 109 | BlinkState blink_state; |
| 110 | QPainter *painter; |
| 111 | QPopupMenu *menu; |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 112 | 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 Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 116 | |
| 117 | protected: |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 118 | 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 Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 127 | #ifdef FEAT_XIM |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 128 | virtual void imStartEvent(QIMEvent *); |
| 129 | virtual void imEndEvent(QIMEvent *); |
| 130 | virtual void imComposeEvent(QIMEvent *); |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 131 | #endif |
Bram Moolenaar | 2df6dcc | 2004-07-12 15:53:54 +0000 | [diff] [blame] | 132 | #ifdef FEAT_MZSCHEME |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 133 | virtual void timerEvent(QTimerEvent *); |
Bram Moolenaar | 2df6dcc | 2004-07-12 15:53:54 +0000 | [diff] [blame] | 134 | #endif |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 135 | |
| 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 Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 142 | |
Bram Moolenaar | 2df6dcc | 2004-07-12 15:53:54 +0000 | [diff] [blame] | 143 | #ifdef FEAT_MZSCHEME |
| 144 | int mzscheme_timer_id; |
| 145 | #endif |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 146 | |
| 147 | public slots: |
| 148 | void blink_cursor(); |
| 149 | void wait_timeout(); |
| 150 | }; |
| 151 | |
| 152 | class VimMainWindow : public KMainWindow |
| 153 | { |
| 154 | Q_OBJECT |
| 155 | |
| 156 | public: |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 157 | VimMainWindow(const char *name = 0L, WFlags f = WDestructiveClose); |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 158 | |
| 159 | /** called when the widget closes */ |
| 160 | // bool close(bool alsoDelete); |
| 161 | VimWidget *w; |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 162 | KEdFind *finddlg; |
| 163 | KEdReplace *repldlg; |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 164 | int have_tearoff; |
| 165 | QTextCodec *codec; |
| 166 | |
| 167 | public slots: |
| 168 | void menu_activated(int dx); |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 169 | void clipboard_selection_update(); |
| 170 | void clipboard_data_update(); |
| 171 | void slotSearch(); |
| 172 | void slotFind(); |
| 173 | void slotReplace(); |
| 174 | void slotReplaceAll(); |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 175 | void showAboutApplication(); |
| 176 | void showAboutKDE(); |
| 177 | void showBugReport(); |
| 178 | void showTipOfTheDay(); |
| 179 | void buffersToolbar(); |
| 180 | bool isLocked(); |
| 181 | void lock(); |
| 182 | void unlock(); |
| 183 | |
| 184 | protected: |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 185 | virtual void wheelEvent(QWheelEvent *); |
| 186 | virtual void resizeEvent(QResizeEvent *e); |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 187 | |
| 188 | #if defined(FEAT_SESSION) |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 189 | void saveGlobalProperties(KConfig *conf); |
| 190 | void readGlobalProperties(KConfig *conf); |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 191 | #endif |
| 192 | bool queryClose(); |
| 193 | bool queryExit(); |
| 194 | bool locked; |
| 195 | }; |
| 196 | |
| 197 | |
| 198 | class VimDialog : public QDialog |
| 199 | { |
| 200 | Q_OBJECT |
| 201 | public: |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 202 | 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 Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 206 | int def_but, /* default button */ |
| 207 | char_u *textfield); /* input text */ |
| 208 | private: |
| 209 | QSignalMapper mapper; |
| 210 | QLineEdit *entry; |
| 211 | char_u *ret; |
| 212 | int butNb; |
| 213 | |
| 214 | protected slots: |
| 215 | void done(int); |
| 216 | }; |
| 217 | |
| 218 | |
| 219 | /* |
| 220 | * QScrollBar pool |
| 221 | */ |
| 222 | struct GuiScrollbar; |
| 223 | |
| 224 | class SBPool : public QObject |
| 225 | { |
| 226 | Q_OBJECT |
| 227 | public: |
| 228 | SBPool(void); |
| 229 | void create(GuiScrollbar * sb, int orient); |
| 230 | void destroy(GuiScrollbar * sb); |
| 231 | public slots: |
| 232 | void sbUsed(int who); |
| 233 | private: |
| 234 | QSignalMapper mapper; |
| 235 | }; |
| 236 | |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 237 | class KVimUtils |
| 238 | { |
Bram Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 239 | public: |
| 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 | |
| 247 | extern VimMainWindow *vmw; |
| 248 | extern SBPool *sbpool; |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 249 | extern 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 Moolenaar | 843ee41 | 2004-06-30 16:16:41 +0000 | [diff] [blame] | 257 | |
| 258 | #endif // GUI_KDE_WIDGET |