[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: vNotepad?



-----Original Message-----
From: Jonathan Hawley <lorimaite@hotmail.com>
To: vgui-discuss@other.debian.org <vgui-discuss@other.debian.org>
Date: Thursday, November 02, 2000 7:45 PM
Subject: vNotepad?


>I was wondering if anyone had code for a vNotepad.  Having trouble figuring
>how to force certain codes, that would have to be done in notepad.  Like
how
>do I set a maximium character per line?  Many more question needs
answering.
>  Easiest answer would be something like notepad except with a forced
>character per line.  Anyways, thanx!



Some time ago I was thinking about a simple "vNotepad", and even
started some programming. So, the starting point was to use STL.
Then, for text we may define

#include <string>
#include <list>

typedef string   Line;
typedef list<Line>   Text;
typedef Line::iterator  Line_Iter;
typedef Line::const_iterator Line_cIter;
typedef Text::iterator  Text_Iter;
typedef Text::const_iterator Text_cIter;

There is no limit for number of chars per line, and it is ease and fast
to insert/delete a line. And we can use well-developed STL library to
work with our Text.
The next step is to draw the text on screen, it can be like this:

class sedCanvasPane : public vCanvasPane       {
    Text  text;
    Text_Iter scr_top;
    Text_Iter scr_bottom;
    Text_Iter cur_line;
    Line_Iter cur_chr;

    int  cline_nmb;
    int  left_marg;
    int  top_marg;
    int  ascent;
    int  descent;
    int  line_h;

    bool  wrap;

public:
    sedCanvasPane();
    virtual ~sedCanvasPane();

 // Scrolling
    virtual void HPage(int shown, int top);
    //...

 // Events
    virtual void MouseDown(int x, int y, int button);
    //...

    virtual void Redraw(int x, int y, int width, int height);
    virtual void Resize(int newW, int newH);

    // new drawing functions
    void DrawLine(int xpos, int line_nmb, const Line& line, Line_cIter
from);
    void DrawLine() {DrawLine(xpos_at(*cur_line, cur_chr), cline_nmb,
*cur_line, cur_chr);}
    void DrawBottom(int lin_nmb, Text_Iter from);
    void ShowCursor();

    bool CurBack();
    bool CurFront();
    void CurUp(int lines=1);
    void CurDown(int lines=1);
    void ScreenUp(int lines=1);
    void ScreenDown(int lines=1);

    void LineBegin() {cur_chr=cur_line->begin(); ShowCursor();}
    void LineEnd() {cur_chr=cur_line->end(); ShowCursor();}

    void InsertChar(char chr);
    bool DeleteChar();
    void BreakLine();
    bool InsertLine(const string& line);
    // and so on ...

protected:
    int line_ypos(int nmb) const {return top_marg+line_h*(nmb+1);}
    int xpos_at(const Line& line, Line_cIter chr);
    void init();
};

Sorry for a long piece of code.
Well, I got it working on a level of insert/delete operations with charcters
and
lines. Not too far as you see. And had no time to work with this poroject
for more
than one year. But if any one is interested in this, I can move it to a
public
place ot send it as attachment.

Best reagrds, Nikolai

==============================
Nikolai V. Tkachenko, Ph.D.
Institute of Materials Chemistry
Tampere University of Technology, Finland
fax: +358 3 3652108
e-mail: nikolai.tkachenko@tut.fi, tkatchen@cc.tut.fi
WWW: http://www.tut.fi/~tkatchen




Reply to: