GtkWidget *
do_css_accordion (GtkWidget *do_widget)
{
  if (!window)
    {
      GtkWidget *container, *child;
      GtkStyleProvider *provider;
      GBytes *bytes;
      gsize data_size;
      const guint8 *data;

      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
      gtk_window_set_default_size (GTK_WINDOW (window), 600, 300);
      g_signal_connect (window, "destroy",
                        G_CALLBACK (gtk_widget_destroyed), &window);
      
      container = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
      gtk_widget_set_halign (container, GTK_ALIGN_CENTER);
      gtk_widget_set_valign (container, GTK_ALIGN_CENTER);
      gtk_container_add (GTK_CONTAINER (window), container);

      child = gtk_button_new_with_label ("This");
      gtk_container_add (GTK_CONTAINER (container), child);

      child = gtk_button_new_with_label ("Is");
      gtk_container_add (GTK_CONTAINER (container), child);

      child = gtk_button_new_with_label ("A");
      gtk_container_add (GTK_CONTAINER (container), child);

      child = gtk_button_new_with_label ("CSS");
      gtk_container_add (GTK_CONTAINER (container), child);

      child = gtk_button_new_with_label ("Accordion");
      gtk_container_add (GTK_CONTAINER (container), child);

      child = gtk_button_new_with_label (":-)");
      gtk_container_add (GTK_CONTAINER (container), child);

      provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());
      bytes = g_resources_lookup_data ("/css_accordion/css_accordion.css", 0, NULL);
      data = g_bytes_get_data (bytes, &data_size);

      gtk_css_provider_load_from_data (GTK_CSS_PROVIDER (provider), (gchar *)data, data_size, NULL);
      g_bytes_unref (bytes);

      apply_css (window, provider);
    }

  if (!gtk_widget_get_visible (window))
    gtk_widget_show_all (window);
  else
    {
      gtk_widget_destroy (window);
      window = NULL;
    }

  return window;
}
示例#2
0
void CalendarDatePrivate::updateYearView(gboolean isForceLoad, GTimeSpan changed) {
    if (NULL == m_swipeBox[VIEWTYPE_YEAR]) {
        initYearView();
    }

    int row = 0;
    int col = 0;
    int rowCount = 3;
    int colCount = 4;
    char buffer[32];
    int selectedYear = m_selectedYear;
    int cellWidth = MAIN_BOX_DEFAULT_WIDTH / colCount;
    int cellHeight = MAIN_BOX_DEFAULT_WIDTH / rowCount;
    GDateTime* nowDate = g_date_time_new_now_local();
    int nowYear = g_date_time_get_year(nowDate);

    int beginYear = ((int)selectedYear / 10) * 10 - 1;
    int endYear = ((int)selectedYear / 10 + 1) * 10;
    int iterYear = beginYear;

    m_viewType = VIEWTYPE_YEAR;

    g_snprintf(buffer, sizeof(buffer), "%d-%d", beginYear, endYear);
    gtk_button_set_label(GTK_BUTTON(m_viewTypeSwitch), buffer);

    for (row = 0; row < rowCount; ++row) {
        for (col = 0; col < colCount; ++col) {
            int index = row * colCount + col;
            iterYear = beginYear + index;
            if (NULL != m_yearItem[index]) {

                m_yearItem[index]->addStyleClass("calendar-year-base");
                m_yearItem[index]->addStyleClass("calendar-year");
                if (nowYear == iterYear) {
                    m_yearItem[index]->removeStyleClass("calendar-other-x-year");
                    m_yearItem[index]->addStyleClass("calendar-current-year");
                } else if (((int)(iterYear / 10)) != ((int)(selectedYear / 10))) {
                    m_yearItem[index]->removeStyleClass("calendar-current-year");
                    m_yearItem[index]->addStyleClass("calendar-other-x-year");
                }

                m_yearItem[index]->setValue(iterYear);
            }
        }
    }

    if (NULL != m_swipeBox[VIEWTYPE_MONTH]) {
        gtk_widget_hide(m_swipeBox[VIEWTYPE_MONTH]);
    }

    if (NULL != m_swipeBox[VIEWTYPE_YEAR]) {
        gtk_widget_show_all(m_swipeBox[VIEWTYPE_YEAR]);
    }

    if (NULL != m_swipeBox[VIEWTYPE_DAY]) {
        gtk_widget_hide(m_swipeBox[VIEWTYPE_DAY]);
    }

    apply_css(GTK_WIDGET(m_actor), m_provider);
}
示例#3
0
GtkWidget *
do_css_basics (GtkWidget *do_widget)
{
  if (!window)
    {
      GtkWidget *container, *child;
      GtkStyleProvider *provider;
      GtkTextBuffer *text;
      GBytes *bytes;

      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
      gtk_window_set_title (GTK_WINDOW (window), "CSS Basics");
      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
      gtk_window_set_default_size (GTK_WINDOW (window), 400, 300);
      g_signal_connect (window, "destroy",
                        G_CALLBACK (gtk_widget_destroyed), &window);

      text = gtk_text_buffer_new (NULL);
      gtk_text_buffer_create_tag (text,
                                  "warning",
                                  "underline", PANGO_UNDERLINE_SINGLE,
                                  NULL);
      gtk_text_buffer_create_tag (text,
                                  "error",
                                  "underline", PANGO_UNDERLINE_ERROR,
                                  NULL);

      provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());

      container = gtk_scrolled_window_new (NULL, NULL);
      gtk_container_add (GTK_CONTAINER (window), container);
      child = gtk_text_view_new_with_buffer (text);
      gtk_container_add (GTK_CONTAINER (container), child);
      g_signal_connect (text, "changed",
                        G_CALLBACK (css_text_changed), provider);

      bytes = g_resources_lookup_data ("/css_basics/css_basics.css", 0, NULL);
      gtk_text_buffer_set_text (text, g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes));
      g_bytes_unref (bytes);

      g_signal_connect (provider,
                        "parsing-error",
                        G_CALLBACK (show_parsing_error),
                        gtk_text_view_get_buffer (GTK_TEXT_VIEW (child)));

      apply_css (window, provider);
    }

  if (!gtk_widget_get_visible (window))
    gtk_widget_show_all (window);
  else
    {
      gtk_widget_destroy (window);
      window = NULL;
    }

  return window;
}
示例#4
0
void CalendarDatePrivate::updateMonthView(gboolean isForceLoad, GTimeSpan changed) {
    if (NULL == m_swipeBox[VIEWTYPE_MONTH]) {
        initMonthView();
    }

    int row = 0;
    int col = 0;
    int rowCount = 3;
    int colCount = 4;
    int cellWidth = MAIN_BOX_DEFAULT_WIDTH / colCount;
    int cellHeight = MAIN_BOX_DEFAULT_WIDTH / rowCount;
    GDateTime* nowDate = g_date_time_new_now_local();

    m_viewType = VIEWTYPE_MONTH;

    GDateTime* selectedDate = g_date_time_new_local(m_selectedYear, m_selectedMonth, m_selectedDayOfMonth, 1, 1, 1);
    gchar* dateLabelText = g_date_time_format(selectedDate, C_("calendar heading", "%Y"));
    gtk_button_set_label(GTK_BUTTON(m_viewTypeSwitch), dateLabelText);
    g_date_time_unref(selectedDate);
    g_free(dateLabelText);

    for (row = 0; row < rowCount; ++row) {
        for (col = 0; col < colCount; ++col) {
            int index = row * colCount + col;
            if (NULL != m_monthItem[index]) {

                m_monthItem[index]->addStyleClass("calendar-month-base");
                m_monthItem[index]->addStyleClass("calendar-month");
                GDateTime* currentDate = g_date_time_new_local(m_selectedYear, index + 1, 1, 0, 0, 0);
                if (isTheSameMonth(nowDate, currentDate)) {
                    m_monthItem[index]->addStyleClass("calendar-current-month");
                } else {
                    m_monthItem[index]->removeStyleClass("calendar-current-month");
                }
                g_date_time_unref(currentDate);

                m_monthItem[index]->setValue(index + 1);
            }
        }
    }

    if (NULL != m_swipeBox[VIEWTYPE_MONTH]) {
        gtk_widget_show_all(m_swipeBox[VIEWTYPE_MONTH]);
    }

    if (NULL != m_swipeBox[VIEWTYPE_YEAR]) {
        gtk_widget_hide(m_swipeBox[VIEWTYPE_YEAR]);
    }
    if (NULL != m_swipeBox[VIEWTYPE_DAY]) {
        gtk_widget_hide(m_swipeBox[VIEWTYPE_DAY]);
    }

    apply_css(GTK_WIDGET(m_actor), m_provider);
}
示例#5
0
GtkWidget *
do_css_multiplebgs (GtkWidget *do_widget)
{
  if (!window)
    {
      GtkWidget *paned, *container, *child;
      GtkStyleProvider *provider;
      GtkTextBuffer *text;
      GBytes *bytes;

      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
      gtk_window_set_default_size (GTK_WINDOW (window), 400, 300);
      g_signal_connect (window, "destroy",
                        G_CALLBACK (gtk_widget_destroyed), &window);

      container = gtk_overlay_new ();
      gtk_widget_add_events (container,
                             GDK_ENTER_NOTIFY_MASK |
                             GDK_LEAVE_NOTIFY_MASK |
                             GDK_POINTER_MOTION_MASK);
      gtk_container_add (GTK_CONTAINER (window), container);

      child = gtk_drawing_area_new ();
      gtk_widget_set_name (child, "canvas");
      g_signal_connect (child, "draw",
                        G_CALLBACK (drawing_area_draw), NULL);
      gtk_container_add (GTK_CONTAINER (container), child);

      child = gtk_button_new ();
      gtk_widget_add_events (child,
                             GDK_ENTER_NOTIFY_MASK |
                             GDK_LEAVE_NOTIFY_MASK |
                             GDK_POINTER_MOTION_MASK);
      gtk_overlay_add_overlay (GTK_OVERLAY (container), child);
      gtk_widget_set_name (child, "bricks-button");
      gtk_widget_set_halign (child, GTK_ALIGN_CENTER);
      gtk_widget_set_valign (child, GTK_ALIGN_CENTER);
      gtk_widget_set_size_request (child, 200, 80);

      paned = gtk_paned_new (GTK_ORIENTATION_VERTICAL);
      gtk_overlay_add_overlay (GTK_OVERLAY (container), paned);

      /* Need a filler so we get a handle */
      child = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
      gtk_container_add (GTK_CONTAINER (paned), child);

      text = gtk_text_buffer_new (NULL);
      gtk_text_buffer_create_tag (text,
                                  "warning",
                                  "underline", PANGO_UNDERLINE_SINGLE,
                                  NULL);
      gtk_text_buffer_create_tag (text,
                                  "error",
                                  "underline", PANGO_UNDERLINE_ERROR,
                                  NULL);

      provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());

      container = gtk_scrolled_window_new (NULL, NULL);
      gtk_container_add (GTK_CONTAINER (paned), container);
      child = gtk_text_view_new_with_buffer (text);
      gtk_container_add (GTK_CONTAINER (container), child);
      g_signal_connect (text,
                        "changed",
                        G_CALLBACK (css_text_changed),
                        provider);

      bytes = g_resources_lookup_data ("/css_multiplebgs/gtk.css", 0, NULL);
      gtk_text_buffer_set_text (text, g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes));

      g_signal_connect (provider,
                        "parsing-error",
                        G_CALLBACK (show_parsing_error),
                        gtk_text_view_get_buffer (GTK_TEXT_VIEW (child)));

      apply_css (window, provider);
    }

  if (!gtk_widget_get_visible (window))
    gtk_widget_show_all (window);
  else
    {
      gtk_widget_destroy (window);
      window = NULL;
    }

  return window;
}
示例#6
0
GtkWidget *
do_css_pixbufs (GtkWidget *do_widget)
{
  static GtkWidget *window = NULL;

  if (!window)
    {
      GtkWidget *paned, *container, *child;
      GtkStyleProvider *provider;
      GtkTextBuffer *text;
      GBytes *bytes;

      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
      gtk_window_set_title (GTK_WINDOW (window), "Animated Backgrounds");
      gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
      gtk_window_set_default_size (GTK_WINDOW (window), 400, 300);
      g_signal_connect (window, "destroy",
                        G_CALLBACK (gtk_widget_destroyed), &window);

      paned = gtk_paned_new (GTK_ORIENTATION_VERTICAL);
      gtk_container_add (GTK_CONTAINER (window), paned);

      /* Need a filler so we get a handle */
      child = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
      gtk_container_add (GTK_CONTAINER (paned), child);

      text = gtk_text_buffer_new (NULL);
      gtk_text_buffer_create_tag (text,
                                  "warning",
                                  "underline", PANGO_UNDERLINE_SINGLE,
                                  NULL);
      gtk_text_buffer_create_tag (text,
                                  "error",
                                  "underline", PANGO_UNDERLINE_ERROR,
                                  NULL);

      provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());

      container = gtk_scrolled_window_new (NULL, NULL);
      gtk_container_add (GTK_CONTAINER (paned), container);
      child = gtk_text_view_new_with_buffer (text);
      gtk_container_add (GTK_CONTAINER (container), child);
      g_signal_connect (text, "changed",
                        G_CALLBACK (css_text_changed), provider);

      bytes = g_resources_lookup_data ("/css_pixbufs/gtk.css", 0, NULL);
      gtk_text_buffer_set_text (text, g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes));
      g_bytes_unref (bytes);

      g_signal_connect (provider,
                        "parsing-error",
                        G_CALLBACK (show_parsing_error),
                        gtk_text_view_get_buffer (GTK_TEXT_VIEW (child)));

      apply_css (window, provider);
    }

  if (!gtk_widget_get_visible (window))
    gtk_widget_show (window);
  else
    gtk_widget_destroy (window);

  return window;
}
示例#7
0
void CalendarDatePrivate::updateDayView(gboolean isForceLoad, GTimeSpan changed) {
    if (NULL == m_swipeBox[VIEWTYPE_DAY]) {
        initDayView();
    }

    ComputeDays();
    gint rowCount = 7;
    gint offsetCols = (m_isShowWeekNum ? 1 : 0);
    gint colCount = 7 + offsetCols;
    int row = 0;
    int col = 0;

    m_viewType = VIEWTYPE_DAY;

    GDateTime* selectedDate = g_date_time_new_local(m_selectedYear, m_selectedMonth, m_selectedDayOfMonth, 1, 1, 1);
    gchar* dateLabelText = g_date_time_format(selectedDate, C_("calendar heading", "%Y, %b"));
    gtk_button_set_label(GTK_BUTTON(m_viewTypeSwitch), dateLabelText);
    g_date_time_unref(selectedDate);
    g_free(dateLabelText);

    for (col = 0; col < colCount; ++col) {
        for (row = 0; row < rowCount; ++row) {
            if (m_isShowWeekNum && (0 == col)) {
                if (0 == row) {
                    // do nothing
                } else {
                    // do nothing
                } // end: if (0 == row)
            } else {
                if (0 == row) {
                } else {
                    if (NULL != m_dayItem[row - 1][col - offsetCols]) {
                        GDateTime* nowDate = g_date_time_new_now_local();
                        m_dayItem[row - 1][col - offsetCols]->addStyleClass("calendar-day-base");
                        m_dayItem[row - 1][col - offsetCols]->addStyleClass("calendar-day");
                        if (isWorkDay(col - offsetCols + m_weekStart)) {
                            m_dayItem[row - 1][col - offsetCols]->addStyleClass("calendar-work-day");
                        } else {
                            m_dayItem[row - 1][col - offsetCols]->addStyleClass("calendar-nonwork-day");
                        }


                        switch (m_dayMonth[row - 1][col - offsetCols]) {
                        case MONTH_CURRENT: {
                            GDateTime * currentDate = g_date_time_new_local(m_selectedYear, m_selectedMonth, m_day[row - 1][col - offsetCols],
                                                                            0, 0, 0);
                            if (isTheSameDate(nowDate, currentDate)) {
                                m_dayItem[row - 1][col - offsetCols]->addStyleClass("calendar-today");
                            } else {
                                m_dayItem[row - 1][col - offsetCols]->removeStyleClass("calendar-today");
                            }
                            g_date_time_unref(currentDate);
                        }
                            break;
                        case MONTH_PREV:
                        case MONTH_NEXT:
                             m_dayItem[row - 1][col - offsetCols]->addStyleClass("calendar-other-month-day");
                            break;
                        default:
                            break;
                        }
                        m_dayItem[row - 1][col - offsetCols]->setValue(m_day[row - 1][col - offsetCols]);
                    }
                }
            } // end: if (priv->show_week_num && (0 == col))
        } // end: for row
    } // end: for col

    if (NULL != m_swipeBox[VIEWTYPE_MONTH]) {
        gtk_widget_hide(m_swipeBox[VIEWTYPE_MONTH]);
    }

    if (NULL != m_swipeBox[VIEWTYPE_YEAR]) {
        gtk_widget_hide(m_swipeBox[VIEWTYPE_YEAR]);
    }

    if (NULL != m_swipeBox[VIEWTYPE_DAY]) {
        gtk_widget_show_all(m_swipeBox[VIEWTYPE_DAY]);
    }

    apply_css(GTK_WIDGET(m_actor), m_provider);
}