APPLICAT.CPP
上传用户:wtrl82617
上传日期:2007-01-07
资源大小:187k
文件大小:32k
源码类别:

界面编程

开发平台:

DOS

  1. ///////////////////////////////////////////////////////////////
  2. ///////// Note::: ONLY SLOWTIMER_MSG  DISHIBITED  5/27/1994
  3. ///////////////////////////////////////////////////////////////
  4. // 1993 (c) ALL RIGHTS RESERVED
  5. // AUTHOR:  XuYongYong
  6. /*      applicat.cpp
  7. */
  8. #include "applicat.h"
  9. #include "yyxmain.h"
  10. #include "msgbox.h"
  11. #include <process.h>
  12. #include <dos.h>
  13. #include <alloc.h>
  14. #include "mouse.h"
  15. #include <malloc.h>
  16. #include <string.h>
  17. #include <fcntl.h>
  18. #include <stdio.h>
  19. extern "C" far _selectVGABitPlane ( int planeNo, int cmd );
  20. enum dosErr { dosInvalidFuncCode = 1, dosFileNotFound, dosPathNotFound,
  21. dosTooManyOpenFiles, dosAccessDenied, dosInvalidHandle,
  22. dosMemCtrlBkDestryed, dosInsufficientMem, dosInvalidMemBkAddr,
  23. dosInvalidEnvir, dosInvalidFormat, dosInvalidAccessCode,
  24. dosInvalidDate, dosUnKnownErr, dosInvalidDrv, dosAttemptRDCurDir,
  25. dosNotSameDevice, dosNoMoreFiles, dosDiskIsWriteProtected,
  26. dosBadDiskUnit, dosDriveNotReady, dosInvalidDiskCom, dosCRCErr,
  27. dosInvalidLeninDiskOp, dosSeekErr, dosNotDosDisk, dosSectorNotFound,
  28. dosOutofPaper, dosWriteFault, dosReadFault, dosGeneralFailt,
  29. dosSharingViolation, dosLockViolation, dosWrongDisk };
  30. application_class::application_class (int menu_num,char *title)
  31. { int i;
  32. this->menu_num =menu_num;
  33. if (this->menu_num<40) this->menu_num=40;
  34. my_menu=(Tmenu **) farmalloc( (sizeof (Tmenu*)) * (menu_num+1) );
  35. for (i=0;i<menu_num;i++ ) my_menu[i]=NULL;
  36. for (i=0;i<=5;i++ )  sub_sysmenu[i]=NULL;
  37. for (i=0;i<=5;i++ )  sub_win_sysmenu[i]=NULL;
  38. start_menu =NULL;
  39. this->title =title;
  40. // /interrupt/interrupt/interrupt/interrupt/interrupt/interrupt/interrupt
  41. //      timer_active =FALSE;
  42. //      kb_active=FALSE;
  43. //      TIMER_COUNT =10;
  44. //      SLOW_TIMER_COUNT =20;
  45. init_msg();     //MUST DO IT FIRST,in case clock send msg
  46. old_timer =getvect (TIMER_VECTOR);
  47. setvect (TIMER_VECTOR,application_class::timer);
  48. key_code =0;
  49. old_key =getvect (KEY_VECTOR);
  50. setvect (KEY_VECTOR,application_class::key  );
  51. old_dos_error =getvect (DOS_ERROR_VECTOR );
  52. setvect (DOS_ERROR_VECTOR ,application_class::dos_error  );
  53. old_mouse =getvect (MOUSE_VECTOR);              //MUST INIT LATER
  54. //      setvect (MOUSE_VECTOR,application_class::mouse  );
  55. }
  56. BOOL application_class::timer_active =FALSE;
  57. BOOL application_class::kb_active=FALSE;
  58. BOOL application_class::mouse_active=FALSE;
  59. BOOL application_class::dos_error_active=FALSE;
  60. int      application_class::TIMER_COUNT =20;
  61. int  application_class::SLOW_TIMER_COUNT =40;
  62. //int  application_class::key_code =0;
  63. int  application_class::time_counter =0;
  64. int  application_class::slow_time_counter =0;
  65. application_class::~application_class ()
  66. { int i;
  67. //      my_menu[0]->dispose_all_submenus();
  68. //      delete (my_menu[0]);
  69. for (i=0;i<menu_num;i++ ) if (my_menu[i]!=NULL ) delete (my_menu[i]);
  70. //      delete (my_menu[39]);
  71. delete (sysmenu);
  72. for (i=0;i<=5;i++ ) if (sub_sysmenu[i]!=NULL )delete (sub_sysmenu[i]);
  73. delete (win_sysmenu);
  74. for (i=0;i<=5;i++ )if(sub_win_sysmenu[i]!=NULL )delete (sub_win_sysmenu[i]);
  75. //
  76. if (start_menu !=NULL) delete (start_menu);
  77. farfree (my_menu);
  78. //   restore old int1c
  79. if (getvect(TIMER_VECTOR)==application_class::timer )
  80. setvect (TIMER_VECTOR,old_timer);
  81. if (getvect(KEY_VECTOR)==application_class::key )
  82. setvect (KEY_VECTOR,old_key);
  83. if (getvect(MOUSE_VECTOR)==application_class::mouse)
  84. setvect (MOUSE_VECTOR,old_mouse);
  85. if (getvect(DOS_ERROR_VECTOR)==application_class::dos_error)
  86. setvect (DOS_ERROR_VECTOR,old_dos_error);
  87. if (sysmouse) delete sysmouse;
  88. }
  89. void application_class::get_my_menu()
  90. {
  91. my_menu[0] =new Tmenu (0,title,main_help_text,NULL );
  92. sysmenu =new Tsysmenu (101,"& ","ALT_SPACE",my_menu[0]); {
  93. sysmenu->bounds.left =my_menu[0]->bounds.left+1;
  94. sysmenu->bounds.top =my_menu[0]->bounds.top+1;
  95. sysmenu->bounds.right=sysmenu->bounds.left+bar_height-2;
  96. sysmenu->bounds.bottom =my_menu[0]->bounds.bottom-1;
  97. }
  98. sub_sysmenu[0]=new Tmenu(SYS_RESTOREID,"&Restore","Restore windnow ",sysmenu);
  99. sub_sysmenu[1]=new Tmenu(SYS_MOVEID,"&Move","Move window",sysmenu);
  100. sub_sysmenu[2]=new Tmenu(SYS_SIZEID,"&Size","Change window size",sysmenu);
  101. sub_sysmenu[3]=new Tmenu(SYS_MINIMIZEID,"Mi&nimize","Iconinize window",sysmenu);
  102. sub_sysmenu[4]=new Tmenu(SYS_MAXIMIZEID,"Ma&ximize","Streatch window",sysmenu);
  103. sub_sysmenu[5]=new Tmenu(SYS_CLOSEID,"Close","Close window",sysmenu);
  104.  int i;
  105. for (i=0;i<5;i++) sub_sysmenu[i]->status |= DISABLE;
  106. // the order is important
  107. win_sysmenu =new Tsysmenu (100,"","",my_menu[0]); {
  108. win_sysmenu->bounds.left =my_menu[0]->bounds.left+1;
  109. win_sysmenu->bounds.top =my_menu[0]->bounds.top+1;
  110. win_sysmenu->bounds.right=win_sysmenu->bounds.left+bar_height-LINE_WIDTH+1;
  111. win_sysmenu->bounds.bottom =my_menu[0]->bounds.bottom-1;
  112. //              OffsetRect (&win_sysmenu->bounds ,100,100 );
  113. win_sysmenu->status =INVISIBLE;
  114. }
  115. sub_win_sysmenu[0]=new Tmenu(WIN_SYS_RESTOREID,"&Restore","Restore windnow to ",win_sysmenu);
  116. sub_win_sysmenu[1]=new Tmenu(WIN_SYS_MOVEID,"&Move","Move window",win_sysmenu);
  117. sub_win_sysmenu[2]=new Tmenu(WIN_SYS_SIZEID,"&Size","Change window size",win_sysmenu);
  118. sub_win_sysmenu[3]=new Tmenu(WIN_SYS_MINIMIZEID,"Mi&nimize","Iconinize window",win_sysmenu);
  119. sub_win_sysmenu[4]=new Tmenu(WIN_SYS_MAXIMIZEID,"Ma&ximize","Streatch window",win_sysmenu);
  120. sub_win_sysmenu[5]=new Tmenu(WIN_SYS_CLOSEID,"Close","Close window",win_sysmenu);
  121. //  Set Imme_key
  122. Imme_Menu_ID[0]= SYS_CLOSEID ;  Immediate_key[0]=ALT_F4; Imme_Menu_fptr[0]=sub_win_sysmenu[5];
  123. Max_Imme_key_nums=2;
  124. }
  125. BOOL application_class::echo_to_menu(long menu_ID)      // utter virtual
  126. {
  127. switch (menu_ID ){
  128. case SYS_CLOSEID    :thequeue.SendMessage(0
  129. ,SysQuitMSG,NULL );
  130. break;
  131. case WIN_SYS_CLOSEID :
  132. thequeue.SendMessage(pcurrent_selected_win->ID
  133. ,WinSysCloseMSG,pcurrent_selected_win );
  134. break;
  135. case DOSSHELL           : DosShell (); break;
  136. case WIN_SYS_MOVEID :
  137. case WIN_SYS_SIZEID     :
  138. key_code=CTRL_F5;
  139. thequeue.SendMessage(0, KeyPressedMSG,NULL);
  140. break;
  141. default :return FALSE;
  142. }
  143. return TRUE;    // handled
  144. }
  145. /* ********************************************************************* */
  146. /* ****************************   KEY    ******************************* */
  147. /* ********************************************************************* */
  148. int  application_class::key_pressed_handler ( int key_scan_num )
  149. {
  150. return FALSE;
  151. }
  152. /* ********************************************************************* */
  153. /* ****************************   MSG    ******************************* */
  154. /* ********************************************************************* */
  155. void application_class::show_status(int kind)
  156. {// disable();
  157. getviewsettings (&current_viewport );
  158. setport (menu_viewport);
  159. setcolor (HELP_TEXT_COLOR);
  160. switch ( kind ) {
  161. case SYS_STATUS:
  162. FillRect ( sys_status_rect,HELP_RECT_COLOR );
  163. outtextxy(sys_status_rect.left+10,sys_status_rect.top,sys_status_string);
  164. break;
  165. case STATUS:
  166. FillRect ( status_rect,HELP_RECT_COLOR );
  167. outtextxy(status_rect.left+10,status_rect.top,status_string);
  168. break;
  169. case HELP_STATUS:
  170. FillRect ( on_line_help_rect,HELP_RECT_COLOR );
  171. outtextxy( on_line_help_rect.left+10,on_line_help_rect.top,main_help_text);
  172. break;
  173. }
  174. //      disable();
  175. setport (current_viewport );
  176. //      enable();
  177. }
  178. int application_class::first_class_msg_handler ( MSG& message )
  179. {
  180. switch ( message .Action){
  181. //              case MouseLButtonDownMSG:
  182. //                      break;
  183. case MenuActionMSG:
  184. return echo_to_menu(sysmsg.ID);
  185. case DlgOkedMSG:
  186. return Dlg_OK;
  187. case DlgCanceledMSG:
  188. return Dlg_CANCEL;
  189. /*              case TimerMSG:
  190.   static unsigned int i=0;
  191. switch (i++ %8) {
  192. case 0:
  193. sprintf (status_string,"_stklen:%ux",_stklen);
  194. break;
  195. case 2:
  196. sprintf (status_string,"s:%up:%ux",stackavail(),_SP);
  197. break;
  198. case 4:
  199. sprintf(status_string,"heaptop:%lux", (unsigned long) coreleft());
  200. break;
  201. case 6:
  202. sprintf(status_string,"Fhtop:%lux", (unsigned long) farcoreleft());
  203. break;
  204. }
  205. show_status(STATUS);
  206. return FALSE;
  207.  */             case SlowTimerMSG:
  208.   static int heap;
  209. switch (slow_timer_click ++ %4) {
  210. /*                      case 0:
  211. if (getvect(MOUSE_VECTOR) !=application_class:: mouse ){
  212. strcpy (sys_status_string,"MOUSE UNOK");
  213. if (!sysmouse) strcat (sys_status_string," !!");
  214. else {
  215. setvect (MOUSE_VECTOR,application_class::mouse );
  216. sysmouse->on(0);
  217. }
  218. }
  219. else strcpy (sys_status_string,"MOUSE OK");
  220. break;
  221. case 1:
  222. //~                             if      ((heap=heapcheckfree(0xff)) == _HEAPOK ) strcpy (sys_status_string,"HEAP OK");
  223. //~                                     else if (heap==_BADVALUE) strcpy (sys_status_string,"BAD VALUE");
  224. //~                                     else strcpy (sys_status_string,"HEAP CORRUPT");
  225. if      ((heap=heapfillfree(0xff)) == _HEAPOK ) strcpy (sys_status_string,"HEAP OK");
  226. else if (heap==_HEAPEMPTY) strcpy (sys_status_string,"EMPTY");
  227. else strcpy (sys_status_string,"HEAP CORRUPT");
  228. break;
  229. case 2:
  230. if      ((heap=farheapfillfree(0x88)) == _HEAPOK ) strcpy (sys_status_string,"FARH OK");
  231. else if (heap==_HEAPEMPTY) strcpy (sys_status_string,"EM FARH");
  232. else strcpy (sys_status_string,"FARH RUPT");
  233. break;
  234. default:return FALSE;
  235. */                      }
  236. //                      show_status(SYS_STATUS);
  237. return FALSE;
  238. case SysQuitMSG:
  239. return Sys_QUIT;
  240. case KeyPressedMSG:
  241. return key_pressed_handler( key_code );
  242. case WinMovingSizingMSG: //for mouse only
  243. pcurrent_selected_win-> draw_size_rect();
  244. if (in_win_moving ==TRUE)       //moving
  245. OffsetRect (&pcurrent_selected_win->newbounds,
  246.  mouse_x-old_mouse_x,mouse_y-old_mouse_y );
  247. else {  //sizing
  248. pcurrent_selected_win->newbounds.right +=mouse_x-old_mouse_x;
  249. pcurrent_selected_win->newbounds.bottom +=mouse_y-old_mouse_y;
  250. }
  251. if (pcurrent_selected_win->newbounds.right>
  252. win_living_viewport.right-win_living_viewport.left-2)
  253. pcurrent_selected_win->newbounds.right
  254. =win_living_viewport.right-win_living_viewport.left-2;
  255. if (pcurrent_selected_win->newbounds.bottom>
  256. win_living_viewport.bottom-win_living_viewport.top-2)
  257. pcurrent_selected_win->newbounds.bottom
  258. =win_living_viewport.bottom-win_living_viewport.top-2;
  259. if (pcurrent_selected_win->newbounds.left<2)
  260. pcurrent_selected_win->newbounds.left=2;
  261. if (pcurrent_selected_win->newbounds.top<2)
  262. pcurrent_selected_win->newbounds.top=2;
  263. old_mouse_x=mouse_x;
  264. old_mouse_y=mouse_y;
  265. pcurrent_selected_win-> draw_size_rect();
  266. return TRUE;
  267. case WinSysCloseMSG:
  268. if (! (((Twin*)message.fptr)->canclose||
  269.   (((Twin*)message.fptr)->func_canclose()) ))  return FALSE;
  270.   int x,y;
  271. if (((Twin*)(message.fptr)) !=pcurrent_selected_win)
  272. ((Twin*)(message.fptr))->select();
  273. x=((Twin*)message.fptr)->bounds.left+win_living_viewport.left-menu_viewport.left+LINE_WIDTH;
  274. y=((Twin*)message.fptr)->bounds.top+win_living_viewport.top -menu_viewport.top+LINE_WIDTH;
  275. win_sysmenu->offsetmenu(-x,-y);
  276. win_sysmenu->status |=INVISIBLE;
  277. delete ((Twin*)message.fptr );
  278. //                      delete message.fptr;
  279. return TRUE ;
  280. case CtrlBreakMSG:
  281. error ("Ctrl  Break Pressed");
  282. break;
  283. default: ;//thequeue.GetMessage(sysmsg);
  284. }
  285. return FALSE;
  286. }
  287. int application_class::second_class_msg_handler ( MSG& message )
  288. {
  289. return FALSE;
  290. }
  291. int application_class::main_message_loop()
  292. { int ret_value=FALSE;
  293. while ( thequeue.GetMessage(sysmsg) )
  294. {
  295. if ((ret_value =first_class_msg_handler(sysmsg))!=FALSE) return ret_value;
  296. // This is the messages MUST be handled; && No more msg should
  297. // converted to the menu && dialog && win moving
  298. // && including messages must be shown in ret_value;
  299. if ( ( pcurrent_selected_win ==NULL )||
  300.  ((!in_win_moving)&&(!(pcurrent_selected_win->type & DIALOG_WIN)))
  301.    )
  302. ret_value =pcurrent_menu->msg_handler(sysmsg);
  303. if ( (in_menu_trap)||(ret_value!=FALSE) ) return ret_value;
  304. if ( pcurrent_selected_win !=NULL )
  305. pcurrent_selected_win->msg_handler(sysmsg);
  306. second_class_msg_handler(sysmsg);
  307. ////////////////!!!!!!!!!!!! New
  308. ///////////     if ( sysmsg.Action == KeyPressedMSG ) key_code =0;
  309. }
  310. if  (
  311. (!in_menu_trap) &&
  312. ( ( pcurrent_selected_win ==NULL )||((!in_win_moving)&&(!(pcurrent_selected_win->type & DIALOG_WIN))))
  313. )
  314. anything_in_the_loop();
  315. return ret_value;
  316. }
  317. void application_class::anything_in_the_loop(){};
  318. void application_class::run()
  319. {
  320.  int keynum;
  321. Begin_Program:
  322. init();
  323. while (1) {
  324. /*              if( (keynum=bioskey(1) )== -1 ) break;
  325. else if (keynum !=0 ) {
  326. keynum=bioskey(0);
  327. key_pressed_handler( keynum );
  328. }
  329. */              if (main_message_loop()==Sys_QUIT) break;
  330. //              if (RE_START != 0) init_screen();       //goto Begin_Program;
  331. }
  332. }
  333. /* ********************************************************************* */
  334. /* ****************************   INIT   ******************************* */
  335. /* ********************************************************************* */
  336. void application_class::init()
  337. {
  338. init_screen();
  339. init_menu();  // the order is important
  340. draw_application_win();
  341. //  settextstyle (DEFAULT_FONT,HORIZ_DIR,1 );
  342. init_win();
  343. init_ctrl();
  344.   void far *mouse_addr;
  345. mouse_addr =getvect (0x33);
  346. if (  (!((mouse_addr==NULL )||(*(unsigned char *)mouse_addr==0xcf))) &&
  347.  !nomouse
  348.    )  { sysmouse=new Tmouse();
  349. old_mouse =getvect (MOUSE_VECTOR);
  350. setvect (MOUSE_VECTOR,application_class::mouse  );
  351. }
  352. else sysmouse =NULL;
  353. }
  354. //#include "tvga256.h"  // Needs More MEMORY
  355. void application_class::init_screen()
  356. {
  357.   int gdriver = DETECT, gmode, errorcode;
  358. //      gdriver = installuserdriver("TVGA256",DETECTTVGA);/* Request auto-detection     */
  359. //      gmode = TVGA640x480;
  360. initgraph(&gdriver, &gmode, "");
  361. errorcode = graphresult();
  362. if (errorcode != grOk)  /* an error occurred */         {
  363. printf("Graphics error: %sn", grapherrormsg(errorcode));
  364. printf("Press any key to halt:");
  365. getch();
  366. error("graphics error exit");      /* return with error code */
  367. }
  368. //      RE_START =0;
  369. screen_viewport.left=0;         screen_viewport.top =0;
  370. screen_viewport.right =getmaxx();       screen_viewport.bottom=getmaxy();
  371. screen_viewport.clip =CLIP_ON;
  372. setusercharsize (10,10,10,10);
  373. settextstyle (DEFAULT_FONT+SMALL_FONT,HORIZ_DIR, /*USER_CHAR_SIZE*/6 );
  374. setport (screen_viewport);
  375. setfillstyle (SOLID_FILL, LIGHTGRAY );
  376. bar (screen_viewport.left,screen_viewport.top,screen_viewport.right,screen_viewport.bottom);
  377. font_height =textheight ("HjklMq") +8;
  378. bar_height =20;
  379. menu_viewport =screen_viewport;
  380. menu_viewport.left      +=5;            menu_viewport.top       +=5;
  381. menu_viewport.right -=5;        menu_viewport.bottom-=5;
  382. }
  383. void application_class::draw_application_win()
  384. {
  385. /////////////////////////////INIT MENUS PART/////////////////////////////////
  386. /////////////////////////////INIT MENUS PART/////////////////////////////////
  387. /////////////////////////////INIT MENUS PART/////////////////////////////////
  388. // draw Frame rect of the screen
  389. pcurrent_menu =start_menu;
  390. pcurrent_menu->psub_menu_selected =my_menu[0];
  391. setport (screen_viewport);
  392. setlinestyle ( SOLID_LINE,1,THICK_WIDTH );
  393. setcolor(LIGHTGRAY);
  394. Rect temp_rect;
  395. SetRect (&temp_rect,menu_viewport.left,menu_viewport.top,
  396. menu_viewport.right,menu_viewport.bottom );
  397. InsetRect (&temp_rect, -LINE_WIDTH,-LINE_WIDTH);
  398. draw_win_frame_rect ( temp_rect );
  399. //  change menu_viewport
  400. setfillstyle (SOLID_FILL, WHITE );
  401. bar (menu_viewport.left,menu_viewport.top,menu_viewport.right,menu_viewport.bottom);
  402. //  draw help_rect
  403. /*      SetRect (&on_line_help_rect,0,
  404. menu_viewport.bottom-menu_viewport.top-bar_height-10,
  405. menu_viewport.right-menu_viewport.left,
  406. menu_viewport.bottom-menu_viewport.top);
  407. */
  408. SetRect (&on_line_help_rect,0,
  409. menu_viewport.bottom-menu_viewport.top-bar_height-10,
  410. 250,
  411. menu_viewport.bottom-menu_viewport.top);
  412. SetRect (&sys_status_rect,270,
  413. menu_viewport.bottom-menu_viewport.top-bar_height-10,
  414. 360,
  415. menu_viewport.bottom-menu_viewport.top);
  416. SetRect (&status_rect,380,
  417. menu_viewport.bottom-menu_viewport.top-bar_height-10,
  418. menu_viewport.right-menu_viewport.left,
  419. menu_viewport.bottom-menu_viewport.top);
  420. setport (menu_viewport);
  421. FillRect (on_line_help_rect, HELP_RECT_COLOR );
  422. InsetRect (&on_line_help_rect, -5, -5 );
  423. draw_in_button (on_line_help_rect );
  424. InsetRect (&on_line_help_rect, -1, -1 );
  425. FillRect (sys_status_rect, HELP_RECT_COLOR );
  426. InsetRect (&sys_status_rect, -5, -5 );
  427. draw_in_button (sys_status_rect );
  428. InsetRect (&sys_status_rect, -1, -1 );
  429. FillRect (status_rect, HELP_RECT_COLOR );
  430. InsetRect (&status_rect, -5, -5 );
  431. draw_in_button (status_rect );
  432. InsetRect (&status_rect, -1, -1 );
  433. if (pcurrent_menu ->psub_menu_selected !=NULL ) {
  434. pcurrent_menu ->psub_menu_selected->pfather_menu=pcurrent_menu;
  435. pcurrent_menu ->psub_menu_selected->select();
  436. pcurrent_menu ->psub_menu_selected->pfather_menu=NULL;
  437. // this makes MOUSE DEAD
  438. }
  439. pcurrent_menu ->enter_menu();
  440. //  draw sys menu
  441. setcolor (BLACK);
  442. if (pcurrent_menu != NULL ) {
  443. Rect tmprect;
  444. setport (menu_viewport);
  445. tmprect = pcurrent_menu->save_bitmap.bounds;
  446. InsetRect (&tmprect ,0,1);
  447. FrameRect (tmprect);
  448. }
  449. FillRect (sysmenu->bounds,LIGHTGRAY );
  450. setcolor (BLACK );
  451. FrameRect (sysmenu->bounds);
  452. sysmenu->bounds.bottom -=1;
  453. sysmenu->bounds.right -=1;
  454. sysmenu->draw ();               //Not Very Good
  455. //  draw up & down rect;
  456.   Rect up_rect,down_rect;
  457. down_rect =my_menu[0]->bounds;
  458. down_rect.left=down_rect.right -bar_height+1;
  459. down_rect.right -=1;
  460. down_rect.bottom -=1;
  461. OffsetRect (&down_rect,LINE_WIDTH-1,0 );
  462. up_rect=down_rect;
  463. OffsetRect (&up_rect, -bar_height+1,0 );
  464. draw_out_button (down_rect);
  465. draw_out_button (up_rect);
  466. }
  467. void application_class::init_msg()
  468. {
  469. thequeue.Reset();
  470. }
  471. void application_class::init_menu()
  472. {   in_menu_trap =FALSE;
  473. start_menu =new Tmenu ("INIT","");
  474. MENU_ITEM_ENABLED_COLOR  =BLACK     ;
  475. MENU_ITEM_SELECTED_COLOR =WHITE ; // for text
  476. MENU_ITEM_DISABLED_COLOR =DARKGRAY;
  477. MENU_ITEM_SELECT_COLOR   =BLUE          ; // for bar
  478. HELP_RECT_COLOR         =LIGHTGRAY ;
  479. HELP_TEXT_COLOR =       BLACK;
  480. MENU_RECT_COLOR =       WHITE ;
  481. get_my_menu();
  482. // show menus
  483. }
  484. void application_class::init_win ()
  485. {
  486. win_living_viewport=menu_viewport;
  487. win_living_viewport.top +=2*bar_height;
  488. win_living_viewport.bottom -=2*bar_height;
  489. pfirst_win_of_all =NULL;
  490. pcurrent_selected_win =NULL;
  491. WIN_TITLEBAR_SELECTED_COLOR             =BLUE;
  492. WIN_TITLEBAR_UNSELECTED_COLOR   =LIGHTGRAY;
  493. WIN_TITLE_SELECTED_COLOR   =WHITE;
  494. WIN_TITLE_UNSELECTED_COLOR =BLACK;
  495. WIN_BACKGROUND_COLOR    =WHITE;
  496. }
  497. void application_class::init_ctrl ()
  498. {
  499. }
  500. //////////////////////////////////////////////////////////////////////////
  501. ///////////////////////////////DOSSHELL///////////////////////////////////
  502. //////////////////////////////////////////////////////////////////////////
  503. /*      // OLD VERSION
  504. void application_class::DosShell(void)
  505. {
  506.   int result;
  507. if (pcurrent_selected_win != NULL ) {
  508. exec_dialog(new Tmsgbox("Message","MUST CLOSE ALL WINDOWS",MB_OK));
  509. //              thequeue.SendMessage(pcurrent_selected_win->ID,
  510. //                      WinSysCloseMSG,pcurrent_selected_win);
  511. //              return ;
  512. }
  513. closegraph();
  514. setvect (KEY_VECTOR,old_key);
  515. setvect (TIMER_VECTOR,old_timer); //otherwise; queue will run out of it
  516. puts("Type EXIT to return to Main Program . . .");
  517. result = spawnlp(P_WAIT, "command.com", NULL);
  518. if(result==-1)  {
  519. puts("nNot enough memory to run command.com. . .");
  520. getch();
  521. }
  522. init_screen();
  523. draw_application_win();
  524. setvect (KEY_VECTOR,application_class::key  );
  525. setvect (TIMER_VECTOR,application_class::timer );
  526. if (sysmouse) sysmouse->on(0);
  527. }
  528. */
  529. void application_class::DosShell(void)
  530. {
  531.   int result;
  532.   void  interrupt (*mynow_timer)(...);
  533.   void  interrupt (*mynow_key  )(...);
  534.   void  interrupt (*mynow_dos_error)(...);
  535.   void  interrupt (*mynow_mouse)(...);
  536. mynow_timer=getvect (TIMER_VECTOR);
  537. mynow_key  =getvect (KEY_VECTOR);
  538. mynow_dos_error=getvect (DOS_ERROR_VECTOR);
  539. mynow_mouse=getvect (MOUSE_VECTOR);
  540. setvect (KEY_VECTOR,old_key);
  541. setvect (DOS_ERROR_VECTOR,old_dos_error);
  542. setvect (TIMER_VECTOR,old_timer);
  543. if (getvect(MOUSE_VECTOR)==application_class::mouse)
  544. setvect (MOUSE_VECTOR,old_mouse);
  545. //otherwise; queue will run out of it
  546. mouse_off;
  547. _screen2Disk ( "XYYSWP.SWP" );
  548. closegraph();
  549. puts("Type EXIT to return to Main Program . . .");
  550. result = spawnlp(P_WAIT, "command.com", NULL);
  551. if(result==-1)  {
  552. puts("nNot enough memory to run command.com. . .");
  553. getch();
  554. }
  555. init_screen();
  556. //  cleardevice ();
  557. if      ( ( _disk2Screen ( "XYYSWP.SWP" ) ) != 0 ) exit (144);
  558. remove ( "XYYSWP.SWP" );
  559. ///     draw_application_win();
  560. setvect (KEY_VECTOR,mynow_key );
  561. setvect (TIMER_VECTOR,mynow_timer );
  562. setvect (DOS_ERROR_VECTOR,mynow_dos_error);
  563. setvect (MOUSE_VECTOR,mynow_mouse);
  564. mouse_on;
  565. }
  566. // if swp file error occur, it return DOS_ERR Code!
  567. int application_class::_screen2Disk ( const char * swpfile )
  568. // return 0 on success // else fail
  569. {
  570.   int result = 0, i;
  571.   FILE *stream;
  572.   size_t count;
  573.   char tmpstr [ 32 ] = "ADFFT(c)LDh1994";
  574.   struct dosdate_t da;
  575.   struct dostime_t ti;
  576. _dos_gettime ( & ti );
  577. _dos_getdate ( & da );
  578. for ( i = strlen ( tmpstr ); i < 32; i ++ ) tmpstr [ i ] = 0;
  579. i = 24;
  580. tmpstr [ i ++ ] = 0x05; // swp file's bandle ID
  581. i ++;
  582. *( (unsigned int *) ( & ( tmpstr [ i ] ) ) ) =
  583. ( (unsigned) ti.hour<<11 ) + ( (unsigned) ti.minute<<5) +
  584. (unsigned) ti.second + 2;
  585. i ++; i ++;
  586. *( (unsigned int *) ( & ( tmpstr [ i ] ) ) ) =
  587. ( ( da.year - 1980 )<<9 ) + ( (unsigned) da.month<<5) +
  588. (unsigned) da.day;
  589. if (( stream = fopen(swpfile, "w+b")) == NULL ) return (-1);
  590. if (( count = fwrite(tmpstr,32 , 1, stream)) != 1 )  return (-1);
  591. //      if      ( ( _currentGrafPort->device == VGA )   // IS VGAHI
  592. //              && ( _currentGrafPort->mode == VGAHI ) )
  593. if      ( ( 1 )
  594. && ( 1 ) )
  595. {
  596. for ( i = 0; i < 4; i ++ )
  597. {
  598. // enable VGA bit-plane read
  599. _selectVGABitPlane ( i, 0 );
  600. fseek ( stream,i* 38400L+32, SEEK_SET );
  601. if ((count =fwrite((void far*)0xa0000000L,
  602. (unsigned)38400, 1, stream) ) != 1 ) return (-1);
  603. }
  604. }
  605. else return (-1);
  606. if      ( ( fclose ( stream ) ) != 0 ) return -1;
  607. return 0;
  608. }
  609. int application_class::_disk2Screen ( const char * swpfile )
  610. {
  611.   int result = 0, i;
  612.   FILE *stream;
  613.   size_t count;
  614.   char tmpstr [ 32 ];
  615. if (( stream = fopen(swpfile, "r+b")) == NULL ) return (-1);
  616. if (( count = fread (tmpstr,32 , 1, stream)) != 1 )  return (-1);
  617. if      ( ( strcmp ( tmpstr, "ADFFT(c)LDh1994" ) != 0 ) || ( tmpstr [ 24 ] != 0x05 ) )
  618. return dosFileNotFound;
  619. //      if      ( ( _currentGrafPort->device == VGA )  //       OK VGAHI
  620. //              && ( _currentGrafPort->mode == VGAHI ) )
  621. if      ( ( 1 )
  622. && ( 1 ) )
  623. {
  624. for ( i = 0; i < 4; i ++ )
  625. {
  626. // enable VGA bit-plane write
  627. _selectVGABitPlane ( i, 1 );
  628. fseek ( stream,i* 38400L+32, SEEK_SET );
  629. if ((count =fread ((void far*)0xa0000000L,
  630. (unsigned)38400, 1, stream) ) != 1 ) return (-1);
  631. }
  632. }
  633. else return (-1);
  634. if      ( ( fclose ( stream ) ) != 0 ) return -1;
  635. return 0;
  636. }
  637. /////////////////////////////////////////////////////////////////////////
  638. //////////////////////////      exec a dialog  //////////////////////////////
  639. /////////////////////////////////////////////////////////////////////////
  640. int application_class::exec_dialog(Tdialog *pdialog_handled)
  641. { int ret_value;
  642.   int keynum;
  643.   class MSGQueue savqueue;
  644.   MSG savmsg;
  645. savqueue =thequeue;
  646. savmsg =sysmsg;
  647. thequeue.Reset();
  648. pdialog_handled->open_one_win ();
  649. do {
  650. ret_value=main_message_loop();
  651. }       while ( ( (ret_value != Dlg_OK)&&(ret_value!=Dlg_CANCEL) ) ||   //Dlg_OK or Dlg_CANCEL
  652. (pdialog_handled ==pcurrent_selected_win )  );
  653. // similar to run
  654. // others no need to delete now
  655.  //     No need to delete pdialog_handled;--->deleted as it is closed
  656. asm cli;
  657. sysmsg   =savmsg;
  658. thequeue =savqueue;
  659. asm sti;
  660. return ret_value;
  661. }
  662. ///////////////////////////////////////////////////////////////////////////
  663. void interrupt application_class::timer(...)
  664. {
  665. //      disable();
  666. //  mouse still makes the program crash////////////////// WHY
  667. if (!timer_active){
  668. timer_active =TRUE;
  669. (*old_timer)(...);
  670. if (thequeue.QueueFull()) goto Ret;
  671. ///Prevent more queue
  672. if ( thequeue.first !=thequeue.last ) {
  673. if (( thequeue.msg_array[thequeue.oldfirst].Action==TimerMSG)
  674. || (thequeue.msg_array[thequeue.oldfirst].Action==SlowTimerMSG))
  675. goto Ret;
  676. }
  677. time_counter++;
  678. slow_time_counter ++;
  679. if ( time_counter > TIMER_COUNT ){
  680. time_counter =0;
  681. thequeue.SendMessage(0,TimerMSG,NULL);
  682. }
  683. if (slow_time_counter > SLOW_TIMER_COUNT ) {
  684. slow_time_counter =0 ;
  685. thequeue.SendMessage(0,SlowTimerMSG,NULL);
  686. }
  687. Ret:    timer_active =FALSE;
  688. }
  689. //      enable();
  690. }
  691. void interrupt (* application_class::old_timer) (...)=getvect(0x19);
  692. void interrupt (* application_class::old_key  ) (...)=getvect(0x19);
  693. void interrupt (* application_class::old_mouse) (...)=getvect(0x19);
  694. void interrupt (* application_class::old_dos_error) (...)=getvect(0x19);
  695. /*
  696. #define MYBIOSKEY                               
  697. switch (key_code) {                     
  698. case 0x48e0:                    
  699. key_code=UPKEY;         
  700. break;                          
  701. case 0x4be0:            
  702. key_code=LEFTKEY;       
  703. break;                          
  704. case 0x4de0:            
  705. key_code=RIGHTKEY;      
  706. break;                          
  707. case 0x50e0:            
  708. key_code=DOWNKEY;       
  709. break;                          
  710. case 0x8de0:            
  711. key_code=CTRL_UP;       
  712. break;                          
  713. case 0x73e0:            
  714. key_code=CTRL_LEFT;                             
  715. break;                          
  716. case 0x74e0:            
  717. key_code=CTRL_RIGHT;                    
  718. break;                          
  719. case 0x91e0:            
  720. key_code=CTRL_DOWN;     
  721. break;                          
  722. case SPACEKEY:                              
  723. if ( bioskey (0x12) & 0x08 )                    
  724. key_code =ALT_SPACE;                    
  725. break;                                                                  
  726. case ALT_LEFT:                              
  727. if ( bioskey (0x12) & 0x04 )                    
  728. key_code =CTRL_ALT_LEFT;            
  729. break;                                                                  
  730. case ALT_RIGHT:                             
  731. if ( bioskey (0x12) & 0x04 )                    
  732. key_code =CTRL_ALT_RIGHT;           
  733. break;                                                                  
  734. };
  735. */
  736. #define MYBIOSKEY                               
  737. switch (tmp) {                  
  738. case 0x53e0:            
  739. tmp=DELKEY;                     
  740. break;          
  741. case 0x52e0:            
  742. tmp=INSKEY;                     
  743. break;          
  744. case 0x49e0:            
  745. tmp=PGUPKEY;            
  746. break;          
  747. case 0x47e0:            
  748. tmp=HOMEKEY;            
  749. break;          
  750. case 0x4fe0:            
  751. tmp=ENDKEY;                     
  752. break;          
  753. case 0x51e0:                    
  754. tmp=PGDNKEY;            
  755. break;                          
  756. case 0x4be0:            
  757. tmp=LEFTKEY;    
  758. break;                          
  759. case 0x4de0:            
  760. tmp=RIGHTKEY;   
  761. break;                          
  762. case 0x48e0:            
  763. tmp=UPKEY;              
  764. break;                          
  765. case 0x50e0:            
  766. tmp=DOWNKEY;    
  767. break;                          
  768. case 0x8de0:            
  769. tmp=CTRL_UP;    
  770. break;                          
  771. case 0x73e0:            
  772. tmp=CTRL_LEFT;                          
  773. break;                          
  774. case 0x74e0:            
  775. tmp=CTRL_RIGHT;                 
  776. break;                          
  777. case 0x91e0:            
  778. tmp=CTRL_DOWN;  
  779. break;                          
  780. case SPACEKEY:                              
  781. if ( bioskey (0x12) & 0x08 )                    
  782. tmp =ALT_SPACE;                         
  783. break;                                                                  
  784. case ALT_LEFT:                              
  785. if ( bioskey (0x12) & 0x04 )                    
  786. tmp =CTRL_ALT_LEFT;            
  787. break;                                                                  
  788. case ALT_RIGHT:                             
  789. if ( bioskey (0x12) & 0x04 )                    
  790. tmp =CTRL_ALT_RIGHT;           
  791. break;                                                                  
  792. };
  793. void interrupt application_class::key (...)
  794. { register int tmp;
  795.   MSG tmpmsg;
  796. //      disable();
  797. (*old_key)(...);
  798. if (!kb_active ){
  799. kb_active  =TRUE;
  800. //~//~  (*old_key)(...);        // put here may cause CAPSLOCK Unable
  801. //~             switch (bioskey(1)) {
  802. switch (bioskey(0x11)) {
  803. case -1:
  804. thequeue.SendMessage(0,CtrlBreakMSG,NULL );
  805. break;
  806. case  0:break;
  807. default :
  808. //~                             key_code=bioskey(0);
  809. //                              tmp =key_code;
  810. //~                             key_code=bioskey(0x10);
  811. tmp=bioskey(0x10);
  812. if (thequeue.QueueFull())       goto Ret;
  813. MYBIOSKEY;
  814. if ( thequeue.first !=thequeue.last ) {
  815. if (( thequeue.msg_array[thequeue.oldfirst].Action
  816. ==KeyPressedMSG) && (tmp==key_code))
  817. goto Ret;
  818. }
  819. //                              if ( thequeue.PeekMessage (tmpmsg) !=FALSE ){
  820. //                                      if ((tmpmsg.Action==KeyPressedMSG) && (tmp==key_code))
  821. //                                              goto Ret;
  822. //                              }
  823. key_code =tmp;
  824. thequeue.SendMessage(0, KeyPressedMSG,NULL);
  825. }
  826. Ret:    kb_active =FALSE;
  827. }
  828. //      enable();
  829. }
  830. void interrupt  application_class::mouse(...)
  831. {
  832. //      disable();
  833. (*old_mouse)(...);
  834. if (!mouse_active ){
  835. mouse_active  =TRUE;
  836. if (in_win_moving) {
  837. if (sysmouse->get_release_count(LEFT_BUTTON) >0 ) {
  838. thequeue.SendMessage(pcurrent_selected_win->ID
  839. ,WinMovedSizedMSG,pcurrent_selected_win );
  840. in_win_moving =FALSE;
  841. mouse_active =FALSE;
  842. return ;
  843. }
  844. sysmouse->get_posn ();
  845. if ( (abs(old_mouse_x-mouse_x )<10) && (abs(old_mouse_y-mouse_y)<10) ){
  846. mouse_active =FALSE;
  847. return ;
  848. }
  849. thequeue.SendMessage(0,WinMovingSizingMSG,pcurrent_selected_win);
  850. mouse_active =FALSE;
  851. return;
  852. }
  853. if (sysmouse->get_press_count(LEFT_BUTTON) >0 )
  854. thequeue.SendMessage(0,MouseLButtonDownMSG,NULL );
  855. mouse_active =FALSE;
  856. }
  857. //      enable();
  858. }
  859. void interrupt  application_class::dos_error(...)
  860. { int i,j;
  861. i=_AX;
  862. j=_DI;
  863. if (dos_error_active ) return ;
  864. dos_error_active =TRUE;
  865. //      enable();
  866. if ( i & 0x8000 ); // AH bit7 is set ; means not disk error
  867. else {
  868. switch (j & 0xff ) {
  869. case 0x00:strcpy (msgbuf,"Write Protected");break;
  870. case 0x01:strcpy (msgbuf,"Invalid Drive Number");break;
  871. case 0x02:strcpy (msgbuf,"Drive not ready");break;
  872. default :strcpy (msgbuf,"Drive error");break;
  873. }
  874. diskerrorno = j & 0xff ;
  875. putch('07');
  876. // To let the owner do next && retry,etc
  877. //              if (theprogram->exec_dialog(new Tmsgbox("Message",msgbuf,MB_RETRYCANCEL))
  878. //                      == Dlg_OK ) _AL=0x01;
  879. //                      else    _AL =0x02;
  880. dos_error_active =FALSE;
  881. //              _AL =0x00;  cannot be touched by the caller
  882. //              asm {
  883. //                      mov bp,sp
  884. //                      mov ax,[bp+22]
  885. //                      mov al,0
  886. //                      mov [bp+22],ax
  887. //              }
  888. return;
  889. }
  890. (*old_dos_error );
  891. dos_error_active =FALSE;
  892. }