⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sec-calendar.html

📁 gtk的教材和问答集
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<HTML><HEAD><TITLE>Calendar</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.49"><LINKREL="HOME"TITLE="GTK+ 1.2 Tutorial"HREF="gtk-tut.html"><LINKREL="UP"TITLE="Miscellaneous Widgets"HREF="ch-miscwidgets.html"><LINKREL="PREVIOUS"TITLE="Combo Box"HREF="sec-combobox.html"><LINKREL="NEXT"TITLE="Color Selection"HREF="sec-colorselection.html"></HEAD></head><body bgcolor="#FFFFFF" marginheight=0 marginwidth=0 width="100%"><table cellspacing=6 border=0 cellpadding=0 width="100%">  <tr>    <td bgcolor="#FFFFFF" valign=top nowrap>    <centeR><A HREF="/"><img src="/images/gtk-logo-rgb.gif" width=107 height=140 border=0></A>      <font face="helvetica,lucidia" color="#000000"><BR><BR><b>GTK+<BR>The GIMP Toolkit</b></center><BR><table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>General</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/">Introduction</A><BR><A HREF="/screenshots/">Screenshots</A><br><A HREF="/download/">Download</A><br><A HREF="/mailinglists.html">Mailing Lists</A><BR><A HREF="/bindings.html">Language Bindings</A><BR><A HREF="http://gtk.themes.org/">Themes</A><BR><A HREF="/bugs.html">Bug Tracker</A><BR></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Documentation</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/faq/">FAQ</A><br><A HREF="/tutorial/">Tutorial</A><BR><A HREF="/api/">API Reference</A><br><A HREF="/books.html">Published Books</A><BR></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Projects</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.pango.org/">Pango</A><BR><A HREF="http://sources.redhat.com/inti/">Inti</A><BR><A HREF="http://www.gnome.org/">GNOME</A><BR><A HREF="http://user.sgic.fi/~tml/gimp/win32/">GTK+ for Win32</A><br><A HREF="http://people.redhat.com/sopwith/gtkfb/">GtkFB (Framebuffer)</A><br><A HREF="http://www.directfb.org/gtk.xml">GTK+ on DirectFB</A><BR><A HREF="/beos/">GTK+ for BeOS</A></td></tr></table></td></tr></table><BR>  <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B><B>Applications</B></B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.gimp.org/">GIMP</A><BR><A HREF="http://www.abiword.org/">Abiword</A><BR><A HREF="http://www.lysator.liu.se/~alla/dia/dia.html">Dia</A><BR><A HREF="http://glade.pn.org/">Glade</A><BR><A HREF="http://www.gnucash.org/">GnuCash</A><BR><A HREF="http://www.gnome.org/projects/gnumeric/">Gnumeric</A><BR><BR><A HREF="http://www.gnome.org/applist/">GNOME Software Map</A><br></td></tr></table></td></tr></table><BR>      </td>  <td bgcolor="#ffffff" valign=top width="99%"><font face="lucida,helvetica"><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">GTK+ 1.2 Tutorial</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="sec-combobox.html">&#60;&#60;&#60; Previous</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 9. Miscellaneous Widgets</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="sec-colorselection.html">Next &#62;&#62;&#62;</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SEC-CALENDAR">9.12. Calendar</A></H1><P>The Calendar widget is an effective way to display and retrievemonthly date related information. It is a very simple widget to createand work with.</P><P>Creating a GtkCalendar widget is a simple as: </P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GtkWidget *gtk_calendar_new();</PRE></TD></TR></TABLE><P>There might be times where you need to change a lot of informationwithin this widget and the following functions allow you to makemultiple change to a Calendar widget without the user seeing multipleon-screen updates.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_calendar_freeze( GtkCalendar *Calendar );void gtk_calendar_thaw  ( GtkCalendar *Calendar );</PRE></TD></TR></TABLE><P>They work just like the freeze/thaw functions of every otherwidget.</P><P>The Calendar widget has a few options that allow you to change the waythe widget both looks and operates by using the function</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_calendar_display_options( GtkCalendar               *calendar,                                   GtkCalendarDisplayOptions  flags );</PRE></TD></TR></TABLE><P>The <TTCLASS="LITERAL">flags</TT> argument can be formed by combining either of thefollowing five options using the logical bitwise OR (|) operation:</P><P></P><UL><LI><P> GTK_CALENDAR_SHOW_HEADING - this option specifies thatthe month and year should be shown when drawing the calendar.</P></LI><LI><P> GTK_CALENDAR_SHOW_DAY_NAMES - this option specifies that thethree letter descriptions should be displayed for each day (egMon,Tue, etc.).</P></LI><LI><P> GTK_CALENDAR_NO_MONTH_CHANGE - this option states that the usershould not and can not change the currently displayed month. This canbe good if you only need to display a particular month such as if youare displaying 12 calendar widgets for every month in a particularyear.</P></LI><LI><P> GTK_CALENDAR_SHOW_WEEK_NUMBERS - this option specifies that thenumber for each week should be displayed down the left side of thecalendar. (eg. Jan 1 = Week 1,Dec 31 = Week 52).</P></LI><LI><P> GTK_CALENDAR_WEEK_START_MONDAY - this option states that thecalander week will start on Monday instead of Sunday which is thedefault. This only affects the order in which days are displayed fromleft to right.</P></LI></UL><P>The following functions are used to set the the currently displayeddate:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">gint gtk_calendar_select_month( GtkCalendar *calendar,                                 guint        month,                                guint        year );void gtk_calendar_select_day( GtkCalendar *calendar,                              guint        day );</PRE></TD></TR></TABLE><P>The return value from <TTCLASS="LITERAL">gtk_calendar_select_month()</TT> is a booleanvalue indicating whether the selection was successful.</P><P>With <TTCLASS="LITERAL">gtk_calendar_select_day()</TT> the specified day number isselected within the current month, if that is possible. A<TTCLASS="LITERAL">day</TT> value of 0 will deselect any current selection.</P><P>In addition to having a day selected, any number of days in the monthmay be "marked". A marked day is highlighted within the calendardisplay. The following functions are provided to manipulate markeddays:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">gint gtk_calendar_mark_day( GtkCalendar *calendar,                            guint        day);gint gtk_calendar_unmark_day( GtkCalendar *calendar,                              guint        day);void gtk_calendar_clear_marks( GtkCalendar *calendar);</PRE></TD></TR></TABLE><P>The currently marked days are stored within an array within theGtkCalendar structure. This array is 31 elements long so to testwhether a particular day is currently marked, you need to access thecorresponding element of the array (don't forget in C that arrayelements are numbered 0 to n-1). For example:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">    GtkCalendar *calendar;    calendar = gtk_calendar_new();    ...    /* Is day 7 marked? */    if (calendar-&#62;marked_date[7-1])       /* day is marked */</PRE></TD></TR></TABLE><P>Note that marks are persistent across month and year changes.</P><P>The final Calendar widget function is used to retrieve the currentlyselected date, month and/or year.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_calendar_get_date( GtkCalendar *calendar,                             guint       *year,                            guint       *month,                            guint       *day );</PRE></TD></TR></TABLE><P>This function requires you to pass the addresses of <TTCLASS="LITERAL">guint</TT>variables, into which the result will be placed. Passing <TTCLASS="LITERAL">NULL</TT> asa value will result in the corresponding value not being returned.</P><P>The Calendar widget can generate a number of signals indicating dateselection and change. The names of these signals are self explanatory,and are:</P><P></P><UL><LI><P> <TTCLASS="LITERAL">month_changed</TT></P></LI><LI><P> <TTCLASS="LITERAL">day_selected</TT></P></LI><LI><P> <TTCLASS="LITERAL">day_selected_double_click</TT></P></LI><LI><P> <TTCLASS="LITERAL">prev_month</TT></P></LI><LI><P> <TTCLASS="LITERAL">next_month</TT></P></LI><LI><P> <TTCLASS="LITERAL">prev_year</TT></P></LI><LI><P> <TTCLASS="LITERAL">next_year</TT></P></LI></UL><P>That just leaves us with the need to put all of this together intoexample code.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -