예제 #1
0
파일: person~2.cpp 프로젝트: mingpen/OpenNT
void CDialogTrustDB::RefreshTrustList()
    {
    //
    // Remove all the entries presently in the trust list and on the display
    //
    FreeTrustList();
    HWND hwndList = WindowOf(IDC_TRUSTLIST);
    ::SendMessage(hwndList, LB_RESETCONTENT, 0, 0);
    EnableWindow(WindowOf(IDC_TRUSTREMOVE), FALSE);

    //
    // Populate our listbox with the current list of trusted publishers
    //
    if (m_pdb->GetTrustList(1, TRUE, &m_rgTrust, &m_cTrust) == S_OK)
        {
        //
        // Sort the trust entries alphabetically
        //
        qsort(m_rgTrust, m_cTrust, sizeof(TRUSTLISTENTRY), CompareTrustListEntries);

        //
        // Add them to the list box
        //
        for (ULONG i=0; i < m_cTrust; i++)
            {
            ::SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)(LPCSTR) &m_rgTrust[i].szDisplayName);
            }

        EnableWindow(WindowOf(IDC_TRUSTREMOVE), m_cTrust > 0);
        }
    }
예제 #2
0
파일: fscale.c 프로젝트: dyne/MuSE
/*
 * This moves the scale field to the given location.
 */
static void _moveCDKFScale (CDKOBJS *object, int xplace, int yplace, boolean relative, boolean refresh_flag)
{
   CDKFSCALE *scale = (CDKFSCALE *)object;
   /* Declare local variables. */
   int currentX = getbegx(scale->win);
   int currentY = getbegy(scale->win);
   int xpos	= xplace;
   int ypos	= yplace;
   int xdiff	= 0;
   int ydiff	= 0;

   /*
    * If this is a relative move, then we will adjust where we want
    * to move to.
    */
   if (relative)
   {
      xpos = getbegx(scale->win) + xplace;
      ypos = getbegy(scale->win) + yplace;
   }

   /* Adjust the window if we need to. */
   alignxy (WindowOf(scale), &xpos, &ypos, scale->boxWidth, scale->boxHeight);

   /* Get the difference. */
   xdiff = currentX - xpos;
   ydiff = currentY - ypos;

   /* Move the window to the new location. */
   moveCursesWindow(scale->win, -xdiff, -ydiff);
   if (scale->labelWin != 0)
   {
      moveCursesWindow(scale->labelWin, -xdiff, -ydiff);
   }
   moveCursesWindow(scale->fieldWin, -xdiff, -ydiff);

   /* If there is a shadow box we have to move it too. */
   if (scale->shadowWin != 0)
   {
      moveCursesWindow(scale->shadowWin, -xdiff, -ydiff);
   }

   /* Touch the windows so they 'move'. */
   touchwin (WindowOf(scale));
   wrefresh (WindowOf(scale));

   /* Redraw the window, if they asked for it. */
   if (refresh_flag)
   {
      drawCDKFScale (scale, ObjOf(scale)->box);
   }
}
예제 #3
0
파일: alphalist.c 프로젝트: dyne/MuSE
/*
 * This moves the alphalist field to the given location.
 */
static void _moveCDKAlphalist (CDKOBJS *object, int xplace, int yplace, boolean relative, boolean refresh_flag)
{
   CDKALPHALIST *alphalist = (CDKALPHALIST *)object;

   /* Declare local variables. */
   int currentX = getbegx(alphalist->win);
   int currentY = getbegy(alphalist->win);
   int xpos	= xplace;
   int ypos	= yplace;
   int xdiff	= 0;
   int ydiff	= 0;

   /*
    * If this is a relative move, then we will adjust where we want
    * to move to.
    */
   if (relative)
   {
      xpos = getbegx(alphalist->win) + xplace;
      ypos = getbegy(alphalist->win) + yplace;
   }

   /* Adjust the window if we need to. */
   alignxy (WindowOf(alphalist), &xpos, &ypos, alphalist->boxWidth, alphalist->boxHeight);

   /* Get the difference. */
   xdiff = currentX - xpos;
   ydiff = currentY - ypos;

   /* Move the window to the new location. */
   moveCursesWindow(alphalist->win, -xdiff, -ydiff);

   /* If there is a shadow box we have to move it too. */
   if (alphalist->shadowWin != 0)
   {
      moveCursesWindow(alphalist->shadowWin, -xdiff, -ydiff);
   }

   /* Move the sub-widgets. */
   moveCDKEntry (alphalist->entryField, xplace, yplace, relative, FALSE);
   moveCDKScroll (alphalist->scrollField, xplace, yplace, relative, FALSE);

   /* Touch the windows so they 'move'. */
   touchwin (WindowOf(alphalist));
   wrefresh (WindowOf(alphalist));

   /* Redraw the window, if they asked for it. */
   if (refresh_flag)
   {
      drawCDKAlphalist (alphalist, ObjOf(alphalist)->box);
   }
}
예제 #4
0
파일: scroll.c 프로젝트: Chaduke/bah.mod
/*
 * This moves the scroll field to the given location.
 */
