?? notebook.c
字號:
* Show information about the traffic on a particular * day. Dumps the information into the clist that * represents the daily graph. * * This is called by the tree traverse callback! */gint ShowDateInfo (gpointer key, gpointer value, gpointer data){ char *strValue[4]; typDateInfo *dateInfo; long *pnMax; char buffer0[88]; char buffer1[88]; char buffer2[88]; /* --- Get info passed it --- */ dateInfo = (typDateInfo *) value; pnMax = (long *) data; /* --- Setup structures to populate clist --- */ strValue[0] = buffer0; strValue[1] = buffer1; strValue[2] = buffer2; strValue[3] = NULL; /* --- Fill in the date in the first column --- */ sprintf (strValue[0], "%02d/%02d/%4d", dateInfo->date->month, dateInfo->date->day, dateInfo->date->year); /* --- Fill in the hits and byte count --- */ sprintf (strValue[1], "%ld", dateInfo->nHits); sprintf (strValue[2], "%ld", dateInfo->nSize); /* --- Append the data into the clist --- */ gtk_clist_append (GTK_CLIST (dailyCList), strValue); /* --- Keep track of the maximum value --- */ if (*pnMax < dateInfo->nSize) { *pnMax = dateInfo->nSize; } /* --- 0 => keep on trucking --- */ return (0);}/* * ShowUserInfo * * Shows information about a user (no graphs) but keeps track * of the maximum byte count so that the graphs can be generated. * * This is called as the traverse tree callback. */gint ShowUserInfo (gpointer key, gpointer value, gpointer data){ char *strValue[4]; typStat *info; long *pnMax; char buffer0[88]; char buffer1[88]; char buffer2[88]; /* --- Get information passed in --- */ info = (typStat *) value; pnMax = (long *) data; /* --- Buffers to append data --- */ strValue[0] = buffer0; strValue[1] = buffer1; strValue[2] = buffer2; strValue[3] = NULL; /* --- Update the URL in first column --- */ sprintf (strValue[0], "%s", info->sURL); /* --- Update bytes and size in next column --- */ sprintf (strValue[1], "%ld", info->nHits); sprintf (strValue[2], "%ld", info->nSize); /* --- Add the data to the clist --- */ gtk_clist_append (GTK_CLIST (userCList), strValue); /* --- Keep track of the maximum size --- */ if (info->nSize > *pnMax) { *pnMax = info->nSize; } return (0);}/* * DisplayGraph * * Display the daily graph in the clist. * * Called as a Tree traverse callback. */gint DisplayGraph (gpointer key, gpointer value, gpointer data){ int ix; typGraphInfo *graphInfo = (typGraphInfo *) data; typDateInfo *dateInfo = (typDateInfo *) value; /* --- Figure out which graph to display based on size --- */ ix = (dateInfo->nSize * NUM_GRAPHS-1) / graphInfo->nMaxSize; /* --- Set the pixmap in the clist to this one --- */ gtk_clist_set_pixmap (GTK_CLIST (graphInfo->widget), graphInfo->row, 3, pixmapGraph[ix], mask[ix]); /* --- Next row to display --- */ graphInfo->row++; /* --- Continue... --- */ return (0);}/* * PopulateDaily * * Populate the clist with the data from the tree. * Assumes that the data in the tree has been fully * populated. */void PopulateDaily (){ gchar *strValue[4]; long nMaxDaily; gchar buffer0[88]; gchar buffer1[88]; gchar buffer2[88]; typGraphInfo graphInfo; /* --- Create the table --- */ strValue[0] = buffer0; strValue[1] = buffer1; strValue[2] = buffer2; /* --- NULL - graphic is going here. --- */ strValue[3] = NULL; /* --- If the clist has not been created yet... --- */ if (dailyCList == NULL) { /* --- Create the clist --- */ dailyCList = gtk_clist_new_with_titles (4, szDailyTitles); /* --- Make sure titles are being shown --- */ gtk_clist_column_titles_show (GTK_CLIST (dailyCList)); /* --- Set the column widths --- */ gtk_clist_set_column_width (GTK_CLIST (dailyCList), 0, 80); gtk_clist_set_column_width (GTK_CLIST (dailyCList), 1, 80); gtk_clist_set_column_width (GTK_CLIST (dailyCList), 2, 80); /* --- Set the column justifications --- */ gtk_clist_set_column_justification (GTK_CLIST (dailyCList), 0, GTK_JUSTIFY_RIGHT); gtk_clist_set_column_justification (GTK_CLIST (dailyCList), 1, GTK_JUSTIFY_RIGHT); gtk_clist_set_column_justification (GTK_CLIST (dailyCList), 2, GTK_JUSTIFY_RIGHT); /* --- Add the clist to the notebook page --- */ gtk_container_add (GTK_CONTAINER (dailyPage), dailyCList); } /* --- set max to zero --- */ nMaxDaily = 0; /* * --- Traverse tree and display the textual information * while gathering the maximum so that the graph can * be displayed */ g_tree_traverse (dateTree, ShowDateInfo, G_IN_ORDER, &nMaxDaily); /* --- Information for displaying of the graph --- */ graphInfo.nMaxSize = nMaxDaily; graphInfo.widget = dailyCList; graphInfo.row = 0; /* --- Re-traverse the tree and display graphs --- */ g_tree_traverse (dateTree, DisplayGraph, G_IN_ORDER, &graphInfo); /* --- Show the clist now --- */ gtk_widget_show_all (GTK_WIDGET (dailyCList));}/* * DisplayUserGraph * * Display the graph for each user. * This is called from a traverse tree - it's a callback with the * data passed into it. * * value - contains information about this users activity * data - contains information about the graph, incl. widget and max */gint DisplayUserGraph (gpointer key, gpointer value, gpointer data){ int ix; typGraphInfo *graphInfo = (typGraphInfo *) data; typStat *statInfo = (typStat *) value; /* --- How big should the graph be? --- */ ix = (long) (((double) statInfo->nSize * NUM_GRAPHS-1) / graphInfo->nMaxSize); /* --- Set the pixmap to be an appropriate size --- */ gtk_clist_set_pixmap (GTK_CLIST (graphInfo->widget), graphInfo->row, 3, pixmapGraph[ix], mask[ix]); /* --- Go to the next row. --- */ graphInfo->row++; return (0);}/* * PopulateUser * * Populate the user graph with the information about each users's * web site traffic. The display is created in two parts. The * first part displays the text data and computes the necessary * values for the second part to display the graph. */void PopulateUser (){ gchar *strValue[4]; gchar buffer0[88]; gchar buffer1[88]; gchar buffer2[88]; long nMax; typGraphInfo graphInfo; /* --- Buffered values --- */ strValue[0] = buffer0; strValue[1] = buffer1; strValue[2] = buffer2; strValue[3] = NULL; /* --- If there's no user clist yet --- */ if (userCList == NULL) { /* --- Create the clist with titles --- */ userCList = gtk_clist_new_with_titles (4, szUserTitles); /* --- Show titles --- */ gtk_clist_column_titles_show (GTK_CLIST (userCList)); /* --- Show width of columns. --- */ gtk_clist_set_column_width (GTK_CLIST (userCList), 0, 80); gtk_clist_set_column_width (GTK_CLIST (userCList), 1, 80); gtk_clist_set_column_width (GTK_CLIST (userCList), 2, 80); /* --- Justify columns --- */ gtk_clist_set_column_justification (GTK_CLIST (userCList), 0, GTK_JUSTIFY_LEFT); gtk_clist_set_column_justification (GTK_CLIST (userCList), 1, GTK_JUSTIFY_RIGHT); gtk_clist_set_column_justification (GTK_CLIST (userCList), 2, GTK_JUSTIFY_RIGHT); /* --- Add clist to page. --- */ gtk_container_add (GTK_CONTAINER (userPage), userCList); } /* --- Traverse the tree to show text info and get max --- */ nMax = 0; g_tree_traverse (userTree, ShowUserInfo, G_IN_ORDER, &nMax); /* --- Populate structure for graphical tree traversal --- */ graphInfo.nMaxSize = nMax; graphInfo.widget = userCList; graphInfo.row = 0; /* --- Display graphs --- */ g_tree_traverse (userTree, DisplayUserGraph, G_IN_ORDER, &graphInfo); gtk_widget_show_all (GTK_WIDGET (userCList));}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -