~mdoyen/homebank/5.3.x

« back to all changes in this revision

Viewing changes to src/ui-widgets.c

  • Committer: Maxime Doyen
  • Date: 2019-05-25 07:29:57 UTC
  • Revision ID: homebank@free.fr-20190525072957-35m6fho2msvt86ko
5.2.6 release

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
42
42
 
43
43
 
44
 
extern gchar *CYA_FLT_RANGE[];
45
 
 
46
 
 
 
44
extern HbKvData CYA_FLT_RANGE[];
47
45
 
48
46
 
49
47
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
50
48
 
51
 
 
52
 
 
 
49
//TODO: only WEIGHT & SCALE are used for now
53
50
void
54
51
gimp_label_set_attributes (GtkLabel *label,
55
52
                           ...)
579
576
}
580
577
 
581
578
 
 
579
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
 
580
 
 
581
 
 
582
gint hbtk_radio_button_get_active (GtkContainer *container)
 
583
{
 
584
GList *lchild, *list;
 
585
GtkWidget *radio;
 
586
gint i, retval = 0;
 
587
 
 
588
        if(!GTK_IS_CONTAINER(container))
 
589
                return -1;
 
590
 
 
591
        lchild = list = gtk_container_get_children (container);
 
592
        for(i=0;list != NULL;i++)
 
593
        {
 
594
                radio = list->data;
 
595
                if(GTK_IS_TOGGLE_BUTTON(radio))
 
596
                {
 
597
                        if( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio)) == TRUE )
 
598
                        {
 
599
                                retval = i;
 
600
                                break;
 
601
                        }
 
602
                }
 
603
                list = g_list_next(list);
 
604
        }
 
605
        g_list_free(lchild);
 
606
        
 
607
        return retval;
 
608
}
 
609
 
 
610
 
 
611
void hbtk_radio_button_set_active (GtkContainer *container, gint active)
 
612
{
 
613
GList *lchild, *list;
 
614
GtkWidget *radio;
 
615
 
 
616
        if(!GTK_IS_CONTAINER(container))
 
617
                return;
 
618
 
 
619
        lchild = list = gtk_container_get_children (container);
 
620
        radio = g_list_nth_data (list, active);
 
621
        if(radio != NULL && GTK_IS_TOGGLE_BUTTON(radio))
 
622
        {
 
623
                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(radio), TRUE);
 
624
        }
 
625
        g_list_free(lchild);
 
626
}
 
627
 
 
628
 
 
629
GtkWidget *hbtk_radio_button_get_nth (GtkContainer *container, gint nth)
 
630
{
 
631
GList *lchild, *list;
 
632
GtkWidget *radio;
 
633
 
 
634
        if(!GTK_IS_CONTAINER(container))
 
635
                return NULL;
 
636
 
 
637
        lchild = list = gtk_container_get_children (container);
 
638
        radio = g_list_nth_data (list, nth);
 
639
        g_list_free(lchild);
 
640
        return radio;   //may return NULL
 
641
}
 
642
 
 
643
 
 
644
void hbtk_radio_button_unblock_by_func(GtkContainer *container, GCallback c_handler, gpointer data)
 
645
{
 
646
GList *lchild, *list;
 
647
GtkWidget *radio;
 
648
gint i;
 
649
 
 
650
        if(!GTK_IS_CONTAINER(container))
 
651
                return;
 
652
 
 
653
        lchild = list = gtk_container_get_children (container);
 
654
        for(i=0;list != NULL;i++)
 
655
        {
 
656
                radio = list->data;
 
657
                if(GTK_IS_TOGGLE_BUTTON(radio))
 
658
                {
 
659
                        g_signal_handlers_unblock_by_func (radio, c_handler, data);
 
660
                }
 
661
                list = g_list_next(list);
 
662
        }
 
663
        g_list_free(lchild);
 
664
}
 
665
 
 
666
 
 
667
void hbtk_radio_button_block_by_func(GtkContainer *container, GCallback c_handler, gpointer data)
 
