Source: /app/hbasic/hbasic/include/source_edit_widget.h


Annotated List
Files
Globals
Hierarchy
Index
/* **************************************************************************
 File: source_edit_widget.h
 Desc: Source code editor
 ----------------------------------------------------------------------------
	copyright            : (C) 2001 HBasic project (Marcus Engels)
 ***************************************************************************/

/* **************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

/* ----------------------------------------------------------------------- */
/* Classlist: List of classes that will be defined in this source file.    */
/* ----------------------------------------------------------------------- */
/**
 * CSourceEditWidget : Sourcode editor widget.
 */
/* ----------------------------------------------------------------------- */
/* Changelog: Description of important changes within this file.           */
/*            Please report with date, maintainer and change description.  */
/* ----------------------------------------------------------------------- */

#ifndef SRCEDITWIDGET_H
#define SRCEDITWIDGET_H

class QListBox;

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

class CBasicDocument;
class CEditScrollWidget;

#include "../src/structs.h"
#include "../src/memory.h"
#include "../src/window_list.h"

#define CODE_COMPLETE_BLANK 1
#define CODE_COMPLETE_DOT 2
#define CODE_COMPLETE_BRACKET 3

#define CC_POPUP_NONE 0
#define CC_POPUP_LIST 1
#define CC_POPUP_TEXT 2

#define PUL_TYPE 1
#define PUL_CLASS 2
#define PUL_METHOD 3
#define PUL_EVENT 4
#define PUL_PROPERTY 5
#define PUL_COMP 6
#define PUL_REF 7
#define PUL_PINVOKE 8
#define PUL_UNDEF 9
#define PUL_INIT 10
#define PUL_FIELD 11
#define PUL_OVERRIDE 12

#define TAB_CHAR 9
#define BREAK_WGT_WIDTH 14
#define BREAK_WGT_COLOR QColor(210,210,210)
#define FOLD_WGT_WIDTH 11
#define FOLD_WGT_COLOR QColor(242,242,242)

#define CODE_COMPLETE_BLANK 1
#define CODE_COMPLETE_DOT 2
#define CODE_COMPLETE_BRACKET 3

#define CC_POPUP_NONE 0
#define CC_POPUP_LIST 1
#define CC_POPUP_TEXT 2

#define PUL_TYPE 1
#define PUL_CLASS 2
#define PUL_METHOD 3
#define PUL_EVENT 4
#define PUL_PROPERTY 5
#define PUL_COMP 6

#define COMMENT_TYPE_NONE 0
#define COMMENT_TYPE_LINE 1
#define COMMENT_TYPE_START 2
#define COMMENT_TYPE_END 3

#define PARSER_CODE_STRING 4
#define PARSER_CODE_IDF 5
#define PARSER_CODE_STDIDF 6

/* Structure used to store insert/delete text undo operations. */

typedef struct _EDIT_UNDO_TEXT EDIT_UNDO_TEXT;

struct _EDIT_UNDO_TEXT
{
	CBasicDocument *source_ptr;  // pointer to source description
	long source_line_offset;  // Start of source line where undo has been used
	short curs_pos;  // cursor pos in startline wher eundo occured
	int undo_data_alloc;   // number of allocated bytes in undo_data_ptr
	int undo_data_used;     // number of used signs in undo_data_ptr
};

class CSourceEditWidget : public CWindowListChild
{
Q_OBJECT

public:
	CSourceEditWidget( QWidget *my_parent, CBasicDocument *srcptr );
	void initEditor( void );
	~CSourceEditWidget();
	void closeEvent( QCloseEvent *e );

/* properties for the source_editor class */

public:
	/* We use offsets instead of absolute positions because the */
	/* memory block for the sourcecode may be reallocated every time. */

	long cursor_line_offset;    /* Start offset for cursor line. */
	long first_scr_line_offset;  /* Start offset for first screen line. */
	char *getCursorLine( void );
	char *getScreenStart( void );
	short current_line_changed;  /* TRUE if current line has been changed */
				     /* and changes haven't been stored yet. */
	short curs_pos;          /* Cursor position (character) in curr. line */
	short last_pos;          /* last used character position in curr. line */
	short line_length;
	short edit_fold_line;    /* Used for folding source code lines. */
	CBasicDocument *source_doc_ptr;

