Function to get screen size added
[scilab.git] / scilab / routines / xsci / x_util.c
index 696bf0a..acd46fd 100644 (file)
 #include "x_data.h"
 #include "x_error.h"
 #include "x_menu.h"
-
+#include "../stack-c.h"
 #include "../machine.h"
 #include "All-extern-x.h"
 
 #include <stdio.h>
 
+extern int IsConsoleMode(void);
+
 static void horizontal_copy_area();
 static void vertical_copy_area();
 
@@ -558,11 +560,11 @@ void DeleteChar (screen, n)
  */
 
 void ClearAbove (screen)
-register TScreen *screen;
+     register TScreen *screen;
 {
-       register top, height;
+  register int top, height;
 
-       if(screen->cursor_state)
+  if(screen->cursor_state)
                HideCursor();
        if((top = -screen->topline) <= screen->max_row) {
                if(screen->scroll_amt)
@@ -588,7 +590,7 @@ register TScreen *screen;
 void ClearBelow (screen)
 register TScreen *screen;
 {
-       register top;
+  register int top;
 
        ClearRight(screen);
        if((top = screen->cur_row - screen->topline) <= screen->max_row) {
@@ -991,3 +993,147 @@ void recolor_cursor (cursor, fg, bg)
     return;
 }
 
+/* Scilab tohome() */
+/* Called by HomeFunction() in SCI/routines/console/zzledt.c */
+/* V.C. 04/2004 */
+void XHomeFunction(void)
+{
+  register TScreen *screen = &term->screen;
+  static int k=0;
+  
+  if (!IsConsoleMode())
+    {
+      /* Screen is filled with empty lines and then cleared */
+      for(k=0;k<(Height(screen) - 1)/FontHeight(screen) - 2;k++) /* 2 is the number of rows used by tohome()\r\n */
+       {
+         sciprint("\r\n");
+       }
+      screen->cur_row = screen->topline; /* New cursor position */
+      ClearBelow(screen); /* Screen is cleared below cursor */
+      ScrollBarDrawThumb(screen->scrollWidget);
+    }
+  else
+    {
+      system("clear");
+    }
+  return;
+}
+
+
+/* Scilab clc() */
+/* Called by ClearScreenConsole() in SCI/routines/console/zzledt.c */
+/* V.C. 04/2004 */
+int XClearScreenConsole(char *fname)
+{
+  register TScreen *screen = &term->screen;
+  int l1,m1=1,n1=1,NbLines=0;
+
+  if (!IsConsoleMode())
+    {
+      CheckRhs(0,1);
+      if (Rhs==0)
+       {
+         ClearScreen(screen); /* All screen is cleared */
+         screen->savedlines = 0; /* Number of lines scrolled */
+         screen->cur_row = screen->topline - 1; /* New cursor position */
+         sciprint("\r\n"); /* To have a blank space above prompt */
+         ScrollBarDrawThumb(screen->scrollWidget);
+       }
+      else
+       {
+         GetRhsVar(1,"i",&m1,&n1,&l1);
+         NbLines = *istk(l1);
+         if (NbLines>0)
+           {
+             if (screen->topline < screen->cur_row - NbLines)
+               {
+                 screen->savedlines = screen->savedlines - NbLines - 2; /* Number of lines scrolled */
+                 if (screen->savedlines < 0)
+                   screen->savedlines=0;
+                 screen->cur_row = screen->cur_row - NbLines - 2; /* New cursor position */
+                 ClearBelow(screen); /* Screen is cleared below cursor */
+                 ScrollBarDrawThumb(screen->scrollWidget);
+               }
+             else
+               {
+                 sciprint("\n Not in screen \n");
+               }
+           }
+         else
+           {
+             sciprint("\n Error %d invalid number \n",NbLines);
+           }
+       }
+    }
+  else
+    {
+      sciprint("\n Only in Window Mode \n");
+    }
+  return 0;
+}
+
+/* Scilab get(0,"....") (root properties) */
+/* V.C. 08/2004 */
+int GetScreenProperty(char *prop, char **value)
+{
+  register TScreen *screen = &term->screen;
+
+  if((value=calloc(1,sizeof(char)))==NULL)
+    {
+      Scierror(999,"GetScreenProperty: No more memory available\r\n");
+      return -1;
+    }
+  if((value[0]=(char *)calloc(1,sizeof(char)*(200+1)))==NULL)
+    {
+      Scierror(999,"GetScreenProperty: No more memory available\r\n");
+      return -1;
+    }
+    (value[0])[200]='\0';
+
+  if(!strcmp(prop,"screensize_px"))
+    {
+      sprintf(value[0],"%f|%f|%f|%f",(float)1,(float)1,
+             (float)DisplayWidth(screen->display,DefaultScreen(screen->display)),
+             (float)DisplayHeight(screen->display,DefaultScreen(screen->display)));
+    }
+  else if(!strcmp(prop,"screensize_mm"))
+    {
+      sprintf(value[0],"%f|%f|%f|%f",(float)0,(float)0,
+             (float)DisplayWidthMM(screen->display,DefaultScreen(screen->display)),
+             (float)DisplayHeightMM(screen->display,DefaultScreen(screen->display)));
+    }
+  else if(!strcmp(prop,"screensize_mm"))
+    {
+      sprintf(value[0],"%f|%f|%f|%f",(float)0,(float)0,
+             (float)DisplayWidthMM(screen->display,DefaultScreen(screen->display)),
+             (float)DisplayHeightMM(screen->display,DefaultScreen(screen->display)));
+    }
+  else if(!strcmp(prop,"screensize_cm"))
+    {
+      sprintf(value[0],"%f|%f|%f|%f",(float)0,(float)0,
+             (float)DisplayWidthMM(screen->display,DefaultScreen(screen->display))/10,
+             (float)DisplayHeightMM(screen->display,DefaultScreen(screen->display))/10);
+    }
+  else if(!strcmp(prop,"screensize_in"))
+    {
+      sprintf(value[0],"%f|%f|%f|%f",(float)0,(float)0,
+             ((float)DisplayWidthMM(screen->display,DefaultScreen(screen->display)))/25.4,
+             ((float)DisplayHeightMM(screen->display,DefaultScreen(screen->display)))/25.4);
+    }
+  else if(!strcmp(prop,"screensize_pt"))
+    {
+      sprintf(value[0],"%f|%f|%f|%f",(float)0,(float)0,
+             (float)DisplayWidthMM(screen->display,DefaultScreen(screen->display))/25.4*72,
+             (float)DisplayHeightMM(screen->display,DefaultScreen(screen->display))/25.4*72);
+    }
+  else if(!strcmp(prop,"screensize_norm"))
+    {
+      sprintf(value[0],"%f|%f|%f|%f",(float)0,(float)0,(float)1,(float)1);
+    }
+  else
+    {
+      sciprint("Unknown property %s\r\n",prop);
+      return -1;
+    }
+  return 0;
+}