home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / notebook / select / select.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-29  |  4.1 KB  |  135 lines

  1. //************************************************************
  2. // Notebook Control - Delayed Page Loading
  3. //
  4. // Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
  5. // Copyright (c) 1997 John Wiley & Sons, Inc. 
  6. // All Rights Reserved.
  7. //************************************************************
  8. #include <inotebk.hpp>
  9. #include <ipagehdr.hpp>
  10. #include <iframe.hpp>
  11. #include <iapp.hpp>
  12. #include <ihandle.hpp>
  13. #include <ifont.hpp>
  14. #include <ipoint.hpp>
  15. #include <icolor.hpp>
  16. #include "select.h"
  17.  
  18. // The page handler for capturing page select
  19. // events (used to delay dialog creation).
  20. class PageSelectHandler : public IPageHandler {
  21. protected:
  22. virtual Boolean
  23.   select ( IPageSelectEvent &event );
  24. };
  25.  
  26. void main ( )
  27. {
  28.   // Create the frame and the notebook.
  29.   IFrameWindow frame ("Delayed Addition of Pages");
  30.   INotebook    notebook (ID_NOTEBOOK, &frame, &frame);
  31.  
  32.   // Make the page parts the same color as the dialog.
  33.   notebook
  34.     .setPageBackgroundColor(
  35.               IGUIColor(IGUIColor::dialogBgnd))
  36.     .setMajorTabBackgroundColor(
  37.               IGUIColor(IGUIColor::dialogBgnd));
  38.  
  39.   // Declare a page settings object.
  40.   INotebook::PageSettings pageData(
  41.            INotebook::PageSettings::statusTextOn |
  42.            INotebook::PageSettings::majorTab |
  43.            INotebook::PageSettings::autoPageSize);
  44.  
  45.  
  46.   // Set up page 1 with text, a major tab, and a dialog.
  47.   // User data is 0 because we load the dialog here.
  48.   pageData
  49.     .setTabText("Page 1")
  50.     .setStatusText("Page 1")
  51.     .setUserData(0);
  52.  
  53.   // Create the dialog for the top page
  54.   // and add the page to the notebook.
  55.   IFrameWindow dialog1(ID_DIALOG1, ¬ebook, ¬ebook);
  56.   notebook.addLastPage( pageData, &dialog1);
  57.  
  58.   // Set up page 2 with text, a major tab, and a dialog.
  59.   // We store the dialog ID in user data and use it
  60.   // later to load the dialog.
  61.   pageData
  62.     .setTabText("Page 2")
  63.     .setStatusText("Page 2 - no window yet")
  64.     .setUserData(ID_DIALOG2);
  65.  
  66.   // Add page 2 to the notebook without a dialog.
  67.   notebook.addLastPage( pageData);
  68.  
  69.   // Repeat the above for page 3.
  70.   pageData
  71.     .setTabText("Page 3")
  72.     .setStatusText("Page 3 - no window yet")
  73.     .setUserData(ID_DIALOG3);
  74.   notebook.addLastPage( pageData);
  75.  
  76.   // Size the tabs to fit the text.
  77.   IFont noteFont(¬ebook);
  78.   ISize tabSize(ISize(noteFont.minTextWidth("no_window Page_3"),
  79.                       noteFont.maxCharHeight()) + ISize(6,6));
  80.   notebook
  81.     .setMajorTabSize(tabSize)
  82.     .setMinorTabSize(tabSize);
  83.  
  84.   // Create and energize a page handler to capture "select"
  85.   // events so we can add the missing dialogs.
  86.   PageSelectHandler pageHandler;
  87.   pageHandler.handleEventsFor(&frame);
  88.  
  89.   // Put the notebook in the client and show the frame.
  90.   frame
  91.     .setClient(¬ebook)
  92.     .show();
  93.   dialog1.setFocus();
  94.  
  95.   // Run the application.
  96.   IApplication::current().run();
  97. }
  98.  
  99.  
  100. Boolean PageSelectHandler::select  ( IPageSelectEvent  &event )
  101. {
  102.   IPageHandle selectedPage = event.pageHandle();
  103.   INotebook* notebook = event.notebook();
  104.   INotebook::PageSettings pageData =
  105.                 event.notebook()->pageSettings(selectedPage);
  106.   unsigned long dialogId = pageData.userData();
  107.  
  108.   // If we have a dialog ID in user data, the frame needs to
  109.   // be created.
  110.   if (dialogId != 0) {
  111.     IFrameWindow* dialog = new IFrameWindow(
  112.                                     dialogId,
  113.                                     notebook,
  114.                                     notebook);
  115.  
  116.     // Size the dialog to the size of the page.
  117.     (*dialog).sizeTo((*notebook).pageSize());
  118.  
  119.     // Put the page on the notebook, and set user data to
  120.     // zero to indicate that we've added the page window.
  121.     IString statusText
  122.               = pageData.tabText() + " has been added";
  123.     (*notebook)
  124.        .setStatusText( selectedPage, statusText ) 
  125.        .setWindow( selectedPage, dialog)
  126.        .setUserData(selectedPage, 0);
  127.   }
  128.   else
  129.   {    // Page window already loaded.
  130.       (*notebook)
  131.          .setStatusText(selectedPage, pageData.tabText());
  132.   }
  133.   return false;
  134. }
  135.