code listing in a writer document

Hello,

i've got a writer document, where i want to cite code fragments.
so i set up a frame template with grey background and a template for the
text inside so the lines are numbered.

but i've got two problems:
1) i can't have lines without a number, which i need, if a code line
doesn't fit in a single line of the document

2) i can't assign a description to that listing, because captions do
always seem to be *inside* the frame - which looks terribly wrong.
so i have the description as a simple text line after the
code/listing-frame - which is bad, wenn i change big parts of the
document, because the self-made caption doesn't stick to the code-listing.

please find attached a picture of what i have so far.

thanks in advance,

Andreas