home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osp1.exe / src / basecntr / iodbcset.cpp < prev    next >
C/C++ Source or Header  |  1997-04-02  |  16KB  |  491 lines

  1. /* @(#)Z 1.4 com/src/samples/basecntr/iodbcset.cpp, odbasepart, od96os2, odos29714c 97/04/02 17:20:08 (97/03/25 13:49:30) */
  2. //====START_GENERATED_PROLOG======================================
  3. //
  4. //
  5. //   COMPONENT_NAME: odbasepart
  6. //
  7. //   CLASSES: none
  8. //
  9. //   ORIGINS: 82,27
  10. //
  11. //
  12. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  13. //   All Rights Reserved
  14. //   Licensed Materials - Property of IBM
  15. //   US Government Users Restricted Rights - Use, duplication or
  16. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  17. //
  18. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  22. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  23. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  24. //   OR PERFORMANCE OF THIS SOFTWARE.
  25. //
  26. //====END_GENERATED_PROLOG========================================
  27. //
  28.  
  29. /*
  30.         File:           BCSettng.cpp
  31.  
  32.         Contains:       code for the BCPartSettingsExt class
  33. */
  34.  
  35. #define BCPartSettingsExt_Class_Source
  36. #define VARIABLE_MACROS
  37.  
  38. #include <ODTypes.h>
  39.  
  40. #if defined(_PLATFORM_OS2_)
  41. #include <odos2.h>
  42. #include <iodbcres.h>
  43. #elif defined(_PLATFORM_WIN32_)
  44. #include <windows.h>
  45. #include <iodbcres.h>
  46. #endif
  47.  
  48. #ifndef _ODRES_
  49. #include <odres.h>
  50. #endif
  51.  
  52. #ifndef SOM_ODSettingsExtension_xh
  53. #include <Settings.xh>
  54. #endif
  55.  
  56. #ifndef _TEMPOBJ_
  57. #include <TempObj.h>
  58. #endif
  59.  
  60. #ifndef SOM_ODFrame_xh
  61. #include <Frame.xh>
  62. #endif
  63.  
  64. #ifndef SOM_ODFacet_xh
  65. #include <Facet.xh>
  66. #endif
  67.  
  68. #ifndef SOM_ODPart_xh
  69. #include <Part.xh>
  70. #endif
  71.  
  72. #ifndef SOM_ODStorageUnit_xh
  73. #include <StorageU.xh>
  74. #endif
  75.  
  76. /*
  77.  *  Settings Notebook headers...
  78.  */
  79. #if defined(_PLATFORM_UNIX_)
  80. #include <Notebook.xh>
  81. #include <iodbcpag.xh>
  82. #endif
  83. #include <iodbcset.xih>
  84.  
  85. #if defined(_PLATFORM_OS2_)
  86. MRESULT EXPENTRY SettingsPageDlgProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2);
  87. #elif defined(_PLATFORM_WIN32_)
  88. SOMEXTERN BOOL SOMLINK CALLBACK SettingsPageDlgProc(HWND hdwnd,UINT message,
  89.                                                   WPARAM wParam, LPARAM lParam);
  90. #endif
  91.  
  92. HWND hwndParent = NULL;
  93.  
  94. //==============================================================================
  95. // BCPartSettingsExt::InitSettingsExtension
  96. //==============================================================================
  97.  
  98. SOM_Scope void  SOMLINK BCPartSettingsExtInitSettingsExtension
  99.                         (BCPartSettingsExt *somSelf,
  100.                          Environment *ev,
  101.                          ODPart *parent)
  102.  
  103. {
  104.     /* BCPartSettingsExtData *somThis =
  105.                 BCPartSettingsExtGetData(somSelf); */
  106.  
  107.     BCPartSettingsExtMethodDebug("BCPartSettingsExt",
  108.                 "BCPartSettingsExtInitSettingsExtension");
  109.  
  110.     BCPartSettingsExt_parent_ODSettingsExtension_InitSettingsExtension(
  111.       somSelf, ev, parent);
  112.  
  113. }
  114.  
  115.  
  116. #if defined(_PLATFORM_WIN32_)
  117.  
  118. //==============================================================================
  119. // BCPartSettingsExt::ShowSettingsPages - Windows
  120. //==============================================================================
  121. SOM_Scope void  SOMLINK BCPartSettingsExtShowSettingsPages
  122.                         (BCPartSettingsExt *somSelf, Environment *ev,
  123.                          ODFacet *facet, HWND hPropSheetDlg)
  124.  
  125. {
  126.     /* BCPartSettingsExtData *somThis =
  127.                 BCPartSettingsExtGetData(somSelf); */
  128.  
  129.     BCPartSettingsExtMethodDebug("BCPartSettingsExt",
  130.                 "BCPartSettingsExtShowSettingsPages");
  131.  
  132. // The settings page is not currently defined in the resource file for
  133. // compilers other than Visual Age.
  134. #if defined(__IBMCPP__) || defined(_IBMR2)
  135.  
  136.     // Save the parent into a global variable to be used within the dialog
  137.     // funtion.
  138.     hwndParent = hPropSheetDlg;
  139.  
  140.     HINSTANCE resInst = LoadLibrary("iodbasec");
  141.     PROPSHEETPAGE page;
  142.  
  143.     page.dwSize      = sizeof(PROPSHEETPAGE);
  144.     page.dwFlags     = PSP_HASHELP;
  145.     page.hInstance   = resInst;
  146.     page.pszTemplate = MAKEINTRESOURCE(ID_SETTINGSPAGEDLG);
  147.     page.pfnDlgProc  = (FARPROC) SettingsPageDlgProc;
  148.     page.lParam      = (LONG) facet;
  149.  
  150.     HPROPSHEETPAGE hPage = CreatePropertySheetPage (&page);
  151.  
  152.     PropSheet_AddPage (hPropSheetDlg, hPage);
  153.  
  154. #endif
  155. }
  156.  
  157. //==============================================================================
  158. // SettingsPageDlgProc - Windows
  159. //==============================================================================
  160. SOMEXTERN BOOL SOMLINK CALLBACK SettingsPageDlgProc(HWND hdwnd, UINT message,
  161.                                                 WPARAM wParam, LPARAM lParam)
  162.  
  163. {
  164.   Environment          *ev = somGetGlobalEnvironment();
  165.   ODFacet              *facet;
  166.   PROPSHEETPAGE        *page;
  167.   ODBoolean            retCode = kODTrue;
  168.   ODBoolean            dialogDismissed = kODFalse;
  169.  
  170.   try
  171.   {
  172.     switch (message)
  173.     {
  174.       //------------------------------------------------------
  175.       //  Initialize the draft page.
  176.       //------------------------------------------------------
  177.       case WM_INITDIALOG:
  178.       {
  179.         // get necessary information from incoming lParam structure
  180.         page = (PROPSHEETPAGE*) lParam;
  181.         facet = (ODFacet*) page->lParam;
  182.  
  183.         // save handle to this object structure passed in as lParam
  184.         SetWindowLong(hdwnd, GWL_USERDATA, lParam);
  185.  
  186.         // NOTE: Uncomment the following lines of code if you need to retrieve
  187.         // information from the part's storage unit for initialization
  188.         //
  189.         // Need to acquire the frame before using it.
  190.         // TempODFrame frame = facet->GetFrame(ev);
  191.         // frame->Acquire(ev);
  192.  
  193.         // Need to acquire the part.
  194.         // TempODPart part = frame->AcquirePart(ev);
  195.  
  196.         // Need to acquire the storage unit before using it.
  197.         // TempODStorageUnit partSU = part->GetStorageUnit(ev);
  198.         // partSU->Acquire(ev);
  199.  
  200.         // ---- Add part specific settings initialization here ----
  201.  
  202.         break;
  203.       }
  204.  
  205.       case WM_HELP:
  206.       {
  207.         MessageBox(hdwnd, "Help is not implemented for this page.",
  208.                    "Information", MB_OK);
  209.         break;
  210.       }
  211.  
  212.       case WM_COMMAND:
  213.       {
  214.         // Retrieve handle to facet.
  215.         page = (PROPSHEETPAGE*) GetWindowLong(hdwnd, GWL_USERDATA);
  216.         facet = (ODFacet*) page->lParam;
  217.  
  218.         switch (LOWORD(wParam))
  219.         {
  220.           case IDCANCEL:
  221.             // Set indicator since this case will cause dialog to be dismissed.
  222.             dialogDismissed = kODTrue;
  223.             break;
  224.  
  225.           default:
  226.             retCode = kODFalse;
  227.             break;
  228.         }
  229.         break;
  230.       } // WM_COMMAND
  231.  
  232.       case WM_NOTIFY:
  233.       {
  234.         // Retrieve handle to facet.
  235.         page = (PROPSHEETPAGE*) GetWindowLong(hdwnd, GWL_USERDATA);
  236.         facet = (ODFacet*) page->lParam;
  237.  
  238.         switch (((NMHDR FAR *) lParam)->code)
  239.         {
  240.           case PSN_SETACTIVE:
  241.           {
  242.             // Set return code.
  243.             SetWindowLong(hdwnd, DWL_MSGRESULT, 0);
  244.  
  245.             break;
  246.           }
  247.  
  248.           case PSN_APPLY:     // OK or APPLY was pressed.
  249.           {
  250.             // Set return code.
  251.             SetWindowLong(hdwnd, DWL_MSGRESULT, PSNRET_NOERROR);
  252.  
  253.             break;
  254.           }
  255.  
  256.           case PSN_KILLACTIVE:     // OK
  257.           {
  258.             // Allow window to lose activation.
  259.             SetWindowLong(hdwnd, DWL_MSGRESULT, FALSE);
  260.  
  261.             break;
  262.           }
  263.  
  264.           case PSN_RESET:     // Cancel pressed.  Need to cleanup.
  265.           {
  266.             // Set indicator since this case will cause dialog to be dismissed.
  267.             dialogDismissed = kODTrue;
  268.  
  269.             break;
  270.           }
  271.  
  272.           case PSN_HELP:
  273.           {
  274.             MessageBox(hdwnd, "Help is not implemented for this page.",
  275.                     "Information", MB_OK);
  276.             break;
  277.           }
  278.  
  279.           default:
  280.             retCode = kODFalse;
  281.             break;
  282.  
  283.         } // switch
  284.         break;
  285.  
  286.       } // WM_NOTIFY
  287.  
  288.       default:
  289.           retCode = kODFalse;
  290.           break;
  291.  
  292.     } // switch (message)
  293.  
  294.   }
  295.   catch (ODException _exception)
  296.   {
  297.     // If dialog hasn't already been dismissed, dismiss it.
  298.     if (!dialogDismissed)
  299.       EndDialog(hdwnd,0);
  300.  
  301.     throw;
  302.   }
  303.   return retCode;
  304. }
  305.  
  306.  
  307. #elif defined(_PLATFORM_UNIX_)
  308.  
  309. //==============================================================================
  310. // BCPartSettingsExt::ShowSettingsPages - AIX
  311. //==============================================================================
  312. SOM_Scope void  SOMLINK BCPartSettingsExtShowSettingsPages
  313.                         (BCPartSettingsExt *somSelf, Environment *ev,
  314.                          ODFacet *facet, ODNotebook *notebook)
  315.  
  316. {
  317.     /* BCPartSettingsExtData *somThis =
  318.                 BCPartSettingsExtGetData(somSelf); */
  319.  
  320.     BCPartSettingsExtMethodDebug("BCPartSettingsExt",
  321.                 "BCPartSettingsExtShowSettingsPages");
  322.  
  323.     BaseContainerPage* bcpage = new BaseContainerPage;
  324.  
  325.     // ---- Add any part page initialization here before adding
  326.     // ---- the page to the notebook, i.e.
  327.     //
  328.     //    bcpage->Initialize(ev, partSU,...)
  329.  
  330.     notebook->AddPage (ev, bcpage);
  331. }
  332.  
  333. #elif defined(_PLATFORM_OS2_)
  334.  
  335. //==============================================================================
  336. // BCPartSettingsExt::ShowSettingsPages - OS2
  337. //==============================================================================
  338. SOM_Scope void  SOMLINK BCPartSettingsExtShowSettingsPages
  339.                         (BCPartSettingsExt *somSelf, Environment *ev,
  340.                          ODFacet* facet, HWND parent, ULONG notebookID)
  341. {
  342.     /* BCPartSettingsExtData *somThis =
  343.                 BCPartSettingsExtGetData(somSelf); */
  344.  
  345.     BCPartSettingsExtMethodDebug("BCPartSettingsExt",
  346.                 "BCPartSettingsExtShowSettingsPages");
  347.  
  348.     // Save the parent into a global variable to be used within the dialog
  349.     // funtion.
  350.     hwndParent = parent;
  351.  
  352.     // Get handle to our load module which contains the resource file.
  353.     HMODULE hmod;
  354.     CHAR Error[256] = "";
  355.     DosLoadModule( Error, sizeof(Error), "iodbasec", &hmod );
  356.  
  357.     // Tell notebook to insert a page and save the id to it.
  358.     ULONG pageId = (LONG)WinSendDlgItemMsg(parent, notebookID,
  359.                 BKM_INSERTPAGE, NULL,
  360.                 MPFROM2SHORT((BKA_STATUSTEXTON | BKA_AUTOPAGESIZE | BKA_MAJOR),
  361.                 BKA_LAST));
  362.  
  363.     // Set the text of the new page's tab.
  364.     WinSendDlgItemMsg(parent, notebookID, BKM_SETTABTEXT, MPFROMLONG(pageId),
  365.                       MPFROMP("Part"));
  366.  
  367.     // Create a page based on the ID_SETTINGSPAGEDLG resource and save the
  368.     // handle.
  369.     HWND pageHwnd = WinLoadDlg(parent,parent,(PFNWP)SettingsPageDlgProc,
  370.                                (HMODULE)hmod, ID_SETTINGSPAGEDLG, facet);
  371.  
  372.     // Associate the handle of the new page dialog to the notebook.
  373.     WinSendDlgItemMsg(parent, notebookID, BKM_SETPAGEWINDOWHWND,
  374.                       MPFROMLONG(pageId), MPFROMHWND(pageHwnd));
  375.  
  376.     // Save the new page handle and id in an internal data structure for
  377.     // the ODInfo class to be able to reference it.
  378.     somSelf->AddNotebookSheet( ev, pageHwnd, pageId );
  379. }
  380.  
  381. //==============================================================================
  382. // SettingsPageDlgProc - OS2
  383. //==============================================================================
  384. /*-------------------------------------------------------------------*/
  385. /* Dialog procedure for the settings page.                           */
  386. /*-------------------------------------------------------------------*/
  387. MRESULT EXPENTRY SettingsPageDlgProc( HWND hdwnd, ULONG msg,
  388.                                       MPARAM mp1, MPARAM mp2 )
  389. {
  390.   ODFacet* facet = kODNULL;
  391.   Environment *ev = somGetGlobalEnvironment();
  392.  
  393.   switch ( msg )
  394.   {
  395.     case WM_INITDLG:
  396.     {
  397.       facet = (ODFacet *) MPFROMP(mp2);
  398.  
  399.       // save handle to facet passed in as lParam
  400.       WinSetWindowULong(hdwnd, QWL_USER, LONGFROMMP(mp2));
  401.  
  402.       // NOTE: Uncomment the following lines of code if you need to retrieve
  403.       // information from the part's storage unit for initialization
  404.       //
  405.       // Need to acquire the frame before using it.
  406.       // TempODFrame frame = facet->GetFrame(ev);
  407.       // frame->Acquire(ev);
  408.  
  409.       // Need to acquire the part.
  410.       // TempODPart part = frame->AcquirePart(ev);
  411.  
  412.       // Need to acquire the storage unit before using it.
  413.       // TempODStorageUnit partSU = part->GetStorageUnit(ev);
  414.       // partSU->Acquire(ev);
  415.  
  416.       // ----- Add part specific settings initialization here -----
  417.  
  418.       return MRESULT(TRUE);
  419.       break;
  420.     }
  421.  
  422. /*---------------------------------------------------------------------*/
  423. /* This is code in response to a user defined message which is sent    */
  424. /* when the notebook page is about to come to the top as the active    */
  425. /* page.  This corresponds to the PSN_SETACTIVE case in Windows.       */
  426. /*---------------------------------------------------------------------*/
  427.     case WM_SET_ACTIVE:
  428.       break;
  429.  
  430. /*---------------------------------------------------------------------*/
  431. /* This is code in response to a user defined message which is sent    */
  432. /* when the user hit the OK button and this page was on top.  This     */
  433. /* corresponds to the PSN_SETACTIVE case in Windows.                   */
  434. /*---------------------------------------------------------------------*/
  435.     case WM_DID_OK:
  436.     {
  437.       facet = (ODFacet *) WinQueryWindowULong(hdwnd, QWL_USER);
  438.  
  439.       // NOTE: Uncomment the following lines of code if you need to retrieve
  440.       // information from the part's storage unit for initialization
  441.       //
  442.       // Need to acquire the frame before using it.
  443.       // TempODFrame frame = facet->GetFrame(ev);
  444.       // frame->Acquire(ev);
  445.  
  446.       // Need to acquire the part.
  447.       // TempODPart part = frame->AcquirePart(ev);
  448.  
  449.       // Need to acquire the storage unit before using it.
  450.       // TempODStorageUnit partSU = part->GetStorageUnit(ev);
  451.       // partSU->Acquire(ev);
  452.  
  453.       // ---- Do any part updating here ----
  454.       break;
  455.     }
  456.  
  457.     case WM_COMMAND:
  458.       if (SHORT1FROMMP( mp1 ) == DID_CANCEL)
  459.       {
  460.         /* This occured as a result of the Escape key being pressed while this
  461.          * page was active.  Want to intercept this so it doesn't go onto
  462.          * WinDefDlgProc.  Eventually, need to pass event back up to parent to
  463.          * handle.
  464.          */
  465.         WinSendMsg(hwndParent, WM_COMMAND, MPFROMSHORT(DID_CANCEL), MPARAM(0));
  466.         break;
  467.       }
  468.  
  469.     case WM_HELP:
  470.     {
  471.        WinMessageBox(HWND_DESKTOP,hdwnd,
  472.                      "Help is not implemented for this page.",
  473.                      "Information",
  474.                      0, MB_INFORMATION | MB_OK);
  475.        break;
  476.     }
  477.  
  478.     default:
  479.       /*
  480.        * Any event messages that the dialog procedure has not processed
  481.        * come here and are processed by WinDefDlgProc.
  482.        * This call MUST exist in your dialog procedure.
  483.        */
  484.       return WinDefDlgProc( hdwnd, msg, mp1, mp2 );
  485.   }
  486.   return (MRESULT) FALSE;
  487. }
  488.  
  489. #endif
  490.  
  491.