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