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

📄 style.class

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 CLASS
📖 第 1 页 / 共 2 页
字号:

					/* track new style in scheme */
	._declare_in_scheme `style'
	.`holder'._declare_in_scheme `.`holder'.stylename'

	.`c(curscm)'.__LOG.Arrpush .makestyle_scm, class(`.classname') /*
		*/ style(`style') holdclass(`.`holder'.classname') 	 /*
		*/ holdstyle(`.`holder'.stylename') attribnm(`last')
end


/* -------------------------------------------------------------------------*/
/* Read the list of stylenames for this style by using stypop to find all
 * files named <style_classname>-<stylename>.style.  The <stylenames> form the
 * list.  The name are put in an array under __SYTLES.<style_classname>.
*/

program _populate_stylenames

	local clsnm = cond("`.proxy'"=="", "`.classname'", "`.proxy'")

	stypop populate __STYLES `clsnm'
	local top 0`.__STYLES.`clsnm'.arrnels'

	if "`.proxy'" != "" {
		if "`.__STYLES.`.classname'.isa'" == "" {
			.__STYLES.Declare `.classname' = {}
			.__STYLES.`.classname'.ref = .__STYLES.`clsnm'.ref
		}
	}

	if `top' > 0 {
		.`c(curscm)'.`.classname'._styles[`top'] = "_placeholder"
	}

end


/* -------------------------------------------------------------------------*/
/*  Create a style object by dynamically adding attributes to a null class
    instance where these attributes are defined by a file on disk.
	
	Usage:  _read_style stylename dex

	where:  style_name is the name of the style to read
	        dex is the index in the _refs array where the read style is to
		be placed
  
*/

program define _read_style

	args style_name dex

// di in white "   _read_style .classname :`.classname': style_name :`style_name':"
	local is_meta 0					// p#[stub] styles
	local style_part `style_name'
	if substr(`"`style_name'"', 1, 1) == "p" {		
		if substr("`style_name'", 2, 1) >= "0" & 		///
		   substr("`style_name'", 2, 1) <= "9" {
			local is_meta 1
			if substr("`style_name'", 3, 1) >= "0" & 	///
		   	   substr("`style_name'", 3, 1) <= "9" {
			    local meta_dex = substr("`style_name'", 2, 2)
			    local style_part `"p#`=substr("`style_name'",4,.)'"'
			}
			else {
			    local meta_dex = substr("`style_name'", 2, 1)
			    local style_part `"p#`=substr("`style_name'",3,.)'"'
			}
		}
	}

	tempname file						// open file
	local clsnm = cond("`.proxy'"=="", "`.classname'", "`.proxy'")
	capture findfile `clsnm'-`style_part'.style
	capture file open `file' using `"`r(fn)'"' , read text
	if _rc {					/* take default */
		exit 
	}					

	local refs `.`c(curscm)'.`.classname'._refs.objkey'

					/* null class to hold attributes */
	.`refs'[`dex'] = .null.new

	file read `file' line					// read file
	while r(eof) == 0 {
// di in white `"   line :`line':"'
	    gettoken cmd        rest : line , quotes
	    gettoken attrib     rest : rest , quotes
	    gettoken value      rest : rest , quotes
	    gettoken scheme_id  rest : rest , quotes

	    if (`is_meta') {
		local value     : subinstr local value     "#" "`meta_dex'", all
		local scheme_id : subinstr local scheme_id "#" "`meta_dex'", all
	    }

	    if `"`cmd'"' == `"set"' {
		local isa `.`attrib'.isa'

		if "`isa'" == "" {			// not in style, Declare
		    capture confirm number `value'
		    if _rc {
			gettoken valstrip : value	//  quoted ?
			local len      : length local value
			local lenstrip : length local valstrip
			if (`len'-`lenstrip') == 2 | (`len'-`lenstrip') == 4 {
				local isa string
			}
		    }
		    else	local isa double

		    if 0`c(cls_style_strict)' | "`isa'" == "" {

		    			// consider option c(cls_style_strict)
			di_g in white in smcl `"{p 0 8}{txt} (note:  "'	   ///
		    	`"{txt}attribute `attrib' from style definition "' ///
			`"{txt}`.classname'/`style_name' is not a "'	   ///
			`"{txt}member attribute of `.classname'){p_end}"'

				// Only #'s and strings can be declared from a
				// set, must use declare subcommand for styles
				// (styles need the style classname)

			file read `file' line
			continue				// Continue
		    }
		}

		if 0`.`attrib'.isofclass style' {
		    	if "`value'" == "" { 
				local value scheme 
			}
			.`refs'[`dex'].Declare `attrib' = .`attrib'.new,  /*
				*/ style(`value' `scheme_id')
		}
		else if "`isa'" == "string" {
			.`refs'[`dex'].Declare `attrib' = `value'
		}
		else if "`isa'" == "double" {
			.`refs'[`dex'].Declare `attrib' = `value'
		}
		else {
		  di in white "invalid line in style file `clsnm'/`style_name':"
		  di in white `"`line'"'
		}
	    }
	    else if ! (`"`cmd'"' == `"*"' | `"`cmd'"' == `"//"'       | ///
	    	       `"`cmd'"' == `""'  | `"`cmd'"' == `"sequence"' |	///
		       `"`cmd'"' == `"label"' | `"`cmd'"' == `"*!"') {
		di in white "invalid line in style file `clsnm'-`style_name':"
		di in white `"`line'"'
	    }

	    file read `file' line
	}
	file close `file'

