/* + style layout name ?spec? */ static int StyleLayoutCmd( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { StylePackageData *pkgPtr = clientData; Ttk_Theme theme = pkgPtr->currentTheme; const char *layoutName; Ttk_LayoutTemplate layoutTemplate; if (objc < 3 || objc > 4) { Tcl_WrongNumArgs(interp, 2, objv, "name ?spec?"); return TCL_ERROR; } layoutName = Tcl_GetString(objv[2]); if (objc == 3) { layoutTemplate = Ttk_FindLayoutTemplate(theme, layoutName); if (!layoutTemplate) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "Layout %s not found", layoutName)); Tcl_SetErrorCode(interp, "TTK", "LOOKUP", "LAYOUT", layoutName, NULL); return TCL_ERROR; } Tcl_SetObjResult(interp, Ttk_UnparseLayoutTemplate(layoutTemplate)); } else { layoutTemplate = Ttk_ParseLayoutTemplate(interp, objv[3]); if (!layoutTemplate) { return TCL_ERROR; } Ttk_RegisterLayoutTemplate(theme, layoutName, layoutTemplate); ThemeChanged(pkgPtr); } return TCL_OK; }
Tcl_Obj *Ttk_UnparseLayoutTemplate(Ttk_TemplateNode *node) { Tcl_Obj *result = Tcl_NewListObj(0,0); # define APPENDOBJ(obj) Tcl_ListObjAppendElement(NULL, result, obj) # define APPENDSTR(str) APPENDOBJ(Tcl_NewStringObj(str,-1)) while (node) { unsigned flags = node->flags; APPENDSTR(node->name); /* Back-compute -side. <<NOTE-PACKSIDE>> * @@@ NOTES: Ick. */ if (flags & TTK_EXPAND) { APPENDSTR("-expand"); APPENDSTR("1"); } else { if (flags & _TTK_MASK_PACK) { int side = 0; unsigned sideFlags = flags & _TTK_MASK_PACK; while ((sideFlags & TTK_PACK_LEFT) == 0) { ++side; sideFlags >>= 1; } APPENDSTR("-side"); APPENDSTR(packSideStrings[side]); } } /* In Ttk_ParseLayoutTemplate, default -sticky is "nsew", * so always include this even if no sticky bits are set. */ APPENDSTR("-sticky"); APPENDOBJ(Ttk_NewStickyObj(flags & _TTK_MASK_STICK)); /* @@@ Check again: are these necessary? */ if (flags & TTK_BORDER) { APPENDSTR("-border"); APPENDSTR("1"); } if (flags & TTK_UNIT) { APPENDSTR("-unit"); APPENDSTR("1"); } if (node->child) { APPENDSTR("-children"); APPENDOBJ(Ttk_UnparseLayoutTemplate(node->child)); } node = node->next; }