home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / ioc / notebook / notebook.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  8.1 KB  |  152 lines

  1. /******************************************************************************
  2. * .FILE:         notebook.cpp                                                 *
  3. *                                                                             *
  4. * .DESCRIPTION:  Notebook Sample Program:  Class Implementation               *
  5. *                                                                             *
  6. * .CLASSES:      ABitmapNotebook                                              *
  7. *                                                                             *
  8. * .COPYRIGHT:                                                                 *
  9. *    Licensed Material - Program-Property of IBM                              *
  10. *    (C) Copyright IBM Corp. 1992, 1996 - All Rights Reserved                 *
  11. *                                                                             *
  12. * .DISCLAIMER:                                                                *
  13. *   The following [enclosed] code is sample code created by IBM               *
  14. *   Corporation.  This sample code is not part of any standard IBM product    *
  15. *   and is provided to you solely for the purpose of assisting you in the     *
  16. *   development of your applications.  The code is provided 'AS IS',          *
  17. *   without warranty of any kind.  IBM shall not be liable for any damages    *
  18. *   arising out of your use of the sample code, even if they have been        *
  19. *   advised of the possibility of such damages.                               *
  20. *                                                                             *
  21. * .NOTE: WE RECOMMEND USING A FIXED SPACE FONT TO LOOK AT THE SOURCE          *
  22. *                                                                             *
  23. ******************************************************************************/
  24. #include <ibase.hpp>
  25. #include <iapp.hpp>
  26. #include <ifont.hpp>
  27. #include <icolor.hpp>
  28. #include <ireslib.hpp>
  29. #include <icoordsy.hpp>
  30. #include "notebook.hpp"
  31. #include "notebook.h"
  32.  
  33. /**************************************************************************
  34. * main() - Application Entry Point                                        *
  35. **************************************************************************/
  36. int main()
  37. {
  38.   ICoordinateSystem::setApplicationOrientation(
  39.           ICoordinateSystem::originLowerLeft );
  40.  
  41. /*------------------------------------------------------------------------|
  42. |  Change the default style for bitmaps that are about to be created.     |
  43. |  Create an ABitmapNotebook object with window ID WND_MAIN.              |
  44. |  Show the main window and begin processing events.                      |
  45. |------------------------------------------------------------------------*/
  46.    IBitmapControl::setDefaultStyle(IBitmapControl::defaultStyle() |
  47.                                    IBitmapControl::sizeToBitmap);
  48.    ABitmapNotebook mainWindow(WND_MAIN);
  49.    mainWindow.show();
  50. #ifdef IC_WIN
  51.    INotebook::setDefaultStyle(INotebook::defaultStyle() |
  52.                               INotebook::pmCompatible);
  53.    ABitmapNotebook mainWindow2(WND_MAIN);
  54.    mainWindow2.show();
  55. #endif
  56.    IApplication::current().run();
  57.    return 0;
  58. }
  59.  
  60. /**************************************************************************
  61. * ABitmapNotebook :: ABitmapNotebook - constuctor                         *
  62. *                                                                         *
  63. * Construct the IFrameWindow using the default style.                     *
  64. * Create a resource library object for accessing the IResourceLibrary     *
  65. *   loadBitmap function.                                                  *
  66. * Create a size object to be used in creating the notebook tabs.          *
  67. * Create each notebook major tab from a bitmap specified in the           *
  68. *   application resource file and the previously created tabSize.         *
  69. * Create the notebook as a child window of the frame and with a spiral    *
  70. *   binding.  The binding is put at the top because the back pages are    *
  71. *   located at the bottom left corner of the window.                      *
  72. * Create each viewport as a child window of the notebook.                 *
  73. * Create each bitmap as a child window of the corresponding viewport.     *
  74. **************************************************************************/
  75. ABitmapNotebook :: ABitmapNotebook(unsigned long windowId)
  76.         :IFrameWindow(windowId)
  77.         ,reslib()
  78.         ,tabSize(50,50)
  79.         ,tab1(reslib.loadBitmap(BM_PAGE1, tabSize))
  80.         ,tab2(reslib.loadBitmap(BM_PAGE2, tabSize))
  81.         ,tab3(reslib.loadBitmap(BM_PAGE3, tabSize))
  82.         ,tab4(reslib.loadBitmap(BM_PAGE4, tabSize))
  83.         ,notebook( WND_NB, this, this, IRectangle()
  84.                  , INotebook::defaultStyle()
  85.                  &~INotebook::majorTabsRight
  86.                  | INotebook::majorTabsBottom
  87.                  | INotebook::spiralBinding)
  88.         ,viewport1(WND_VP1, ¬ebook, ¬ebook)
  89.         ,viewport2(WND_VP2, ¬ebook, ¬ebook)
  90.         ,viewport3(WND_VP3, ¬ebook, ¬ebook)
  91.         ,viewport4(WND_VP4, ¬ebook, ¬ebook)
  92.         ,bitmap1(BM_PAGE1, &viewport1, &viewport1, BM_PAGE1)
  93.         ,bitmap2(BM_PAGE2, &viewport2, &viewport2, BM_PAGE2)
  94.         ,bitmap3(BM_PAGE3, &viewport3, &viewport3, BM_PAGE3)
  95.         ,bitmap4(BM_PAGE4, &viewport4, &viewport4, BM_PAGE4)
  96. {
  97. /*------------------------------------------------------------------------|
  98. |  Load the font string from the resource and set the point size to 24.   |
  99. |  Set bitmap 3 to the new font.                                          |
  100. |  Set the color of the text to red.  Before major version 300, the       |
  101. |    IStaticText setColor function was used to set the color of the       |
  102. |    bitmap control.  Beginning in version 300, an IWindow function for   |
  103. |    each color area is provided and should be used, instead.             |
  104. |  Set the text in the bitmap to a string representing the sound of a cat.|
  105. |  Align the text in the bitmap to the bottom center of the window.       |
  106. |------------------------------------------------------------------------*/
  107.   IResourceLibrary reslib;
  108.   IFont font(reslib.loadString(STR_FONT),24);
  109.   bitmap3.setFont(font);
  110.  
  111.   bitmap3.setForegroundColor(IColor::red);
  112.   bitmap3.setText(reslib.loadString(STR_PRRR));
  113.   bitmap3.setAlignment(IStaticText::bottomCenter);
  114.  
  115. /*------------------------------------------------------------------------|
  116. |  Create a page settings object that specifies the type of tab to use,   |
  117. |    that status text should be displayed, and that pages should be       |
  118. |    automatically sized to fit the notebook.                             |
  119. |  For each page to be added to the notebook,                             |
  120. |    set the tab using a previously loaded bitmap,                        |
  121. |    set the status text from a string in the resource file,              |
  122. |    add the viewport containing the the appropriate bitmap to the        |
  123. |      notebook using the page settings created previously.               |
  124. |------------------------------------------------------------------------*/
  125.   INotebook::PageSettings majorTab(INotebook::PageSettings::majorTab|
  126.                                    INotebook::PageSettings::statusTextOn |
  127.                                    INotebook::PageSettings::autoPageSize);
  128.  
  129.   majorTab.setTabBitmap(tab1);
  130.   majorTab.setStatusText(BM_PAGE1);
  131.   notebook.addLastPage(majorTab, &viewport1);
  132.  
  133.   majorTab.setTabBitmap(tab2);
  134.   majorTab.setStatusText(BM_PAGE2);
  135.   notebook.addLastPage(majorTab, &viewport2);
  136.  
  137.   majorTab.setTabBitmap(tab3);
  138.   majorTab.setStatusText(BM_PAGE3);
  139.   notebook.addLastPage(majorTab, &viewport3);
  140.  
  141.   majorTab.setTabBitmap(tab4);
  142.   majorTab.setStatusText(BM_PAGE4);
  143.   notebook.addLastPage(majorTab, &viewport4);
  144.  
  145. /*------------------------------------------------------------------------|
  146. | Set the icon of the application and make the notebook the cleint of the |
  147. | frame window.                                                           |
  148. -------------------------------------------------------------------------*/
  149.   setIcon(WND_MAIN);
  150.   setClient(¬ebook);
  151. } /* end ABitmapNotebook::ABitmapNotebook(...) */
  152.