Back to index

plt-scheme  4.2.1
Defines | Functions | Variables
de_win.c File Reference
#include "windows.h"
#include "gc.h"
#include "cord.h"
#include "de_cmds.h"
#include "de_win.h"

Go to the source code of this file.

Defines

#define RED   RGB(255,0,0)

Functions

void de_error (char *s)
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR command_line, int nCmdShow)
char * plain_chars (char *text, size_t len)
char * control_chars (char *text, size_t len)
void get_line_rect (int line, int win_width, RECT *rectp)
void update_cursor (void)
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
void move_cursor (int c, int l)
void invalidate_line (int i)
LRESULT CALLBACK AboutBox (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)

Variables

int LINES = 0
int COLS = 0
char szAppName [] = "DE"
char FullAppName [] = "Demonstration Editor"
HWND hwnd
int char_width
int char_height
int caret_visible = 0
int screen_was_painted = 0
int last_col
int last_line

Define Documentation

#define RED   RGB(255,0,0)

Function Documentation

LRESULT CALLBACK AboutBox ( HWND  hDlg,
UINT  message,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 341 of file de_win.c.

{
   switch( message )
   {
      case WM_INITDIALOG:
           SetFocus( GetDlgItem( hDlg, IDOK ) );
           break;

      case WM_COMMAND:
           switch( wParam )
           {
              case IDOK:
                   EndDialog( hDlg, TRUE );
                   break;
           }
           break;

      case WM_CLOSE:
           EndDialog( hDlg, TRUE );
           return TRUE;

   }
   return FALSE;
}

Here is the caller graph for this function:

char* control_chars ( char *  text,
size_t  len 
)

Definition at line 144 of file de_win.c.

{
    char * result = GC_MALLOC_ATOMIC(len + 1);
    register size_t i;
    
    for (i = 0; i < len; i++) {
       if (iscntrl(text[i])) {
           result[i] = text[i] + 0x40;
       } else {
           result[i] = ' ';
       }
    }
    result[len] = '\0';
    return(result);
}

Here is the caller graph for this function:

void de_error ( char *  s)

Definition at line 39 of file de_win.c.

{
    MessageBox( hwnd, (LPSTR) s,
                (LPSTR) FullAppName,
                MB_ICONINFORMATION | MB_OK );
    InvalidateRect(hwnd, NULL, TRUE);
}
void get_line_rect ( int  line,
int  win_width,
RECT *  rectp 
)

Definition at line 163 of file de_win.c.

{
    rectp -> top = line * char_height;
    rectp -> bottom = rectp->top + char_height;
    rectp -> left = 0;
    rectp -> right = win_width;
}

Here is the caller graph for this function:

Definition at line 330 of file de_win.c.

{
    RECT line;
    
    if (!screen_was_painted) return;
       /* Invalidating a rectangle before painting seems result in a  */
       /* major performance problem.                                  */
    get_line_rect(i, COLS*char_width, &line);
    InvalidateRect(hwnd, &line, FALSE);
}

Here is the call graph for this function:

void move_cursor ( int  c,
int  l 
)

Definition at line 316 of file de_win.c.

Here is the call graph for this function:

char* plain_chars ( char *  text,
size_t  len 
)

Definition at line 126 of file de_win.c.

{
    char * result = GC_MALLOC_ATOMIC(len + 1);
    register size_t i;
    
    for (i = 0; i < len; i++) {
       if (iscntrl(text[i])) {
           result[i] = ' ';
       } else {
           result[i] = text[i];
       }
    }
    result[len] = '\0';
    return(result);
}

Here is the caller graph for this function:

Definition at line 324 of file de_win.c.

{
    SetCaretPos(last_col * char_width, last_line * char_height);
    ShowCaret(hwnd);
}

Here is the caller graph for this function:

int APIENTRY WinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
LPSTR  command_line,
int  nCmdShow 
)

Definition at line 47 of file de_win.c.

