fpmwnd.inc 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. {
  2. This file is part of the Free Pascal Integrated Development Environment
  3. Copyright (c) 1998 by Berczi Gabor
  4. Window menu entries
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. procedure TIDEApp.CloseAll;
  12. procedure SendClose(P: PView);
  13. begin
  14. Message(P,evCommand,cmClose,nil);
  15. end;
  16. begin
  17. Desktop^.ForEach(TCallbackProcParam(@SendClose));
  18. end;
  19. procedure TIDEApp.ResizeApplication(x, y : longint);
  20. var
  21. OldR : TRect;
  22. Mode : TVideoMode;
  23. begin
  24. GetBounds(OldR);
  25. { adapt to new size }
  26. if (OldR.B.Y-OldR.A.Y<>y) or
  27. (OldR.B.X-OldR.A.X<>x) then
  28. begin
  29. Mode.color:=ScreenMode.Color;
  30. Mode.col:=x;
  31. Mode.row:=y;
  32. SetScreenVideoMode(Mode);
  33. UpdateRecentFileList; {ensure file menu not go over screen}
  34. Redraw;
  35. end;
  36. end;
  37. type
  38. PWindowListBox = ^TWindowListBox;
  39. TWindowListBox = object(TAdvancedListBox)
  40. constructor Init(var Bounds: TRect; AScrollBar: PScrollBar);
  41. function GetText(Item,MaxLen: Sw_Integer): String; virtual;
  42. end;
  43. PWindowListDialog = ^TWindowListDialog;
  44. TWindowListDialog = object(TCenterDialog)
  45. constructor Init;
  46. procedure HandleEvent(var Event: TEvent); virtual;
  47. destructor Done; virtual;
  48. private
  49. LB: PWindowListBox;
  50. C : PCollection;
  51. BtnShow,BtnHide: PNoUpdateButton;
  52. procedure UpdateList;
  53. procedure UpdateButtons;
  54. end;
  55. constructor TWindowListBox.Init(var Bounds: TRect; AScrollBar: PScrollBar);
  56. begin
  57. inherited Init(Bounds,1,AScrollBar);
  58. end;
  59. function TWindowListBox.GetText(Item,MaxLen: Sw_Integer): String;
  60. var P: PView;
  61. S: string;
  62. begin
  63. P:=List^.At(Item);
  64. case P^.HelpCtx of
  65. hcSourceWindow : S:=PSourceWindow(P)^.GetTitle(MaxLen);
  66. hcHelpWindow : S:=PHelpWindow(P)^.GetTitle(MaxLen);
  67. hcCalcWindow : S:=PCalculator(P)^.GetTitle(MaxLen);
  68. hcBrowserWindow: S:=PBrowserWindow(P)^.GetTitle(MaxLen);
  69. hcCompilerMessagesWindow,
  70. hcMessagesWindow:S:=PFPWindow(P)^.GetTitle(MaxLen);
  71. hcGDBWindow,
  72. hcDisassemblyWindow,
  73. hcWatchesWindow,
  74. hcStackWindow,
  75. hcRegistersWindow,
  76. hcFPURegisters,
  77. hcVectorRegisters,
  78. hcClipboardWindow,
  79. hcASCIITableWindow,
  80. hcUserScreenWindow,
  81. hcBreakpointListWindow :
  82. S:=PWindow(P)^.GetTitle(MaxLen);
  83. else S:='???? - '+PWindow(P)^.GetTitle(MaxLen);
  84. end;
  85. if PWindow(P)^.Number<>0 then
  86. S:=S+'('+IntToStr(PWindow(P)^.Number)+')';
  87. if P^.GetState(sfVisible) then S:=' '+S else
  88. begin
  89. S:='*'+S+' - '+msg_windowlist_hidden;
  90. end;
  91. GetText:=copy(S,1,MaxLen);
  92. end;
  93. constructor TWindowListDialog.Init;
  94. var R,R2: TRect;
  95. SB: PScrollBar;
  96. begin
  97. R.Assign(0,0,round(ScreenWidth*5/8),15);
  98. inherited Init(R, dialog_windowlist);
  99. HelpCtx:=hcWindowList;
  100. New(C, Init(20,10));
  101. GetExtent(R); R.Grow(-2,-2); Inc(R.A.Y); R.B.X:=R.B.X-14;
  102. R2.Copy(R); R2.Move(1,0); R2.A.X:=R2.B.X-1;
  103. New(SB, Init(R2)); Insert(SB);
  104. New(LB, Init(R, SB));
  105. LB^.Default:=true;
  106. LB^.NewList(C);
  107. UpdateList;
  108. if C^.Count>=2 then
  109. if PWindow(C^.At(1))^.GetState(sfVisible) then
  110. LB^.FocusItem(1); { focus the 2nd one }
  111. Insert(LB);
  112. R2.Copy(R); Dec(R2.A.Y); R2.B.Y:=R2.A.Y+1;
  113. Insert(New(PLabel, Init(R2, label_wndlist_windows, LB)));
  114. GetExtent(R); R.Grow(-2,-2); Inc(R.A.Y); R.A.X:=R.B.X-13+1; R.B.Y:=R.A.Y+2;
  115. Insert(New(PButton, Init(R, button_OK, cmOK, bfDefault)));
  116. R.Move(0,2);
  117. Insert(New(PButton, Init(R, button_Delete, cmDeleteItem, bfNormal)));
  118. R.Move(0,2);
  119. New(BtnShow, Init(R, button_Show, cmShowItem, bfNormal));
  120. Insert(BtnShow);
  121. R.Move(0,2);
  122. New(BtnHide, Init(R, button_Hide, cmHideItem, bfNormal));
  123. Insert(BtnHide);
  124. R.Move(0,2);
  125. Insert(New(PButton, Init(R, button_Cancel, cmCancel, bfNormal)));
  126. LB^.Select;
  127. PutCommand(@Self,evBroadcast,cmListFocusChanged,LB);
  128. end;
  129. procedure TWindowListDialog.UpdateList;
  130. var VisState: boolean;
  131. procedure AddIt(P: PView);
  132. begin
  133. if (P<>pointer(Desktop^.Background)) and
  134. (P^.GetState(sfDisabled)=false) and
  135. ((P^.Options and ofSelectable)<>0) and
  136. (P^.GetState(sfVisible)=VisState) then
  137. C^.Insert(P);
  138. end;
  139. begin
  140. C^.DeleteAll;
  141. VisState:=true; Desktop^.ForEach(TCallbackProcParam(@AddIt)); { add visible windows to list }
  142. VisState:=false; Desktop^.ForEach(TCallbackProcParam(@AddIt)); { add hidden windows }
  143. LB^.SetRange(C^.Count);
  144. UpdateButtons;
  145. ReDraw;
  146. end;
  147. procedure TWindowListDialog.UpdateButtons;
  148. var W: PView;
  149. begin
  150. if LB^.Range>0 then
  151. begin
  152. W:=LB^.List^.At(LB^.Focused);
  153. if Assigned(BtnShow) then
  154. BtnShow^.SetState(sfDisabled,W^.GetState(sfVisible));
  155. if Assigned(BtnHide) then
  156. BtnHide^.SetState(sfDisabled,not W^.GetState(sfVisible));
  157. end
  158. else
  159. begin
  160. BtnShow^.SetState(sfDisabled,true);
  161. BtnHide^.SetState(sfDisabled,true);
  162. end;
  163. ReDraw;
  164. end;
  165. procedure TWindowListDialog.HandleEvent(var Event: TEvent);
  166. var W: PWindow;
  167. KeePOwner : PGroup;
  168. begin
  169. case Event.What of
  170. evKeyDown :
  171. case Event.KeyCode of
  172. kbDel :
  173. begin
  174. Message(@Self,evCommand,cmDeleteItem,nil);
  175. ClearEvent(Event);
  176. end;
  177. end;
  178. evBroadcast :
  179. case Event.Command of
  180. cmListFocusChanged :
  181. if Event.InfoPtr=LB then
  182. UpdateButtons;
  183. end;
  184. evCommand :
  185. case Event.Command of
  186. cmDeleteItem :
  187. if C^.Count>0 then
  188. begin
  189. W:=PWindow(C^.At(LB^.Focused));
  190. { we need to remove the window from the list
  191. because otherwise
  192. IDEApp.SourceWindowClosed
  193. is called after the object has been freed
  194. but the ListBox.Redraw will still try to
  195. read the title PM }
  196. KeepOwner:=W^.Owner;
  197. if assigned(KeepOwner) then
  198. KeepOwner^.Delete(W);
  199. UpdateList;
  200. { But reinsert it as Close might only
  201. trigger Hide in some cases }
  202. if assigned(KeepOwner) then
  203. KeepOwner^.Insert(W);
  204. Message(W,evCommand,cmClose,nil);
  205. UpdateList;
  206. ClearEvent(Event);
  207. end;
  208. cmShowItem :
  209. if C^.Count>0 then
  210. begin
  211. PWindow(C^.At(LB^.Focused))^.Show;
  212. UpdateList;
  213. ClearEvent(Event);
  214. end;
  215. cmHideItem :
  216. if C^.Count>0 then
  217. begin
  218. PWindow(C^.At(LB^.Focused))^.Hide;
  219. UpdateList;
  220. ClearEvent(Event);
  221. end;
  222. cmOK :
  223. if C^.Count>0 then
  224. begin
  225. W:=PWindow(C^.At(LB^.Focused));
  226. if W^.GetState(sfVisible)=false then
  227. W^.Show;
  228. W^.MakeFirst;
  229. end;
  230. end;
  231. end;
  232. inherited HandleEvent(Event);
  233. end;
  234. destructor TWindowListDialog.Done;
  235. begin
  236. if C<>nil then begin C^.DeleteAll; Dispose(C, Done); end;
  237. inherited Done;
  238. end;
  239. procedure TIDEApp.WindowList;
  240. var W: PWindowListDialog;
  241. begin
  242. New(W,Init);
  243. ExecView(W);
  244. Dispose(W,Done);
  245. if assigned(Desktop^.Current) then
  246. begin
  247. Desktop^.Lock;
  248. { force correct commands to be enabled }
  249. Desktop^.Current^.SetState(sfActive,false);
  250. Desktop^.Current^.SetState(sfActive,true);
  251. Desktop^.UnLock;
  252. end;
  253. end;