diff options
Diffstat (limited to 'apps/X11/wxSword')
26 files changed, 1686 insertions, 0 deletions
diff --git a/apps/X11/wxSword/Makefile b/apps/X11/wxSword/Makefile new file mode 100644 index 0000000..736cf95 --- /dev/null +++ b/apps/X11/wxSword/Makefile @@ -0,0 +1,26 @@ +root := ../../.. +subdirs := +pre-targets := +targets := gui_sword +bin := gui_sword +include ${root}/Makefile.cfg + +cpp += gui_sword.cpp +CPPFLAGS += -I. -I/usr/local/wxGTK/include -D__WXGTK__ +#CPPFLAGS += -I. -I/usr/local/wxGTK/include -I/usr/local/wxGTK/src/zlib -D__WXGTK__ +LFLAGS += -L/usr/X11/lib + + +s = $(c) $(cpp) +d = $(c:%.c=%.d) $(cpp:%.cpp=%.d) +o = $(c:%.c=%.o) $(cpp:%.cpp=%.o) +l = -lsword -lstdc++-lwx_gtk -lgtk -lgdk -lglib -lXext -lX11 -lm -ldl -lSM -lICE -lpthread-0.7 + + +gui_sword: $(o) + $(CC) -D__WXGTK__ $(LFLAGS) -o $@ $(o) $(l) $(l) + + +ifneq ($(nodeps),yes) +-include $(d) +endif diff --git a/apps/X11/wxSword/bak/gui_sword.mak b/apps/X11/wxSword/bak/gui_sword.mak new file mode 100644 index 0000000..c6805d5 --- /dev/null +++ b/apps/X11/wxSword/bak/gui_sword.mak @@ -0,0 +1,18 @@ +sword.e : sword.o + egcs -pipe -o sword.e gui_sword.o -L. \ + -L/home/lcortes/WXGUI/wxGTK/lib/Linux \ + -L/home/lcortes/SWORD/sword/lib \ + -lwx_gtk -L/usr/lib -L/usr/X11/lib -lgtk \ + -lgdk -lglib -lXext -lX11 -lm -ldl -lSM \ + -lmodules -lswmgr -lutilfuns -lfrontend -lkeys \ + -lICE -lpthread-0.7 -lstdc++ + + +sword.o : gui_sword.C gui_sword.h + egcs -c -pipe -o gui_sword.o -Wall -g -I.. -D__WXGTK__ \ + -I. -I.. -I/home/lcortes/WXGUI/wxGTK/include \ + -I/home/lcortes/WXGUI/wxGTKsrc/zlib \ + -I/home/lcortes/SWORD/sword/include \ + -I/usr/lib/glib/include gui_sword.C + + diff --git a/apps/X11/wxSword/bak/project.prj b/apps/X11/wxSword/bak/project.prj new file mode 100644 index 0000000..8b6e7d5 --- /dev/null +++ b/apps/X11/wxSword/bak/project.prj @@ -0,0 +1,17 @@ +# +# xwpe - project-file: project.prj +# createted by xwpe version Version 1.5.9 +# + + +CMP= egcs +CMPFLAGS= -g -D__WXGTK__ -I. -I.. -I/home/lcortes/WXGUI/wxGTK/include -I/home/lcortes/WXGUI/wxGTKsrc/zlib -I/home/lcortes/SWORD/sword/include -I/usr/lib/glib/include +LDFLAGS= -L. -L/home/lcortes/WXGUI/wxGTK/lib/Linux -L/home/lcortes/SWORD/sword/lib -lwx_gtk -L/usr/lib -L/usr/X11/lib -lgtk -lgdk -lglib -lXext -lX11 -lm -ldl -lSM -lmodules -lswmgr -lutilfuns -lfrontend -lkeys -lICE -lpthread-0.7 -lstdc++ +EXENAME= sword.e +CMPSWTCH= gnu +CMPMESSAGE= '${?*:warning:}\"${FILE}\", line ${LINE}:* at or near * \"${COLUMN=AFTER}\"' + +FILES= gui_sword.C + +install: + diff --git a/apps/X11/wxSword/bitmaps/copy.bmp b/apps/X11/wxSword/bitmaps/copy.bmp Binary files differnew file mode 100644 index 0000000..4551a06 --- /dev/null +++ b/apps/X11/wxSword/bitmaps/copy.bmp diff --git a/apps/X11/wxSword/bitmaps/copy.xpm b/apps/X11/wxSword/bitmaps/copy.xpm new file mode 100644 index 0000000..47565c1 --- /dev/null +++ b/apps/X11/wxSword/bitmaps/copy.xpm @@ -0,0 +1,25 @@ +/* XPM */ +static char *copy_xpm[] = { +/* columns rows colors chars-per-pixel */ +"16 15 4 1", +" c None", +". c Black", +"X c Gray100", +"o c #000080", +/* pixels */ +" ", +" ...... ", +" .XXXX.. ", +" .XXXX.X. ", +" .X..X.oooooo ", +" .XXXXXoXXXXoo ", +" .X....oXXXXoXo ", +" .XXXXXoX..Xoooo", +" .X....oXXXXXXXo", +" .XXXXXoX.....Xo", +" ......oXXXXXXXo", +" oX.....Xo", +" oXXXXXXXo", +" ooooooooo", +" " +}; diff --git a/apps/X11/wxSword/bitmaps/cut.bmp b/apps/X11/wxSword/bitmaps/cut.bmp Binary files differnew file mode 100644 index 0000000..1555433 --- /dev/null +++ b/apps/X11/wxSword/bitmaps/cut.bmp diff --git a/apps/X11/wxSword/bitmaps/cut.xpm b/apps/X11/wxSword/bitmaps/cut.xpm new file mode 100644 index 0000000..bfe7e95 --- /dev/null +++ b/apps/X11/wxSword/bitmaps/cut.xpm @@ -0,0 +1,24 @@ +/* XPM */ +static char *cut_xpm[] = { +/* columns rows colors chars-per-pixel */ +"16 15 3 1", +" c None", +". c Black", +"X c #000080", +/* pixels */ +" ", +" . . ", +" . . ", +" . . ", +" .. .. ", +" . . ", +" ... ", +" . ", +" X.X ", +" X XXX ", +" XXX X X ", +" X X X X ", +" X X X X ", +" X X XX ", +" XX " +}; diff --git a/apps/X11/wxSword/bitmaps/help.bmp b/apps/X11/wxSword/bitmaps/help.bmp Binary files differnew file mode 100644 index 0000000..2d9e692 --- /dev/null +++ b/apps/X11/wxSword/bitmaps/help.bmp diff --git a/apps/X11/wxSword/bitmaps/help.xpm b/apps/X11/wxSword/bitmaps/help.xpm new file mode 100644 index 0000000..50fdb41 --- /dev/null +++ b/apps/X11/wxSword/bitmaps/help.xpm @@ -0,0 +1,25 @@ +/* XPM */ +static char *help_xpm[] = { +/* columns rows colors chars-per-pixel */ +"16 15 4 1", +" c None", +". c Black", +"X c Blue", +"o c #000080", +/* pixels */ +" ", +" ...... ", +" .XXXXX.. ", +" .XX...oX.. ", +" .X.. .X.. ", +" .X.. .XX.. ", +" .. .XX.. ", +" .XX.. ", +" .X.. ", +" .X.. ", +" .o.. ", +" .. ", +" .XX.. ", +" .XX.. ", +" ... " +}; diff --git a/apps/X11/wxSword/bitmaps/new.bmp b/apps/X11/wxSword/bitmaps/new.bmp Binary files differnew file mode 100644 index 0000000..d66feb2 --- /dev/null +++ b/apps/X11/wxSword/bitmaps/new.bmp diff --git a/apps/X11/wxSword/bitmaps/new.xpm b/apps/X11/wxSword/bitmaps/new.xpm new file mode 100644 index 0000000..754d2d2 --- /dev/null +++ b/apps/X11/wxSword/bitmaps/new.xpm @@ -0,0 +1,24 @@ +/* XPM */ +static char *new_xpm[] = { +/* columns rows colors chars-per-pixel */ +"16 15 3 1", +" c None", +". c Black", +"X c Gray100", +/* pixels */ +" ", +" ........ ", +" .XXXXXX.. ", +" .XXXXXX.X. ", +" .XXXXXX.... ", +" .XXXXXXXXX. ", +" .XXXXXXXXX. ", +" .XXXXXXXXX. ", +" .XXXXXXXXX. ", +" .XXXXXXXXX. ", +" .XXXXXXXXX. ", +" .XXXXXXXXX. ", +" .XXXXXXXXX. ", +" ........... ", +" " +}; diff --git a/apps/X11/wxSword/bitmaps/open.bmp b/apps/X11/wxSword/bitmaps/open.bmp Binary files differnew file mode 100644 index 0000000..bbf93fe --- /dev/null +++ b/apps/X11/wxSword/bitmaps/open.bmp diff --git a/apps/X11/wxSword/bitmaps/open.xpm b/apps/X11/wxSword/bitmaps/open.xpm new file mode 100644 index 0000000..54748e9 --- /dev/null +++ b/apps/X11/wxSword/bitmaps/open.xpm @@ -0,0 +1,26 @@ +/* XPM */ +static char *open_xpm[] = { +/* columns rows colors chars-per-pixel */ +"16 15 5 1", +" c None", +". c Black", +"X c Yellow", +"o c Gray100", +"O c #bfbf00", +/* pixels */ +" ", +" ... ", +" . . .", +" ..", +" ... ...", +" .XoX....... ", +" .oXoXoXoXo. ", +" .XoXoXoXoX. ", +" .oXoX..........", +" .XoX.OOOOOOOOO.", +" .oo.OOOOOOOOO. ", +" .X.OOOOOOOOO. ", +" ..OOOOOOOOO. ", +" ........... ", +" " +}; diff --git a/apps/X11/wxSword/bitmaps/page.bmp b/apps/X11/wxSword/bitmaps/page.bmp Binary files differnew file mode 100644 index 0000000..3dbd4b0 --- /dev/null +++ b/apps/X11/wxSword/bitmaps/page.bmp diff --git a/apps/X11/wxSword/bitmaps/paste.bmp b/apps/X11/wxSword/bitmaps/paste.bmp Binary files differnew file mode 100644 index 0000000..564f514 --- /dev/null +++ b/apps/X11/wxSword/bitmaps/paste.bmp diff --git a/apps/X11/wxSword/bitmaps/preview.bmp b/apps/X11/wxSword/bitmaps/preview.bmp Binary files differnew file mode 100644 index 0000000..da1f4db --- /dev/null +++ b/apps/X11/wxSword/bitmaps/preview.bmp diff --git a/apps/X11/wxSword/bitmaps/preview.xpm b/apps/X11/wxSword/bitmaps/preview.xpm new file mode 100644 index 0000000..0dfdca4 --- /dev/null +++ b/apps/X11/wxSword/bitmaps/preview.xpm @@ -0,0 +1,26 @@ +/* XPM */ +static char *preview_xpm[] = { +/* columns rows colors chars-per-pixel */ +"16 15 5 1", +" c Black", +". c None", +"X c Gray100", +"o c #808080", +"O c Cyan", +/* pixels */ +" .......", +" XXXXXXX ......", +" XXXXXXX . .....", +" XXXXXXX ....", +" XXXXXXXXXX ....", +" XXXXXXX ....", +" XXXXXX o..o ...", +" XXXXX oOO.oo ..", +" XXXXX .O..o. ..", +" XXXXX ....o. ..", +" XXXXX o..Ooo ..", +" XXXXXX o..o o..", +" XXXXXXX o .", +" XXXXXXXXXX . ", +" .. " +}; diff --git a/apps/X11/wxSword/bitmaps/print.bmp b/apps/X11/wxSword/bitmaps/print.bmp Binary files differnew file mode 100644 index 0000000..00319b5 --- /dev/null +++ b/apps/X11/wxSword/bitmaps/print.bmp diff --git a/apps/X11/wxSword/bitmaps/print.xpm b/apps/X11/wxSword/bitmaps/print.xpm new file mode 100644 index 0000000..3c2e2be --- /dev/null +++ b/apps/X11/wxSword/bitmaps/print.xpm @@ -0,0 +1,26 @@ +/* XPM */ +static char *print_xpm[] = { +/* columns rows colors chars-per-pixel */ +"16 15 5 1", +" c None", +". c Black", +"X c Gray100", +"o c #808000", +"O c Yellow", +/* pixels */ +" ", +" ......... ", +" .XXXXXXXX. ", +" .X.....X. ", +" .XXXXXXXX. ", +" .X.....X.... ", +" .XXXXXXXX. . .", +" .......... . ..", +". . . .", +"............. .", +". ooo . . ", +". OOO ... ", +"............. . ", +" . . . ", +" ........... " +}; diff --git a/apps/X11/wxSword/bitmaps/save.bmp b/apps/X11/wxSword/bitmaps/save.bmp Binary files differnew file mode 100644 index 0000000..56dd10b --- /dev/null +++ b/apps/X11/wxSword/bitmaps/save.bmp diff --git a/apps/X11/wxSword/bitmaps/save.xpm b/apps/X11/wxSword/bitmaps/save.xpm new file mode 100644 index 0000000..01b18f9 --- /dev/null +++ b/apps/X11/wxSword/bitmaps/save.xpm @@ -0,0 +1,25 @@ +/* XPM */ +static char *save_xpm[] = { +/* columns rows colors chars-per-pixel */ +"16 15 4 1", +" c None", +". c Black", +"X c #808000", +"o c #808080", +/* pixels */ +" ", +" .............. ", +" .X. . . ", +" .X. ... ", +" .X. .X. ", +" .X. .X. ", +" .X. .X. ", +" .X. .X. ", +" .XX........oX. ", +" .XXXXXXXXXXXX. ", +" .XX.........X. ", +" .XX...... .X. ", +" .XX...... .X. ", +" .XX...... .X. ", +" ............. " +}; diff --git a/apps/X11/wxSword/gui_sword.cpp b/apps/X11/wxSword/gui_sword.cpp new file mode 100644 index 0000000..33d50ca --- /dev/null +++ b/apps/X11/wxSword/gui_sword.cpp @@ -0,0 +1,1075 @@ +// -------------------------------------------------------------- +// For compilers that support precompilation, includes "wx/wx.h" + +#include "wx/wxprec.h" + +#ifndef WX_PRECOMP +#include "wx/wx.h" +#endif + +// Things for Sword +#include <stdio.h> +#include <iostream.h> +#include <versekey.h> +#include <rawtext.h> +#include <zcom.h> +#include <rawcom.h> +#include <rawgbf.h> +#include <stdlib.h> +#include <rawcom.h> +#include <rawld.h> +#include <regex.h> + +#include <swmgr.h> + +// I added +#include <stl.h> +#include <strstream.h> + +#include "wx/notebook.h" +#include "wx/imaglist.h" +#include "wx/toolbar.h" +#include "gui_sword.h" + + +#ifdef __WXGTK__ +#include "mondrian.xpm" +#include "bitmaps/new.xpm" +#include "bitmaps/open.xpm" +#include "bitmaps/save.xpm" +#include "bitmaps/copy.xpm" +#include "bitmaps/cut.xpm" + +// #include "bitmaps/paste.xpm" + +#include "bitmaps/print.xpm" +#include "bitmaps/preview.xpm" +#include "bitmaps/help.xpm" +#endif + +#include "jptr.h" + + +int ID_CHOICE = 300; + +// =============================================================================== +// Global Declarations +// =============================================================================== +class ttextVec : public vector<clJPTR<wxTextCtrl> > +{ +}; + +class tpanelVec : public vector<clJPTR<wxPanel> > +{ +}; + +class globals +{ +private: + static int id_counter; + +public: + int get_id() + { + return (id_counter ++ ); + } +}; + +int globals::id_counter = 10; +globals gPool; + + +IMPLEMENT_APP(MyApp) + +// ============================================= +// CLASS: cNewNote +// +// Contain all information for a particular +// notebook control. +// +// ============================================= + template< class tType > +class cNewNote +{ +public: + class tVec : public vector< clJPTR<tType> > + { + }; + +private: + ttextVec m_vpTextCtrl; + tpanelVec m_vpPanel; + +private: + clJPTR<wxNotebook> m_notebook; + tVec m_vBookList; + +public: + + cNewNote() + { + } + + void Init( wxPanel* pMainPanel ) + { + assert( m_vBookList.size() > 0 && "use AddPage First!" ); + + // Create a new NOTEBOOK item + m_notebook = new wxNotebook( pMainPanel, gPool.get_id() ); + + // Add all the pages + make_panels (); + + // Layout NoteBook in Main Panel + wxLayoutConstraints *pLayout = new wxLayoutConstraints; + pLayout->left.SameAs ( pMainPanel, wxLeft ); + pLayout->top.SameAs ( pMainPanel, wxTop ); + pLayout->right.SameAs ( pMainPanel, wxRight); + pLayout->bottom.SameAs ( pMainPanel, wxBottom); + m_notebook -> SetConstraints( pLayout ); + + // Create Initial Verse and Populate notebook texts. + // Update all commentaries and bibles + // NewVerse( wxString( "Genesis 1:1" )); + } + + // ----------------------------------------------- + // Create a note book tab, including + // panel, name of tab, and text area. + // + // ----------------------------------------------- + void make_panels() + { + tVec& oList = m_vBookList; + tVec::const_iterator iWalk; + + // For all books in our list do ... + for( iWalk = oList.begin(); iWalk != oList.end(); iWalk ++ ) + { + // Create a new Panel + m_vpPanel.push_back( new wxPanel( m_notebook.ptr() ) ); + m_vpPanel.back() -> SetAutoLayout( TRUE ); + + // Create a Text control for our panel + m_vpTextCtrl.push_back( new wxTextCtrl( (m_vpPanel.back()).ptr(), + gPool.get_id(), "", + wxPoint(-1,-1), wxSize(-1,-1), wxTE_MULTILINE )); + + // Remove right to edit + m_vpTextCtrl.back() -> SetEditable( FALSE ); + + // Set layout for this panel + wxLayoutConstraints *pLayout = new wxLayoutConstraints; + pLayout->left.SameAs ( (m_vpPanel.back()).ptr(), wxLeft ); + pLayout->top.SameAs ( (m_vpPanel.back()).ptr(), wxTop ); + pLayout->right.SameAs ( (m_vpPanel.back()).ptr(), wxRight); + pLayout->bottom.SameAs ( (m_vpPanel.back()).ptr(), wxBottom); + m_vpTextCtrl.back() -> SetConstraints(pLayout); + + // SET: Tab Name + m_notebook->AddPage( (m_vpPanel.back()).ptr(), (*iWalk)->Name(NULL), FALSE); + } + } + + // Adds a book I want to reference in my NoteBook. + void AddBook( tType* pABook ) + { + m_vBookList.push_back( pABook ); + } + + + // --------------------------------------------------------- + // NewVerse + // + // + void CommentaryVerse( wxString sVerse ) + { + VerseKey oKey = (char * ) sVerse.c_str(); + + oKey.Persist(1); + + tVec::iterator iWalk; + + // For every book in my list of books + // set this verse + for( iWalk = m_vBookList.begin(); + iWalk != m_vBookList.end(); + iWalk ++ ) + { + (*iWalk) -> SetKey( oKey ); + } + + ttextVec::iterator iText; + tVec::iterator iBooks = m_vBookList.begin(); + + // For every book, update verse info in text control. + for( iText = m_vpTextCtrl.begin(); + iText != m_vpTextCtrl.end(); + iText ++, iBooks ++ ) + { + // (*iText) -> SetValue( wxString( (*iBooks)->KeyText() )); + (*iText) -> SetValue( wxString( * ((*iBooks).ptr()) )); + } + } + // ---------------------------------------------------- + // Set the chapter in all the relevant note books + // + void BibleVerse( wxString sBook, const int nChapter, const int nVerse ) + { + wxString sTop; + sTop.Printf( "%s %d:%d", sBook.c_str(), nChapter, nVerse ); + + VerseKey oKey = (char * ) sTop.c_str(); + oKey.Persist(1); + + tVec::iterator iWalk; + + // For every book in my list of books + // set this verse + for( iWalk = m_vBookList.begin(); iWalk != m_vBookList.end(); iWalk ++ ) + { + (*iWalk) -> SetKey( oKey ); + } + + ttextVec::iterator iText; + tVec::iterator iBooks = m_vBookList.begin(); + + // For every book, update verse info in text control. + for( iText = m_vpTextCtrl.begin(); + iText != m_vpTextCtrl.end(); + iText ++, iBooks ++ ) + { + int i = 1; + ostrstream oOut; + int nStartPos = 0; + + // Clear Previous Text + (*iText) -> SetValue(""); + + // Add new Text + for( oKey = (char * ) sTop.c_str() ; oKey.Chapter() == nChapter; oKey ++, i++ ) + { + if ( i == nVerse ) + { + // Here is the verse we are interested in, mark it in some special + // way. + oOut << " <" << i << "> "; + } + else + oOut << " [" << i <<"] " ; + + oOut << * ((*iBooks).ptr()); + + if ( i == nVerse ) + { + nStartPos = oOut.pcount(); + } + } + oOut.put(0); + // Write out entire chapter + (*iText) -> WriteText( oOut.str()); + + // @todo: At this point you might want to + // 1. Grab a dynamic scroll bar + // 2. If you have the scroll bar, adjust it to the + // correct position, and with any insight + // the window should scroll to the appropriate + // verse. + // Exercise is left to the reader + + } + } + + + + void DictionaryKey( wxString sWord ) { + ttextVec::iterator iText; + tVec::iterator iBooks = m_vBookList.begin(); + + // For every book, update verse info in text control. + for( iText = m_vpTextCtrl.begin(); iText != m_vpTextCtrl.end(); iText ++, iBooks ++ ) { + ostrstream oOut; + + (*iBooks)->SetKey( sWord.c_str() ); + + // Clear Previous Text + (*iText) -> SetValue(""); + + // Add new Text + // This 'if' checks to make sure we have an entry + // It also forces the module to retrieve its text which forces KeyText to closest + // match. Without it, the call to KeyText would get exactly what we set with + // SetKey, above. + if (strlen(* ((*iBooks).ptr())) > 0) { + oOut << "[ " << ((*iBooks).ptr()) -> KeyText() << " ]" << endl; + oOut << * ((*iBooks).ptr()) << endl; + oOut.put(0); + (*iText) -> WriteText( oOut.str()); + } + } + } + + // NEW UPDATE + + void UpdateSearch( wxString sWord ) + { + ttextVec::iterator iText; + tVec::iterator iBooks = m_vBookList.begin(); + + // For every book, update verse info in text control. + for( iText = m_vpTextCtrl.begin(); + iText != m_vpTextCtrl.end(); + iText ++, iBooks ++ ) + { + ostrstream oOut; + + // Get the search results and start a key here. + SWListKey& oSearchResults = (*iBooks)->Search( sWord ); + oSearchResults.Persist( true ); + (*iBooks)->SetKey( oSearchResults ); + + // Clear Previous Text + (*iText) -> SetValue(""); + + // Add new Text + for( oSearchResults = TOP; + !oSearchResults.Error(); + oSearchResults ++ ) + { + oOut << (const char *) oSearchResults << ":" << endl; + oOut << * ((*iBooks).ptr()) << endl; + } + // Write out all matches + oOut.put(0); + (*iText) -> WriteText( oOut.str()); + } + } + + + + // --------------------------------------------------------- + // UpdateSearch + // Given a word, update all windows to reflect + // that word. + // NOTE: This may only be need by the Definition + // Windows. + // + void OLD_UpdateSearch( const wxString sWord ) + { + SWListKey oList; + tVec::iterator iWalk; + ttextVec::iterator iText = m_vpTextCtrl.begin(); + char szBuff[5000] = { 0 }; + + for( iWalk = m_vBookList.begin(); + iWalk != m_vBookList.end(); + iWalk ++ ) + { + // For all the matches do: + for( SWListKey oListKey = (*iWalk) -> Search( sWord.c_str(), REG_ICASE ); + !oListKey.Error(); + oListKey++ ) + { + strcat( szBuff, (const char *) oListKey ); + strcat( szBuff, "\n\n" ); + } + + // Update Text of Notebook + (*iText) -> SetValue( wxString( szBuff ) ); + } + return; + } + + +}; + + + + +// -------------------------------------------------------- +// CLASS: CHEADLINE +// +// + +class cHeadLine +{ +public: + clJPTR<wxComboBox> m_pBible; + clJPTR<wxComboBox> m_pChapter; + clJPTR<wxComboBox> m_pVerse; +private: + clJPTR<wxButton> m_pButton; + + +private: // member functions + // ---------------------------------------------------------- + // Find Book info in one of our 2 book lists. + // --------------------------------------------------------- + struct sbook* FindBook( const wxString& sBook ) + { + static const VerseKey oStep; + + + for(int i = 0; i < 2; i ++ ) + { + for( int j = 0; j < oStep.BMAX[i]; j ++ ) + { + if ( wxStringEq(sBook, wxString(oStep.books[i][j].name)) ) + { + return &oStep.books[i][j]; + } + } + } + return ( NULL ); + } + +public: + cHeadLine( wxPanel* pPanel) + { + static wxString choices[ 200 ]; + static VerseKey oStep; + int k = 0; + + // Initialize STRINGS of books of bible + for( int i = 0; i < 2; i ++ ) + { + for( int j = 0; j < oStep.BMAX[i]; j ++ ) + { + choices[k++] = wxString( oStep.books[i][j].name ); + } + } + + // Create Bible Book Selector + m_pBible = new wxComboBox( pPanel , + ID_CHOICE+1, choices[0], wxPoint(10,10), + wxSize(200,-1), k, choices ); + + m_pBible -> SetEditable( FALSE ); + + // Create Chapter Selector + m_pChapter = new wxComboBox( pPanel , + ID_CHOICE+2, "", wxPoint(220,10), + wxSize(50,-1) ); + + m_pChapter -> SetEditable( FALSE ); + + // Create Verse Selector + + m_pVerse = new wxComboBox( pPanel , + ID_CHOICE+3, "", wxPoint(280,10), + wxSize(50,-1) ); + + m_pVerse -> SetEditable( FALSE ); + + // Create Button for Search for Verse NOW. + m_pButton = new wxButton( pPanel, + ID_CHOICE+4, "GO!", wxPoint( 340, 10), + wxSize( 60 , -1 )); + + UpdateChapter( choices[0] ); + UpdateVerse( choices[0], 0 ); + } + + // ----------------------------------------------------- + // UpdateChapter + // Set all chapter numbers for the 1st chapter + // of this particular book. + // + // + void UpdateChapter( const wxString& sBook ) + { + struct sbook* pFound = NULL; + wxString sTemp; + + // Find Struct of Book Info + pFound = FindBook( sBook ); + assert( pFound && "This should always find something!"); + + // Remove all elements from chapter control. + m_pChapter->Clear(); + + // Fill List of Chapters + for( int i = 0; i < pFound->chapmax; i ++ ) + { + sTemp.Printf("%2d", i + 1 ); + m_pChapter->Append( sTemp ); + } + } + + + // ----------------------------------------------------- + // UpdateVerse + // Set all verses for the 1st verse of this + // particular chapter, in this particular + // book. + // + UpdateVerse( wxString sBook, const int iChapter ) + { + struct sbook* pFound = NULL; + + // Find Struct of Book Info + pFound = FindBook( sBook ); + assert( pFound && "This should always find something!"); + + wxString sTemp; + + m_pVerse -> Clear(); + for( int i = 0; i < pFound->versemax[iChapter]; i ++ ) + { + sTemp.Printf( "%d", i + 1 ); + m_pVerse->Append( sTemp ); + } + } +}; + + + +// =================================================================== +// CLASS: CDEFHEADLINE +// Contain Headliner information about Definition notebook. +// +// @todo: Looks like a kludge - fix. +int WID_STATICTEXT = 100; +int WID_TEXT = WID_STATICTEXT + 1; + + +class cDefHeadLine +{ +public: + clJPTR<wxTextCtrl> m_pSearchCtrl; + +public: + cDefHeadLine(wxPanel* pPanel) + { + + // Create Bible Book Selector + new wxStaticText( pPanel, + WID_STATICTEXT, "Dictionary Key:", + wxPoint( 10, 15), wxSize( 100, -1 ), + wxRAISED_BORDER); + + m_pSearchCtrl = new wxTextCtrl( pPanel, + WID_TEXT, "", wxPoint(105,10), + wxSize(200,-1), wxTE_PROCESS_ENTER); + } +}; + + +// =================================================================== +// CLASS: MyFrame +// +// Define a new frame +class MyFrame: public wxFrame +{ +public: + wxPanel* m_pBiblePanel; + wxPanel* m_pCommentPanel; + wxPanel* m_pDefPanel; + wxPanel* m_pHeadLine; + wxPanel* m_pDefHeadLine; + + cHeadLine* m_pcHeadLine; + cDefHeadLine* m_pcDefHeadLine; + + cNewNote<SWModule>* m_pcNoteBible; + cNewNote<SWModule>* m_pcNoteCommentary; + cNewNote<SWModule>* m_pcNoteDef; + +public: + MyFrame(wxFrame *parent, wxWindowID id = -1, const wxString& title = "wxToolBar Sample", + const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, + long style = wxDEFAULT_FRAME_STYLE); + + virtual ~MyFrame(); + +public: + // Event Handlers + void OnCloseWindow(wxCloseEvent& event); + void OnQuit(wxCommandEvent& event); + void OnAbout(wxCommandEvent& event); + void OnToolLeftClick(wxCommandEvent& event); + void OnToolEnter(wxCommandEvent& event); + void OnBookUpdate( wxCommandEvent& event ); + void OnChapterUpdate( wxCommandEvent& event ); + void OnGoButton( wxCommandEvent& event ); + void OnDefinitionSearch( wxCommandEvent& event ); + + DECLARE_EVENT_TABLE() + + + public: + SWMgr *mainMgr; + char CreateTextPane(SWModule *mod, char *font = 0); + char CreateCommentPane(SWModule *mod); + char CreateLDPane(SWModule *mod); +}; + + +// ----------------------------------------------------------------------- +// The `main program' equivalent, creating the windows and returning the +// main frame +// ----------------------------------------------------------------------- +bool MyApp::OnInit(void) +{ + // CREATE Main Frame + MyFrame* pFrame = + new MyFrame((wxFrame *) NULL, -1, + (const wxString) "Sword Project 1.0", + wxPoint(100, 100), wxSize(650, 500)); + + // CREATE Status Line + pFrame -> CreateStatusBar(); + + // SET: Auto Layout + pFrame -> SetAutoLayout( TRUE ); + + // SET: Icon + pFrame->SetIcon( wxIcon(mondrian_xpm) ); + + // CREATE File Menu + wxMenu *fileMenu = new wxMenu; + + fileMenu->Append(wxID_EXIT, "E&xit"); + + // CREATE Help Menu + wxMenu *helpMenu = new wxMenu; + helpMenu->Append(wxID_HELP, "&About"); + + // CREATE Menu Bar + wxMenuBar* menuBar = new wxMenuBar; + + menuBar->Append(fileMenu, "&File"); + menuBar->Append(helpMenu, "&Help"); + + // ASSOCIATE: Menubar and Frame + pFrame->SetMenuBar(menuBar); + + // CREATE: toolbar + pFrame->CreateToolBar(wxNO_BORDER|wxHORIZONTAL|wxTB_FLAT, ID_TOOLBAR); + + // INITIALIZE: toolbar + InitToolbar(pFrame->GetToolBar()); + + // Text Message + pFrame->SetStatusText("Alpha $Revision: 1.1.1.1 $:Linux Version:Sword Development Team."); + + // Add Panel Info ============================================== + + // CREATE: Bible All Major Panels + pFrame->m_pBiblePanel = new wxPanel(pFrame, 0, 0, 10, 10, wxTAB_TRAVERSAL); + pFrame->m_pCommentPanel = new wxPanel(pFrame, 0, 0, 10, 10, wxTAB_TRAVERSAL); + pFrame->m_pDefPanel = new wxPanel(pFrame, 0, 0, 10, 10, wxTAB_TRAVERSAL); + pFrame->m_pHeadLine = new wxPanel(pFrame, 0, 0, 10, 10, wxRAISED_BORDER); + pFrame->m_pDefHeadLine = new wxPanel(pFrame, 0, 0, 10, 10, wxRAISED_BORDER); + + // pFrame->m_pDefPanel->SetBackgroundColour(wxColour(192, 192, 192)); + + // Set constraints for panel subwindow + wxLayoutConstraints *pLayout = new wxLayoutConstraints; + + // Set constraints for Head Line Window + + pLayout->left.SameAs ( pFrame, wxLeft ); + pLayout->right.SameAs ( pFrame, wxRight); + pLayout->top.SameAs ( pFrame, wxTop ); + pLayout->height.PercentOf ( pFrame, wxHeight, 10 ); + + pFrame-> m_pHeadLine ->SetConstraints( pLayout ); + + // Bible Constraints + pLayout = new wxLayoutConstraints; + pLayout->left.SameAs (pFrame, wxLeft); + pLayout->right.PercentOf (pFrame, wxWidth, 60); + pLayout->top.SameAs ( pFrame -> m_pHeadLine, wxBottom ); + pLayout->height.PercentOf (pFrame, wxHeight, 50); + + pFrame-> m_pBiblePanel -> SetConstraints( pLayout ); + + // Commentary Constraints + pLayout = new wxLayoutConstraints; + + pLayout->left.SameAs ( pFrame->m_pBiblePanel, wxRight ); + pLayout->right.SameAs ( pFrame, wxRight ); + pLayout->top.SameAs ( pFrame -> m_pHeadLine, wxBottom ); + pLayout->height.PercentOf ( pFrame, wxHeight, 50 ); + + pFrame-> m_pCommentPanel -> SetConstraints( pLayout ); + + // Set constraints for Definition Search + pLayout = new wxLayoutConstraints; + + pLayout->left.SameAs ( pFrame, wxLeft ); + pLayout->right.SameAs ( pFrame, wxRight); + pLayout->top.SameAs ( pFrame->m_pBiblePanel, wxBottom ); + pLayout->height.PercentOf ( pFrame, wxHeight, 10 ); + + pFrame -> m_pDefHeadLine -> SetConstraints( pLayout ); + + // Definition Window + pLayout = new wxLayoutConstraints; + pLayout->left.SameAs ( pFrame, wxLeft ); + pLayout->right.SameAs ( pFrame, wxRight); + pLayout->top.SameAs ( pFrame->m_pDefHeadLine, wxBottom ); + pLayout->bottom.SameAs ( pFrame, wxBottom); + + pFrame-> m_pDefPanel ->SetConstraints( pLayout ); + + + // ===================================================== + // Start loading modules. + // + pFrame -> m_pcHeadLine = new cHeadLine( pFrame -> m_pHeadLine ); + pFrame -> m_pcDefHeadLine = new cDefHeadLine( pFrame -> m_pDefHeadLine ); + + pFrame -> m_pcNoteBible = new cNewNote<SWModule>; + pFrame -> m_pcNoteCommentary = new cNewNote<SWModule>; + pFrame -> m_pcNoteDef = new cNewNote<SWModule>; + + ModMap::iterator it; + SectionMap::iterator sit; + ConfigEntMap::iterator eit; + char *font; + + pFrame->mainMgr = new SWMgr(); + + // -------------------------------------------- + // @todo: Need to find a better way to exit. + // + assert( (pFrame -> mainMgr -> Modules.size() > 0) && "No modules found!" ); + + for (it = pFrame->mainMgr->Modules.begin(); + it != pFrame->mainMgr->Modules.end(); it++) + { + if (!strcmp((*it).second->Type(), "Biblical Texts")) + { + font = 0; + if ((sit = pFrame->mainMgr->config->Sections.find((*it).second->Name())) != pFrame->mainMgr->config->Sections.end()) + { + if ((eit = (*sit).second.find("Font")) != (*sit).second.end()) + { + font = (char *)(*eit).second.c_str(); + } + } + + // question: why is font null? + // answer: most of the time, a unique font is not + // specified in mods.conf with 'font=' + cout << font << endl; + pFrame->CreateTextPane((*it).second, font); + } + + if (!strcmp((*it).second->Type(), "Commentaries")) + pFrame->CreateCommentPane((*it).second); + + if (!strcmp((*it).second->Type(), "Lexicons / Dictionaries")) + pFrame->CreateLDPane((*it).second); + } + + // Initialize all views with data + if ( pFrame && pFrame -> m_pcNoteBible ) + pFrame -> m_pcNoteBible -> Init( pFrame -> m_pBiblePanel ); + + if ( pFrame && pFrame -> m_pcNoteCommentary ) + pFrame -> m_pcNoteCommentary -> Init( pFrame -> m_pCommentPanel ); + + if (pFrame && pFrame -> m_pcNoteDef ) + pFrame -> m_pcNoteDef -> Init( pFrame -> m_pDefPanel ); + + // ----------------------------------------------- + // Okay, Initial verse would be a nice touch. + // + wxString sBook = "Genesis"; + wxString sStart = sBook + " 1:1"; + + if (pFrame && pFrame -> m_pcNoteBible ) + pFrame -> m_pcNoteBible -> BibleVerse( sBook, 1, 1 ); + + if (pFrame && pFrame -> m_pcNoteCommentary ) + pFrame -> m_pcNoteCommentary -> CommentaryVerse( sStart ); + + // Force a resize. This should probably be replaced by a call to a wxFrame + // function that lays out default decorations and the remaining content window. + + // pFrame->OnSize(wxSizeEvent(wxSize(-1, -1), pFrame->GetId()) ); + pFrame->Show(TRUE); + + // ================================================= + + SetTopWindow( pFrame ); + return TRUE; +} + + +/****************************************************************************** + * CreateTextPane - creates a new pane in the tabsheet for a Bible Text + * + * mod - Bible text module to associate with this panel + * font - font to use for displaying this module (default = 0) + * + * RETURN: error status + */ + +char MyFrame::CreateTextPane(SWModule *mod, char *font) +{ + // @todo: need to make use of font for displaying Greek MSS + + m_pcNoteBible->AddBook(mod); + return 0; +} + + +/****************************************************************************** + * CreateCommentPane - creates a new pane in the tabsheet for a Bible + * Commentary + * + * mod - Bible commentary module to associate with this panel + * + * RETURN: error status + */ + +char MyFrame::CreateCommentPane(SWModule *mod) +{ + m_pcNoteCommentary->AddBook(mod); + return 0; +} + + +/****************************************************************************** + * CreateLDPane - creates a new pane in the tabsheet for a Bible + * Lexicon or Dictionary + * + * mod - Bible text module to associate with this panel + * + * RETURN: error status + */ + +char MyFrame::CreateLDPane(SWModule *mod) +{ + m_pcNoteDef->AddBook(mod); + return 0; +} + + + + +bool MyApp::InitToolbar(wxToolBar* toolBar) +{ + toolBar->SetMargins(5, 5); + + // Set up toolbar + wxBitmap* toolBarBitmaps[8]; + + toolBarBitmaps[0] = new wxBitmap( new_xpm ); + toolBarBitmaps[1] = new wxBitmap( open_xpm ); + toolBarBitmaps[2] = new wxBitmap( save_xpm ); + toolBarBitmaps[3] = new wxBitmap( copy_xpm ); + toolBarBitmaps[4] = new wxBitmap( cut_xpm ); + // toolBarBitmaps[5] = new wxBitmap( paste_xpm ); + toolBarBitmaps[5] = new wxBitmap( preview_xpm ); + toolBarBitmaps[6] = new wxBitmap( print_xpm ); + toolBarBitmaps[7] = new wxBitmap( help_xpm ); + + int width = 16; + int currentX = 5; + + toolBar->AddTool(wxID_NEW, *(toolBarBitmaps[0]), wxNullBitmap, FALSE, (float)currentX, -1, (wxObject *) NULL, "New file"); + currentX += width + 5; + toolBar->AddTool(wxID_OPEN, *(toolBarBitmaps[1]), wxNullBitmap, FALSE, (float)currentX, -1, (wxObject *) NULL, "Open file"); + currentX += width + 5; + toolBar->AddTool(wxID_SAVE, *(toolBarBitmaps[2]), wxNullBitmap, FALSE, (float)currentX, -1, (wxObject *) NULL, "Save file"); + currentX += width + 5; + toolBar->AddSeparator(); + toolBar->AddTool(wxID_COPY, *(toolBarBitmaps[3]), wxNullBitmap, FALSE, (float)currentX, -1, (wxObject *) NULL, "Copy"); + currentX += width + 5; + toolBar->AddTool(wxID_CUT, *(toolBarBitmaps[4]), wxNullBitmap, FALSE, (float)currentX, -1, (wxObject *) NULL, "Cut"); + currentX += width + 5; + toolBar->AddTool(wxID_PASTE, *(toolBarBitmaps[5]), wxNullBitmap, FALSE, (float)currentX, -1, (wxObject *) NULL, "Paste"); + currentX += width + 5; + toolBar->AddSeparator(); + toolBar->AddTool(wxID_PRINT, *(toolBarBitmaps[6]), wxNullBitmap, FALSE, (float)currentX, -1, (wxObject *) NULL, "Print"); + currentX += width + 5; + toolBar->AddSeparator(); + toolBar->AddTool(wxID_HELP, *(toolBarBitmaps[7]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Help"); + + toolBar->Realize(); + + // Can delete the bitmaps since they're reference counted + int i; + for (i = 0; i < 8; i++) + delete toolBarBitmaps[i]; + + return TRUE; +} + +// wxID_HELP will be processed for the 'About' menu and the toolbar help button. + +BEGIN_EVENT_TABLE(MyFrame, wxFrame) + EVT_MENU(wxID_EXIT, MyFrame::OnQuit) + EVT_MENU(wxID_HELP, MyFrame::OnAbout) + EVT_CLOSE(MyFrame::OnCloseWindow) + EVT_TOOL_RANGE(wxID_OPEN, wxID_PASTE, MyFrame::OnToolLeftClick) + EVT_TOOL_ENTER(ID_TOOLBAR, MyFrame::OnToolEnter) + EVT_CHOICE(ID_CHOICE+1, MyFrame::OnBookUpdate) + EVT_CHOICE(ID_CHOICE+2, MyFrame::OnChapterUpdate) + EVT_BUTTON(ID_CHOICE+4, MyFrame::OnGoButton) + + // REQUIREMENT: On enter on text to search + EVT_TEXT(WID_TEXT, MyFrame::OnDefinitionSearch ) + + // End + END_EVENT_TABLE() + + // Define my frame constructor + MyFrame::MyFrame(wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos, + const wxSize& size, long style): + wxFrame(parent, id, title, pos, size, style) +{ + // m_textWindow = new wxTextCtrl(this, -1, "", wxPoint(0, 0), wxSize(-1, -1), wxTE_MULTILINE); + mainMgr = 0; +} + + +MyFrame::~MyFrame() +{ + if (mainMgr) + delete mainMgr; +} + + +void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) +{ + Close(TRUE); +} + +void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) +{ + static char * szMess = + { + "Sword Project 1.0\n" + "Linux Version\n" + "Sword Development Team\n" + "LC\n" + }; + + + (void)wxMessageBox( szMess , "About Sword"); +} + +// Define the behaviour for the frame closing +// - must delete all frames except for the main one. +void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) +{ + Destroy(); +} + +void MyFrame::OnToolLeftClick(wxCommandEvent& event) +{ + wxString str; + str.Printf("Clicked on tool %d", event.GetId()); + SetStatusText(str); +} + +void MyFrame::OnToolEnter(wxCommandEvent& event) +{ + if (event.GetSelection() > -1) + { + wxString str; + str.Printf("This is tool number %d", event.GetSelection()); + SetStatusText(str); + } + else + SetStatusText(""); +} + + +// ============================================================================ +// OnBookUpdate +// When the book changes we do 3 things. +// 1. Reset verse and chapter to 1 ( all books have 1 chapter 1 verse ). +// 2. Update the valid list of Chapters 1..ChapterMax for this book +// 3. Update the verse list for the first chapter (1..verse max for this chapter). +// +void MyFrame::OnBookUpdate( wxCommandEvent& event ) +{ + if (event.GetSelection() > -1) + { + + if (m_pcHeadLine) + { + // Get book name. + wxString sBook = m_pcHeadLine ->m_pBible->GetString( event.GetSelection() ); + + // Update chapter (automagically calls OnChapterUpdate ) + m_pcHeadLine -> UpdateChapter( sBook ); + } + } +} + +// =============================================================== +// On chapter change we need to do +// 1. Update Verse information for this chapter. +// +void MyFrame::OnChapterUpdate( wxCommandEvent& event ) +{ + if (event.GetSelection() > -1 ) + { + + if (m_pcHeadLine) + { + // Get Book and current chapter + wxString sBook = m_pcHeadLine -> m_pBible -> GetValue(); + int iChapter = event.GetSelection(); + + m_pcHeadLine -> UpdateVerse( sBook, iChapter ); + } + } +} + +void MyFrame::OnGoButton( wxCommandEvent& event ) +{ + wxString sNewVerse; + + // Check for Programmer Error + assert( m_pcHeadLine ); + assert( m_pcNoteBible ); + assert( m_pcNoteCommentary ); + + + // Insanity Check + if ( m_pcHeadLine ) + { + // Get Selection Data + wxString sBook = m_pcHeadLine ->m_pBible-> GetValue(); + int iChapter = atoi(m_pcHeadLine -> m_pChapter -> GetValue()); + int iVerse = atoi(m_pcHeadLine -> m_pVerse -> GetValue()); + + sNewVerse.Printf( "%s %d : %d", sBook.c_str(), iChapter, iVerse ); + + // Update current verse + SetStatusText( "VERSE: " + sNewVerse ); + + // Update all commentaries and bibles + m_pcNoteBible -> BibleVerse( sBook, iChapter, iVerse); + m_pcNoteCommentary -> CommentaryVerse( sNewVerse ); + } +} + + +// ---------------------------------------------------- +// OnDefinitionSearch +// Search for definition of the word in the +// text area. Use the definition NOTEBOOK object. +// +// + +void MyFrame::OnDefinitionSearch( wxCommandEvent& event ) +{ + if (m_pcDefHeadLine) + { + wxString sDefinition = wxString( "Searching for: ") + + m_pcDefHeadLine -> m_pSearchCtrl -> GetValue(); + SetStatusText( sDefinition ); + + m_pcNoteDef -> DictionaryKey( m_pcDefHeadLine -> m_pSearchCtrl -> GetValue() ); + } +} diff --git a/apps/X11/wxSword/gui_sword.h b/apps/X11/wxSword/gui_sword.h new file mode 100644 index 0000000..9cdc152 --- /dev/null +++ b/apps/X11/wxSword/gui_sword.h @@ -0,0 +1,11 @@ +// Define a new application +class MyApp: public wxApp +{ + public: + bool OnInit(void); + bool InitToolbar(wxToolBar* toolBar); +}; + + +#define ID_TOOLBAR 500 + diff --git a/apps/X11/wxSword/jptr.C b/apps/X11/wxSword/jptr.C new file mode 100644 index 0000000..bf2c2c4 --- /dev/null +++ b/apps/X11/wxSword/jptr.C @@ -0,0 +1,199 @@ +// #include "jptr.h" + + +template <class tType> + tType* clJPTR<tType>::ptr() const + { + ldebug(cout<<"MEMBER type*"<<endl, 3 ); + + assert( _pKey && "Key should always have data!" ); + return (_pKey ); + } + +template < class tType > + void clJPTR< tType >::operator=( tType* pMem ) + { + ldebug(cout<<"MEMBER operator=pMemory"<<endl,3); + + // check if new returned null. I really don't know + // if it does or throughs an exception, but just + // in case. + if (!pMem) + { + OutOfMemory(); + return; + } + + // If we where pointing to something else, + // stop point to it, and start pointing to pMEm. + if (_pKey) + remove(); + add( pMem ); + } + +template < class tType > + void clJPTR< tType >::operator=( const clJPTR& oOther ) + { + ldebug(cout<<"MEMBER operator=Java Pointer"<<endl,3); + + // Re-use other code. + *this = oOther._pKey; + } + +template < class tType > + tType* clJPTR< tType >::operator->() const + { + ldebug(cout<<"MEMBER operator ->"<<endl, 3 ); + + assert( _pKey && "Key should always have data!" ); + return (_pKey ); + } + +template < class tType > + tType* clJPTR< tType >::clone() const + { + ldebug( cout<<"MEMBER clone"<<endl,3 ); + assert( _pKey && "This shouldn't be null!" ); + + // DANGER: This assumes that class we point to has + // copy constructor! + return new tType(*_pKey); + } + +template < class tType > + void clJPTR< tType >::add( tType* pMem ) + { + ldebug(cout<<"MEMBER add"<<endl,4); + + // Add key + _pKey = pMem; + + // Add 1 to our count + _oMap[ pMem ] ++; + + ldebug(print(2),2); + } + +template < class tType > + void clJPTR< tType >::remove() + { + ldebug(cout<<"MEMBER remove"<<endl,4); + + // Decrement our reference count + _oMap[ _pKey ] --; + + // Insanity Check + assert( (_oMap[_pKey] >= 0) && "Map value is negative!" ); + + // If 0 then we have just deleted our last pointer + if ( _oMap[_pKey] == 0 ) + { + ldebug( cout<<"DELETEING MEMORY: ",2 ); + assert( _pKey && "Major bug, this should never be NULL" ); + + // Remove Memory + delete _pKey; + + // Remove Key Entry + _oMap.erase( _pKey ); + } + + // undefine key + _pKey = NULL; + + // List table of entries + ldebug( print(2), 2 ); + } + + +template< class tType > + void clJPTR< tType >::print(int level) + { + assert( (level > -1) && "Expecting a non-negative level!" ); + + clMap::const_iterator iWalk; + char cBuff[30] = { 0 }; + char cTabs[20] = { 0 }; + + // Fill fillers + memset( cBuff, '-', sizeof( cBuff ) -1 ); + memset( cTabs, '\t', min( level, (int) sizeof( cTabs ) - 1) ); + + // add a new line + cout << endl; + + // Title of table + cout << cTabs << "Ptr -> Reference Count" << endl; + cout << cTabs << cBuff << endl; + + // Elements of Table + for( iWalk = _oMap.begin(); iWalk != _oMap.end(); iWalk ++ ) + { + cout << cTabs << (*iWalk).first << " -> " << (*iWalk).second << endl; + } + + // Trailer of table + cout << cTabs << cBuff << endl; + } + + + +/* + The reason this is private is so the you the programmer are not + tempted to write something like + clJPTR< xcl > oNew; + + because this pointer will not have an object to after it's + constructor and a little too dangerous. +*/ + +template < class tType > + clJPTR< tType >::clJPTR() + { + ldebug(cout<<"DEFAULT Constructor"<<endl,4); + _pKey = NULL; + }; + +template < class tType > + clJPTR<tType>::clJPTR( tType* pMem ) + { + ldebug(cout<<"MEM Constructor"<<endl,4); + _pKey = NULL; + *this=pMem; + } + +template < class tType > + clJPTR<tType>::clJPTR(const clJPTR<tType>& oThat) + { + ldebug(cout<<"COPY Constructor"<<endl,4); + _pKey = NULL; + *this=oThat; + } + +template <class tType > + clJPTR<tType>::~clJPTR() + { + ldebug(cout<<"Destructor"<<endl,4); + if (_pKey) + remove(); + } + +/* override this method, + it is for the instance when new returns + NULL +*/ + +template <class tType> + void clJPTR<tType>::OutOfMemory() + { + ldebug(cout << "ERROR: Out of Memory" << endl, 1 ); + assert( 0 && "Out of Memory!" ); + } + + +// Wierd but true, global variable declaration for this +// class. +// +template <class tType> + clJPTR<tType>::clMap clJPTR<tType>::_oMap; + diff --git a/apps/X11/wxSword/jptr.h b/apps/X11/wxSword/jptr.h new file mode 100644 index 0000000..2a5a3be --- /dev/null +++ b/apps/X11/wxSword/jptr.h @@ -0,0 +1,95 @@ +// #ifndef __JPTR_H__ +// #define __JPTR_H__ + + + +#include <iostream> +#include <stl.h> +#include <assert.h> +#include <string.h> + +const int gDebugLevel = 0 ; + +// level 0: no Debugging +// level 1: construction of test object +// level 2: list of memory after add or delete of pointer to object +// level 3: Public api of jptr +// level 4: all api of jptr + + +#define ldebug(oRoutine,level) {if (level <= gDebugLevel) \ + {for(int i = 0; i < max(level,1); i++ ) \ + cout << "\t"; \ + cout<<"D"<<level<<": "; oRoutine; }} + + +// =============================================================== +// class template clJPTR +// purpose: simulate symantics of Java Pointers. +// benefits: +// 1. Don't need to worry about freeing the memory. +// 2. Don't need to design ownership models. +// 3. Generic. +// 4. Easy to use, almost fool proof. +// +// =============================================================== +template <class tType> + class clJPTR + { + private: // declarations + // The following is declaration of a global multimap + // for an instanciation of this template class. + // + class clMap : + public map< tType*, int, less< tType* > > + { }; + + + private: // variables + static clMap _oMap; + tType* _pKey; + + + public: // public member functions + void operator=( tType* pMem ); + void operator=( const clJPTR& oOther ); + tType* operator->() const; + tType* clone() const; + tType* ptr() const; + + + private: // private helper functions + void add( tType* pMem ); + void remove(); + void print(int level); + +/* + The reason this is private is so the you the programmer are not + tempted to write something like + clJPTR< xcl > oNew; + + because this pointer will not have an object to after it's + constructor and a little too dangerous. +*/ + + public: // Constructors + clJPTR(); + + clJPTR( tType* pMem ); + clJPTR(const clJPTR<tType>& oThat); + + public: // Virtual Methods! + + virtual ~clJPTR(); + + /* override this method, + it is for the instance when new returns + NULL + */ + virtual void OutOfMemory(); + +}; + +#include "jptr.C" + +// #endif // JPTR diff --git a/apps/X11/wxSword/mondrian.xpm b/apps/X11/wxSword/mondrian.xpm new file mode 100644 index 0000000..409f27a --- /dev/null +++ b/apps/X11/wxSword/mondrian.xpm @@ -0,0 +1,44 @@ +/* XPM */ +static char *mondrian_xpm[] = { +/* columns rows colors chars-per-pixel */ +"32 32 6 1", +" c Black", +". c Blue", +"X c #00bf00", +"o c Red", +"O c Yellow", +"+ c Gray100", +/* pixels */ +" ", +" oooooo +++++++++++++++++++++++ ", +" oooooo +++++++++++++++++++++++ ", +" oooooo +++++++++++++++++++++++ ", +" oooooo +++++++++++++++++++++++ ", +" oooooo +++++++++++++++++++++++ ", +" oooooo +++++++++++++++++++++++ ", +" oooooo +++++++++++++++++++++++ ", +" ", +" ++++++ ++++++++++++++++++ .... ", +" ++++++ ++++++++++++++++++ .... ", +" ++++++ ++++++++++++++++++ .... ", +" ++++++ ++++++++++++++++++ .... ", +" ++++++ ++++++++++++++++++ .... ", +" ++++++ ++++++++++++++++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++++++++++++++++ ++++ ", +" ++++++ ++++ ", +" ++++++ OOOOOOOOOOOO XXXXX ++++ ", +" ++++++ OOOOOOOOOOOO XXXXX ++++ ", +" ++++++ OOOOOOOOOOOO XXXXX ++++ ", +" ++++++ OOOOOOOOOOOO XXXXX ++++ ", +" ++++++ OOOOOOOOOOOO XXXXX ++++ ", +" ++++++ OOOOOOOOOOOO XXXXX ++++ ", +" " +}; |