コード例 #1
0
int chooseProject(int index, char *desc) {
   if (index == 0) { // new project
      ::qstrncpy(description, desc, sizeof(description));
   }
   if (index > 0) {
      if (numProjectsGlobal > 1) {
         if (snapUpdateIDs[index - 1] > 0) {
            ::qstrncpy(description, desc, sizeof(description));               
            isSnapShotGlobal = 1;
         }
      }
      index = projects[index - 1];
   }

   //there is still some value in keeping these as they limit the
   //amount of traffic the client will generate to some extent
#ifdef DEBUG
   msg("   publish bits are 0x%s\n", formatOptVal(&userOpts.pub));
   msg("   subscribe bits are 0x%s\n", formatOptVal(&userOpts.sub));
#endif
   publish = userPublish = userOpts.pub.ll != 0;
   subscribe = userOpts.sub.ll != 0;
   //remember these as the current options
   setUserOpts(userOpts);
   return index;
}
コード例 #2
0
ファイル: collabreate_ui.cpp プロジェクト: XVilka/htools
//The global projectBuffer pointer should be initialized to point to 
//the incoming buffer that contains the project list to be displayed in
//the project list dialog PRIOR to calling DialogBox
BOOL CALLBACK ProjectDlgProc(HWND hwndDlg, UINT message,
                             WPARAM wParam, LPARAM lParam) {
   switch (message) {
      case WM_INITDIALOG: {
         int numProjects = projectBuffer->readInt();
         numProjectsGlobal = numProjects;
         
         projects = (int*)qalloc(numProjects * sizeof(int));
         snapUpdateIDs = (unsigned long long*)qalloc(numProjects * sizeof(unsigned long long));
         optMasks = (Options*)qalloc(numProjects * sizeof(Options));
         
         SetDlgItemText(hwndDlg, IDC_PROJECT_LIST, "");
         SetDlgItemText(hwndDlg, IDC_DESCRIPTION, "");
         //the New project is always listed as the first option
         SendDlgItemMessage(hwndDlg, IDC_PROJECT_LIST, CB_ADDSTRING, (WPARAM)0, (LPARAM)"<New project>");
         for (int i = 0; i < numProjects; i++) {
            projects[i] = projectBuffer->readInt();
            snapUpdateIDs[i] = projectBuffer->readLong();
            //if (snapUpdateIDs[i] > 0 ) {
            //   msg(PLUGIN_NAME": project %d is a snapshot\n", i+1);
            //}
            char *desc = projectBuffer->readUTF8();
            int isSnapShot = 0;
            if ( snapUpdateIDs[i] !=0 ) {
               isSnapShot = 1;
            }
            #if DEBUG
               msg(PLUGIN_NAME": %d : %d - %s (%d) ", i, projects[i], desc, isSnapShot);
            #endif
            SendDlgItemMessage(hwndDlg, IDC_PROJECT_LIST, CB_ADDSTRING, (WPARAM)0, (LPARAM)desc);
            qfree(desc);
            
            //need to read options mask for this project
            //but for now everything is enabled
            //memset(optMasks + i, 0xFF, sizeof(Options));
            optMasks[i].pub = projectBuffer->readLong();
            optMasks[i].sub = projectBuffer->readLong();
            #if DEBUG
               msg(PLUGIN_NAME": P %x  S %x \n", (unsigned int)optMasks[i].pub, (unsigned int)optMasks[i].sub);
            #endif
         }
         int numOptions = projectBuffer->readInt();
         numOptionsGlobal = numOptions;

         optLabels = (char**)qalloc(numOptions * sizeof(char*));
         for (int i = 0; i < numOptions; i++) {
            optLabels[i] = projectBuffer->readUTF8();
         }

         CheckDlgButton(hwndDlg, IDC_PUBLISH, BST_CHECKED);
         CheckDlgButton(hwndDlg, IDC_SUBSCRIBE, BST_CHECKED);
         return TRUE;
      }
      case WM_COMMAND: {
         switch (LOWORD(wParam)) {
            case IDOK: {//OK Button
               int selected = SendDlgItemMessage(hwndDlg, IDC_PROJECT_LIST, CB_GETCURSEL, 0, 0);
               if (selected != LB_ERR) {
                  if (selected != 0) {
                     if (numProjectsGlobal > 1) {
                        if (snapUpdateIDs[selected - 1] > 0) {
                           GetDlgItemText(hwndDlg, IDC_DESCRIPTION, description, sizeof(description));
                           isSnapShotGlobal = 1;
                        }
                     }
                     selected = projects[selected - 1];
                  }
                  else { // selected == 0, new project
                     GetDlgItemText(hwndDlg, IDC_DESCRIPTION, description, sizeof(description));
                  }
               }
               else {
                  selected = -1;
               }
               //there is still some value in keeping these as they limit the
               //amount of traffic the client will generate to some extent
               publish = userOpts.pub != 0;
               subscribe = userOpts.sub != 0;
               //remember these as the current options
               setUserOpts(userOpts);
//               publish = IsDlgButtonChecked(hwndDlg, IDC_PUBLISH) == BST_CHECKED;
//               subscribe = IsDlgButtonChecked(hwndDlg, IDC_SUBSCRIBE) == BST_CHECKED;
               EndDialog(hwndDlg, selected);
               return TRUE;
            }
            case IDCANCEL: { //Cancel Button
               EndDialog(hwndDlg, -1);
               return TRUE;
            }
            case IDC_PROJECT_LIST: {
               if (HIWORD(wParam) == CBN_SELCHANGE) {
                  int selected = SendDlgItemMessage(hwndDlg, IDC_PROJECT_LIST, CB_GETCURSEL, 0, 0);
                  HWND desc = GetDlgItem(hwndDlg, IDC_DESCRIPTION);
                  if (selected == 0) {   //New project
                     //enable all persmissions for new projects
                     memset(&userOpts, 0xFF, sizeof(userOpts));
                     //enable description control for new projects
                     EnableWindow(desc, TRUE);
                  }
//                  else if (numProjectsGlobal > 1) {
                  else if (numProjectsGlobal > 0) {
                     if (snapUpdateIDs[selected - 1] != 0) {
                        //enable all persmissions for new projects
                        memset(&userOpts, 0xFF, sizeof(userOpts));
                        EnableWindow(desc, TRUE);
                     }
                     else {
                        userOpts = optMasks[selected - 1];
                        EnableWindow(desc, FALSE);
                     }
                  }
                  else {
                     //unreachable?
                     msg(PLUGIN_NAME": unkown desc window state entered, please tell developers\n");
                     EnableWindow(desc, FALSE);
                  }
                  return TRUE;
               }
               break;
            }
            case IDC_OPTIONS: {
               #if DEBUG
                  msg(PLUGIN_NAME": calling showOptionsDlg\n");
               #endif
               showOptionsDlg(hwndDlg, optLabels, numOptionsGlobal, &userOpts, &userOpts, &userOpts);
               return TRUE;
            }
         }
      }
   }
   return FALSE;
}