668
{
 
669
GList *lchild, *list;
 
670
GtkWidget *radio;
 
671
gint i;
 
672
 
 
673
        if(!GTK_IS_CONTAINER(container))
 
674
                return;
 
675
 
 
676
        lchild = list = gtk_container_get_children (container);
 
677
        for(i=0;list != NULL;i++)
 
678
        {
 
679
                radio = list->data;
 
680
                if(GTK_IS_TOGGLE_BUTTON(radio))
 
681
                {
 
682
                        g_signal_handlers_block_by_func (radio, c_handler, data);
 
683
                }
 
684
                list = g_list_next(list);
 
685
        }
 
686
        g_list_free(lchild);
 
687
}
 
688
 
 
689
 
 
690
void hbtk_radio_button_connect(GtkContainer *container, const gchar *detailed_signal, GCallback c_handler, gpointer data)
 
691
{
 
692
GList *lchild, *list;
 
693
GtkWidget *radio;
 
694
gint i;
 
695
 
 
696
        if(!GTK_IS_CONTAINER(container))
 
697
                return;
 
698
 
 
699
        lchild = list = gtk_container_get_children (container);
 
700
        for(i=0;list != NULL;i++)
 
701
        {
 
702
                radio = list->data;
 
703
                if(GTK_IS_TOGGLE_BUTTON(radio))
 
704
                {
 
705
                        g_signal_connect (radio, "toggled", c_handler, data);
 
706
                }
 
707
                list = g_list_next(list);
 
708
        }
 
709
        g_list_free(lchild);
 
710
 
 
711
}
 
712
 
 
713
 
 
714
GtkWidget *hbtk_radio_button_new (gchar **items, gboolean buttonstyle)
 
715
{
 
716
GtkWidget *box, *button, *newbutton;
 
717
guint i;
 
718
 
 
719
        box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
 
720
 
 
721
    button = gtk_radio_button_new_with_label (NULL, _(items[0]));
 
722
        gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), !buttonstyle);
 
723
    gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
 
724
        for (i = 1; items[i] != NULL; i++)
 
725
        {
 
726
                newbutton = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (button), _(items[i]));
 
727
                gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (newbutton), !buttonstyle);
 
728
            gtk_box_pack_start (GTK_BOX (box), newbutton, FALSE, FALSE, 0);
 
729
        }
 
730
 
 
731
        if(buttonstyle)
 
732
        {
 
733
                gtk_style_context_add_class (gtk_widget_get_style_context (box), GTK_STYLE_CLASS_LINKED);
 
734
                gtk_style_context_add_class (gtk_widget_get_style_context (box), GTK_STYLE_CLASS_RAISED);
 
735
        }
 
736
        
 
737
        return box;
 
738
}
 
739
 
 
740
 
 
741
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
 
742
 
 
743
 
582
744
static gboolean
583
745
is_separator (GtkTreeModel *model,
584
746
              GtkTreeIter  *iter,
602
764
  return retval;
603
765
}
604
766
 
605
 
static void
606
 
set_sensitive (GtkCellLayout   *cell_layout,
607
 
               GtkCellRenderer *cell,
608
 
               GtkTreeModel    *tree_model,
609
 
               GtkTreeIter     *iter,
610
 
               gpointer         data)
611
 
{
612
 
GtkTreePath *path;
613
 
gint *indices;
614
 
gboolean sensitive;
615
 
 
616
 
        path = gtk_tree_model_get_path (tree_model, iter);
617
 
        indices = gtk_tree_path_get_indices (path);
618
 
        sensitive = indices[0] != FLT_RANGE_OTHER;  
619
 
        gtk_tree_path_free (path);
620
 
 
621
 
        g_object_set (cell, "sensitive", sensitive, NULL);
622
 
}
623
 
 
624
767
 
625
768
GtkWidget *make_cycle(GtkWidget *label, gchar **items)
626
769
{
646
789
}
647
790
 
648
791
 
649
 
GtkWidget *make_daterange(GtkWidget *label, gboolean custom)
650
 
