6 static gint _get_position_in_array (gint window,
8 static gint _get_position_in_parameters (gint window,
11 static void _create_output_window (OutputWindow **outwin);
12 static gboolean _create_select_tests_window (AtkObject *obj,
14 OutputWindow **outwin);
15 static void _toggle_selectedcb (GtkWidget *widget,
17 static void _testselectioncb (GtkWidget *widget,
19 static void _destroy (GtkWidget *widget,
22 /* General functions */
25 * find_object_by_role:
27 * @roles: An array of roles to search for
28 * @num_roles: The number of entries in @roles
30 * Find the #AtkObject which is a decendant of the specified @obj
31 * which is of an #AtkRole type specified in the @roles array.
33 * Returns: the #AtkObject that meets the specified criteria or NULL
34 * if no object is found.
37 find_object_by_role (AtkObject *obj,
42 * Find the first object which is a descendant of the specified object
43 * which matches the specified role.
45 * This function returns a reference to the AtkObject which should be
46 * removed when finished with the object.
55 for (j=0; j < num_roles; j++)
57 if (atk_object_get_role (obj) == roles[j])
61 n_children = atk_object_get_n_accessible_children (obj);
62 for (i = 0; i < n_children; i++)
66 child = atk_object_ref_accessible_child (obj, i);
71 for (j=0; j < num_roles; j++)
73 if (atk_object_get_role (child) == roles[j])
77 found_obj = find_object_by_role (child, roles, num_roles);
78 g_object_unref (child);
86 * find_object_by_name_and_role:
88 * @name: The GTK widget name
89 * @roles: An array of roles to search for
90 * @num_roles: The number of entries in @roles
92 * Find the #AtkObject which is a decendant of the specified @obj
93 * which is of an #AtkRole type specified in the @roles array which
94 * also has the GTK widget name specified in @name.
96 * Returns: the #AtkObject that meets the specified criteria or NULL
97 * if no object is found.
100 find_object_by_name_and_role(AtkObject *obj,
113 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
114 if (GTK_IS_WIDGET (widget))
116 if (strcmp (name, gtk_widget_get_name(GTK_WIDGET (widget))) == 0)
118 for (j=0; j < num_roles; j++)
120 if (atk_object_get_role (obj) == roles[j])
126 n_children = atk_object_get_n_accessible_children (obj);
127 for (i = 0; i < n_children; i++)
129 AtkObject* found_obj;
131 child = atk_object_ref_accessible_child (obj, i);
136 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (child));
137 if (GTK_IS_WIDGET (widget))
139 if (strcmp(name, gtk_widget_get_name(GTK_WIDGET (widget))) == 0)
141 for (j=0; j < num_roles; j++)
143 if (atk_object_get_role (child) == roles[j])
148 found_obj = find_object_by_name_and_role (child, name, roles, num_roles);
149 g_object_unref (child);
157 * find_object_by_accessible_name_and_role:
158 * @obj: An #AtkObject
159 * @name: The accessible name
160 * @roles: An array of roles to search for
161 * @num_roles: The number of entries in @roles
163 * Find the #AtkObject which is a decendant of the specified @obj
164 * which has the specified @name and matches one of the
167 * Returns: the #AtkObject that meets the specified criteria or NULL
168 * if no object is found.
171 find_object_by_accessible_name_and_role (AtkObject *obj,
179 G_CONST_RETURN gchar *accessible_name;
184 accessible_name = atk_object_get_name (obj);
185 if (accessible_name && (strcmp(name, accessible_name) == 0))
187 for (j=0; j < num_roles; j++)
189 if (atk_object_get_role (obj) == roles[j])
194 n_children = atk_object_get_n_accessible_children (obj);
195 for (i = 0; i < n_children; i++)
197 AtkObject* found_obj;
199 child = atk_object_ref_accessible_child (obj, i);
204 accessible_name = atk_object_get_name (child);
205 if (accessible_name && (strcmp(name, accessible_name) == 0))
207 for (j=0; j < num_roles; j++)
209 if (atk_object_get_role (child) == roles[j])
213 found_obj = find_object_by_accessible_name_and_role (child, name,
215 g_object_unref (child);
223 * find_object_by_name_and_role:
224 * @obj: An #AtkObject
227 * Find the #AtkObject which is a decendant of the specified @obj
228 * which has the specified @type.
230 * Returns: the #AtkObject that meets the specified criteria or NULL
231 * if no object is found.
234 find_object_by_type (AtkObject *obj,
238 * Find the first object which is a descendant of the specified object
239 * which matches the specified type.
241 * This function returns a reference to the AtkObject which should be
242 * removed when finished with the object.
247 G_CONST_RETURN gchar * typename = NULL;
252 typename = g_type_name (G_OBJECT_TYPE (obj));
253 if (strcmp (typename, type) == 0)
256 n_children = atk_object_get_n_accessible_children (obj);
257 for (i = 0; i < n_children; i++)
259 AtkObject* found_obj;
261 child = atk_object_ref_accessible_child (obj, i);
266 typename = g_type_name (G_OBJECT_TYPE (child));
268 if (strcmp (typename, type) == 0)
271 found_obj = find_object_by_type (child, type);
272 g_object_unref (child);
280 * already_accessed_atk_object
281 * @obj: An #AtkObject
283 * Keeps a static GPtrArray of objects that have been passed into this
286 * Returns: TRUE if @obj has been passed into this function before
287 * and FALSE otherwise.
290 already_accessed_atk_object (AtkObject *obj)
292 static GPtrArray *obj_array = NULL;
293 gboolean found = FALSE;
297 * We create a property handler for each object if one was not associated
300 * We add it to our array of objects which have property handlers; if an
301 * object is destroyed it remains in the array.
303 if (obj_array == NULL)
304 obj_array = g_ptr_array_new ();
306 for (i = 0; i < obj_array->len; i++)
308 if (obj == g_ptr_array_index (obj_array, i))
315 g_ptr_array_add (obj_array, obj);
322 * @obj: An #AtkObject
323 * @depth: Number of spaces to indent output.
324 * @child_number: The child number of this object.
326 * Displays the hierarchy of widgets starting from @obj.
329 display_children (AtkObject *obj,
333 display_children_to_depth(obj, -1, depth, child_number);
337 * display_children_to_depth
338 * @obj: An #AtkObject
339 * @to_depth: Display to this depth.
340 * @depth: Number of spaces to indent output.
341 * @child_number: The child number of this object.
343 * Displays the hierarchy of widgets starting from @obj only
344 * to the specified depth.
347 display_children_to_depth (AtkObject *obj,
353 const gchar *rolename;
354 const gchar *typename;
355 gint n_children, parent_index, i;
357 if (to_depth >= 0 && depth > to_depth)
363 for (i=0; i < depth; i++)
366 role = atk_object_get_role (obj);
367 rolename = atk_role_get_name (role);
370 * Note that child_number and parent_index should be the same
371 * unless there is an error.
373 parent_index = atk_object_get_index_in_parent(obj);
374 g_print("child <%d == %d> ", child_number, parent_index);
376 n_children = atk_object_get_n_accessible_children (obj);
377 g_print ("children <%d> ", n_children);
380 g_print("role <%s>, ", rolename);
382 g_print("role <error>");
384 if (GTK_IS_ACCESSIBLE(obj))
388 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
389 g_print("name <%s>, ", gtk_widget_get_name(GTK_WIDGET (widget)));
392 g_print("name <NULL>, ");
394 typename = g_type_name (G_OBJECT_TYPE (obj));
395 g_print ("typename <%s>\n", typename);
397 for (i = 0; i < n_children; i++)
401 child = atk_object_ref_accessible_child (obj, i);
404 display_children_to_depth (child, to_depth, depth + 1, i);
405 g_object_unref (G_OBJECT (child));
412 /* GUI Information for the Select Tests Window */
415 GtkWidget *selecttestsWindow;
419 GtkWidget *textInsert;
421 gchar *selecttestsTitle;
424 /* Functionality information about each added test */
427 GtkWidget *toggleButton;
429 GtkWidget *parameterLabel[MAX_PARAMS];
430 GtkWidget *parameterInput[MAX_PARAMS];
442 static MainDialog *md[MAX_WINDOWS];
443 static OutputWindow *ow;
445 /* An array containing function information on all of the tests */
446 static TestList listoftests[MAX_WINDOWS][MAX_TESTS];
448 /* A counter for the actual number of added tests */
451 /* A global for keeping track of the window numbers */
452 static gint window_no = 0;
453 /* An array containing the names of the tests that are "on" */
454 static gchar *onTests[MAX_WINDOWS][MAX_TESTS];
455 static gint g_visibleDialog = 0;
456 static gint testcount[MAX_WINDOWS];
457 static TestCB testcb[MAX_WINDOWS];
461 * @obj: An #AtkObject
462 * @runtest: The callback function to run when the "Run Tests" button
464 * @outwin: The output window to use. If NULL is passed in, then
467 * Creates the test window and the output window (if @outwin is NULL)
468 * Runs _create_output_window() and _create_select_tests_window()
469 * and sets g_visibleDialog to 1
471 * Returns: The window number of the created window if successful, -1 otherwise.
474 create_windows (AtkObject *obj,
476 OutputWindow **outwin)
482 _create_output_window(outwin);
483 valid = _create_select_tests_window(obj, runtest, outwin);
495 * _create_output_window
496 * @outwin: If outwin is passed in as NULL, a new output window is created
497 * otherwise, the outwin passed in is shared.
499 * Creates the Test Result Output Window .
502 _create_output_window (OutputWindow **outwin)
505 GtkWidget *scrolled_window;
506 OutputWindow *localow;
510 localow = (OutputWindow *) malloc (sizeof(OutputWindow));
512 localow->outputBuffer = gtk_text_buffer_new(NULL);
513 view = gtk_text_view_new_with_buffer(GTK_TEXT_BUFFER(localow->outputBuffer));
514 gtk_widget_set_size_request (view, 700, 500);
515 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD);
516 gtk_text_view_set_editable(GTK_TEXT_VIEW(view), FALSE);
518 localow->outputWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
519 gtk_window_set_title(GTK_WINDOW(localow->outputWindow), "Test Output");
520 scrolled_window = gtk_scrolled_window_new(NULL, NULL);
522 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
523 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
524 gtk_container_add(GTK_CONTAINER(localow->outputWindow), scrolled_window);
525 gtk_container_add(GTK_CONTAINER(scrolled_window), view);
526 gtk_text_buffer_get_iter_at_offset(localow->outputBuffer, &localow->outputIter, 0);
527 gtk_widget_show(view);
528 gtk_widget_show(scrolled_window);
529 gtk_widget_show(localow->outputWindow);
531 gtk_text_buffer_set_text(GTK_TEXT_BUFFER(localow->outputBuffer),
532 "\n\nWelcome to the test GUI:\nTest results are printed here\n\n", 58);
533 gtk_text_buffer_get_iter_at_offset(GTK_TEXT_BUFFER(localow->outputBuffer),
534 &localow->outputIter, 0);
541 * _create_select_tests_window:
542 * @obj: An #AtkObject
543 * @runtest: The callback function that is run when the "Run Tests"
545 * @outwin: The output window to use.
547 * Creates the Test Select Window
549 * Returns: TRUE if successful, FALSE otherwise
552 _create_select_tests_window (AtkObject *obj,
554 OutputWindow **outwin)
557 GtkWidget *hbuttonbox;
558 GtkWidget *scrolledWindow;
560 if (window_no >= 0 && window_no < MAX_WINDOWS)
562 md[window_no] = (MainDialog *) malloc (sizeof(MainDialog));
564 textwidget = ATK_TEXT (obj);
567 md[window_no]->selecttestsTitle = "Test Setting";
568 md[window_no]->selecttestsWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
569 gtk_window_set_title (GTK_WINDOW( ow->outputWindow),
570 md[window_no]->selecttestsTitle);
571 gtk_window_set_resizable (GTK_WINDOW(md[window_no]->selecttestsWindow),
573 gtk_window_set_position (GTK_WINDOW(md[window_no]->selecttestsWindow),
575 g_signal_connect (md[window_no]->selecttestsWindow,
577 G_CALLBACK (_destroy),
578 &md[window_no]->selecttestsWindow);
580 /* Setup Scrolling */
581 scrolledWindow = gtk_scrolled_window_new(NULL, NULL);
582 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledWindow),
583 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
584 gtk_widget_set_size_request (scrolledWindow, 500, 600);
585 gtk_container_add (GTK_CONTAINER (md[window_no]->selecttestsWindow),
589 md[window_no]->vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, TRUE, 0);
590 md[window_no]->button = gtk_button_new_with_mnemonic ("_Run Tests");
591 hbuttonbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
592 gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox),
593 GTK_BUTTONBOX_SPREAD);
594 gtk_box_pack_end (GTK_BOX (hbuttonbox),
595 GTK_WIDGET (md[window_no]->button), TRUE, TRUE, 0);
596 gtk_box_pack_end (GTK_BOX (md[window_no]->vbox), hbuttonbox,
598 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolledWindow),
599 md[window_no]->vbox);
601 testcb[window_no].runtest = runtest;
602 testcb[window_no].obj = obj;
603 testcb[window_no].win_num = window_no;
604 g_signal_connect (md[window_no]->button,
606 G_CALLBACK (_testselectioncb),
607 (gpointer)&testcb[window_no]);
610 gtk_widget_grab_focus (md[window_no]->button);
611 gtk_widget_show (md[window_no]->button);
612 gtk_widget_show (hbuttonbox);
613 gtk_widget_show (scrolledWindow);
614 gtk_widget_show_all (GTK_WIDGET (md[window_no]->selecttestsWindow));
623 * @window: The window number
624 * @name: The test name
625 * @num_params: The number of arguments the test uses.
626 * @parameter_names: The names of each argument.
627 * @default_names: The default values of each argument.
629 * Adds a Test with the passed-in details to the Tests Select Window.
631 * Returns: FALSE if the num_params passed in is greater than
632 * MAX_PARAMS, otherwise returns TRUE
636 add_test (gint window,
639 gchar* parameter_names[],
640 gchar* default_names[])
644 if (num_params > MAX_PARAMS)
648 md[window]->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 0);
649 gtk_box_set_spacing (GTK_BOX (md[window]->hbox), 10);
650 gtk_container_set_border_width (GTK_CONTAINER (md[window]->hbox), 10);
651 gtk_container_add (GTK_CONTAINER (md[window]->vbox), md[window]->hbox);
652 listoftests[window][testcount[window]].toggleButton =
653 gtk_toggle_button_new_with_label (name);
654 gtk_box_pack_start (GTK_BOX (md[window]->hbox),
655 listoftests[window][testcount[window]].toggleButton, FALSE, FALSE, 0);
656 listoftests[window][testcount[window]].testName = name;
657 listoftests[window][testcount[window]].numParameters = num_params;
658 for (i=0; i<num_params; i++)
660 listoftests[window][testcount[window]].parameterLabel[i] =
661 gtk_label_new (parameter_names[i]);
662 gtk_box_pack_start (GTK_BOX (md[window]->hbox),
663 listoftests[window][testcount[window]].parameterLabel[i], FALSE, FALSE, 0);
664 listoftests[window][testcount[window]].parameterInput[i] = gtk_entry_new();
665 gtk_entry_set_text (GTK_ENTRY (listoftests[window][testcount[window]].parameterInput[i]),
667 gtk_widget_set_size_request (listoftests[window][testcount[window]].parameterInput[i], 50, 22);
668 gtk_box_pack_start (GTK_BOX (md[window]->hbox),
669 listoftests[window][testcount[window]].parameterInput[i], FALSE, FALSE, 0);
670 gtk_widget_set_sensitive (
671 GTK_WIDGET (listoftests[window][testcount[window]].parameterLabel[i]), FALSE);
672 gtk_widget_set_sensitive (
673 GTK_WIDGET (listoftests[window][testcount[window]].parameterInput[i]), FALSE);
674 gtk_widget_show (listoftests[window][testcount[window]].parameterLabel[i]);
675 gtk_widget_show (listoftests[window][testcount[window]].parameterInput[i]);
677 g_signal_connect (listoftests[window][testcount[window]].toggleButton,
679 G_CALLBACK (_toggle_selectedcb),
680 (gpointer)&(listoftests[window][testcount[window]]));
681 gtk_widget_show (listoftests[window][testcount[window]].toggleButton);
682 gtk_widget_show (md[window]->hbox);
683 gtk_widget_show (md[window]->vbox);
693 * @window: The window number
694 * @count: Passes back the number of tests on.
696 * Gets an array of strings corresponding to the tests that are "on".
697 * A test is assumed on if the toggle button is on and if all its
698 * parameters have values.
700 * Returns: an array of strings corresponding to the tests that
703 gchar **tests_set(gint window, int *count)
705 gint i =0, j = 0, num;
710 for (i = 0; i < MAX_TESTS; i++)
711 onTests[window][i] = NULL;
713 for (i = 0; i < testcount[window]; i++)
716 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (listoftests[window][i].toggleButton)))
718 num = listoftests[window][i].numParameters;
719 for (j = 0; j < num; j++)
721 input = gtk_editable_get_chars (
722 GTK_EDITABLE (listoftests[window][i].parameterInput[j]), 0, -1);
724 if (input != NULL && (! strcmp(input, "")))
729 onTests[window][*count] = listoftests[window][i].testName;
734 return onTests[window];
738 * _get_position_in_array:
739 * @window: The window number
740 * @the_test_name: The name of the test
742 * Gets the index of the passed-in @the_test_name.
744 * Returns: the position in listoftests[] of @the_test_name
747 _get_position_in_array(gint window,
748 gchar *the_test_name)
752 for (i = 0; i < testcount[window]; i++)
754 if (strcmp(listoftests[window][i].testName, the_test_name) == 0)
761 * _get_position_in_parameters:
762 * @window: The window number
763 * @label: The label name
764 * @position: The parameter position
766 * Gets the index of the passed-in parameter @label.
768 * Returns: the position in parameterLabel[] (a member of
769 * listoftests[]) of @label
772 _get_position_in_parameters(gint window,
777 G_CONST_RETURN gchar *label_string;
779 for (i = 0; i < MAX_PARAMS; i++)
781 label_string = gtk_label_get_text(
782 GTK_LABEL (listoftests[window][position].parameterLabel[i]));
784 if (strcmp(label_string, label) == 0)
792 * @output: The string to add to the output buffer
794 * Tidies up the output Window
797 set_output_buffer(gchar *output)
799 gtk_text_buffer_insert (GTK_TEXT_BUFFER (ow->outputBuffer),
800 &ow->outputIter, output, strlen(output));
801 gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (ow->outputBuffer),
808 * Informs user if a visible test window running.
810 * Returns: TRUE if g_visibleDialog is set to 1, otherwise FALSE
813 isVisibleDialog(void)
815 if (g_visibleDialog >= 1)
823 * @window: The window number
824 * @function_name: The name of the function
825 * @arg_label: The label of the argument.
827 * Gets the user input associated with the @function_name and @arg_label.
829 * Returns: the user input associated with the @function_name and @arg_label.
832 get_arg_of_func (gint window,
833 gchar *function_name,
836 G_CONST_RETURN gchar *argString;
838 gint position, paramPosition;
840 position = _get_position_in_array(window, function_name);
844 g_print("No such function\n");
848 paramPosition = _get_position_in_parameters(window, arg_label, position);
850 if (paramPosition == -1)
852 g_print("No such parameter Label\n");
856 if (position != -1 && paramPosition != -1)
858 argString = gtk_editable_get_chars (
859 GTK_EDITABLE (listoftests[window][position].parameterInput[paramPosition]),
861 retString = g_strdup(argString);
871 * @the_string: The string to convert
873 * Converts the passed-in string to an integer
875 * Returns: An integer corresponding to @the_string.
878 string_to_int (const char *the_string)
886 ret_val = strtod( the_string, &end_ptr);
887 if (*end_ptr == '\0')
890 printf("\nError: input must be a number\n");
893 int_ret_val = (int) ret_val;
894 return (int_ret_val);
898 * _toggle_selectedcb:
899 * @widget: The ToggleButton widget
900 * @test: user data containing the TestList structure.
902 * Toggle Button Callback, activating the text entry fields
905 _toggle_selectedcb (GtkWidget *widget,
909 TestList *testlist = (TestList *) test;
912 toggled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
918 for (i=0; i < testlist->numParameters; i++)
920 gtk_widget_set_sensitive (GTK_WIDGET (testlist->parameterLabel[i]),
922 gtk_widget_set_sensitive (GTK_WIDGET (testlist->parameterInput[i]),
929 * widget: The Button widget
930 * data: The user data containing a TestCB structure
932 * Callback for when the "Run Tests" button is pressed
935 _testselectioncb (GtkWidget *widget,
938 TestCB* local_testcb = (TestCB *)data;
939 local_testcb->runtest(local_testcb->obj, local_testcb->win_num);
944 * @widget: The GUI widget
945 * @data: User data, not used.
950 _destroy (GtkWidget *widget,