home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / wksinst / rwpdemo.pak / RWPDLGS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1991-09-09  |  9.4 KB  |  339 lines

  1. {   Copyright (c) 1991 by Borland International }
  2.  
  3. unit RWPDlgs;
  4.  
  5. interface
  6.  
  7. {$ifdef BWCC}
  8. uses WinProcs, WinTypes, WObjectB, WinDOS, RWPDemoC, bwcc, Strings;
  9. {$else}
  10. uses WinProcs, WinTypes, WObjects, WinDOS, RWPDemoC, bwcc, Strings;
  11. {$endif}
  12.  
  13. const
  14.   fsFileSpec        = fsPathName + fsExtension;
  15.   ScribbleExtension = '.SCR';
  16.   GraphExtension    = '.GRP';
  17.  
  18. type
  19.   PRWPDialog = ^TRWPDialog;
  20.   TRWPDialog = object(TDialog)
  21. {$ifdef BWCC}
  22.     function DialogHelp(var Msg: TMessage): integer; virtual id_First + IdHelp;
  23. {$else}
  24.     function DialogHelp(var Msg: TMessage): integer; virtual id_First + Id_Help;
  25. {$endif}
  26.   end;
  27.  
  28. type
  29.   PDlgDirectories = ^TDlgDirectories;
  30.   TDlgDirectories = object(TRWPDialog)
  31.     procedure SetupWindow; virtual;
  32.   end;
  33.  
  34. type
  35.   PFileNew = ^TFileNew;
  36.   TFileNew = object(TRWPDialog)
  37.     FileType: ^Integer;
  38.     constructor Init(AParent: PWindowsObject; var AType: Integer);
  39.     function CanClose: Boolean; virtual;
  40.     procedure SetupWindow; virtual;
  41.   end;
  42.  
  43. type
  44.   PFileOpen = ^TFileOpen;
  45.   TFileOpen = object(TRWPDialog)
  46.     Caption: PChar;
  47.     FilePath: PChar;
  48.     FileType: ^Integer;
  49.     PathName: array[0..fsPathName] of Char;
  50.     Extension: array[0..fsExtension] of Char;
  51.     FileSpec: array[0..fsFileSpec] of Char;
  52.     constructor Init(AParent: PWindowsObject; var AType: Integer;
  53.       AName, AFilePath: PChar);
  54.     function CanClose: Boolean; virtual;
  55.     function HasWildCards(AFilePath: PChar): Boolean;
  56.     function GetExtension(AFilePath: PChar): PChar;
  57.     function GetFileName(AFilePath: PChar): PChar;
  58.     function GetFileFirst(AFilePath: PChar): PChar;
  59.     procedure HandleBGrp(var Msg: TMessage); virtual id_First + id_Graph;
  60.     procedure HandleBScr(var Msg: TMessage); virtual id_First + id_Scribble;
  61.     procedure HandleBTxt(var Msg: TMessage); virtual id_First + id_Text;
  62.     procedure HandleDList(var Msg: TMessage); virtual id_First + id_DList;
  63.     procedure HandleFList(var Msg: TMessage); virtual id_First + id_FList;
  64.     procedure HandleFName(var Msg: TMessage); virtual id_First + id_FName;
  65.     procedure SetupWindow; virtual;
  66.   private
  67.     procedure SelectFileName;
  68.     procedure UpdateButtons;
  69.     procedure UpdateFileName;
  70.     function UpdateListBoxes: Boolean;
  71.   end;
  72.  
  73. implementation
  74.  
  75. function TRwpDialog.DialogHelp(var Msg: TMessage): integer;
  76. begin
  77. {$ifdef BWCC}
  78.   MessageBox(HWindow,'Call WinHelp here','Help',mb_OK or mb_IconInformation);
  79. {$else}
  80.   MessageBox(HWindow,'Call WinHelp here','Help',mb_OK or mb_IconInformation);
  81. {$endif}
  82. end;
  83.  
  84. procedure TDlgDirectories.SetupWindow;
  85. begin
  86.   TRWPDialog.SetupWindow;
  87.   { allow only 128 characters in each combo box }
  88.   SendDlgItemMsg(id_TextDirectory, cb_LimitText, 128, 0);
  89.   SendDlgItemMsg(id_GraphicDirectory, cb_LimitText, 128, 0);
  90.   SendDlgItemMsg(id_ScribbleDirectory, cb_LimitText, 128, 0);
  91. end;
  92.  
  93. constructor TFileNew.Init(AParent: PWindowsObject; var AType: Integer);
  94. begin
  95.   TRWPDialog.Init(AParent, MakeIntResource(dlg_FileNew));
  96.   FileType := @AType;
  97. end;
  98.  
  99. function TFileNew.CanClose: Boolean;
  100. begin
  101.   CanClose := True;
  102.   if IsDlgButtonChecked(HWindow, id_Text) = 1 then
  103.     FileType^ := FileWindow
  104.   else
  105.   if IsDlgButtonChecked(HWindow, id_Scribble) = 1 then
  106.     FileType^ := ScribbleWindow
  107.   else
  108.   if IsDlgButtonChecked(HWindow, id_Graphics) = 1 then
  109.     FileType^ := GraphWindow
  110.   else
  111.     CanClose := False;
  112. end;
  113.  
  114. procedure TFileNew.SetupWindow;
  115. begin
  116.   TRWPDialog.SetupWindow;
  117.   SetFocus(GetDlgItem(HWindow, id_Text));
  118.   SendDlgItemMessage(HWindow, id_Text, bm_SetCheck, 1, 0);
  119. end;
  120.  
  121. constructor TFileOpen.Init(AParent: PWindowsObject;
  122.   var AType: Integer; AName, AFilePath: PChar);
  123. begin
  124.   TRWPDialog.Init(AParent, MakeIntResource(dlg_Open));
  125.   Caption := nil;
  126.   FilePath := AFilePath;
  127.   FileType := @AType;
  128. end;
  129.  
  130. function TFileOpen.CanClose: Boolean;
  131. var
  132.   PathLen: Word;
  133. begin
  134.   CanClose := False;
  135.   GetDlgItemText(HWindow, id_FName, PathName, fsPathName + 1);
  136.   FileExpand(PathName, PathName);
  137.   PathLen := StrLen(PathName);
  138.   if (PathName[PathLen - 1] = '\') or HasWildCards(PathName) or
  139.     (GetFocus = GetDlgItem(HWindow, id_DList)) then
  140.   begin
  141.     if PathName[PathLen - 1] = '\' then
  142.       StrLCat(PathName, FileSpec, fsPathName);
  143.     if not UpdateListBoxes then
  144.     begin
  145.       MessageBeep(0);
  146.       SelectFileName;
  147.     end;
  148.     Exit;
  149.   end;
  150.   StrLCat(StrLCat(PathName, '\', fsPathName), FileSpec, fsPathName);
  151.   if UpdateListBoxes then Exit;
  152.   PathName[PathLen] := #0;
  153.   if GetExtension(PathName)[0] = #0 then
  154.     StrLCat(PathName, Extension, fsPathName);
  155.   AnsiLower(StrCopy(FilePath, PathName));
  156.   UpdateButtons;
  157.   if IsDlgButtonChecked(HWindow, id_Text) = 1 then
  158.     FileType^ := FileWindow
  159.   else
  160.   if IsDlgButtonChecked(HWindow, id_Scribble) = 1 then
  161.     FileType^ := ScribbleWindow
  162.   else
  163.   if IsDlgButtonChecked(HWindow, id_Graph) = 1 then
  164.     FileType^ := GraphWindow
  165.   else
  166.   begin
  167.     CanClose := False;
  168.     Exit;
  169.   end;
  170.   CanClose := True;
  171. end;
  172.  
  173. function TFileOpen.HasWildCards(AFilePath: PChar): Boolean;
  174. begin
  175.   HasWildCards := (StrScan(AFilePath, '*') <> nil) or
  176.     (StrScan(AFilePath, '?') <> nil);
  177. end;
  178.  
  179. function TFileOpen.GetFileFirst(AFilePath: PChar): PChar;
  180. var
  181.   P, Q: PChar;
  182. begin
  183.   P := GetFileName(AFilePath);
  184.   Q := StrScan(P, '.');
  185.   if Q <> nil then Q[0] := #0;
  186.   GetFileFirst := P;
  187. end;
  188.  
  189. function TFileOpen.GetExtension(AFilePath: PChar): PChar;
  190. var
  191.   P: PChar;
  192. begin
  193.   P := StrScan(GetFileName(AFilePath), '.');
  194.   if P = nil then GetExtension := StrEnd(FilePath)
  195.   else GetExtension := P;
  196. end;
  197.  
  198. function TFileOpen.GetFileName(AFilePath: PChar): PChar;
  199. var
  200.   P: PChar;
  201. begin
  202.   P := StrRScan(AFilePath, '\');
  203.   if P = nil then P := StrRScan(AFilePath, ':');
  204.   if P = nil then GetFileName := AFilePath else GetFileName := P + 1;
  205. end;
  206.  
  207. procedure TFileOpen.SetupWindow;
  208. begin
  209.   SendDlgItemMessage(HWindow, id_FName, em_LimitText, fsPathName, 0);
  210.   if Caption <> nil then SetWindowText(HWindow, Caption);
  211.   StrLCopy(PathName, FilePath, fsPathName);
  212.   StrLCopy(Extension, GetExtension(PathName), fsExtension);
  213.   if HasWildCards(Extension) then Extension[0] := #0;
  214.   if not UpdateListBoxes then
  215.   begin
  216.     StrCopy(PathName, '*.*');
  217.     UpdateListBoxes;
  218.   end;
  219.   SelectFileName;
  220. end;
  221.  
  222. procedure TFileOpen.HandleFName(var Msg: TMessage);
  223. begin
  224.   if Msg.LParamHi = en_Change then
  225.     EnableWindow(GetDlgItem(HWindow, id_Ok),
  226.       SendMessage(Msg.LParamLo, wm_GetTextLength, 0, 0) <> 0);
  227. end;
  228.  
  229. procedure TFileOpen.HandleFList(var Msg: TMessage);
  230. begin
  231.   case Msg.LParamHi of
  232.     lbn_SelChange, lbn_DblClk:
  233.       begin
  234.     DlgDirSelect(HWindow, PathName, id_FList);
  235.     UpdateFileName;
  236.     if Msg.LParamHi = lbn_DblClk then Ok(Msg);
  237.       end;
  238.     lbn_KillFocus:
  239.       SendMessage(Msg.LParamLo, lb_SetCurSel, Word(-1), 0);
  240.   end;
  241. end;
  242.  
  243. procedure TFileOpen.HandleDList(var Msg: TMessage);
  244. begin
  245.   case Msg.LParamHi of
  246.     lbn_SelChange, lbn_DblClk:
  247.       begin
  248.     DlgDirSelect(HWindow, PathName, id_DList);
  249.     StrCat(PathName, FileSpec);
  250.     if Msg.LParamHi = lbn_DblClk then
  251.       UpdateListBoxes else
  252.       UpdateFileName;
  253.       end;
  254.     lbn_KillFocus:
  255.       SendMessage(Msg.LParamLo, lb_SetCurSel, Word(-1), 0);
  256.   end;
  257. end;
  258.  
  259. procedure TFileOpen.HandleBScr(var Msg: TMessage);
  260. begin
  261.   StrCat(StrCopy(PathName,GetFileFirst(PathName)), ScribbleExtension);
  262.   UpdateFileName;
  263. end;
  264.  
  265. procedure TFileOpen.HandleBTxt(var Msg: TMessage);
  266. begin
  267.   if StrComp(GetExtension(PathName),'.') <> 0 then
  268.   begin
  269.     StrCat(StrCopy(PathName,GetFileFirst(PathName)), '.TXT');
  270.     UpdateFileName;
  271.   end;
  272. end;
  273.  
  274. procedure TFileOpen.HandleBGrp(var Msg: TMessage);
  275. begin
  276.   StrCat(StrCopy(PathName, GetFileFirst(PathName)), GraphExtension);
  277.   UpdateFileName;
  278. end;
  279.  
  280. procedure TFileOpen.SelectFileName;
  281. begin
  282.   SendDlgItemMessage(HWindow, id_FName, em_SetSel, 0, $7FFF0000);
  283.   SetFocus(GetDlgItem(HWindow, id_FName));
  284. end;
  285.  
  286. procedure TFileOpen.UpdateFileName;
  287. begin
  288.   SetDlgItemText(HWindow, id_FName, AnsiLower(PathName));
  289.   SendDlgItemMessage(HWindow, id_FName, em_SetSel, 0, $7FFF0000);
  290.   UpdateButtons;
  291. end;
  292.  
  293. procedure TFileOpen.UpdateButtons;
  294. var
  295.   P: PChar;
  296.   WhichButton: Integer;
  297. begin
  298.   P := GetExtension(PathName);
  299.   if P <> nil then
  300.   begin
  301.     if StrIComp(P, ScribbleExtension) = 0 then
  302.       WhichButton := id_Scribble
  303.     else
  304.     if StrIComp(P, GraphExtension) =  0 then WhichButton := id_Graph
  305.     else WhichButton := id_Text;
  306.     SendDlgItemMessage(HWindow, id_Text, bm_SetCheck, 0, 0);
  307.     SendDlgItemMessage(HWindow, id_Graph, bm_SetCheck, 0, 0);
  308.     SendDlgItemMessage(HWindow, id_Scribble, bm_SetCheck, 0, 0);
  309.     SendDlgItemMessage(HWindow, WhichButton, bm_SetCheck, 1, 0);
  310.   end;
  311. end;
  312.  
  313. function TFileOpen.UpdateListBoxes: Boolean;
  314. var
  315.   Result: Integer;
  316.   Path: array[0..fsPathName] of Char;
  317. begin
  318.   UpdateListBoxes := False;
  319.   if GetDlgItem(HWindow, id_FList) <> 0 then
  320.   begin
  321.     StrCopy(Path, PathName);
  322.     Result := DlgDirList(HWindow, Path, id_FList, id_FPath, 0);
  323.     if Result <> 0 then DlgDirList(HWindow, '*.*', id_DList, 0, $C010);
  324.   end else
  325.   begin
  326.     StrLCopy(Path, PathName, GetFileName(PathName) - PathName);
  327.     StrLCat(Path, '*.*', fsPathName);
  328.     Result := DlgDirList(HWindow, Path, id_DList, id_FPath, $C010);
  329.   end;
  330.   if Result <> 0 then
  331.   begin
  332.     StrLCopy(FileSpec, GetFileName(PathName), fsFileSpec);
  333.     StrCopy(PathName, FileSpec);
  334.     UpdateFileName;
  335.     UpdateListBoxes := True;
  336.   end;
  337. end;
  338.  
  339. end.