gRadioBtns[gNumRadioBtns++] = radioButton;
nsresult WidgetTest(int *argc, char **argv){    // Open global test log file    gFD = fopen(gLogFileName, "w");    if (gFD == nsnull) {      fprintf(stderr, "Couldn't open file[%s]\n", gLogFileName);      exit(1);    }    // register widget classes    NSRepository::RegisterFactory(kCWindowCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    NSRepository::RegisterFactory(kCChildCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    NSRepository::RegisterFactory(kCButtonCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    NSRepository::RegisterFactory(kCCheckButtonCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    NSRepository::RegisterFactory(kCComboBoxCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    NSRepository::RegisterFactory(kCFileWidgetCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    NSRepository::RegisterFactory(kCListBoxCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    NSRepository::RegisterFactory(kCRadioButtonCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    NSRepository::RegisterFactory(kCHorzScrollbarCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    NSRepository::RegisterFactory(kCVertScrollbarCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    NSRepository::RegisterFactory(kCTextAreaCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    NSRepository::RegisterFactory(kCTextFieldCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    NSRepository::RegisterFactory(kCTabWidgetCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    NSRepository::RegisterFactory(kCTooltipWidgetCID, WIDGET_DLL, PR_FALSE, PR_FALSE);    NSRepository::RegisterFactory(kCAppShellCID, WIDGET_DLL, PR_FALSE, PR_FALSE);        static NS_DEFINE_IID(kCRenderingContextIID, NS_RENDERING_CONTEXT_CID);     static NS_DEFINE_IID(kCDeviceContextIID, NS_DEVICE_CONTEXT_CID);     static NS_DEFINE_IID(kCFontMetricsIID, NS_FONT_METRICS_CID);     static NS_DEFINE_IID(kCImageIID, NS_IMAGE_CID);     NSRepository::RegisterFactory(kCRenderingContextIID, GFX_DLL, PR_FALSE, PR_FALSE);     NSRepository::RegisterFactory(kCDeviceContextIID, GFX_DLL, PR_FALSE, PR_FALSE);     NSRepository::RegisterFactory(kCFontMetricsIID, GFX_DLL, PR_FALSE, PR_FALSE);     NSRepository::RegisterFactory(kCImageIID, GFX_DLL, PR_FALSE, PR_FALSE);       // Create a application shell    nsIAppShell *appShell;    NSRepository::CreateInstance(kCAppShellCID, nsnull, kIAppShellIID, (void**)&appShell);    if (appShell != nsnull) {      appShell->Create(argc, argv);    } else {      printf("AppShell is null!\n");    }    nsIDeviceContext* deviceContext = 0;    // Create a device context for the widgets    nsresult  res;    static NS_DEFINE_IID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID);    static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID);    res = NSRepository::CreateInstance(kDeviceContextCID, nsnull, kDeviceContextIID, (void **)&deviceContext);    if (NS_OK == res)    {      deviceContext->Init(nsnull);      NS_ADDREF(deviceContext);    }    //    // create the main window    //    NSRepository::CreateInstance(kCWindowCID, nsnull, kIWidgetIID, (void**)&window);#ifdef XP_PC    nsRect rect(100, 100, 600, 700);    window->Create((nsIWidget*)NULL, rect, HandleEvent, NULL);#endif#ifdef XP_UNIX    nsRect rect(0, 0, 600, 700);    window->Create((nsNativeWidget)NULL, rect, HandleEvent,                    (nsIDeviceContext *)nsnull,                    (nsIToolkit *)nsnull,                   (nsWidgetInitData*)appShell->GetNativeData(NS_NATIVE_SHELL));#endif    window->SetTitle("TOP-LEVEL window");    window->Show(PR_TRUE);    window->SetBackgroundColor(NS_RGB(196, 196, 196));#ifdef XP_PC    tooltipWindow = createTooltipWindow(window, "INSERT <tooltip> here", 0, 0, 150, 0);    tooltipWindow->Show(PR_FALSE);    toolTipButton1 = createSimpleButton(window, "Tooltip \\/\\/",400, 100, 100, 0);    toolTipButton2 = createSimpleButton(window, "Tooltip /\\/\\",500, 200, 100, 0);    createTestButton(window, "Move Tooltip pos 1", 450, 150, 130, TooltipPos1);    createTestButton(window, "Move Tooltip pos 2", 450, 175, 130, TooltipPos2);    SetTooltipPos(1, window, toolTipButton1, toolTipButton2);#endif    //    // create a child    //    nsIWidget *child;    //    // create another child    //    int x = 5;    int y = 10;    rect.SetRect(x, y, 100, 100);      NSRepository::CreateInstance(kCChildCID, nsnull, kIWidgetIID, (void**)&child);      #if 0     child->SetBorderStyle(eBorderStyle_dialog);    child->Create(window, rect, HandleEvent, NULL);    //child->SetBackgroundColor(NS_RGB(255, 255, 0));    child->SetForegroundColor(NS_RGB(255, 0, 0));    child->SetBackgroundColor(NS_RGB(255, 128, 64));#endif      //NS_RELEASE(child); // the parent keeps a reference on this child    y += rect.height + 5;       //    // create a button    //    nsIButton *button;    rect.SetRect(x, y, 60, 25);      NSRepository::CreateInstance(kCButtonCID, nsnull, kIButtonIID, (void**)&button);    button->Create(window, rect, HandleEvent, NULL);    nsString label("Slider");    button->SetLabel(label);    nsAutoString strBuf;    button->GetLabel(strBuf);    button->Show(PR_TRUE);    movingWidget = button;    y += rect.height + 5;    x = 5;    x = createTestButton(window, kHideBtn, x, y, 75, ButtonTestHandleEvent) + 5;    x = createTestButton(window, kShowBtn, x, y, 75, ButtonTestHandleEvent);    x = 5;    y += rect.height + 5;    // Create browse button    x = createTestButton(window, kBrowseBtn, x,   y, 75, HandleFileButtonEvent);    x = 5;    y += rect.height + 5;    //    // create a check button    //    nsICheckButton * checkButton;    rect.SetRect(x, y, 100, 25);      NSRepository::CreateInstance(kCCheckButtonCID, nsnull, kICheckButtonIID, (void**)&checkButton);    checkButton->Create(window, rect, CheckButtonTestHandleEvent, NULL);    nsString cbLabel("CheckButton");    checkButton->SetLabel(cbLabel);    checkButton->Show(PR_TRUE);    //NS_RELEASE(checkButton);    y += rect.height + 5;    //    // create a text widget    //    nsITextWidget * textWidget;    rect.SetRect(x, y, 100, TEXT_HEIGHT);      NSRepository::CreateInstance(kCTextFieldCID, nsnull, kITextWidgetIID, (void**)&textWidget);    textWidget->Create(window, rect, HandleEvent, deviceContext);    nsFont font("Times", NS_FONT_STYLE_NORMAL,                         NS_FONT_VARIANT_NORMAL,                         NS_FONT_WEIGHT_BOLD,                         0,                         12);    textWidget->SetFont(font);    nsString initialText("0123456789");    textWidget->SetText(initialText);    textWidget->SetMaxTextLength(12);    textWidget->SelectAll();    textWidget->Show(PR_TRUE);    //NS_RELEASE(textWidget);     y += rect.height + 5;     //    // create a text password widget    //    nsITextWidget * ptextWidget;    rect.SetRect(x, y, 100, TEXT_HEIGHT);      NSRepository::CreateInstance(kCTextFieldCID, nsnull, kITextWidgetIID, (void**)&ptextWidget);    ptextWidget->SetPassword(PR_TRUE);    ptextWidget->Create(window, rect, HandleEvent, NULL);    nsString pinitialText("password text");    ptextWidget->SetText(pinitialText);    passwordText = ptextWidget;    x = x+180;    int saveX = x;    x = createTestButton(window, kSetSelection, saveX,y, 100, PasswordTextTestHandleEvent);    x = createTestButton(window, kClearSelection, x+5,y, 100, PasswordTextTestHandleEvent);    x = createTestButton(window, kSelectAll,      x+5,y, 100, PasswordTextTestHandleEvent);    // Next Row of texting Buttons    x = saveX;    y += 30;    x = createTestButton(window, kSetCaret, x+5,y, 75, PasswordTextTestHandleEvent);    x = createTestButton(window, kGetCaret, x+5,y, 75, PasswordTextTestHandleEvent);    x = createTestButton(window, kSetText,  x+5,y, 75, PasswordTextTestHandleEvent);    x = createTestButton(window, kGetText,  x+5,y, 75, PasswordTextTestHandleEvent);    x = 5;    //y += rect.height + 5;    //    // create a readonly text widget    //    nsITextWidget * rtextWidget;    rect.SetRect(x, y, 100, TEXT_HEIGHT);      NSRepository::CreateInstance(kCTextFieldCID, nsnull, kITextWidgetIID, (void**)&rtextWidget);    rtextWidget->SetReadOnly(PR_TRUE);    rtextWidget->Create(window, rect, HandleEvent, NULL);    nsString rinitialText("This is readonly");    rtextWidget->SetText(rinitialText);    //NS_RELEASE(rtextWidget);     y += rect.height + 5;    //    // create a text area widget    //    nsITextAreaWidget * textAreaWidget;    rect.SetRect(x, y, 150, 100);      NSRepository::CreateInstance(kCTextAreaCID, nsnull, kITextAreaWidgetIID, (void**)&textAreaWidget);    textAreaWidget->Create(window, rect, HandleEvent, NULL);    nsString textAreaInitialText("Text Area Widget");    textWidgetInstance = textAreaWidget;    textAreaWidget->SetText(textAreaInitialText);    //NS_RELEASE(textAreaWidget);     //y += rect.height + 5;    x += rect.width + 5;    // Save these for later    int saveY = y;    saveX = x;    //    // create a scrollbar    //    rect.SetRect(x, 10, 25, 300);      NSRepository::CreateInstance(kCVertScrollbarCID, nsnull, kIScrollbarIID, (void**)&scrollbar);    scrollbar->Create(window, rect, HandleEvent, NULL);    scrollbar->SetMaxRange(300);    scrollbar->SetThumbSize(50);    scrollbar->SetPosition(100);    x += rect.width + 5;     //    // create a Status Text    //    y = 10;    rect.SetRect(x, y, 350, TEXT_HEIGHT);      NSRepository::CreateInstance(kCTextFieldCID, nsnull, kITextWidgetIID, (void**)&statusText);    statusText->Create(window, rect, HandleEvent, deviceContext);    statusText->Show(PR_TRUE);    y += rect.height + 5;    //    // create a Failed Button    //    rect.SetRect(x, y, 100, 25);      NSRepository::CreateInstance(kCButtonCID, nsnull, kIButtonIID, (void**)&button);    button->Create(window, rect, FailedButtonHandleEvent, NULL);    nsString failedLabel("Failed");    button->SetLabel(failedLabel);    button->Show(PR_TRUE);    //NS_RELEASE(button);    rect.SetRect(x, y+30, 150, 25);      NSRepository::CreateInstance(kCButtonCID, nsnull, kIButtonIID, (void**)&button);    button->Create(window, rect, DoSelfTests, NULL);    nsString selfTestLabel("Perform Self Tests");    button->SetLabel(selfTestLabel);    button->Show(PR_TRUE);    x += rect.width + 5;    //    // create a Succeeded Button    //    rect.SetRect(x, y, 100, 25);      NSRepository::CreateInstance(kCButtonCID, nsnull, kIButtonIID, (void**)&button);    button->Create(window, rect, SucceededButtonHandleEvent, NULL);    nsString succeededLabel("Succeeded");    button->SetLabel(succeededLabel);    button->Show(PR_TRUE);    //NS_RELEASE(button);        //    // create a listbox widget    //    y = saveY;    x = saveX;    rect.SetRect(x, y, 150, 100);      NSRepository::CreateInstance(kCListBoxCID, nsnull, kIListBoxIID, (void**)&listBox);    listBox->Create(window, rect, HandleEvent, NULL);    listBox->Show(PR_TRUE);    char str[256];    int i;    for (i=0;i<NUM_COMBOBOX_ITEMS;i++) {      sprintf(str, "%s %d", "List Item", i);      nsString listStr1(str);      listBox->AddItemAt(listStr1, i);    }    x += rect.width+5;    x = createTestButton(window, kSetSelection,    x, y, 125, ListBoxTestHandleEvent) + 5;    x = createTestButton(window, kRemoveSelection, x,   y, 125, ListBoxTestHandleEvent);    x = 5;    y += rect.height + 5;    //    // create a multi-selection listbox widget    //    rect.SetRect(x, y, 150, 100);  //#ifdef XP_PC    NSRepository::CreateInstance(kCListBoxCID, nsnull, kIListBoxIID, (void**)&gMultiListBox);      // Notice the extra agrument PR_TRUE below which indicates that      // the list widget is multi-select    gMultiListBox->SetMultipleSelection(PR_TRUE);    gMultiListBox->Create(window, rect, HandleEvent, NULL);    for (i=0;i<NUM_COMBOBOX_ITEMS;i++) {      sprintf(str, "%s %d", "Multi List Item", i);      nsString listStr1(str);      gMultiListBox->AddItemAt(listStr1, i);    }    gMultiListBox->Show(PR_TRUE);//#endif    x = createTestButton(window, kSetSelection,    x+150, y, 125, MultiListBoxTestHandleEvent);    x = createTestButton(window, kRemoveSelection, x+5,   y, 125, MultiListBoxTestHandleEvent);    x = createTestButton(window, kSetSelectedIndices, x+5,   y, 125, MultiListBoxTestHandleEvent);    y += rect.height + 5;    x = 5;    //    // create a tab widget    //    rect.SetRect(300, 500, 200, 50);  #ifdef XP_PC    NSRepository::CreateInstance(kCTabWidgetCID, nsnull, kITabWidgetIID, (void**)&tabWidget);    tabWidget->Create(window, rect, HandleTabEvent, NULL);    nsString tabs[] = {"low", "medium", "high" };       tabWidget->SetTabs(3, tabs);    tabWidget->Show(PR_TRUE);#endif    //    // create a Radio button    //    nsIRadioButton * radioButton;    rect.SetRect(x, y, 120, 25);      NSRepository::CreateInstance(kCRadioButtonCID, nsnull, kIRadioButtonIID, (void**)&radioButton);    radioButton->Create(window, rect, HandleEvent, NULL);    nsString rbLabel("RadioButton1");    radioButton->SetLabel(rbLabel);    radioButton->Show(PR_TRUE);    //NS_RELEASE(radioButton);    y += rect.height + 5;    //    // create a Radio button    //    rect.SetRect(x, y, 120, 25);      NSRepository::CreateInstance(kCRadioButtonCID, nsnull, kIRadioButtonIID, (void**)&radioButton);    radioButton->Create(window, rect, HandleEvent, NULL);    nsString rbLabel2("RadioButton2");    radioButton->SetLabel(rbLabel2);    radioButton->Show(PR_TRUE);    //NS_RELEASE(radioButton);    y += rect.height + 5;    //window->SetBackgroundColor(NS_RGB(0,255,0));    //    // create a ComboBox    //    rect.SetRect(x, y, 120, 100);      NSRepository::CreateInstance(kCComboBoxCID, nsnull, kIComboBoxIID, (void**)&comboBox);    comboBox->Create(window, rect, HandleEvent, NULL);    comboBox->Show(PR_TRUE);    for (i=0;i<NUM_COMBOBOX_ITEMS;i++) {      sprintf(str, "%s %d", "List Item", i);      nsString listStr1(str);      comboBox->AddItemAt(listStr1, i);    }    //NS_RELEASE(comboBox);    x = createTestButton(window, kSetSelection,    x+125, y, 125, ComboTestHandleEvent);    x = createTestButton(window, kRemoveSelection, x+5,   y, 125, ComboTestHandleEvent);    x = 5;    y += 30;       nsString status("The non-visual tests: ");    status.Append( (gOverallStatus  ? "PASSED":"FAILED"));    gNonVisualStatus = gOverallStatus;    statusText->SetText(status);    // show    window->Show(PR_TRUE);    window->SetCursor(eCursor_hyperlink);    return(appShell->Run());}