static void _moveCDKScroll (CDKOBJS *object,
			    int xplace,
			    int yplace,
			    boolean relative,
			    boolean refresh_flag)
{
   /* *INDENT-EQLS* */
   CDKSCROLL *scrollp = (CDKSCROLL *)object;
   int currentX       = getbegx (scrollp->win);
   int currentY       = getbegy (scrollp->win);
   int xpos           = xplace;
   int ypos           = yplace;
   int xdiff          = 0;
   int ydiff          = 0;

   /*
    * If this is a relative move, then we will adjust where we want
    * to move to.
    */
   if (relative)
   {
      xpos = getbegx (scrollp->win) + xplace;
      ypos = getbegy (scrollp->win) + yplace;
   }

   /* Adjust the window if we need to. */
   alignxy (WindowOf (scrollp), &xpos, &ypos, scrollp->boxWidth, scrollp->boxHeight);

   /* Get the difference. */
   xdiff = currentX - xpos;
   ydiff = currentY - ypos;

   /* Move the window to the new location. */
   moveCursesWindow (scrollp->win, -xdiff, -ydiff);
   moveCursesWindow (scrollp->listWin, -xdiff, -ydiff);
   moveCursesWindow (scrollp->shadowWin, -xdiff, -ydiff);
   moveCursesWindow (scrollp->scrollbarWin, -xdiff, -ydiff);

   /* Touch the windows so they 'move'. */
   refreshCDKWindow (WindowOf (scrollp));

   /* Redraw the window, if they asked for it. */
   if (refresh_flag)
   {
      drawCDKScroll (scrollp, ObjOf (scrollp)->box);
   }
}
예제 #5
0
파일: scale.c 프로젝트: lavenliu/linuxc
/*
 * This moves the widget's data field to the given location.
 */
static void _moveCDKScale (CDKOBJS *object,
                           int xplace,
                           int yplace,
                           boolean relative,
                           boolean refresh_flag)
{
    CDKSCALE *widget = (CDKSCALE *) object;
    int currentX = getbegx (widget->win);
    int currentY = getbegy (widget->win);
    int xpos = xplace;
    int ypos = yplace;
    int xdiff = 0;
    int ydiff = 0;

    /*
     * If this is a relative move, then we will adjust where we want
     * to move to.
     */
    if (relative)
    {
        xpos = getbegx (widget->win) + xplace;
        ypos = getbegy (widget->win) + yplace;
    }

    /* Adjust the window if we need to. */
    alignxy (WindowOf (widget), &xpos, &ypos, widget->boxWidth, widget->boxHeight);

    /* Get the difference. */
    xdiff = currentX - xpos;
    ydiff = currentY - ypos;

    /* Move the window to the new location. */
    moveCursesWindow (widget->win, -xdiff, -ydiff);
    moveCursesWindow (widget->labelWin, -xdiff, -ydiff);
    moveCursesWindow (widget->fieldWin, -xdiff, -ydiff);
    moveCursesWindow (widget->shadowWin, -xdiff, -ydiff);

    /* Touch the windows so they 'move'. */
    refreshCDKWindow (WindowOf (widget));

    /* Redraw the window, if they asked for it. */
    if (refresh_flag)
    {
        drawCDKScale (widget, ObjOf (widget)->box);
    }
}
예제 #6
0
파일: uisupp~1.cpp 프로젝트: mingpen/OpenNT
HBRUSH CBadTrustDialog::OnCtlColorEdit(HDC hdcEdit, HWND hwndEdit)
    {
    if (hwndEdit == WindowOf(IDC_BADTRUSTBANTER2))
        {
        SetBkColor(hdcEdit, GetSysColor(COLOR_BTNFACE));    // text background color
        return m_hbrBackground;                             // brush for edit control background
        }
    return NULL;
    }
예제 #7
0
파일: person~2.cpp 프로젝트: mingpen/OpenNT
void CDialogTrustDB::OnApplyNow()
    {
    //
    // Update the registry settings per the current commercial checkbox setting
    //
    m_pdb->SetCommercialPublishersTrust(
        ::SendMessage
                (
                WindowOf(IDC_TRUSTCOMMERCIAL), 
                BM_GETCHECK, 0, 0L
                ) == BST_CHECKED
        );
    }
예제 #8
0
파일: person~2.cpp 프로젝트: mingpen/OpenNT
void CDialogTrustDB::NoteIrrevocableChange()
//
// An irrevocable change has taken place in the UI. Note that
// as appropriate
//
    {
    if (!m_fPropertySheet)
        {
        // 
        // Change 'cancel' to 'close'
        //
        TCHAR sz[30];
        ::LoadString(hinst, IDS_CLOSE, &sz[0], 30);
        ::SetWindowText(WindowOf(IDCANCEL), sz);
        }
    }
예제 #9
0
파일: person~2.cpp 프로젝트: mingpen/OpenNT
void CDialogTrustDB::RemoveSelectedTrustEntries()
    {
    //
    // Remove from trust those items that are presently selected
    //
    HWND hwndList = WindowOf(IDC_TRUSTLIST);
    ULONG cSelected = ::SendMessage(hwndList, LB_GETSELCOUNT, 0, 0);
    if (cSelected > 0)
        {
        int* rgSelected = (int*)_alloca(cSelected * sizeof(int));
        ::SendMessage(hwndList, LB_GETSELITEMS, (WPARAM)cSelected, (LPARAM)(LPINT) rgSelected);
        //
        // rgSelected is an array of zero-origin indices into the sorted
        // list of trusted parties
        //
        for (ULONG i=0; i<cSelected; i++)
            {
            //
            // Remove the i'th entry from the trust database
            //
            int iSelected = rgSelected[i];
            m_pdb->RemoveTrustToken
                (
                &m_rgTrust[iSelected].szToken[0], 
                 m_rgTrust[iSelected].iLevel, 
                FALSE
                );
            }
        //
        // Update the display
        //
        RefreshTrustList();
        //
        // Note the change
        //
        NoteIrrevocableChange();
        }
    }
