Main Page   File List   Globals  

eclipselauncher.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2002 Ingo Richter and others.
00003  * All rights reserved.   This program and the accompanying materials
00004  * are made available under the terms of the Common Public License v1.0
00005  * which accompanies this distribution, and is available at
00006  * http://www.eclipse.org/legal/cpl-v10.html
00007  * 
00008  * Contributors:
00009  *    Ingo Richter - Initial implementation.
00010  */
00011 #define strict
00012 
00013 #include <windows.h>
00014 #include <windowsx.h>
00015 #include <commctrl.h>
00016 #include <string.h>
00017 #include "resource.h"
00018 
00019 #include <assert.h>
00020 
00021 #include "persistent.h"
00022 #include "eclipselauncher.h"
00023 #include "launcherconfig.h"
00024 #include "clipboard.h"
00025 #include "changeConfigurationDialog.h"
00026 #include "utils.h"
00027 
00028 /* prototype for the dialog box function. */
00029 LRESULT MainDialogWindowProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
00030 
00031 /* Event Handler */
00032 BOOL OnInitializeApp(HWND hDlg, HWND wParam, LPARAM lParam);
00033 BOOL OnExitApp(HWND hDlg);
00034 BOOL OnCommandHelper(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify);
00035 void OnDeleteConfiguration(HWND hwnd);
00036 int OnAddNewConfiguration(HWND hwnd);
00037 int OnEditNewConfiguration(HWND hwnd);
00038 void OnLeftButtonDoubleClick(HWND hwnd, BOOL what, int x, int y, UINT keyFlags);
00039 void OnSize(HWND hDialog, int type, int notused1, int notused2);
00040 
00041 //extern BOOL gConfigChanged = FALSE;
00042 static WNDPROC gOldListViewWindowProc;
00043 static HWND ghMainDialog;
00044 static BOOL gSendToTray = FALSE;
00045 
00046 // Tray Data
00047 static NOTIFYICONDATA gNotifyIconData;
00048 static HMENU ghTrayMenu;
00049 
00050 #define HEADER_CONFIGURATION_NAME   "Configuration Name"
00051 #define HEADER_WORKSPACE_PATH       "Workspace Directory"
00052 #define HEADER_VMPARAMETER          "VM Parameter"
00053 #define HEADER_JAVAVM               "Java VM"
00054 
00055 TCHAR* headerLabel[] = { HEADER_CONFIGURATION_NAME, HEADER_WORKSPACE_PATH, HEADER_JAVAVM, HEADER_VMPARAMETER };
00056 int headerLabelSize[] = { 150, 150, 150, 150 };
00057 
00065 int APIENTRY WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR lpCmdLine, int nCmdShow)
00066 {
00067     TCHAR appName[APPNAME_BUFFER_SIZE] = {0};
00068     HWND hDialog;
00069     MSG msg;
00070     WNDCLASS wc;
00071 
00072     memset(&wc, 0, sizeof(wc));
00073     wc.lpfnWndProc = DefDlgProc;
00074     wc.cbWndExtra = DLGWINDOWEXTRA;
00075     wc.hInstance = hinst;
00076     wc.hIcon = LoadIcon(NULL, MAKEINTRESOURCE(IDI_ECLIPSELAUNCHER));
00077     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
00078     wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
00079     wc.lpszClassName = LocString(IDS_APPNAME, appName);
00080     RegisterClass(&wc);
00081 
00082     hDialog = CreateDialog(hinst, MAKEINTRESOURCE(IDD_MAINDIALOG_NOBUTTONS), NULL, (DLGPROC) MainDialogWindowProc);
00083     ListView_SetExtendedListViewStyleEx(GetDlgItem(hDialog, ID_CONFIGLIST), LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP /*| LVS_EX_GRIDLINES*/, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP /*| LVS_EX_GRIDLINES*/);
00084     if(!hDialog)
00085     {
00086         TCHAR buf[BUFFERSIZE_256];
00087         wsprintf(buf, "Error %ld", GetLastError());
00088         MessageBox(0, buf, "CreateDialog", MB_ICONEXCLAMATION | MB_OK);
00089         return 1;
00090     }
00091 
00092     while (GetMessage(&msg, NULL, 0, 0))
00093     {
00094         if (!IsDialogMessage(hDialog, &msg))
00095         {
00096             TranslateMessage(&msg);
00097             DispatchMessage(&msg);
00098         }
00099     }
00100 
00101     return msg.wParam;
00102 
00103 /*  return DialogBox(hinst, MAKEINTRESOURCE(IDD_MAINDIALOG_NOBUTTONS), NULL, (DLGPROC) MainDialogWindowProc); */
00104 }
00105 
00106 /*
00107  * Describe here
00108  * @param lpSubkey
00109  * @param lpClass
00110  * @param lpData
00111  */
00112 LPLAUNCHERCONFIG hitTestForLauncherConfig(HWND hwnd, int x, int y)
00113 {
00114     LPLAUNCHERCONFIG launcherConfig = NULL;
00115     int listEntryPosition;
00116 
00117     LV_HITTESTINFO hitTest = {0};
00118     hitTest.pt.x = x;
00119     hitTest.pt.y = y;
00120     hitTest.flags = LVHT_ONITEM;
00121 
00122     listEntryPosition = ListView_HitTest(hwnd, &hitTest);
00123 
00124     if(listEntryPosition != (-1))
00125     {
00126         // select the Entry before determinig the active configuration
00127         ListView_SetItemState(hwnd, listEntryPosition, LVIS_SELECTED | LVIS_FOCUSED, 0xffff);
00128         launcherConfig = getLauncherConfig(hwnd, listEntryPosition);
00129     }
00130 
00131     return(launcherConfig);
00132 }
00133 
00134 /*
00135  * Describe here
00136  * @param lpSubkey
00137  * @param lpClass
00138  * @param lpData
00139  */
00140 void showPopupMenu(HMENU hMenu, HWND hMainWindow)
00141 {
00142     POINT cursorPos;
00143     GetCursorPos(&cursorPos);
00144 
00145     // PRB: Menus for Notification Icons Don't Work Correctly
00146     SetForegroundWindow(hMainWindow);
00147     TrackPopupMenu(hMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON, cursorPos.x, cursorPos.y, 0, hMainWindow, NULL);
00148     PostMessage(hMainWindow, WM_NULL, 0, 0);
00149 }
00150 
00151 //int OnRightButtonDown(HWND hwnd, int x, int y, UINT flags)
00152 /*
00153  * Describe here
00154  * @param lpSubkey
00155  * @param lpClass
00156  * @param lpData
00157  */
00158 int OnRightButtonDown(HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlags)
00159 {
00160     POINT cursorPos;
00161     HMENU hContextMenu;
00162     TCHAR* locbuffer = (TCHAR*) malloc(256);
00163 
00164     LPLAUNCHERCONFIG launcherConfig = hitTestForLauncherConfig(hwnd, x, y);
00165 
00166     hContextMenu = CreatePopupMenu();
00167 
00168     if(launcherConfig != NULL)
00169     {
00170         TCHAR buffer[BUFFERSIZE_256] = {0};
00171 
00172         wsprintf(buffer, LocString(IDS_POPUP_EDIT_CONFIGURATION, locbuffer), getName(launcherConfig));
00173         AppendMenu(hContextMenu, MF_STRING, (UINT) IDM_EDITCONFIGURATION, 
00174             buffer); 
00175 
00176         wsprintf(buffer, LocString(IDS_POPUP_DUPLICATE_CONFIGURATION, locbuffer), getName(launcherConfig));
00177         AppendMenu(hContextMenu, MF_STRING, (UINT) IDM_DUPLICATECONFIGURATION, 
00178             buffer); 
00179 
00180         AppendMenu(hContextMenu, MF_MENUBREAK, (UINT) 0, 
00181             NULL); 
00182 
00183         wsprintf(buffer, LocString(IDS_POPUP_DELETE_CONFIGURATION, locbuffer), getName(launcherConfig));
00184         AppendMenu(hContextMenu, MF_STRING, (UINT) IDM_DELETECONFIGURATION, 
00185             buffer);
00186     }
00187     else
00188     {
00189         AppendMenu(hContextMenu, MF_STRING, (UINT) IDM_ADDCONFIGURATION, 
00190             LocString(IDS_POPUP_ADD_NEW_CONFIGURATION, locbuffer)); 
00191     }
00192 
00193     GetCursorPos(&cursorPos);
00194     TrackPopupMenu(hContextMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON, cursorPos.x, cursorPos.y, 0, ghMainDialog, NULL);
00195 
00196     free(locbuffer);
00197 
00198     return(1);
00199 }
00200 
00201 /*
00202  * Locate an Environment Variable, expand them and create a new String with the Value of the
00203  * expanded Variable.
00204  * Supports only "ONE" Environment Variable at the Moment!!!
00205  * First Version! Needs to be improved!
00206  */
00207 TCHAR* expandEnvironmentVariable(TCHAR* stringToExpand, TCHAR* newBuffer, int bufferSize)
00208 {
00209     TCHAR* startEnvironmentVariable = NULL;
00210     assert(stringToExpand != NULL);
00211 
00212     startEnvironmentVariable = strchr(stringToExpand, '%');
00213     if (startEnvironmentVariable != NULL)
00214     {
00215         int startIndex = startEnvironmentVariable - stringToExpand + 1;
00216 
00217         TCHAR* endEnvironmentVariable = strrchr(stringToExpand, '%');
00218         if (endEnvironmentVariable != NULL)
00219         {
00220             int endIndex = endEnvironmentVariable - stringToExpand + 1;
00221 
00222             TCHAR environmentVariableName[BUFFERSIZE_512] = {0};
00223             TCHAR environmentVariableValue[BUFFERSIZE_512] = {0};
00224 
00225             strncpy(environmentVariableName, stringToExpand + startIndex, endIndex - startIndex - 1);
00226             GetEnvironmentVariable(environmentVariableName, environmentVariableValue, 512);
00227 
00228             lstrcpyn(newBuffer, stringToExpand, startIndex);
00229             strcat(newBuffer, environmentVariableValue);
00230             strcat(newBuffer, stringToExpand + endIndex);
00231         }
00232     }
00233     else /* nothing found */
00234     {
00235         lstrcpyn(newBuffer, stringToExpand, bufferSize);
00236     }
00237 
00238     return newBuffer;
00239 }
00240 
00241 /*
00242  * Describe here
00243  * @param lpSubkey
00244  * @param lpClass
00245  * @param lpData
00246  */
00247 void executeLaunchConfiguration(LPLAUNCHERCONFIG launcherConfiguration)
00248 {
00249     int CMDLineLength = 4096;
00250     TCHAR* commandline = (TCHAR*)malloc(CMDLineLength);
00251     ZeroMemory(commandline, CMDLineLength);
00252 
00253     assert(launcherConfiguration != NULL);
00254 
00255     if(lstrlen(getWorkspacePath(launcherConfiguration)) > 0)
00256     {
00257         TCHAR tempBuffer[BUFFERSIZE_512] = {0};
00258         wsprintf(commandline, "%s %s %s %s", expandEnvironmentVariable(getExecutablePath(launcherConfiguration), tempBuffer, 512), 
00259                                             "-showlocation -data", 
00260                                             getWorkspacePath(launcherConfiguration),
00261                                             getOptionalParameter(launcherConfiguration));
00262     }
00263     else
00264     {
00265         TCHAR tempBuffer[BUFFERSIZE_512] = {0};
00266         wsprintf(commandline, "%s %s %s", expandEnvironmentVariable(getExecutablePath(launcherConfiguration), tempBuffer, 512),
00267                                         "-showlocation",
00268                                         getOptionalParameter(launcherConfiguration));
00269     }
00270 
00271     if(lstrlen(getJavaVM(launcherConfiguration)) > 0)
00272     {
00273         TCHAR tempBuffer[BUFFERSIZE_512 * 2] = {0};
00274         wsprintf(tempBuffer, " -vm %s", getJavaVM(launcherConfiguration));
00275         lstrcat(commandline, tempBuffer);
00276     }
00277 
00278     if(lstrlen(getVMParameter(launcherConfiguration)) > 0)
00279     {
00280         TCHAR tempBuffer[BUFFERSIZE_512 * 2] = {0};
00281         wsprintf(tempBuffer, " -vmargs %s", getVMParameter(launcherConfiguration));
00282         lstrcat(commandline, tempBuffer);
00283     }
00284 
00285     ShowWindow(ghMainDialog, SW_HIDE);
00286 
00287     // >31 means success!
00288     if(WinExec(commandline, SW_SHOW) > 31)
00289     {
00290 //      launcherConfiguration->isCurrentlyRunning = TRUE;
00291     }
00292     else
00293     {
00294         TCHAR messageBuffer[BUFFERSIZE_512] = {0};
00295         TCHAR locString[BUFFERSIZE_256] = {0};
00296         wsprintf(messageBuffer, "%s\n%s", LocString(IDS_ERROR_EXECUTING_CONFIGURATION, locString), commandline);
00297         MessageBox(ghMainDialog, messageBuffer, "Error during Execution", MB_ICONEXCLAMATION | MB_OK);
00298     }
00299 
00300     free(commandline);
00301 }
00302 
00303 /*
00304  * Describe here
00305  * @param lpSubkey
00306  * @param lpClass
00307  * @param lpData
00308  */
00309 void OnLeftButtonDoubleClick(HWND hwnd, BOOL what, int x, int y, UINT keyFlags)
00310 {
00311     LPLAUNCHERCONFIG launcherConfig = hitTestForLauncherConfig(hwnd, x, y);
00312 
00313     if(launcherConfig != NULL)
00314     {
00315         /* if the Control Key is pressed open to edit. */
00316         if((keyFlags & MK_CONTROL) == MK_CONTROL)
00317         {
00318             OnEditNewConfiguration(ghMainDialog);
00319         }
00320         else
00321         {
00322             executeLaunchConfiguration(launcherConfig);
00323         }
00324     }
00325 }
00326 
00330 void OnKeyPressed(HWND hwnd, UINT vk, BOOL fDown, int cRepeat, UINT flags)
00331 {
00332     switch(vk)
00333     {
00334         case VK_DELETE:
00335         {
00336             OnDeleteConfiguration(hwnd);
00337         }
00338         break;
00339 
00340         case VK_INSERT:
00341         {
00342             OnAddNewConfiguration(ghMainDialog);
00343         }
00344         break;
00345     }
00346 }
00347 
00352 LRESULT ListViewWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
00353 {
00354     switch (msg)
00355     {
00356         HANDLE_MSG(hwnd, WM_LBUTTONDBLCLK, OnLeftButtonDoubleClick);
00357         HANDLE_MSG(hwnd, WM_RBUTTONDOWN, OnRightButtonDown);
00358         HANDLE_MSG(hwnd, WM_KEYUP, OnKeyPressed);
00359     }
00360 
00361     return(CallWindowProc(gOldListViewWindowProc, hwnd, msg, wParam, lParam));
00362 }
00363 
00368 void setUpTrayIcon(HWND hDialog)
00369 {
00370     TCHAR buffer[BUFFERSIZE_256] = {0};
00371 
00372     ghTrayMenu = LoadMenu(getApplicationInstance(), MAKEINTRESOURCE(ID_TRAYMENU));
00373     
00374     gNotifyIconData.cbSize = sizeof(NOTIFYICONDATA);
00375     gNotifyIconData.hWnd = hDialog;
00376     gNotifyIconData.uID = 0;
00377     gNotifyIconData.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
00378     gNotifyIconData.uCallbackMessage = WM_USER;
00379     gNotifyIconData.hIcon = LoadImage(getApplicationInstance(), MAKEINTRESOURCE(IDI_ECLIPSELAUNCHER), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
00380     lstrcpy(gNotifyIconData.szTip, LocString(IDS_POPUP_ENABLE_HINT, buffer));
00381 
00382     Shell_NotifyIcon(NIM_ADD, &gNotifyIconData);
00383 }
00384 
00389 void setUpListViewHeader(HWND hDialog)
00390 {
00391     HWND hListBox;
00392     int headerCount;
00393     int headers = sizeof(headerLabel) / sizeof(headerLabel[0]);
00394     
00395     LV_COLUMN column = {0};
00396 
00397     column.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
00398     column.cx = 150;
00399     column.fmt = LVCFMT_LEFT;
00400 
00401     hListBox = GetDlgItem(hDialog, ID_CONFIGLIST);
00402 
00403     for(headerCount = 0; headerCount < headers; headerCount++)
00404     {
00405         column.pszText = headerLabel[headerCount];
00406         column.cx = headerLabelSize[headerCount];
00407         ListView_InsertColumn(hListBox, headerCount, &column);
00408     }
00409   }
00410 
00411 /*
00412 You should add your initialization code here. This function will be called
00413 when the dialog box receives the WM_INITDIALOG message.
00414 */
00415 BOOL OnInitializeApp(HWND hDlg, HWND wParam, LPARAM lParam)
00416 {
00417     TCHAR appNameVersion[BUFFERSIZE_256] = {0};
00418     TCHAR appName[APPNAME_BUFFER_SIZE] = {0};
00419     TCHAR appVersion[APPVERSION_BUFFER_SIZE] = {0};
00420 
00421     HWND hListBox = GetDlgItem(hDlg, ID_CONFIGLIST);
00422 
00423     wsprintf(appNameVersion, "%s %s", LocString(IDS_APPNAME, appName), LocString(IDS_APPVERSION, appVersion));
00424 
00425     setUpListViewHeader(hDlg);
00426     
00427     loadConfiguration(hListBox);
00428 
00429 /*  EnableWindow(GetDlgItem(hDlg, ID_EDITCONFIGURATION), FALSE);
00430     EnableWindow(GetDlgItem(hDlg, ID_DELETECONFIG), FALSE);
00431 */
00432     gOldListViewWindowProc = (WNDPROC)GetWindowLong(hListBox, GWL_WNDPROC);
00433     SetWindowLong(hListBox, GWL_WNDPROC, (LONG)ListViewWindowProc);
00434 
00435     SetWindowText(hDlg, appNameVersion);
00436 
00437     setUpTrayIcon(hDlg);
00438 
00439     ShowWindow(hDlg, SW_HIDE);
00440 
00441     return TRUE;
00442 }
00443 
00448 BOOL OnExitApp(HWND hDlg)
00449 {
00450     // Remove from tray
00451     Shell_NotifyIcon(NIM_DELETE, &gNotifyIconData);
00452 
00453     disposeAllConfigurations(GetDlgItem(hDlg, ID_CONFIGLIST));
00454 
00455     DestroyMenu(ghTrayMenu);
00456 
00457     EndDialog(hDlg,0);
00458     return TRUE;
00459 }
00460 
00461 /*
00462  * Delete the Configuration that is currently selected in hListBox.
00463  */
00464 void OnDeleteConfiguration(HWND hListBox)
00465 {
00466     int currentSelection = getCurrentSelection(hListBox);
00467     if(currentSelection != LB_ERR)
00468     {
00469         LPLAUNCHERCONFIG data = getLauncherConfig(hListBox, currentSelection);
00470         int result;
00471         TCHAR resString[STRINGBUFFER_SIZE];// = (TCHAR*)malloc(bufferSize);
00472         TCHAR message[STRINGBUFFER_SIZE];
00473         TCHAR dialogTitle[STRINGBUFFER_SIZE];
00474 
00475         wsprintf(message, LocString(IDS_REMOVE_CONFIGURATION, resString), getName(data));
00476 
00477         LocString(IDS_REMOVE_CONFIGURATION_TITLE, resString);
00478         wsprintf(dialogTitle, resString);
00479 
00480         result = MessageBox(NULL, message, dialogTitle, MB_YESNO);
00481         if(IDYES == result)
00482         {
00483             releaseLauncherConfig(data);
00484             ListView_DeleteItem(hListBox, currentSelection);
00485             saveConfiguration(hListBox);
00486         }
00487     }
00488 }
00489 
00494 void restoreWindow(HWND hWindow)
00495 {
00496     ShowWindow(hWindow, SW_SHOWNORMAL);
00497     SetForegroundWindow(hWindow);
00498 }
00499 
00500 
00505 BOOL OnCommandHelper(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
00506 {
00507     // we ignore all other Messages
00508     if (codeNotify == 0)
00509     {
00510         switch (id)
00511         {
00512             case IDCANCEL:
00513             {
00514                 EndDialog(hwnd, 0);
00515                 return 1;
00516             }
00517             break;
00518 
00519             case ID_TRAYEXIT:
00520             {
00521                 gSendToTray = FALSE;
00522                 EndDialog(hwnd,0);
00523                 SendMessage(hwnd, WM_DESTROY, 0, 0);
00524                 return TRUE;
00525             }
00526 
00527             case IDM_ADDCONFIGURATION:
00528             case ID_ADDCONFIGURATION:
00529             {
00530                 return(OnAddNewConfiguration(hwnd));
00531             }
00532 
00533             case IDM_EDITCONFIGURATION:
00534             case ID_EDITCONFIGURATION:
00535             {
00536                 return(OnEditNewConfiguration(hwnd));
00537             }
00538 
00539             case IDM_DUPLICATECONFIGURATION:
00540             {
00541                 HWND hListbox = GetDlgItem(hwnd, ID_CONFIGLIST);
00542                 OnDuplicateLaunchConfiguration(hListbox);
00543             }
00544             break;
00545 
00546             case IDM_DELETECONFIGURATION:
00547             case ID_DELETECONFIG:
00548             {
00549                 HWND hListBox = GetDlgItem(hwnd, ID_CONFIGLIST);
00550                 OnDeleteConfiguration(hListBox);
00551                 return TRUE;
00552             }
00553 
00554             case ID_RESTOREFROMTRAY:
00555             {
00556                 restoreWindow(hwnd);
00557             }
00558             break;
00559 
00560             case ID_ABOUT:
00561             {
00562                 TCHAR appAbout[BUFFERSIZE_512] = {0};
00563                 TCHAR appVersionString[BUFFERSIZE_512 * 2] = {0};
00564                 TCHAR appName[APPNAME_BUFFER_SIZE] = {0};
00565                 TCHAR appVersion[APPVERSION_BUFFER_SIZE] = {0};
00566 
00567                 LocString(APP_ABOUT, appAbout);
00568                 LocString(IDS_APPNAME, appName);
00569                 LocString(IDS_APPVERSION, appVersion);
00570                 
00571                 wsprintf(appVersionString, "%s %s\n%s", appName, appVersion, appAbout);
00572                 MessageBox(hwnd, appVersionString, "About EclipseLauncher", MB_OK | MB_ICONEXCLAMATION);
00573             }
00574             break;
00575 
00576             // this is to capture the Execute from the Tray popup Menu
00577             default:
00578             {
00579                 int launcherConfigNum = id - IDM_EXECUTECONFIGURATION;
00580                 LPLAUNCHERCONFIG launcherConfig = getLauncherConfig(GetDlgItem(hwnd, ID_CONFIGLIST), launcherConfigNum);
00581                 executeLaunchConfiguration(launcherConfig);
00582             }
00583         }
00584     }
00585 
00586     return TRUE;
00587 }
00588 
00589 void OnSize(HWND hDialog, int type, int notused1, int notused2)
00590 {
00591     if(type == SIZE_MINIMIZED)
00592     {
00593         ShowWindow(hDialog, SW_HIDE);
00594     }
00595 }
00596 
00597 BOOL OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct)
00598 {
00599     lpCreateStruct->style &= WS_MINIMIZE;
00600 
00601     return 0;
00602 }
00603 
00608 void OnSysCommand(HWND hDialog, UINT cmd, int x, int y)
00609 {
00610     if(cmd == SC_MINIMIZE || cmd == SC_CLOSE)
00611     {
00612         ShowWindow(hDialog, SW_HIDE);
00613         gSendToTray = TRUE;
00614     }
00615 }
00616 
00625 LRESULT MainDialogWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
00626 {
00627     static HWND editLabelControl;
00628     ghMainDialog = hwnd;
00629 
00630     switch (msg)
00631     {
00632         HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
00633         HANDLE_MSG(hwnd, WM_INITDIALOG, OnInitializeApp);
00634         HANDLE_MSG(hwnd, WM_COMMAND, OnCommandHelper);
00635         HANDLE_MSG(hwnd, WM_SYSCOMMAND, OnSysCommand);
00636         HANDLE_MSG(hwnd, WM_SIZE, OnSize);
00637 
00638         case WM_NOTIFY:
00639         {
00640             int idCtrl = (int) wParam; 
00641             LPNMHDR pnmh = (LPNMHDR) lParam;
00642             
00643             switch(pnmh->code)
00644             {
00645                 case LVN_BEGINLABELEDIT:
00646                 {
00647                     editLabelControl = ListView_GetEditControl(pnmh->hwndFrom);
00648                     return FALSE; /* allow editiing */
00649                 }
00650                 break;
00651 
00652                 case LVN_ENDLABELEDIT:
00653                 {
00654                     char text[255]="";
00655                     HWND hListView = pnmh->hwndFrom;
00656                     int iIndex = SendMessage(hListView, LVM_GETNEXTITEM, -1, LVNI_FOCUSED); // get selected item
00657                     LPLAUNCHERCONFIG data = getLauncherConfig(hListView, iIndex);
00658  
00659                     GetWindowText(editLabelControl, text, sizeof(text)); // get the text into a buffer              
00660                     setName(data, text, sizeof(text));
00661                     updateLauchnerConfig(hListView, data, iIndex);
00662                     saveConfiguration(hListView);
00663                 }
00664                 break;
00665 
00666                 case LVN_GETINFOTIP:
00667                 {
00668                     TCHAR* tempValue;
00669                     TCHAR buffer[BUFFERSIZE_512*2] = {0};
00670                     LPNMLVGETINFOTIP pGetInfoTip = (LPNMLVGETINFOTIP)lParam;
00671                     LPLAUNCHERCONFIG data = getLauncherConfig(pGetInfoTip->hdr.hwndFrom, pGetInfoTip->iItem);
00672                     
00673                     wsprintf(buffer, "Name:\t\t%s\nExecutable:\t%s", getName(data), getExecutablePath(data));
00674                     
00675                     tempValue = getJavaVM(data);
00676 
00677                     if (lstrlen(tempValue))
00678                     {
00679                         lstrcat(buffer, "\nJavaVM:\t");
00680                         lstrcat(buffer, tempValue);
00681                     }
00682 
00683                     tempValue = getWorkspacePath(data);
00684                     if (lstrlen(tempValue))
00685                     {
00686                         lstrcat(buffer, "\nWorkspace:\t");
00687                         lstrcat(buffer, tempValue);
00688                     }
00689 
00690                     tempValue = getOptionalParameter(data);
00691                     if (lstrlen(tempValue))
00692                     {
00693                         lstrcat(buffer, "\nParameter:\t");
00694                         lstrcat(buffer, tempValue);
00695                     }
00696 
00697                     tempValue = getVMParameter(data);
00698                     if (lstrlen(tempValue))
00699                     {
00700                         lstrcat(buffer, "\nVM Parameter:\t");
00701                         lstrcat(buffer, tempValue);
00702                     }
00703 
00704                     lstrcpy(pGetInfoTip->pszText, buffer);
00705                 }
00706             }
00707         }
00708         break;
00709 
00710         case WM_DESTROY:
00711         {
00712             if( gSendToTray != TRUE)
00713             {
00714                 OnExitApp(hwnd);
00715                 PostQuitMessage(0);
00716             }
00717         }
00718         break;
00719 /*
00720         case WM_MEASUREITEM:
00721         {
00722             SIZE size = {0};
00723 
00724             // Retrieve a device context for the main window.  
00725             HDC hdc = GetDC(hwnd); 
00726  
00727             // Retrieve pointers to the menu item's 
00728             // MEASUREITEMSTRUCT structure and MYITEM structure. 
00729  
00730             LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT) lParam; 
00731             LPLAUNCHERCONFIG launcherConfig = (LPLAUNCHERCONFIG) lpmis->itemData; 
00732  
00733             // check if we are already running
00734             if(launcherConfig->isCurrentlyRunning != FALSE)
00735             {
00736                 launcherConfig->isCurrentlyRunning = lockfileIsDeleteable(launcherConfig->workspacePath);
00737             }
00738 
00739             // Retrieve the width and height of the item's string, 
00740             // and then copy the width and height into the 
00741             // MEASUREITEMSTRUCT structure's itemWidth and 
00742             // itemHeight members. 
00743  
00744             GetTextExtentPoint32(hdc, launcherConfig->name, lstrlen(launcherConfig->name), &size); 
00745             lpmis->itemWidth = size.cx; 
00746             lpmis->itemHeight = size.cy; 
00747  
00748             ReleaseDC(hwnd, hdc); 
00749  
00750             return TRUE; 
00751         }
00752         break;
00753         
00754         case WM_DRAWITEM: 
00755         {
00756             COLORREF crText;
00757             COLORREF crBkgnd;
00758 
00759             int wCheckX;
00760             int nTextX;
00761             int nTextY;
00762             BOOL fSelected = FALSE;
00763 
00764             // Get pointers to the menu item's DRAWITEMSTRUCT 
00765             // structure and MYITEM structure. 
00766  
00767             LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) lParam; 
00768             LPLAUNCHERCONFIG launcherConfig = (LPLAUNCHERCONFIG) lpdis->itemData; 
00769  
00770             // If the user has selected the item, use the selected 
00771             // text and background colors to display the item. 
00772  
00773             if (lpdis->itemState & ODS_SELECTED)
00774             { 
00775                 crBkgnd = SetBkColor(lpdis->hDC, GetSysColor(COLOR_HIGHLIGHT)); 
00776                 fSelected = TRUE;
00777             } 
00778  
00779             if (launcherConfig->isCurrentlyRunning)
00780             {
00781                 crText = SetTextColor(lpdis->hDC, RGB(0xff,0x0,0x0)); 
00782             }
00783             
00784             // Remember to leave space in the menu item for the 
00785             // check-mark bitmap. Retrieve the width of the bitmap 
00786             // and add it to the width of the menu item. 
00787  
00788             wCheckX = GetSystemMetrics(SM_CXMENUCHECK); 
00789             nTextX = wCheckX + lpdis->rcItem.left; 
00790             nTextY = lpdis->rcItem.top; 
00791  
00792             // Select the font associated with the item into the 
00793             // item's device context, and then draw the string. 
00794  
00795 //            hfontOld = SelectObject(lpdis->hDC, pmyitem->hfont); 
00796             ExtTextOut(lpdis->hDC, nTextX, nTextY, ETO_OPAQUE, 
00797                 &lpdis->rcItem, launcherConfig->name, 
00798                 lstrlen(launcherConfig->name), NULL); 
00799  
00800             // Select the previous font back into the device 
00801             // context. 
00802  
00803 //            SelectObject(lpdis->hDC, hfontOld); 
00804  
00805             // Return the text and background colors to their 
00806             // normal state (not selected). 
00807  
00808             if (fSelected) 
00809             { 
00810 //                SetTextColor(lpdis->hDC, crText); 
00811                 SetBkColor(lpdis->hDC, crBkgnd); 
00812             } 
00813  
00814             return TRUE; 
00815         }
00816         break;
00817 */
00818         case WM_USER:
00819         {
00820             switch(lParam)
00821             {
00822                 // @TODO: Make this configurable for the user. Allow the User to enable the Popup on Right or left clicks.
00823                 case WM_RBUTTONUP:
00824                 {
00825                     HWND hConfigList = GetDlgItem(hwnd, ID_CONFIGLIST);
00826                     int configurationCount = getConfigurationCount(hConfigList); 
00827                     HMENU hSubMenu = GetSubMenu(ghTrayMenu, 0);
00828                     LPLAUNCHERCONFIG launcherConfig;
00829 
00830                     int configurationNum;
00831                     int menuItemCount = GetMenuItemCount(hSubMenu);
00832                     int itemCount;
00833                     int flags;
00834                     MENUITEMINFO menuiteminfo = {0};
00835                     menuiteminfo.cbSize = sizeof(MENUITEMINFO);
00836                     menuiteminfo.fMask = MIIM_ID;
00837 
00838                     for(itemCount = 0; itemCount < menuItemCount; itemCount++)
00839                     {
00840                         // always get the 0th Element!
00841                         GetMenuItemInfo(hSubMenu, 0, TRUE, &menuiteminfo);
00842 
00843                         if(menuiteminfo.wID == (UINT)(IDM_EXECUTECONFIGURATION + itemCount))
00844                         {
00845                             DeleteMenu(hSubMenu, 0, MF_BYPOSITION);
00846                         }
00847 
00848                         if(menuiteminfo.wID == 9999)
00849                         {
00850                             DeleteMenu(hSubMenu, 0, MF_BYPOSITION);
00851                             break; // Now our Delimiter has marked the end...
00852                         }
00853                     }
00854                     
00855                     for(configurationNum = 0; configurationNum < configurationCount; configurationNum++)
00856                     {
00857                         launcherConfig = getLauncherConfig(hConfigList, configurationNum);
00858                         
00859 /*                      InsertMenu(hSubMenu, configurationNum, MF_BYPOSITION | MF_OWNERDRAW, (UINT) IDM_EXECUTECONFIGURATION + configurationNum, 
00860                             launcherConfig); 
00861 */
00862                         flags = MF_BYPOSITION;
00863 
00864                         if(! lockfileIsDeleteable(getWorkspacePath(launcherConfig)))
00865                         {
00866                             flags |= MF_CHECKED;
00867                         }
00868 
00869                         InsertMenu(hSubMenu, configurationNum, flags, (UINT) IDM_EXECUTECONFIGURATION + configurationNum, 
00870                             getName(launcherConfig));
00871                     }
00872 
00873                     InsertMenu(hSubMenu, configurationNum, MF_BYPOSITION, 9999, NULL); 
00874 
00875                     showPopupMenu(hSubMenu, hwnd);
00876 
00877                     return TRUE;
00878                 }
00879                 break;
00880 
00881                 case WM_LBUTTONDBLCLK:
00882                 {
00883                     restoreWindow(hwnd);
00884                     return TRUE;
00885                 }
00886                 break;
00887             }
00888         }
00889         break;
00890     }
00891 
00892     return FALSE;
00893 }
00894 
00895 int OnAddNewConfiguration(HWND hwnd)
00896 {
00897     return(DialogBoxParam(getApplicationInstance(),
00898                             MAKEINTRESOURCE(IDD_ADDCONFIGDLG),
00899                             hwnd,
00900                             (DLGPROC) HandleAddConfigurationDialogProc,
00901                             MAKELPARAM(NULL, GetDlgItem(hwnd, ID_CONFIGLIST))));
00902 }
00903 
00904 int OnEditNewConfiguration(HWND hwnd)
00905 {
00906     return(DialogBoxParam(getApplicationInstance(),
00907                             MAKEINTRESOURCE(IDD_ADDCONFIGDLG),
00908                             hwnd,
00909                             (DLGPROC) HandleEditConfigurationDialogProc,
00910                             MAKELPARAM(NULL, GetDlgItem(hwnd, ID_CONFIGLIST))));
00911 }
00912 
00913 /*
00914 BOOL CTestbed2Dlg::OnCommand(WPARAM wParam, LPARAM lParam) 
00915 {
00916    CString csURL;
00917 
00918    if (HIWORD(wParam) == STN_CLICKED)
00919    {
00920       if (LOWORD(wParam) == IDC_URL)
00921       {
00922          FromHandle ((HWND)lParam)->GetWindowText (csURL);
00923          ShellExecute (GetSafeHwnd(),
00924                        "open",
00925                        csURL,
00926                        NULL,
00927                        NULL,
00928                        SW_SHOWNORMAL);
00929          return TRUE;
00930       }
00931    }
00932    return (CDialog::OnCommand(wParam,lParam));
00933 }
00934 */

Generated on Sun Apr 6 13:49:02 2003 for EclipseLauncher by doxygen1.2.17