00001 #include "vapiGtkInterface.h"
00002 #include "vapiOptions.h"
00003 #include "vapiGtkOptions.h"
00004 #include "vapiGtkOptionsOperations.h"
00005 #include "vapiGtkEventsOperations.h"
00006 #include "vapiAux.h"
00007
00008 #define OptionWidgetsWidth 80
00009
00017 void
00018 vapiGtkOptionsCreate (GtkWidget * ParentContainer,
00019 GtkWidget ** Container, GList ** OptionsList[3],
00020 vOptions * Options,
00021 vOptionsSettings * OptionsSettings,
00022 vGtkOptionsCustomCreate CustomFunc,
00023 GCallback EventFunc, vpointer EventData)
00024 {
00025 int i = 0, j;
00026 GList *tempList[3], **tempLists[3];
00027 int widgetsWidth = OptionWidgetsWidth;
00028
00029 tempList[0] = NULL;
00030 tempList[1] = NULL;
00031 tempList[2] = NULL;
00032
00033 tempLists[0] = &tempList[0];
00034 tempLists[1] = &tempList[1];
00035 tempLists[2] = &tempList[2];
00036
00037
00038
00039
00040
00041 vapiGtkOptionsFree (Container, OptionsList);
00042 *Container = gtk_scrolled_window_new (NULL, NULL);
00043
00044 gtk_scrolled_window_set_policy ((GtkScrolledWindow *) * Container,
00045 GTK_POLICY_AUTOMATIC,
00046 GTK_POLICY_AUTOMATIC);
00047
00048 gtk_box_pack_start ((GtkBox *)
00049 ParentContainer, *Container, TRUE, TRUE, 1);
00050 gtk_box_reorder_child ((GtkBox *) ParentContainer, *Container, 4);
00051
00052 *OptionsList[0] =
00053 g_list_append (*OptionsList[0], gtk_vbox_new (TRUE, 1));
00054
00055 gtk_scrolled_window_add_with_viewport ((GtkScrolledWindow *)
00056 * Container,
00057 g_list_nth_data (*OptionsList
00058 [0], 0));
00059 gtk_box_set_homogeneous ((GtkBox *)
00060 g_list_nth_data (*OptionsList[0], 0), FALSE);
00061
00062
00063
00064
00065
00066
00067 if (CustomFunc != NULL)
00068 {
00069 i = CustomFunc (Options, OptionsSettings,
00070 OptionsList, tempLists,
00071 i, widgetsWidth, EventFunc, EventData);
00072 }
00073
00074
00075
00076
00077 i = vapiGtkOptionsCreateDefault (Options, OptionsSettings,
00078 OptionsList, tempLists,
00079 i, widgetsWidth, EventFunc,
00080 EventData);
00081
00082
00083 for (j = 0; j < i; j++)
00084 {
00085 gtk_box_pack_start ((GtkBox *)
00086 g_list_nth_data (*OptionsList[0],
00087 0),
00088 (GtkWidget *)
00089 g_list_nth_data
00090 (tempList[1], j), FALSE, FALSE, 6);
00091 gtk_box_pack_start ((GtkBox *)
00092 g_list_nth_data (*OptionsList[0],
00093 0),
00094 (GtkWidget *)
00095 g_list_nth_data (*OptionsList[1],
00096 j), FALSE, FALSE, 0);
00097 if (tempList[0] != NULL && j > 0)
00098 {
00099 gtk_box_pack_start ((GtkBox *)
00100 g_list_nth_data (*OptionsList[0],
00101 0),
00102 (GtkWidget *)
00103 g_list_nth_data (tempList[0],
00104 j - 1), FALSE,
00105 FALSE, 0);
00106 }
00107
00108 tempList[2] =
00109 g_list_append (tempList[2], gtk_hseparator_new ());
00110 gtk_widget_set_size_request (g_list_nth_data
00111 (tempList[2], j), widgetsWidth,
00112 5);
00113
00114 gtk_box_pack_start ((GtkBox *)
00115 g_list_nth_data (*OptionsList[0],
00116 0),
00117 (GtkWidget *)
00118 g_list_nth_data (tempList[2],
00119 j), FALSE, FALSE, 0);
00120
00121 }
00122 g_list_free (tempList[0]);
00123 g_list_free (tempList[1]);
00124 g_list_free (tempList[2]);
00125 gtk_widget_show_all (*Container);
00126 }
00127
00128 void
00129 vapiGtkOptionsFree (GtkWidget ** Container, GList ** OptionsList[3])
00130 {
00131 int listSize, i;
00132 if (*Container != 0)
00133 {
00134 g_list_free (*OptionsList[0]);
00135 g_list_free (*OptionsList[1]);
00136
00137
00138
00139
00140 if (*OptionsList[2] != NULL)
00141 {
00142 listSize = g_list_length (*OptionsList[2]);
00143 if (listSize > 0)
00144 {
00145 for (i = 0; i < listSize; i++)
00146 {
00147 free (g_list_nth_data
00148 (*OptionsList[2], i));
00149 }
00150 g_list_free (*OptionsList[2]);
00151 }
00152 }
00153 gtk_widget_destroy (*Container);
00154 *Container = 0;
00155 *OptionsList[0] = NULL;
00156 *OptionsList[1] = NULL;
00157 *OptionsList[2] = NULL;
00158 }
00159
00160
00161 }
00162
00163 int
00164 vapiGtkOptionsCreateDefault (vOptions * Options,
00165 vOptionsSettings * OptionsSettings,
00166 GList ** OptionsList[3], GList ** tempList[3],
00167 int i, int widgetsWidth,
00168 GCallback EventFunc, vpointer EventData)
00169 {
00170 int j, k;
00171 vapiEventList *eventList;
00172 if (OptionsSettings->floatsNumber)
00173 {
00174
00175 for (j = 0; j < OptionsSettings->floatsNumber; j++)
00176 {
00177 *OptionsList[1] =
00178 g_list_append (*OptionsList[1],
00179 vapiGtkOptionsCreateByInterfaceType
00180 (OptionsSettings->
00181 floats[j].interfaceType,
00182 OptionsSettings->
00183 floats[j].min,
00184 OptionsSettings->
00185 floats[j].max,
00186 OptionsSettings->
00187 floats[j].scale,
00188 Options->floats[j]));
00189 gtk_widget_set_size_request (g_list_nth_data
00190 (*OptionsList[1], i),
00191 widgetsWidth, 35);
00192
00193 *tempList[1] =
00194 g_list_append (*tempList[1],
00195 gtk_label_new
00196 (OptionsSettings->floats[j].
00197 name));
00198
00199
00200 *tempList[2] =
00201 g_list_append (*tempList[2],
00202 gtk_hseparator_new ());
00203 if (OptionsSettings->floats[j].interfaceType == vBar)
00204 {
00205 eventList = malloc (sizeof (vapiEventList));
00206 eventList->widget
00207 =
00208 g_list_nth_data (*OptionsList[1], i);
00209 eventList->eventHandler =
00210 g_signal_connect_after
00211 (G_OBJECT
00212 (g_list_nth_data
00213 (*OptionsList[1],
00214 i)),
00215 "value-changed",
00216 EventFunc, EventData);
00217 *OptionsList[2] =
00218 g_list_append (*OptionsList[2],
00219 eventList);
00220 }
00221
00222 ++i;
00223 }
00224 }
00225 if (OptionsSettings->intsNumber)
00226 {
00227
00228 for (j = 0; j < OptionsSettings->intsNumber; j++)
00229 {
00230
00231 *OptionsList[1] =
00232 g_list_append (*OptionsList[1],
00233 vapiGtkOptionsCreateByInterfaceType
00234 (OptionsSettings->
00235 ints[j].interfaceType,
00236 OptionsSettings->
00237 ints[j].min,
00238 OptionsSettings->
00239 ints[j].max,
00240 OptionsSettings->
00241 ints[j].scale,
00242 Options->ints[j]));
00243 *tempList[1] =
00244 g_list_append (*tempList[1],
00245 gtk_label_new
00246 (OptionsSettings->ints[j].
00247 name));
00248 if (OptionsSettings->ints[j].interfaceType == vBar)
00249 {
00250 eventList = malloc (sizeof (vapiEventList));
00251 eventList->widget
00252 =
00253 g_list_nth_data (*OptionsList[1], i);
00254 eventList->eventHandler =
00255 g_signal_connect_after
00256 (G_OBJECT
00257 (g_list_nth_data
00258 (*OptionsList[1],
00259 i)),
00260 "value-changed",
00261 EventFunc, EventData);
00262 *OptionsList[2] =
00263 g_list_append (*OptionsList[2],
00264 eventList);
00265 }
00266
00267
00268 ++i;
00269 }
00270 }
00271 if (OptionsSettings->charsNumber)
00272 {
00273 for (j = 0; j < OptionsSettings->charsNumber; j++)
00274 {
00275 *OptionsList[1] =
00276 g_list_append (*OptionsList[1],
00277 gtk_entry_new ());
00278 *tempList[1] =
00279 g_list_append (*tempList[1],
00280 gtk_label_new
00281 (OptionsSettings->chars[j].
00282 name));
00283
00284
00285 gtk_entry_set_text ((GtkEntry *)
00286 g_list_nth_data (*OptionsList[1],
00287 i),
00288 Options->chars[j].ch);
00289 ++i;
00290 }
00291 }
00292 if (OptionsSettings->chooseNumber)
00293 {
00294 for (j = 0; j < OptionsSettings->chooseNumber; j++)
00295 {
00296 *OptionsList[1] =
00297 g_list_append (*OptionsList[1],
00298 gtk_combo_box_new_text ());
00299 *tempList[1] =
00300 g_list_append (*tempList[1],
00301 gtk_label_new
00302 (OptionsSettings->choose[j].
00303 name));
00304
00305
00306 for (k = 0;
00307 k <
00308 OptionsSettings->choose[j].numberOfChoices; k++)
00309 {
00310 gtk_combo_box_append_text ((GtkComboBox *)
00311 g_list_nth_data
00312 (*OptionsList[1],
00313 i),
00314 OptionsSettings->
00315 choose[j].
00316 listOfChoices[k].
00317 ch);
00318 }
00319
00320 gtk_combo_box_set_active ((GtkComboBox *)
00321 g_list_nth_data
00322 (*OptionsList[1], i),
00323 OptionsSettings->
00324 choose[j].defaultOption);
00325 ++i;
00326 }
00327 }
00328 if (OptionsSettings->booleansNumber)
00329 {
00330 for (j = 0; j < OptionsSettings->booleansNumber; j++)
00331 {
00332 *OptionsList[1] =
00333 g_list_append (*OptionsList[1],
00334 gtk_check_button_new ());
00335 *tempList[1] =
00336 g_list_append (*tempList[1],
00337 gtk_label_new
00338 (OptionsSettings->booleans[j].
00339 name));
00340
00341
00342 gtk_toggle_button_set_active ((GtkToggleButton *)
00343 g_list_nth_data
00344 (*OptionsList[1], i),
00345 OptionsSettings->
00346 booleans[j].
00347 defaultValue);
00348 ++i;
00349 }
00350 }
00351 return i;
00352 }
00353
00354 GtkWidget *
00355 vapiGtkOptionsCreateByInterfaceType (vInterfaceType interfaceType,
00356 double min, double max,
00357 double scale, double defaultValue)
00358 {
00359 GtkWidget *newRange=NULL;
00360
00361 if (interfaceType == vBar || !interfaceType)
00362 {
00363 newRange = gtk_hscale_new_with_range (min, max, scale);
00364 gtk_range_set_value ((GtkRange *) newRange, defaultValue);
00365 gtk_range_set_update_policy ((GtkRange *)
00366 newRange,
00367 GTK_UPDATE_DISCONTINUOUS);
00368 }
00369 if (interfaceType == vSpin)
00370 {
00371 newRange = gtk_spin_button_new_with_range (min, max, scale);
00372 gtk_spin_button_set_value ((GtkSpinButton *) newRange,
00373 defaultValue);
00374 gtk_spin_button_set_update_policy ((GtkSpinButton *) newRange,
00375 GTK_UPDATE_IF_VALID);
00376 }
00377 return newRange;
00378 }
00379
00380
00381 void
00382 vapiGtkOptionsPopulate (vOptions * Options,
00383 vOptionsSettings * OptionsSettings,
00384 GList ** OptionsList[3],
00385 vGtkOptionsCustomPopulate CustomFunc)
00386 {
00387 int i = 0, j;
00388
00389 vapiGtkOptionsBlockEvents (OptionsList[2]);
00390
00391 i = CustomFunc (Options, OptionsSettings, OptionsList, i);
00392
00393 if (OptionsSettings->floatsNumber)
00394 {
00395 for (j = 0; j < OptionsSettings->floatsNumber; j++)
00396 {
00397
00398 vapiGtkOptionsSetOptionByInterfaceType
00399 (g_list_nth_data
00400 (*OptionsList[1], i),
00401 Options->floats[j],
00402 OptionsSettings->floats[j].
00403 interfaceType, vFALSE);
00404 ++i;
00405 }
00406 }
00407 if (OptionsSettings->intsNumber)
00408 {
00409
00410 for (j = 0; j < OptionsSettings->intsNumber; j++)
00411 {
00412
00413 vapiGtkOptionsSetOptionByInterfaceType
00414 (g_list_nth_data
00415 (*OptionsList[1], i),
00416 Options->ints[j],
00417 OptionsSettings->ints[j].
00418 interfaceType, vTRUE);
00419 ++i;
00420 }
00421 }
00422 if (OptionsSettings->charsNumber)
00423 {
00424 for (j = 0; j < OptionsSettings->charsNumber; j++)
00425 {
00426
00427 gtk_entry_set_text ((GtkEntry *)
00428 g_list_nth_data
00429 (*OptionsList[1], i),
00430 Options->chars[j].ch);
00431 ++i;
00432 }
00433 }
00434 if (OptionsSettings->chooseNumber)
00435 {
00436 for (j = 0; j < OptionsSettings->chooseNumber; j++)
00437 {
00438 gtk_combo_box_set_active ((GtkComboBox *)
00439 g_list_nth_data
00440 (*OptionsList[1], i),
00441 Options->choices[j]);
00442 ++j;
00443 }
00444 }
00445 if (OptionsSettings->booleansNumber)
00446 {
00447 for (j = 0; j < OptionsSettings->booleansNumber; j++)
00448 {
00449
00450 gtk_toggle_button_set_active ((GtkToggleButton *)
00451 g_list_nth_data
00452 (*OptionsList[1], i),
00453 Options->booleans[j]);
00454 ++j;
00455 }
00456 }
00457 vapiGtkOptionsUnBlockEvents (OptionsList[2]);
00458 }
00459
00460 void
00461 vapiGtkOptionsBlockEvents (GList ** OptionsEvents)
00462 {
00463 int listSize, i;
00464 vapiEventList *eventList;
00465 if (*OptionsEvents == NULL)
00466 {
00467 return;
00468 }
00469 listSize = g_list_length (*OptionsEvents);
00470 if (listSize > 0)
00471 {
00472 for (i = 0; i < listSize; i++)
00473 {
00474 eventList = (vapiEventList *) g_list_nth_data
00475 (*OptionsEvents, i);
00476 g_signal_handler_block (GTK_OBJECT
00477 (eventList->widget),
00478 eventList->eventHandler);
00479 }
00480 }
00481
00482
00483 }
00484
00485 void
00486 vapiGtkOptionsUnBlockEvents (GList ** OptionsEvents)
00487 {
00488 int listSize, i;
00489 vapiEventList *eventList;
00490 if (*OptionsEvents == NULL)
00491 {
00492 return;
00493 }
00494 listSize = g_list_length (*OptionsEvents);
00495 if (listSize > 0)
00496 {
00497 for (i = 0; i < listSize; i++)
00498 {
00499 eventList = (vapiEventList *) g_list_nth_data
00500 (*OptionsEvents, i);
00501 g_signal_handler_unblock (GTK_OBJECT
00502 (eventList->widget),
00503 eventList->eventHandler);
00504 }
00505 }
00506
00507
00508 }
00509
00510 GtkWidget *
00511 vapiGtkOptionsGetAssociatedWidget (const char *requiredOption,
00512 vOptionsSettings * OptionsSettings,
00513 GList ** OptionsData)
00514 {
00515 int i = 0, varNumber = 0, times;
00516
00517
00518
00519
00520
00521 times = vapiGtkOptionsCountCustomOperationsMembers (OptionsSettings);
00522
00523 switch (requiredOption[i])
00524 {
00525 case 'f':
00526 {
00527
00528 if (OptionsSettings->floatsNumber == 0)
00529 {
00530 return NULL;
00531 }
00532 varNumber = atoi (&requiredOption[i]);
00533
00534
00535
00536
00537 return g_list_nth_data (*OptionsData, varNumber + times);
00538 break;
00539 }
00540 case 'd':
00541 {
00542
00543 if (OptionsSettings->intsNumber == 0)
00544 {
00545 return NULL;
00546 }
00547 varNumber = atoi (&requiredOption[++i]);
00548
00549
00550
00551
00552 return g_list_nth_data (*OptionsData,
00553 times + varNumber +
00554 OptionsSettings->floatsNumber);
00555 break;
00556 }
00557 case 'c':
00558 {
00559
00560 if (OptionsSettings->charsNumber == 0)
00561 {
00562 return NULL;
00563 }
00564 varNumber = atoi (&requiredOption[++i]);
00565
00566
00567
00568
00569 return g_list_nth_data (*OptionsData,
00570 varNumber + times +
00571 OptionsSettings->
00572 floatsNumber +
00573 OptionsSettings->intsNumber);
00574 break;
00575 }
00576
00577 }
00578 return NULL;
00579
00580 }
00581
00582 void
00583 vapiGtkOptionsSetOptionByInterfaceType (GtkWidget * Range, double Value,
00584 vInterfaceType interfaceType,
00585 vBoolean ISint)
00586 {
00587
00588 if (interfaceType == vBar || !interfaceType)
00589 {
00590 if (ISint)
00591 {
00592 gtk_range_set_value ((GtkRange *) Range, (int) Value);
00593 }
00594 else
00595 {
00596 gtk_range_set_value ((GtkRange *) Range, Value);
00597 }
00598 }
00599 if (interfaceType == vSpin)
00600 {
00601 if (ISint)
00602 {
00603 gtk_spin_button_set_value ((GtkSpinButton *) Range,
00604 (int) Value);
00605 }
00606 else
00607 {
00608 gtk_spin_button_set_value ((GtkSpinButton *) Range,
00609 Value);
00610 }
00611 }
00612
00613 }
00614
00615 vTempFloat *
00616 vapiGtkOptionsGetOptionByInterfaceType (GtkWidget * Range,
00617 vInterfaceType interfaceType,
00618 vBoolean ISint)
00619 {
00620 vTempFloat *Value = malloc (sizeof (vTempFloat));
00621
00622 if (interfaceType == vBar || !interfaceType)
00623 {
00624 if (ISint)
00625 {
00626 Value->intValue =
00627 (int) gtk_range_get_value ((GtkRange *)
00628 Range);
00629 }
00630 else
00631 {
00632 Value->value =
00633 gtk_range_get_value ((GtkRange *) Range);
00634 }
00635
00636 }
00637 if (interfaceType == vSpin)
00638 {
00639 if (ISint)
00640 {
00641 Value->intValue =
00642 gtk_spin_button_get_value_as_int ((GtkSpinButton *) Range);
00643 }
00644 else
00645 {
00646 Value->value =
00647 gtk_spin_button_get_value ((GtkSpinButton *)
00648 Range);
00649 }
00650
00651 }
00652
00653 return Value;
00654
00655 }
00656
00657 void
00658 vapiGtkOptionsGetOptions (vOptions * options,
00659 vOptionsSettings * OptionsSettings,
00660 vGtkOptionsCustomGet CustomGet,
00661 GList ** OptionsData)
00662 {
00663 vTempFloat *tempFloat;
00664 int i=0, j;
00665
00666 if (CustomGet!=NULL)
00667 {
00668 i= CustomGet(options,
00669 OptionsSettings, OptionsData);
00670 }
00671
00672 if (OptionsSettings->floatsNumber)
00673 {
00674 for (j = 0; j < OptionsSettings->floatsNumber; j++)
00675 {
00676 tempFloat = (vTempFloat *)
00677 vapiGtkOptionsGetOptionByInterfaceType
00678 (g_list_nth_data
00679 (*OptionsData, i),
00680 OptionsSettings->floats[j].
00681 interfaceType, vFALSE);
00682 options->floats[j] = tempFloat->value;
00683 v_debug ("OPTIONS FLOAT VALOR: %f", options->floats[j]);
00684 free (tempFloat);
00685 ++i;
00686 }
00687 }
00688 if (OptionsSettings->intsNumber)
00689 {
00690 for (j = 0; j < OptionsSettings->intsNumber; j++)
00691 {
00692
00693 tempFloat = (vTempFloat *)
00694 vapiGtkOptionsGetOptionByInterfaceType
00695 (g_list_nth_data
00696 (*OptionsData, i),
00697 OptionsSettings->ints[j].
00698 interfaceType, vTRUE);
00699 options->ints[j] = tempFloat->intValue;
00700 v_debug ("OPTIONS VALOR: %d", options->ints[j]);
00701 free (tempFloat);
00702 ++i;
00703 }
00704 }
00705 if (OptionsSettings->charsNumber)
00706 {
00707 for (j = 0; j < OptionsSettings->charsNumber; j++)
00708 {
00709 options->chars[j].ch =
00710 vapiReturnStringPointer (gtk_entry_get_text
00711 ((GtkEntry *)
00712 g_list_nth_data
00713 (*OptionsData, i)));
00714 v_debug ("GET O CHAR: %s.", options->chars[j].ch);
00715 ++i;
00716 }
00717 }
00718 if (OptionsSettings->chooseNumber)
00719 {
00720 for (j = 0; j < OptionsSettings->chooseNumber; j++)
00721 {
00722
00723 options->choices[j] =
00724 gtk_combo_box_get_active ((GtkComboBox *)
00725 g_list_nth_data
00726 (*OptionsData, i));
00727 ++i;
00728 }
00729 }
00730 if (OptionsSettings->booleansNumber)
00731 {
00732 for (j = 0; j < OptionsSettings->booleansNumber; j++)
00733 {
00734
00735 options->booleans[j] =
00736 gtk_toggle_button_get_active ((GtkToggleButton
00737 *)
00738 g_list_nth_data
00739 (*OptionsData,
00740 i));
00741 ++i;
00742 }
00743 }
00744 }