end


/* -------------------------------------------------------------------------*/
/* Sets all of the attributes of the current object to refer to those in the
   named style at the specified index.  That is, all attributes common to the
   object and style are assigned to the object by reference.  If
   c(cls_style_strict) == 0, then any attributes in the named style that do
   not exist in the current object are .Declare'ed in the current object.
*/

/* internal
program define _restyle
	args dex

// di in white "_ restyle scheme :`c(curscm)': class :`.classname': dex=`dex'"
	.styledex = `dex'

	local nmd_style `.`c(curscm)'.`.classname'._refs[`dex'].objkey'

	forvalues i = 1/0`.`nmd_style'.dynamicmv.arrnels' {
		class nameof `nmd_style' .dynamicmv[`i']
		._reset_attrib `nmd_style' `r(name)'
	}

end
*/


// ---------------------------------------------------------------------------
//  Sets all the attributes of the current object to refer to those in the
//  specified style.  That is, all attributes common to the object and style 
//  are assigned to the object by reference.  If c(cls_style_strict) == 0, then 
//  any attributes in the source style that do not exist in the current 
//  object are .Declare'ed in the current object.

program restyle
	args src

	forvalues i = 1/0`.`src'.dynamicmv.arrnels' {
		class nameof `src' .dynamicmv[`i']
		._reset_attrib `src' `r(name)'
	}

	forvalues i = 1/0`.`src'.instancemv.arrnels' {
		class nameof `src' .instancemv[`i']
		._reset_attrib `src' `r(name)'
	}

	.styledex = .`src'.styledex
end

/* internal
program _reset_attrib
	args src attrib

	if ("`attrib'" == "styledex" | "`attrib'" == "from_scheme" ) exit

	if "`.Local.`attrib'.isa'" == "" {
	    if ! 0`c(cls_style_strict)' {
		capture .Declare `attrib' = .`src'.`attrib'.ref
		local rc = _rc
	    }
	    else	local rc 1
	}
	else {
		capture .`attrib'.ref = .`src'.`attrib'.ref
		local rc = _rc
	}

	if 0`.`attrib'_hasset' {
		._Set_Attrib `attrib'
	}

	if `rc' {
		di in white "(note: in _restyle `attrib' could not " /*
			*/ "be assigned to `.classname'.)"
	}
end
*/

program _Set_Attrib
	args attrib

	._set_`attrib' `.`attrib'.stylename' , force

end


// ---------------------------------------------------------------------------
//  Like restyle, but picks up attributes by value.

program RestyleVal
	args src

	forvalues i = 1/0`.`src'.dynamicmv.arrnels' {
		class nameof `src' .dynamicmv[`i']
		._reset_attrib_val `src' `r(name)'
	}

	forvalues i = 1/0`.`src'.instancemv.arrnels' {
		class nameof `src' .instancemv[`i']
		._reset_attrib_val `src' `r(name)'
	}

	.styledex = 0
end

program _reset_attrib_val
	args src attrib

	if ("`attrib'" == "styledex" | "`attrib'" == "from_scheme" ) exit

	if "`.Local.`attrib'.isa'" == "" {
	    if ( ! 0`c(cls_style_strict)' )  local lhs ".Declare `attrib'"
	    else			     local rc 1
	}
	else	local lhs ".`attrib'.ref"

	
	if 0`.`src'.`attrib'.isofclass style' {
	    if "`.`src'.`attrib'.snm'" != "" {
		capture `lhs' = .`attrib'.new , style(`.`src'.`attrib'.snm')
		local rc = _rc
	    }
	    else {
		.`attrib'.ref = .`attrib'.new
		capture .`attrib'.RestyleVal `.`src'.`attrib'.objkey'
		local rc = _rc
	    }
	}
	else {
		local isa `.`src'.`attrib'.isa'

		if "`isa'" == "string" {
			capture `lhs' =  `"`.`src'.`attrib''"'
			local rc = _rc
		}
		else if "`isa'" == "double" {
			capture `lhs' = `.`src'.`attrib''
			local rc = _rc
		}
		else {
			di in white "invalid attribute in RestyleVal
		}
	}

	if 0`.`attrib'_hasset' {
		._set_`attrib' `.`attrib'.stylename' , force
	}

	if 0`rc' {
		di in white "(note: in RestyleVal `attrib' could not "	///
			    "be assigned to `.classname')"
	}
end

// ---------------------------------------------------------------------------
// Restyles by reference if the source style is named, by value otherwise.

