home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Acorn User 2
/
AUCD2.iso
/
program
/
vista.arc
/
!hyperview
/
h
/
viewer
< prev
Wrap
Text File
|
1996-01-25
|
10KB
|
313 lines
// **************************************************************************
// Copyright 1996 David Allison
//
// VV VV IIIIII SSSSS TTTTTT AA
// VV VV II SS TT AA AA
// VV VV II SSSS TT AA AA
// VV VV II SS TT AAAAAAAA
// VV IIIIII SSSS TT AA AA
//
// MULTI-THREADED C++ WIMP CLASS LIBRARY
// for RISC OS
// **************************************************************************
//
// P U B L I C D O M A I N L I C E N C E
// -------------------------------------------
//
// This library is copyright. You may not sell the library for
// profit, but you may sell products which use it providing
// those products are presented as executable code and are not
// libraries themselves. The library is supplied without any
// warranty and the copyright owner cannot be held responsible for
// damage resulting from failure of any part of this library.
//
// See the User Manual for details of the licence.
//
// *************************************************************************
#ifndef __viewer_h
#define __viewer_h
#include "Vista:vista.h"
#include "viewer.h"
#include <stdio.h>
#include <setjmp.h>
class Viewer ;
class HyperView ;
class HTMLObject
{
public:
HTMLObject(Viewer *v) ;
virtual ~HTMLObject() ;
Viewer *viewer ;
HTMLObject *next ;
HTMLObject *prev ;
} ;
class Paragraph ;
class ParagraphBody : public FontObject
{
public:
ParagraphBody(Paragraph *p, Window *w, char *name, int fhandle, int x0, int y0, int width, int priority = 0, char *menu = 0) ;
~ParagraphBody() ;
void pointer (int entering) ; // pointer entering or leaving object
void click (int mx, int my, int button) ; // click on object
void set_url (char *url) ;
int hyperlink ;
char *url ; // uniform resouce locator for hyperlink
Paragraph *p ;
} ;
class PointerIcon : public Icon
{
public:
PointerIcon (Window *w, Icon *temp, int x, int y, int width, int height, ParagraphBody *body) ;
~PointerIcon() ;
void click(int mx, int my, int button, int icon) ; // icon has been clicked
private:
ParagraphBody *body ;
} ;
class Paragraph : public HTMLObject
{
public:
Paragraph(Viewer *v, int x, int y, int width, int priority) ; // specify top left x,y and width
~Paragraph() ;
void add_text (char *text) ; // add text to the object
void finish() ; // finish off the object
int height() ;
void bold() ;
void normal() ;
void italic() ;
void header(int level) ;
void system() ;
void begin_hyperlink() ;
void end_hyperlink() ;
void read_position (int &x, int &y) ;
int width() ;
void set_font (int) ;
void set_indent(int) ;
void set_url (char *url) ;
void set_last_gap(int gap) ;
int last_line_height() ;
void redraw() ; // redraw the window under the paragraph
ParagraphBody *body ; // paragraph body
int current_font ;
} ;
class Image : public HTMLObject
{
public:
Image (Viewer *v, char *filename, int x, int y, int priority) ;
~Image() ;
int height() ;
int width() ;
private:
DrawObject *image ;
} ;
class HRuleObject : public Object
{
public:
HRuleObject (Window *w, int y, int width, int priority) ;
~HRuleObject() ;
void redraw (int x0, int y0, int x1, int y1) ;
} ;
class HLine : public HTMLObject
{
public:
HLine (Viewer *v, int y, int width, int priority) ;
~HLine() ;
int height() ;
int width() ;
private:
HRuleObject *line ;
} ;
class Controls : public Window
{
enum buttons
{
BACK,
FORWARD,
HOME
} ;
public:
Controls(Viewer *v) ;
~Controls() ;
virtual void click(int mx, int my, int button, int icon) ; // icon has been clicked
private:
Viewer *viewer ;
} ;
class Display : public Window
{
public:
Display(Window *parent) ;
~Display() ;
void print (char *text) ;
private:
Icon *output ;
} ;
const int PARAGRAPH_NORMAL_PRIORITY = 1 ;
struct Anchor
{
Anchor *left, *right ;
char *name ; // anchor name
int x ; // x coordinate in window
int y ; // y coord
} ;
struct Context
{
Context *prev ; // previous context
Context *next ; // next context
char filename[256] ;
char root[256] ;
int x ;
int y ;
} ;
class Viewer : public Window
{
public:
Viewer(HyperView *h) ;
~Viewer() ;
void close() ; // on closing
void display_file(char *filename, bool new_ctx = true) ; // diaplay a file in the viewer
void set_home_document(char *filename) ;
void add_object(HTMLObject *) ; // add a new HTML object to viewer
void clear() ; // clear the viewer of all objects
int normal_font() ; // return font handle for normal font
int bold_font() ;
int italic_font() ;
int bold_italic_font() ;
int header_font (int level) ;
int system_font() ;
void print (char *format...) ;
bool parse_url (char *url, char *filename, char *anchor) ; // parse a url into filename and anchor
void follow_hyperlink (char *filename, char *anchor) ; // follow a hyper link
void back() ; // go back one context
void forward() ; // go forward one context
void home() ; // go to home document
Viewer *next ;
Viewer *prev ;
private:
enum Tokens
{
TITLE,
P,
BR,
IMG,
EM,
B,
PRE,
H1,
H2,
H3,
H4,
H5,
H6,
STRING,
NUMBER,
A,
EQUALS,
WORD,
EOL,
HR,
HTML,
UL,
LI,
OL,
END = 0x100
} ;
enum Attributes
{
NAME,
HREF,
ALIGN,
TOP,
MIDDLE,
BOTTOM,
ALT,
ISMAP,
CEND, // command end token
SRC
} ;
HyperView *hyperview ;
Controls *controls ;
Display *display ;
HTMLObject *objects ;
HTMLObject *last_object ;
int normal_fhandle ; // normal font handle
int bold_fhandle ; // bold font handle
int italic_fhandle ; // italic font handle
int bold_italic_fhandle ; // bold and italic font
int header_fonts[6] ; // header font handles
int system_fhandle ; // system font handle
jmp_buf eof_state ; // jmp_buf for end of file
FILE *fp ;
static char line[4096] ; // line
static char sentence[4096] ; // sentence being built
char *ch ;
char *p ; // current position in sentence
char spelling[256] ;
int value ;
Paragraph *paragraph ; // current paragraph
int x, y ; // current x and y coords
int width ; // window width in OS coords
int min_height ; // minimum window height
char document_root[256] ; // root directory for documents
char home_document[256] ; // home document file name
char current_document[256] ; // current document
int sp ;
int stack[256] ;
int current_font ;
bool preformatted ;
bool eol ;
int num_bytes ;
Anchor *anchors ; // tree of anchors in window
Anchor *insert_anchor (Anchor *t, Anchor **root, char *name) ;
Anchor *find_anchor (Anchor *t, char *name) ;
void delete_anchor (Anchor *t) ;
Anchor *current_anchor ;
Context *context_stack ;
Context *current_context ;
Icon *template_pointer_icon ;
bool converted ;
void next_line() ;
int next_char() ;
int token() ; // read a single token
int word() ; // read a single word
int reserved_word(bool&) ;
int html_reserved_word() ; // reserved word inside HTML command
void new_paragraph(int font, int priority = PARAGRAPH_NORMAL_PRIORITY) ;
void process_html() ;
void append_word (char *word) ;
void begin_anchor() ;
void end_anchor() ;
void html_error() ; // an error in an HTML command - abort command
Image *insert_image(int xpos) ; // insert an image
void save_current_context() ; // push current context onto stack
void new_context() ; // get a new context
void scroll_to (int x, int y) ; // scroll to y coord
void scroll_to_anchor(char *) ; // scroll to an anchor
void push(int handle) ;
int pop() ;
} ;
#endif