home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
g
/
gina15.zip
/
demos
/
hello.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-02-27
|
5KB
|
181 lines
/* @(#)hello.C 1.21 1/23/92 */
/*
Dies ist eine 'Hello-world'-Anwendung.
Auf Mouseclick wird ein Hi-Button erzeugt.
*/
#include <Gina/Gina.h>
#ifdef INCLUDE_SRC
#include "Gina.C"
#endif
//---------------------------------------------------------------------
class MyPair : public GnObject {
public:
int x, y;
MyPair () { x = 0; y = 0; }
MyPair ( int px, int py ) { x = px; y = py; }
};
DefGenericListWithIterator(MyPairList,MyPair,MyPairListIterator);
ImplGenericListWithIterator(MyPairList,MyPairListIterator);
//---------------------------------------------------------------------
class hello_world_application : public GnApplication {
public:
GnDocument* create_document ();
char * app_class () { return "HelloWorld" ; }
char * app_signature() { return "hello" ; }
char * app_file_type() { return ".hello" ; }
};
class hello_world_document : public GnDocument {
public:
GnView *create_view();
void create_windows (int new_width = 0, int new_height = 0);
void add_hi (int x, int y);
void rem_hi ( caddr_t, caddr_t );
void clear_all ( caddr_t, caddr_t );
Boolean write_to_stream ( ostream & );
Boolean read_from_stream ( istream & );
void draw_his();
private:
MyPairList hi_list;
};
class hello_world_view : public GnView {
public:
hello_world_view ( GnDocument *doc );
void draw ( int count, int x, int y, Dimension width, Dimension height );
void button_press ( int code, int repetition, int x, int y );
};
//---------------------------------------------------------------------
GnDocument * hello_world_application ::
create_document () { return new hello_world_document; }
//---------------------------------------------------------------------
GnView * hello_world_document ::
create_view () { return (new hello_world_view( this )); }
void hello_world_document ::
create_windows (int new_width, int new_height)
{
Gina_Debug_NL ("hello_world_document :: create_windows");
main_shell = new GnDocumentShellWithScroller( this, new_width, new_height );
main_shell->create( GnApplication::get()->get_application_shell(),
"mainShell" );
main_shell->add_menu_command( "Hello", "Remove Last Hi",
CALLBACK(hello_world_document,rem_hi,this) );
main_shell->add_menu_command( "Hello", "Clear All",
CALLBACK(hello_world_document,clear_all,this) );
}
void hello_world_document ::
add_hi (int x, int y)
{
Gina_Debug_NL ("hello_world_document :: add_hi");
MyPair *xy = new MyPair( x, y );
hi_list.Prepend( xy );
}
void hello_world_document ::
rem_hi ( caddr_t, caddr_t )
{
Gina_Debug_NL ("hello_world_document :: rem_hi");
if ( hi_list.Length() > 0 ) {
MyPair *xy = hi_list.RemoveFirst();
main_view->invalidate_rectangle( xy->x, xy->y-18, 20, 20 );
delete( xy );
main_view->force_redraw();
}
}
void hello_world_document ::
clear_all ( caddr_t, caddr_t )
{
if ( hi_list.Length() > 0 ) {
MyPair *xy;
while ( hi_list.Length() > 0 ) {
xy = hi_list.RemoveFirst();
delete( xy );
}
main_view->invalidate_rectangle( 0, 0, 200, 200 );
main_view->force_redraw();
}
}
Boolean hello_world_document ::
write_to_stream( ostream &ofs )
{
MyPair *xy;
ofs << hi_list.Length() << endl;
for( MyPairListIterator it(hi_list); ! it.Off(); it.Forth() ) {
xy = it.Item();
ofs << xy->x << " " << xy->y << endl;
}
return True;
}
Boolean hello_world_document ::
read_from_stream ( istream &ifs )
{
int no_obj, x, y;
ifs >> no_obj;
for ( int i = 0; i < no_obj; i++ ) {
ifs >> x >> y;
MyPair *xy = new MyPair(x,y);
hi_list.Prepend( xy );
}
return True;
}
void hello_world_document ::
draw_his()
{
MyPair *xy;
for(MyPairListIterator it(hi_list); ! it.Off(); it.Forth() ) {
xy = it.Item();
main_view->draw_glyphs (xy->x, xy->y, "Hi!");
}
}
//---------------------------------------------------------------------
hello_world_view ::
hello_world_view ( GnDocument *doc )
: GnView( doc )
{
setR_width( 400 );
setR_height( 400 );
}
void hello_world_view ::
draw ( int, int, int, Dimension, Dimension )
{
Gina_Debug_NL ("hello_world_view :: draw");
draw_rectangle (24, 16, 87, 19);
draw_glyphs (30, 30, "Hello, world!");
((hello_world_document*)document)->draw_his();
}
void hello_world_view ::
button_press ( int, int, int x, int y )
{
Gina_Debug_NL( "hello_world_view :: button_press" );
((hello_world_document*)document)->add_hi( x, y );
force_redraw();
}
//---------------------------------------------------------------------
int main (unsigned int argc, char ** argv)
{
hello_world_application hwa;
#ifdef GINA_DEBUG
hwa.set_sync();
#endif
hwa.run( argc, argv );
}