	/* Pointer to token array for syntax highlightning / parser. */
	char **token_strings;
	short packed_line_format;

	/* ------------------------------------------------- */
	/* Size and position of marked block in source file. */

	SOURCE_BLOCK_HEADER block_desc;   /* Marked block description. */
	int line_count;        /* number of lines in source code */
	short block_marked;       /* TRUE if marked block exists */
	CEditScrollWidget *main_view;
	char *current_edit_line;
	/* Widget for code completion popup. */
	QWidget *code_compl_widget;

private:
	short break_widget_width;     // Width of breakpoint widget at left side
	short fold_widget_width;  // width of fold widget

	/* First token found when parsing new line. */
	/* Used to find keywords for indentation. */
	short first_line_token;
	short error_message_visible;   /* TRUE if error message has been displayed. */
	QFontMetrics *font_metrics;
	QLabel *sizePreviewLabel;

	/* Pointer to allowed sub description strings. */
	QString *sew_code_sub_list;
	/* Number of real lines in code_sub_list string. (used to compute size of widget) */
	int sew_code_num_lines;
	/* Type of popup used for code completion. */
	short sew_code_compl_type;
	/* Pointer to first entry for popup list. */
	char *gl_cc_first_list_entry;

	/* Position of current editor pos. in parameterlist. */
	/* Startpos of list pos idf in lists. */
	int sew_code_compl_edit_pos;
	/* Cursor position for trigger widget. */
	int sew_code_compl_start_curspos;

	short current_line_compflags;
	short current_line_editflags;
	short lineend;

	/* Range of lines in which the source code lines have to be marked. */
	char *start_marked_lines;
	char *end_marked_lines; 
	short current_line_marked;   /* True if current edit line is marked line. */

	short curs_pix_xpos;     /* cursor x-position as pixel offset */
	short curs_pix_ypos;     /* cursor y-position as pixel offset */
	short text_line_height;  /* pixel height of one textline */
	short char_width;        /* Default width of one character. */
				 /* This doesn't work for proportional fonts. */
	
	short current_line_number;  /* Number of current line in file. */
	short last_mouse_x;
	short last_mouse_y;
	QTimer *mouse_moved_timer;
	QFont source_font;
	QFont bold_font;
	QColor bg_col;         /* Background color */
	WINDOW_DESC *my_window;
	QPixmap *stop_pixmap;
	QPixmap *arrow_pixmap;
	QPixmap *arrow_stop_pixmap;
	QLabel *preview_label;
	QListBox *popup_listbox;

public:
	void setEditFont( void );
	void initSource( void );
	void initParameter( void );
	void windowTopped( void );
	void setErrorLine( void );
	void redrawScreen2( void );
	void redrawScreen( QPainter *p, int cx, int cy, int cw, int ch );
	int parse_new_line( char *readptr );
	void storeCurrentLine( void );
	void delete_block( short with_undo );
	int unparseLine( char *start_line, char *write_ptr);
	void undoInsertChar( long code_offset, short last_curs_pos, short new_char );
	void undoDeleteChar( long code_offset, short last_curs_pos, short del_char );
	void undo_create_block_delete( SOURCE_BLOCK_HEADER *block_desc_ptr, short cut_type );
	void undo_create_block_insert( SOURCE_BLOCK_HEADER *block_desc_ptr, short block_holds_data );
	void copySourceBuffer( void );
	void moveScreenDown( void );
	char *insertSourceLine( char *new_line );
	void keyLeft( void );
	void keyRight( void );
	void keyUp( void );
	short getCursorPos( void );
	void moveCursorUp( void );
	void keyDown( void );
	void compCursYpos( char *start_line );
	void setEditCursorPos( char *current_line, short curs_pos );
	void redrawAllLines2( void );
	void redrawAllLines( QPainter *p, int cx, int cy, int cw, int ch );
	void drawCurrentLine( void );
	void insertNewChar( short sign, bool with_undo );
	void deleteChar( short direction, bool with_undo );
	void removeErrorMessage( void );
	void setCursorXPosition( int new_curs_pos );
	void setCursorYPosition( int new_curs_line );
	void handleMousePress( QMouseEvent *ev );
	void handleMouseRelease( QMouseEvent *ev );
	void deleteBlock( SOURCE_BLOCK_HEADER *block_desc_ptr, short with_undo, short paste );
	void insertBlock( SOURCE_BLOCK_HEADER *sblock_ptr, short with_undo );
	short getLastPos( void );
	void setLastPos( short new_last_pos );
	void viewportMouseMoveEvent(QMouseEvent* e);
	void viewportMousePressEvent(QMouseEvent* e);
	void viewportMouseReleaseEvent(QMouseEvent* e);
	char *skipFoldedLines( char *start_ptr );
	void setNewCurrentLine( char *start_line, short curspos_in_line );
	char *getCurrentSourceLine();
	void saveCurrentLineIfChanged( void );
	void appendSourceLine( QFile *f, FILE_TAG_HEADER *file_info );
	/* recompute number of lines (line_count) in source */
	void countVisibleLines( void );
	void appendPopupListEntry( int type, char *name );
	void destroyPopupWidget( void );
	void insertPopupText( void );
	void keyReturn( void );
	void makeEditLineVisible( char *source_line, short set_cursor );
	void setCurrentSourceLine( char *new_source_line );

private:
	void drawContents( QPainter *p, int cx, int cy, int cw, int ch);
	void findMouseLine( int xpos, int ypos, char **lineptr, short *pos);
	void markSelectedLines( short markflag );
	void joinTwoLines( short is_backspace );
	/* return number of lines in source code */
	long getLineNumber( void );
	void storeCurrentLine( bool with_preparse );
	char *writeCommentSign( char *write_ptr, short sign );
	void markCommentLinesForward( void );
	void markCommentLinesBackward( void );

