You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
4.7 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "cliClass.h"
  2. #ifdef TURBOVISION
  3. void WindowCLI::handleEvent(TEvent &event){
  4. TApplication::handleEvent(event);
  5. if (event.what == evCommand){
  6. switch (event.message.command){
  7. case cmAboutCmd: // About Dialog Box
  8. aboutDlgBox();
  9. default: // Unknown command
  10. return;
  11. };
  12. clearEvent (event);
  13. };
  14. };
  15. TMenuBar *WindowCLI::initMenuBar(TRect r){
  16. r.b.y = r.a.y + 1;
  17. return new TMenuBar(r,
  18. *new TSubMenu( "~F~ile", kbAltF, hcNoContext ) +
  19. *new TMenuItem( "~A~bout...", cmAboutCmd, kbNoKey, hcNoContext) +
  20. newLine() +
  21. *new TMenuItem( "E~x~it...", cmQuit, kbAltX, hcNoContext)
  22. );
  23. };
  24. void WindowCLI::aboutDlgBox(){
  25. TDialog *aboutBox = new TDialog(TRect(0, 0, 39, 13), "About");
  26. aboutBox->insert(
  27. new TStaticText(TRect(9, 2, 30, 9),
  28. "\003Direct Memo Access\n\n" // These strings will be
  29. "\003C++ Version\n\n" // concatenated by the compiler.
  30. "\003Copyright (c) 2018\n\n" // The \003 centers the line.
  31. "\003by Gagua"
  32. )
  33. );
  34. aboutBox->insert( new TButton(TRect(14, 10, 26, 12), " OK", cmOK, bfDefault) );
  35. aboutBox->options |= ofCentered;
  36. executeDialog(aboutBox);
  37. };
  38. #else
  39. #ifdef NEWT_CLI
  40. WindowCLI::WindowCLI( WindowCLI *parent ){
  41. m_oForm = newtForm( NULL, NULL, 0 );
  42. };
  43. WindowCLI::~WindowCLI(){
  44. newtFormDestroy( m_oForm );
  45. };
  46. void WindowCLI::show(){
  47. paint();
  48. };
  49. void WindowCLI::hide(){
  50. newtPopWindow();
  51. };
  52. newtComponent WindowCLI::run(){
  53. struct newtExitStruct es;
  54. return newtRunForm( m_oForm );//, &es );
  55. //return es;
  56. };
  57. #else
  58. #include "../components/base/basicNCursesEngine.h"
  59. WindowCLI::WindowCLI( WINDOW *parent ){
  60. m_pParent = parent;
  61. m_pWND = NULL;
  62. m_pCDKScreen = NULL;
  63. //m_iHeight = 3;
  64. //m_iWidth = 10;
  65. //m_iStartY = ( LINES - m_iHeight )/2;
  66. //m_iStartX = ( COLS - m_iWidth )/2;
  67. m_sBorder.ls = '|';
  68. m_sBorder.rs = '|';
  69. m_sBorder.ts = '-';
  70. m_sBorder.bs = '-';
  71. m_sBorder.tl = '+';
  72. m_sBorder.tr = '+';
  73. m_sBorder.bl = '+';
  74. m_sBorder.br = '+';
  75. };
  76. WindowCLI::~WindowCLI(){
  77. /* box(local_win, ' ', ' '); : This won't produce the desired
  78. * result of erasing the window. It will leave it's four corners
  79. * and so an ugly remnant of window.
  80. */
  81. wborder( m_pWND, ' ', ' ', ' ',' ',' ',' ',' ',' ');
  82. /* The parameters taken are
  83. * 1. win: the window on which to operate
  84. * 2. ls: character to be used for the left side of the window
  85. * 3. rs: character to be used for the right side of the window
  86. * 4. ts: character to be used for the top side of the window
  87. * 5. bs: character to be used for the bottom side of the window
  88. * 6. tl: character to be used for the top left corner of the window
  89. * 7. tr: character to be used for the top right corner of the window
  90. * 8. bl: character to be used for the bottom left corner of the window
  91. * 9. br: character to be used for the bottom right corner of the window
  92. */
  93. wrefresh( m_pWND );
  94. delwin( m_pWND );
  95. };
  96. bool WindowCLI::create( int startx, int starty, int width, int height ){
  97. m_iStartX = startx;
  98. m_iStartY = starty;
  99. m_iWidth = width;
  100. m_iHeight = height;
  101. m_pWND = newwin( m_iHeight, m_iWidth, m_iStartY, m_iStartX );
  102. if( m_pWND != NULL ) {
  103. createBox( true );
  104. wrefresh( m_pWND );
  105. basicNCursesEngine::getInstance()->attachWindow( this );
  106. return true;
  107. };
  108. return false;
  109. };
  110. void WindowCLI::createBox( bool flag ){
  111. if( flag ){
  112. mvaddch(m_iStartY, m_iStartX, m_sBorder.tl);
  113. mvaddch(m_iStartY, m_iStartX + m_iWidth, m_sBorder.tr);
  114. mvaddch(m_iStartY + m_iHeight, m_iStartX, m_sBorder.bl);
  115. mvaddch(m_iStartY + m_iHeight, m_iStartX + m_iWidth, m_sBorder.br);
  116. mvhline(m_iStartY, m_iStartX + 1, m_sBorder.ts, m_iWidth - 1);
  117. mvhline(m_iStartY + m_iHeight, m_iStartX + 1, m_sBorder.bs, m_iWidth - 1);
  118. mvvline(m_iStartY + 1, m_iStartX, m_sBorder.ls, m_iHeight - 1);
  119. mvvline(m_iStartY + 1, m_iStartX + m_iWidth, m_sBorder.rs, m_iHeight - 1);
  120. } else {
  121. for(int j = m_iStartY; j <= m_iStartY + m_iHeight; ++j)
  122. for(int i = m_iStartX; i <= m_iStartX + m_iWidth; ++i)
  123. mvaddch(j, i, ' ');
  124. };
  125. refresh();
  126. };
  127. bool WindowCLI::addControl( void *obj, EObjectType objectType ){
  128. CTRL *tVar;
  129. tVar =( CTRL * ) malloc( sizeof( CTRL ));
  130. if( tVar != NULL ) {
  131. tVar->CTL = obj;
  132. tVar->type = objectType;
  133. m_vCTRLs.push_back( tVar );
  134. return true;
  135. };
  136. return false;
  137. };
  138. #endif // NEWT_CLI
  139. #endif