{
651
 
GtkWidget *combobox;
652
 
GList *renderers, *list;
653
 
GtkCellRenderer *renderer;
654
 
gchar **items = CYA_FLT_RANGE;
655
 
guint i;
656
 
 
657
 
        combobox = gtk_combo_box_text_new ();
658
 
 
659
 
        for (i = 0; items[i] != NULL; i++)
660
 
        {
661
 
                if(*items[i] != 0)
662
 
                        gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(combobox), _(items[i]));
663
 
                else
664
 
                        gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(combobox), "");
665
 
        }
666
 
        gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), 0);
667
 
 
668
 
        if(label)
669
 
                gtk_label_set_mnemonic_widget (GTK_LABEL(label), combobox);
670
 
 
671
 
        // special stuffs
672
 
        renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT(combobox));
673
 
        if(g_list_length(renderers) == 1 && custom == FALSE)
674
 
        {
675
 
                list = g_list_first(renderers);
676
 
                renderer = list->data;
677
 
        
678
 
        
679
 
                gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox),
680
 
                                                renderer,
681
 
                                                set_sensitive,
682
 
                                                NULL, NULL);
683
 
        }       
684
 
        g_list_free(renderers);
685
 
 
686
 
        gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combobox), is_separator, NULL, NULL);
687
 
 
688
 
        return combobox;
689
 
}
690
 
 
691
 
 
692
792
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
693
793
 
 
794
 
694
795
#define HB_KV_BUFFER_MAX_LEN    8
695
796
#define HB_KV_ITEMS_MAX_LEN             32
696
797
 
807
908
 
808
909
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
809
910
 
810
 
 
811
 
gint hbtk_radio_get_active (GtkContainer *container)
812
 
{
813
 
GList *lchild, *list;
814
 
GtkWidget *radio;
815
 
gint i, retval = 0;
816
 
 
817
 
        if(!GTK_IS_CONTAINER(container))
818
 
                return -1;
819
 
 
820
 
        lchild = list = gtk_container_get_children (container);
821
 
        for(i=0;list != NULL;i++)
822
 
        {
823
 
                radio = list->data;
824
 
                if(GTK_IS_TOGGLE_BUTTON(radio))
825
 
                {
826
 
                        if( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio)) == TRUE )
827
 
                        {
828
 
                                retval = i;
829
 
                                break;
830
 
                        }
831
 
                }
832
 
                list = g_list_next(list);
833
 
        }
834
 
        g_list_free(lchild);
835
 
        
836
 
        return retval;
837
 
}
838
 
 
839
 
 
840
 
void hbtk_radio_set_active (GtkContainer *container, gint active)
841
 
{
842
 
GList *lchild, *list;
843
 
GtkWidget *radio;
844
 
 
845
 
        if(!GTK_IS_CONTAINER(container))
846
 
                return;
847
 
 
848
 
        lchild = list = gtk_container_get_children (container);
849
 
        radio = g_list_nth_data (list, active);
850
 
        if(radio != NULL && GTK_IS_TOGGLE_BUTTON(radio))
851
 
        {
852
 
                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(radio), TRUE);
853
 
        }
854
 
        g_list_free(lchild);
855
 
}
856
 
 
857
 
 
858
 
GtkWidget *hbtk_radio_get_nth (GtkContainer *container, gint nth)
859
 
{
860
 
GList *lchild, *list;
861
 
GtkWidget *radio;
862
 
 
863
 
        if(!GTK_IS_CONTAINER(container))
864
 
                return NULL;
865
 
 
866
 
        lchild = list = gtk_container_get_children (container);
867
 
        radio = g_list_nth_data (list, nth);
868
 
        g_list_free(lchild);
869
 
        return radio;   //may return NULL
870
 
}
871
 
 
872
 
 
873
 
void hbtk_radio_connect(GtkContainer *container, const gchar *detailed_signal, GCallback c_handler, gpointer data)
874
 
{
875
 
GList *lchild, *list;
876
 
GtkWidget *radio;
877
 
gint i;
878
 
 
879
 
        if(!GTK_IS_CONTAINER(container))
880
 
                return;
881
 
 
882
 
        lchild = list = gtk_container_get_children (container);
883
 
        for(i=0;list != NULL;i++)
884
 
        {
885
 
                radio = list->data;
886
 
                if(GTK_IS_TOGGLE_BUTTON(radio))
887
 
                {
888
 
                        g_signal_connect (radio, "toggled", c_handler, data);
889
 
                }
890
 
                list = g_list_next(list);
891
 
        }
892
 
        g_list_free(lchild);
893
 
 
894
 
}
895
 
 
896
 
 
897
 
