home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / expert.pak / CMDI.OWL < prev    next >
Text File  |  1997-07-23  |  13KB  |  403 lines

  1. ##{cheader.snp}
  2. #include <owl\owlpch.h>
  3. #pragma hdrstop
  4.  
  5. ##@OPT_APPL_DRAGDROP 2
  6. #include <dir.h>
  7.  
  8. ##QUERY_FILE_H [[FileName]]
  9. #include "[[FileName]]"
  10. ##<<TMDIClient QUERY_FILE_H [[FileName]]
  11. #include "[[FileName]]"
  12. ##<<TDialog QUERY_FILE_H [[Filename]]
  13. #include "[[Filename]]"                        // Definition of about dialog.       
  14.  
  15.  
  16. ##--BEGIN-- @OPT_APPL_HELP
  17. ##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  18. //
  19. // Generated help file.
  20. //
  21. ##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  22. ##@QUERY_APPL_HELP [[HelpFile]]
  23. const char HelpFileName[] = "[[HelpFile]].hlp";
  24.  
  25.  
  26. ##--END-- @OPT_APPL_HELP
  27. ##{cdragdrp.owl}
  28. //{{[[TApplication]] Implementation}}
  29.  
  30.  
  31. ##--BEGIN-- @QUERY_APPL_OLE_AUTO 
  32. //
  33. // OLE's ITypeInfo browses this symbol table for a list of all data,
  34. // properties, and methods exposed by this automated class.
  35. //
  36. DEFINE_AUTOCLASS([[TApplication]])
  37.     EXPOSE_APPLICATION([[TApplication]], "Application", "Application object", 0)
  38.     EXPOSE_QUIT("Quit", "Quit application", 0)
  39. //{{[[TApplication]]SYM_TBL_BEGIN}}
  40. //{{[[TApplication]]SYM_TBL_END}}
  41. END_AUTOCLASS([[TApplication]], tfAppObject | tfCanCreate, "[[TApplication]]", 0, 0);
  42.  
  43.  
  44. DEFINE_APP_DICTIONARY(AppDictionary);
  45. static TPointer<TRegistrar> Registrar;
  46.  
  47. REGISTRATION_FORMAT_BUFFER(100)
  48.  
  49. BEGIN_REGISTRATION(ApplicationReg)
  50. ##@QUERY_OLE_GUID [[GUID]]
  51.     REGDATA(clsid, "{[[GUID]]}")
  52. ##--BEGIN-- @QUERY_PRJ_NAME [[AppTitle]]
  53.     REGDATA(progid, "[[AppTitle]].Application.1")
  54.     REGDATA(appname, "[[AppTitle]] Server")
  55.     REGDATA(description, "[[AppTitle]] Server Application")
  56.     REGDATA(cmdline, "/Automation")
  57. //    REGDATA(debugger, "TDW")
  58. ##--END-- @QUERY_PRJ_NAME [[AppTitle]]
  59. END_REGISTRATION
  60.  
  61.  
  62. ##--END-- @QUERY_APPL_OLE_AUTO 
  63. ##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  64. //
  65. // Build a response table for all messages/commands handled
  66. // by the application.
  67. //
  68. ##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  69. DEFINE_RESPONSE_TABLE1([[TApplication]], TApplication)
  70. //{{[[TApplication]]RSP_TBL_BEGIN}}
  71. ##@OPT_APPL_HELP 2
  72. ##:DBResponse(\\"[[TApplication]]", "CM_HELPCONTENTS", "CmHelpContents", "", "COMMAND")
  73. ##:DBResponse(\\"[[TApplication]]", "CM_HELPUSING", "CmHelpUsing", "", "COMMAND")
  74.     EV_COMMAND(CM_HELPCONTENTS, CmHelpContents),
  75.     EV_COMMAND(CM_HELPUSING, CmHelpUsing),
  76. ##:DBResponse(\\"[[TApplication]]", "CM_HELPABOUT", "CmHelpAbout", "", "COMMAND")
  77.     EV_COMMAND(CM_HELPABOUT, CmHelpAbout),
  78. ##@OPT_APPL_DRAGDROP
  79. ##:DBResponse(\\"[[TApplication]]", "", "", "WM_DROPFILES", "")
  80.     EV_WM_DROPFILES,
  81. ##@OPT_APPL_PRINTING
  82. ##:DBResponse(\\"[[TApplication]]", "", "", "WM_WININICHANGE", "")
  83.     EV_WM_WININICHANGE,
  84. //{{[[TApplication]]RSP_TBL_END}}
  85. END_RESPONSE_TABLE;
  86.  
  87.  
  88. ##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  89. //////////////////////////////////////////////////////////
  90. // [[TApplication]]
  91. // =====
  92. //
  93. ##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  94. ##@QUERY_APPL_OLE_AUTO
  95. [[TApplication]]::[[TApplication]] () : TApplication(::ApplicationReg["appname"], ::Module, &::AppDictionary)
  96. ##!@QUERY_APPL_OLE_AUTO
  97. ##QUERY_WIND_TITLE [[Title]]
  98. [[TApplication]]::[[TApplication]] () : TApplication("[[Title]]")
  99. {
  100. ##@OPT_APPL_HELP 3
  101.     HelpState = false;
  102.     ContextHelp = false;
  103.     HelpCursor = 0;
  104.  
  105. ##@OPT_APPL_PRINTING 3
  106.     Printer = 0;
  107.     Printing = 0;
  108.  
  109.     // INSERT>> Your constructor code here.
  110. }
  111.  
  112.  
  113. [[TApplication]]::~[[TApplication]] ()
  114. {
  115. ##@OPT_APPL_PRINTING 3
  116.     if (Printer)
  117.         delete Printer;
  118.  
  119.     // INSERT>> Your destructor code here.
  120. }
  121.  
  122.  
  123. ##--BEGIN-- @OPT_APPL_HELP
  124. bool [[TApplication]]::CanClose ()
  125. {
  126.     bool result = TApplication::CanClose();
  127.  
  128. ##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  129.     //
  130.     // Close the help engine if we used it.
  131.     //
  132. ##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  133.     if (result && HelpState)
  134.         GetMainWindow()->WinHelp(HelpFileName, HELP_QUIT, 0L);
  135.  
  136.     return result;
  137. }
  138.  
  139.  
  140. ##--END-- @OPT_APPL_HELP
  141. ##--BEGIN-- @OPT_APPL_TOOLBAR
  142. void [[TApplication]]::SetupSpeedBar (TDecoratedMDIFrame *frame)
  143. ##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  144.     //
  145.     // Create default toolbar New and associate toolbar buttons with commands.
  146.     //   
  147. ##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  148.     TControlBar* cb = new TControlBar(frame);
  149.     cb->Insert(*new TButtonGadget(CM_MDIFILENEW, CM_MDIFILENEW));
  150.     cb->Insert(*new TButtonGadget(CM_MDIFILEOPEN, CM_MDIFILEOPEN));
  151.     cb->Insert(*new TButtonGadget(CM_FILESAVE, CM_FILESAVE));
  152.     cb->Insert(*new TSeparatorGadget(6));
  153.     cb->Insert(*new TButtonGadget(CM_EDITCUT, CM_EDITCUT));
  154.     cb->Insert(*new TButtonGadget(CM_EDITCOPY, CM_EDITCOPY));
  155.     cb->Insert(*new TButtonGadget(CM_EDITPASTE, CM_EDITPASTE));
  156.     cb->Insert(*new TSeparatorGadget(6));
  157.     cb->Insert(*new TButtonGadget(CM_EDITUNDO, CM_EDITUNDO));
  158.     cb->Insert(*new TSeparatorGadget(6));
  159.     cb->Insert(*new TButtonGadget(CM_EDITFIND, CM_EDITFIND));
  160.     cb->Insert(*new TButtonGadget(CM_EDITFINDNEXT, CM_EDITFINDNEXT));
  161. ##@OPT_APPL_PRINTING 3
  162.     cb->Insert(*new TSeparatorGadget(6));
  163.     cb->Insert(*new TButtonGadget(CM_FILEPRINT, CM_FILEPRINT));
  164.     cb->Insert(*new TButtonGadget(CM_FILEPRINTPREVIEW, CM_FILEPRINTPREVIEW));
  165. ##@OPT_APPL_HELP 2
  166.     cb->Insert(*new TSeparatorGadget(6));
  167.     cb->Insert(*new TButtonGadget(CM_HELPCONTENTS, CM_HELPCONTENTS));
  168.  
  169. ##@QUERY_APPL_COMMENT == VALUE_VERBOSE
  170.     // Add fly-over help hints.
  171.     cb->SetHintMode(TGadgetWindow::EnterHints);
  172.  
  173.     frame->Insert(*cb, TDecoratedFrame::Top);
  174. }
  175.  
  176.  
  177. ##--END-- @OPT_APPL_TOOLBAR
  178. ##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  179. //////////////////////////////////////////////////////////
  180. // [[TApplication]]
  181. // =====
  182. // Application intialization.
  183. //
  184. ##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  185. void [[TApplication]]::InitMainWindow ()
  186. {
  187.     if (nCmdShow != SW_HIDE)
  188. ##@QUERY_APPL_STARTUP == VALUE_NORMAL
  189.         nCmdShow = (nCmdShow != SW_SHOWMINNOACTIVE) ? SW_SHOWNORMAL : nCmdShow;
  190. ##@QUERY_APPL_STARTUP == VALUE_MIN
  191.         nCmdShow = (nCmdShow != SW_SHOWMINNOACTIVE) ? SW_SHOWMINIMIZED : nCmdShow;
  192. ##@QUERY_APPL_STARTUP == VALUE_MAX
  193.         nCmdShow = (nCmdShow != SW_SHOWMINNOACTIVE) ? SW_SHOWMAXIMIZED : nCmdShow;
  194.  
  195. ##<<TMDIClient QUERY_CLASS_NAME [[TMDIClient]]
  196.     mdiClient = new [[TMDIClient]];
  197. ##@OPT_APPL_STATUSBAR
  198.     TDecoratedMDIFrame* frame = new TDecoratedMDIFrame(Name, MDI_MENU, *mdiClient, true);
  199. ##!@OPT_APPL_STATUSBAR
  200.     TDecoratedMDIFrame* frame = new TDecoratedMDIFrame(Name, MDI_MENU, *mdiClient, false);
  201.  
  202. ##QUERY_WIND_STYLE [[StyleAttributes]]
  203. ##StyleAttributes != "" 3
  204.     // Override the default window style for the main window.
  205. [[StyleAttributes]]
  206.  
  207. ##--BEGIN-- QUERY_WIND_BACKGRND [[BackgroundColor]]
  208. ##BackgroundColor != "" 3
  209.     // Change the window's background color
  210.     frame->SetBkgndColor([[BackgroundColor]]);
  211.  
  212. ##BackgroundColor == "" 3
  213.     // Set the client area to the application workspace color.
  214.     frame->SetBkgndColor(::GetSysColor(COLOR_APPWORKSPACE));
  215.  
  216. ##--END-- QUERY_WIND_BACKGRND [[BackgroundColor]]
  217. ##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  218.     //
  219.     // Assign ICON w/ this application.
  220.     //
  221. ##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  222.     frame->SetIcon(this, IDI_MDIAPPLICATION);
  223.  
  224. ##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  225.     //
  226.     // Menu associated with window and accelerator table associated with table.
  227.     //
  228. ##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  229.     frame->AssignMenu(MDI_MENU);
  230.     
  231. ##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  232.     //
  233.     // Associate with the accelerator table.
  234.     //
  235. ##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  236. ##@QUERY_APPL_MODEL == VALUE_MDI
  237.     frame->Attr.AccelTable = MDI_MENU;
  238. ##@QUERY_APPL_MODEL == VALUE_SDI
  239.     frame->Attr.AccelTable = SDI_MENU;
  240.  
  241. ##@OPT_APPL_TOOLBAR
  242.     SetupSpeedBar(frame);
  243. ##@OPT_APPL_STATUSBAR 7
  244.  
  245.     TStatusBar *sb = new TStatusBar(frame, TGadget::Recessed,
  246.                                     TStatusBar::CapsLock        |
  247.                                     TStatusBar::NumLock         |
  248.                                     TStatusBar::ScrollLock      |
  249.                                     TStatusBar::Overtype);
  250.     frame->Insert(*sb, TDecoratedFrame::Bottom);
  251.   
  252.     SetMainWindow(frame);
  253.  
  254.     frame->SetMenuDescr(TMenuDescr(MDI_MENU));
  255. ##--BEGIN-- @QUERY_APPL_CONTROL==VALUE_3D
  256.  
  257. ##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  258.     //
  259.     // Windows 3-D controls.
  260.     //
  261. ##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  262.     EnableCtl3d(true);
  263. ##--END-- @QUERY_APPL_CONTROL==VALUE_3D
  264. ##--BEGIN-- @QUERY_APPL_CONTROL==VALUE_BWCC
  265.  
  266. ##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  267.     //
  268.     // Borland Windows custom controls.
  269.     //
  270. ##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  271.     EnableBWCC();
  272. ##--END-- @QUERY_APPL_CONTROL==VALUE_BWCC
  273. }
  274. ##--BEGIN-- @OPT_APPL_HELP
  275.  
  276.  
  277. ##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  278. //////////////////////////////////////////////////////////
  279. // [[TApplication]]
  280. // =====
  281. // Menu Help Contents command
  282. ##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  283. void [[TApplication]]::CmHelpContents ()
  284. {
  285. ##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  286.     //
  287.     // Show the help table of contents.
  288.     //
  289. ##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  290.     HelpState = GetMainWindow()->WinHelp(HelpFileName, HELP_CONTENTS, 0L);
  291. }
  292.  
  293.  
  294. ##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  295. //////////////////////////////////////////////////////////
  296. // [[TApplication]]
  297. // =====
  298. // Menu Help Using Help command
  299. ##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  300. void [[TApplication]]::CmHelpUsing ()
  301. {
  302. ##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  303.     //
  304.     // Display the contents of the Windows help file.
  305.     //
  306. ##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  307.     HelpState = GetMainWindow()->WinHelp(HelpFileName, HELP_HELPONHELP, 0L);
  308. }
  309. ##--END-- @OPT_APPL_HELP
  310.  
  311.  
  312. ##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  313. //////////////////////////////////////////////////////////
  314. // [[TApplication]]
  315. // ===========
  316. ##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  317. ##@QUERY_TARGET_NAME [[Target]]
  318. // Menu Help About [[Target]] command
  319. void [[TApplication]]::CmHelpAbout ()
  320. {
  321. ##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  322.     //
  323.     // Show the modal dialog.
  324.     //
  325. ##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  326. ##<<TDialog QUERY_CLASS_NAME [[TDialog]]
  327.     [[TDialog]](MainWindow).Execute();
  328. }
  329. ##--BEGIN-- @OPT_APPL_DRAGDROP
  330.  
  331.  
  332. void [[TApplication]]::InitInstance ()
  333. {
  334.     TApplication::InitInstance();
  335.  
  336. ##:@QUERY_APPL_COMMENT == VALUE_VERBOSE
  337.     // Accept files via drag/drop in the frame window.
  338.     GetMainWindow()->DragAcceptFiles(true);
  339. }
  340.  
  341.  
  342. void [[TApplication]]::EvDropFiles (TDropInfo drop)
  343. {
  344. ##@QUERY_APPL_COMMENT == VALUE_VERBOSE
  345.     // Number of files dropped.
  346.     int totalNumberOfFiles = drop.DragQueryFileCount();
  347.  
  348.     TFileList* files = new TFileList;
  349.  
  350.     for (int i = 0; i < totalNumberOfFiles; i++) {
  351. ##@QUERY_APPL_COMMENT == VALUE_VERBOSE
  352.         // Tell DragQueryFile the file interested in (i) and the length of your buffer.
  353.         int     fileLength = drop.DragQueryFileNameLen(i) + 1;
  354.         char    *fileName = new char[fileLength];
  355.  
  356.         drop.DragQueryFile(i, fileName, fileLength);
  357.  
  358. ##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  359.         // Getting the file dropped. The location is relative to your client coordinates,
  360.         // and will have negative values if dropped in the non client parts of the window.
  361.         //
  362.         // DragQueryPoint copies that point where the file was dropped and returns whether
  363.         // or not the point is in the client area.  Regardless of whether or not the file
  364.         // is dropped in the client or non-client area of the window, you will still receive
  365.         // the file name.
  366. ##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  367.         TPoint  point;
  368.         bool    inClientArea = drop.DragQueryPoint(point);
  369.         files->Add(new TFileDrop(fileName, point, inClientArea, this));
  370.     }
  371.  
  372. ##@QUERY_APPL_COMMENT == VALUE_VERBOSE
  373.     // Open the files that were dropped.
  374.     AddFiles(files);
  375.  
  376. ##@QUERY_APPL_COMMENT == VALUE_VERBOSE
  377.     // Release the memory allocated for this handle with DragFinish.
  378.     drop.DragFinish();
  379. }
  380.  
  381.  
  382. void [[TApplication]]::AddFiles (TFileList* files)
  383. {
  384. ##@QUERY_APPL_COMMENT == VALUE_VERBOSE
  385.     // Open all files dragged in.
  386.     TFileListIter fileIter(*files);
  387.  
  388.     TFrameWindow *tfw = TYPESAFE_DOWNCAST(GetMainWindow(), TFrameWindow);
  389.     if (tfw) {
  390. ##<<TMDIClient QUERY_CLASS_NAME [[TMDIClient]]
  391.         [[TMDIClient]] *theClient = TYPESAFE_DOWNCAST(tfw->GetClientWindow(), [[TMDIClient]]);
  392.  
  393.         if (theClient)
  394.             while (fileIter) {
  395.                 theClient->OpenFile(fileIter.Current()->WhoAmI());
  396.                 fileIter++;
  397.             }
  398.     }
  399. }
  400. ##--END-- @OPT_APPL_DRAGDROP
  401. ##{main.owl}
  402.