Source: /app/hbasic/hbasic/source_editor/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

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

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

class QListBox;
class QFrame;
class QPushButton;
class CSourceEditData;
class CBasicDocument;
class CEditScrollWidget;

#define END_OF_EDIT_TEXT 0xff

#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 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;

class CCInfoButton : public QPushButton
{
public:
	CCInfoButton( QWidget *parent, void *new_class_desc );

	void *class_desc_ptr;
};

struct _EDIT_UNDO_TEXT
{
	CSourceEditData *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 *parent, CSourceEditData *srcptr, CBasicDocument *new_src_cont );
	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. */
	unsigned char *getCursorLine( void );
	unsigned 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. */
	CSourceEditData *source_doc_ptr;
	CBasicDocument *source_container;

	short packed_line_format;

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

	SOURCE_BLOCK_HEADER block_desc;   /* Marked block description. */
	short block_marked;       /* TRUE if marked block exists */
	CEditScrollWidget *main_view;
	unsigned 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
	short doc_id[20];
	/* TRUE if error message has been displayed. */
	short error_message_visible;
	/* Line range hidden by error message */
	long error_hidden_start;
	long error_hidden_end;
	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;
	/* Token that started code completion SEW_TOK_NEW SEW_TOK_AS blank ... */
	short sew_start_token;
	/* 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 lineend;

	/* Range of lines in which the source code lines have to be marked. */
	unsigned char *start_marked_lines;
	unsigned 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;
	QFrame *preview_widget;
	QListBox *popup_listbox;

	short popup_type;

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 );
	void storeCurrentLine( void );
	void handleKeyEvent( QKeyEvent *ev );
	void delete_block( short with_undo );
	int unparseLine( unsigned char *start_line, unsigned 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 );
	unsigned char *insertSourceLine( unsigned char *new_line );
	void keyLeft( void );
	void keyRight( void );
	void keyUp( void );
	short getCursorPos( void );
	void moveCursorUp( void );
	void keyDown( void );
	void compCursYpos( unsigned char *start_line );
	void setEditCursorPos( unsigned char *current_line, short curs_pos );
	void redrawAllLines2( void );
	void redrawAllLines( QPainter *p, int cx, int cy, int cw, int ch );
	void drawCurrentLine( void );

	/* Sourcefile: edit_keycode.cpp */

	void insertNewChar( short sign, bool with_undo );
	void insertString( unsigned char *str );

	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 checkBracketCodeCompl( void );
	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);
	unsigned char *skipFoldedLines( unsigned char *start_ptr );
	void setNewCurrentLine( unsigned char *start_line, short curspos_in_line );
	unsigned 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( unsigned char *source_line, short set_cursor );
	void setCurrentSourceLine( unsigned char *new_source_line );
	QWidget *createCCParent( void );
	void storeCurrentLine( bool with_preparse );

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

	unsigned char *getLineStart( short line_number );
	unsigned char *getNextVisibleLine( unsigned char *line_ptr );
	unsigned char *getPreviousVisibleLine( unsigned char *start_line );
	unsigned char *getCurrentLine();
	void setCurrentLine( unsigned char *new_line_ptr );
	short getCurrentChar();
	void editDeleteChar( short direction, short width_undo );
	void editInsertChar( short new_sign, short with_undo );
	unsigned char *get_last_line_start( unsigned char *lineptr );
	unsigned char *get_next_line_start( unsigned char *lineptr );
	void drawColorLine( QPainter *p, unsigned char *start_line, int yoffset, int draw_cursor );
	void drawColorLine( QPainter *p, unsigned char *start_line, int xoffset, int yoffset, int draw_cursor );
	void drawColorLine3( QPainter *p, unsigned char *start_line, int xoffset, int yoffset, int draw_cursor );
	void drawColorLine2( unsigned char *start_line, int yoffset, int draw_cursor );
	void drawColorPart( QPainter *pbuf, short yoffset, short *skip, short *xpx);
	void createSourcePopup( QPoint mouse_pos );

	/* Fold or unfold a block of lines starting at line_ptr */
	void foldFollowingLines( unsigned char *line_ptr, short fold_flag );

	void drawErrorLine( QPainter *p, unsigned char *start_line, int yoffset );
	void unmarkLastSelectedBlock( void );
	void setErrorCursorPos( unsigned char *error_pos );
	void unmarkBlockLines( SOURCE_BLOCK_HEADER *block_desc_ptr );
	short isIdentifier( unsigned 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 );

	void createPopupMethodText( char *method_desc_ptr );
	VAR_DESC *findCodeComplClassVar( void );
	void createPopup( int type );
	void checkCodeCompletion( int type );
	void reposPopupPosition( void );
	void createTypePopup( short class_only );
	void createInheritsPopup( void );
	void searchGlobalMethodDescription( void );
	void createVarClassPopup( CLASS_DESC *class_desc_ptr );
	void createQtcClassPopup( void *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 );
	void slotCCInfoClicked( void );
};

#endif


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