Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afssvrmgr / window.cpp
blob0b0be1384eb272a0188ac9e44e6668474b2d40c7
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
10 #include <winsock2.h>
11 #include <ws2tcpip.h>
13 extern "C" {
14 #include <afs/param.h>
15 #include <afs/stds.h>
18 #include "svrmgr.h"
19 #include <shellapi.h>
20 #include "display.h"
21 #include "command.h"
22 #include "messages.h"
23 #include "svr_window.h"
24 #include "svr_general.h"
25 #include "svr_security.h"
26 #include "set_repprop.h"
27 #include "set_createrep.h"
28 #include "set_rename.h"
29 #include "columns.h"
30 #include "propcache.h"
31 #include "action.h"
32 #include "creds.h"
36 * RESIZING WINDOWS ___________________________________________________________
40 #define cxMIN_SERVER 75
41 #define cyMIN_SERVER 70
43 #define cxMIN_TABS 100
44 #define cyMIN_TABS 100
46 #define cxMIN_WINDOW_PREVIEW 220
47 #define cyMIN_WINDOW_PREVIEW 250
49 #define cxMIN_WINDOW 120
50 #define cyMIN_WINDOW 120
52 rwWindowData awdMain[] = {
53 { IDC_CELL_BORDER, raSizeX, 0, 0 },
54 { IDC_CELL, raSizeX | raRepaint, 0, 0 },
55 { IDC_AFS_ID, raSizeX | raRepaint, 0, 0 },
56 { IDC_SERVERS, raSizeX | raSizeY, MAKELONG(cxMIN_SERVER,cyMIN_SERVER), 0 },
57 { IDC_COVERDLG, raSizeX | raSizeY, 0, 0 },
58 { IDC_ANIMATE, raMoveX, 0, 0 },
59 { idENDLIST, 0, 0, 0 }
62 rwWindowData awdMainVert[] = {
63 { IDC_CELL_BORDER, raSizeX, 0, 0 },
64 { IDC_CELL, raSizeX | raRepaint, 0, 0 },
65 { IDC_AFS_ID, raSizeX | raRepaint, 0, 0 },
66 { IDC_SERVERS, raSizeX, MAKELONG(cxMIN_SERVER,cyMIN_SERVER), 0 },
67 { IDC_SPLITTER_SERVER, raSizeX, 0, 0 },
68 { IDC_TABS, raSizeX | raSizeY, MAKELONG(cxMIN_TABS,cyMIN_TABS), 0 },
69 { IDC_COVERDLG, raSizeX, 0, 0 },
70 { IDC_ANIMATE, raMoveX, 0, 0 },
71 { idENDLIST, 0, 0, 0 }
74 rwWindowData awdMainHorz[] = {
75 { IDC_CELL_BORDER, raSizeX, 0, 0 },
76 { IDC_CELL, raSizeX | raRepaint, 0, 0 },
77 { IDC_AFS_ID, raSizeX | raRepaint, 0, 0 },
78 { IDC_SERVERS, raSizeY, MAKELONG(cxMIN_SERVER,cyMIN_SERVER), 0 },
79 { IDC_SPLITTER_SERVER, raSizeY, 0, 0 },
80 { IDC_TABS, raSizeX | raSizeY, MAKELONG(cxMIN_TABS,cyMIN_TABS), 0 },
81 { IDC_COVERDLG, raSizeY, 0, 0 },
82 { IDC_ANIMATE, raMoveX, 0, 0 },
83 { idENDLIST, 0, 0, 0 }
86 rwWindowData awdSplitServer[] = {
87 { IDC_CELL, raRepaint, 0, 0 },
88 { IDC_AFS_ID, raRepaint, 0, 0 },
89 { IDC_SERVERS, raSizeX | raSizeY, MAKELONG(cxMIN_SERVER,cyMIN_SERVER), 0 },
90 { IDC_SPLITTER_SERVER, raMoveX | raMoveY, 0, 0 },
91 { IDC_TABS, raMoveX | raMoveY | raSizeXB | raSizeYB, MAKELONG(cxMIN_TABS,cyMIN_TABS), 0 },
92 { IDC_COVERDLG, raSizeX | raSizeY, 0, 0 },
93 { IDC_ANIMATE, 0, 0, 0 },
94 { idENDLIST, 0, 0, 0 }
99 * PROTOTYPES _________________________________________________________________
103 void Main_OnNotifyFromDispatch (LPNOTIFYSTRUCT lpns);
105 void Main_OnPreviewPane (BOOL fPreviewNew, BOOL fVertNew, BOOL fStoreView);
106 DWORD WINAPI Main_OnOpenServers_ThreadProc (PVOID lp);
108 void Main_SubclassServers (HWND hDlg);
110 void Main_CreateTabControl (void);
111 void Main_DeleteTabControl (void);
112 void Main_DisplayTab (CHILDTAB iTab);
113 void Main_RearrangeChildren (BOOL fSplitNew, BOOL fVertNew);
115 BOOL Main_HandleDialogKeys (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
116 void Main_OnKey_CtrlTab (BOOL fForward);
117 void Main_OnKey_Tab (BOOL fForward);
119 #ifdef DEBUG
120 void ExportCell (void);
121 #endif
125 * ROUTINES ___________________________________________________________________
130 static BOOL fEnforceMinimumSize = TRUE;
131 static BOOL fNotifyChildrenForResize = TRUE;
132 static LONG nReqWorking = 0;
133 static int iFrameLast = 0;
135 BOOL CALLBACK Main_DialogProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
137 if (HandleColumnNotify (hDlg, msg, wp, lp, (gr.fPreview && !gr.fVert) ? &gr.diHorz.viewSvr : &gr.diVert.viewSvr))
138 return FALSE;
140 if (Main_HandleDialogKeys (hDlg, msg, wp, lp))
141 return TRUE;
143 if (msg == WM_INITDIALOG) // get this out of the way. :)
145 g.hMain = hDlg;
146 AfsAppLib_SetMainWindow (g.hMain);
149 switch (msg)
151 case WM_INITDIALOG:
153 LPRECT prTarget = (gr.fPreview) ? &gr.rMainPreview : &gr.rMain;
154 if (prTarget->right == 0)
155 GetWindowRect (g.hMain, prTarget);
156 ResizeWindow (g.hMain, awdMain, rwaMoveToHere, prTarget);
158 Main_SetActionMenus();
160 // Subclass the Servers window, so we can watch for focus changes
161 // and context-menu requests
163 Main_SubclassServers (hDlg);
164 FastList_SetTextCallback (GetDlgItem (hDlg, IDC_SERVERS), GetItemText, ((gr.fPreview && !gr.fVert) ? &gr.diHorz.viewSvr : &gr.diVert.viewSvr));
166 // Create the preview pane and rearrange the children of this dialog.
167 // This also fixes the Servers display--was it in Large Icons view?
168 // What columns were shown?
170 Main_OnPreviewPane (gr.fPreview, gr.fVert, FALSE);
172 // Tell our notification dispatcher to let this window know whenever
173 // a cell gets opened or closed (that's what the NULL does--otherwise,
174 // an LPIDENT would go there to indicate we're interested in a
175 // particular server etc).
177 NotifyMe (WHEN_CELL_OPENED, NULL, hDlg, 0); // tell me about any cell
179 // If we weren't around when the cell was created, we might have
180 // missed some notifications. Send a redraw just in case.
182 StartThread (Main_Redraw_ThreadProc, FALSE);
184 SetTimer (hDlg, ID_DISPATCH_TIMER, 200, NULL); // do all notifications
186 break;
188 case WM_DESTROY:
189 KillTimer (hDlg, ID_DISPATCH_TIMER);
190 break;
192 case WM_QUERYENDSESSION:
193 if (Action_fAnyActive())
195 ShowWindow (g.hMain, SW_SHOW);
196 if (Message (MB_ICONHAND | MB_YESNO, IDS_CANT_QUIT_TITLE, IDS_CANT_QUIT_REBOOT) != IDYES)
197 return TRUE;
199 break;
201 case WM_TIMER:
202 if (wp == ID_DISPATCH_TIMER)
204 DispatchNotification_OnPump();
206 break;
208 case WM_HELP:
209 if ((lp == 0) || (IsAncestor (g.hMain, (HWND)(((LPHELPINFO)lp)->hItemHandle))))
211 WinHelp (hDlg, cszHELPFILENAME, HELP_FINDER, 0);
213 break;
215 case WM_NOTIFY_FROM_DISPATCH:
216 Main_OnNotifyFromDispatch ((LPNOTIFYSTRUCT)lp);
217 Delete ((LPNOTIFYSTRUCT)lp);
218 break;
220 case WM_ENDTASK:
221 LPTASKPACKET ptp;
222 if ((ptp = (LPTASKPACKET)lp) != NULL)
224 if (ptp->idTask == taskSVR_GETWINDOWPOS)
225 Server_Open ((LPIDENT)(ptp->lpUser), &TASKDATA(ptp)->rWindow);
226 else if (ptp->idTask == taskSET_REPPROP_INIT)
227 Filesets_OnEndTask_ShowReplication (ptp);
228 else if (ptp->idTask == taskSET_RENAME_INIT)
229 Filesets_OnEndTask_ShowRename (ptp);
230 FreeTaskPacket (ptp);
232 break;
234 case WM_OPEN_SERVERS:
235 StartThread (Main_OnOpenServers_ThreadProc, 0);
236 break;
238 case WM_OPEN_SERVER:
239 StartTask (taskSVR_GETWINDOWPOS, g.hMain, (LPIDENT)lp);
240 break;
242 case WM_SHOW_CREATEREP_DIALOG:
243 Filesets_CreateReplica ((LPIDENT)wp, (LPIDENT)lp);
244 break;
246 case WM_SHOW_YOURSELF:
247 if (lp || g.lpiCell)
249 ShowWindow (g.hMain, SW_SHOW);
250 BringWindowToTop (g.hMain);
251 Action_WindowToTop (TRUE);
253 break;
255 case WM_OPEN_ACTIONS:
256 Action_OpenWindow();
257 break;
259 case WM_REFRESHED_CREDENTIALS:
260 g.hCreds = (UINT_PTR)lp;
261 UpdateDisplay_Cell(FALSE);
262 StartTask (taskREFRESH_CREDS, NULL, g.lpiCell);
263 break;
265 case WM_SIZE:
266 // if (lp==0), we're minimizing--don't call ResizeWindow().
268 Action_WindowToTop ((lp) ? TRUE : FALSE);
269 if (lp != 0)
271 rwWindowData *pwdResizeInfo;
273 if (!gr.fPreview)
274 pwdResizeInfo = awdMain;
275 else if (gr.fVert)
276 pwdResizeInfo = awdMainVert;
277 else // (!gr.fVert)
278 pwdResizeInfo = awdMainHorz;
280 if (fNotifyChildrenForResize)
281 ResizeWindow (hDlg, pwdResizeInfo, rwaFixupGuts);
282 else
283 ResizeWindow (hDlg, pwdResizeInfo, rwaJustResync);
285 break;
287 case WM_ACTIVATEAPP:
288 Action_WindowToTop ((wp) ? TRUE : FALSE);
290 if (wp)
291 StartTask (taskEXPIRED_CREDS);
292 break;
294 case WM_CONTEXTMENU:
296 POINT ptScreen;
297 POINT ptClient;
298 ptScreen.x = LOWORD(lp);
299 ptScreen.y = HIWORD(lp);
301 ptClient = ptScreen;
302 ScreenToClient ((HWND)wp, &ptClient);
304 if ((HWND)wp == GetDlgItem (g.hMain, IDC_SERVERS))
305 Server_ShowPopupMenu ((HWND)wp, ptClient, ptScreen);
307 break;
309 case WM_COMMAND:
310 switch (LOWORD(wp))
312 case IDCANCEL:
313 case M_EXIT:
314 Quit (0);
315 break;
317 case M_DIVIDE_NONE:
318 Main_OnPreviewPane (FALSE, gr.fVert, TRUE);
319 UpdateDisplay_Servers (FALSE, NULL, 0);
320 break;
321 case M_DIVIDE_H:
322 Main_OnPreviewPane (TRUE, FALSE, TRUE);
323 UpdateDisplay_Servers (FALSE, NULL, 0);
324 break;
325 case M_DIVIDE_V:
326 Main_OnPreviewPane (TRUE, TRUE, TRUE);
327 UpdateDisplay_Servers (FALSE, NULL, 0);
328 break;
330 case M_SVR_VIEW_LARGE:
331 Main_OnServerView (FLS_VIEW_LARGE);
332 break;
333 case M_SVR_VIEW_SMALL:
334 Main_OnServerView (FLS_VIEW_SMALL);
335 break;
336 case M_SVR_VIEW_REPORT:
337 Main_OnServerView (FLS_VIEW_LIST);
338 break;
340 case M_COLUMNS:
341 if (!gr.fPreview)
342 ShowColumnsDialog (hDlg, NULL);
343 else
345 CHILDTAB iTab = Server_GetDisplayedTab (g.hMain);
346 if (iTab == tabSERVICES)
347 ShowColumnsDialog (hDlg, &gr.viewSvc);
348 else if (iTab == tabAGGREGATES)
349 ShowColumnsDialog (hDlg, &gr.viewAgg);
350 else if (iTab == tabFILESETS)
351 ShowColumnsDialog (hDlg, &gr.viewSet);
352 else
353 ShowColumnsDialog (hDlg, NULL);
355 break;
357 case M_ACTIONS:
358 if ((gr.fActions = !gr.fActions) == TRUE)
359 Action_OpenWindow();
360 else
361 Action_CloseWindow();
362 Main_SetActionMenus();
363 break;
365 #ifdef DEBUG
366 case M_EXPORT:
367 ExportCell();
368 break;
369 #endif
371 case IDC_COVER_BUTTON:
372 // The user must have clicked the "Try Again" or "Credentials"
373 // button on the cover we placed over the Servers list.
374 // Refresh the cell or obtain new credentials, as appropriate.
376 if (g.lpiCell)
378 TCHAR szButton[ cchRESOURCE ];
379 GetWindowText ((HWND)lp, szButton, cchRESOURCE);
381 TCHAR szTest[ cchRESOURCE ];
383 GetString (szTest, IDS_ALERT_BUTTON_TRYAGAIN);
384 if (!lstrcmp (szTest, szButton))
386 StartTask (taskREFRESH, NULL, g.lpiCell);
387 break;
390 GetString (szTest, IDS_ALERT_BUTTON_GETCREDS);
391 if (!lstrcmp (szTest, szButton))
393 NewCredsDialog();
394 break;
397 break;
399 default:
400 StartContextCommand (g.hMain, NULL, NULL, LOWORD(wp));
401 break;
403 break;
405 case WM_NOTIFY:
406 switch (((LPNMHDR)lp)->code)
408 case TCN_SELCHANGE:
410 int iPage = TabCtrl_GetCurSel (GetDlgItem (g.hMain, IDC_TABS));
411 Main_DisplayTab ((CHILDTAB)iPage);
413 break;
415 case FLN_ITEMSELECT:
416 if (gr.fPreview)
418 HWND hServers = GetDlgItem (hDlg, IDC_SERVERS);
419 LPIDENT lpi = (LPIDENT)FL_GetSelectedData (hServers);
421 Server_SelectServer (SERVERWINDOW_PREVIEWPANE, lpi);
423 break;
425 case FLN_LDBLCLICK:
427 HWND hServers = GetDlgItem (g.hMain, IDC_SERVERS);
429 if (((LPNMHDR)lp)->hwndFrom == hServers)
431 LPIDENT lpi = (LPIDENT)FL_GetSelectedData (hServers);
433 if (lpi && lpi->fIsServer())
435 BOOL fOpenWindow;
437 if (gr.fDoubleClickOpens == 0)
438 fOpenWindow = FALSE;
439 else if (gr.fDoubleClickOpens == 1)
440 fOpenWindow = TRUE;
441 else if (gr.fPreview)
442 fOpenWindow = FALSE;
443 else // (!gr.Preview)
444 fOpenWindow = TRUE;
446 if (!fOpenWindow)
448 PostMessage (hServers, WM_COMMAND, M_PROPERTIES, 0);
450 else // (fOpenWindow)
452 PostMessage (g.hMain, WM_OPEN_SERVER, 0, (LPARAM)lpi);
457 break;
459 break;
462 return FALSE;
466 void Main_OnNotifyFromDispatch (LPNOTIFYSTRUCT lpns)
468 switch (lpns->evt)
470 case evtCreate:
471 StartTask (taskOPENEDCELL, NULL, lpns->Params.lpi1);
472 break;
474 case evtDestroy:
475 StartTask (taskCLOSEDCELL, NULL, lpns->Params.lpi1);
476 break;
478 case evtRefreshStatusEnd:
479 case evtAlertsChanged:
480 if (lpns->Params.lpi1 && lpns->Params.lpi1->fIsCell())
482 UpdateDisplay_Cell (FALSE);
484 else if (lpns->Params.lpi1 && lpns->Params.lpi1->fIsServer())
486 UpdateDisplay_Servers (FALSE, lpns->Params.lpi1, lpns->Params.status);
488 break;
490 case evtRefreshServersEnd:
491 if (g.lpiCell || lpns->Params.status == 0)
493 UpdateDisplay_Servers (FALSE, NULL, 0);
495 break;
500 DWORD WINAPI Main_OnOpenServers_ThreadProc (PVOID lp)
502 AfsClass_Enter();
504 if (g.lpiCell != NULL)
506 LPCELL lpCell;
507 if ((lpCell = g.lpiCell->OpenCell()) != NULL)
509 HENUM hEnum;
510 for (LPSERVER lpServer = lpCell->ServerFindFirst (&hEnum); lpServer; lpServer = lpCell->ServerFindNext (&hEnum))
512 LPSERVER_PREF lpsp;
513 if ((lpsp = (LPSERVER_PREF)lpServer->GetUserParam()) != NULL)
515 if (lpsp->fOpen && !PropCache_Search (pcSERVER, lpServer->GetIdentifier()))
517 PostMessage (g.hMain, WM_OPEN_SERVER, 0, (LPARAM)(lpServer->GetIdentifier()));
520 lpServer->Close();
522 lpCell->Close();
526 AfsClass_Leave();
527 return 0;
531 DWORD WINAPI Main_Redraw_ThreadProc (PVOID lp)
533 BOOL fInvalidate = (BOOL)(UINT_PTR)lp;
534 AfsClass_Enter();
536 if (g.lpiCell == NULL)
538 AfsAppLib_Uncover (GetDlgItem (g.hMain, IDC_SERVERS));
540 else
542 TCHAR szName[ cchRESOURCE ];
543 g.lpiCell->GetCellName (szName);
545 LPTSTR pszCover = FormatString (IDS_SEARCHING_FOR_SERVERS, TEXT("%s"), szName);
546 AfsAppLib_CoverWindow (GetDlgItem (g.hMain, IDC_SERVERS), pszCover);
547 FreeString (pszCover);
550 LPCELL lpCell = NULL;
551 if (g.lpiCell != NULL)
552 lpCell = g.lpiCell->OpenCell();
554 if (lpCell)
556 if (fInvalidate)
558 lpCell->Invalidate();
559 lpCell->RefreshAll();
561 else
563 lpCell->RefreshStatus();
564 lpCell->RefreshServers();
567 else // no cell is selected; we'll have to redraw the window directly.
569 UpdateDisplay_Cell (TRUE);
570 UpdateDisplay_Servers (TRUE, NULL, 0);
573 if (lpCell != NULL)
574 lpCell->Close();
576 AfsClass_Leave();
577 return 0;
581 void Main_OnPreviewPane (BOOL fPreviewNew, BOOL fVertNew, BOOL fStoreCurrentView)
583 if (fStoreCurrentView)
585 if (gr.fPreview && !gr.fVert)
586 FL_StoreView (GetDlgItem (g.hMain, IDC_SERVERS), &gr.diHorz.viewSvr);
587 else
588 FL_StoreView (GetDlgItem (g.hMain, IDC_SERVERS), &gr.diVert.viewSvr);
590 if (gr.fPreview)
591 GetWindowRect (g.hMain, &gr.rMainPreview);
592 else
593 GetWindowRect (g.hMain, &gr.rMain);
596 // If switching from having a preview pane to not (or vice-versa),
597 // and we have an alterate gr.rMain* to switch to, resize the window.
599 if (IsWindowVisible (g.hMain))
601 RECT rNow;
602 GetWindowRect (g.hMain, &rNow);
604 LPRECT prTarget = (fPreviewNew) ? &gr.rMainPreview : &gr.rMain;
605 if (prTarget->right == 0)
607 *prTarget = rNow;
608 if (gr.fPreview && gr.fVert) // preview pane exists below main window?
610 RECT rPreview;
611 GetWindowRect (GetDlgItem (g.hMain, IDC_TABS), &rPreview);
612 if (gr.fVert)
613 prTarget->bottom -= cyRECT(rPreview);
616 prTarget->right = prTarget->left + cxRECT(rNow); // keep the same width!
618 fEnforceMinimumSize = FALSE;
619 fNotifyChildrenForResize = FALSE;
621 SetWindowPos (g.hMain, NULL,
622 0, 0, cxRECT(*prTarget), cyRECT(*prTarget),
623 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE);
625 fNotifyChildrenForResize = TRUE;
626 fEnforceMinimumSize = TRUE;
629 // Create a tab control if necessary, or remove it if it should be gone.
631 if (fPreviewNew && !GetDlgItem (g.hMain, IDC_TABS))
633 Main_CreateTabControl();
635 if (!fPreviewNew && GetDlgItem (g.hMain, IDC_TABS))
637 Main_DeleteTabControl();
640 // If there's a tab control, we'll need a splitter; if not, not.
642 if (GetDlgItem (g.hMain, IDC_SPLITTER_SERVER))
644 DeleteSplitter (g.hMain, IDC_SPLITTER_SERVER);
647 Main_RearrangeChildren (fPreviewNew, fVertNew);
649 if (fPreviewNew)
651 CreateSplitter (g.hMain, IDC_SERVERS, IDC_TABS, IDC_SPLITTER_SERVER,
652 (fVertNew) ? &gr.diVert.cSplitter : &gr.diHorz.cSplitter,
653 awdSplitServer,
654 TRUE);
657 if (GetDlgItem (g.hMain, IDC_TABS))
659 ShowWindow (GetDlgItem (g.hMain, IDC_TABS), SW_SHOW);
662 LPVIEWINFO lpvi = (fPreviewNew && !fVertNew) ? &gr.diHorz.viewSvr : &gr.diVert.viewSvr;
664 FL_RestoreView (GetDlgItem (g.hMain, IDC_SERVERS), lpvi);
666 CheckMenuRadioItem (GetMenu (g.hMain),
667 M_DIVIDE_NONE, M_DIVIDE_H,
668 ( (!fPreviewNew) ? M_DIVIDE_NONE :
669 (fVertNew) ? M_DIVIDE_V :
670 M_DIVIDE_H ),
671 MF_BYCOMMAND);
673 gr.fVert = fVertNew;
674 gr.fPreview = fPreviewNew;
676 Main_SetServerViewMenus();
680 void Main_OnServerView (int lvsNew)
682 HWND hServers = GetDlgItem (g.hMain, IDC_SERVERS);
684 if (gr.fPreview && !gr.fVert)
685 FL_StoreView (hServers, &gr.diHorz.viewSvr);
686 else
687 FL_StoreView (hServers, &gr.diVert.viewSvr);
689 if (gr.fPreview && !gr.fVert)
690 gr.diHorz.viewSvr.lvsView = lvsNew;
691 else
692 gr.diVert.viewSvr.lvsView = lvsNew;
694 if (gr.fPreview && !gr.fVert)
695 FL_RestoreView (hServers, &gr.diHorz.viewSvr);
696 else
697 FL_RestoreView (hServers, &gr.diVert.viewSvr);
699 Main_SetServerViewMenus();
700 FastList_SetTextCallback (GetDlgItem (g.hMain, IDC_SERVERS), GetItemText, ((gr.fPreview && !gr.fVert) ? &gr.diHorz.viewSvr : &gr.diVert.viewSvr));
701 UpdateDisplay_Servers (FALSE, NULL, 0);
705 void Main_SetServerViewMenus (void)
707 LONG lvs;
709 if (gr.fPreview && !gr.fVert)
710 lvs = gr.diHorz.viewSvr.lvsView;
711 else
712 lvs = gr.diVert.viewSvr.lvsView;
714 CheckMenuRadioItem (GetMenu (g.hMain),
715 M_SVR_VIEW_LARGE, M_SVR_VIEW_REPORT,
716 ( (lvs == FLS_VIEW_SMALL) ? M_SVR_VIEW_SMALL :
717 (lvs == FLS_VIEW_LIST) ? M_SVR_VIEW_REPORT :
718 M_SVR_VIEW_LARGE ),
719 MF_BYCOMMAND);
721 ICONVIEW ivSvr = Display_GetServerIconView();
723 CheckMenuRadioItem (GetMenu (g.hMain),
724 M_SVR_VIEW_ONEICON, M_SVR_VIEW_STATUS,
725 (ivSvr == ivTWOICONS) ? M_SVR_VIEW_TWOICONS :
726 (ivSvr == ivONEICON) ? M_SVR_VIEW_ONEICON : M_SVR_VIEW_STATUS,
727 MF_BYCOMMAND);
729 EnableMenu (GetMenu (g.hMain), M_SVR_VIEW_ONEICON, (lvs == FLS_VIEW_LIST) ? TRUE : FALSE);
730 EnableMenu (GetMenu (g.hMain), M_SVR_VIEW_TWOICONS, (lvs == FLS_VIEW_LIST) ? TRUE : FALSE);
731 EnableMenu (GetMenu (g.hMain), M_SVR_VIEW_STATUS, (lvs == FLS_VIEW_LIST) ? TRUE : FALSE);
735 void Main_SetActionMenus (void)
737 CheckMenu (GetMenu (g.hMain), M_ACTIONS, gr.fActions);
741 void Main_CreateTabControl (void)
743 HWND hTab = CreateWindowEx (WS_EX_CLIENTEDGE,
744 WC_TABCONTROL,
745 TEXT(""),
746 WS_CHILD | WS_CLIPSIBLINGS | WS_TABSTOP,
747 0, 0, 128, 128, // arbitrary, but not too small
748 SERVERWINDOW_PREVIEWPANE,
749 (HMENU)IDC_TABS,
750 THIS_HINST,
751 NULL);
753 if (hTab != NULL)
755 HFONT hf = (HFONT)GetStockObject (DEFAULT_GUI_FONT);
756 SendMessage (hTab, WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE,0));
758 Server_PrepareTabControl (hTab);
760 LPIDENT lpi = (LPIDENT)FL_GetSelectedData (GetDlgItem (g.hMain, IDC_SERVERS));
761 Server_SelectServer (SERVERWINDOW_PREVIEWPANE, lpi);
766 void Main_DeleteTabControl (void)
768 if (GetDlgItem (SERVERWINDOW_PREVIEWPANE, IDC_TABS))
770 DestroyWindow (GetDlgItem (SERVERWINDOW_PREVIEWPANE, IDC_TABS));
775 void Main_DisplayTab (CHILDTAB iTab)
777 if (gr.fPreview)
779 Server_DisplayTab (SERVERWINDOW_PREVIEWPANE, iTab);
780 gr.tabLast = (CHILDTAB)iTab;
785 void Main_RearrangeChildren (BOOL fPreviewNew, BOOL fVertNew)
787 RECT rServers;
788 RECT rPreview;
790 // Start with the Servers window taking up the entire dialog's client area,
791 // leaving a space at the top for the cell combobox.
793 RECT rCell;
794 GetRectInParent (GetDlgItem (g.hMain, IDC_AFS_ID), &rCell);
796 GetClientRect (g.hMain, &rServers);
797 rServers.top = rCell.bottom +3;
799 // Then, if the preview tab is to be displayed, make the server window
800 // share the space equally with the tab control (vertically or horizontally)
802 if (fPreviewNew)
804 rPreview = rServers;
806 if (fVertNew)
808 rServers.bottom = rServers.top + cyRECT(rServers)/2 - 1;
809 rPreview.top = rServers.bottom + 2;
811 else
813 rServers.right = rServers.left + cxRECT(rServers)/2 - 1;
814 rPreview.left = rServers.right + 2;
817 // Adjust the server/tab windows for the Server splitter's position
819 if (fVertNew)
821 LONG cyMod = gr.diVert.cSplitter;
823 if (cyRECT(rServers) > cyMIN_SERVER)
824 cyMod = min( cyMod, cyRECT(rServers)-cyMIN_SERVER );
825 if (cyRECT(rPreview) > cyMIN_TABS)
826 cyMod = min( cyMod, cyRECT(rPreview)-cyMIN_TABS );
828 rServers.bottom += cyMod;
829 rPreview.top += cyMod;
831 else
833 LONG cxMod = gr.diHorz.cSplitter;
835 if (cxRECT(rServers) > cxMIN_SERVER)
836 cxMod = min( cxMod, cxRECT(rServers)-cxMIN_SERVER );
837 if (cxRECT(rPreview) > cxMIN_TABS)
838 cxMod = min( cxMod, cxRECT(rPreview)-cxMIN_TABS );
840 rServers.right += cxMod;
841 rPreview.left += cxMod;
845 // Now move the children to their new places!
847 int nWindows = 1;
848 if (GetDlgItem (g.hMain, IDC_COVERDLG))
849 ++nWindows;
850 if (GetDlgItem (g.hMain, IDC_TABS))
851 ++nWindows;
852 HDWP dwp = BeginDeferWindowPos (nWindows);
854 DeferWindowPos (dwp, GetDlgItem (g.hMain, IDC_SERVERS), NULL,
855 rServers.left, rServers.top,
856 cxRECT(rServers), cyRECT(rServers),
857 SWP_NOACTIVATE | SWP_NOZORDER);
859 if (GetDlgItem (g.hMain, IDC_COVERDLG))
861 DeferWindowPos (dwp, GetDlgItem (g.hMain, IDC_COVERDLG), NULL,
862 rServers.left, rServers.top,
863 cxRECT(rServers), cyRECT(rServers),
864 SWP_NOACTIVATE | SWP_NOZORDER);
867 if (GetDlgItem (g.hMain, IDC_TABS))
869 DeferWindowPos (dwp, GetDlgItem (g.hMain, IDC_TABS), NULL,
870 rPreview.left, rPreview.top,
871 cxRECT(rPreview), cyRECT(rPreview),
872 SWP_NOACTIVATE | SWP_NOZORDER);
875 EndDeferWindowPos (dwp);
880 static LONG_PTR procServers = 0;
882 LRESULT CALLBACK Main_SubclassServersProc (HWND hServers, UINT msg, WPARAM wp, LPARAM lp)
884 LRESULT rc;
886 if (procServers == 0)
887 rc = DefWindowProc (hServers, msg, wp, lp);
888 else
889 rc = (LRESULT) CallWindowProc ((WNDPROC)procServers, hServers, msg, wp, lp);
891 switch (msg)
893 case WM_DESTROY:
894 if (procServers != 0)
895 SetWindowLongPtr (hServers, GWLP_WNDPROC, procServers);
896 break;
898 case WM_COMMAND:
899 switch (LOWORD(wp))
901 case M_SVR_VIEW_LARGE:
902 case M_SVR_VIEW_SMALL:
903 case M_SVR_VIEW_REPORT:
904 SendMessage (g.hMain, msg, wp, lp);
905 break;
907 case M_VIEW_ONEICON:
908 case M_VIEW_TWOICONS:
909 case M_VIEW_STATUS:
910 SendMessage (g.hMain, msg, wp, lp);
911 break;
913 case M_COLUMNS:
914 ShowColumnsDialog (g.hMain, NULL);
915 break;
917 default:
918 StartContextCommand (g.hMain,
919 NULL,
920 (LPIDENT)FL_GetSelectedData (hServers),
921 LOWORD(wp));
922 break;
924 break;
927 return rc;
931 void Main_SubclassServers (HWND hDlg)
933 HWND hServers = GetDlgItem (hDlg, IDC_SERVERS);
934 procServers = GetWindowLongPtr (hServers, GWLP_WNDPROC);
935 SetWindowLongPtr (hServers, GWLP_WNDPROC, (LONG_PTR)Main_SubclassServersProc);
939 #ifdef DEBUG
940 void ExportCell (void)
942 if (!g.lpiCell)
943 return;
945 TCHAR szFilter[ cchRESOURCE ];
946 lstrcpy (szFilter, TEXT("Text File|*.TXT|"));
947 TCHAR chFilter = szFilter[ lstrlen(szFilter)-1 ];
948 for (LPTSTR pszFilter = szFilter;
949 (*pszFilter) && ((pszFilter = (LPTSTR)lstrchr (pszFilter, chFilter)) != NULL);
950 ++pszFilter)
952 *pszFilter = TEXT('\0');
955 TCHAR szSaveAs[ MAX_PATH ] = TEXT("export");
957 OPENFILENAME sfn;
958 memset (&sfn, 0x00, sizeof(sfn));
959 sfn.lStructSize = sizeof(sfn);
960 sfn.hwndOwner = g.hMain;
961 sfn.hInstance = THIS_HINST;
962 sfn.lpstrFilter = szFilter;
963 sfn.nFilterIndex = 1;
964 sfn.lpstrFile = szSaveAs;
965 sfn.nMaxFile = MAX_PATH;
966 sfn.Flags = OFN_HIDEREADONLY | OFN_NOREADONLYRETURN |
967 OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST;
968 sfn.lpstrDefExt = TEXT("txt");
970 if (GetSaveFileName (&sfn))
972 LPTSTR psz = CloneString (szSaveAs);
973 StartTask (taskEXPORTCELL, NULL, psz);
976 #endif
979 void Main_StartWorking (void)
981 if (InterlockedIncrement(&nReqWorking) == 1)
983 AfsAppLib_StartAnimation (GetDlgItem (g.hMain, IDC_ANIMATE));
987 void Main_StopWorking (void)
989 if (InterlockedDecrement(&nReqWorking) == 0)
991 AfsAppLib_StopAnimation (GetDlgItem (g.hMain, IDC_ANIMATE));
996 void Main_AnimateIcon (HWND hIcon, int *piFrameLast)
998 static HICON hiStop;
999 static HICON hiFrame[8];
1000 static BOOL fLoaded = FALSE;
1002 if (!fLoaded)
1004 hiStop = TaLocale_LoadIcon (IDI_SPINSTOP);
1005 hiFrame[0] = TaLocale_LoadIcon (IDI_SPIN1);
1006 hiFrame[1] = TaLocale_LoadIcon (IDI_SPIN2);
1007 hiFrame[2] = TaLocale_LoadIcon (IDI_SPIN3);
1008 hiFrame[3] = TaLocale_LoadIcon (IDI_SPIN4);
1009 hiFrame[4] = TaLocale_LoadIcon (IDI_SPIN5);
1010 hiFrame[5] = TaLocale_LoadIcon (IDI_SPIN6);
1011 hiFrame[6] = TaLocale_LoadIcon (IDI_SPIN7);
1012 hiFrame[7] = TaLocale_LoadIcon (IDI_SPIN8);
1013 fLoaded = TRUE;
1016 if (piFrameLast)
1018 *piFrameLast = (*piFrameLast == 7) ? 0 : (1+*piFrameLast);
1021 SendMessage (hIcon, STM_SETICON, (WPARAM)((piFrameLast) ? hiFrame[ *piFrameLast ] : hiStop), 0);
1025 BOOL Main_HandleDialogKeys (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
1027 if (msg == WM_COMMAND)
1029 switch (LOWORD(wp))
1031 case M_KEY_RETURN:
1032 Server_OnKey_Return();
1033 return TRUE;
1035 case M_KEY_CTRLTAB:
1036 Main_OnKey_CtrlTab (TRUE);
1037 return TRUE;
1039 case M_KEY_CTRLBACKTAB:
1040 Main_OnKey_CtrlTab (FALSE);
1041 return TRUE;
1043 case M_KEY_TAB:
1044 Main_OnKey_Tab (TRUE);
1045 return TRUE;
1047 case M_KEY_BACKTAB:
1048 Main_OnKey_Tab (FALSE);
1049 return TRUE;
1051 case M_KEY_MENU:
1052 Server_OnKey_Menu();
1053 return TRUE;
1055 case M_KEY_ESC:
1056 Server_OnKey_Esc();
1057 return TRUE;
1059 case M_KEY_PROPERTIES:
1060 Server_OnKey_Properties();
1061 return TRUE;
1065 return FALSE;
1069 void Main_OnKey_Tab (BOOL fForward)
1071 // The tab-cycle should go:
1072 // ServerList <-> TabsOnQuickViewPane <-> TabChildControls
1074 // If the quick-view pane isn't showing, there's nowhere to tab to.
1076 if (gr.fPreview)
1078 HWND hFocus = GetFocus();
1079 HWND hTabChild = GetTabChild (GetDlgItem (g.hMain, IDC_TABS));
1081 if (fForward)
1083 if (hFocus == GetDlgItem (g.hMain, IDC_SERVERS))
1085 PostMessage (g.hMain, WM_NEXTDLGCTL, (WPARAM)GetDlgItem (g.hMain, IDC_TABS), TRUE);
1087 else if (hFocus == GetDlgItem (g.hMain, IDC_TABS))
1089 PostMessage (g.hMain, WM_NEXTDLGCTL, (WPARAM)GetNextDlgTabItem (hTabChild, NULL, FALSE), TRUE);
1091 else
1093 if (GetNextDlgTabItem (hTabChild, hFocus, FALSE) == GetNextDlgTabItem (hTabChild, NULL, FALSE))
1094 PostMessage (g.hMain, WM_NEXTDLGCTL, (WPARAM)GetDlgItem (g.hMain, IDC_SERVERS), TRUE);
1095 else
1096 PostMessage (g.hMain, WM_NEXTDLGCTL, (WPARAM)GetNextDlgTabItem (hTabChild, hFocus, FALSE), TRUE);
1099 else // (!fForward)
1101 if (hFocus == GetDlgItem (g.hMain, IDC_SERVERS))
1103 PostMessage (g.hMain, WM_NEXTDLGCTL, (WPARAM)GetLastDlgTabItem (hTabChild), TRUE);
1105 else if (hFocus == GetDlgItem (g.hMain, IDC_TABS))
1107 PostMessage (g.hMain, WM_NEXTDLGCTL, (WPARAM)GetDlgItem (g.hMain, IDC_SERVERS), TRUE);
1109 else
1111 if (hFocus == GetNextDlgTabItem (hTabChild, NULL, FALSE))
1112 PostMessage (g.hMain, WM_NEXTDLGCTL, (WPARAM)GetDlgItem (g.hMain, IDC_TABS), TRUE);
1113 else
1114 PostMessage (g.hMain, WM_NEXTDLGCTL, (WPARAM)GetNextDlgTabItem (hTabChild, hFocus, TRUE), TRUE);
1121 void Main_OnKey_CtrlTab (BOOL fForward)
1123 if (gr.fPreview)
1125 Server_OnKey_CtrlTab (SERVERWINDOW_PREVIEWPANE, fForward);