home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / windows / c / lckowl15 / lckowl.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-08  |  23.2 KB  |  930 lines

  1. /************************************************************************
  2.  
  3.     Software:    LCKOWL.DLL
  4.  
  5.     Version:    1.5
  6.             Copyright by Larry Klein, LCK Consulting, December 15, 1992
  7.  
  8.     Developed By:    Larry Klein
  9.             LCK Consulting
  10.             732 Symphony Woods Drive
  11.             Silver Spring, MD  20901
  12.             Phone - 301-593-2745
  13.             Fax   - 301-593-4262
  14.             Compuserve - 76330,2525
  15.  
  16.     Purpose:    BC++ OWL-derived MDI Frame class that automatically manages
  17.                 a status bar, tool bar and toolbox.
  18.             BC++ OWL-derived Window classes that add administrative
  19.                 features lacking in OWL.
  20.  
  21.     Requirements:    Borland C++ Compiler 3.0 or higher
  22.             LCKUtil.DLL for error message handling
  23.  
  24.     Requirements    Drover's Toolbox by Farpoint
  25.     For Extending        FarPoint Technologies
  26.     LCKOWL.DLL:        P.O. Box 309
  27.                 75 Walnut Street
  28.                 Richmond, Ohio  43944-0309
  29.                 Phone: 614-765-4333
  30.                 Fax:   614-765-4939
  31.  
  32.             DataTable by ProtoView Development Corp
  33.                 ProtoView Development Corp
  34.                 353 Georges Road
  35.                 Dayton, NJ  08810
  36.                 Phone: 908-329-8588
  37.                                    Fax:   908-329-8624
  38.  
  39.     NOTE:        This product was developed by LCK
  40.             Consulting as shareware for general use.
  41.             This software and associated
  42.             documentation are provided "as-is" and
  43.             without any express or implied
  44.             warranties whatsoever.  The user is
  45.             advised to test the program thoroughly
  46.             before relying on it.  The user assumes
  47.             the entire risk of using the program.
  48.  
  49.     Shareware:    If this program is utilized to your
  50.             satisfaction, a $20 shareware fee can be
  51.             sent to the LCK Consulting.  This fee
  52.             will go towards upgrading the product.
  53.             Your name and address will be placed on
  54.             a mailing list for further upgrades.
  55.             Where possible, include any bulletin
  56.             board address to which notifications can
  57.             be sent.
  58.  
  59.  
  60. ************************************************************************/
  61.  
  62. #include "windows.h"
  63. extern "C" {
  64. #include "toolbox.h"
  65. }
  66. #include "lckowl.h"
  67. #include "lckutil.h"
  68.  
  69. char        szAppName[]     = "LCK OWL Extension";
  70. char        szNull[]    = "";
  71.  
  72. PTModule     TheModule;
  73.  
  74. TWindowTools::TWindowTools(PTWindowsObject AParent, LPSTR ATitle, WORD AWindowType)
  75.     : TWindow(AParent, ATitle)
  76. {
  77.     StatusBar = NULL;
  78.     ToolBar = NULL;
  79.     ToolBox = NULL;
  80.     strncpy(szClassName, ATitle, LCK_MAXLEN_CLASSNAME);
  81.         szClassName[LCK_MAXLEN_CLASSNAME] = NULL;
  82.     SetFlags(WB_KBHANDLER, FALSE);
  83.     wWindowType = AWindowType;
  84.     bResize = TRUE;
  85.     bMDIMenu = FALSE;
  86. };
  87.  
  88. TWindowTools::~TWindowTools()
  89. {
  90.     if(StatusBar) delete StatusBar;
  91.     if(ToolBar) delete ToolBar;
  92.     if(ToolBox) delete ToolBox;
  93. }
  94.  
  95. void    TWindowTools::CMCreateStatusBar(RTMessage Msg)
  96. {
  97.     if( StatusBar && !StatusBar->Exists() ) {
  98.         StatusBar->Create(HWindow);
  99.         Resize();
  100.     }
  101.     DefCommandProc(Msg);
  102. }
  103.  
  104. void    TWindowTools::CMCreateToolBar(RTMessage Msg)
  105. {
  106.     if( ToolBar && !ToolBar->Exists() ) {
  107.         ToolBar->Create(GetApplication()->hInstance, HWindow);
  108.         Resize();
  109.     }
  110.     DefCommandProc(Msg);
  111. }
  112.  
  113. void    TWindowTools::CMCreateToolBox(RTMessage Msg)
  114. {
  115.     if( ToolBox && !ToolBox->Exists() ) {
  116.         ToolBox->Create(GetApplication()->hInstance, HWindow);
  117.         Resize();
  118.     }
  119.     DefCommandProc(Msg);
  120. }
  121.  
  122. void     TWindowTools::CMDestroyStatusBar(RTMessage Msg)
  123. {
  124.     if( StatusBar && StatusBar->Exists() ) {
  125.         StatusBar->Destroy();
  126.         Resize();
  127.     }
  128.     DefCommandProc(Msg);
  129. }
  130.  
  131. void     TWindowTools::CMDestroyToolBar(RTMessage Msg)
  132. {
  133.     if( ToolBar && ToolBar->Exists() ) {
  134.         ToolBar->Destroy();
  135.         Resize();
  136.     }
  137.     DefCommandProc(Msg);
  138. }
  139.  
  140. void     TWindowTools::CMDestroyToolBox(RTMessage Msg)
  141. {
  142.     if( ToolBox && ToolBox->Exists() ) {
  143.         ToolBox->Destroy();
  144.         Resize();
  145.     }
  146.     DefCommandProc(Msg);
  147. }
  148.  
  149. void     TWindowTools::CMToggleStatusBar(RTMessage Msg)
  150. {
  151.     HMENU    hMenu;
  152.  
  153.     if ( !StatusBar ) return;     // Must first initialize status bar
  154.  
  155.     hMenu = GetMenu(HWindow);
  156.  
  157.     if ( StatusBar->Exists() ) {
  158.         CheckMenuItem(hMenu, IDM_TOGGLESTATUSBAR, MF_BYCOMMAND | MF_UNCHECKED);
  159.         StatusBar->Destroy();
  160.     }
  161.     else {
  162.         CheckMenuItem(hMenu, IDM_TOGGLESTATUSBAR, MF_BYCOMMAND | MF_CHECKED);
  163.         StatusBar->Create(HWindow);
  164.     }
  165.     Resize();
  166.     DrawMenuBar(HWindow);
  167.     DefCommandProc(Msg);
  168. }
  169.  
  170. void     TWindowTools::CMToggleToolBar(RTMessage Msg)
  171. {
  172.     HMENU    hMenu;
  173.  
  174.     if ( !ToolBar ) return;     // Must first initialize tool bar
  175.  
  176.     hMenu = GetMenu(HWindow);
  177.  
  178.     if ( ToolBar->Exists() ) {
  179.         CheckMenuItem(hMenu, IDM_TOGGLETOOLBAR, MF_BYCOMMAND | MF_UNCHECKED);
  180.         ToolBar->Destroy();
  181.     }
  182.     else {
  183.         CheckMenuItem(hMenu, IDM_TOGGLETOOLBAR, MF_BYCOMMAND | MF_CHECKED);
  184.         ToolBar->Create(GetApplication()->hInstance, HWindow);
  185.     }
  186.     Resize();
  187.     DrawMenuBar(HWindow);
  188.     DefCommandProc(Msg);
  189. }
  190.  
  191. void     TWindowTools::CMToggleToolBox(RTMessage Msg)
  192. {
  193.     HMENU    hMenu;
  194.  
  195.     if ( !ToolBox ) return;     // Must first initialize tool box
  196.  
  197.     hMenu = GetMenu(HWindow);
  198.  
  199.     if ( ToolBox->Exists() ) {
  200.         CheckMenuItem(hMenu, IDM_TOGGLETOOLBOX, MF_BYCOMMAND | MF_UNCHECKED);
  201.         ToolBox->Destroy();
  202.     }
  203.     else {
  204.         CheckMenuItem(hMenu, IDM_TOGGLETOOLBOX, MF_BYCOMMAND | MF_CHECKED);
  205.         ToolBox->Create(GetApplication()->hInstance, HWindow);
  206.     }
  207.     Resize();
  208.     DrawMenuBar(HWindow);
  209.     DefCommandProc(Msg);
  210. }
  211.  
  212. LPSTR     TWindowTools::GetClassName()
  213. {
  214.     return szClassName;
  215. }
  216.  
  217. void     TWindowTools::GetWindowClass(WNDCLASS _FAR & AWndClass)
  218. {
  219.     TWindow::GetWindowClass(AWndClass);
  220.     AWndClass.hIcon = LoadIcon(GetApplication()->hInstance, szClassName);
  221.     AWndClass.cbWndExtra = 2;
  222. }
  223.  
  224. void CALLBACK TWindowTools::InitStatusBar(LPSTATUSBARITEM AStatusBar, int AItems, int AHeight, DWORD AStyle)
  225. {
  226.      StatusBar = new TLCKStatusBar(AStatusBar, AItems, AHeight, AStyle);
  227. }
  228.  
  229. void CALLBACK TWindowTools::InitToolBar(LPTOOLBOXITEM AToolBar, int AItems, int AHeight, int AWidth, DWORD AStyle)
  230. {
  231.     ToolBar = new TLCKToolBar(AToolBar, AItems, AHeight, AWidth, AStyle);
  232. }
  233.  
  234. void CALLBACK TWindowTools::InitToolBox(LPTOOLBOXITEM AToolBox, int AItems, LPSTR ATitle, int AColumns, int ARows, int AHeight, int AWidth, DWORD AStyle)
  235. {
  236.     ToolBox = new TLCKToolBox(AToolBox, AItems, ATitle, AColumns, ARows, AHeight, AWidth, AStyle);
  237. }
  238.  
  239. void     TWindowTools::Resize()
  240. {
  241.     RECT    Rect;
  242.     int    nClientBottomOffset;
  243.  
  244.     if( IsIconic(HWindow) ) return;    // can't resize icon!
  245.  
  246.     nClientBottomOffset = 0;
  247.  
  248.     if( StatusBar && StatusBar->Exists() ) nClientBottomOffset += StatusBar->nHeight;
  249.  
  250.     GetClientRect(HWindow, &Rect);
  251.     if( StatusBar && StatusBar->Exists() ) MoveWindow(StatusBar->HWindow, 0, Rect.bottom - StatusBar->nHeight,
  252.                 Rect.right, StatusBar->nHeight, TRUE);
  253. }
  254.  
  255. void    TWindowTools::SetMDIMenu(LPSTR AMenuName, int AChildMenuPos)
  256. {
  257.     strncpy(szMDIMenu, AMenuName, LCK_MAXLEN_MENUNAME);
  258.     szMDIMenu[LCK_MAXLEN_MENUNAME] = NULL;
  259.     MDIChildMenuPos = AChildMenuPos;
  260.     bMDIMenu = TRUE;
  261. }
  262.  
  263. void    TWindowTools::SetOldMDIMenu(LPSTR AMenuName, int AChildMenuPos)
  264. {
  265.     strncpy(szOldMDIMenu, AMenuName, LCK_MAXLEN_MENUNAME);
  266.     szOldMDIMenu[LCK_MAXLEN_MENUNAME] = NULL;
  267.     OldMDIChildMenuPos = AChildMenuPos;
  268. }
  269.  
  270. void     TWindowTools::SetupWindow()
  271. {
  272.     TWindow::SetupWindow();
  273.     GetApplication()->SetKBHandler(this);
  274.     EnableKBHandler();
  275.     SetWindowWord(HWindow, 0, wWindowType);
  276. }
  277.  
  278. void     TWindowTools::WMCommand(RTMessage Msg)
  279. {
  280.         TWindow::WMCommand(Msg);
  281.  
  282.     // This will convert toolbar/box button clicks to menu commands
  283.     // if the button IDs match menu IDs
  284.  
  285.     if(Msg.LP.Hi == TBXN_CLICKED)    
  286.         PostMessage(HWindow, WM_COMMAND, Msg.WParam, 0L);
  287. }
  288.  
  289. void    TWindowTools::WMMDIActivate(RTMessage Msg)
  290. {
  291.     HMENU     FrameMenu, PopupMenu;
  292.  
  293.     if( !bMDIMenu ) goto Exit1;
  294.     if( Msg.WParam == TRUE ) {
  295.         SetOldMDIMenu(((PTMDIFrame) Parent)->Attr.Menu, ((PTMDIFrame) Parent)->ChildMenuPos);
  296.         ((PTMDIFrame) Parent)->AssignMenu(szMDIMenu);
  297.         FrameMenu = GetMenu(Parent->HWindow);
  298.         ((PTMDIFrame) Parent)->ChildMenuPos = MDIChildMenuPos;
  299.         PopupMenu = ((PTMDIFrame) Parent)->ClientWnd->ClientAttr->hWindowMenu = GetSubMenu(FrameMenu, MDIChildMenuPos);
  300.         SendMessage(((PTMDIFrame) Parent)->ClientWnd->HWindow, WM_MDISETMENU, FALSE, MAKELONG(FrameMenu, PopupMenu));
  301.     }
  302.     else {
  303.         ((PTMDIFrame) Parent)->AssignMenu(szOldMDIMenu);
  304.         FrameMenu = GetMenu(Parent->HWindow);
  305.         ((PTMDIFrame) Parent)->ChildMenuPos = OldMDIChildMenuPos;
  306.         PopupMenu = ((PTMDIFrame) Parent)->ClientWnd->ClientAttr->hWindowMenu = GetSubMenu(FrameMenu, OldMDIChildMenuPos);
  307.         SendMessage(((PTMDIFrame) Parent)->ClientWnd->HWindow, WM_MDISETMENU, FALSE, MAKELONG(FrameMenu, PopupMenu));
  308.     }
  309.  
  310. Exit1:
  311.     TWindow::WMMDIActivate(Msg);
  312. }
  313.  
  314. void     TWindowTools::WMNCCreate(RTMessage Msg)
  315. {
  316.     LONG       Styles;
  317.  
  318.         if(!bResize) {
  319.         Styles = GetWindowLong( HWindow, GWL_STYLE );
  320.         Styles &= ~( WS_MAXIMIZEBOX );
  321.         SetWindowLong( HWindow, GWL_STYLE, Styles);
  322.         }
  323.  
  324.     DefWndProc( Msg );
  325. }
  326.  
  327. void     TWindowTools::WMNCLButtonDown(RTMessage Msg)
  328. {
  329.     if( bResize ) {
  330.         DefWndProc( Msg );
  331.         return;
  332.     }
  333.  
  334.     switch( Msg.WParam ) {
  335.         case HTLEFT:
  336.         case HTRIGHT:
  337.         case HTTOP:
  338.         case HTTOPLEFT:
  339.         case HTTOPRIGHT:
  340.         case HTBOTTOM:
  341.         case HTBOTTOMLEFT:
  342.         case HTBOTTOMRIGHT:
  343.         break;
  344.         default:
  345.         DefWndProc( Msg );
  346.     }
  347. }
  348.  
  349. void     TWindowTools::WMSize(RTMessage Msg)
  350. {
  351.     // Must send TMDIFrame::WMSize so that maximize option works if a MDI child
  352.     TWindow::WMSize(Msg);
  353.     Resize();
  354. }
  355.  
  356. TMDIChildWindow::TMDIChildWindow(PTWindowsObject AParent, LPSTR ATitle, LPSTR ADialogName, WORD AWindowType)
  357.     : TWindowTools(AParent, ATitle, AWindowType)
  358. {
  359.     ChildDialog = NULL;
  360.     bResize = FALSE;
  361.     strncpy(szDialogName, ADialogName, LCK_MAXLEN_DIALOGNAME);
  362.         szDialogName[LCK_MAXLEN_DIALOGNAME] = NULL;
  363. }
  364.  
  365. PTDialog TMDIChildWindow::CreateChildDialog()
  366. {
  367.     ChildDialog = (PTDialog) GetApplication()->MakeWindow(new TMDIChildDialog(this, szDialogName));
  368.     return ChildDialog;
  369. }
  370.  
  371. void     TMDIChildWindow::Resize()
  372. {
  373.     RECT        Rect;
  374.     int        nClientTopOffset, nClientBottomOffset;
  375.     RECT        rcWindow, rcDialog;
  376.     PTMDIFrame    Frame;
  377.         POINT        pWindow;
  378.  
  379.     if(IsIconic(HWindow)) return;    // can't resize icon!
  380.     if(!ChildDialog) return;
  381.  
  382.     Frame = (PTMDIFrame) Parent;
  383.  
  384.     GetWindowRect(HWindow, &rcWindow);
  385.     GetWindowRect(ChildDialog->HWindow, &rcDialog);
  386.  
  387.     pWindow.x = rcWindow.left;
  388.     pWindow.y = rcWindow.top;
  389.  
  390.     ScreenToClient(Frame->ClientWnd->HWindow, &pWindow);
  391.  
  392.     nClientTopOffset = nClientBottomOffset = 0;
  393.     if( ToolBar && ToolBar->Exists() ) {
  394.         nClientTopOffset += ToolBar->nHeight + 2;
  395.         nClientBottomOffset += ToolBar->nHeight + 2;
  396.     }
  397.     if( StatusBar && StatusBar->Exists() ) nClientBottomOffset += StatusBar->nHeight;
  398.  
  399.     MoveWindow(HWindow, pWindow.x, pWindow.y,
  400.         rcDialog.right - rcDialog.left + GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXDLGFRAME) ,
  401.         rcDialog.bottom - rcDialog.top + GetSystemMetrics(SM_CYCAPTION)
  402.         + GetSystemMetrics(SM_CYDLGFRAME) + GetSystemMetrics(SM_CYFRAME) + nClientBottomOffset,
  403.         TRUE);
  404.     MoveWindow(ChildDialog->HWindow, 0, nClientTopOffset, rcDialog.right - rcDialog.left,
  405.         rcDialog.bottom - rcDialog.top, TRUE);
  406.  
  407.     TWindowTools::Resize();
  408. }
  409.  
  410. void     TMDIChildWindow::SetupWindow()
  411. {
  412.     TWindowTools::SetupWindow();
  413.     CreateChildDialog();
  414.     Resize();
  415. }
  416.  
  417. void     TMDIChildWindow::WMMDIActivate(RTMessage Msg)
  418. {
  419.     TWindowTools::WMMDIActivate(Msg);
  420.     if ( Msg.WParam == TRUE ) {
  421.         GetApplication()->SetKBHandler( this );
  422.         if( ChildDialog != NULL ) SetFocus(ChildDialog->HWindow);
  423.     }
  424. }
  425.  
  426. void     TMDIChildWindow::WMSize(RTMessage Msg)
  427. {
  428.     TWindowTools::WMSize(Msg);
  429.     if(!bResize) Resize();    // In case user cascades or tiles child window
  430. }
  431.  
  432. TMDIFrameTools::TMDIFrameTools(LPSTR ATitle, LPSTR MenuName)
  433.     : TMDIFrame(ATitle, MenuName)
  434. {
  435.     StatusBar = NULL;
  436.     ToolBar = NULL;
  437.         ToolBox = NULL;
  438. };
  439.  
  440. TMDIFrameTools::~TMDIFrameTools()
  441. {
  442.     if(StatusBar) delete StatusBar;
  443.     if(ToolBar) delete ToolBar;
  444.     if(ToolBox) delete ToolBox;
  445. }
  446.  
  447. void    TMDIFrameTools::CloseChildWindows(WORD AWindowType)
  448. {
  449.     ForEach((TActionMemFunc) &TMDIFrameTools::CloseChildWindow, (void *) AWindowType);
  450. }
  451.  
  452. void    TMDIFrameTools::CloseChildWindow(PTWindowsObject Child, Pvoid Param)
  453. {
  454.     WORD        wType;
  455.  
  456.     wType = GetWindowWord(Child->HWindow, 0);
  457.     if(wType == (WORD) Param)
  458.         Child->CloseWindow();
  459. }
  460.  
  461. void    TMDIFrameTools::CMCreateStatusBar(RTMessage)
  462. {
  463.     if( StatusBar && !StatusBar->Exists() ) {
  464.         StatusBar->Create(HWindow);
  465.         Resize();
  466.     }
  467. }
  468.  
  469. void    TMDIFrameTools::CMCreateToolBar(RTMessage)
  470. {
  471.     if( ToolBar && !ToolBar->Exists() ) {
  472.         ToolBar->Create(GetApplication()->hInstance, HWindow);
  473.         Resize();
  474.     }
  475. }
  476.  
  477. void    TMDIFrameTools::CMCreateToolBox(RTMessage)
  478. {
  479.     if( ToolBox && !ToolBox->Exists() ) {
  480.         ToolBox->Create(GetApplication()->hInstance, HWindow);
  481.         Resize();
  482.     }
  483. }
  484.  
  485. void     TMDIFrameTools::CMDestroyStatusBar(RTMessage)
  486. {
  487.     if( StatusBar && StatusBar->Exists() ) {
  488.         StatusBar->Destroy();
  489.         Resize();
  490.     }
  491. }
  492.  
  493. void     TMDIFrameTools::CMDestroyToolBar(RTMessage)
  494. {
  495.     if( ToolBar && ToolBar->Exists() ) {
  496.         ToolBar->Destroy();
  497.         Resize();
  498.     }
  499. }
  500.  
  501. void     TMDIFrameTools::CMDestroyToolBox(RTMessage)
  502. {
  503.     if( ToolBox && ToolBox->Exists() ) {
  504.         ToolBox->Destroy();
  505.         Resize();
  506.     }
  507. }
  508.  
  509. void     TMDIFrameTools::CMToggleStatusBar(RTMessage)
  510. {
  511.     HMENU    hMenu;
  512.  
  513.     if ( !StatusBar ) return;     // Must first initialize status bar
  514.  
  515.     hMenu = GetMenu(HWindow);
  516.  
  517.     if ( StatusBar->Exists() ) {
  518.         CheckMenuItem(hMenu, IDM_TOGGLESTATUSBAR, MF_BYCOMMAND | MF_UNCHECKED);
  519.         StatusBar->Destroy();
  520.     }
  521.     else {
  522.         CheckMenuItem(hMenu, IDM_TOGGLESTATUSBAR, MF_BYCOMMAND | MF_CHECKED);
  523.         StatusBar->Create(HWindow);
  524.     }
  525.     Resize();
  526.     DrawMenuBar(HWindow);
  527. }
  528.  
  529. void     TMDIFrameTools::CMToggleToolBar(RTMessage)
  530. {
  531.     HMENU    hMenu;
  532.  
  533.     if ( !ToolBar ) return;     // Must first initialize tool bar
  534.  
  535.     hMenu = GetMenu(HWindow);
  536.  
  537.     if ( ToolBar->Exists() ) {
  538.         CheckMenuItem(hMenu, IDM_TOGGLETOOLBAR, MF_BYCOMMAND | MF_UNCHECKED);
  539.         ToolBar->Destroy();
  540.     }
  541.     else {
  542.         CheckMenuItem(hMenu, IDM_TOGGLETOOLBAR, MF_BYCOMMAND | MF_CHECKED);
  543.         ToolBar->Create(GetApplication()->hInstance, HWindow);
  544.     }
  545.     Resize();
  546.     DrawMenuBar(HWindow);
  547. }
  548.  
  549. void     TMDIFrameTools::CMToggleToolBox(RTMessage)
  550. {
  551.     HMENU    hMenu;
  552.  
  553.     if ( !ToolBox ) return;     // Must first initialize tool bar
  554.  
  555.     hMenu = GetMenu(HWindow);
  556.  
  557.     if ( ToolBox->Exists() ) {
  558.         CheckMenuItem(hMenu, IDM_TOGGLETOOLBOX, MF_BYCOMMAND | MF_UNCHECKED);
  559.         ToolBox->Destroy();
  560.     }
  561.     else {
  562.         CheckMenuItem(hMenu, IDM_TOGGLETOOLBOX, MF_BYCOMMAND | MF_CHECKED);
  563.         ToolBox->Create(GetApplication()->hInstance, HWindow);
  564.     }
  565.     Resize();
  566.     DrawMenuBar(HWindow);
  567. }
  568.  
  569. PTWindowsObject    TMDIFrameTools::GetFirstChildWindow(WORD AWindowType)
  570. {
  571.     return FirstThat((TCondMemFunc) &TMDIFrameTools::IsWindowType, (void *) AWindowType);
  572. }
  573.  
  574. int    TMDIFrameTools::GetWindowTypeCount(WORD AWindowType)
  575. {
  576.     nWindowTypeCount = 0;
  577.     ForEach((TActionMemFunc) &TMDIFrameTools::IncWindowTypeCount, (void *) AWindowType);
  578.     return nWindowTypeCount;
  579. }
  580.  
  581. void     TMDIFrameTools::IncWindowTypeCount(PTWindowsObject Child, Pvoid Param)
  582. {
  583.     WORD        wType;
  584.  
  585.     wType = GetWindowWord(Child->HWindow, 0);
  586.     if(wType == (WORD) Param) nWindowTypeCount++;
  587. }
  588.  
  589. void CALLBACK TMDIFrameTools::InitStatusBar(LPSTATUSBARITEM AStatusBar, int AItems, int AHeight, DWORD AStyle)
  590. {
  591.      StatusBar = new TLCKStatusBar(AStatusBar, AItems, AHeight, AStyle);
  592. }
  593.  
  594. void CALLBACK TMDIFrameTools::InitToolBar(LPTOOLBOXITEM AToolBar, int AItems, int AHeight, int AWidth, DWORD AStyle)
  595. {
  596.     ToolBar = new TLCKToolBar(AToolBar, AItems, AHeight, AWidth, AStyle);
  597. }
  598.  
  599. void CALLBACK TMDIFrameTools::InitToolBox(LPTOOLBOXITEM AToolBox, int AItems, LPSTR ATitle, int AColumns, int ARows, int AHeight, int AWidth, DWORD AStyle)
  600. {
  601.     ToolBox = new TLCKToolBox(AToolBox, AItems, ATitle, AColumns, ARows, AHeight, AWidth, AStyle);
  602. }
  603.  
  604. BOOL     TMDIFrameTools::IsWindowType(PTWindowsObject Child, Pvoid Param)
  605. {
  606.     WORD        wType;
  607.  
  608.     wType = GetWindowWord(Child->HWindow, 0);
  609.     if(wType == (WORD) Param) return TRUE;
  610.         return FALSE;
  611. }
  612.  
  613. void     TMDIFrameTools::Resize()
  614. {
  615.     RECT    Rect;
  616.     int    nClientTopOffset, nClientBottomOffset;
  617.  
  618.     if( IsIconic(HWindow) ) return;    // can't resize icon!
  619.  
  620.     nClientTopOffset = nClientBottomOffset = 0;
  621.      
  622.     if( ToolBar && ToolBar->Exists() ) {
  623.         nClientTopOffset += ToolBar->nHeight + 2;
  624.         nClientBottomOffset += ToolBar->nHeight + 2;
  625.     }
  626.     if( StatusBar && StatusBar->Exists() ) nClientBottomOffset += StatusBar->nHeight;
  627.  
  628.     GetClientRect(HWindow, &Rect);
  629.     MoveWindow(ClientWnd->HWindow, 0, nClientTopOffset, Rect.right,
  630.          Rect.bottom - nClientBottomOffset, TRUE);
  631.     if( StatusBar && StatusBar->Exists() ) MoveWindow(StatusBar->HWindow, 0, Rect.bottom - StatusBar->nHeight,
  632.                 Rect.right, StatusBar->nHeight, TRUE);
  633.  
  634. }
  635.  
  636. void     TMDIFrameTools::WMCommand(RTMessage Msg)
  637. {
  638.         TMDIFrame::WMCommand(Msg);
  639.  
  640.     // This will convert toolbar/box button clicks to menu commands
  641.     // if the button IDs match menu IDs
  642.  
  643.     if(Msg.LP.Hi == TBXN_CLICKED)    
  644.         PostMessage(HWindow, WM_COMMAND, Msg.WParam, 0L);
  645. }
  646.  
  647. void     TMDIFrameTools::WMSize(RTMessage)
  648. {
  649.     // Don't send TMDIFrame::WMSize or you will get a double flash
  650.     Resize();
  651. }
  652.  
  653. TLCKStatusBar::TLCKStatusBar(LPSTATUSBARITEM AStatusBar, int AItems, int AHeight, DWORD AStyle)
  654. {
  655.     HWindow = NULL;
  656.     Style = AStyle;
  657.     nHeight = AHeight;
  658.     nItems = AItems;
  659.     StatusBar = new STATUSBARITEM[nItems];
  660.     if(!StatusBar) LCKMessage(LCKERR_CANTALLOCATE);
  661.         else MemCpy(StatusBar, AStatusBar, nItems * sizeof(STATUSBARITEM));
  662. }
  663.  
  664. TLCKStatusBar::~TLCKStatusBar()
  665. {
  666.     delete StatusBar;
  667. }
  668.  
  669. HWND CALLBACK TLCKStatusBar::Create(HWND AWindow)
  670. {
  671.     RECT        RectClient;
  672.  
  673.     if(!nHeight) {
  674.         HDC hdc = GetDC(AWindow);
  675.         TEXTMETRIC tm;
  676.         GetTextMetrics(hdc, &tm);
  677.         nHeight = tm.tmHeight + tm.tmExternalLeading + 2;
  678.         ReleaseDC(AWindow, hdc);
  679.         }
  680.  
  681.     GetClientRect(AWindow, &RectClient);
  682.     HWindow = tbCreateStatusBar(AWindow, WS_CHILD | WS_VISIBLE | SBRS_DRAWTOPLINE |
  683.                 SBRS_PIXELS, 0,
  684.                             RectClient.bottom - nHeight,
  685.                 RectClient.right, nHeight,
  686.                 StatusBar, nItems);
  687.  
  688.         return HWindow;
  689. }
  690.  
  691. void CALLBACK TLCKStatusBar::Destroy()
  692. {
  693.     if(!HWindow) {
  694.         LCKMessage(LCKERR_CANTDESTROYSTATUSBAR);
  695.                 return;
  696.         }
  697.  
  698.     DestroyWindow(HWindow);
  699.     HWindow = NULL;
  700. }
  701.  
  702. void CALLBACK TLCKStatusBar::SetItemText(WORD AItem, LPSTR AText)
  703. {
  704.     SendMessage(HWindow, SBRM_SETITEMTEXT, AItem, (LONG) AText);
  705. }
  706.  
  707. void CALLBACK TLCKStatusBar::SetProgressPos(WORD AItem, WORD APos)
  708. {
  709.     SendMessage(HWindow, SBRM_SETPROGRESSPOS, AItem, (LONG) APos);
  710. }
  711.  
  712. void CALLBACK TLCKStatusBar::SetProgressRange(WORD AItem, WORD AMinimum, WORD AMaximum)
  713. {
  714.     SendMessage(HWindow, SBRM_SETPROGRESSRANGE, AItem, MAKELONG(AMinimum, AMaximum));
  715. }
  716.  
  717. TLCKToolBar::TLCKToolBar(LPTOOLBOXITEM AToolBar, int AItems, int AHeight, int AWidth, DWORD AStyle)
  718. {
  719.     HWindow = NULL;
  720.     Style = AStyle;
  721.     nHeight = AHeight;
  722.         nWidth = AWidth;
  723.     nItems = AItems;
  724.     x = y = 0;
  725.     dColCount = TBX_MAXSIZE;
  726.     dRowCount = 1;
  727.     dBorderSize = 0;
  728.     ToolBar = new TOOLBOXITEM[nItems];
  729.     if(!ToolBar) LCKMessage(LCKERR_CANTALLOCATE);
  730.     else MemCpy(ToolBar, AToolBar, nItems * sizeof(TOOLBOXITEM));
  731. }
  732.  
  733. TLCKToolBar::~TLCKToolBar()
  734. {
  735.     delete ToolBar;
  736. }
  737.  
  738. HWND CALLBACK TLCKToolBar::Create(HINSTANCE AInst, HWND AWindow)
  739. {
  740.     int    i;
  741.  
  742.     HWindow = tbCreateToolBox(AInst, AWindow, Style, x, y, nWidth, nHeight,
  743.              dColCount, dRowCount, dBorderSize, NULL);
  744.  
  745.     for (i = 0; i < nItems; i++)
  746.         SendMessage(HWindow, TBXM_ADDITEM, 0, (long)(LPSTR)&ToolBar[i]);
  747.  
  748.         return HWindow;
  749. }
  750.  
  751. void CALLBACK TLCKToolBar::Destroy()
  752. {
  753.     if(!HWindow) {
  754.         LCKMessage(LCKERR_CANTDESTROYTOOLBAR);
  755.                 return;
  756.         }
  757.  
  758.     DestroyWindow(HWindow);
  759.     HWindow = NULL;
  760. }
  761.  
  762. TLCKToolBox::TLCKToolBox(LPTOOLBOXITEM AToolBox, int AItems, LPSTR ATitle, int AColumns, int ARows, int AHeight, int AWidth, DWORD AStyle)
  763. {
  764.     HWindow = NULL;
  765.         if(ATitle) {
  766.         strncpy(Title, ATitle, LCK_MAXLEN_TITLE);
  767.         Title[LCK_MAXLEN_TITLE - 1] = NULL;
  768.     }
  769.     else *Title = NULL;
  770.     Style = AStyle;
  771.     nHeight = AHeight;
  772.         nWidth = AWidth;
  773.     nItems = AItems;
  774.     x = y = 0;
  775.     dColCount = AColumns;
  776.     dRowCount = ARows;
  777.     dBorderSize = 0;
  778.     ToolBox = new TOOLBOXITEM[nItems];
  779.     if(!ToolBox) LCKMessage(LCKERR_CANTALLOCATE);
  780.     else MemCpy(ToolBox, AToolBox, nItems * sizeof(TOOLBOXITEM));
  781. }
  782.  
  783. TLCKToolBox::~TLCKToolBox()
  784. {
  785.     delete ToolBox;
  786. }
  787.  
  788. HWND CALLBACK TLCKToolBox::Create(HINSTANCE AInst, HWND AWindow)
  789. {
  790.     int    i;
  791.  
  792.     HWindow = tbCreateToolBox(AInst, AWindow, Style, x, y, nWidth, nHeight,
  793.              dColCount, dRowCount, dBorderSize, *Title ? Title : NULL);
  794.  
  795.     for (i = 0; i < nItems; i++)
  796.         SendMessage(HWindow, TBXM_ADDITEM, 0, (long)(LPSTR)&ToolBox[i]);
  797.  
  798.         return HWindow;
  799. }
  800.  
  801. void CALLBACK TLCKToolBox::Destroy()
  802. {
  803.     if(!HWindow) {
  804.         LCKMessage(LCKERR_CANTDESTROYTOOLBOX);
  805.                 return;
  806.         }
  807.  
  808.     DestroyWindow(HWindow);
  809.     HWindow = NULL;
  810. }
  811.  
  812. TWindowTable::TWindowTable(PTWindowsObject AParent, LPSTR ATitle, WORD AWindowType, WORD ATableStyle)
  813.     : TWindowTools(AParent, ATitle, AWindowType)
  814. {
  815.     wTableStyle = ATableStyle;
  816.         DataTbl = NULL;
  817. }
  818.  
  819. TWindowTable::~TWindowTable()
  820. {
  821.      if ( DataTbl ) delete DataTbl;
  822. }
  823.  
  824. void     TWindowTable::Resize()
  825. {
  826.     int        nClientTopOffset, nClientBottomOffset;
  827.     RECT        rcWindow;
  828.  
  829.     if(IsIconic(HWindow)) return;    // can't resize icon!
  830.  
  831.     GetClientRect(HWindow, &rcWindow);
  832.     nClientTopOffset = nClientBottomOffset = 0;
  833.     if( ToolBar && ToolBar->Exists() ) {
  834.         nClientTopOffset += ToolBar->nHeight + 2;
  835.         nClientBottomOffset += ToolBar->nHeight + 2;
  836.     }
  837.     if( StatusBar && StatusBar->Exists() ) nClientBottomOffset += StatusBar->nHeight;
  838.  
  839.     MoveWindow(DataTbl->HWindow, 0, nClientTopOffset, rcWindow.right,
  840.         rcWindow.bottom - nClientBottomOffset, TRUE);
  841.  
  842.     TWindowTools::Resize();
  843. }
  844.  
  845. void     TWindowTable::SetColumns(int NCols, PCOLUMNCFG TableColumns)
  846. {
  847.     int    i;
  848.  
  849.     DataTbl->ResetAll();
  850.     DataTbl->SetColCount(NCols);
  851.     for(i = 0; i < NCols; i++) {
  852.         DataTbl->SetColCfg(i, (HPVOID) &TableColumns[i]);
  853.         }
  854.  
  855.     DataTbl->SetAccessPos(0, DTPOS_AFTERLAST);
  856. }
  857.  
  858. void    TWindowTable::SetNotifyToAccess()
  859. {
  860.     // Necessary so that all notification messages "automatically"
  861.         // set the current access position to the notification position
  862.     LONG    CurRow;
  863.     int    CurCol;
  864.  
  865.     CurRow = DataTbl->GetNotifyRow();
  866.     CurCol = DataTbl->GetNotifyCol();
  867.     if ( CurRow < 0 || CurRow > 65500 ) CurRow = DTPOS_AFTERLAST;
  868. //    if ( CurRow < 0 ) CurRow = DTPOS_AFTERLAST;
  869.     if ( CurCol < 0 ) CurCol = 0;
  870.  
  871.     DataTbl->SetAccessPos(CurCol, CurRow);
  872. }
  873.  
  874. void     TWindowTable::SetupWindow()
  875. {
  876.     RECT    Rect;
  877.  
  878.     TWindowTools::SetupWindow();
  879.  
  880.     GetClientRect(HWindow, &Rect);
  881.     DataTbl = (PTDataTbl) GetApplication()->MakeWindow(new TDataTbl(this, 100, Rect.left, Rect.top, Rect.right, Rect.bottom, GetModule()));
  882.     if( !DataTbl ) LCKMessage(LCKERR_CANTALLOCATE);
  883.     DataTbl->SetWndStyle(wTableStyle | WS_BORDER | WS_VISIBLE | WS_CHILD);
  884. }
  885.  
  886. void     TWindowTable::WMCommand(RTMessage Msg)
  887. {
  888.     if( Msg.LP.Hi == DTN_SELCHANGE ||
  889.         Msg.LP.Hi == DTN_POSCHANGE ||
  890.         Msg.LP.Hi == DTN_CLICKED) {
  891.         SetNotifyToAccess();
  892.         StatusChange();
  893.     }
  894.     if( Msg.LP.Hi == DTN_DBLCLK )
  895.         DoubleClick();
  896.  
  897.     if( Msg.LP.Hi == DTN_ERRSPACE )
  898.         LCKMessage(LCKERR_OUTOFMEMORY);
  899.  
  900.     TWindowTools::WMCommand(Msg);
  901. }
  902.  
  903. void     TWindowTable::WMSize(RTMessage Msg)
  904. {
  905.     TWindowTools::WMSize(Msg);
  906.     Resize();
  907. }
  908.  
  909. int FAR PASCAL LibMain(HANDLE hInstance, WORD /*wDataSeg*/,
  910.   WORD /* cbHeapSize */, LPSTR lpCmdLine)
  911. {
  912.     int TheStatus;
  913.  
  914.     TheModule = new TModule("LCKOWL", hInstance, lpCmdLine);
  915.     TheStatus = TheModule->Status;
  916.     if ( TheStatus != 0 ) {
  917.         delete TheModule;
  918.         TheModule = NULL;
  919.     }
  920.  
  921.     return (TheStatus == 0);
  922. }
  923.  
  924. int FAR PASCAL WEP(int /*bSystemExit*/)
  925. {
  926. //    if ( TheModule ) delete TheModule;
  927.     return 1;
  928. }
  929.  
  930.