fpmwnd.inc 7.3 KB

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