home *** CD-ROM | disk | FTP | other *** search
- /*======================================================*/
- /* UIWOPEN.C */
- /* */
- /* (c) Copyright 1988 Ralf Brown. All Rights Reserved. */
- /*======================================================*/
-
- #include <bios.h>
- #include "tvapi.h"
- #include "tvui.h"
-
- /*================================================*/
- /*================================================*/
-
- static void pascal near box(OBJECT win,int rows,int cols)
- {
- int attr = TVqry_logattr(win)?9:135 ;
- int i ;
-
- TVwin_cursor(win,0,0) ;
- TVputchar(win,'╔',attr) ;
- for (i = 0 ; i < cols ; i++)
- TVputchar(win,'═',attr) ;
- TVputchar(win,'╗',attr) ;
- for (i = 1 ; i <= rows ; i++)
- {
- TVwin_cursor(win,i,0) ;
- TVputchar(win,'║',attr) ;
- TVwin_cursor(win,i,cols+1) ;
- TVputchar(win,'║',attr) ;
- }
- TVwin_cursor(win,rows+1,0) ;
- TVputchar(win,'╚',attr) ;
- for (i = 0 ; i < cols ; i++)
- TVputchar(win,'═',attr) ;
- TVputchar(win,'╝',attr) ;
- TVwin_cursor(win,0,0) ;
- }
-
- /*================================================*/
- /* UIwin_open allow user to choose size and loc */
- /* of a window which is to be opened */
- /* Ralf Brown 7/29/88 */
- /*================================================*/
-
- OBJECT pascal UIwin_open(OBJECT parent,int minrows,int mincols,
- int maxrows,int maxcols, int defrows,int defcols)
- {
- OBJECT p, w, mw ;
- int row, col ;
- int rows, cols ;
- POINTER_MSG msg ;
- int new_message ;
- int left_button = FALSE, right_button = FALSE ;
-
- if (minrows < 0) minrows = 0 ;
- if (mincols < 0) mincols = 0 ;
- if (defrows < minrows) defrows = minrows ;
- if (defcols < mincols) defcols = mincols ;
- if ((w = TVwin_new(parent,defrows>5?defrows:5,defcols>9?defcols:9)) == NIL)
- return NIL ;
- if ((p = TVptr_new()) == NIL)
- {
- TVwin_free(w) ;
- return NIL ;
- }
- if ((mw = TVwin_new(parent,1,32)) != NIL)
- {
- TVwin_title(mw,"Open Window") ;
- TVwin_move(mw,1,1) ;
- TVwin_cursor(mw,0,0) ;
- TVwin_swrite(mw,"Drag window to desired position") ;
- TVwin_topsys(mw) ;
- }
- TVptr_open(p,w) ;
- if (TVqry_kmouse())
- TVapi_kmouse(TRUE) ;
- TVptr_setflags(p,PTR_RELEASE | PTR_HIDDEN | PTR_ABSOLUTE) ;
- TVqry_position(parent,&row,&col) ;
- TVptr_goto(p,row+defrows/2,col+defcols/2) ;
- TVptr_clrflags(p,PTR_ABSOLUTE) ;
- TVwin_clear(w) ;
- TVwin_cursor(w,0,0) ;
- TVwin_move(w,row,col) ;
- /* use reverse video frame if logical attributes, blinking if physical */
- TVwin_frattr(w,TVqry_logattr(w)?9:143) ;
- TVwin_top(w) ;
- new_message = FALSE ;
- do {
- TVptr_read(p,&msg) ;
- if (!new_message && mw)
- {
- new_message = TRUE ;
- TVwin_cursor(mw,0,0) ;
- TVwin_swrite(mw,"Left button: done Right: cancel") ;
- TVwin_redraw(mw) ;
- }
- row += msg.row - defrows/2 ;
- col += msg.column - defcols/2 ;
- if (msg.button_state == 0x81)
- left_button = TRUE ;
- else if (msg.button_state == 0x82)
- right_button = TRUE ;
- TVwin_move(w,row,col) ;
- TVwin_redraw(w) ;
- } while (!left_button && !right_button) ;
- if (right_button)
- {
- TVwin_free(mw) ;
- TVwin_free(w) ;
- TVptr_free(p) ;
- if (TVqry_kmouse())
- TVapi_kmouse(FALSE) ;
- return NIL ;
- }
- rows = defrows ;
- cols = defcols ;
- if (mw)
- {
- TVwin_cursor(mw,0,0) ;
- TVwin_swrite(mw,"Size window and click button ") ;
- TVwin_redraw(mw) ;
- }
- TVptr_setflags(p,PTR_ABSOLUTE) ;
- TVptr_goto(p,row+rows,col+cols) ;
- TVwin_frame(w,FALSE) ;
- TVwin_move(w,row-1,col-1) ;
- TVwin_lsize(w,rows+4,cols+7) ;
- TVwin_resize(w,rows+4,cols+7) ;
- box(w,rows,cols) ;
- TVwin_redraw(w) ;
- do {
- TVptr_read(p,&msg) ;
- rows = msg.row-row ;
- cols = msg.column-col ;
- if (rows >= minrows && cols >= mincols)
- {
- TVwin_lsize(w,rows+4,cols+7) ;
- TVwin_resize(w,rows+4,cols+7) ;
- TVwin_clear(w) ;
- box(w,rows,cols) ;
- TVwin_redraw(w) ;
- }
- } while ((msg.button_state & 0x41) != 0x41) ; /* until left button is released */
- TVwin_clear(w) ;
- TVwin_lsize(w,rows,cols) ;
- TVwin_resize(w,rows,cols) ;
- TVwin_move(w,row,col) ;
- TVwin_frame(w,TRUE) ;
- if (TVqry_kmouse())
- TVapi_kmouse(FALSE) ;
- TVptr_free(p) ;
- TVwin_free(mw) ;
- if (rows > maxrows)
- rows = maxrows ;
- if (cols > maxcols)
- cols = maxcols ;
- TVwin_resize(w,rows,cols) ;
- TVwin_frattr(w,TVqry_logattr(w)?1:7) ;
- return w ;
- }
-
- /* End of UIWOPEN.C */
-