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

Password:

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

Ovbrow98.cpp

Go to the documentation of this file.
00001 //Filename    : OVBROW98.CPP
00002 //Description : Object Visual Browse
00003 //owner :chw1021
00004 
00005 #include <ALL.H>
00006 #include <OINFO.H>
00007 #include <OMOUSE.H>
00008 #include <OVGA.H>
00009 #include <OSYS.H>
00010 #include <OFONT.H>
00011 #include <OPOWER.H>
00012 #include <OVBROW98.H>
00013 #include <OIFACE.H>
00014 
00015 //---------- Define static class variables -------//
00016 
00017 char    VBrowse98::press_record=0;                // for detecting pulling records upwards and downloads
00018 VBrowse98* VBrowse98::press_vbrowse_ptr;
00019 
00020 VBrowse98::VBrowse98() {
00021     init_flag=0;
00022     refresh_bitmap=NULL;
00023 }
00024 
00025 VBrowse98::~VBrowse98() {
00026     deinit();
00027 }
00028 
00029 void VBrowse98::deinit() {
00030     if(refresh_bitmap) {
00031         mem_del(refresh_bitmap);
00032         refresh_bitmap=NULL;
00033     }
00034 }
00035 
00036 //--------- Begin of function VBrowse98::init --------//
00055 void VBrowse98::init(int inX1, int inY1, int inX2, int inY2,
00056                      int recWidth, int recHeight,
00057                      int totalRec, BrowDispFP dispFunc,
00058                      BrowDetectFP detectFunc,
00059                      int dispFrame, int minInterSpace) {
00060     x1 = inX1;
00061     y1 = inY1;
00062     x2 = inX2;
00063     y2 = inY2;
00064 
00065     ix1 = x1+6;                                     // content area coordination
00066     iy1 = y1+6;
00067     ix2 = x2-6-SCROLL_BAR_WIDTH;
00068     iy2 = y2-6;
00069 
00070     //---------------------------------------------//
00071 
00072     if( recWidth <= 0 )
00073         rec_width = ix2-ix1+1;
00074     else
00075         rec_width = recWidth;
00076 
00077     rec_height = recHeight;
00078 
00079     disp_rec_func   = dispFunc;
00080     disp_frame      = dispFrame;
00081 
00082     x_max_rec = (ix2-ix1+minInterSpace+1) / (rec_width +minInterSpace);
00083     y_max_rec = (iy2-iy1+minInterSpace+1) / (rec_height+minInterSpace);
00084 
00085     detect_pull_flag = 1;                           // whether detect pulling records or not
00086 
00087     err_if( x_max_rec <= 0 || y_max_rec <= 0 )
00088         err_now( "VBrowse98::init() error : disp_max_rec <= 0" );
00089 
00090     //--- calculate the suitable inter-record space -------//
00091 
00092     if( x_max_rec > 1 )
00093         rec_x_space = minInterSpace + (ix2-ix1+minInterSpace+1) % (rec_width +minInterSpace)/(x_max_rec-1);
00094     else
00095         rec_x_space = minInterSpace;
00096 
00097     if( y_max_rec > 1 )
00098         rec_y_space = minInterSpace + (iy2-iy1+minInterSpace+1) % (rec_height+minInterSpace)/(y_max_rec-1);
00099     else
00100         rec_y_space = minInterSpace;
00101 
00102     init_var(totalRec,-1);
00103 
00104     init_flag = 1;
00105 
00106     //------- paint the list box --------//
00107 
00108     paint();
00109 }
00110 
00111 //---------- End of function VBrowse98::init ---------//
00112 
00113 //---------- Begin of function VBrowse98::init_var -------//
00117 void VBrowse98::init_var(int totalRec, int recNo) {
00118     if( totalRec >= 0 ) {                           // if totalRec == -1, then no change
00119         none_record = totalRec==0;
00120 
00121         if( totalRec == 0 )
00122             total_rec_num = 1;                          // prevent divided by zero if it is a closed box
00123         else
00124             total_rec_num = totalRec;
00125     }
00126 
00127     //--- maximum records can be display on a browse box ---//
00128 
00129     disp_max_rec = x_max_rec * y_max_rec;
00130 
00131     if( disp_max_rec > total_rec_num )
00132         disp_max_rec = total_rec_num;
00133 
00134     //------- changable variables --------//
00135 
00136     rec_no = recNo;
00137 
00138     if(((recNo<top_rec_no)&&(recNo>top_rec_no+disp_max_rec-1))
00139        ||(init_flag==0)) {
00140         // Change top_rec_no
00141         top_rec_no = recNo - disp_max_rec/2;
00142         top_rec_no = max(1,top_rec_no);
00143         // if there is an empty area at the lower part of the browser
00144         if( top_rec_no+disp_max_rec-1 > total_rec_num ) {
00145             top_rec_no = total_rec_num-disp_max_rec+1;
00146             top_rec_no = max(top_rec_no,1);
00147         }
00148     }
00149 
00150     //------------- initialize scroll bar ---------------//
00151     //
00152     // If display frame      , then scroll unit is 1 record
00153     // If don't display frame, then the scroll unit is disp_max_rec record
00154     //
00155     //---------------------------------------------------//
00156 
00157     scroll_bar.init( 1, x2-SCROLL_BAR_WIDTH-7, y1+4, x2-7, y2-4, disp_max_rec,
00158                      (disp_frame && x_max_rec==1 ? 1 : disp_max_rec),// only use record as scroller unit when it's a vertical browser with frame
00159                      total_rec_num, 1 );
00160 }
00161 
00162 //----------- End of function VBrowse98::init_var ----------//
00163 
00164 //--------- Begin of function VBrowse98::open ---------//
00176 void VBrowse98::open(int recNo, int newTotalRec) {
00177     state = 1;                                      // state = OPENED
00178 
00179     if( newTotalRec >= 0 )
00180         total_rec_num = newTotalRec;
00181 
00182     if( recNo > 0 )                                 // keep current record no.
00183         rec_no = recNo;
00184 
00185     if( rec_no<1 )
00186         rec_no=1;
00187 
00188     if( rec_no > total_rec_num )
00189         rec_no = total_rec_num;
00190 
00191     //------- set the top recno ----------//
00192 
00193     if( !newTotalRec ) {
00194         top_rec_no = rec_no - disp_max_rec/2;
00195         top_rec_no = max(1,top_rec_no);
00196     }
00197     else {                                          // keep the original top_rec_no
00198         if( rec_no > top_rec_no+disp_max_rec-1 )
00199             top_rec_no = rec_no-disp_max_rec+1;
00200 
00201         if( rec_no < top_rec_no )
00202             top_rec_no = rec_no;
00203     }
00204 
00205     // if there is an empty area at the lower part of the browser
00206     if( top_rec_no+disp_max_rec-1 > total_rec_num ) {
00207         top_rec_no = total_rec_num-disp_max_rec+1;
00208         top_rec_no = max(top_rec_no,1);
00209     }
00210 
00211     //------- display all records -------//
00212 
00213     disp_all();
00214 }
00215 
00216 //--------- End of function VBrowse98::open ---------//
00217 
00218 //--------- Begin of function VBrowse98::close ---------//
00222 void VBrowse98::close() {
00223     state = 0;                                      // state = CLOSED
00224 
00225     //-------- paint the closed outlook of the list box -------//
00226 
00227     // the place a large block on the list content box
00228     Vga::active_buf->d3_panel_up( x1+1, y1+1, x2-SCROLL_BAR_WIDTH-3, y2-1  );
00229 }
00230 
00231 //--------- End of function VBrowse98::close ---------//
00232 
00233 //--------- Begin of function VBrowse98::paint ---------//
00237 void VBrowse98::paint() {
00238     vga.use_back();
00239     refresh_bitmap=vga_back.save_area( x1, y1, x2-SCROLL_BAR_WIDTH-3, y2,refresh_bitmap);
00240     scroll_bar.paint();
00241     sys.yield();                                    // chwg032799
00242 }
00243 
00244 //--------- End of function VBrowse98::paint ---------//
00245 
00246 //------- Begin of function VBrowse98::refresh ---------//
00255 void VBrowse98::refresh(int newRecNo, int newTotalRec) {
00256     disp_one(rec_no,CLEAR_HIGH);
00257 
00258     if( newRecNo>=0 || newTotalRec>=0 ) {           // if current recno and total recno has no change, don't do the recalculation
00259         if( newRecNo >= 1 )
00260             rec_no = newRecNo;
00261 
00262         if( newTotalRec != -1 && rec_no > newTotalRec )
00263             rec_no = newTotalRec;
00264 
00265         if( rec_no==0 && newTotalRec>0 )              // if originally rec_no==0, and total_rec is also 0, when the new total_rec is > 0, the rec_no should also be adjusted
00266             rec_no=1;
00267 
00268         init_var(newTotalRec,rec_no);
00269     }
00270 
00271     disp_all();
00272 }
00273 
00274 //---------- End of function VBrowse98::refresh ----------//
00275 
00276 //------- Begin of function VBrowse98::update ---------//
00280 void VBrowse98::update() {
00281     int recNo, x, y;
00282 
00283     if( none_record )
00284         return;
00285 
00286     for( recNo=top_rec_no ; recNo<=total_rec_num && recNo<top_rec_no+disp_max_rec ; recNo++ ) {
00287         y = iy1 + (recNo-top_rec_no)/x_max_rec * (rec_height+rec_y_space);
00288         x = ix1 + (recNo-top_rec_no)%x_max_rec * (rec_width+rec_x_space);
00289 
00290         disp_rec( recNo, x, y, INFO_UPDATE );         // call user defined function
00291     }
00292 }
00293 
00294 //---------- End of function VBrowse98::update ----------//
00295 
00296 //--------- Begin of function VBrowse98::detect ------//
00303 int VBrowse98::detect() {
00304     int newRecNo=0, rc;
00305 
00306     double_click = 0;
00307 
00308     if( state == 0 || none_record )                 // closed
00309         return 0;
00310 
00311     //-- Detect pulling on record if the browser is with frame --//
00312 
00313     // only pull when the vbrowser is vertical, horizontal is technically possible, but not used practically
00314     if( detect_pull_flag && disp_frame && x_max_rec==1 ) {
00315         if( detect_pull() )
00316             return rec_no;
00317     }
00318 
00319     //--------- Detect pressing on record if disp_frame is 1 ---------//
00320 
00321     if( disp_frame ) {
00322         // #### begin Gilbert 23/04/2001 ######//
00323         // if( mouse.press_area(ix1, iy1, ix2, iy2) )
00324         if( mouse.any_click(ix1, iy1, ix2, iy2) ) {
00325             // #### end Gilbert 23/04/2001 ######//
00326             newRecNo = top_rec_no +
00327                 (mouse.cur_y-iy1) / (rec_height+rec_y_space) * x_max_rec +
00328                 (mouse.cur_x-ix1) / (rec_width +rec_x_space);
00329 
00330             if( detect_pull_flag )
00331                 press_record = 1;
00332 
00333             press_vbrowse_ptr = this;
00334         }
00335 
00336         // if it is not in the empty browser area
00337         if( newRecNo>=top_rec_no && newRecNo<=top_rec_no-1+disp_max_rec ) {
00338             if( mouse.click_count()==2 )                // double clicked
00339                 double_click = 1;
00340 
00341             if( newRecNo != rec_no ) {                  // if user point to a new record
00342                 disp_one(rec_no, CLEAR_HIGH);
00343                 disp_one(newRecNo , DISP_HIGH );          // 2 means display record content only
00344 
00345                 rec_no = newRecNo;
00346                 return rec_no;
00347             }
00348 
00349             if( double_click )                          // even if current record no. doesn't change, return recno if double clicked
00350                 return rec_no;
00351         }
00352     }
00353     else {                                          //---- when disp_frame is 0, fast scrolling is enabled ----//
00354         if( mouse.any_click( ix1, iy1, ix2, iy2 ) ) {
00355             int newTopRec;
00356 
00357             if( mouse.click_y() < iy1+ ( (iy2-iy1) >> 1 ) )
00358                 newTopRec = scroll_bar.page_up();         // page up
00359             else
00360                 newTopRec = scroll_bar.page_down();       // page down
00361 
00362             if( top_rec_no != newTopRec ) {
00363                 double_click = mouse.click_count()==2;    // double clicked
00364 
00365                 rec_no = top_rec_no = newTopRec;
00366                 disp_all();
00367 
00368                 return rec_no;
00369             }
00370         }
00371     }
00372 
00373     //------- detect for pressing on scroll bar -----//
00374 
00375     if( ( rc=scroll_bar.detect() ) > 0 ) {
00376         disp_one(rec_no,CLEAR_HIGH);
00377         rec_no = rc;
00378 
00379         if( disp_frame && x_max_rec==1 ) {            // only use record as scroller unit when it's a vertical browser with frame, refer to scroll_bar.init() in VBrowse98::init_var()
00380             if( rec_no < top_rec_no ) {
00381                 top_rec_no = rec_no;
00382                 disp_all();
00383             }
00384 
00385             else if( rec_no >= top_rec_no + disp_max_rec ) {
00386                 top_rec_no = rec_no - disp_max_rec + 1;
00387                 if( top_rec_no < 1 )
00388                     top_rec_no = 1;
00389                 disp_all();
00390             }
00391 
00392             else
00393                 disp_one(rec_no,DISP_HIGH);
00394         }
00395         else {
00396             top_rec_no = rc;
00397             disp_all();
00398         }
00399 
00400         return rec_no;
00401     }
00402 
00403     return 0;
00404 }
00405 
00406 //----------- End of function VBrowse98::detect -------//
00407 
00408 //---------- Begin of function VBrowse98::detect_pull ---------//
00412 int VBrowse98::detect_pull() {
00413     if( press_record ) {                            // test whether user continue pressing it
00414         press_record = mouse.left_press;
00415 
00416         if( press_record )
00417             press_vbrowse_ptr = this;
00418     }
00419 
00420     if( !( mouse.left_press || mouse.click_count() ) )
00421         return 0;
00422 
00423     if( !press_record )
00424         return 0;
00425 
00426     //--------- detect for pulling record upwards ---------//
00427 
00428     if( ( x_max_rec==1 && mouse.press_area( x1, 0 , x2, y1 ) ) ||
00429         ( y_max_rec==1 && mouse.press_area(  0, y1, x1, y2 ) ) ) {
00430         if( rec_no > 1 ) {
00431             disp_one(rec_no, CLEAR_HIGH);
00432 
00433             rec_no--;
00434             if( rec_no < top_rec_no )
00435                 top_rec_no--;
00436 
00437             disp_all();
00438             return 1;
00439         }
00440     }
00441 
00442     //---- detect for pressing down button or pulling record downwards ---//
00443 
00444     if( ( x_max_rec==1 && mouse.press_area( x1, y2, x2, VGA_HEIGHT-1 ) ) ||
00445         ( y_max_rec==1 && mouse.press_area( x2, y1, VGA_WIDTH-1, y2  ) ) ) {
00446         if( rec_no < total_rec_num ) {
00447             disp_one(rec_no, CLEAR_HIGH);
00448 
00449             rec_no++;
00450             if( rec_no >= top_rec_no+disp_max_rec )
00451                 top_rec_no++;
00452 
00453             disp_all();
00454             return 1;
00455         }
00456     }
00457 
00458     return 0;
00459 }
00460 
00461 //---------- End of function VBrowse98::detect_pull ---------//
00462 
00463 //--------- Begin of function VBrowse98::detect_right ------//
00470 int VBrowse98::detect_right() {
00471     if( state == 0 || none_record )                 // closed
00472         return 0;
00473 
00474     // 1-right mouse button
00475     if( mouse.single_click( ix1, iy1, ix2, iy2, 1 ) ) {
00476         int recNo;
00477 
00478         recNo = top_rec_no +
00479             (mouse.click_y(1)-iy1) / (rec_height+rec_y_space) * x_max_rec +
00480             (mouse.click_x(1)-ix1) / (rec_width +rec_x_space);
00481 
00482         if( recNo <= top_rec_no-1+disp_max_rec ) {
00483             disp_one(rec_no,CLEAR_HIGH);
00484             disp_one(recNo, DISP_HIGH);                 // 2 means display record content only
00485 
00486             rec_no = recNo;
00487             return recNo;
00488         }
00489     }
00490 
00491     return 0;
00492 }
00493 
00494 //----------- End of function VBrowse98::detect_right -------//
00495 
00496 //-------- Begin of function VBrowse98::disp_all ----------//
00500 void VBrowse98::disp_all() {
00501     int recNo;
00502 
00503     int scrollRecno = (disp_frame && x_max_rec==1) ? rec_no : top_rec_no;
00504 
00505     scroll_bar.refresh( scrollRecno, 1, disp_max_rec,
00506                         (disp_frame && x_max_rec==1 ? 1 : disp_max_rec),
00507                         total_rec_num );
00508 
00509     for( recNo=top_rec_no ; recNo<=total_rec_num && recNo<top_rec_no+disp_max_rec ; recNo++ ) {
00510         disp_one( recNo, DISP_REC );
00511 
00512         if( recNo == rec_no )
00513             disp_one( recNo, DISP_HIGH );
00514     }
00515 }
00516 
00517 //--------- End of function VBrowse98::disp_all ----------//
00518 
00519 //-------- Begin of function VBrowse98::disp_one ----------//
00526 void VBrowse98::disp_one(int recNo, int dispType) {
00527     if( none_record )
00528         return;
00529 
00530     int x,y;
00531 
00532     y = iy1 + (recNo-top_rec_no)/x_max_rec * (rec_height+rec_y_space);
00533     x = ix1 + (recNo-top_rec_no)%x_max_rec * (rec_width+rec_x_space);
00534 
00535     //---- put a outline rect around the record if it is highlight ---//
00536 
00537     if( disp_frame && dispType == CLEAR_HIGH ) {
00538         vga_back.rest_area_with_clipping(refresh_bitmap,
00539                                          x-2-x1,y-2-y1,x+rec_width-3-x1, y+rec_height+1-y1,
00540                                          0,1);
00541         disp_rec( recNo, x, y, INFO_REPAINT );
00542         vga.blt_buf(x-2,y-2,x+rec_width-3,y+rec_height-1);
00543     }
00544 
00545     if( dispType == DISP_REC ) {
00546         disp_rec( recNo, x, y, INFO_REPAINT );        // call user defined function
00547         // ##chwg0628
00548         vga.blt_buf(x-2,y-2,x+rec_width-3,y+rec_height-1);
00549     }
00550     if( disp_frame && dispType == DISP_HIGH ) {
00551         vga_back.rest_area_with_clipping(refresh_bitmap,
00552                                          x-2-x1,y-2-y1,x+rec_width-3-x1, y+rec_height+1-y1,
00553                                          0,1);
00554         disp_rec( recNo, x, y, INFO_REPAINT );
00555         user_interface.darken(x-2,y+rec_height-2,x+rec_width-7,y+rec_height-1);
00556         user_interface.darken(x+rec_width-9,y-2,x+rec_width-7,y+rec_height-3);
00557         user_interface.darken(x-2,y-2,x+rec_width-7,y+rec_height-1);
00558         vga.blt_buf(x-2,y-2,x+rec_width-7,y+rec_height-1);
00559 
00560         int scrollRecno = (disp_frame && x_max_rec==1) ? recNo : top_rec_no;
00561 
00562         scroll_bar.refresh( scrollRecno, 0, disp_max_rec,
00563                             (disp_frame && x_max_rec==1 ? 1 : disp_max_rec),
00564                             total_rec_num );
00565     }
00566 }
00567 
00568 //--------- End of function VBrowse98::disp_one ----------//
00569 
00570 //-------- Begin of function VBrowse98::disp_rec --------//
00572 void VBrowse98::disp_rec(int recNo, int x, int y, int refreshFlag) {
00573     vga.use_back();
00574     vga_back.rest_area_with_clipping(refresh_bitmap,
00575                                      0,y-y1,(rec_width-SCROLL_BAR_WIDTH+12),rec_height+y-y1,
00576                                      0,1);
00577     (*disp_rec_func)( recNo, x, y, refreshFlag );   // call user defined function
00578 }
00579 
00580 //----------- End of function VBrowse98::disp_rec -----------//

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