예제 #10
0
파일: button.c 프로젝트: Chaduke/bah.mod
/*
 * This allows the user to use the cursor keys to adjust the
 * position of the widget.
 */
void positionCDKButton (CDKBUTTON *button)
{
   /* Declare some variables. */
   int origX = getbegx (button->win);
   int origY = getbegy (button->win);
   chtype key = (chtype)0;
   boolean functionKey;

   /* Let them move the widget around until they hit return. */
   while (key != KEY_ENTER)
   {
      key = (chtype)getchCDKObject (ObjOf (button), &functionKey);
      if (key == KEY_UP || key == '8')
      {
	 if (getbegy (button->win) > 0)
	 {
	    moveCDKButton (button, 0, -1, TRUE, TRUE);
	 }
	 else
	 {
	    BEEP ();
	 }
      }
      else if (key == KEY_DOWN || key == '2')
      {
	 if (getbegy (button->win) + getmaxy (button->win) <
	     getmaxy (WindowOf (button)) - 1)
	 {
	    moveCDKButton (button, 0, 1, TRUE, TRUE);
	 }
	 else
	 {
	    BEEP ();
	 }
      }
      else if (key == KEY_LEFT || key == '4')
      {
	 if (getbegx (button->win) > 0)
	 {
	    moveCDKButton (button, -1, 0, TRUE, TRUE);
	 }
	 else
	 {
	    BEEP ();
	 }
      }
      else if (key == KEY_RIGHT || key == '6')
      {
	 if (getbegx (button->win) + getmaxx (button->win) < getmaxx
	     (WindowOf (button)) - 1)
	 {
	    moveCDKButton (button, 1, 0, TRUE, TRUE);
	 }
	 else
	 {
	    BEEP ();
	 }
      }
      else if (key == '7')
      {
	 if (getbegy (button->win) > 0 && getbegx (button->win) > 0)
	 {
	    moveCDKButton (button, -1, -1, TRUE, TRUE);
	 }
	 else
	 {
	    BEEP ();
	 }
      }
      else if (key == '9')
      {
	 if (getbegx (button->win) + getmaxx (button->win) < getmaxx
	     (WindowOf (button)) - 1 &&
	     getbegy (button->win) > 0)
	 {
	    moveCDKButton (button, 1, -1, TRUE, TRUE);
	 }
	 else
	 {
	    BEEP ();
	 }
      }
      else if (key == '1')
      {
	 if (getbegx (button->win) > 0 && getbegx (button->win) +
	     getmaxx (button->win) < getmaxx (WindowOf (button)) - 1)
	 {
	    moveCDKButton (button, -1, 1, TRUE, TRUE);
	 }
	 else
	 {
	    BEEP ();
	 }
      }
      else if (key == '3')
      {
	 if (getbegx (button->win) + getmaxx (button->win) <
	     getmaxx (WindowOf (button)) - 1
	     && getbegy (button->win) + getmaxy (button->win) <
	     getmaxy (WindowOf (button)) - 1)
	 {
	    moveCDKButton (button, 1, 1, TRUE, TRUE);
	 }
	 else
	 {
	    BEEP ();
	 }
      }
      else if (key == '5')
      {
	 moveCDKButton (button, CENTER, CENTER, FALSE, TRUE);
      }
      else if (key == 't')
      {
	 moveCDKButton (button, getbegx (button->win), TOP, FALSE, TRUE);
      }
      else if (key == 'b')
      {
	 moveCDKButton (button, getbegx (button->win), BOTTOM, FALSE, TRUE);
      }
      else if (key == 'l')
      {
	 moveCDKButton (button, LEFT, getbegy (button->win), FALSE, TRUE);
      }
      else if (key == 'r')
      {
	 moveCDKButton (button, RIGHT, getbegy (button->win), FALSE, TRUE);
      }
      else if (key == 'c')
      {
	 moveCDKButton (button, CENTER, getbegy (button->win), FALSE, TRUE);
      }
      else if (key == 'C')
      {
	 moveCDKButton (button, getbegx (button->win), CENTER, FALSE, TRUE);
      }
      else if (key == CDK_REFRESH)
      {
	 eraseCDKScreen (ScreenOf (button));
	 refreshCDKScreen (ScreenOf (button));
      }
      else if (key == KEY_ESC)
      {
	 moveCDKButton (button, origX, origY, FALSE, TRUE);
      }
      else if (key != KEY_ENTER)
      {
	 BEEP ();
      }
   }
}
예제 #11
0
파일: position.c 프로젝트: Chaduke/bah.mod
/*
 * This allows the user to use the cursor keys to adjust the
 * position of the widget.
 */
