fpmwnd.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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.TileVertical;
  12. begin
  13. if not assigned(Desktop) then exit;
  14. Desktop^.TileColumnsFirst:=True;
  15. Tile;
  16. Desktop^.TileColumnsFirst:=False;
  17. end;
  18. FUNCTION Tileable (P: PView): Boolean;
  19. BEGIN
  20. Tileable := (P^.Options AND ofTileable <> 0) AND { View is tileable }
  21. (P^.State AND sfVisible <> 0); { View is visible }
  22. END;
  23. { This pretty much copy of window cascade }
  24. { added extra variable `Count` }
  25. { calculate one of `NR.A.Y` or `NR.A.X` in reverse }
  26. procedure TIDEApp.Stepped(aDirection:boolean);
  27. var R: TRect;
  28. VAR CascadeNum, Count: SmallInt; LastView: PView; Min, Max: TPoint;
  29. PROCEDURE DoCount (P: PView);
  30. BEGIN
  31. If Tileable(P) Then Begin
  32. Inc(CascadeNum); LastView := P; { Count tileable }
  33. End;
  34. END;
  35. PROCEDURE DoCascade (P: PView);
  36. VAR PState: Word; NR: TRect;
  37. BEGIN
  38. If Tileable(P) AND (CascadeNum >= 0) Then Begin { View tileable }
  39. NR.Copy(R); { Copy rect area }
  40. if aDirection then
  41. begin
  42. {option 1 active window in lowest position, window titles visible}
  43. Inc(NR.A.X, Count*1-CascadeNum*1-1); { Inc x position }
  44. Inc(NR.A.Y, CascadeNum); { Inc y position }
  45. end else
  46. begin
  47. {option 2 active window in highest position, window titles not visible}
  48. Inc(NR.A.X, CascadeNum*1); { Inc x position }
  49. Inc(NR.A.Y, Count-CascadeNum-1); { Inc y position }
  50. end;
  51. PState := P^.State; { Hold view state }
  52. P^.State := P^.State AND NOT sfVisible; { Temp stop draw }
  53. P^.Locate(NR); { Locate the view }
  54. P^.State := PState; { Now allow draws }
  55. Dec(CascadeNum); { Dec count }
  56. End;
  57. END;
  58. begin
  59. if not assigned(Desktop) then exit;
  60. GetTileRect(R); { Tileable area }
  61. CascadeNum := 0; { Zero step count }
  62. Desktop^.ForEach(TCallbackProcParam(@DoCount)); { Count tileable }
  63. Count:=CascadeNum; { Keep count in Count }
  64. If (CascadeNum>0) Then Begin
  65. LastView^.SizeLimits(Min, Max); { Check size limits }
  66. If (Min.X > R.B.X - R.A.X - CascadeNum) OR
  67. (Min.Y > R.B.Y - R.A.Y - CascadeNum) Then
  68. Desktop^.TileError Else Begin { Check for error }
  69. Dec(CascadeNum); { One less view }
  70. Desktop^.ForEach(TCallbackProcParam(@DoCascade)); { Stepped view }
  71. Desktop^.DrawView; { Redraw now }
  72. End;
  73. End;
  74. end;
  75. procedure TIDEApp.CloseAll;
  76. procedure SendClose(P: PView);
  77. begin
  78. Message(P,evCommand,cmClose,nil);
  79. end;
  80. begin
  81. Desktop^.ForEach(TCallbackProcParam(@SendClose));
  82. end;
  83. procedure TIDEApp.ResizeApplication(x, y : longint);
  84. var
  85. OldR : TRect;
  86. Mode : TVideoMode;
  87. begin
  88. GetBounds(OldR);
  89. { adapt to new size }
  90. if (OldR.B.Y-OldR.A.Y<>y) or
  91. (OldR.B.X-OldR.A.X<>x) then
  92. begin
  93. Mode.color:=ScreenMode.Color;
  94. Mode.col:=x;
  95. Mode.row:=y;
  96. SetScreenVideoMode(Mode);
  97. UpdateRecentFileList; {ensure file menu not go over screen}
  98. Redraw;
  99. end;
  100. end;
  101. type
  102. PWindowListBox = ^TWindowListBox;
  103. TWindowListBox = object(TAdvancedListBox)
  104. constructor Init(var Bounds: TRect; AScrollBar: PScrollBar);
  105. function GetText(Item,MaxLen: Sw_Integer): String; virtual;
  106. end;
  107. PWindowListDialog = ^TWindowListDialog;
  108. TWindowListDialog = object(TCenterDialog)
  109. constructor Init;
  110. procedure HandleEvent(var Event: TEvent); virtual;
  111. destructor Done; virtual;
  112. private
  113. LB: PWindowListBox;
  114. C : PCollection;
  115. BtnShow,BtnHide: PNoUpdateButton;
  116. procedure UpdateList;
  117. procedure UpdateButtons;
  118. end;
  119. constructor TWindowListBox.Init(var Bounds: TRect; AScrollBar: PScrollBar);
  120. begin
  121. inherited Init(Bounds,1,AScrollBar);
  122. end;
  123. function TWindowListBox.GetText(Item,MaxLen: Sw_Integer): String;
  124. var P: PView;
  125. S: string;
  126. begin
  127. P:=List^.At(Item);
  128. case P^.HelpCtx of
  129. hcSourceWindow : S:=PSourceWindow(P)^.GetTitle(MaxLen);
  130. hcHelpWindow : S:=PHelpWindow(P)^.GetTitle(MaxLen);
  131. hcCalcWindow : S:=PCalculator(P)^.GetTitle(MaxLen);
  132. hcBrowserWindow: S:=PBrowserWindow(P)^.GetTitle(MaxLen);
  133. hcCompilerMessagesWindow,
  134. hcMessagesWindow:S:=PFPWindow(P)^.GetTitle(MaxLen);
  135. hcGDBWindow,
  136. hcDisassemblyWindow,
  137. hcWatchesWindow,
  138. hcStackWindow,
  139. hcRegistersWindow,
  140. hcFPURegisters,
  141. hcVectorRegisters,
  142. hcClipboardWindow,
  143. hcASCIITableWindow,
  144. hcUserScreenWindow,
  145. hcBreakpointListWindow :
  146. S:=PWindow(P)^.GetTitle(MaxLen);
  147. else S:='???? - '+PWindow(P)^.GetTitle(MaxLen);
  148. end;
  149. if PWindow(P)^.Number<>0 then
  150. S:=S+'('+IntToStr(PWindow(P)^.Number)+')';
  151. if P^.GetState(sfVisible) then S:=' '+S else
  152. begin
  153. S:='*'+S+' - '+msg_windowlist_hidden;
  154. end;
  155. GetText:=copy(S,1,MaxLen);
  156. end;
  157. constructor TWindowListDialog.Init;
  158. var R,R2: TRect;
  159. SB: PScrollBar;
  160. begin
  161. R.Assign(0,0,Max(60,round(ScreenWidth*5/8)),Max(13,round(ScreenHeight*3/5)));
  162. inherited Init(R, dialog_windowlist);
  163. HelpCtx:=hcWindowList;
  164. New(C, Init(20,10));
  165. GetExtent(R); R.Grow(-2,-2); Inc(R.A.Y); R.B.X:=R.B.X-14;
  166. R2.Copy(R); R2.Move(1,0); R2.A.X:=R2.B.X-1;
  167. New(SB, Init(R2)); Insert(SB);
  168. New(LB, Init(R, SB));
  169. LB^.Default:=true;
  170. LB^.NewList(C);
  171. UpdateList;
  172. if C^.Count>=2 then
  173. if PWindow(C^.At(1))^.GetState(sfVisible) then
  174. LB^.FocusItem(1); { focus the 2nd one }
  175. Insert(LB);
  176. R2.Copy(R); Dec(R2.A.Y); R2.B.Y:=R2.A.Y+1;
  177. Insert(New(PLabel, Init(R2, label_wndlist_windows, LB)));
  178. 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;
  179. Insert(New(PButton, Init(R, button_OK, cmOK, bfDefault)));
  180. R.Move(0,2);
  181. Insert(New(PButton, Init(R, button_Delete, cmDeleteItem, bfNormal)));
  182. R.Move(0,2);
  183. New(BtnShow, Init(R, button_Show, cmShowItem, bfNormal));
  184. Insert(BtnShow);
  185. R.Move(0,2);
  186. New(BtnHide, Init(R, button_Hide, cmHideItem, bfNormal));
  187. Insert(BtnHide);
  188. R.Move(0,2);
  189. Insert(New(PButton, Init(R, button_Cancel, cmCancel, bfNormal)));
  190. LB^.Select;
  191. PutCommand(@Self,evBroadcast,cmListFocusChanged,LB);
  192. end;
  193. procedure TWindowListDialog.UpdateList;
  194. var VisState: boolean;
  195. procedure AddIt(P: PView);
  196. begin
  197. if (P<>pointer(Desktop^.Background)) and
  198. (P^.GetState(sfDisabled)=false) and
  199. ((P^.Options and ofSelectable)<>0) and
  200. (P^.GetState(sfVisible)=VisState) then
  201. C^.Insert(P);
  202. end;
  203. begin
  204. C^.DeleteAll;
  205. VisState:=true; Desktop^.ForEach(TCallbackProcParam(@AddIt)); { add visible windows to list }
  206. VisState:=false; Desktop^.ForEach(TCallbackProcParam(@AddIt)); { add hidden windows }
  207. LB^.SetRange(C^.Count);
  208. UpdateButtons;
  209. ReDraw;
  210. end;
  211. procedure TWindowListDialog.UpdateButtons;
  212. var W: PView;
  213. begin
  214. if LB^.Range>0 then
  215. begin
  216. W:=LB^.List^.At(LB^.Focused);
  217. if Assigned(BtnShow) then
  218. BtnShow^.SetState(sfDisabled,W^.GetState(sfVisible));
  219. if Assigned(BtnHide) then
  220. BtnHide^.SetState(sfDisabled,not W^.GetState(sfVisible));
  221. end
  222. else
  223. begin
  224. BtnShow^.SetState(sfDisabled,true);
  225. BtnHide^.SetState(sfDisabled,true);
  226. end;
  227. ReDraw;
  228. end;
  229. procedure TWindowListDialog.HandleEvent(var Event: TEvent);
  230. var W: PWindow;
  231. KeePOwner : PGroup;
  232. begin
  233. case Event.What of
  234. evKeyDown :
  235. case Event.KeyCode of
  236. kbDel :
  237. begin
  238. Message(@Self,evCommand,cmDeleteItem,nil);
  239. ClearEvent(Event);
  240. end;
  241. end;
  242. evBroadcast :
  243. case Event.Command of
  244. cmListFocusChanged :
  245. if Event.InfoPtr=LB then
  246. UpdateButtons;
  247. end;
  248. evCommand :
  249. case Event.Command of
  250. cmDeleteItem :
  251. if C^.Count>0 then
  252. begin
  253. W:=PWindow(C^.At(LB^.Focused));
  254. { we need to remove the window from the list
  255. because otherwise
  256. IDEApp.SourceWindowClosed
  257. is called after the object has been freed
  258. but the ListBox.Redraw will still try to
  259. read the title PM }
  260. KeepOwner:=W^.Owner;
  261. if assigned(KeepOwner) then
  262. KeepOwner^.Delete(W);
  263. UpdateList;
  264. { But reinsert it as Close might only
  265. trigger Hide in some cases }
  266. if assigned(KeepOwner) then
  267. KeepOwner^.Insert(W);
  268. Message(W,evCommand,cmClose,nil);
  269. UpdateList;
  270. ClearEvent(Event);
  271. end;
  272. cmShowItem :
  273. if C^.Count>0 then
  274. begin
  275. PWindow(C^.At(LB^.Focused))^.Show;
  276. UpdateList;
  277. ClearEvent(Event);
  278. end;
  279. cmHideItem :
  280. if C^.Count>0 then
  281. begin
  282. PWindow(C^.At(LB^.Focused))^.Hide;
  283. UpdateList;
  284. ClearEvent(Event);
  285. end;
  286. cmOK :
  287. if C^.Count>0 then
  288. begin
  289. W:=PWindow(C^.At(LB^.Focused));
  290. if W^.GetState(sfVisible)=false then
  291. W^.Show;
  292. W^.MakeFirst;
  293. end;
  294. end;
  295. end;
  296. inherited HandleEvent(Event);
  297. end;
  298. destructor TWindowListDialog.Done;
  299. begin
  300. if C<>nil then begin C^.DeleteAll; Dispose(C, Done); end;
  301. inherited Done;
  302. end;
  303. procedure TIDEApp.WindowList;
  304. var W: PWindowListDialog;
  305. begin
  306. New(W,Init);
  307. ExecView(W);
  308. Dispose(W,Done);
  309. Desktop^.Lock;
  310. { force correct commands to be enabled }
  311. Desktop^.SetState(sfActive,true); { activate everything }
  312. Desktop^.SetState(sfActive,false); { deactivate everything }
  313. if assigned(Desktop^.Current) then
  314. Desktop^.Current^.SetState(sfActive,true); { set active only current }
  315. Desktop^.UnLock;
  316. end;