Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

windows.c 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #include <curses.h>
  2. #include <stddef.h>
  3. #include <stdlib.h>
  4. #include "mucurses.h"
  5. /** @file
  6. *
  7. * MuCurses windows instance functions
  8. *
  9. */
  10. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  11. /**
  12. * Delete a window
  13. *
  14. * @v *win pointer to window being deleted
  15. * @ret rc return status code
  16. */
  17. int delwin ( WINDOW *win ) {
  18. /* I think we should blank the region covered by the window -
  19. ncurses doesn't do this, but they have a buffer, so they
  20. may just be deleting from an offscreen context whereas we
  21. are guaranteed to be deleting something onscreen */
  22. wmove( win, 0, 0 );
  23. chtype killch = (chtype)' ';
  24. do {
  25. _wputch( win, killch, WRAP );
  26. } while ( win->curs_x + win->curs_y );
  27. free( win );
  28. wmove ( stdscr, 0, 0 );
  29. return OK;
  30. }
  31. /**
  32. * Create a new derived window
  33. *
  34. * @v parent parent window
  35. * @v nlines window height
  36. * @v ncols window width
  37. * @v begin_y window y origin (relative to parent)
  38. * @v begin_x window x origin (relative to parent)
  39. * @ret ptr return pointer to child window
  40. */
  41. WINDOW *derwin ( WINDOW *parent, int nlines, int ncols,
  42. int begin_y, int begin_x ) {
  43. WINDOW *child;
  44. if ( ( (unsigned)ncols > parent->width ) ||
  45. ( (unsigned)nlines > parent->height ) )
  46. return NULL;
  47. if ( ( child = malloc( sizeof( WINDOW ) ) ) == NULL )
  48. return NULL;
  49. child->ori_y = parent->ori_y + begin_y;
  50. child->ori_x = parent->ori_x + begin_x;
  51. child->height = nlines;
  52. child->width = ncols;
  53. child->parent = parent;
  54. child->scr = parent->scr;
  55. return child;
  56. }
  57. /**
  58. * Create a duplicate of the specified window
  59. *
  60. * @v orig original window
  61. * @ret ptr pointer to duplicate window
  62. */
  63. WINDOW *dupwin ( WINDOW *orig ) {
  64. WINDOW *copy;
  65. if ( ( copy = malloc( sizeof( WINDOW ) ) ) == NULL )
  66. return NULL;
  67. copy->scr = orig->scr;
  68. copy->attrs = orig->attrs;
  69. copy->ori_y = orig->ori_y;
  70. copy->ori_x = orig->ori_x;
  71. copy->curs_y = orig->curs_y;
  72. copy->curs_x = orig->curs_x;
  73. copy->height = orig->height;
  74. copy->width = orig->width;
  75. return copy;
  76. }
  77. /**
  78. * Move window origin to specified coordinates
  79. *
  80. * @v *win window to move
  81. * @v y Y position
  82. * @v x X position
  83. * @ret rc return status code
  84. */
  85. int mvwin ( WINDOW *win, int y, int x ) {
  86. if ( ( ( (unsigned)y + win->height ) > LINES ) ||
  87. ( ( (unsigned)x + win->width ) > COLS ) )
  88. return ERR;
  89. win->ori_y = y;
  90. win->ori_x = x;
  91. return OK;
  92. }
  93. /**
  94. * Create new WINDOW
  95. *
  96. * @v nlines number of lines
  97. * @v ncols number of columns
  98. * @v begin_y column origin
  99. * @v begin_x line origin
  100. * @ret *win return pointer to new window
  101. */
  102. WINDOW *newwin ( int nlines, int ncols, int begin_y, int begin_x ) {
  103. WINDOW *win;
  104. if ( ( (unsigned)( begin_y + nlines ) > stdscr->height ) &&
  105. ( (unsigned)( begin_x + ncols ) > stdscr->width ) )
  106. return NULL;
  107. if ( ( win = malloc( sizeof(WINDOW) ) ) == NULL )
  108. return NULL;
  109. win->ori_y = begin_y;
  110. win->ori_x = begin_x;
  111. win->height = nlines;
  112. win->width = ncols;
  113. win->scr = stdscr->scr;
  114. win->parent = stdscr;
  115. return win;
  116. }
  117. /**
  118. * Create a new sub-window
  119. *
  120. * @v orig parent window
  121. * @v nlines window height
  122. * @v ncols window width
  123. * @v begin_y window y origin (absolute)
  124. * @v begin_x window x origin (absolute)
  125. * @ret ptr return pointer to child window
  126. */
  127. WINDOW *subwin ( WINDOW *parent, int nlines, int ncols,
  128. int begin_y, int begin_x ) {
  129. WINDOW *child;
  130. child = newwin( nlines, ncols, begin_y, begin_x );
  131. child->parent = parent;
  132. child->scr = parent->scr;
  133. return child;
  134. }