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

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1993, 1995 by Borland International, All Rights Reserved
  4. //----------------------------------------------------------------------------
  5. #include <owl/pch.h>
  6. #include <owl/inputdia.h>
  7. #include <dos.h>
  8. #include <dir.h>
  9. #include "dialogs.h"
  10.  
  11. DEFINE_RESPONSE_TABLE1(TAppPropertiesDialog, TDialog)
  12.   EV_CHILD_NOTIFY(IDOK, BN_CLICKED, CmOk),
  13.   EV_CHILD_NOTIFY(CM_BROWSE_PROG, BN_CLICKED, CmBrowseProg),
  14.   EV_CHILD_NOTIFY(CM_BROWSE_ICON, BN_CLICKED, CmBrowseIcon),
  15. END_RESPONSE_TABLE;
  16.  
  17. //
  18. // Constructor.  Create controls for later manipulation.  Setup file open
  19. // data. Store TAppProperties record to be filled in later.
  20. //
  21. TAppPropertiesDialog::TAppPropertiesDialog(TWindow* parent, int resId,
  22.                                            TAppPropertiesData& data)
  23. :
  24.   TDialog(parent, resId),
  25.   AppProperties(data)
  26. {
  27.   ProgramPath = new TEdit(this, ID_PROGRAM_PATH, ProgramPathLen);
  28.   ProgramArgs = new TEdit(this, ID_PROGRAM_ARGS, ProgramArgsLen);
  29.   IconPath = new TEdit(this, ID_ICON_PATH, IconPathLen);
  30.   PromptForInput = new TCheckBox(this, ID_PROMPT_FOR_INPUT);
  31.   StartupStyles = new TGroupBox(this, ID_STARTUP_GROUPBOX);
  32.   RunNormal = new TRadioButton(this, ID_RUN_NORMAL, StartupStyles);
  33.   RunMinimized = new TRadioButton(this, ID_RUN_MINIMIZED, StartupStyles);
  34.   RunMaximized = new TRadioButton(this, ID_RUN_MAXIMIZED, StartupStyles);
  35.  
  36.   FileData.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_CREATEPROMPT|
  37.                    OFN_OVERWRITEPROMPT;
  38.   FileData.SetFilter("AllFiles (*.*)|*.*|");
  39. }
  40.  
  41. //
  42. // SetupWindow(). Initialize dialog fields with given fields from
  43. // TAppProperties record.
  44. //
  45. void
  46. TAppPropertiesDialog::SetupWindow()
  47. {
  48.   TDialog::SetupWindow();
  49.  
  50.   // Initialize dialog fields with data from AppProperties record.
  51.   //
  52.   ProgramPath->Insert(AppProperties.AppRec->ProgramPath.c_str());
  53.   ProgramArgs->Insert(AppProperties.AppRec->ProgramArgs.c_str());
  54.   IconPath->Insert(AppProperties.AppRec->IconPath.c_str());
  55.  
  56.   if (AppProperties.AppRec->PromptForInput)
  57.     PromptForInput->Check();
  58.  
  59.   switch (AppProperties.AppRec->StartupStyle) {
  60.     case 1:
  61.       RunNormal->Check();
  62.       break;
  63.     case 2:
  64.       RunMinimized->Check();
  65.       break;
  66.     case 3:
  67.       RunMaximized->Check();
  68.     default:
  69.       break;
  70.   };
  71. }
  72.  
  73. //
  74. // CmOk(). Update TAppProperties record with any fields that the user changed.
  75. // Record the following information in the TAppProperties record:
  76. //  . Does the Bitmap for the button need to be updated.
  77. //
  78. void
  79. TAppPropertiesDialog::CmOk()
  80. {
  81.   char*           buf = new char[ProgramArgsLen*2];
  82.  
  83.   ProgramPath->GetLine(buf, ProgramPathLen, 0);
  84.   if (AppProperties.AppRec->ProgramPath != buf)
  85.     AppProperties.ChangeBitmap = true;
  86.   AppProperties.AppRec->ProgramPath = buf;
  87.  
  88.   ProgramArgs->GetLine(buf, ProgramArgsLen, 0);
  89.   AppProperties.AppRec->ProgramArgs = buf;
  90.  
  91.   IconPath->GetLine(buf, IconPathLen, 0);
  92.   if (AppProperties.AppRec->IconPath != buf)
  93.     AppProperties.ChangeBitmap = true;
  94.   AppProperties.AppRec->IconPath = buf;
  95.  
  96.   AppProperties.AppRec->PromptForInput = PromptForInput->GetCheck();
  97.  
  98.   if (RunNormal->GetCheck())
  99.     AppProperties.AppRec->StartupStyle = 1;
  100.   else if (RunMinimized->GetCheck())
  101.     AppProperties.AppRec->StartupStyle = 2;
  102.   else
  103.     AppProperties.AppRec->StartupStyle = 3;
  104.  
  105.   delete buf;
  106.   TDialog::CmOk();
  107. }
  108.  
  109. //
  110. // CmBrowseProg(). Bring up a file open dialog so the user can choose the
  111. // program path to use for this app.
  112. //
  113. void
  114. TAppPropertiesDialog::CmBrowseProg()
  115. {
  116.   string  s;
  117.   if (GetFilePath(s)) {
  118.     ProgramPath->DeleteLine(0);
  119.     ProgramPath->Insert(s.c_str());
  120.   }
  121. }
  122.  
  123. //
  124. // CmBrowseIcon(). Bring up a file open dialog so the user can enter the path
  125. // to the icon file to use for this app.
  126. //
  127. void
  128. TAppPropertiesDialog::CmBrowseIcon()
  129. {
  130.   string  s;
  131.   if (GetFilePath(s)) {
  132.     IconPath->DeleteLine(0);
  133.     IconPath->Insert(s.c_str());
  134.   }
  135. }
  136.  
  137. //
  138. // GetFilePath(). Bring up file open dialog.  If 'OK' button was pressed
  139. // set 'path' parameter to path user has entered.
  140. //
  141. int
  142. TAppPropertiesDialog::GetFilePath(string& path)
  143. {
  144.   *FileData.FileName = 0;
  145.   if (TFileOpenDialog(this, FileData).Execute() == IDOK) {
  146.     path = FileData.FileName;
  147.     return 1;
  148.   }
  149.   return 0;
  150. }
  151.  
  152. //////////////////////////////////////////////////////////////////////
  153.  
  154. DEFINE_RESPONSE_TABLE1(TAddAppDialog, TDialog)
  155.   EV_CHILD_NOTIFY(CM_BROWSE_PROG, BN_CLICKED, CmBrowseProg),
  156. END_RESPONSE_TABLE;
  157.  
  158. //
  159. // Constructor.  Create interface objects and initialize file open record.
  160. //
  161. TAddAppDialog::TAddAppDialog(TWindow* parent, int resId, string& progPathStr,
  162.                              int& loc, StringList& pathStrs)
  163. :
  164.   TDialog(parent, resId),
  165.   ProgPathStr(progPathStr),
  166.   Loc(loc),
  167.   PathStrs(pathStrs)
  168. {
  169.   ProgramPath = new TEdit(this, ID_PROGRAM_PATH, ProgramPathLen);
  170.   Paths = new TComboBox(this, ID_PATHS, ProgramPathLen);
  171.  
  172.   FileData.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_CREATEPROMPT|
  173.                    OFN_OVERWRITEPROMPT;
  174.   FileData.SetFilter("AllFiles (*.*)|*.*|");
  175.   *FileData.FileName = 0;
  176. }
  177.  
  178. //
  179. // CanClose().
  180. //
  181. bool
  182. TAddAppDialog::CanClose()
  183. {
  184.   char    path[MAXPATH];
  185.   string  modPath;
  186.  
  187.   Loc = Paths->GetSelIndex();
  188.  
  189.   ProgramPath->GetLine(path,MAXPATH,0);
  190.   modPath = path;
  191.   modPath.strip(string::Both);
  192.   if (modPath.is_null() || modPath[0] == ' ') {
  193.     MessageBox("Program Path field can't be left blank", "Error", MB_OK);
  194.     return false;
  195.   }
  196.   ProgPathStr = modPath;
  197.   PathStrs.AddAt(modPath, Loc);
  198.   return true;
  199. }
  200.  
  201. //
  202. // SetupWindow(). Setup default location for new app as -1 (append).
  203. //
  204. void
  205. TAddAppDialog::SetupWindow()
  206. {
  207.   TDialog::SetupWindow();
  208.  
  209.   unsigned  stop = PathStrs.Count();
  210.   for (unsigned i = 0; i < stop ;i++ )
  211.     Paths->InsertString(PathStrs[i].c_str(), -1);
  212.   Paths->InsertString("<Append>", -1);
  213.   Paths->SetSelIndex(PathStrs.Count());
  214. }
  215.  
  216. //
  217. // CmBrowseProg(). Bring up a file open dialog so the user can choose the
  218. // program path to use for this app.
  219. //
  220. void
  221. TAddAppDialog::CmBrowseProg()
  222. {
  223.   *FileData.FileName = 0;
  224.   if (TFileOpenDialog(this, FileData).Execute() == IDOK) {
  225.     ProgramPath->DeleteLine(0);
  226.     ProgramPath->Insert(FileData.FileName);
  227.   }
  228. }
  229.  
  230. //////////////////////////////////////////////////////////////////////
  231.  
  232. DEFINE_RESPONSE_TABLE1(TMyPickListDialog, TDialog)
  233.   EV_CHILD_NOTIFY(IDOK, BN_CLICKED, CmOk),
  234. END_RESPONSE_TABLE;
  235.  
  236. //
  237. // Constructor.  Create interface object for listbox.
  238. //
  239. TMyPickListDialog::TMyPickListDialog(TWindow* parent, int resId,
  240.                                  StringList& strings,
  241.                                  NumberList& selections)
  242. :
  243.   TDialog(parent, resId),
  244.   Strings(strings),
  245.   Selections(selections)
  246. {
  247.   PickList = new TListBox(this, ID_PICK_LIST);
  248. }
  249.  
  250. //
  251. // SetupWindow(). Load listbox with the paths of all the apps in AppLauncher.
  252. //
  253. void
  254. TMyPickListDialog::SetupWindow()
  255. {
  256.   TDialog::SetupWindow();
  257.  
  258.   unsigned stop = Strings.Count();
  259.   for (unsigned i = 0; i < stop; i++ )
  260.     PickList->AddString(Strings[i].c_str());
  261. }
  262.  
  263. //
  264. // CmOk().  Record selections form pick list that user for return from dialog.
  265. //
  266. void
  267. TMyPickListDialog::CmOk()
  268. {
  269.   int* selectionsFromPickList = new int[Strings.Count()+1];
  270.   int nitems = PickList->GetSelIndexes(selectionsFromPickList, Strings.Count());
  271.   for (unsigned i = 0; i < nitems; i++ )
  272.     Selections.Add(selectionsFromPickList[i]);
  273.   delete selectionsFromPickList;
  274.   TDialog::CmOk();
  275. }
  276.  
  277. //----------------------------------------------------------------------------
  278.  
  279. DEFINE_RESPONSE_TABLE1(TConfigDialog, TDialog)
  280.   EV_CHILD_NOTIFY(IDOK, BN_CLICKED, CmOk),
  281.   EV_COMMAND(CM_SAVENOW, CmSaveNow),
  282. END_RESPONSE_TABLE;
  283.  
  284. //
  285. // Constructor. Create interface objects for dialog fields and save
  286. // configuration record for update later.
  287. //
  288. TConfigDialog::TConfigDialog(TWindow* parent, int resId, TConfigRec& rec)
  289. :
  290.   TDialog(parent, resId),
  291.   ConfigRec(rec)
  292. {
  293.   OrientationGroupBox = new TGroupBox(this, ID_ORIENTATION);
  294.   Vertical = new TRadioButton(this, ID_VERTICAL, OrientationGroupBox);
  295.   Horizontal = new TRadioButton(this, ID_HORIZONTAL, OrientationGroupBox);
  296.   SaveOnExit = new TCheckBox(this, ID_SAVE_ON_EXIT);
  297.   ConfirmOnRemove = new TCheckBox(this, ID_CONFIRM_ON_REMOVE);
  298.  
  299. }
  300.  
  301. //
  302. // SetupWindow().  Initialize dialog fields with current AppLauncher setup.
  303. //
  304. void
  305. TConfigDialog::SetupWindow()
  306. {
  307.   TDialog::SetupWindow();
  308.   Vertical->SetCheck(ConfigRec.Orientation ? BF_UNCHECKED : BF_CHECKED);
  309.   Horizontal->SetCheck(ConfigRec.Orientation ? BF_CHECKED : BF_UNCHECKED);
  310.   SaveOnExit->SetCheck(ConfigRec.SaveOnExit ? BF_CHECKED : BF_UNCHECKED);
  311.   ConfirmOnRemove->SetCheck(ConfigRec.ConfirmOnRemove ? BF_CHECKED : BF_UNCHECKED);
  312. }
  313.  
  314. //
  315. // CmOk().  Record any configuration changes in configuration record.
  316. //
  317. void
  318. TConfigDialog::CmOk()
  319. {
  320.   ConfigRec.Orientation = Vertical->GetCheck() == BF_CHECKED ? 0 : 1;
  321.   ConfigRec.SaveOnExit = SaveOnExit->GetCheck() == BF_CHECKED ? 1 : 0;
  322.   ConfigRec.ConfirmOnRemove = ConfirmOnRemove->GetCheck() == BF_CHECKED ? 1 : 0;
  323.  
  324.   TDialog::CmOk();
  325. }
  326.  
  327. //
  328. // CmSaveNow().  Send message to parent that the application settings should
  329. // be saved to INI file now.
  330. //
  331. void
  332. TConfigDialog::CmSaveNow()
  333. {
  334.   ConfigRec.SaveNow = 1;
  335.   CmOk();
  336. }
  337.