/*

  XPostIt V1.0 
  ( October 31, 1996 )

  Notes for the X-Window-System

  by Georg C. F. Greve (greve@fusebox.hanse.de)

 */

/*{{{  Includes & Header  */
#include <stdio.h>
#include <iostream.h>
#include <xview/xview.h>
#include <xview/panel.h>
#include <xview/server.h>
#include <xview/seln.h>
#include <xview/textsw.h>
#include <xview/scrollbar.h>

#include "xpostit.H"
/*}}}*/

/*{{{  Main  */
void main(int argc, char *argv[]){

  xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);

  frame = (Frame) xv_create((long unsigned int) NULL, FRAME,
			    XV_WIDTH, 300,
			    XV_HEIGHT, 200,
			    FRAME_LABEL, "NOTE",
			    NULL);

  Textsw textsw = xv_create(frame, TEXTSW,
			    TEXTSW_CONFIRM_OVERWRITE, FALSE,
			    TEXTSW_IGNORE_LIMIT, TEXTSW_INFINITY,
			    NULL);

  Scrollbar scrollbar_v = xv_create(textsw, SCROLLBAR,
				    SCROLLBAR_DIRECTION, SCROLLBAR_VERTICAL,
				    NULL);

  xv_set(textsw,
	 WIN_COLUMNS, 500,
	 WIN_ROWS, 50,
	 NULL);

  server = (Xv_Server) xv_get (xv_get(frame, XV_SCREEN), SCREEN_SERVER);

  get_selection();

  textsw_insert(textsw, text, strlen(text));

  Xv_Window parent = xv_get(frame, WIN_PARENT);

  Rect* r = (Rect*) xv_get(parent, WIN_MOUSE_XY);
  int xpos = r->r_left;
  int ypos = r->r_top;

  xv_set(frame, XV_X, xpos, XV_Y, ypos, NULL);

  xv_main_loop(frame);

}
void exit(){
  xv_destroy_safe(frame);
}
/*}}}*/

/*{{{  get Selection  */
int get_selection(){
  Seln_holder holder;
  Seln_request *response;

  holder = selection_inquire(server, SELN_PRIMARY);
  response = selection_ask(server, &holder,
			   SELN_REQ_CONTENTS_ASCII, NULL,
			   NULL);

  strcpy(text, response->data + sizeof(SELN_REQ_CONTENTS_ASCII));

  return XV_OK;
}
/*}}}*/
