Don't feel bad, surprise rounds are complex and take a lot of thinking to make sense. Also, chances are that what I would do is different than somebody else so remember that most of the time it's up to the DM, in the moment, to decide if it's a surprise round.
1) Let's assume that in this scenario, the baddies are sitting around the table getting ready for dinner. Three are goofing off at the table, one is walking from the kitchen to table with food, and one is searching the drawers for an extra fork. When the party opens the door, this forces a few checks and a possible surprise round.
Party was stealthing, but didn't know about the enemy eating dinner: Have the party roll their stealth checks before they open the door, and compare this to the enemy group's perception roll. The enemy walking around gets to make a check or take 10, your choice. The three at the table just get their base modifier, no roll. And the poor fellow searching for a fork is caught completely unaware. Combat begins with a surprise round, any baddies who made their check get to act in this round as well as the entire party.
Enemies knew about the party somehow: Doesn't matter how well the party was stealthing. The enemies aren't sitting around waiting for dinner, they're waiting for the party. No surprise round for either group, the bad guys were waiting for the party but didn't know the exact instant they would show up. If they have some ability to know the exact round that the party would open the door, then maybe, but that will likely just piss off your players (it would piss off me)
2) Pretty much the same as above. In this case though, rather than a door opening to announce the start of the room, it will likely be light from the room going into the tunnel or from the party into the cavern. Play it out the same as above, but it's much more likely that the enemies would hear some echo of the pc's moving around or see the light. Similarly the party will know about the baddies, but not exactly which bend in the cave will open into the cavern.
3) The rules for surprse rounds are that everyone gets to make either a standard or move action. There are feats and class abilities that modify this rule, but unless noted otherwise you do get your standard action. And that can be casing a spell or the 'attack' action (vital strike etc can be used) Normally when I'm dming, if the party gets a full group surprise round I'll let them act in the order they choose, and then roll initiative for the first round of 'real' combat. This way the group can do buffs and what not while still letting the higher initiative characters stay at the top of the order, rather than delay until the slower caster gets off their spell and then rush in.
4) If the ranger is going to interrupt the evil queen in the open, then she's aware of his actions. No surprise round, roll initiative once he declares that he's going to shoot. Even if he goes before the queen, if she knows the party is going to try to stop her, she shouldn't be caught flat footed. If the ranger has ranks in bluff I'd let him bluff vs sense motive but Id probably just start initiative.