You have the basic idea right regarding the definition of firearms. Add that under federal law, guns made before 1899 are not considered firearms, and can be transferred or mailed with no paperwork. They can still be considered "deadly weapons", as can black powder guns, even if they aren't specifically "firearms" under the law.
RE: stun guns
You're getting confused. Some state and/or local laws may classify stun guns the same as firearms when outlining certain restrictions, but I don't know of any laws that have a definition of "firearm" that would cause a stun gun to qualify. Some states (Ohio) treat BB guns the same as firearms, requiring a person possessing one to have a FOID card. Again, they aren't saying a BB-gun IS a firearm; just that they've decided to treat it like one under the law.
Basically, Federal law superceeds state law where they disagree. However, states can adopt stricter laws then the federal laws (if any) for almost anything, as long as they can get judges to uphold it as "not un-Constitutional."
Some states have almost no firearms laws, leaving it up to BATF to prosecute most offenses. In these states, police generally call in BATF for firearm-specific issues.
Other states, such as Kalifornistan, have tons of their own laws that are much more restrictive than the federal laws. BATF can't enforce these state laws; that's up to state and local LEOs to do.
-Troy