home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / odtlktv4.zip / ODTLKT / TOOLKIT / BETA / SAMPLES / OPENDOC / PARTS / CNTNRPRT / CNNOTEBK.CPP next >
Text File  |  1995-11-29  |  13KB  |  402 lines

  1. /*
  2.  *  This file was generated by the SOM Compiler and Emitter Framework.
  3.  *  Generated using:
  4.  *      SOM Emitter emitxtm: 2.41
  5.  */
  6.  
  7. /*   File:      Cnnotebk.cpp
  8.  *
  9.  *   Contains:  Implementation for Container Part's notebook
  10.  *
  11.  *   Written by:   The OpenDoc Development Team
  12.  *
  13.  *   Copyright: (c) 1995 by IBM Corp., all rights reserved.
  14.  *
  15.  *   Change History (most recent first):
  16.  *
  17.  *     137691  11/28/95    ced      Fix up exception handling
  18.  *     143378  11/14/95    BLG      mod AddNotebookPages() added removeNotebookPage()
  19.  *     127364   9/28/95    BLG      Insert view pages for containers - AddNotebookPages.
  20.  *     137002   9/15/95    jso      Updated to follow base cntnrpr specs
  21.  */
  22.  
  23. #ifndef _EXCEPT_
  24. #include "Except.h"
  25. #endif
  26.  
  27. #ifndef SOM_Module_cnnotebk_Source
  28. #define SOM_Module_cnnotebk_Source
  29. #endif
  30. #define CNNotebook_Class_Source
  31. #define VARIABLE_MACROS
  32.  
  33. #define INCL_WINHELP
  34. #define INCL_DOS
  35. #define INCL_WINPOINTERS
  36. #define INCL_WINFRAMEMGR
  37. #define INCL_WINWINDOWMGR
  38. #define INCL_WIN
  39. #define INCL_GPI
  40. #define INCL_WPCLASS
  41. #define INCL_ODFRAME
  42. #define INCL_ODPART
  43. #define INCL_ODAPI
  44. #define INCL_GPIPOLYGON
  45. #define INCL_ODFACET
  46. #include <os2.h>
  47.  
  48.  
  49. #ifndef _CNTMRI_
  50.    #include "cntmri.h"
  51. #endif
  52.  
  53. #define WM_FOCUS_PROCESSING   WM_USER + 1
  54.  
  55. #ifndef _ORDCOLL_
  56. #include "OrdColl.h"
  57. #endif
  58.  
  59. #include "cnnotebk.xih"
  60.  
  61. #ifndef _CNTNRPRT_
  62. #include "Cntnrprt.xih"
  63. #endif
  64.  
  65. /*********************************/
  66. /* globals                       */
  67. /*********************************/
  68.  
  69. typedef struct _LISTDATA
  70. {
  71.    ContainerPart * realPart;
  72.    ODPart  * partWrapper;
  73.    ULONG origColor;
  74.    ULONG currColor;
  75. } COLORDATA;
  76. typedef COLORDATA *PCOLORDATA;
  77.  
  78. #define WM_FOCUS_PROCESSING   WM_USER + 1
  79.  
  80. /*********************************/
  81. /* prototypes                    */
  82. /*********************************/
  83.  
  84. extern "C" {
  85.    MPARAM EXPENTRY ColorPageDlgProc(
  86.       HWND hwnd,
  87.       USHORT msg,
  88.       MPARAM mp1,
  89.       MPARAM mp2);
  90. }
  91.  
  92.  
  93. /**********************************************************************\
  94.  * FUNCTION:  ColorPageDlgProc
  95.  *
  96.  * DESCRIPTION: Dialog procedure for the Color Page
  97.  *
  98.  *
  99. \**********************************************************************/
  100.  
  101.    MPARAM EXPENTRY ColorPageDlgProc(
  102.       HWND hwnd,
  103.       USHORT msg,
  104.       MPARAM mp1,
  105.       MPARAM mp2)
  106. {
  107.  
  108.  
  109.    MRESULT mresReply;
  110.    PCOLORDATA pColorData;
  111.    Environment *    ev;
  112.    ev = somGetGlobalEnvironment();
  113.    ODFrame * displayFrame;
  114.  
  115.    /* Get the data for this notebook
  116.     */
  117.    switch(msg)
  118.    {
  119.  
  120.       case WM_INITDLG:
  121.       {
  122.  
  123.           pColorData = new COLORDATA;
  124.  
  125.           /*  a pointer to the notebook is set inside the bookinfo structure which is stored
  126.            *  in the window words. Get in order to access part methods. Note that the Part
  127.            *  part wrapper should always be the notebook extensions base.
  128.            */
  129.           ODULong  initColor = 0;
  130.  
  131.         SOM_TRY
  132.  
  133.           ODSettingsExtension * notebook = (ODSettingsExtension *) mp2;
  134.           pColorData->partWrapper = (ODPart *)notebook->GetBase(ev);
  135.           pColorData->realPart    = (ContainerPart *) pColorData->partWrapper->GetRealPart(ev);
  136.  
  137.           /*  Get the original backfround color for undo  */
  138.  
  139.           initColor = pColorData->realPart->GetBGColor(ev);
  140.  
  141.         SOM_CATCH_ALL
  142.           return 0;
  143.         SOM_ENDTRY
  144.  
  145.           if(!initColor)
  146.           {
  147.              pColorData->origColor = pColorData->currColor = IDMA_COLOR_WHITE;
  148.           }
  149.           else
  150.           {
  151.               /* select the appropriate color */
  152.               switch(initColor)
  153.               {
  154.                 case CLR_DARKGRAY:
  155.                     pColorData->origColor = IDMA_COLOR_GRAY;
  156.                     break;
  157.                 case CLR_RED:
  158.                     pColorData->origColor = IDMA_COLOR_RED;
  159.                     break;
  160.                 case CLR_GREEN:
  161.                     pColorData->origColor = IDMA_COLOR_GREEN;
  162.                     break;
  163.                 case CLR_YELLOW:
  164.                     pColorData->origColor = IDMA_COLOR_YELLOW;
  165.                     break;
  166.                 case CLR_BLUE:
  167.                     pColorData->origColor = IDMA_COLOR_BLUE;
  168.                     break;
  169.                 case CLR_DARKPINK:
  170.                     pColorData->origColor = IDMA_COLOR_MAGENTA;
  171.                     break;
  172.                 case CLR_CYAN:
  173.                     pColorData->origColor = IDMA_COLOR_CYAN;
  174.                     break;
  175.                 case CLR_WHITE:
  176.                 default:
  177.                     pColorData->origColor = IDMA_COLOR_WHITE;
  178.                     break;
  179.               }
  180.               pColorData->currColor = pColorData->origColor;
  181.           }
  182.           /* store the kind name in the listbox reserved memory area  */
  183.           WinSetWindowULong( hwnd, 0, (ULONG)pColorData);
  184.           WinSendMsg(WinWindowFromID(hwnd, pColorData->origColor), BM_CLICK,
  185.              MPFROMSHORT(FALSE), 0);
  186.  
  187.        }
  188.  
  189.        case WM_CONTROL:
  190.        {
  191.            switch (SHORT2FROMMP(mp1))
  192.            {
  193.              case BN_CLICKED:
  194.              {
  195.                ODULong whichColor = 0;
  196.                USHORT usCheckId = SHORT1FROMMP(mp1);
  197.                switch (usCheckId)
  198.                {
  199.                   case IDMA_COLOR_GRAY:
  200.                       whichColor = IDMA_COLOR_GRAY;
  201.                       break;
  202.  
  203.                   case IDMA_COLOR_RED:
  204.                       whichColor = IDMA_COLOR_RED;
  205.                       break;
  206.                   case IDMA_COLOR_GREEN:
  207.                       whichColor = IDMA_COLOR_GREEN;
  208.                       break;
  209.                   case IDMA_COLOR_YELLOW:
  210.                       whichColor = IDMA_COLOR_YELLOW;
  211.                       break;
  212.                   case IDMA_COLOR_BLUE:
  213.                       whichColor = IDMA_COLOR_BLUE;
  214.                       break;
  215.                   case IDMA_COLOR_MAGENTA:
  216.                       whichColor = IDMA_COLOR_MAGENTA;
  217.                       break;
  218.                   case IDMA_COLOR_CYAN:
  219.                       whichColor = IDMA_COLOR_CYAN;
  220.                       break;
  221.                   case IDMA_COLOR_WHITE:
  222.                       whichColor = IDMA_COLOR_WHITE;
  223.                       break;
  224.  
  225.                 } /* end switch */
  226.                 pColorData = (PCOLORDATA)WinQueryWindowULong(hwnd, 0L);
  227.                 if(whichColor != pColorData->currColor)
  228.                 {
  229.                  pColorData->currColor = whichColor;
  230.  
  231.                 SOM_TRY
  232.  
  233.                  ContainerPartData * somThis = ContainerPartGetData(pColorData->realPart);
  234.                  displayFrame = (ODFrame *) somThis->fDisplayFrames->First();
  235.                  pColorData->realPart->HandleColorMenu(ev, displayFrame, whichColor);
  236.                  displayFrame->Invalidate(ev, kODNULL, kODNULL);
  237.  
  238.                 SOM_CATCH_ALL
  239.                 SOM_ENDTRY
  240.  
  241.                  return (MPARAM)0;
  242.                 }
  243.              }
  244.            }
  245.        break;
  246.        }
  247.        case WM_COMMAND:
  248.        {
  249.             switch (SHORT1FROMMP(mp1))
  250.             {
  251.               case DID_UNDO:
  252.               {
  253.                  pColorData = (PCOLORDATA)WinQueryWindowULong(hwnd, 0L);
  254.                  WinSendMsg(WinWindowFromID(hwnd, pColorData->origColor), BM_CLICK,
  255.                        MPFROMSHORT(FALSE), 0);
  256.                  return (MPARAM)0;
  257.               }
  258.               case DID_DEFAULT:
  259.               {
  260.                  WinSendMsg(WinWindowFromID(hwnd, IDMA_COLOR_WHITE), BM_CLICK,
  261.                        MPFROMSHORT(FALSE), 0);
  262.                  return (MPARAM)0;
  263.               }
  264.  
  265.             }
  266.  
  267.         }
  268.       case WM_FOCUSCHANGE:
  269.          /* On a focus change, we will post a message to process all of the
  270.           * changes to stuff.  We don't want to do it here, because if a
  271.           * method displays an error message, we can't switch focus to the
  272.           * message and will hang.
  273.           */
  274.          WinPostMsg(hwnd, WM_FOCUS_PROCESSING, mp1, mp2);
  275.          return WinDefDlgProc( hwnd, msg, mp1, mp2);
  276.  
  277.       case WM_FOCUS_PROCESSING:
  278.                   return (MPARAM)0;
  279.       case WM_DESTROY:
  280.       {
  281.          /* save everything, as the post by the WM_FOCUSCHANGE message
  282.           * will not get processed before this message kills the dialog.
  283.           */
  284.          WinSendMsg(hwnd, WM_FOCUS_PROCESSING, mp1, mp2);
  285.  
  286.          pColorData = (PCOLORDATA)WinQueryWindowULong(hwnd, 0L);
  287.          if(pColorData->realPart)
  288.  
  289.            SOM_TRY
  290.              pColorData->partWrapper->ReleaseRealPart(ev);
  291.            SOM_CATCH_ALL
  292.            SOM_ENDTRY
  293.  
  294.          if(pColorData)
  295.              delete pColorData;
  296.          return WinDefDlgProc(hwnd, msg, mp1, mp2);
  297.       }
  298.       default:
  299.          /* Pass all unprocessed messages to the default dialog proc.
  300.           */
  301.          return WinDefDlgProc( hwnd, msg, mp1, mp2);
  302.    }
  303. }
  304.  
  305. SOM_Scope ODULong  SOMLINK CNNotebookInsertBackgroundPage(CNNotebook *somSelf,
  306.                                                            Environment *ev,
  307.                                                           HWND hwndNotebook)
  308. {
  309.     CNNotebookData *somThis = CNNotebookGetData(somSelf);
  310.     CNNotebookMethodDebug("CNNotebook","CNNotebookInsertBackgroundPage");
  311.  
  312.     /*
  313.      * Called by AddNotebookPages to insert the Part-Properties Background
  314.      *   page. The user can then modify the parts background color.
  315.      *   It in turn calls InsertNotebookPage.
  316.      *  Returns: The pageid for the inserted page.
  317.      *
  318.      *  Note: It is helpful to send a pointer to the settings extension in
  319.      *        the create parameters so that the dialog procedure can
  320.      *        get access to the part's methods.
  321.      */
  322.  
  323.     PAGEINFO      pageinfo;
  324.  
  325.     CHAR LoadError[100];
  326.     APIRET rc = DosLoadModule(LoadError, sizeof(LoadError),
  327.                    "CNTMRI", &_hmodHandle);
  328.  
  329.     memset( (PCH)&pageinfo, 0, sizeof( PAGEINFO ) );
  330.     pageinfo.cb                = sizeof(PAGEINFO);
  331.     pageinfo.usPageStyleFlags  = BKA_MAJOR;
  332.     pageinfo.usPageInsertFlags = BKA_FIRST;
  333.     pageinfo.pfnwp             = (PFNWP)ColorPageDlgProc;
  334.     pageinfo.resid             = _hmodHandle;
  335.  
  336.  
  337.     pageinfo.dlgid             = DL_COLORS;
  338.     pageinfo.pszName           = "Background";
  339.     pageinfo.usSettingsFlags    = SETTINGS_PAGE_NUMBERS;
  340.     pageinfo.pCreateParams     = (PVOID)somSelf; /* Let dialog know what object */
  341.  
  342.     return somSelf->InsertNotebookPage(ev, hwndNotebook,  &pageinfo );
  343. }
  344.  
  345. SOM_Scope ODULong SOMLINK CNNotebookAddNotebookPages(CNNotebook *somSelf,
  346.                                                     Environment *ev,
  347.                                                    HWND hwndNotebook,ODULong flPageFlag, ODULong ulReserve)
  348. {
  349.     CNNotebookData *somThis = CNNotebookGetData(somSelf);
  350.     CNNotebookMethodDebug("CNNotebook","CNNotebookAddNotebookPages");
  351.  
  352.    SOM_TRY
  353.  
  354.     /* This method will add the background page behind the standard pages
  355.      */
  356.  
  357.     somSelf->InsertBackgroundPage(ev, hwndNotebook);
  358.  
  359.     /* insert all pages here to include container pages in proper order. 127364*/
  360. //  somSelf->InsertGeneralPage(ev, hwndNotebook);
  361. //  somSelf->InsertFilePage2(ev, hwndNotebook);
  362. //  somSelf->InsertFilePage1(ev, hwndNotebook);
  363. //
  364. //  somSelf->InsertDetailsViewPage(ev, hwndNotebook); // pages for containers
  365. //  somSelf->InsertTreeViewPage(ev, hwndNotebook);    //  "
  366. //  somSelf->InsertIconViewPage(ev, hwndNotebook);    //  "
  367. //
  368. //  somSelf->InsertViewPage(ev, hwndNotebook);
  369. //  somSelf->InsertTypePage(ev, hwndNotebook);
  370.  
  371.  
  372.  
  373.     CNNotebook_parent_ODSettingsExtension_AddNotebookPages(somSelf, ev,
  374.                                                   hwndNotebook, flPageFlag|kODFolderViewPages,ulReserve);
  375. //    somSelf->RemoveNotebookPages(ev,hwndNotebook, kODViewPage);
  376.  
  377.    SOM_CATCH_ALL
  378.    SOM_ENDTRY
  379.  
  380. return flPageFlag;
  381. }
  382.  
  383. SOM_Scope void  SOMLINK CNNotebooksomInit(CNNotebook *somSelf)
  384. {
  385.     CNNotebookData *somThis = CNNotebookGetData(somSelf);
  386.     CNNotebookMethodDebug("CNNotebook","CNNotebooksomInit");
  387.  
  388.     CNNotebook_parent_ODSettingsExtension_somInit(somSelf);
  389.  
  390.     _hmodHandle = 0;
  391. }
  392.  
  393. SOM_Scope void  SOMLINK CNNotebooksomUninit(CNNotebook *somSelf)
  394. {
  395.     CNNotebookData *somThis = CNNotebookGetData(somSelf);
  396.     CNNotebookMethodDebug("CNNotebook","CNNotebooksomUninit");
  397.  
  398.     DosFreeModule(_hmodHandle);
  399.     CNNotebook_parent_ODSettingsExtension_somUninit(somSelf);
  400. }
  401.  
  402.