void positionCDKObject (CDKOBJS *obj, WINDOW *win)
{
   /* *INDENT-EQLS* */
   CDKSCREEN *screen = ScreenOf (obj);
   WINDOW *parent    = screen->window;
   int origX         = getbegx (win);
   int origY         = getbegy (win);
   int begX          = getbegx (parent);
   int begY          = getbegy (parent);
   int endX          = begX + getmaxx (WindowOf (obj));
   int endY          = begY + getmaxy (WindowOf (obj));

   chtype key;
   boolean functionKey;

   /* Let them move the widget around until they hit return. */
   while ((key = (chtype)getchCDKObject (obj, &functionKey)) != KEY_ENTER)
   {
      switch (key)
      {
      case KEY_UP:
      case '8':
	 if (getbegy (win) > begY)
	 {
	    moveCDKObject (obj, 0, -1, TRUE, TRUE);
	 }
	 else
	 {
	    BEEP ();
	 }
	 break;
      case KEY_DOWN:
      case '2':
	 if (getendy (win) < endY)
	 {
	    moveCDKObject (obj, 0, 1, TRUE, TRUE);
	 }
	 else
	 {
	    BEEP ();
	 }
	 break;
      case KEY_LEFT:
      case '4':
	 if (getbegx (win) > begX)
	 {
	    moveCDKObject (obj, -1, 0, TRUE, TRUE);
	 }
	 else
	 {
	    BEEP ();
	 }
	 break;
      case KEY_RIGHT:
      case '6':
	 if (getendx (win) < endX)
	 {
	    moveCDKObject (obj, 1, 0, TRUE, TRUE);
	 }
	 else
	 {
	    BEEP ();
	 }
	 break;
      case '7':
	 if (getbegy (win) > begY && getbegx (win) > begX)
	 {
	    moveCDKObject (obj, -1, -1, TRUE, TRUE);
	 }
	 else
	 {
	    BEEP ();
	 }
	 break;
      case '9':
	 if (getendx (win) < endX && getbegy (win) > begY)
	 {
	    moveCDKObject (obj, 1, -1, TRUE, TRUE);
	 }
	 else
	 {
	    BEEP ();
	 }
	 break;
      case '1':
	 if (getbegx (win) > begX && getendy (win) < endY)
	 {
	    moveCDKObject (obj, -1, 1, TRUE, TRUE);
	 }
	 else
	 {
	    BEEP ();
	 }
	 break;
      case '3':
	 if (getendx (win) < endX && getendy (win) < endY)
	 {
	    moveCDKObject (obj, 1, 1, TRUE, TRUE);
	 }
	 else
	 {
	    BEEP ();
	 }
	 break;
      case '5':
	 moveCDKObject (obj, CENTER, CENTER, FALSE, TRUE);
	 break;
      case 't':
	 moveCDKObject (obj, getbegx (win), TOP, FALSE, TRUE);
	 break;
      case 'b':
	 moveCDKObject (obj, getbegx (win), BOTTOM, FALSE, TRUE);
	 break;
      case 'l':
	 moveCDKObject (obj, LEFT, getbegy (win), FALSE, TRUE);
	 break;
      case 'r':
	 moveCDKObject (obj, RIGHT, getbegy (win), FALSE, TRUE);
	 break;
      case 'c':
	 moveCDKObject (obj, CENTER, getbegy (win), FALSE, TRUE);
	 break;
      case 'C':
	 moveCDKObject (obj, getbegx (win), CENTER, FALSE, TRUE);
	 break;
      case CDK_REFRESH:
	 eraseCDKScreen (ScreenOf (obj));
	 refreshCDKScreen (ScreenOf (obj));
	 break;
      case KEY_ESC:
	 moveCDKObject (obj, origX, origY, FALSE, TRUE);
	 break;
      default:
	 BEEP ();
	 break;
      }
   }
}
예제 #12
0
파일: clock.c 프로젝트: iamjamestl/school
int main (int argc, char **argv)
{
   /* Declare variables. */
   CDKSCREEN *cdkscreen = 0;
   CDKLABEL *demo	= 0;
   WINDOW *cursesWin	= 0;
   int boxLabel		= 0;
   char *mesg[4], temp[256];
   struct tm *currentTime;
   time_t clck;
   int ret;

   /* Parse up the command line. */
   while ((ret = getopt (argc, argv, "b")) != -1)
   {
      switch (ret)
      {
	 case 'b' :
	      boxLabel = 1;
      }
   }

   /* Set up CDK */ 
   cursesWin = initscr();
   cdkscreen = initCDKScreen (cursesWin);

   /* Start CDK Colors */
   initCDKColor();

   /* Set the labels up. */
   mesg[0] = "</1/B>HH:MM:SS";

   /* Declare the labels. */
   demo = newCDKLabel (cdkscreen, CENTER, CENTER, mesg, 1, boxLabel, FALSE);

   /* Is the label null??? */
   if (demo == 0)
   {
      /* Clean up the memory. */
      destroyCDKScreen (cdkscreen);

      /* End curses... */
      endCDK();

      /* Spit out a message. */
      printf ("Oops. Can't seem to create the label. Is the window too small?\n");
      ExitProgram (EXIT_FAILURE);
   }

   curs_set(0);
   wtimeout (WindowOf(demo), 50);

   /* Do this for-a-while... */
   do
   {
      /* Get the current time. */
      time(&clck);
      currentTime = localtime (&clck);

      /* Put the current time in a string. */
      sprintf (temp, "<C></B/29>%02d:%02d:%02d", currentTime->tm_hour, currentTime->tm_min, currentTime->tm_sec);
      mesg[0] = copyChar (temp);

      /* Set the label contents. */
      setCDKLabel (demo, mesg, 1, ObjOf(demo)->box);

      /* Clean up the memory used. */
      freeChar (mesg[0]);

      /* Draw the label, and sleep. */
      drawCDKLabel (demo, ObjOf(demo)->box);
      napms (500);
   }
   while (wgetch(WindowOf(demo)) == ERR);

   /* Clean up */
   destroyCDKLabel (demo);
   destroyCDKScreen (cdkscreen);
   endCDK();

   ExitProgram (EXIT_SUCCESS);
}
예제 #13
0
파일: uisupp~1.cpp 프로젝트: mingpen/OpenNT
void CBadTrustDialog::OnInitDialog()
    {
    //
    // Get the background brush for our edit controls
    //
    m_hbrBackground = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));

    // Load the icon
    LPSTR idi;
    switch (m_rrn.hrValid)
        {
    case HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND):
    case TRUST_E_NOSIGNATURE:
        idi = IDI_EXCLAMATION;
        break;
    default:
        idi = IDI_HAND;
        break;
        }
    HICON hicon = LoadIcon(NULL, idi);
    ::SendDlgItemMessage(m_hWnd, IDC_BADTRUSTICON, STM_SETICON, (WPARAM)hicon, (LPARAM)0);

    // Set the window title
		{
		TCHAR sz[128];
        WideCharToMultiByte(CP_ACP, 0, m_rrn.wszDialogTitle, -1, (LPSTR)sz, 128, NULL, NULL);
		::SetWindowText(GetWindow(), sz);
		}

    // Set the banter text
    int cchBanter2;
        {
        const int cchMax = INTERNET_MAX_URL_LENGTH+64;
        TCHAR sz[cchMax];

        // Set the top level banter
        ::LoadString(hinst, IDS_BADTRUSTBANTER1, &sz[0], cchMax);
        ::SetWindowText(WindowOf(IDC_BADTRUSTBANTER1), &sz[0]);

        // Set the program name
            {
            //
            // The 'program' name we see can in fact often be a full URL. URLs
            // can be very long, up to 1024 or so.
            //
            if (m_rrn.wszProgramName)
                {
                WideCharToMultiByte(CP_ACP, 0, m_rrn.wszProgramName, -1, &sz[0], cchMax, NULL, NULL);
                }
            else
                ::LoadString(hinst, IDS_UNKNOWNPROGRAM, &sz[0], cchMax);

            TCHAR szF[cchMax];
            ::FormatMessage(hinst, &szF[0], cchMax, IDS_BADTRUSTBANTER2, &sz[0]);

            ::SetWindowText(WindowOf(IDC_BADTRUSTBANTER2), &szF[0]);
            cchBanter2 = lstrlen(&szF[0]);

            //
            // This control is read-only. Note that the text on the control
            // can be copied using the context menu in the control.
            //
            SendMessage(WindowOf(IDC_BADTRUSTBANTER2), EM_SETREADONLY, (WPARAM)TRUE, 0);
            }

        // Set the trailing banter
        UINT ids;
        switch (m_rrn.hrValid)
            {
        case HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND):
        case TRUST_E_NOSIGNATURE:
            ids = IDS_BADTRUSTBANTER31;
            break;
        case CERT_E_EXPIRED:
        case CERT_E_VALIDIYPERIODNESTING:
            ids = IDS_BADTRUSTBANTER32;
            break;
        case NTE_BAD_SIGNATURE:
            ids = IDS_BADTRUSTBANTER33;
            break;
        default:
            ids = IDS_BADTRUSTBANTER34;
            break;
            }
        ::LoadString(hinst, ids, &sz[0], cchMax);
        ::SetWindowText(WindowOf(IDC_BADTRUSTBANTER3), &sz[0]);

        }

    // Position the controls so that all are visible
        {
        UINT spacing = GetSystemMetrics(SM_CYFIXEDFRAME) * 2;
        RECT rc1, rc2, rc3;
        int h;
        POINT pt;

        //
        // Where on the screen is the client area of the dialog?
        //
        pt.x = 0;
        pt.y = 0;
        ClientToScreen(GetWindow(), &pt);

        //
        // Find first text box location
        //
        GetWindowRect(WindowOf(IDC_BADTRUSTBANTER1), &rc1);

        //
        // Adjust second text box size
        //
        SizeControlToFitText(WindowOf(IDC_BADTRUSTBANTER2));
        //
        // Adjust second text box location
        //
        GetWindowRect(WindowOf(IDC_BADTRUSTBANTER2), &rc2);
        rc2.top    = rc1.bottom + spacing;
        ::SetWindowPos(WindowOf(IDC_BADTRUSTBANTER2), NULL,
            rc2.left - pt.x, rc2.top - pt.y, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
        GetWindowRect(WindowOf(IDC_BADTRUSTBANTER2), &rc2);

        //
        // Adjust third text box location
        //
        GetWindowRect(WindowOf(IDC_BADTRUSTBANTER3), &rc3);
        h = Height(rc3);
        rc3.top         = rc2.bottom + spacing;
        rc3.bottom      = rc3.top + h;
        ::SetWindowPos(WindowOf(IDC_BADTRUSTBANTER3), NULL,
            rc3.left - pt.x, rc3.top - pt.y, Width(rc3), Height(rc3), SWP_NOZORDER);

        //
        // Adjust the button locations
        //
        RECT rcOk, rcCancel, rcDetails;
        GetWindowRect(WindowOf(IDOK),        &rcOk);
        GetWindowRect(WindowOf(IDCANCEL),    &rcCancel);
        GetWindowRect(WindowOf(IDC_DETAILS), &rcDetails);
        rcOk.top        = rc3.bottom + spacing;
        rcCancel.top    = rcOk.top;
        rcDetails.top   = rcOk.top;
        ::SetWindowPos(WindowOf(IDOK),        NULL, rcOk.left-pt.x, rcOk.top-pt.y,0,0, SWP_NOZORDER|SWP_NOSIZE);
        ::SetWindowPos(WindowOf(IDCANCEL),    NULL, rcCancel.left-pt.x, rcCancel.top-pt.y,0,0, SWP_NOZORDER|SWP_NOSIZE);
        ::SetWindowPos(WindowOf(IDC_DETAILS), NULL, rcDetails.left-pt.x, rcDetails.top-pt.y,0,0, SWP_NOZORDER|SWP_NOSIZE);
        GetWindowRect(WindowOf(IDOK),        &rcOk);
        GetWindowRect(WindowOf(IDCANCEL),    &rcCancel);
        GetWindowRect(WindowOf(IDC_DETAILS), &rcDetails);

        //
        // Adjust the overall dialog box size
        //
        RECT rcMe;
	    ::GetWindowRect(GetWindow(), &rcMe);            // screen coords	
        rcMe.bottom = rcOk.bottom + spacing + GetSystemMetrics(SM_CYFIXEDFRAME);
        ::SetWindowPos(GetWindow(), NULL, 0,0,Width(rcMe),Height(rcMe), SWP_NOZORDER | SWP_NOMOVE);

        //
        // Center ourselves in the parent window
        //
        HWND hwndParent = ::GetParent(GetWindow());
	    if (hwndParent == NULL)
		    hwndParent = ::GetDesktopWindow();
	    RECT rcParent;
	    ::GetWindowRect(GetWindow(), &rcMe);            // screen coords	
        ::GetWindowRect(hwndParent,  &rcParent);        // screen coords

        POINT ptParent = Center(rcParent);
        POINT ptMe     = Center(rcMe);
        pt.x = ptParent.x - ptMe.x;
        pt.y = ptParent.y - ptMe.y;

	    ::SetWindowPos
            (
            GetWindow(),
            NULL,
            pt.x,
            pt.y,
            0,
            0,
            SWP_NOZORDER | SWP_NOSIZE
            );
        }

    //
    // Make sure we're on the screen
    //
    EnsureOnScreen(GetWindow());

    //
    // Bring ourselves to the attention of the user
    //
    SetForegroundWindow(GetWindow());
    }
