Displaying the Clock
There are two parts to a widget's display. First, the size must be determined. This is done at configuration time, and then that space is requested from the geometry manager. When the widget is later displayed, it should use the Tk_Width and Tk_Height calls to find out how much space was actually allocated to it by the geometry manager. Example 46-13 shows ComputeGeometry. This procedure is identical in both versions of the widget.
Example 46-13 ComputeGeometry computes the widget's size.
static void ComputeGeometry(Clock *clockPtr) { int width, height; Tk_FontMetrics fm; /* Font size information */ struct tm *tmPtr; /* Time info split into fields */ struct timeval tv; /* BSD-style time value */ int bd; /* Padding from borders ... |
Get Practical Programming in Tcl & Tk, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.