home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / APPLAUNC.PAK / DIALOGS.CPP < prev    next >
C/C++ Source or Header  |  1995-08-29  |  9KB  |  326 lines

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