예제 #14
0
파일: person~2.cpp 프로젝트: mingpen/OpenNT
void CDialogTrustDB::OnInitDialog()
    {
    //
    // Initialize our internals
    //
    if (Init() != S_OK)
        return;

    //
    // Set the state of our commercial checkbox per the current registry setting
    // 
    ::SendMessage(
        WindowOf(IDC_TRUSTCOMMERCIAL),
        BM_SETCHECK, 
        (m_pdb->AreCommercialPublishersTrusted()==S_OK) ? BST_CHECKED : BST_UNCHECKED,
        0L);

    //
    // If we are a property sheet, then hide the OK & Cancel buttons and
    // make the banter wider
    //
    if (m_fPropertySheet)
        {
        RECT rcBanter, rcOk;
        GetWindowRect(WindowOf(IDC_BANTER), &rcBanter);     // get in screen coords
        GetWindowRect(WindowOf(IDOK      ), &rcOk);         // get in screen coords
        ::SetWindowPos(WindowOf(IDC_BANTER), NULL, 
            0, 0, Width(rcBanter) + (rcOk.right - rcBanter.right), Height(rcBanter), 
            SWP_NOMOVE | SWP_NOZORDER);

        ::ShowWindow(WindowOf(IDOK),     SW_HIDE);
        ::ShowWindow(WindowOf(IDCANCEL), SW_HIDE);
        }
    else
        {
        //
        // We are the modal dialog variation. Center ourselves in our
        // parent window
        //
	    RECT rcParent, rcMe;
        ::GetWindowRect(m_hWndParent,  &rcParent);
	    ::GetWindowRect(GetWindow(), &rcMe);

        POINT ptParent = Center(rcParent);
        POINT ptMe     = Center(rcMe);
        POINT pt;
        pt.x = ptParent.x - ptMe.x + rcMe.left;
        pt.y = ptParent.y - ptMe.y + rcMe.top;

	    ::SetWindowPos
            (
            GetWindow(), 
            NULL,
            pt.x,
            pt.y,
            0,
            0,
            SWP_NOZORDER | SWP_NOSIZE
            );

        //
        // Make sure we're on the screen
        //
        EnsureOnScreen(GetWindow());
        }

    //
    // Populate our list box
    //
    RefreshTrustList();

    }
