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

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1996, 1996 by Borland International, All Rights Reserved
  4. //
  5. // $Revision:   10.3  $
  6. //
  7. // Docking window example main source file
  8. //----------------------------------------------------------------------------
  9. #include <owl/pch.h>
  10. #include <owl/printer.h>
  11. #include <owl/buttonga.h>
  12. #include <owl/textgadg.h>
  13. #include <owl/controlb.h>
  14. #include <owl/controlg.h>
  15. #include <owl/statusba.h>
  16. #include <owl/docking.h>
  17. #include <owl/combobox.h>
  18. #include <owl/edit.h>
  19. #include <owl/decmdifr.h>
  20. #include <owl/editfile.h>
  21. #include <dir.h>
  22. #include "docking.h"
  23.  
  24. //
  25. // Build a response table for all messages/commands handled
  26. // by the application.
  27. //
  28. DEFINE_RESPONSE_TABLE1(TDockingApp, TApplication)
  29.   EV_COMMAND(CM_HELPABOUT, CmHelpAbout),
  30.   EV_COMMAND(CM_MDIFILENEW, CmFileNew),
  31.   EV_COMMAND(CM_MDIFILEOPEN, CmFileOpen),
  32.   EV_COMMAND(CM_FILEPRINT, CmFilePrint),
  33.   EV_COMMAND(CM_FILEPRINTERSETUP, CmFilePrintSetup),
  34.   EV_COMMAND(CM_FILEPRINTPREVIEW, CmFilePrintPreview),
  35.   EV_COMMAND_ENABLE(CM_FILEPRINT, CePrint),
  36.   EV_COMMAND_ENABLE(CM_FILEPRINTERSETUP, CePrint),
  37.   EV_COMMAND_ENABLE(CM_FILEPRINTPREVIEW, CePrint),
  38. END_RESPONSE_TABLE;
  39.  
  40.  
  41. //
  42. //
  43. //
  44. TDockingApp::TDockingApp() : TApplication("Docking Example")
  45. {}
  46.  
  47.  
  48. TDockingApp::~TDockingApp()
  49. {}
  50.  
  51. static TDockable* 
  52. newSpeedbar(TDecoratedFrame* frame, const char* caption)
  53. {
  54.   // Create command toolbar and associate toolbar buttons with commands.
  55.   //
  56.   TDockableControlBar* cb = new TDockableControlBar(frame);
  57.   cb->SetCaption(caption);
  58.   cb->Insert(*new TButtonGadget(CM_MDIFILENEW, CM_MDIFILENEW));
  59.   cb->Insert(*new TButtonGadget(CM_MDIFILEOPEN, CM_MDIFILEOPEN));
  60.   cb->Insert(*new TButtonGadget(CM_FILESAVE, CM_FILESAVE));
  61.   cb->Insert(*new TSeparatorGadget);
  62.   cb->Insert(*new TButtonGadget(CM_EDITCUT, CM_EDITCUT));
  63.   cb->Insert(*new TButtonGadget(CM_EDITCOPY, CM_EDITCOPY));
  64.   cb->Insert(*new TButtonGadget(CM_EDITPASTE, CM_EDITPASTE));
  65.   cb->Insert(*new TSeparatorGadget);
  66.   cb->Insert(*new TButtonGadget(CM_EDITUNDO, CM_EDITUNDO));
  67.   cb->Insert(*new TSeparatorGadget);
  68.   cb->Insert(*new TButtonGadget(CM_EDITREDO, CM_EDITREDO));
  69.   cb->Insert(*new TSeparatorGadget);
  70.   cb->Insert(*new TButtonGadget(CM_EDITFIND, CM_EDITFIND));
  71.   cb->Insert(*new TButtonGadget(CM_EDITFINDNEXT, CM_EDITFINDNEXT));
  72.   cb->Insert(*new TSeparatorGadget);
  73.   cb->Insert(*new TButtonGadget(CM_FILEPRINT, CM_FILEPRINT));
  74.   cb->Insert(*new TButtonGadget(CM_FILEPRINTPREVIEW, CM_FILEPRINTPREVIEW));
  75.  
  76.   // Add fly-over help hints.
  77.   //
  78.   cb->SetHintMode(TGadgetWindow::EnterHints);
  79.   return cb;
  80. }
  81.  
  82. void 
  83. TDockingApp::SetupSpeedBar(TDecoratedFrame* frame)
  84. {
  85.   Harbor = new THarbor(*frame);
  86.  
  87.   // Create text style toolbar and associate toolbar buttons with commands.
  88.   //
  89.   TDockableControlBar* cb2 = new TDockableControlBar(frame);
  90.   cb2->SetCaption("Toolbar with Combobox");
  91.   TComboBox* cBox = new TComboBox(0, 500, 0, 0, 180, 150, CBS_DROPDOWNLIST, 20);
  92.   cb2->Insert(*new TControlGadget(*cBox));
  93.   cb2->Insert(*new TSeparatorGadget);
  94.   cb2->Insert(*new TControlGadget(*new TComboBox(0, 510, 0, 0, 50, 100, CBS_DROPDOWNLIST, 20)));
  95.   cb2->Insert(*new TSeparatorGadget);
  96.   cb2->Insert(*new TButtonGadget(CM_FONTBOLD, CM_FONTBOLD));
  97.   cb2->Insert(*new TSeparatorGadget);
  98.   cb2->Insert(*new TButtonGadget(CM_FONTITALIC, CM_FONTITALIC));
  99.   cb2->Insert(*new TSeparatorGadget);
  100.   cb2->Insert(*new TButtonGadget(CM_FONTUNDER, CM_FONTUNDER));
  101.   cb2->Insert(*new TSeparatorGadget);
  102.   cb2->Insert(*new TButtonGadget(CM_FONTLEFT, CM_FONTLEFT));
  103.   cb2->Insert(*new TButtonGadget(CM_FONTRIGHT, CM_FONTRIGHT));
  104.   cb2->Insert(*new TButtonGadget(CM_FONTCENTER, CM_FONTCENTER));
  105.  
  106.   // Insert some toolbars on the edges
  107.   //
  108.   Harbor->Insert(*cb2, alTop);
  109.   Harbor->Insert(*newSpeedbar(frame, "Toolbar 1"), alTop);
  110.   Harbor->Insert(*newSpeedbar(frame, "Toolbar 2"), alRight);
  111.  
  112.   // Create a dockable floating toolbar
  113.   //
  114.   Harbor->Insert(*newSpeedbar(frame, "Toolbar 3"), alNone);
  115.  
  116.   // Create coord toolbar and associate toolbar buttons with commands.
  117.   //
  118.   TDockableControlBar* cb3 = new TDockableControlBar(frame);
  119.   cb3->SetCaption("Toolbar with Edit controls");
  120.   cb3->Insert(*new TTextGadget(650, TGadget::None, TTextGadget::Left, 1, "X"));
  121.   cb3->Insert(*new TControlGadget(*new TEdit(0, 651, "10", 0, 0, 60, 24, 4)));
  122.   cb3->Insert(*new TSeparatorGadget);
  123.  
  124.   cb3->Insert(*new TTextGadget(660, TGadget::None, TTextGadget::Left, 1, "Y"));
  125.   cb3->Insert(*new TControlGadget(*new TEdit(0, 661, "20", 0, 0, 60, 24, 4)));
  126.   cb3->Insert(*new TSeparatorGadget);
  127.  
  128.   cb3->Insert(*new TTextGadget(670, TGadget::None, TTextGadget::Left, 1, "W"));
  129.   cb3->Insert(*new TControlGadget(*new TEdit(0, 671, "30", 0, 0, 60, 24, 4)));
  130.   cb3->Insert(*new TSeparatorGadget);
  131.  
  132.   cb3->Insert(*new TTextGadget(680, TGadget::None, TTextGadget::Left, 1, "H"));
  133.   cb3->Insert(*new TControlGadget(*new TEdit(0, 681, "40", 0, 0, 60, 24, 4)));
  134.  
  135.   Harbor->Insert(*cb3, alLeft);
  136. }
  137.  
  138. //
  139. // Application intialization.
  140. //
  141. void TDockingApp::InitMainWindow()
  142. {
  143.   if (nCmdShow != SW_HIDE)
  144.     nCmdShow = (nCmdShow != SW_SHOWMINNOACTIVE) ? SW_SHOWNORMAL : nCmdShow;
  145.  
  146.   MdiClient = new TMDIClient;
  147.   TDecoratedMDIFrame* frame = new TDecoratedMDIFrame(Name, IDM_MAIN, *MdiClient, true);
  148.  
  149.   // Assign ICON w/ this application.
  150.   //
  151.   frame->SetIcon(this, IDI_MDIAPPLICATION);
  152.  
  153.   // Associate with the accelerator table.
  154.   //
  155.   frame->Attr.AccelTable = IDA_MAIN;
  156.  
  157.   SetupSpeedBar(frame);
  158.  
  159.   TStatusBar *sb = new TStatusBar(frame, TGadget::Recessed,
  160.                                   TStatusBar::CapsLock | 
  161.                                   TStatusBar::NumLock |
  162.                                   TStatusBar::ScrollLock | 
  163.                                   TStatusBar::SizeGrip);
  164.  
  165.   // Show hints in the text gadget
  166.   //
  167.   sb->SetWideHints(false);
  168.   frame->Insert(*sb, TDecoratedFrame::Bottom);
  169.  
  170.   SetMainWindow(frame);
  171.   frame->SetMenuDescr(TMenuDescr(IDM_MAIN, 1, 2, 0, 0, 1, 1));
  172. }
  173.  
  174.  
  175. //
  176. // Menu Help About palette.exe command
  177. //
  178. void TDockingApp::CmHelpAbout()
  179. {
  180.   GetMainWindow()->MessageBox("Dockable toolbar Example", "About", MB_OK);
  181. }
  182.  
  183. void TDockingApp::CmFileNew()
  184. {
  185.   char  title[255];
  186.  
  187.   // Generate a title for the MDI child window.
  188.   //
  189.   wsprintf(title, "%d", ChildCount++);
  190.  
  191.   TMDIChild* child = new TMDIChild(*MdiClient, title, new TEditFile(0, 0, 0));
  192.  
  193.   // Associate ICON w/ this child window.
  194.   //
  195.   child->SetIcon(this, IDI_DOC);
  196.  
  197.   // If the current active MDI child is maximize then this one should be also.
  198.   //
  199.   TMDIChild* curChild = MdiClient->GetActiveMDIChild();
  200.   if (curChild && (curChild->GetWindowLong(GWL_STYLE) & WS_MAXIMIZE))
  201.     child->Attr.Style |= WS_MAXIMIZE;
  202.  
  203.   child->Create();
  204. }
  205.  
  206. void TDockingApp::OpenFile(const char* fileName)
  207. {
  208.   if (fileName)
  209.     strcpy(FileData.FileName, fileName);
  210.  
  211.   // Create a MDIChild window whose client is TEditFile.
  212.   //
  213.   TMDIChild* child = new TMDIChild(*MdiClient, "",
  214.     new TEditFile(0, 0, 0, 0, 0, 0, 0, FileData.FileName));
  215.  
  216.   // Associate ICON w/ this child window.
  217.   //
  218.   child->SetIcon(this, IDI_DOC);
  219.  
  220.   // If the current active MDI child is maximize then this one should be also.
  221.   //
  222.   TMDIChild* curChild = MdiClient->GetActiveMDIChild();
  223.   if (curChild && (curChild->GetWindowLong(GWL_STYLE) & WS_MAXIMIZE))
  224.     child->Attr.Style |= WS_MAXIMIZE;
  225.  
  226.   child->Create();
  227. }
  228.  
  229. //
  230. // Menu File Open command
  231. //
  232. void TDockingApp::CmFileOpen()
  233. {
  234.   // Display standard Open dialog box to select a file name.
  235.   //
  236.   *FileData.FileName = 0;
  237.   if (TFileOpenDialog(GetMainWindow(), FileData).Execute() == IDOK)
  238.     OpenFile();
  239. }
  240.  
  241. //
  242. // Menu File Print command
  243. //
  244. void TDockingApp::CmFilePrint()
  245. {
  246. }
  247.  
  248. //
  249. // Menu File Print Setup command
  250. //
  251. void TDockingApp::CmFilePrintSetup()
  252. {
  253. }
  254.  
  255. //
  256. // Menu File Print Preview command
  257. //
  258. void TDockingApp::CmFilePrintPreview()
  259. {
  260. }
  261.  
  262. //
  263. // Menu enabler used by Print, Print Setup and Print Preview.
  264. //
  265. void TDockingApp::CePrint(TCommandEnabler& ce)
  266. {
  267.   ce.Enable(true);
  268. }
  269.  
  270. int OwlMain(int , char* [])
  271. {
  272.   return TDockingApp().Run();
  273. }
  274.