PageRenderTime 1007ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/KFEM_0_0_0/kfem/kfem/keditcl.h

#
C Header | 605 lines | 267 code | 139 blank | 199 comment | 14 complexity | e1a70283ca0f64f0c1d418af9ad1ad15 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, MPL-2.0-no-copyleft-exception
  1. /*
  2. *
  3. *
  4. * NOTE THIS CLASS IS NOT THE SAME AS THE ONE IN THE KDEUI LIB
  5. * The difference is that this one uses KFileDialog instead of
  6. * QFileDialog. So don't remove this class with the idea in mind to
  7. * link against kdeui.
  8. * Bernd
  9. $Id: keditcl.h 4 2000-01-13 16:41:48Z prudhomm $
  10. KEdit, a simple text editor for the KDE project
  11. Copyright (C) 1996 Bernd Johannes Wuebben
  12. wuebben@math.cornell.edu
  13. This program is free software; you can redistribute it and/or modify
  14. it under the terms of the GNU General Public License as published by
  15. the Free Software Foundation; either version 2 of the License, or
  16. (at your option) any later version.
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. GNU General Public License for more details.
  21. You should have received a copy of the GNU General Public License
  22. along with this program; if not, write to the Free Software
  23. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. #ifndef __KEDIT_H__
  26. #define __KEDIT_H__
  27. #include <qpopmenu.h>
  28. #include <qmenubar.h>
  29. #include <qstrlist.h>
  30. #include <qapp.h>
  31. #include <qkeycode.h>
  32. #include <qaccel.h>
  33. #include <qregexp.h>
  34. #include <qobject.h>
  35. #include <qmlined.h>
  36. #include <qlined.h>
  37. #include <qradiobt.h>
  38. #include <qfiledlg.h>
  39. #include <qchkbox.h>
  40. #include <qmsgbox.h>
  41. #include <qcombo.h>
  42. #include <qpushbt.h>
  43. #include <qgrpbox.h>
  44. #include <qregexp.h>
  45. #include <qtstream.h>
  46. #include <qkeycode.h>
  47. #include <qfileinf.h>
  48. #include <stdio.h>
  49. #include <stdlib.h>
  50. #include <string.h>
  51. #include <unistd.h>
  52. #include <errno.h>
  53. #include <sys/types.h>
  54. #include <sys/stat.h>
  55. #include <sys/mman.h>
  56. #include <fcntl.h>
  57. #include <ctype.h>
  58. #include <pwd.h>
  59. #include <kapp.h>
  60. #include <kfontdialog.h>
  61. #include <kfiledialog.h>
  62. #include <kspell.h>
  63. #include <kfem_main.hpp>
  64. ///
  65. class KIntLineEdit : public QLineEdit
  66. {
  67. Q_OBJECT
  68. public:
  69. KIntLineEdit( QWidget *parent = 0, const char *name = 0 )
  70. : QLineEdit( parent, name ) {};
  71. int getValue() { return atoi( text() ); };
  72. protected:
  73. void keyPressEvent( QKeyEvent *e ) {
  74. char key = e->ascii();
  75. if( isdigit( key )
  76. || ( e->key() == Key_Return) || ( e->key() == Key_Enter )
  77. || ( e->key() == Key_Delete) || ( e->key() == Key_Backspace)
  78. || ( e->key() == Key_Left ) || ( e->key() == Key_Right )){
  79. QLineEdit::keyPressEvent( e );
  80. return;
  81. } else {
  82. e->ignore();
  83. return;
  84. }
  85. };
  86. };
  87. ///
  88. class KEdGotoLine : public QDialog
  89. {
  90. Q_OBJECT
  91. public:
  92. KEdGotoLine( QWidget *parent = 0, const char *name = 0 );
  93. int getLineNumber();
  94. KIntLineEdit *lineNum;
  95. private:
  96. QPushButton *ok, *cancel;
  97. QGroupBox *frame;
  98. void resizeEvent(QResizeEvent *);
  99. void focusInEvent(QFocusEvent *);
  100. public slots:
  101. void selected( int );
  102. };
  103. ///
  104. class KEdSrch : public QDialog
  105. {
  106. Q_OBJECT
  107. public:
  108. KEdSrch ( QWidget *parent = 0, const char *name=0);
  109. QString getText();
  110. void setText(QString string);
  111. bool case_sensitive();
  112. bool get_direction();
  113. protected:
  114. void focusInEvent( QFocusEvent *);
  115. void resizeEvent(QResizeEvent *);
  116. private:
  117. QPushButton *ok, *cancel;
  118. QCheckBox *sensitive;
  119. QCheckBox *direction;
  120. QGroupBox *frame1;
  121. QLineEdit *value;
  122. signals:
  123. void search_signal();
  124. void search_done_signal();
  125. public slots:
  126. void done_slot();
  127. void ok_slot();
  128. };
  129. ///
  130. class KEdReplace : public QDialog
  131. {
  132. Q_OBJECT
  133. public:
  134. KEdReplace ( QWidget *parent = 0, const char *name=0);
  135. QString getText();
  136. QString getReplaceText();
  137. void setText(QString);
  138. QLineEdit *value;
  139. QLineEdit *replace_value;
  140. QLabel *label;
  141. bool case_sensitive();
  142. bool get_direction();
  143. protected:
  144. void focusInEvent( QFocusEvent *);
  145. void resizeEvent ( QResizeEvent *);
  146. private:
  147. QPushButton *ok, *cancel, *replace, *replace_all;
  148. QCheckBox *sensitive;
  149. QCheckBox *direction;
  150. QGroupBox *frame1;
  151. signals:
  152. void replace_signal();
  153. void find_signal();
  154. void replace_all_signal();
  155. void replace_done_signal();
  156. public slots:
  157. void done_slot();
  158. void replace_slot();
  159. void replace_all_slot();
  160. void ok_slot();
  161. };
  162. ///
  163. class KEdit : public QMultiLineEdit
  164. {
  165. Q_OBJECT
  166. public:
  167. KEdit (KFemApp *a=NULL,QWidget *parent=NULL, const char *name=NULL,
  168. const char *filename=NULL);
  169. ~KEdit();
  170. enum { NONE,
  171. FORWARD,
  172. BACKWARD };
  173. enum { KEDIT_OK = 0,
  174. KEDIT_OS_ERROR = 1,
  175. KEDIT_USER_CANCEL = 2 ,
  176. KEDIT_RETRY = 3,
  177. KEDIT_NOPERMISSIONS = 4};
  178. enum { OPEN_READWRITE = 1,
  179. OPEN_READONLY = 2,
  180. OPEN_INSERT = 4 };
  181. /// Opens a new untitled document in the text widget
  182. /** Opens a new untitled document in the text widget The user is given
  183. a chance to save the current document if the current document has
  184. been modified.
  185. */
  186. int newFile();
  187. /// Saves the file if necessary under the current file name
  188. /** Saves the file if necessary under the current file name. If the current file
  189. name is Untitled, as it is after a call to newFile(), this routing will
  190. call saveAs().
  191. */
  192. int doSave();
  193. /// Saves the file as filename
  194. /** Saves the file as filename
  195. */
  196. int doSave( const char *filename );
  197. /// Allows the user to save the file under a new name
  198. /** Allows the user to save the file under a new name
  199. */
  200. int saveAs();
  201. /// Let the user open an new file
  202. /** This will present an open file dialog and open the file specified by the user,
  203. if possible. The return codes are KEDIT_OK, KEDIT_USER_CANCEL and
  204. KEDIT_OS_ERROR. The user will be given a chance to save the current file if
  205. it has been modified. mode is one of OPEN_READONLY, OPEN_READWRITE.
  206. OPEN_READONLY means that the user will not be able to insert characters
  207. into the document.
  208. */
  209. int openFile( int mode );
  210. /// Lets the user insert a file at the current cursor position
  211. /** Calling this method will let the user insert a file at the current cursor
  212. position. Return codes are KEDIT_OK, KEDIT_USER_CANCEL, KDEDIT_OS_ERROR.
  213. */
  214. int insertFile();
  215. /// Loads the file filemane in the editor
  216. /** Loads the file filename into editor. The possible modes are
  217. OPEN_READONLY, OPEN_READWRITE, OPEN_INSERT.
  218. OPEN_READONLY means that the user will not be able to insert characters
  219. into the document. OPEN_INSERT means that the file will be inserted
  220. into the current document at the current cursor position.
  221. */
  222. int loadFile( QString filename , int mode );
  223. /// Returns the filename of the current file.
  224. /** Returns the filename of the currnet file. You can use setName() to set the
  225. filename of the current file
  226. */
  227. QString getName();
  228. /// Sets the filename of the current file.
  229. /** Sets the filename of the currnet file. You can use getName() to set the
  230. filename of the current file
  231. */
  232. void setName( const char *_name );
  233. /// Returns the currently marked text.
  234. /** Returns the currently marked text.
  235. */
  236. QString markedText();
  237. /// Lets the user select a font and sets the font of the textwidget.
  238. /** Lets the user select a font and sets the font of the textwidget to that
  239. selected font.
  240. */
  241. void selectFont();
  242. /// Presents a search dialog to the user
  243. /** Presents a search dialog to the user
  244. */
  245. void Search();
  246. /// Repeats the last search specified on the search dialog.
  247. /** Repeasts the last search specified on the search dialog. If the user
  248. hasn't searched for anything until now, this method will simply return
  249. without doing anything.
  250. */
  251. int repeatSearch();
  252. /// Presents a Search and Replace Dialog to the User.
  253. /** Presents a Search and Replace Dialog to the User.
  254. */
  255. void Replace();
  256. /// Presents a "Goto Line" dialog to the User
  257. /** Presents a "Goto Line" dialog to the User
  258. */
  259. void doGotoLine();
  260. /// Returns true if the document has been modified.
  261. /**Returns true if the document has been modified.
  262. */
  263. bool isModified();
  264. /// Toggles the modification status of the document
  265. /** Toggles the modification status of the document. TRUE = Modified,
  266. FALSE = UNMODIFIED. Methods such as doSave() rely on this to see whether
  267. the document needs to be saved.
  268. */
  269. void toggleModified( bool );
  270. /// Sets Indent Mode
  271. /** Sets the Indent Mode. TRUE = Indent mode on, FALSE = Indent mode off.
  272. */
  273. void setAutoIndentMode( bool );
  274. /// Returns the Indent Mode
  275. /** Returns the Indent Mode. TRUE = Indent mode on, FALSE = Indent mode off.
  276. */
  277. bool AutoIndentMode(){ return autoIndentMode; };
  278. /// Install a Popup Menue for KEdit.
  279. /** Install a Popup Menue for KEdit. The Popup Menu will be activated on
  280. a right mouse button press event.
  281. */
  282. void installRBPopup( QPopupMenu* );
  283. /// Return the current Line number
  284. /** Returns the current line number, that is the line the cursor is on.
  285. */
  286. int currentLine();
  287. /// Returns the current Column number
  288. /** This returns the actual column number the cursor is on. This call differs
  289. from QMultiLineEdit::getCursorPosition in that it returns the actual cursor
  290. position and not the character position. Use currentLine() and currentColumn()
  291. if you want to display the current line or column in the status bar for
  292. example.
  293. */
  294. int currentColumn();
  295. /// Returns TRUE if word wrap is on
  296. /** Returns TRUE if word wrap is on. You also need to specify the fill column
  297. with setFillColumnMode() otherwise wordwrap is not in effect.
  298. */
  299. bool WordWrap();
  300. /// Turn word wrap mode on or off.
  301. /** You also need to specify the fill column
  302. with setFillColumnMode() otherwise wordwrap is not in effect.
  303. */
  304. void setWordWrap(bool );
  305. /// Returns TRUE if fill column mode is on
  306. /** Returns TRUE if fill column mode is on, that is if the line will
  307. be broken automatically when if a character is to be inserted past
  308. this position.
  309. */
  310. bool FillColumnMode();
  311. /// Set the fill column to column col if line is strictly larger than 0.
  312. /** Set the fill column to column col, if col is strictly larger than 0.
  313. If col is 0, fill column mode is turned off.
  314. In fill column mode, the line will
  315. be broken automatically at column col, when a character is
  316. inserted past column col..
  317. */
  318. void setFillColumnMode(int line, bool set);
  319. /// save a backup copy
  320. /** If copy is TRUE KEdit will make a backup copy of the document that
  321. is being edited on opening it. The backup copy will receive the
  322. suffix ~. The default is TRUE.
  323. */
  324. void saveBackupCopy(bool copy);
  325. /// set the name of the file
  326. /** Sets the name of the file if a file is open.
  327. */
  328. void setFileName(char* name);
  329. /// save the current file as 'name'
  330. /** saves the current file as 'name'
  331. */
  332. void saveasfile(char* name);
  333. /// remove tabs and whitespace on the end of lines during a justify operation
  334. /** remove tabs and whitespace on the end of lines during a justify operation
  335. */
  336. void setReduceWhiteOnJustify(bool reduce);
  337. bool format(QStrList& );
  338. bool format2(QStrList& par, int& upperbound);
  339. void getpar(int line,QStrList& par);
  340. void getpar2(int line,QStrList& par,int& upperbound,QString &prefix);
  341. /**
  342. * Returns the KSpellConfig object used by KEdit.
  343. */
  344. KSpellConfig *ksConfig(void) {return ksc;}
  345. /**
  346. * Sets the KSpellConfig object used by KEdit. (The object is
  347. * copied internally.)
  348. */
  349. void setKSConfig (const KSpellConfig _ksc) {*ksc=_ksc;}
  350. signals:
  351. /**
  352. * This says spellchecking is <i>percent</i> done.
  353. * It is emitted every 10% during spellchecking.
  354. **/
  355. void spellcheck_progress (unsigned int percent);
  356. /**
  357. * Emitted when spellcheck is complete.
  358. **/
  359. void spellcheck_done ();
  360. /// This signal is emitted when the document in the textwidget has changed
  361. /** This signal is emitted when the document in the textwidget has changed
  362. */
  363. void fileChanged();
  364. /// This signal is emitted whenever the cursor position changed.
  365. /** This signal is emitted whenever the cursor position changed.
  366. Use this in conjunction with currentLine(), currentColumn()
  367. if you need to know the cursor position.
  368. */
  369. void CursorPositionChanged();
  370. /// This signal is emitted just before saving a file.
  371. /** This signal is emitted just before saving a file. Since KEdit calls
  372. kapp->processEvents(), you have a chance to let the user know what's
  373. going to happen.
  374. */
  375. void saving();
  376. /// This signal is emitted just before loading a file.
  377. /** This signal is emitted just before loading a file. Since KEdit calls
  378. kapp->processEvents(), you have a chance to let the user know what's
  379. going to happen.
  380. */
  381. void loading();
  382. /// This signal is emitted if the user toggles from overwrite to insert mode
  383. /** This signal is emitted if the user toggles from overwrite to insert mode.
  384. He can do so by pressing the "Insert" Button on a PC keyboard.
  385. */
  386. void toggle_overwrite_signal();
  387. public slots:
  388. void spellResult (char *newtext);
  389. void corrected (char *originalword, char *newword, unsigned pos);
  390. void misspelling (char *word, QStrList *, unsigned pos);
  391. void spellcheck();
  392. void spellcheck2(KSpell*);
  393. void spellCleanDone();
  394. void setModified();
  395. void search_slot();
  396. void searchdone_slot();
  397. void replace_slot();
  398. void replace_all_slot();
  399. void replace_search_slot();
  400. void replacedone_slot();
  401. void computePosition();
  402. void repaintAll();
  403. protected:
  404. #if QT_VERSION >= 142
  405. QTimer* repaintTimer;
  406. #endif
  407. int saveFile();
  408. int doSearch(QString s_pattern, bool case_sensitive,
  409. bool regex, bool forward,int line, int col);
  410. int doReplace(QString s_pattern, bool case_sensitive,
  411. bool regex, bool forward,int line, int col,bool replace);
  412. protected:
  413. bool eventFilter ( QObject *, QEvent * );
  414. void keyPressEvent ( QKeyEvent * );
  415. void mousePressEvent ( QMouseEvent* );
  416. void mouseReleaseEvent( QMouseEvent* );
  417. void mouseMoveEvent ( QMouseEvent* );
  418. private:
  419. void setContextSens();
  420. void mynewLine();
  421. QString prefixString(QString);
  422. private:
  423. // Spellchecking
  424. KSpell *kspell;
  425. KSpellConfig *ksc;
  426. int spell_offset;
  427. QString killbufferstring;
  428. QWidget *p_parent;
  429. KFileDialog *fbox;
  430. KEdSrch *srchdialog;
  431. KEdReplace *replace_dialog;
  432. KEdGotoLine *gotodialog;
  433. QPopupMenu *rb_popup;
  434. KFemApp* kfemapp;
  435. KFileDialog *file_dialog;
  436. QStrList par;
  437. QString filename;
  438. QString pattern;
  439. QString current_directory;
  440. bool modified;
  441. bool autoIndentMode;
  442. bool can_replace;
  443. bool killing;
  444. bool killtrue;
  445. bool lastwasanewline;
  446. bool reduce_white_on_justify;
  447. int cursor_offset;
  448. int edit_mode;
  449. int last_search;
  450. int last_replace;
  451. int replace_all_line;
  452. int replace_all_col;
  453. int line_pos, col_pos;
  454. bool fill_column_is_set;
  455. bool word_wrap_is_set;
  456. int fill_column_value;
  457. bool make_backup_copies;
  458. };
  459. #endif