home *** CD-ROM | disk | FTP | other *** search
- /* w4init.c Setup Routines (c)Copyright Sequiter Software Inc., 1991. All rights reserved. */
-
- #include "c4window.h"
- #include "e4error.h"
-
- #ifdef __TURBOC__
- #pragma hdrstop
- #endif
-
- C4WINDOWS *S4FUNCTION w4init( HANDLE hInst, HANDLE hParentWindow )
- {
- WNDCLASS wc ;
- C4WINDOWS *cw ;
-
- #ifdef S4DEBUG
- if ( GetWindowWord( hParentWindow, GWW_HINSTANCE ) != hInst )
- {
- e4severe( e4parm, "w4init", (char *) 0 ) ;
- return 0 ;
- }
- #endif
-
- if ( GetClassInfo( hInst, "B4BROWSE", &wc ) == 0 )
- {
- wc.style = NULL ;
- wc.lpfnWndProc = entry4_proc ;
- wc.cbClsExtra = 0 ;
- wc.cbWndExtra = sizeof( LONG ) ;
- wc.hInstance = hInst ;
- wc.hIcon = LoadIcon( NULL, IDI_APPLICATION ) ;
- wc.hCursor = LoadCursor( NULL, IDC_ARROW ) ;
- wc.hbrBackground = GetStockObject( WHITE_BRUSH ) ;
- wc.lpszMenuName = 0 ;
- wc.lpszClassName = "W4ENTRY" ;
-
- if ( RegisterClass( &wc ) == 0 )
- return 0 ;
-
- wc.lpfnWndProc = browse4_proc ;
- wc.lpszClassName = "B4BROWSE" ;
- wc.lpszMenuName = "B4MENU" ;
-
- if ( RegisterClass( &wc ) == 0 )
- return 0 ;
-
- wc.lpfnWndProc = browse4_area_proc ;
- wc.lpszClassName = "B4AREA" ;
- wc.lpszMenuName = 0 ;
-
- if ( RegisterClass( &wc ) == 0 )
- return 0 ;
-
- wc.style = CS_PARENTDC ;
- wc.lpfnWndProc = edit4_proc ;
- wc.lpszClassName = "G4EDIT" ;
-
- if ( RegisterClass( &wc ) == 0 )
- return 0 ;
- }
-
- cw = (C4WINDOWS *) u4alloc( sizeof( C4WINDOWS ) ) ;
- if ( cw == 0 )
- {
- e4severe( e4memory, "w4init()", (char *) 0 ) ;
- return 0 ;
- }
- d4init( &cw->cb ) ;
-
- cw->TypeOver = 0 ;
- cw->bad_date = 0 ;
-
- cw->cb.hWnd = hParentWindow ;
- cw->cb.hInst = hInst ;
-
- #ifdef S4DLL
- cw->button4_proc = (FARPROC) button4_proc ;
- cw->combo4_proc = (FARPROC) combo4_proc ;
- cw->list4_proc = (FARPROC) list4_proc ;
- #else
- cw->button4_proc = MakeProcInstance( (FARPROC) button4_proc, hInst ) ;
- cw->combo4_proc = MakeProcInstance( (FARPROC) combo4_proc, hInst ) ;
- cw->list4_proc = MakeProcInstance( (FARPROC) list4_proc, hInst ) ;
- #endif
-
- cw->combo_arrow = LoadBitmap( NULL, (LPSTR) OBM_COMBO ) ;
-
- if ( (cw->button4_proc == 0) || (cw->combo4_proc == 0) ||
- (cw->list4_proc == 0) || (cw->combo_arrow == 0) )
- {
- w4init_undo( cw ) ;
- return 0 ;
- }
- return cw ;
- }
-
- void S4FUNCTION w4init_undo( C4WINDOWS *cw )
- {
- /* this assumes that all windows from these classes have been destroyed */
-
- UnregisterClass( "W4ENTRY", cw->cb.hInst ) ;
- UnregisterClass( "B4BROWSE", cw->cb.hInst ) ;
- UnregisterClass( "B4AREA", cw->cb.hInst ) ;
- UnregisterClass( "G4EDIT", cw->cb.hInst ) ;
-
- #ifndef S4DLL
- FreeProcInstance( (FARPROC) cw->button4_proc ) ;
- FreeProcInstance( (FARPROC) cw->combo4_proc ) ;
- FreeProcInstance( (FARPROC) cw->list4_proc ) ;
- cw->button4_proc = 0 ;
- cw->combo4_proc = 0 ;
- cw->list4_proc = 0 ;
- #endif
-
- if ( cw->combo_arrow != 0 )
- DeleteObject( cw->combo_arrow ) ;
-
- d4init_undo( &cw->cb ) ;
- u4free( cw ) ;
- }
-
- long FAR PASCAL _export browse4_area_proc( HWND hWnd, UINT message,
- UINT wParam, LONG lParam )
- {
- int rc = 0 ;
-
- B4AREA *ba = (B4AREA *) GetWindowLong( hWnd, 0 ) ;
-
- if ( ba != 0 )
- rc = browse4_area_process_message( ba, message, wParam, lParam ) ;
- if ( rc == 0 )
- return DefWindowProc( hWnd, message, wParam, lParam ) ;
-
- return 0 ;
- }
-
- long FAR PASCAL _export browse4_proc( HWND hWnd, UINT message, UINT wParam,
- LONG lParam )
- {
- int rc = 0 ;
-
- B4BROWSE *bw = (B4BROWSE *) GetWindowLong( hWnd, 0 ) ;
-
- if ( bw != 0 )
- rc = browse4_process_message( bw, message, wParam, lParam ) ;
- if ( rc == 0 )
- return DefWindowProc( hWnd, message, wParam, lParam ) ;
-
- return 0 ;
- }
-
- long FAR PASCAL _export entry4_proc( HWND hWnd, UINT message, UINT wParam,
- LONG lParam )
- {
- int rc = 0 ;
-
- W4ENTRY *ew = (W4ENTRY *) GetWindowLong( hWnd, 0 ) ;
-
- if ( ew != 0 )
- rc = entry4_process_message( ew, message, wParam, lParam ) ;
- if ( rc == 0 )
- return DefWindowProc( hWnd, message, wParam, lParam ) ;
-
- return 0 ;
- }
-
- long FAR PASCAL _export edit4_proc( HWND hWnd, UINT message, UINT wParam,
- LONG lParam )
- {
- int rc = 0 ;
-
- G4EDIT *ea = (G4EDIT *) GetWindowLong( hWnd, 0 ) ;
-
- if ( ea != 0 )
- rc = edit4_process_message( ea, message, wParam, lParam ) ;
- if ( rc == 0 )
- return DefWindowProc( hWnd, message, wParam, lParam ) ;
-
- return 0 ;
- }
-
- long FAR PASCAL _export button4_proc( HWND hWnd, UINT message, UINT wParam,
- LONG lParam )
- {
- int id = GetWindowWord( hWnd, GWW_ID ) ;
- int parent = GetWindowWord( hWnd, GWW_HWNDPARENT ) ;
- W4ENTRY *ew = (W4ENTRY *) GetWindowLong( parent, 0 ) ;
-
- if ( ew != 0 )
- {
- G4BUTTON *button = g4lookup_button( ew, id ) ;
- if ( button != 0 )
- {
- int rc = button4_process_message( button, message, wParam, lParam ) ;
- if ( rc == 0 )
- return CallWindowProc( button->ca.gw.OldWindowProc, hWnd, message,
- wParam, lParam ) ;
- }
- return 0 ;
- }
- return DefWindowProc( hWnd, message, wParam, lParam ) ;
- }
-
- long FAR PASCAL _export list4_proc( HWND hWnd, UINT message, UINT wParam,
- LONG lParam )
- {
- int id = GetWindowWord( hWnd, GWW_ID ) ;
- int parent = GetWindowWord( hWnd, GWW_HWNDPARENT ) ;
- W4ENTRY *ew = (W4ENTRY *) GetWindowLong( parent, 0 ) ;
-
- if ( ew != 0 )
- {
- G4LIST *list = g4lookup_list( ew, id ) ;
- if ( list != 0 )
- {
- int rc = list4_process_message( list, message, wParam, lParam ) ;
- if ( rc == 0 )
- return CallWindowProc( list->ca.gw.OldWindowProc, hWnd, message,
- wParam, lParam ) ;
- }
- return 0 ;
- }
- return DefWindowProc( hWnd, message, wParam, lParam ) ;
- }
-
- long FAR PASCAL _export combo4_proc( HWND hWnd, UINT message, UINT wParam,
- LONG lParam )
- {
- int id = GetWindowWord( hWnd, GWW_ID ) ;
- int parent = GetWindowWord( hWnd, GWW_HWNDPARENT ) ;
- W4ENTRY *ew = (W4ENTRY *) GetWindowLong( parent, 0 ) ;
-
- if ( ew != 0 )
- {
- G4EDIT *edit = g4lookup_edit( ew, id ) ;
- G4COMBO *combo = (G4COMBO *) edit->combo ;
- if ( combo != 0 )
- {
- int rc = combo4_process_message( combo, message, wParam, lParam ) ;
- if ( rc == 0 )
- return CallWindowProc( combo->edit.ca.gw.OldWindowProc, hWnd,
- message, wParam, lParam ) ;
- }
- return 0 ;
- }
- return DefWindowProc( hWnd, message, wParam, lParam ) ;
- }
-
- HDC S4FUNCTION w4get_dc( C4CODE *cb, HWND hwnd )
- {
- HDC hDC = GetDC( hwnd ) ;
- if ( hDC == NULL )
- return e4error( cb, 0, E4_RESULT_GDC, (char *) 0 ) ;
-
- return hDC ;
- }
-
- int S4FUNCTION w4release_dc( C4CODE *cb, HWND hwnd, HDC hDC )
- {
- if ( ReleaseDC( hwnd, hDC ) ) return 1 ;
-
- return e4error( cb, 0, E4_RESULT_RDC, (char *) 0 ) ;
- }
-
- HWND S4FUNCTION w4create_window( char *class_name, char *caption, DWORD style, int x, int y, int width,
- int height, HWND parent, HMENU menu, HANDLE hInst, char *lParam )
- {
- HWND hwnd = CreateWindow( class_name, caption, style, x, y, width, height,
- parent, menu, hInst, lParam ) ;
- if ( hwnd == 0 )
- e4severe( e4result, E4_RESULT_WIN, (char *) 0 ) ;
- return hwnd ;
- }
-
- void S4FUNCTION w4get_metrics( HDC hDC, TEXTMETRIC *metrics )
- {
- if ( GetTextMetrics( hDC, metrics ) == 0 )
- e4severe( e4result, E4_RESULT_GTM, (char *) 0 ) ;
- }
-
- void S4FUNCTION w4get_rect( HWND hwnd, RECT *r, int type )
- {
- if ( type == 0 )
- GetClientRect( hwnd, r ) ;
- else
- GetWindowRect( hwnd, r ) ;
-
- #ifdef S4DEBUG
- if ( (r->bottom <= 0) || (r->right <= 0) )
- e4severe( e4parm, E4_PARM_WIN, (char *) 0 ) ;
- #endif
- }
-
- /* note, if fields used, the record will be marked as changed, thus will be
- written to disk at next available time */
-
- int S4FUNCTION w4save( W4ENTRY *ew )
- {
- return entry4_controlssave( ew ) ;
- }
-
- int S4FUNCTION w4refresh( W4ENTRY *ew )
- {
- return entry4_controlsrefresh( ew ) ;
- }
-