program Restyle
	args src

	local i 0`.__STYLES.`.classname'.arrindexof "`.`src'.stylename'"'
	if ! `i' {
		local i 0`.`styles'.arrindexof "`.`src'.stylename'"'
	}

	if ( `i' )  ._restyle `i'
	else        .RestyleVal `src'
end

// ---------------------------------------------------------------------------
// Recursively parses:  
//
//      [ stylename        attrib1(snm) attrib2(snm subattrib(snm ...)) ...  ]
//                               or
//      [ style(stylename) attrib1(snm) attrib2(snm subattrib(snm ...)) ...  ]
//
//  sets the current style to stylename (if specified) and recursively sets all
//  specified substyles/attributes.
// 
//  If option editcopy is specified, then a copy of the style is made before
//  the edits are applied to the unamed copy of the style.  If
//  editcopyname(newname) is specified, then the copy is given the name
//  newname.  Either of these options imply that unnamed copies will be made
//  recursively as any edits are made to contained attributes.  Note, if 
//  ONLY a stylename is specified and there are no recursive changes to that 
//  style, then editcopy and editcopyname are ignored and we just become 
//  the named style.
//
//  consider adding permissive option and only then allowing named styles
//  that don't exist to become the defaults.

program editstyle

	local 0 , `0'
	syntax [ , Style(passthru) EDITCOPY EDITCOPYNAME(name) * ]

	if `"`style'"' != "" {				// style(name) found
		.setstyle, `style'
	}

							// any x() opts left?
	local unused : subinstr local options "(" "" , count(local ct)
	if ! `ct' & `"`options'"' != `""' {		// just setting self
		if "`editcopy'`editcopyname'" != "" & 0`.styledex' {
			.remake_as_copy `editcopyname'
		}
		.setstyle, style(`options')
		exit						// Exit
	}

	gettoken name options : options			// process [stylename] 
	local unused : subinstr local name "(" "" , count(local ct)
	if ! `ct' {
		if "`name'" == "editcopy" {		// special case ?
			local options `options' `name'
		}
		else {
			.setstyle, style(`name')
		}
	}
	else	local options `name' `options'

							// possibly make copy
	if "`editcopy'`editcopyname'" != "" {
		if `"`options'"' != `""' & 0`.styledex' {
			.remake_as_copy `editcopyname'
		}
		local cpy editcopy
	}

	if `"`options'"' == `""' {
		exit						// We're done
	}

	forvalues i = 1/0`.instancemv.arrnels' {	// [ attrib(style) ...
		_cls nameoflocal instancemv[`i']
		local opt `r(name)'
		if ! ("`opt'" == "styledex" || "`opt'" == "from_scheme") {
			local found 1
			while `found' {
				local 0 , `options'
				syntax [, `opt'(string) * ]

				if `"``opt''"' != `""' {
					local found 1

					if "`.`opt'.isa'" == "double" {
						.`opt' = ``opt''
					}
					else if "`.`opt'.isa'" == "string" {
						.`opt' = `"``opt''"'
					}
					else {
						.`opt'.editstyle ``opt'' `cpy'
						if 0`.`opt'_hasset' {
						    capture ._set_`opt' ///
						    `.`opt'.stylename' , force
						}
					}
				}
				else {
					local found 0
				}
			}
		}
	}
	if `"`options'"' != `""' {
		di as error "option(s) `options' not allowed"
		exit 198
	}
end



/* -------------------------------------------------------------------------*/
/*
	for a.b.c.d

		fmac = "a"
		rmac = ".b.c.d"
		hmac = "a.b.c

	array references a[1].b.c[4].d are bound with their preceeding name.

*/
program define _splitname
	args fmac rmac hmac lmac colon rest

	gettoken test : rest , parse(" .")
	if "`test'" == "" {
		c_local `fmac'
		c_local `rmac'
		c_local `hmac'
		exit
	}

	while "`tok'" == "" | "`tok'" == "." {
		gettoken tok rest : rest , parse(" .")
		if "`tok'" != "." {
			local first `tok'
		}
	}

	local holder `first'
	gettoken tok nm : rest , parse(" .") 
	while "`nm'" != "" {
		if "`tok'" != "." {
			local holder `holder'.`tok'
		}
		gettoken tok nm : nm , parse(" .") 
	}
	local last `tok'			/* assumes no trailing .'s */

	c_local `fmac' `first'
	c_local `rmac' `rest'
	c_local `hmac' `holder'
	c_local `lmac' `last'
end


/* -------------------------------------------------------------------------*/
/*  Declares the style in the style list (really a class) of the current 
    scheme.
*/
program define _declare_in_scheme
	args style

	if "`.`c(curscm)'.styles.`.classname'.`style'.isa'" == "" {
		if "`.`c(curscm)'.styles.`.classname'.isa'" == "" {
			.`c(curscm)'.styles.Declare `.classname' = .null.new
		}

		.`c(curscm)'.styles.`.classname'.Declare		/*
			*/ `style' = .`.classname'.new, style(`style')
	}
end

program setmyfun
	capture di "hi"
end

⌨️ 快捷键说明

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