home *** CD-ROM | disk | FTP | other *** search
- # $Header: P:/source/ppee/macros/library.pev 1.35 27 Aug 1990 12:41:06 ericj $
-
- ##############################################################################
- #
- # Sage Software - POLYTRON Division
- # 1700 NW 167th Place
- # Beaverton, OR 97006
- #
- # Copyright 1990, Sage Software, Inc.
- #
- # Permission is hereby granted for licensed users of Sage Professional
- # Editor and PolyAwk to copy and modify this source code for their own
- # personal use. These derivative works may be distributed only to other
- # licensed Sage Professional Editor and PolyAwk users. All other usage
- # is prohibited without express written permission from Sage Software.
- #
- ##############################################################################
-
- #### $Workfile: library.pel $: On line reference manual
-
- local libraryBuffer; # buffer containing reference material in file
- local libraryListBuffer; # buffer containing list of reference names
- local libraryDispBuffer; # buffer containing reference information
- local lastLibraryLine = 1 # line displayed during last call to library()
-
- local srchfwdregex = 0x35; # search_flags
- #local srchbwdregex = 0x31; # search_flags
- local srchfwdregexwrap = 0x3D # search_flags
-
- local saveWindow;
- local saveBuffer;
- local libraryListWindow; # window containing list of reference names
- local libraryDispWindow; # window containing reference information
- local indexArray[];
- local tmpArray[];
-
- local windowHeight;
-
- local libraryInitialized = 0;
- local libraryResident = 0;
- local libraryId; # function id of libraryWindowHandler()
-
- local save_last_window;
-
-
- local function library_init() {
- local buffOff;
- local len;
- local str;
- local cb = current_buffer;
- local save_eol_str = default_buffer_eol_string;
- local size;
- local txtfile
-
-
- message( "Initializing Library System..." );
-
- init_menu_colors();
-
- # search sageedit path for the on-line manual
- if ( !(txtfile = locate_sageedit_file(SAGEEDIT_FILE_REFMAN))) {
- txtfile = editor_path( SAGEEDIT_FILE_REFMAN )
- }
-
- default_buffer_eol_string = "\010";
- current_buffer =
- libraryBuffer = create_buffer( "", txtfile,
- BUFFER_READ_ONLY + BUFFER_SYSTEM + BUFFER_NO_UNDO + BUFFER_REAL_SPACE_ONLY)
- buffer_flags = and( buffer_flags, not(BUFFER_READ_ONLY) );
- size = buffer_size;
- current_buffer = cb;
- if (!size) {
- # couldn't find the help information
- default_buffer_eol_string = save_eol_str;
- notify( "Cannot find help information in: %s", txtfile );
- delete_buffer( libraryBuffer );
- return FALSE;
- }
-
-
- default_buffer_eol_string = "\r";
- libraryListBuffer = create_buffer( \
- "Library", \
- "", \
- BUFFER_SYSTEM + BUFFER_NO_UNDO + BUFFER_REAL_SPACE_ONLY )
-
- default_buffer_eol_string = "\010";
- libraryDispBuffer = create_buffer( \
- "Library", \
- "", \
- BUFFER_SYSTEM + BUFFER_NO_UNDO + BUFFER_REAL_SPACE_ONLY )
- default_buffer_eol_string = save_eol_str;
-
- #
- # read the offset of the indices and library text from the first two
- # lines in the library file
- #
- current_buffer = libraryListBuffer;
- transfer( libraryBuffer, 1, 1, 1, 8000 );
- goto_buffer_bottom();
- backspace();
-
- current_buffer = libraryBuffer;
- delete_line();
- split( read_buffer(), indexArray, "\r" );
- delete_line();
-
- current_buffer = cb;
- message( "" );
-
- libraryInitialized = 1;
- return TRUE;
- }
-
-
-
- global function library( item ) {
- local x0 = 3
- local y0 = 3
- local libraryListWindowWidth = 22
- local is_diag = 0+dialog_window
- local cb;
-
- if (!is_diag)
- toggle_dialog( 1 );
-
-
- if (libraryResident) {
- delete_event( EVENT_NEW_CURNT_WINDOW, libraryId );
- libraryResident = 0;
- }
-
- saveWindow = current_window;
- saveBuffer = current_buffer;
-
- windowHeight = display_height - y0 -y0;
-
- if (!libraryInitialized)
- if (!library_init()) {
- toggle_dialog( is_diag )
- return;
- }
-
-
- if (item) {
- cb = current_buffer;
- current_buffer = libraryListBuffer;
- if ( search( " " item, or(srchfwdregex, SEARCH_WRAPS) ) ){
- lastLibraryLine = current_line;
- current_buffer = cb;
- } else {
- current_buffer = cb;
- toggle_dialog( is_diag );
- beep();
- return;
- }
- }
-
-
- if (libraryDispWindow) {
- raise_window( libraryDispWindow );
- } else {
- #
- # create the display window which will contain the library text
- #
- current_window =
- libraryDispWindow = create_factory_window( x0+libraryListWindowWidth, y0, display_width - x0 - libraryListWindowWidth - x0,
- windowHeight,
- WINDOW_SYSTEM + WINDOW_SB_BELOW + WINDOW_SB_RIGHT + WINDOW_BORDER );
-
- initLibraryAttributes( 1 );
- attach_window_buffer( libraryDispWindow, libraryDispBuffer );
- }
-
-
- if (libraryListWindow) {
- raise_window( libraryListWindow );
- } else {
- #
- # create the list window which will contain the list of available
- # library items
- #
- current_window =
- libraryListWindow = create_factory_window( x0, y0, libraryListWindowWidth, windowHeight,
- WINDOW_SYSTEM + WINDOW_SB_BELOW + WINDOW_SB_RIGHT + WINDOW_BORDER );
- attach_window_buffer( libraryListWindow, libraryListBuffer );
- initLibraryAttributes( 2 );
- }
-
- current_window = libraryListWindow;
- current_buffer = libraryListBuffer;
- goto_buffer_top();
-
- current_line = lastLibraryLine;
-
- menu_search();
-
- save_last_window = current_window;
-
- toggle_dialog( is_diag )
- }
-
-
- #
- # initialize the attribute and window names for the library windows
- # win == 1 setting display window, win == 2 setting list window
- #
- local function initLibraryAttributes( win ) {
-
- color_border = BAR_COLOR;
- color_text = BAR_COLOR;
- color_highlight = HBAR_COLOR
- visible_virtual_lines = "";
- visible_virtual_spaces = "";
- visible_end_buffer = "";
-
- }
-
-
- local function showLibraryItem( lineNum, clear_anchor ) {
- local cw = current_window;
-
- #
- # locate the item in the database
- #
-
- split( indexArray[ lineNum ], tmpArray, " " );
-
- current_window = libraryDispWindow;
-
- if (clear_anchor)
- raise_anchor();
-
- goto_buffer_top();
- drop_anchor();
- goto_buffer_bottom();
- delete_chars();
-
- transfer( libraryBuffer, atoi( tmpArray[1] ), 1, atoi( tmpArray[2]), 8000 );
- buffer_tabs = "6"
- down()
- insert_string( "────────────────────────────────────────────────\n" );
- goto_buffer_top();
-
- if (cw)
- current_window = cw;
- }
-
- local function menu_search() {
- local ch;
- local xy_win
- local mpos;
-
- #
- # reset the position to the top of the list and highlight the
- # first entry
- #
- drop_anchor( LINE_SELECTION )
- updateItem( 1 )
-
- do {
- display_update(); # update the screen
-
- ch = getchar();
-
- if (ch == 0) {
- ch = getchar(); # expanded code, get rest of key
- if (ch == SCANCODE_DOWN) {
- menu_down(1)
- } else if (ch == SCANCODE_UP) {
- menu_up(1)
- } else if (ch == SCANCODE_PGUP) {
- menu_up( window_height-1 )
- } else if (ch == SCANCODE_PGDN) {
- menu_down( window_height-1 )
- } else if ((ch == 0x8d) || (ch == SCANCODE_LEFT)) {
- libraryDisplayUp();
- continue;
- } else if ((ch == 0x91) || (ch == SCANCODE_RIGHT)) {
- libraryDisplayDn();
- continue;
- } else if ((ch == SCANCODE_LEFT_PRESS) || \
- (ch == SCANCODE_RIGHT_PRESS) || \
- (ch == SCANCODE_LEFT_CLICK)) {
- xy_win = window_containing( mouse_event_x, mouse_event_y );
- if ( (xy_win == libraryListWindow) ||
- (xy_win == libraryDispWindow) ) {
- mpos = mouse_position(1);
- if ( !and(mpos,MOUSE_W) ){
- if (!((current_window == libraryListWindow) && \
- (ch == SCANCODE_RIGHT_PRESS))) {
- assign_current_window( xy_win );
- setHighlightedScrolling( current_window == libraryListWindow );
- if (ch == SCANCODE_RIGHT_PRESS)
- right_press( 1 );
- else # LEFT PRESS or CLICK
- left_press( 1 );
-
- display_update();
- setHighlightedScrolling( 0 );
- }
- }
- current_window = libraryListWindow;
- display_update();
- } else if (xy_win) {
- raise_anchor();
- assign_current_window( xy_win );
- installLibraryHandler();
- ungetkey( shiftl(ch,8) );
- return;
- }
-
- if ( !region_type() )
- drop_anchor( LINE_SELECTION );
- }
- } else {
- if (ch == ASCII_ESC) {
- prev_window();
- esc();
- return;
- } else if (ch == ASCII_CR) {
- current_window = libraryDispWindow;
- #
- # copy any marked block to scrap
- # and return
- #
- if (region_type()) {
- copy_to_scrap();
- raise_anchor();
- }
- current_window = libraryListWindow;
- prev_window()
- installLibraryHandler();
- return;
- } else {
- menu_search_i( ch );
- }
- }
- updateItem()
- } while (TRUE);
- }
-
-
- global function libraryWindowHandler(){
- if ( and(mouse_buttons, LEFT_BUTTON) ||
- (current_key == LEFT_CLICK) ||
- (current_key == LEFT_PRESS) ) {
- if ((current_window == libraryListWindow) ||
- (current_window == libraryDispWindow)) {
- library();
-
- assign_current_window( save_last_window );
-
- # see if the save_last_window was deleted
- if ((current_window == libraryListWindow) ||
- (current_window == libraryDispWindow))
- prev_window();
- # flush_keyboard();
- }
- } else if ( !and(window_flags, WINDOW_SYSTEM) )
- save_last_window = current_window;
- }
-
- local function installLibraryHandler(){
- libraryResident = 1;
- libraryId = function_id( "libraryWindowHandler" );
- attach_event_handler( EVENT_NEW_CURNT_WINDOW, libraryId );
- }
-
- local function libraryDisplayDn(){
- scrollDispWindow( 2 );
- }
-
- local function libraryDisplayUp(){
- scrollDispWindow( -2 );
- }
-
- local function scrollDispWindow( inc ){
- current_window = libraryDispWindow;
- scroll_vertical( inc, 1 );
- current_window = libraryListWindow;
- # flush_keyboard();
- }
-
-
- #
- # process an escape key pressed from within the dir menu
- #
- local function esc() {
- raise_anchor();
- assign_current_window( saveWindow );
- current_buffer = saveBuffer;
- delete_window( libraryListWindow )
- delete_window( libraryDispWindow )
- libraryListWindow = 0;
- libraryDispWindow = 0;
- current_key = 0;
- message( "" );
- }
-
-
- #
- # process a down key press from within the dir menu
- #
- local function menu_down( lines ) {
-
- if ( down( lines )) {
- #
- # redisplay the highlight on the new selection
- #
- raise_anchor()
- drop_anchor( LINE_SELECTION )
- }
- }
-
-
- #
- # process an up key press from within the dir menu
- #
- local function menu_up( lines ){
-
- if ( up( lines )) {
- #
- # redisplay the highlight on the new selection
- #
- raise_anchor()
- drop_anchor( LINE_SELECTION )
- }
- }
-
-
- local function menu_search_i( ch ) {
- local pattern = "",
- char = "",
- level = 0
-
- display_update();
-
- while (TRUE) {
-
- if ((ch == 0) || (ch == ASCII_ESC) || (ch == ASCII_CR)) {
- break;
- } else if (ch == ASCII_BACKSPACE) {
- #
- # remove the last char in the search string and
- # restore the previous position
- #
- pattern = substr( pattern, 0, length( pattern ) - 1)
- if (level) {
- raise_anchor()
- restore_position( TRUE );
- drop_anchor( LINE_SELECTION );
- level--;
- }
- } else {
- #
- # It is a normal ascii character.
- # Let's search for the new pattern. If we find it,
- # save the previous position and advance to the
- # newly found string.
- #
- char = chr( ch );
- raise_anchor();
- save_position();
- if (search( " " pattern char, srchfwdregexwrap )){
- pattern = pattern char
- level++;
- } else {
- beep();
- restore_position( FALSE );
- }
- drop_anchor( LINE_SELECTION );
- message( "Library-Search for: %s\137", pattern)
- }
- updateItem( 1 )
-
- display_update()
-
- # display the prompt message with a fake cursor
- message( "Library-Search for: %s\334", pattern)
-
- # get the next ascii character from the keyboard
- # ignore extended character which have an ascii code of 0
- ch = getchar()
- }
-
- message( "" );
-
- while (level--)
- restore_position( FALSE );
-
- display_update();
- ungetkey( ch );
- }
-
- local function updateItem( force_update ) {
- local cb = current_buffer;
-
- if (keyboard_input_pending == 0) {
- if (force_update || (lastLibraryLine != current_line)) {
- showLibraryItem( current_line, lastLibraryLine != current_line );
- lastLibraryLine = current_line;
- # flush_keyboard();
- }
- }
- }
-