home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / CLISP / CLISPSRC.TAR / clisp-1995-01-01 / src / winmain.d < prev    next >
Encoding:
Text File  |  1994-09-22  |  5.4 KB  |  139 lines

  1. # The main window has input, output and menu.
  2.  
  3. global mywindow main_window; # main window
  4.  
  5. # The event handler for the main window.
  6. local long main_event (mywindow w, UINT message, WPARAM wParam, LPARAM lParam);
  7. local long main_event(w,message,wParam,lParam)
  8.   var mywindow w;
  9.   var UINT message;
  10.   var WPARAM wParam;
  11.   var LPARAM lParam;
  12.   { WINDEBUG( event_out("main_event",w->hWnd,w,message,wParam,lParam); )
  13.     switch (message)
  14.       { case WM_INITMENUPOPUP:
  15.           if (HIWORD(lParam)==0)
  16.             { var HMENU hmenu = (HMENU) wParam;
  17.               EnableMenuItem(hmenu,M_COPY, main_window->text.in_marking==marked ? MF_ENABLED : MF_GRAYED);
  18.               EnableMenuItem(hmenu,M_PASTE, IsClipboardFormatAvailable(CF_TEXT) ? MF_ENABLED : MF_GRAYED);
  19.               EnableMenuItem(hmenu,M_STATUS, status ? MF_ENABLED : MF_GRAYED);
  20.               CheckMenuItem(hmenu,M_STATUS, status_active ? MF_CHECKED : MF_UNCHECKED);
  21.               return 0;
  22.             }
  23.           break;
  24.         case WM_COMMAND: # Menu selection
  25.           switch (wParam)
  26.             { case M_EXIT:
  27.                 SendMessage(w->hWnd,WM_CLOSE,0,0);
  28.                 return 0;
  29.               case M_ABOUT:
  30.                 # display a mix of the files README, SUMMARY and ANNOUNCE
  31.                 MessageBox(w->hWnd,
  32.                            #include "winabout.c"
  33.                            ,
  34.                            "About CLISP",
  35.                            MB_ICONINFORMATION | MB_OK
  36.                           );
  37.                 return 0;
  38.               case M_COPYRIGHT:
  39.                 # display the files COPYRIGHT and GNU-GPL
  40.                 MessageBox(w->hWnd,
  41.                            #include "wincopyr.c"
  42.                            ,
  43.                            "Copyright of CLISP",
  44.                            MB_ICONINFORMATION | MB_OK
  45.                           );
  46.                 return 0;
  47.               case M_STATUS:
  48.                 if (status)
  49.                   { if (!status_active)
  50.                       status_on();
  51.                     else
  52.                       status_off();
  53.                   }
  54.                 return 0;
  55.               default:
  56.                 break;
  57.             }
  58.           break;
  59.         case WM_DESTROY: # while destroying the main window
  60.           if (status_active) { status_off(); } # destroy subwindows
  61.           PostQuitMessage(final_exitcode); # application goes into WM_QUIT state
  62.           return 0;
  63.         default:
  64.           break;
  65.       }
  66.     return w->eventhandler4(w,message,wParam,lParam);
  67.   }
  68.  
  69. # Create the main window.
  70. local boolean main_create (int main_width, int main_height);
  71. local boolean main_create(main_width,main_height)
  72.   var int main_width;
  73.   var int main_height;
  74.   { var mywindow w;
  75.     begin_system_call();
  76.     w = (struct mywindow *) malloc(sizeof(struct mywindow));
  77.     if (!w) { MessageBeep(MB_OK); end_system_call(); return FALSE; }
  78.    {var HWND hWnd =
  79.       CreateWindow(text_class_name,           # registered class name
  80.                    "CLISP",                   # window title
  81.                    WS_OVERLAPPED | WS_CAPTION # window style
  82.                     | WS_SYSMENU | WS_MINIMIZEBOX,
  83.                    CW_USEDEFAULT,             # horizontal position
  84.                    CW_USEDEFAULT,             # vertical position
  85.                    main_width*text_char_size.x         # window width
  86.                     + 2*GetSystemMetrics(SM_CXBORDER),
  87.                    main_height*text_char_size.y        # window height
  88.                     + 2*GetSystemMetrics(SM_CYBORDER)
  89.                     + GetSystemMetrics(SM_CYCAPTION)
  90.                     + GetSystemMetrics(SM_CYMENU),
  91.                    HWND_DESKTOP,              # parent window
  92.                    NULL,                      # menu oder child window id
  93.                    global_hInstance,          # application instance
  94.                    global_lpszCmdLine         # window-creation data
  95.                   );
  96.     # If we didn't succeed in creating a window, abort immediately.
  97.     if (!hWnd)
  98.       { free(w); MessageBeep(MB_OK); end_system_call(); return FALSE; }
  99.     # Set the background brush. (See the doc of WNDCLASS for the +1.)
  100.     SetClassWord(hWnd,GCW_HBRBACKGROUND,COLOR_WINDOW+1);
  101.     # Fill in w:
  102.     w->hWnd = hWnd;
  103.     w->in_focus = FALSE;
  104.     w->for_output = w->for_input = TRUE;
  105.     w->eventhandler1 = text_event;
  106.     w->eventhandler2 = textio_event;
  107.     w->eventhandler3 = main_event;
  108.     w->eventhandler4 = default_event;
  109.     w->text.width = main_width; w->text.height = main_height;
  110.     w->text.contents = malloc(main_height*sizeof(char*)); # check??
  111.     { var uintL y;
  112.       for (y = 0; y < main_height; y++)
  113.         w->text.contents[y] = malloc(main_width*sizeof(char)); # check??
  114.     }
  115.     w->text.in_marking = none;
  116.     w->text.cursor.x = 0; w->text.cursor.y = 0;
  117.     w->text.cursor_visible = FALSE;
  118.     w->input.ev_fifo = (event*) malloc((w->input.ev_fifo_size = 16)*sizeof(event));
  119.     w->input.ev_fifo_out = w->input.ev_fifo_in = &w->input.ev_fifo[0];
  120.     w->input.in_paste = FALSE;
  121.     w->textinput.line = (char*) malloc((w->textinput.line_size = 80)*sizeof(char));
  122.     w->textinput.count = 0; w->textinput.index = 0;
  123.     end_system_call();
  124.     register_window(w);
  125.     text_clear(w);
  126.     main_window = w;
  127.     return TRUE;
  128.   }}
  129.  
  130.  
  131. # Keyboard input from the main window:
  132. global boolean win_main_kbhit (void);
  133. global cint win_main_getch (void);
  134. global boolean win_main_kbhit()
  135.   { return win_kbhit(main_window); }
  136. global cint win_main_getch()
  137.   { return win_getch(main_window); }
  138.  
  139.