	int isKeyword( char *start);
	char *getLineStart( short line_number );
	char *getNextVisibleLine( char *start_line );
	char *getPreviousVisibleLine( char *start_line );
	char *getCurrentLine();
	void setCurrentLine( char *new_line_ptr );
	short getCurrentChar();
	void editDeleteChar( short direction, short width_undo );
	void editInsertChar( short new_sign, short with_undo );
	char *get_last_line_start( char *lineptr );
	char *get_next_line_start( char *lineptr );
	char *getSourceLine( void );
	void drawColorLine( QPainter *p, char *start_line, int yoffset, int draw_cursor );
	void drawColorLine( QPainter *p, char *start_line, int xoffset, int yoffset, int draw_cursor );
	void drawColorLine3( QPainter *p, char *start_line, int xoffset, int yoffset, int draw_cursor );
	void drawColorLine2( char *start_line, int yoffset, int draw_cursor );
	void drawColorPart( QPainter *pbuf, short yoffset, short *skip, short *xpx);
	void createSourcePopup( QPoint mouse_pos );
	int isIdfCharacter( int sign );
	void foldFollowingLines( char *line_ptr, short fold_flag );
	void drawErrorLine( QPainter *p, char *start_line, int yoffset );
	void unmarkLastSelectedBlock( void );
	void setErrorCursorPos( char *error_pos );
	void unmarkBlockLines( SOURCE_BLOCK_HEADER *block_desc_ptr );
	short isIdentifier( char *line_ptr, short startpos);
	QString *findVarAtMousepos( void );
	void showVariableWidget( QString *var_name, QString *var_value );
	bool appendUndoInsertPossible( void );
	bool appendUndoDeletePossible( int type );
	void createInsertUndoDescription( short sign );
	void createDeleteUndoDescription( short sign, short direction );

	char *getTypeText( short type );
	void createPopupMethodText( char *method_desc_ptr );
	VAR_DESC *findCodeComplClassVar( void );
	void createPopup( int type );
	void checkCodeCompletion( int type );
	void reposPopupPosition( void );
	void createTypePopup( void );
	void createInheritsPopup( void );
	void createVarClassPopup( CLASS_DESC *class_desc_ptr );
	void createVarCompPopup( VAR_DESC *comp_var_desc );
	void createVarUsertypePopup( TYPE_DESC *user_var_desc );
	void createListBoxContents( QListBox *popup_listbox );
	void createNetClassPopup( void );
	void initPopupList( void );
	short popupEntryNotExists( char *name );
	void createNetClassVarPopup( void *class_desc );
	void resizeEvent( QResizeEvent *evt );

public slots:
	void mouseHasMoved();

	void slotUnfoldAllLines( void );
	void slotFoldAllLines( void );
};

#endif


Generated by: root on linux on Sun Jul 13 18:06:35 2003, using kdoc 2.0a54.