Virtual U.org
Get Personal Training on VU Today
    
Top shadow
 
 register/help
User Name:

Password:

Otxtlist.cpp Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Otxtlist.cpp

Go to the documentation of this file.
00001 //Filename    : OTXTLIST.CPP
00002 //Description : Object text list
00003 // owner                        : chwg 1015
00004 #include <OVGA.H>
00005 #include <OSYS.H>
00006 #include <OFONT.H>
00007 #include <OINFO.H>
00008 #include <OMOUSE.H>
00009 #include <OVBROW98.H>
00010 #include <OSCROLL.H>
00011 #include <OTXTLIST.H>
00012 #include <OIFACE.H>
00013 
00014 //-------- Define macro constant ----------//
00015 
00016 #define SCROLL_BAR_WIDTH 15
00017 
00018 #define TEXT_LINE_SPACE   6
00019 #define TEXT_MARGIN       20
00020 
00021 //--------- Define static varaibles --------//
00022 
00023 static ScrollBar scroll_bar;
00024 static TxtList*  cur_txt_list_ptr;                // for static function
00025 static VBrowse98 topic_browse;
00026 // ##### begin Gilbert 19/04/2001 ###### //
00027 static short * txtlist_refresh_bitmap = NULL;
00028 // ##### end Gilbert 19/04/2001 ###### //
00029 static void disp_topic_rec(int,int,int,int);
00030 static void disp_idx_topic_rec(int,int,int,int);
00031 
00032 //--------- Begin of function TxtList::TxtList ---------//
00033 
00034 TxtList::TxtList() {
00035     init_flag      = 0;
00036     init_pict_flag = 0;
00037     init_list_flag = 0;
00038     history_pos = 0;
00039     can_back=0;
00040     top_line=1;
00041     memset( history_array, 0, sizeof(history_array[0]) * HISTORY_SIZE );
00042 }
00043 
00044 //----------- End of function TxtList::TxtList ---------//
00045 
00046 //---------- Begin of function TxtList::init -------//
00054 void TxtList::init(int x1, int y1, int x2, int y2, char* resTxtName) {
00055     text_x1 = x1;
00056     text_y1 = y1;
00057     text_x2 = x2-SCROLL_BAR_WIDTH-4;                // space + scroll bar width
00058     text_y2 = y2;
00059 
00060     scroll_x1 = x2-SCROLL_BAR_WIDTH+1;
00061     scroll_y1 = y1;
00062     scroll_x2 = x2;
00063     scroll_y2 = y2;
00064 
00065     res_txt.init( resTxtName, 0 );                  // 0-don't always open the file, only open it during reading, save file handle
00066 
00067     if(topic_id < 1)
00068         topic_id=1;                                   // default topic id.
00069 
00070     init_flag = 1;
00071 }
00072 
00073 //---------- End of function TxtList::init -------//
00074 
00075 //-------- Begin of function TxtList::deinit -------//
00077 void TxtList::deinit() {
00078     res_txt .deinit();
00079 
00080     res_pict.deinit();
00081     if(txtlist_refresh_bitmap)
00082         mem_del(txtlist_refresh_bitmap);
00083     txtlist_refresh_bitmap=NULL;
00084 }
00085 
00086 //---------- End of function TxtList::deinit -------//
00087 
00088 //---------- Begin of function TxtList::init_pict -------//
00094 void TxtList::init_pict(int x1, int y1, int x2, int y2, char* resPictName) {
00095     pict_x1 = x1;
00096     pict_y1 = y1;
00097     pict_x2 = x2;
00098     pict_y2 = y2;
00099 
00100     res_pict.init( resPictName, 0 );
00101 
00102     init_pict_flag = 1;
00103 }
00104 
00105 //---------- End of function TxtList::init_pict -------//
00106 
00107 //---------- Begin of function TxtList::init_list -------//
00111 void TxtList::init_list(int x1, int y1, int x2, int y2) {
00112     list_x1 = x1;
00113     list_y1 = y1;
00114     list_x2 = x2;
00115     list_y2 = y2;
00116 
00117     init_list_flag = 1;
00118     top_line=1;
00119 }
00120 
00121 //---------- End of function TxtList::init_list -------//
00122 
00123 //------- Begin of function TxtList::disp -------//
00129 void TxtList::disp(int refreshFlag, int topicId) {
00130     vga.use_back();
00131     err_when( !init_flag );
00132 
00133     //-------- display a new topic ----------//
00134 
00135     char* textPtr;
00136 
00137     if( topicId )
00138         topic_id = topicId;
00139 
00140     //------------ paint panel --------------//
00141     if(init_list_flag) {
00142         if( refreshFlag==INFO_REPAINT ) {
00143             user_interface.brighten( list_x1, list_y1, list_x2, list_y2 );
00144             user_interface.rect( list_x1, list_y1, list_x2, list_y2 );
00145             //                  if( init_pict_flag )
00146             //                          vga.active_buf->d3_panel_down( pict_x1, pict_y1, pict_x2, pict_y2, 2, 0 );
00147             cur_txt_list_ptr = this;
00148             // for static rec display function's reference
00149             topic_browse.init( list_x1, list_y1, list_x2, list_y2,
00150                                0, 20, res_txt.rec_count, disp_topic_rec );
00151             topic_browse.open(topic_id);
00152         }
00153         //              topic_browse.update();
00154     }
00155 
00156     if(!init_list_flag) {
00157         if( refreshFlag==INFO_REPAINT ) {
00158             user_interface.rect( text_x1, text_y1, text_x2, text_y2 );
00159             user_interface.brighten( text_x1, text_y1, text_x2, text_y2 );
00160 
00161             if( init_pict_flag )
00162                 vga.active_buf->d3_panel_down( pict_x1, pict_y1, pict_x2, pict_y2, 2, 0 );
00163             cur_txt_list_ptr = this;                    // for static rec display function's reference
00164 
00165             txtlist_refresh_bitmap=vga_back.save_area(
00166                 text_x1,text_y1,text_x2,text_y2,
00167                 txtlist_refresh_bitmap);
00168         }
00169         //------------ retrieve topic ------------//
00170         vga_back.rest_area(txtlist_refresh_bitmap,0,1);
00171 
00172         if(topicId && refreshFlag==INFO_REPAINT ) {   // topicId can be NULL, while INFO_REPAINT
00173             //                  top_line=1;
00174             textPtr = res_txt.get_body(topic_id);
00175 
00176             //-------- count the no. of lines of the text --------//
00177 
00178             int dispLines;                              // no. of lines can be displayed on the area
00179             int totalLines;                             // total no. of lines of the text
00180 
00181             font_letter.count_line( text_x1+TEXT_MARGIN, text_y1+TEXT_MARGIN,
00182                                     text_x2-TEXT_MARGIN+2, text_y2-TEXT_MARGIN,
00183                                     textPtr, TEXT_LINE_SPACE, dispLines, totalLines );
00184 
00185             //-------- display scroll bar ------//
00186 
00187             scroll_bar.init( 1, scroll_x1, scroll_y1, scroll_x2, scroll_y2,
00188                              dispLines, dispLines, totalLines );
00189 
00190             scroll_bar.paint();
00191             scroll_bar.refresh(top_line,1);
00192         }
00193         else {                                        // redisplay current topic, only scroll to a different part of the text
00194             textPtr = res_txt.get_body(topic_id);
00195         }
00196         font_letter.put_paragraph( text_x1+TEXT_MARGIN, text_y1+TEXT_MARGIN,
00197                                    text_x2-TEXT_MARGIN+2, text_y2-TEXT_MARGIN,
00198                                    textPtr, TEXT_LINE_SPACE, top_line );
00199 
00200         if( init_pict_flag ) {
00201             char* pictName = res_txt.get_pict_name(topic_id);
00202 
00203             if( pictName[0] ) {
00204                 char* pictPtr = res_pict.read(pictName);
00205 
00206                 if( pictPtr )
00207                     vga.active_buf->put_bitmap( pict_x1+2, pict_y1+2, pictPtr );
00208             }
00209         }
00210 
00211         vga.blt_buf( text_x1, text_y1, text_x2, text_y2 );
00212     }
00213 
00214     //--------- display text body ----------//
00215 }
00216 
00217 //-------- End of function TxtList::disp -------//
00218 
00219 //-------- Begin of function TxtList::add_history -----------//
00223 void TxtList::add_history(int topicId) {
00224     /*
00225       can_back=(history_array[history_pos]>0);
00226       if( ++history_pos >= HISTORY_SIZE )
00227       history_pos = 0;
00228       history_array[history_pos] = topicId;
00229     */
00230 
00231     int next_pos=((history_pos+1)>=HISTORY_SIZE)?0:history_pos+1;
00232     int prev_pos=((history_pos-1)<0)?HISTORY_SIZE-1:history_pos-1;
00233 
00234     // do nothing if same history idx is added.
00235     // chwg ##1215
00236     if(history_array[prev_pos]==topicId)
00237         return;
00238 
00239     if(history_array[history_pos]!=0) {
00240         history_array[next_pos]=0;
00241     }
00242 
00243     history_array[history_pos] = topicId;
00244     can_back=(history_array[(((prev_pos)<0)?HISTORY_SIZE-1:prev_pos)]>0);;
00245     history_pos = next_pos;
00246 }
00247 
00248 //----------- End of function TxtList::add_history -----------//
00249 
00250 //-------- Begin of function TxtList::back_history -----------//
00254 void TxtList::back_history() {
00255     /*
00256       history_array[history_pos]=0;     // the history just added is useless
00257       if((history_pos-1) < 0 )
00258       history_pos = HISTORY_SIZE;
00259 
00260       int topicId = history_array[--history_pos];
00261 
00262       if( topicId>0 )        // if topicId==0, means no history
00263       {
00264       history_array[history_pos] = 0;
00265       can_back=(history_array[(((history_pos-1)<0)?HISTORY_SIZE-1:history_pos-1)]>0);
00266       disp( INFO_UPDATE, topicId );
00267 
00268       if( init_list_flag )
00269       topic_browse.refresh( topicId );
00270       }
00271     */
00272     int prev_pos=history_pos;
00273 
00274     do {
00275         prev_pos--;
00276         prev_pos=(prev_pos<0)?HISTORY_SIZE-1:prev_pos;
00277     }
00278     while(history_array[prev_pos]==topic_id && history_array[prev_pos]!=0);
00279 
00280     int topicId = history_array[prev_pos];
00281     if( topicId>0 ) {                               // if topicId==0, means no history
00282         history_array[prev_pos] = 0;
00283         history_pos = prev_pos;
00284         disp( INFO_UPDATE, topicId );
00285         if( init_list_flag )
00286             topic_browse.refresh( topicId );
00287         can_back=(history_array[(((prev_pos-1)<0)?HISTORY_SIZE-1:prev_pos-1)]>0);
00288     }
00289 }
00290 
00291 //----------- End of function TxtList::back_history -----------//
00292 
00293 //------- Begin of function TxtList::detect -------//
00298 int TxtList::detect() {
00299     int rc;
00300 
00301     //------- detect topic list list ----------//
00302     //  vga.use_front();
00303     // select new topic
00304     if( init_list_flag && (rc=topic_browse.detect()) > 0 ) {
00305         double_clicked=topic_browse.double_click;
00306         topic_id=rc;
00307         sys.redraw_all_flag=1;
00308         //              disp(INFO_UPDATE, rc);
00309         return 1;
00310     }
00311 
00312     if(!init_list_flag) {
00313         if( (rc=scroll_bar.detect()) > 0 ) {
00314             //-------- detect text scroll bar ----------//
00315             top_line = rc;
00316             sys.redraw_all_flag=1;
00317             disp(INFO_UPDATE);
00318             return 1;
00319             //------- detect on text body ---------//
00320         }
00321         if( detect_text() )
00322             return 1;
00323     }
00324     return 0;
00325 
00326 }
00327 
00328 //------- Begin of function TxtList::detect_text -------//
00333 int TxtList::detect_text() {
00334     //------- if mouse pressed on text area ------//
00335     //-- can pressed on hyper-texted field or just fast scrolling --//
00336 
00337     if( !mouse.single_click( text_x1, text_y1, text_x2, text_y2 ) )
00338         return 0;
00339 
00340     //---- detect hyper-texted field ------//
00341 
00342     int         i, topicId;
00343     char        saveChar;
00344     HyperField* hyperField = font_letter.hyper_field_array;
00345 
00346     for( i=0 ; i<font_letter.hyper_field_count ; i++, hyperField++ ) {
00347         if( mouse.click_x() >= hyperField->x1 &&
00348             mouse.click_x() <= hyperField->x2 &&
00349             mouse.click_y() >= hyperField->y1 &&
00350             mouse.click_y() <= hyperField->y2 ) {
00351             err_when( hyperField->text_len > TxtIndex::TITLE_LEN );
00352 
00353             saveChar = hyperField->text_ptr[hyperField->text_len];
00354             hyperField->text_ptr[hyperField->text_len] = NULL;
00355 
00356             topicId = res_txt.locate_topic(hyperField->text_ptr);
00357 
00358             hyperField->text_ptr[hyperField->text_len] = saveChar;
00359 
00360             if( topicId ) {
00361                 add_history(topic_id);                    // add current topic id to the history
00362 
00363                 disp(INFO_UPDATE, topicId);
00364                 sys.redraw_all_flag=1;
00365                 if( init_list_flag )
00366                     topic_browse.refresh( topicId );
00367 
00368                 return 1;
00369             }
00370         }
00371     }
00372 
00373     //------ detect fast scrolling --------//
00374 
00375     if( mouse.click_y() < text_y1 + (text_y2-text_y1) / 2 )
00376         top_line = scroll_bar.page_up(1);             // page up, 1 = skip less one line, so when scrolling text, want the last line of previous page be the first line of current page, then pass 1 as skipLess
00377     else
00378         top_line = scroll_bar.page_down(1);           // page down
00379 
00380     disp(INFO_UPDATE);
00381 
00382     return 1;
00383 }
00384 
00385 //-------- Begin of function TxtList::detect_text -------//
00386 
00387 //-------- Begin of static function disp_topic_rec -----------//
00388 //
00389 static void disp_topic_rec(int recNo, int x, int y, int refreshFlag) {
00390     if( refreshFlag == INFO_REPAINT )
00391         font_letter.put( x+10, y, cur_txt_list_ptr->res_txt.get_title(recNo) );
00392 }
00393 
00394 //----------- End of static function disp_topic_rec -----------//

Generated on Fri Aug 23 01:38:32 2002 for VirtualU by doxygen1.2.17