예제 #15
0
bool InstallFiles()
{
    ButtonBar.Clear();
    ButtonBar.AddButton("C", "Cancel");
    ButtonBar.Draw();

    char *msg;
    char *dbuttons[2] = { GetTranslation("Continue"), GetTranslation("Exit program") };
    
    if ((InstallInfo.dest_dir_type == DEST_SELECT) || (InstallInfo.dest_dir_type == DEST_DEFAULT))
    {
        msg = CreateText(GetTranslation("This will install %s to the following directory:\n%s\nContinue?"),
                                   InstallInfo.program_name.c_str(), MakeCString(InstallInfo.dest_dir));
    }
    else
    {
        msg = CreateText(GetTranslation("This will install %s\nContinue?"), InstallInfo.program_name.c_str());
    }

    CCDKDialog Diag(CDKScreen, CENTER, CENTER, msg, dbuttons, 2);
    Diag.SetBgColor(26);
        
    int sel = Diag.Activate();
    
    Diag.Destroy();
    refreshCDKScreen(CDKScreen);
                
    if (sel == 1)
        return false;
    
    CCDKSWindow InstallOutput(CDKScreen, 0, 6, GetDefaultHeight()-5, -1,
                              CreateText("<C></29/B>%s", GetTranslation("Install output")), 2000);
    InstallOutput.SetBgColor(5);
    nodelay(WindowOf(InstallOutput.GetSWin()), true); // Make sure input doesn't block

    const int maxx = getmaxx(InstallOutput.GetSWin()->win);

    CCDKSWindow ProggWindow(CDKScreen, 0, 2, 5, maxx, NULL, 4);
    ProggWindow.SetBgColor(5);
    ProggWindow.AddText("");
    ProggWindow.AddText(CreateText("</B/29>%s:<!29!B>", GetTranslation("Status")));
    ProggWindow.AddText(CreateText("%s (1/%d)", GetTranslation("Extracting files"), InstallInfo.command_entries.size()+1),
                        true, BOTTOM, 24);
    
    CCDKHistogram ProgressBar(CDKScreen, 25, 3, 1, maxx-29, HORIZONTAL,
                              CreateText("<C></29/B>%s", GetTranslation("Progress")), false);
    ProgressBar.SetBgColor(5);
    ProgressBar.SetHistogram(vPERCENT, TOP, 0, 100, 0, COLOR_PAIR (24) | A_REVERSE | ' ', A_BOLD);
    
    setCDKSwindowLLChar(ProggWindow.GetSWin(), ACS_LTEE);
    setCDKSwindowLRChar(ProggWindow.GetSWin(), ACS_RTEE);
    
    InstallOutput.Draw();
    ProggWindow.Draw();
    
    // Check if we need root access
    char *passwd = NULL;
    LIBSU::CLibSU SuHandler;
    SuHandler.SetUser("root");
    SuHandler.SetTerminalOutput(false);

    bool askpass = false;
    
    for (std::list<command_entry_s *>::iterator it=InstallInfo.command_entries.begin();
        it!=InstallInfo.command_entries.end(); it++)
    {
        if ((*it)->need_root != NO_ROOT)
        {
            // Command may need root permission, check if it is so
            if ((*it)->need_root == DEPENDED_ROOT)
            {
                param_entry_s *p = GetParamByVar((*it)->dep_param);
                if (p && !WriteAccess(p->value))
                {
                    (*it)->need_root = NEED_ROOT;
                    if (!askpass) askpass = true;
                }
            }
            else if (!askpass) askpass = true;
        }
    }

    if (!askpass)
        askpass = !WriteAccess(InstallInfo.dest_dir);
    
    // Ask root password if one of the command entries need root access and root isn't passwordless
    if (askpass && SuHandler.NeedPassword())
    {
        CCDKEntry entry(CDKScreen, CENTER, CENTER,
                        GetTranslation("This installation requires root(administrator) privileges in order to continue\n"
                                       "Please enter the password of the root user"), "", 60, 0, 256, vHMIXED);
        entry.SetHiddenChar('*');
        entry.SetBgColor(26);

        while(1)
        {
            char *sz = entry.Activate();

            if ((entry.ExitType() != vNORMAL) || !sz || !sz[0])
            {
                if (YesNoBox(GetTranslation("Root access is required to continue\nAbort installation?")))
                    EndProg();
                refreshCDKScreen(CDKScreen);
            }
            else
            {
                if (SuHandler.TestSU(sz))
                {
                    passwd = strdup(sz);
                    for (short s=0;s<strlen(sz);s++) sz[s] = 0;
                    break;
                }

                for (short s=0;s<strlen(sz);s++) sz[s] = 0;
                entry.Clean();
                
                // Some error appeared
                if (SuHandler.GetError() == LIBSU::CLibSU::SU_ERROR_INCORRECTPASS)
                {
                    WarningBox(GetTranslation("Incorrect password given for root user\nPlease retype"));
                }
                else
                {
                    throwerror(true, GetTranslation("Could not use su to gain root access\n"
                               "Make sure you can use su(adding the current user to the wheel group may help)"));
                }
            }
        }
        // Restore screen
        entry.Destroy();
        refreshCDKScreen(CDKScreen);
    }

    short percent = 0;
    
    bool alwaysroot = false;
    if (!WriteAccess(InstallInfo.dest_dir))
    {
        CExtractAsRootFunctor Extracter;
        Extracter.SetUpdateProgFunc(SUUpdateProgress, &ProgressBar);
        Extracter.SetUpdateTextFunc(SUUpdateText, &InstallOutput);
        
        if (!Extracter(passwd))
        {
            CleanPasswdString(passwd);
            passwd = NULL;
            throwerror(true, "Error during extracting files");
        }

        InstallOutput.AddText("Done!\n");
        alwaysroot = true; // Install commands need root now too
    }
    else
    {

        while(percent<100)
        {
            std::string curfile;
            percent = ExtractArchive(curfile);
            
            InstallOutput.AddText("Extracting file: " + curfile, false);
            if (percent==100) InstallOutput.AddText("Done!", false);
            else if (percent==-1) throwerror(true, "Error during extracting files");
    
            ProgressBar.SetValue(0, 100, percent/(1+InstallInfo.command_entries.size()));
            ProgressBar.Draw();
    
            chtype input = getch();
            if (input == 'c')
            {
                if (YesNoBox(GetTranslation("Install commands are still running\n"
                    "If you abort now this may lead to a broken installation\n"
                    "Are you sure?")))
                {
                    CleanPasswdString(passwd);
                    passwd = NULL;
                    EndProg();
                }
            }
        }
    }

    SuHandler.SetThinkFunc(InstThinkFunc, passwd);
    SuHandler.SetOutputFunc(PrintInstOutput, &InstallOutput);

    percent = 100/(1+InstallInfo.command_entries.size()); // Convert to overall progress
    
    short step = 2; // Not 1, because extracting files is also a step
    for (std::list<command_entry_s*>::iterator it=InstallInfo.command_entries.begin();
         it!=InstallInfo.command_entries.end(); it++, step++)
    {
        if ((*it)->command.empty()) continue;

        ProggWindow.Clear();
        ProggWindow.AddText("");
        ProggWindow.AddText(CreateText("</B/29>%s:<!29!B>", GetTranslation("Status")));
        ProggWindow.AddText(CreateText("%s (%d/%d)", GetTranslation((*it)->description.c_str()), step,
                            InstallInfo.command_entries.size()+1), true, BOTTOM, 24);

        ProgressBar.Draw();
        
        std::string command = (*it)->command + " " + GetParameters(*it);
        InstallOutput.AddText("");
        InstallOutput.AddText(CreateText("Execute: %s", command.c_str()));
        InstallOutput.AddText("");
        InstallOutput.AddText("");
        
        if (((*it)->need_root == NEED_ROOT) || alwaysroot)
        {
            SuHandler.SetPath((*it)->path.c_str());
            SuHandler.SetCommand(command);
            if (!SuHandler.ExecuteCommand(passwd))
            {
                if ((*it)->exit_on_failure)
                {
                    CleanPasswdString(passwd);
                    passwd = NULL;
                    throwerror(true, "%s\n('%s')", GetTranslation("Failed to execute install command"),
                               SuHandler.GetErrorMsgC());
                }
            }
        }
        else
        {
            // Redirect stderr to stdout, so that errors will be displayed too
            command += " 2>&1";
            
            setenv("PATH", (*it)->path.c_str(), 1);
            FILE *pipe = popen(command.c_str(), "r");
            char term[1024];
            if (pipe)
            {
                while (fgets(term, sizeof(term), pipe))
                {
                    InstallOutput.AddText(term);

                    chtype input = getch();
                    if (input == 'c') /*injectCDKSwindow(InstallOutput.GetSWin(), input);*/
                    {
                        if (YesNoBox(GetTranslation("Install commands are still running\n"
                                                    "If you abort now this may lead to a broken installation\n"
                                                    "Are you sure?")))
                        {
                            CleanPasswdString(passwd);
                            passwd = NULL;
                            EndProg();
                        }
                    }
                }
                
                // Check if command exitted normally and close pipe
                int state = pclose(pipe);
                if (!WIFEXITED(state) || (WEXITSTATUS(state) == 127)) // SH returns 127 if command execution failes
                {
                    if ((*it)->exit_on_failure)
                    {
                        CleanPasswdString(passwd);
                        passwd = NULL;
                        throwerror(true, "Failed to execute install command");
                    }
                }
            }
            else
            {
                CleanPasswdString(passwd);
                passwd = NULL;
                throwerror(true, "Could not execute installation commands (could not open pipe)");
            }
            
#if 0
            // Need to find a good way to safely suspend a process...this code doesn't always work :(
            
            int pipefd[2];

            pipe(pipefd);
            pid_t pid = fork();
            if (pid == -1) throwerror(true, "Error during command execution: Could not fork process");
            else if (pid) // Parent process
            {
                close(pipefd[1]); // We're not going to write here

                std::string out;
                char c;
                int compid = -1; // PID of the executed command

                while(read(pipefd[0], &c, sizeof(c)) > 0)
                {
                    out += c;
                    if (c == '\n')
                    {
                        if (compid == -1)
                        {
                            compid = atoi(out.c_str());
                            InstallOutput.AddText(CreateText("pid: %d compid: %d", pid, compid), false);
                        }
                        else InstallOutput.AddText(out, false);
                        out.clear();
                    }

                    chtype input = getch();
                    if (input != ERR) /*injectCDKSwindow(InstallOutput.GetSWin(), input);*/
                    {
                        if (kill(compid, SIGTSTP) < 0) // Pause command execution
                            WarningBox("PID Error: %s\n", strerror(errno));
                        
                        char *buttons[2] = { GetTranslation("Yes"), GetTranslation("No") };
                        CCharListHelper msg;
    
                        msg.AddItem(GetTranslation("This will abort the installation"));
                        msg.AddItem(GetTranslation("Are you sure?"));
    
                        CCDKDialog dialog(CDKScreen, CENTER, CENTER, msg, msg.Count(), buttons, 2);
                        dialog.SetBgColor(26);
                        int ret = dialog.Activate();
                        bool cont = ((ret == 1) || (dialog.ExitType() != vNORMAL));

                        dialog.Destroy();
                        refreshCDKScreen(CDKScreen);

                        if (!cont)
                        {
                            kill(pid, SIGTERM);
                            EndProg();
                        }

                        kill(compid, SIGCONT); // Continue command execution
                    }
                }
                close (pipefd[0]);

                int status;
                //waitpid(pid, &status, 0);
            }
            else // Child process
            {
                // Redirect stdout to pipe
                close(STDOUT_FILENO);
                dup (pipefd[1]);
                
                close (pipefd[0]); // No need to read here

                // Make sure no errors are printed and write pid of new command
                command += " 2> /dev/null &  echo $!";
                execl("/bin/sh", "sh", "-c", command.c_str(), NULL);
                system(CreateText("echo %s", strerror(errno)));
                _exit(1);
            }
#endif
        }

        percent += (1.0f/((float)InstallInfo.command_entries.size()+1.0f))*100.0f;
        ProgressBar.SetValue(0, 100, percent);
    }

    ProgressBar.SetValue(0, 100, 100);
    ProgressBar.Draw();
    
    CleanPasswdString(passwd);
    passwd = NULL;
    
    ButtonBar.Clear();
    ButtonBar.AddButton("Arrows", "Scroll install output");
    ButtonBar.AddButton("Enter", (FileExists(InstallInfo.own_dir + "/config/finish")) ? "Continue" : "Finish"); // HACK
    ButtonBar.Draw();

    WarningBox("Installation of %s complete!", InstallInfo.program_name.c_str());

    InstallOutput.Activate();
    return (InstallOutput.ExitType() == vNORMAL);
}