FreeBASIC  0.91.0
io_window.c
Go to the documentation of this file.
1 /* console window stuff */
2 
3 #include "../fb.h"
4 #include "fb_private_console.h"
5 
6 static SMALL_RECT srRealConsoleWindow;
7 
8 static __inline__ void hReadConsoleRect( SMALL_RECT *pRect, int GetRealWindow )
9 {
10  CONSOLE_SCREEN_BUFFER_INFO info;
11 
12  if( GetConsoleScreenBufferInfo( __fb_out_handle, &info )==0 ) {
13  memset( pRect, 0, sizeof(SMALL_RECT) );
14  } else {
15  if( GetRealWindow ) {
16  memcpy( pRect, &info.srWindow, sizeof(SMALL_RECT) );
17  } else {
18  pRect->Left = 0;
19  pRect->Top = info.srWindow.Top;
20  pRect->Right = info.dwSize.X - 1;
21  pRect->Bottom = info.srWindow.Bottom;
22  }
23  }
24 }
25 
45 {
46  /* Whenever the console was set by the user, we MUST NOT query this
47  * information again because this would cause a mess with SAA
48  * applications otherwise. */
49  if (__fb_con.setByUser)
50  return;
51 
54 }
55 
57 {
58  static int inited = FALSE;
59  if( !inited )
60  {
61  inited = TRUE;
62  /* query the console window position/size only when needed */
64  }
65 }
66 
68 {
69  SMALL_RECT sr;
70 
71  /* Whenever the console was set by the user, there's no need to
72  * restore the original window console because we don't have to
73  * mess around with scrollable windows */
74  if (__fb_con.setByUser)
75  return;
76 
78 
79  /* Update only when changed! */
80  hReadConsoleRect( &sr, TRUE );
81  if( (sr.Top != srRealConsoleWindow.Top)
82  || (sr.Bottom != srRealConsoleWindow.Bottom) )
83  {
84  /* Keep the left/right coordinate of the console */
85  sr.Top = srRealConsoleWindow.Top;
86  sr.Bottom = srRealConsoleWindow.Bottom;
87  int i;
88  for( i = 0; i < FB_CONSOLE_MAXPAGES; i++ )
89  {
90  if( __fb_con.pgHandleTb[i] != NULL )
91  SetConsoleWindowInfo( __fb_con.pgHandleTb[i], TRUE, &srRealConsoleWindow );
92  }
93  }
94 }
95 
96 void fb_ConsoleGetMaxWindowSize( int *cols, int *rows )
97 {
98  COORD max = GetLargestConsoleWindowSize( __fb_out_handle );
99  if( cols != NULL )
100  *cols = (max.X==0 ? FB_SCRN_DEFAULT_WIDTH : max.X);
101  if( rows != NULL )
102  *rows = (max.Y==0 ? FB_SCRN_DEFAULT_HEIGHT : max.Y);
103 }
104 
105 FBCALL void fb_hConvertToConsole( int *left, int *top, int *right, int *bottom )
106 {
107  int win_left, win_top;
108 
110 
112  return;
113 
114  fb_hConsoleGetWindow( &win_left, &win_top, NULL, NULL );
115  if( left != NULL )
116  *left += win_left - 1;
117  if( top != NULL )
118  *top += win_top - 1;
119  if( right != NULL )
120  *right += win_left - 1;
121  if( bottom != NULL )
122  *bottom += win_top - 1;
123 }
124 
125 FBCALL void fb_hConvertFromConsole( int *left, int *top, int *right, int *bottom )
126 {
127  int win_left, win_top;
128 
130 
132  return;
133 
134  fb_hConsoleGetWindow( &win_left, &win_top, NULL, NULL );
135  if( left != NULL )
136  *left -= win_left - 1;
137  if( top != NULL )
138  *top -= win_top - 1;
139  if( right != NULL )
140  *right -= win_left - 1;
141  if( bottom != NULL )
142  *bottom -= win_top - 1;
143 }
144 
145 void fb_hConsoleGetWindow( int *left, int *top, int *cols, int *rows )
146 {
148 
150  {
151  if( left != NULL )
152  *left = 0;
153  if( top != NULL )
154  *top = 0;
155  if( cols != NULL )
156  *cols = 0;
157  if( rows != NULL )
158  *rows = 0;
159  }
160  else
161  {
162  if( left != NULL )
163  *left = __fb_con.window.Left;
164  if( top != NULL )
165  *top = __fb_con.window.Top;
166  if( cols != NULL )
167  *cols = __fb_con.window.Right - __fb_con.window.Left + 1;
168  if( rows != NULL )
169  *rows = __fb_con.window.Bottom - __fb_con.window.Top + 1;
170  }
171 }