GtkWidget *hbtk_radio_new (gchar **items, gboolean buttonstyle)
898
 
{
899
 
GtkWidget *box, *button, *newbutton;
900
 
guint i;
901
 
 
902
 
        box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
903
 
 
904
 
    button = gtk_radio_button_new_with_label (NULL, _(items[0]));
905
 
        gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), !buttonstyle);
906
 
    gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
907
 
        for (i = 1; items[i] != NULL; i++)
908
 
        {
909
 
                newbutton = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (button), _(items[i]));
910
 
                gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (newbutton), !buttonstyle);
911
 
            gtk_box_pack_start (GTK_BOX (box), newbutton, FALSE, FALSE, 0);
912
 
        }
913
 
 
914
 
        if(buttonstyle)
915
 
        {
916
 
                gtk_style_context_add_class (gtk_widget_get_style_context (box), GTK_STYLE_CLASS_LINKED);
917
 
                gtk_style_context_add_class (gtk_widget_get_style_context (box), GTK_STYLE_CLASS_RAISED);
918
 
        }
919
 
        
920
 
        return box;
 
911
static void
 
912
set_sensitive (GtkCellLayout   *cell_layout,
 
913
               GtkCellRenderer *cell,
 
914
               GtkTreeModel    *tree_model,
 
915
               GtkTreeIter     *iter,
 
916
               gpointer         data)
 
917
{
 
918
GtkTreePath *path;
 
919
gint *indices;
 
920
gboolean sensitive;
 
921
 
 
922
        path = gtk_tree_model_get_path (tree_model, iter);
 
923
        indices = gtk_tree_path_get_indices (path);
 
924
        sensitive = indices[0] != FLT_RANGE_OTHER;  
 
925
        gtk_tree_path_free (path);
 
926
 
 
927
        g_object_set (cell, "sensitive", sensitive, NULL);
 
928
}
 
929
 
 
930
 
 
931
 
 
932
GtkWidget *make_daterange(GtkWidget *label, guint dspmode)
 
933
{
 
934
GtkWidget *combobox = hbtk_combo_box_new(label);
 
935
GList *renderers, *list;
 
936
HbKvData *tmp, *kvdata = CYA_FLT_RANGE;
 
937
guint32 i;
 
938
 
 
939
        for(i=0;i<HB_KV_ITEMS_MAX_LEN;i++)
 
940
        {
 
941
                tmp = &kvdata[i];
 
942
                if( tmp->name == NULL )
 
943
                        break;
 
944
 
 
945
                if( (tmp->key == FLT_RANGE_OTHER) )
 
946
                {
 
947
                        if( dspmode == DATE_RANGE_CUSTOM_DISABLE )
 
948
                        {
 
949
                                renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT(combobox));
 
950
                                if(g_list_length(renderers) == 1)
 
951
                                {
 
952
                                        list = g_list_first(renderers);
 
953
                                        gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox),
 
954
                                                                        list->data,
 
955
                                                                        set_sensitive,
 
956
                                                                        NULL, NULL);
 
957
                                }       
 
958
                                g_list_free(renderers);
 
959
                        }
 
960
                        else
 
961
                        if( dspmode == DATE_RANGE_CUSTOM_HIDE )
 
962
                        {
 
963
                                //if hide, we do not show it
 
964
                                i++;
 
965
                                continue;
 
966
                        }
 
967
                }
 
968
 
 
969
                hbtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(combobox), tmp->key, (*tmp->name != 0) ? (gchar *)_(tmp->name) : (gchar *)"");
 
970
        }
 
971
 
 
972
        gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), 0);
 
973
        gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combobox), hbtk_combo_box_is_separator, NULL, NULL);
 
974
 
 
975
        return combobox;
921
976
}
922
977
 
923
978