home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / TOOLBRES.PAK / TOOLBRES.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.1 KB  |  115 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1996 by Borland International, All Rights Reserved
  4. //
  5. // Illustrates usage of Toolbar resource
  6. //----------------------------------------------------------------------------
  7. #include <owl/pch.h>
  8. #if !defined(OWL_DECFRAME_H)
  9. # include <owl/decframe.h>
  10. #endif
  11. #if !defined(OWL_STATUSBA_H)
  12. # include <owl/statusba.h>
  13. #endif
  14. #if !defined(OWL_CONTROLB_H)
  15. # include <owl/controlb.h>
  16. #endif
  17. #if !defined(OWL_RESOURCE_H)
  18. # include <owl/resource.h>
  19. #endif
  20. #if !defined(OWL_EDITFILE_H)
  21. # include <owl/editfile.h>
  22. #endif
  23. #include <stdio.h>
  24.  
  25. //
  26. // class TSampleApp
  27. // ~~~~~ ~~~~~~~~~~
  28. class TSampleApp : public TApplication {
  29.   public:
  30.     TSampleApp(){}
  31.  
  32.     // Override virtuals from TApplication
  33.     //
  34.     void    InitMainWindow();
  35. };
  36.  
  37. void
  38. TSampleApp::InitMainWindow()
  39. {
  40.   // Setup main window + client
  41.   //
  42.   SetMainWindow(new TDecoratedFrame(0, 0, new TEditFile()));
  43.  
  44.   // Create decoration objects
  45.   //
  46.   TStatusBar*  sbar = new TStatusBar(GetMainWindow());
  47.   TControlBar* cbar = new TControlBar(GetMainWindow());
  48.  
  49.   // Build toolbar from resource
  50.   //
  51.   TToolbarBldr(*cbar, 1000).Build();
  52.  
  53. #if 0
  54.  
  55.   // Load toolbar resource
  56.   // NOTE: Don't let TToolbarRes own bitmap, we'll give it to TCelArray 
  57.   //       instead.
  58.   //
  59.   TToolbarRes tbRes(*this, 1000, NoAutoDelete);
  60.   if (tbRes.IsOK()) {
  61.     TCelArray* celArray = new TCelArray(&tbRes.GetBitmap(), tbRes.GetCount(),
  62.                                         TSize(tbRes.GetWidth(),
  63.                                               tbRes.GetHeight()));
  64.     cbar->SetCelArray(celArray);
  65.  
  66.     //
  67.     //
  68.     for (int i=0, j=0; i<tbRes.GetCount(); i++) {
  69.       if (tbRes.GetIds()[i] == 0)
  70.         cbar->Insert(*new TSeparatorGadget(6));
  71.       else {
  72.         cbar->Insert(*new TButtonGadget(j, tbRes.GetIds()[i], 
  73.                                         TButtonGadget::Command, 
  74.                                         false, TButtonGadget::Up, true));
  75.         j++;
  76.       }
  77.     }
  78.   }
  79.  
  80. /////////////////////////// OLD METHOD ////////////////////////////////
  81.  
  82.   // Insert gadgets in control bar
  83.   //
  84.   cbar->Insert(*new TButtonGadget(CM_FILENEW, CM_FILENEW));
  85.   cbar->Insert(*new TButtonGadget(CM_FILEOPEN, CM_FILEOPEN));
  86.   cbar->Insert(*new TButtonGadget(CM_FILESAVE, CM_FILESAVE));
  87.   cbar->Insert(*new TButtonGadget(CM_FILEPRINT, CM_FILEPRINT));
  88.  
  89.   cbar->Insert(*new TSeparatorGadget(6));
  90.   cbar->Insert(*new TButtonGadget(CM_EDITUNDO, CM_EDITUNDO));
  91.   cbar->Insert(*new TButtonGadget(CM_EDITCUT, CM_EDITCUT));
  92.   cbar->Insert(*new TButtonGadget(CM_EDITCOPY, CM_EDITCOPY));
  93.   cbar->Insert(*new TButtonGadget(CM_EDITPASTE, CM_EDITPASTE));
  94.  
  95. #endif
  96.  
  97.   // Insert decorations in main window
  98.   //
  99.   TYPESAFE_DOWNCAST(GetMainWindow(), TDecoratedFrame)->Insert(
  100.                     *cbar, TDecoratedFrame::Top);
  101.   TYPESAFE_DOWNCAST(GetMainWindow(), TDecoratedFrame)->Insert(
  102.                     *sbar, TDecoratedFrame::Bottom);
  103.  
  104.   GetMainWindow()->AssignMenu(100);
  105. }
  106.  
  107. //
  108. //
  109. //
  110. int
  111. OwlMain(int /*argc*/, char* /*argv*/ [])
  112. {
  113.   return TSampleApp().Run();
  114. }
  115.