{
   MSG         msg;
   WNDCLASS    wndclass;
   HANDLE      hAccel;

   if (!hPrevInstance)
   {
      wndclass.style          = CS_HREDRAW | CS_VREDRAW;
      wndclass.lpfnWndProc    = WndProc;
      wndclass.cbClsExtra     = 0;
      wndclass.cbWndExtra     = DLGWINDOWEXTRA;
      wndclass.hInstance      = hInstance;
      wndclass.hIcon          = LoadIcon (hInstance, szAppName);
      wndclass.hCursor        = LoadCursor (NULL, IDC_ARROW);
      wndclass.hbrBackground  = GetStockObject(WHITE_BRUSH);
      wndclass.lpszMenuName   = "DE";
      wndclass.lpszClassName  = szAppName;

      if (RegisterClass (&wndclass) == 0) {
          char buf[50];
       
         sprintf(buf, "RegisterClass: error code: 0x%X", GetLastError());
         de_error(buf);
         return(0);
      }
   }
   
   /* Empirically, the command line does not include the command name ...
   if (command_line != 0) {
       while (isspace(*command_line)) command_line++;
       while (*command_line != 0 && !isspace(*command_line)) command_line++;
       while (isspace(*command_line)) command_line++;
   } */
   
   if (command_line == 0 || *command_line == 0) {
        de_error("File name argument required");
        return( 0 );
   } else {
        char *p = command_line;
        
        while (*p != 0 && !isspace(*p)) p++;
       arg_file_name = CORD_to_char_star(
                         CORD_substr(command_line, 0, p - command_line));
   }

   hwnd = CreateWindow (szAppName,
                     FullAppName,
                     WS_OVERLAPPEDWINDOW | WS_CAPTION, /* Window style */
                     CW_USEDEFAULT, 0, /* default pos. */
                     CW_USEDEFAULT, 0, /* default width, height */
                     NULL,  /* No parent */
                     NULL,  /* Window class menu */
                     hInstance, NULL);
   if (hwnd == NULL) {
       char buf[50];
       
       sprintf(buf, "CreateWindow: error code: 0x%X", GetLastError());
       de_error(buf);
       return(0);
   }

   ShowWindow (hwnd, nCmdShow);

   hAccel = LoadAccelerators( hInstance, szAppName );
   
   while (GetMessage (&msg, NULL, 0, 0))
   {
      if( !TranslateAccelerator( hwnd, hAccel, &msg ) )
      {
         TranslateMessage (&msg);
         DispatchMessage (&msg);
      }
   }
   return msg.wParam;
}

Here is the call graph for this function:

LRESULT CALLBACK WndProc ( HWND  hwnd,
UINT  message,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 177 of file de_win.c.

{
   static FARPROC lpfnAboutBox;
   static HANDLE  hInstance;
   HDC dc;
   PAINTSTRUCT ps;
   RECT client_area;
   RECT this_line;
   RECT dummy;
   TEXTMETRIC tm;
   register int i;
   int id;

   switch (message)
   {
      case WM_CREATE:
           hInstance = ( (LPCREATESTRUCT) lParam)->hInstance;
           lpfnAboutBox = MakeProcInstance( (FARPROC) AboutBox, hInstance );
           dc = GetDC(hwnd);
           SelectObject(dc, GetStockObject(SYSTEM_FIXED_FONT));
           GetTextMetrics(dc, &tm);
           ReleaseDC(hwnd, dc);
           char_width = tm.tmAveCharWidth;
           char_height = tm.tmHeight + tm.tmExternalLeading;
           GetClientRect(hwnd, &client_area);
          COLS = (client_area.right - client_area.left)/char_width;
          LINES = (client_area.bottom - client_area.top)/char_height;
          generic_init();
           return(0);

      case WM_CHAR:
          if (wParam == QUIT) {
              SendMessage( hwnd, WM_CLOSE, 0, 0L );
          } else {
              do_command(wParam);
          }
          return(0);
      
      case WM_SETFOCUS:
          CreateCaret(hwnd, NULL, char_width, char_height);
          ShowCaret(hwnd);
          caret_visible = 1;
          update_cursor();
          return(0);
          
      case WM_KILLFOCUS:
          HideCaret(hwnd);
          DestroyCaret();
          caret_visible = 0;
          return(0);
          
      case WM_LBUTTONUP:
          {
              unsigned xpos = LOWORD(lParam);    /* From left  */
              unsigned ypos = HIWORD(lParam);    /* from top */
              
              set_position( xpos/char_width, ypos/char_height );
              return(0);
          }
          
      case WM_COMMAND:
          id = LOWORD(wParam);
          if (id & EDIT_CMD_FLAG) {
               if (id & REPEAT_FLAG) do_command(REPEAT);
               do_command(CHAR_CMD(id));
               return( 0 );
           } else {
             switch(id) {
               case IDM_FILEEXIT:
                  SendMessage( hwnd, WM_CLOSE, 0, 0L );
                  return( 0 );

               case IDM_HELPABOUT:
                  if( DialogBox( hInstance, "ABOUTBOX",
                                 hwnd, lpfnAboutBox ) )
                     InvalidateRect( hwnd, NULL, TRUE );
                  return( 0 );
              case IDM_HELPCONTENTS:
                de_error(
                     "Cursor keys: ^B(left) ^F(right) ^P(up) ^N(down)\n"
                     "Undo: ^U    Write: ^W   Quit:^D  Repeat count: ^R[n]\n"
                     "Top: ^T   Locate (search, find): ^L text ^L\n");
                return( 0 );
            }
          }
           break;

      case WM_CLOSE:
           DestroyWindow( hwnd );
           return 0;

      case WM_DESTROY:
           PostQuitMessage (0);
          GC_win32_free_heap();
           return 0;
      
      case WM_PAINT:
          dc = BeginPaint(hwnd, &ps);
          GetClientRect(hwnd, &client_area);
          COLS = (client_area.right - client_area.left)/char_width;
          LINES = (client_area.bottom - client_area.top)/char_height;
          SelectObject(dc, GetStockObject(SYSTEM_FIXED_FONT));
          for (i = 0; i < LINES; i++) {
              get_line_rect(i, client_area.right, &this_line);
              if (IntersectRect(&dummy, &this_line, &ps.rcPaint)) {
                  CORD raw_line = retrieve_screen_line(i);
                  size_t len = CORD_len(raw_line);
                  char * text = CORD_to_char_star(raw_line);
                            /* May contain embedded NULLs      */
                  char * plain = plain_chars(text, len);
                  char * blanks = CORD_to_char_star(CORD_chars(' ',
                                                          COLS - len));
                  char * control = control_chars(text, len);
#                define RED RGB(255,0,0)
                  
                  SetBkMode(dc, OPAQUE);
                  SetTextColor(dc, GetSysColor(COLOR_WINDOWTEXT));
                  
                  TextOut(dc, this_line.left, this_line.top,
                        plain, len);
                  TextOut(dc, this_line.left + len * char_width, this_line.top,
                        blanks, COLS - len);
                  SetBkMode(dc, TRANSPARENT);
                  SetTextColor(dc, RED);
                  TextOut(dc, this_line.left, this_line.top,
                        control, strlen(control));
              }
          }
          EndPaint(hwnd, &ps);
          screen_was_painted = 1;
          return 0;
   }
   return DefWindowProc (hwnd, message, wParam, lParam);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 171 of file de_win.c.

Definition at line 161 of file de_win.c.

Definition at line 160 of file de_win.c.

int COLS = 0

Definition at line 32 of file de_win.c.

char FullAppName[] = "Demonstration Editor"

Definition at line 35 of file de_win.c.

HWND hwnd

Definition at line 37 of file de_win.c.

Definition at line 313 of file de_win.c.

Definition at line 314 of file de_win.c.

int LINES = 0

Definition at line 31 of file de_win.c.

Definition at line 173 of file de_win.c.

char szAppName[] = "DE"

Definition at line 34 of file de_win.c.