filedlg.pas 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. program demofiledialog;
  2. {$codepage utf8}
  3. uses
  4. {$ifdef UNIX}cwstring,{$endif}
  5. //Objects, Drivers, Views, Menus, Dialogs, App, Stddlg, MsgBox, FVCommon; { for legacy uncomment this line and comment next line }
  6. Objects, uDrivers, uViews, uMenus, uDialogs, uApp, uStddlg, uMsgBox, uFVCommon; { for unicode support uncomment this line and comment previous line }
  7. const cmOpneFileDlg =14523;
  8. cmDirChangeDlg=26745;
  9. cmDirChangeDlg2=3412;
  10. {$if sizeof(sw_string)<=8}
  11. const cStr1: utf8String = '◀ ◌ ◂ ◃ ◄ ◅ ◆ ◇ ';
  12. cStr2: utf8String = ' ◈ ◉ ◊ ○ ◌ ◍ ◎ ●';
  13. cMoStr = '◇ ';
  14. cMcStr = '◊ ';
  15. cMeStr = '◌ ';
  16. {$else}
  17. const cStr1: AnsiString = '';
  18. cStr2: AnsiString = '';
  19. cMoStr = '';
  20. cMcStr = '';
  21. cMeStr = '';
  22. {$endif}
  23. type
  24. PFileDlgApp = ^TFileDlgApp;
  25. TFileDlgApp = object(TApplication)
  26. procedure HandleEvent(var Event: TEvent); virtual;
  27. procedure InitMenuBar; virtual;
  28. end;
  29. procedure TFileDlgApp.InitMenuBar;
  30. var
  31. R: TRect;
  32. begin
  33. GetExtent(R);
  34. R.B.Y := R.A.Y + 1;
  35. MenuBar := New(PMenubar, Init(R, NewMenu(NewSubMenu('~M~enu', hcNoContext,
  36. NewMenu(
  37. NewItem(cMoStr+'~O~pen File Dialog', 'F2', kbF2, cmOpneFileDlg, hcNoContext,
  38. NewItem(cMcStr+'~C~hange Directory Dialog', 'F4', kbF4, cmDirChangeDlg, hcNoContext,
  39. NewItem(cMeStr+'Change ~D~irectory Dialog II', 'F6', kbF6, cmDirChangeDlg2, hcNoContext,
  40. NewLine(
  41. NewItem('E~x~it', 'Alt-X', kbNoKey, cmQuit, hcNoContext,
  42. nil))))))
  43. ,
  44. nil))));
  45. end;
  46. procedure TFileDlgApp.HandleEvent(var Event: TEvent);
  47. procedure OpenFileDialog;
  48. var
  49. R: TRect;
  50. D: PFileDialog;
  51. S: Sw_String;
  52. P : pointer;
  53. begin
  54. S:='*.pas';
  55. D := New(PFileDialog, Init(S,cStr1+'File dialog'+cStr2,'Chosen ~f~ile ',fdOkButton,199));
  56. //D := New(PFileDialog, Init(S,'File dialog','Chosen ~f~ile ',fdOkButton,199));
  57. { Resize }
  58. if Desktop^.Size.Y > 26 then
  59. D^.GrowTo(D^.Size.X,Desktop^.Size.Y-6);
  60. if Desktop^.Size.X > 60 then
  61. D^.GrowTo(Min(Desktop^.Size.X-(60-D^.Size.X),102),D^.Size.Y);
  62. { Number of columns in file open dialog }
  63. D^.FileList^.NumCols:= Max((D^.FileList^.Size.X-(D^.FileList^.Size.X div 14)) div 14,2);
  64. { Adjust scrollbar step and page step }
  65. D^.FileList^.SetRange(D^.FileList^.Range); {set again for scrollbar min max values}
  66. if ExecuteDialog(D, @S) <> cmCancel then
  67. begin
  68. P:=@S;
  69. MessageBox('The file %s', @P, mfInformation + mfOKButton);
  70. end;
  71. end;
  72. procedure DirChangeDialog;
  73. var
  74. R: TRect;
  75. D: PChDirDialog;
  76. S: Sw_String;
  77. begin
  78. GetDir(0,S); { current directory }
  79. D := New(PEditChDirDialog, Init(cdNormal,213));
  80. { Resize }
  81. if Desktop^.Size.Y > 26 then
  82. D^.GrowTo(D^.Size.X,Desktop^.Size.Y-6);
  83. if Desktop^.Size.X > 60 then
  84. D^.GrowTo(Min(Desktop^.Size.X-(60-D^.Size.X),102),D^.Size.Y);
  85. if ExecuteDialog(D, @S) <> cmCancel then
  86. begin
  87. MessageBox('The directory '+S, nil, mfInformation + mfOKButton);
  88. end;
  89. end;
  90. procedure DirChangeDialogII;
  91. var
  92. R: TRect;
  93. D: PChDirDialog;
  94. S: Sw_String;
  95. begin
  96. GetDir(0,S); { current directory }
  97. D := New(PChDirDialog, Init(cdNormal,213));
  98. { Resize }
  99. if Desktop^.Size.Y > 26 then
  100. D^.GrowTo(D^.Size.X,Desktop^.Size.Y-6);
  101. if Desktop^.Size.X > 60 then
  102. D^.GrowTo(Min(Desktop^.Size.X-(60-D^.Size.X),102),D^.Size.Y);
  103. if ExecuteDialog(D, nil) <> cmCancel then
  104. begin
  105. GetDir(0,S); { new current directory }
  106. MessageBox('The directory '+S, nil, mfInformation + mfOKButton);
  107. end;
  108. end;
  109. begin
  110. inherited HandleEvent(Event);
  111. case Event.What of
  112. evCommand:
  113. begin
  114. case Event.Command of
  115. cmOpneFileDlg : OpenFileDialog;
  116. cmDirChangeDlg: DirChangeDialog;
  117. cmDirChangeDlg2:DirChangeDialogII;
  118. else
  119. Exit;
  120. end;
  121. ClearEvent(Event);
  122. end;
  123. end;
  124. end;
  125. var
  126. FileDlgApp: TFileDlgApp;
  127. begin
  128. FileDlgApp.Init;
  129. FileDlgApp.Run;
  130. FileDlgApp.Done;
  131. end.