fpmwnd.inc 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  5. Window menu entries
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. procedure TIDEApp.CloseAll;
  13. procedure SendClose(P: PView); {$ifndef FPC}far;{$endif}
  14. begin
  15. Message(P,evCommand,cmClose,nil);
  16. end;
  17. begin
  18. Desktop^.ForEach(@SendClose);
  19. end;
  20. procedure TIDEApp.ResizeApplication(x, y : longint);
  21. var
  22. OldR : TRect;
  23. Mode : TVideoMode;
  24. begin
  25. GetBounds(OldR);
  26. { adapt to new size }
  27. if (OldR.B.Y-OldR.A.Y<>y) or
  28. (OldR.B.X-OldR.A.X<>x) then
  29. begin
  30. Mode.color:=ScreenMode.Color;
  31. Mode.col:=x;
  32. Mode.row:=y;
  33. SetScreenVideoMode(Mode);
  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. hcInfoWindow : S:=PProgramInfoWindow(P)^.GetTitle(MaxLen);
  67. hcHelpWindow : S:=PHelpWindow(P)^.GetTitle(MaxLen);
  68. hcCalcWindow : S:=PCalculator(P)^.GetTitle(MaxLen);
  69. hcBrowserWindow: S:=PBrowserWindow(P)^.GetTitle(MaxLen);
  70. hcCompilerMessagesWindow,
  71. hcMessagesWindow:S:=PMessagesWindow(P)^.GetTitle(MaxLen);
  72. hcGDBWindow,
  73. hcDisassemblyWindow,
  74. hcWatchesWindow,
  75. hcStackWindow,
  76. hcRegistersWindow,
  77. hcFPURegisters,
  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-13;
  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); {$ifndef FPC}far;{$endif}
  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(@AddIt); { add visible windows to list }
  142. VisState:=false; Desktop^.ForEach(@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. 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. Message(C^.At(LB^.Focused),evCommand,cmClose,nil);
  189. UpdateList;
  190. ClearEvent(Event);
  191. end;
  192. cmShowItem :
  193. if C^.Count>0 then
  194. begin
  195. PWindow(C^.At(LB^.Focused))^.Show;
  196. UpdateList;
  197. ClearEvent(Event);
  198. end;
  199. cmHideItem :
  200. if C^.Count>0 then
  201. begin
  202. PWindow(C^.At(LB^.Focused))^.Hide;
  203. UpdateList;
  204. ClearEvent(Event);
  205. end;
  206. cmOK :
  207. if C^.Count>0 then
  208. begin
  209. W:=PWindow(C^.At(LB^.Focused));
  210. if W^.GetState(sfVisible)=false then
  211. W^.Show;
  212. W^.MakeFirst;
  213. end;
  214. end;
  215. end;
  216. inherited HandleEvent(Event);
  217. end;
  218. destructor TWindowListDialog.Done;
  219. begin
  220. if C<>nil then begin C^.DeleteAll; Dispose(C, Done); end;
  221. inherited Done;
  222. end;
  223. procedure TIDEApp.WindowList;
  224. var W: PWindowListDialog;
  225. begin
  226. New(W,Init);
  227. ExecView(W);
  228. Dispose(W,Done);
  229. if assigned(Desktop^.Current) then
  230. begin
  231. Desktop^.Lock;
  232. { force correct commands to be enabled }
  233. Desktop^.Current^.SetState(sfActive,false);
  234. Desktop^.Current^.SetState(sfActive,true);
  235. Desktop^.UnLock;
  236. end;
  237. end;
  238. {
  239. $Log$
  240. Revision 1.5 2004-11-06 22:02:49 peter
  241. * fixed resize helptext
  242. Revision 1.4 2002/09/07 15:40:44 peter
  243. * old logs removed and tabs fixed
  244. Revision 1.3 2002/06/07 14:09:56 pierre
  245. * try to get resizing to work
  246. Revision 1.2 2002/05/30 15:03:24 pierre
  247. + ResizeApplication pethod for fvision
  248. }