header *create_environ_header(char *name,char *value){
	if(value==NULL){
		return create_header(name,"");
	}
	else{
		return create_header(name,value);
	}

}
Example #2
0
File: about.c Project: morenko/sven
void create_about_gui(Sven *sven,GtkWidget *vbox1)
{ 
	GtkWidget *vbox;
	GtkWidget *notebook;
	GdkColor color;
	

	DEBUG_MSG("Start create_about_gui\n");

	gtk_box_pack_start (GTK_BOX (vbox1), create_header(_("Info")), FALSE, FALSE, 0);
	
	vbox =gtk_vbox_new (FALSE, BORDER);
	gtk_container_set_border_width (GTK_CONTAINER (vbox), BORDER);
	gtk_widget_show (vbox);
	gtk_box_pack_start (GTK_BOX (vbox1), vbox, TRUE, TRUE, 0);
	
  
 
	/* the notebook */
	notebook = gtk_notebook_new ();
	gtk_widget_show (notebook);
	gtk_widget_set_size_request (notebook, -1, 300);
	gtk_box_pack_start (GTK_BOX (vbox), notebook, TRUE, TRUE, 0);

	/* add pages */
	add_page (GTK_NOTEBOOK (notebook), _("Info"), INFO, FALSE);
	add_page (GTK_NOTEBOOK (notebook), _("Authors"), AUTHORS, FALSE);
	add_page (GTK_NOTEBOOK (notebook), _("Thanks To"), THANKS, TRUE);
	add_page (GTK_NOTEBOOK (notebook), _("Translators"), TRANSLATORS, TRUE);

	gtk_widget_show_all(vbox);
}
Example #3
0
void display(struct tree_node* root)
{
	struct tree_node* temp;
	int i=1;
	printf("Level 0 : %d\n",root->data);
	if(((root->lson)==NULL)&&((root->rson)==NULL))
	{
		return;
	}
	struct node* head=create_header();
	push(head,root);
	while(head->next!=NULL)
	{
		temp=pop(head);
		if(temp->lson!=NULL)
		{
			push(head,temp->lson);
		}
		if(temp->rson!=NULL)
		{
			push(head,temp->rson);
		}	
		if(temp->lson!=NULL)
			printf("level %d  :%d",i,temp->lson->data);
	 	if(temp->rson!=NULL)
		 	printf("level %d  :%d",i,temp->rson->data);
    	i++;
			printf("\n");
	}
free(head);
}
Example #4
0
struct tree_node* find_node(struct tree_node* root,int data)
{
	struct tree_node* temp;///
	if(root->data==data)
	{
		return (root);
	}
	if(((root->lson)==NULL)&&((root->rson)==NULL))
	{
		return (NULL);
	}
	struct node* head=create_header();
	push(head,root);
	while(head->next!=NULL)
	{
		temp=pop(head);
		if(temp->data==data)
		{
			return (temp);
		}
		if(temp->lson!=NULL)
		{
			push(head,temp->lson);
		}
		if(temp->rson!=NULL)
		{
			push(head,temp->rson);
		}
	}
free(head);
return(NULL);
}
Example #5
0
bool elfio::load( std::istream &stream ) {
	clean();
	unsigned char e_ident[EI_NIDENT];
	// Read ELF file signature
	stream.seekg( 0 );
	stream.read( reinterpret_cast<char*>( &e_ident ), sizeof( e_ident ) );
	// Is it ELF file?
	if ( stream.gcount() != sizeof( e_ident ) ||
		 e_ident[EI_MAG0] != ELFMAG0	||
		 e_ident[EI_MAG1] != ELFMAG1	||
		 e_ident[EI_MAG2] != ELFMAG2	||
		 e_ident[EI_MAG3] != ELFMAG3 ) {
		return false;
	}
	if ( ( e_ident[EI_CLASS] != ELFCLASS64 ) &&
		 ( e_ident[EI_CLASS] != ELFCLASS32 )) {
		return false;
	}
	convertor.setup( e_ident[EI_DATA] );
	header = create_header( e_ident[EI_CLASS], e_ident[EI_DATA] );
	if ( 0 == header ) {
		return false;
	}
	if ( !header->load( stream ) ) {
		return false;
	}
	load_sections( stream );
	load_segments( stream );
	return true;
}
Example #6
0
int test_write_header()
{
	 struct setec_astronomy_header w_header, r_header;
	 char temp_file[] = TEST_DATA_DIR "temp";

	 
	 init_header(&w_header);
	 init_header(&r_header);

	 create_header(&w_header, DEFAULT_IV_LEN, DEFAULT_SALT_LEN, 
								 DEFAULT_HASH_COUNT, DEFAULT_PASSWORD, DEFAULT_HASH_LEN);
	 
	 test_equals(write_header(&w_header, temp_file), SA_SUCCESS);	 
	 test_equals(read_header(&r_header, temp_file), SA_SUCCESS);
	 
	 test_equals(w_header.salt_len, r_header.salt_len);
	 test_equals(w_header.hash_count, r_header.hash_count);
	 test_equals(w_header.hash_len, w_header.hash_len);
	 test_equals(w_header.iv_len, r_header.iv_len);
	 
	 test_equals(strncmp(w_header.salt, r_header.salt, w_header.salt_len), 0);
	 test_equals(strncmp(w_header.hash, r_header.hash, w_header.hash_len), 0);
	 test_equals(strncmp(w_header.iv, r_header.iv, w_header.iv_len), 0);
	 test_equals(strncmp(w_header.hash, r_header.hash, w_header.hash_len), 0);

	 free_header(&w_header);
	 free_header(&r_header);
	 
	 return 0;
}
Example #7
0
void create_archive_file(std::vector<fs::path> const& files, std::string const& archive_name)
{
  using size_type = std::vector<fs::path>::size_type;
  auto const file_sizes = enumerate_file_sizes(files);
  std::ofstream archive{archive_name, std::ofstream::binary};
  create_body(files, file_sizes, archive);
  create_header(files, file_sizes, archive);
}
Example #8
0
	lfl_string as_loadvars::create_request(const lfl_string& method, const lfl_string& uri, bool send_data)
	{
		lfl_string information;
		//create information in the form of name=value (urlencoded)
		string_hash<lfl_string>::iterator it = m_values.begin();
		for(bool first = true; it != m_values.end(); ++it)
		{
			lfl_string name, value;

			name = it->first;
			value = it->second;

			url_encode( &name );
			url_encode( &value );
			information += string_printf("%s%s=%s", first? "":"&",name.c_str(), value.c_str() );
			first = false;
		}

		if( method == "POST")
		{
			lfl_string request = string_printf( "POST %s HTTP/1.1\r\n", uri.c_str() );

			m_headers.set("Content-Length", string_printf( "%i", information.size()));

			request += create_header();
			request += "\r\n";
			request += information;

			return request;
		}
		else if(method == "GET")
		{
			lfl_string request = string_printf( "GET %s?%s HTTP/1.1\r\n", uri.c_str(), information.c_str() );
			request += create_header();
			request += "\r\n";

			return request;
		}
		else
		{
			assert(0 && "unsupported");
		}

		return "";
	}
Example #9
0
void connection::read_directory(net::connection_info & CI)
{
	namespace fs = boost::filesystem;
	std::stringstream ss;
	ss <<
	"<head>\n"
	"</head>\n"
	"<body bgcolor=\"#111111\" text=\"#D8D8D8\" link=\"#FF8C00\" vlink=\"#FF8C00\">\n"
	"<table>\n"
	"<tr>\n"
	"<td>name</td>\n"
	"<td>size</td>\n"
	"</tr>\n";
	try{
		std::map<std::string, std::string> directory;
		std::map<std::string, std::string> file;
		for(fs::directory_iterator it_cur(path), it_end; it_cur != it_end; ++it_cur){
			std::string relative_path = it_cur->path().directory_string().substr(web_root.size());
			encode_chars(relative_path);
			std::string file_name = it_cur->path().filename();
			std::stringstream tmp_ss;
			if(fs::is_directory(it_cur->path())){
				tmp_ss << "<tr>\n<td>\n<a href=\"" << relative_path << "\">" << file_name
					<< "/</a>\n</td>\n<td>DIR</td>\n</tr>";
				boost::to_upper(file_name);
				directory.insert(std::make_pair(file_name, tmp_ss.str()));
			}else{
				tmp_ss << "<tr>\n<td>\n<a href=\"" << relative_path << "\">" << it_cur->path().filename()
					<< "</a>\n</td>\n<td>" << convert::bytes_to_SI(fs::file_size(it_cur->path()))
					<< "</td>\n</tr>\n";
				boost::to_upper(file_name);
				file.insert(std::make_pair(file_name, tmp_ss.str()));
			}
		}
		//append sorted listing to ss
		for(std::map<std::string, std::string>::iterator it_cur = directory.begin(),
			it_end = directory.end(); it_cur != it_end; ++it_cur)
		{
			ss << it_cur->second;
		}
		for(std::map<std::string, std::string>::iterator it_cur = file.begin(),
			it_end = file.end(); it_cur != it_end; ++it_cur)
		{
			ss << it_cur->second;
		}
	}catch(std::exception & ex){
		LOG << ex.what();
		Proactor.disconnect(CI.connection_ID);
		return;
	}
	ss << "</table>\n</body>\n";
	std::string header = create_header(ss.str().size());
	net::buffer B;
	B.append(header).append(ss.str());
	Proactor.send(CI.connection_ID, B);
	Proactor.disconnect_on_empty(CI.connection_ID);
}
Example #10
0
static GtkWidget *
populate_menu_from_directory (GtkWidget          *menu,
			      MateMenuTreeDirectory *directory)
{
	GList    *children;
	GSList   *l;
	GSList   *items;
	gboolean  add_separator;

	children = gtk_container_get_children (GTK_CONTAINER (menu));
	add_separator = (children != NULL);
	g_list_free (children);

	items = matemenu_tree_directory_get_contents (directory);

	for (l = items; l; l = l->next) {
		MateMenuTreeItem *item = l->data;

		if (add_separator ||
		    matemenu_tree_item_get_type (item) == MATEMENU_TREE_ITEM_SEPARATOR) {
			add_menu_separator (menu);
			add_separator = FALSE;
		}

		switch (matemenu_tree_item_get_type (item)) {
		case MATEMENU_TREE_ITEM_DIRECTORY:
			create_submenu (menu, MATEMENU_TREE_DIRECTORY (item), NULL);
			break;

		case MATEMENU_TREE_ITEM_ENTRY:
			create_menuitem (menu, MATEMENU_TREE_ENTRY (item), NULL);
			break;

		case MATEMENU_TREE_ITEM_SEPARATOR :
			/* already added */
			break;

		case MATEMENU_TREE_ITEM_ALIAS:
			create_menuitem_from_alias (menu, MATEMENU_TREE_ALIAS (item));
			break;

		case MATEMENU_TREE_ITEM_HEADER:
			create_header (menu, MATEMENU_TREE_HEADER (item));
			break;

		default:
			break;
		}

		matemenu_tree_item_unref (item);
	}

	g_slist_free (items);

	return menu;
}
void regen_good_header_data()
{
	 struct setec_astronomy_header header;
	 remove(GOOD_HEADER_DATA);

	 create_header(&header, DEFAULT_IV_LEN, DEFAULT_SALT_LEN, DEFAULT_HASH_COUNT,
								 DEFAULT_PASSWORD, DEFAULT_HASH_LEN);

	 write_header(&header, GOOD_HEADER_DATA);
	 free_header(&header);
}
void regen_file_exists()
{
	 struct setec_astronomy_header header;
	 remove(FILE_EXISTS);

	 create_header(&header, DEFAULT_IV_LEN, DEFAULT_SALT_LEN, DEFAULT_HASH_COUNT,
								 DEFAULT_PASSWORD, DEFAULT_HASH_LEN);

	 write_header(&header, FILE_EXISTS);
	 free_header(&header);
}
Example #13
0
fcgi_begin_request* create_begin_request(uint16_t request_id, int alive)
{
    fcgi_begin_request *h = (fcgi_begin_request *) emalloc(sizeof(fcgi_begin_request));
    h->header = create_header(FCGI_BEGIN_REQUEST, request_id);
    h->body   = ecalloc(1, sizeof(fcgi_begin_request_body));
    if (alive == 1) {
        h->body->flags |= FCGI_KEEP_CONN;
    }
    h->body->role_lo = FCGI_RESPONDER;
    h->header->content_len_lo = sizeof(fcgi_begin_request_body);
    return h;
}
Example #14
0
LIBCOUCHSTORE_API
couchstore_error_t couchstore_open_db_ex(const char *filename,
        couchstore_open_flags flags,
        const couch_file_ops *ops,
        Db **pDb)
{
    couchstore_error_t errcode = COUCHSTORE_SUCCESS;
    Db *db;
    int openflags;

    /* Sanity check input parameters */
    if ((flags & COUCHSTORE_OPEN_FLAG_RDONLY) &&
            (flags & COUCHSTORE_OPEN_FLAG_CREATE)) {
        return COUCHSTORE_ERROR_INVALID_ARGUMENTS;
    }

    if ((db = calloc(1, sizeof(Db))) == NULL) {
        return COUCHSTORE_ERROR_ALLOC_FAIL;
    }

    if (flags & COUCHSTORE_OPEN_FLAG_RDONLY) {
        openflags = O_RDONLY;
    } else {
        openflags = O_RDWR;
    }

    if (flags & COUCHSTORE_OPEN_FLAG_CREATE) {
        openflags |= O_CREAT;
    }

    error_pass(tree_file_open(&db->file, filename, openflags, ops));

    if ((db->file.pos = db->file.ops->goto_eof(db->file.handle)) == 0) {
        /* This is an empty file. Create a new fileheader unless the
         * user wanted a read-only version of the file
         */
        if (flags & COUCHSTORE_OPEN_FLAG_RDONLY) {
            error_pass(COUCHSTORE_ERROR_NO_HEADER);
        } else {
            error_pass(create_header(db));
        }
    } else {
        error_pass(find_header(db));
    }

    *pDb = db;
    return COUCHSTORE_SUCCESS;

cleanup:
    couchstore_close_db(db);
    return errcode;
}
Example #15
0
static int inotify_new_task(t_task_base *base)
{
	char httpheader[1024] = {0x0};

	create_header(httpheader, base);

	int fd = active_connect();
	if (fd < 0)
	{
		LOG(vfs_sig_log, LOG_ERROR, "connect err %m\n");
		return -1;
	}

	return active_send(fd, httpheader);
}
Example #16
0
int	write_dir_header(char *name, int tar, t_count *count)
{
  t_header	*header;

  if ((header = create_header(name)) == NULL)
    return (1);
#ifdef DEBUG
  printf("%s is a dir\n", name);
#endif
  open_dir(name, tar, count, header);
#ifdef DEBUG
  printf("OPEN DIR OK\n");
#endif
  free(header);
  free(name);
  return (0);
}
Example #17
0
/* FIXME this expects start and end aligned to 30mins marks do the rounding
 * here rather than epg-grid? -> yes */
void
mex_epg_grid_set_date_time_span (MexEpgGrid *grid,
                                 GDateTime  *start,
                                 GDateTime  *end)
{
  MexEpgGridPrivate *priv;

  g_return_if_fail (MEX_IS_EPG_GRID (grid));
  g_return_if_fail (start && end);
  priv = grid->priv;

  priv->first_date = g_date_time_ref (start);
  priv->last_date = g_date_time_ref (end);

  create_header (grid);
  clutter_actor_queue_relayout (CLUTTER_ACTOR (grid));
}
Example #18
0
//------------------------------------------------------------------------------
    bool load( const std::string& file_name )
    {
        clean();

        std::ifstream stream;
        stream.open( file_name.c_str(), std::ios::in | std::ios::binary );
        if ( !stream ) {
            return false;
        }

        unsigned char e_ident[EI_NIDENT];

        // Read ELF file signature
        stream.seekg( 0 );
        stream.read( reinterpret_cast<char*>( &e_ident ), sizeof( e_ident ) );

        // Is it ELF file?
        if ( stream.gcount() != sizeof( e_ident ) ||
             e_ident[EI_MAG0] != ELFMAG0    ||
             e_ident[EI_MAG1] != ELFMAG1    ||
             e_ident[EI_MAG2] != ELFMAG2    ||
             e_ident[EI_MAG3] != ELFMAG3 ) {
            return false;
        }

        if ( ( e_ident[EI_CLASS] != ELFCLASS64 ) &&
             ( e_ident[EI_CLASS] != ELFCLASS32 )) {
            return false;
        }

        convertor.setup( e_ident[EI_DATA] );

        header = create_header( e_ident[EI_CLASS], e_ident[EI_DATA] );
        if ( 0 == header ) {
            return false;
        }
        if ( !header->load( stream ) ) {
            return false;
        }

        load_sections( stream );
        load_segments( stream );

        return true;
    }
Example #19
0
int			create_cor(char *file)
{
  int			fd;
  int			fdwrite;
  int			error;

  if ((fd = open(file, O_RDONLY)) == -1)
    return (-5);
  if ((fdwrite = open(my_strfusion(take_begin(file, '.'), ".cor"),
		      O_WRONLY | O_CREAT | O_TRUNC,
		      S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1)
    return (-2);
  if (create_header(fd, fdwrite) == -1)
    return (-3);
  if ((error = write_instructions(fd, fdwrite)) != 0)
    return (error);
  close(fd);
  close(fdwrite);
  return (0);
}
void Ebu3264SubtitleFormat::WriteFile(const AssFile *src, wxString const& filename, wxString const& encoding) const
{
	// collect data from user
	EbuExportSettings export_settings = get_export_config(0);
	AssFile copy(*src);

	std::vector<EbuSubtitle> subs_list = convert_subtitles(copy, export_settings);
	std::vector<BlockTTI> tti = create_blocks(subs_list, export_settings);
	BlockGSI gsi = create_header(copy, export_settings);

	BlockTTI &block0 = tti.front();
	snprintf(gsi.tcf, 8, "%02u%02u%02u%02u", (unsigned int)block0.tci.h, (unsigned int)block0.tci.m, (unsigned int)block0.tci.s, (unsigned int)block0.tci.f);
	snprintf(gsi.tnb, 5, "%5u", (unsigned int)tti.size());
	snprintf(gsi.tns, 5, "%5u", (unsigned int)subs_list.size());

	// write file
	agi::io::Save f(from_wx(filename), true);
	f.Get().write((const char *)&gsi, sizeof(gsi));
	for (auto const& block : tti)
		f.Get().write((const char *)&block, sizeof(block));
}
Example #21
0
void connection::file_send_call_back(net::connection_info & CI)
{
	net::buffer B;
	if(index == 0){
		//prepare header
		boost::uint64_t size;
		try{
			size = boost::filesystem::file_size(path);
		}catch(std::exception & ex){
			LOG << ex.what();
			CI.send_call_back.clear();
			Proactor.disconnect(CI.connection_ID);
			return;
		}
		std::string header = create_header(size);
		B.append(header);
	}
	if(index == 0 || CI.send_buf_size < MTU){
		std::fstream fin(path.string().c_str(), std::ios::in | std::ios::binary);
		if(fin.is_open()){
			fin.seekg(index, std::ios::beg);
			B.tail_reserve(MTU);
			fin.read(reinterpret_cast<char *>(B.tail_start()), B.tail_size());
			B.tail_resize(fin.gcount());
			index += fin.gcount();
			Proactor.send(CI.connection_ID, B);
			if(fin.eof()){
				CI.send_call_back.clear();
				Proactor.disconnect_on_empty(CI.connection_ID);
			}
		}else{
			CI.send_call_back.clear();
			Proactor.disconnect(CI.connection_ID);
		}
	}
}
Example #22
0
// Print (or preview) a single page
void CHexEditView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
	ASSERT(print_offset_.cx >= 0 && print_offset_.cy >= 0);
	pDC->SetMapMode(print_map_mode_);
	int u_scale = pDC->GetDeviceCaps(LOGPIXELSX); // units scaling (pixels/inch)
	if (theApp.print_units_ == CHexEditApp::PRN_CM)
		u_scale = int(u_scale/2.54);

	CRect rct;                              // Encloses all incl. header/footer - ie nothing is printed outside this box
	CRect margin_rct;                       // Smaller box based on margins - does not include header/footer
	CString ss;                             // String to display at top of page

	// Work out text height of the (printer) font
	pDC->SelectObject(print_font_);
	TEXTMETRIC tm;
	pDC->GetTextMetrics(&tm);
	int text_height = tm.tmHeight + tm.tmExternalLeading;

	// Work out size of the page
	int vert_res = pDC->GetDeviceCaps(VERTRES);
	int horz_res = pDC->GetDeviceCaps(HORZRES);
	if (vert_res < horz_res/5)                // May be lines of text not pixels (Eg Text Only driver)
		vert_res *= text_height;              // xxx should be device units not logical

	// Work out where the margins are
	margin_rct.top = LONG(theApp.top_margin_*u_scale);
	margin_rct.left = LONG(theApp.left_margin_*u_scale);
	margin_rct.bottom = vert_res - LONG(theApp.bottom_margin_*u_scale);
	margin_rct.right  = horz_res - LONG(theApp.right_margin_*u_scale);
	pDC->DPtoLP(&margin_rct);

	// Work out where to print the header and footer
	rct.top = LONG(theApp.header_edge_*u_scale);
	rct.left = LONG(theApp.left_margin_*u_scale);
	rct.bottom = vert_res - LONG(theApp.footer_edge_*u_scale);
	rct.right  = horz_res - LONG(theApp.right_margin_*u_scale);

	// Note we can't use ConvertFromDP here as this is for printer not screen
	pDC->DPtoLP(&rct);

	pDC->SetBkMode(TRANSPARENT);
	if (theApp.print_watermark_)
	{
		// Work out angle of diagonal from bottom left to top right
		ASSERT(rct.Height() != 0 && rct.Width() != 0);  // else we get divide by zero error
		double diag = (int)sqrt((double)(rct.Height()*rct.Height()) + rct.Width()*rct.Width());
		double angle = asin(rct.Height()/diag);

		// Create a large font at the angle of the diagonal
		int fangle = int(angle * 1800 / 3.141592 /*M_PI*/);   // convert diag angle to tenth of degrees from X-axis
		CFont fontWatermark;
		fontWatermark.CreateFont(rct.Height()/10, 0, fangle, fangle, FW_BOLD, 0, 0, 0,
								 ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
								 DEFAULT_PITCH | FF_SWISS, _T("Arial"));
		CFont * pSaved = pDC->SelectObject(&fontWatermark);

		// Create the text
		CString str = create_header(theApp.watermark_, pInfo->m_nCurPage);

		// Get length of text then work out how far from the bottom page of the corner should the text start
		double d = (diag - pDC->GetTextExtent(str).cx)/2;  // distance along diag of start of text
		int x = int(d * cos(angle));
		int y = int(d * sin(angle));

		pDC->SetTextColor(RGB(208, 208, 208));          // light grey
		pDC->SetTextAlign(TA_BASELINE);
		pDC->TextOut(x, rct.Height() - y, str);

		pDC->SetTextAlign(TA_TOP);
		(void)pDC->SelectObject(pSaved);
		fontWatermark.DeleteObject();
	}

	pDC->SetTextColor(RGB(0,0,0));          // Display headers/footers in black

	int left, mid=1, right;
	if (theApp.even_reverse_ && pInfo->m_nCurPage%2 == 0)
		left = 2, right = 0;
	else
		left = 0, right = 2;

	if (rct.top - text_height > margin_rct.top)  // Note y values are always -ve down in printer map mode
	{
		// Get normal header unless using diff header for 1st page and its the first page
		CString strHeader;
		if (theApp.diff_first_header_ && pInfo->m_nCurPage == 1)
			strHeader = theApp.first_header_;
		else
			strHeader = theApp.header_;

		// Print the 3 parts of the header
		AfxExtractSubString(ss, strHeader, left, '|');
		pDC->DrawText(create_header(ss, pInfo->m_nCurPage), &rct, DT_LEFT | DT_TOP | DT_NOPREFIX | DT_SINGLELINE);

		AfxExtractSubString(ss, strHeader, mid, '|');
		pDC->DrawText(create_header(ss, pInfo->m_nCurPage), &rct, DT_CENTER | DT_TOP | DT_NOPREFIX | DT_SINGLELINE);

		AfxExtractSubString(ss, strHeader, right, '|');
		pDC->DrawText(create_header(ss, pInfo->m_nCurPage), &rct, DT_RIGHT | DT_TOP | DT_NOPREFIX | DT_SINGLELINE);
	}

	if (rct.bottom + text_height < margin_rct.bottom)  // Note y values are -ve down
	{
		// Get normal footer unless using diff footer for 1st page and it's the first page
		CString strFooter;
		if (theApp.diff_first_footer_ && pInfo->m_nCurPage == 1)
			strFooter = theApp.first_footer_;
		else
			strFooter = theApp.footer_;

		// Print the 3 parts of the footer
		AfxExtractSubString(ss, strFooter, left, '|');
		pDC->DrawText(create_header(ss, pInfo->m_nCurPage), &rct, DT_LEFT | DT_BOTTOM | DT_NOPREFIX | DT_SINGLELINE);

		AfxExtractSubString(ss, strFooter, mid, '|');
		pDC->DrawText(create_header(ss, pInfo->m_nCurPage), &rct, DT_CENTER | DT_BOTTOM | DT_NOPREFIX | DT_SINGLELINE);

		AfxExtractSubString(ss, strFooter, right, '|');
		pDC->DrawText(create_header(ss, pInfo->m_nCurPage), &rct, DT_RIGHT | DT_BOTTOM | DT_NOPREFIX | DT_SINGLELINE);
	}

	if (theApp.print_hdr_)
	{
		// Print column headings
		rct = margin_rct + CSize(print_offset_.cx, 0);
		pDC->DrawText("Address", &rct, DT_LEFT | DT_TOP | DT_NOPREFIX | DT_SINGLELINE);
		for (int ii = 0; ii < rowsize_; ++ii)
		{
			char buf[10];
			if (!display_.hex_addr)            // Probably showing dec addresses and/or line numbers so show dec hdr
				sprintf(buf, "%2d", ii%100);
			else if (theApp.hex_ucase_)
				sprintf(buf, "%02X", ii%0x100);
			else
				sprintf(buf, "%02x", ii%0x100);
			if (!display_.vert_display && display_.hex_area)
				pDC->TextOut(rct.left + hex_pos(ii, print_text_width_), rct.top, buf, 2);
			if (display_.vert_display || display_.char_area)
				pDC->TextOut(rct.left + char_pos(ii, print_text_width_, print_text_width_w_), rct.top, buf+1, 1);
		}
	}

	// Draw margins in print preview
	if (pInfo != NULL && pInfo->m_bPreview && pDC->m_hAttribDC != NULL)
	{
		CPen pen(PS_DOT, 0, RGB(0,0,0));
		CPen* ppen = pDC->SelectObject(&pen);
		pDC->MoveTo(-30000, margin_rct.top);
		pDC->LineTo(30000, margin_rct.top);
		pDC->MoveTo(margin_rct.left, -30000);
		pDC->LineTo(margin_rct.left, 30000);
		pDC->MoveTo(-30000, margin_rct.bottom);
		pDC->LineTo(30000, margin_rct.bottom);
		pDC->MoveTo(margin_rct.right, -30000);
		pDC->LineTo(margin_rct.right, 30000);
		pDC->SelectObject(ppen);
	}

	if (theApp.print_box_)
	{
		// Work out width of total printed text
		CSize size;

		rct = margin_rct + CSize(print_offset_.cx, 0);

		if (display_.char_area)
			size.cx = char_pos(rowsize_, print_text_width_, print_text_width_w_);
		else
			size.cx = hex_pos(rowsize_, print_text_width_);
		size.cy = 0;

		// Draw a box around it
		CPen pen(PS_SOLID, 0, RGB(0,0,0));
		CPen* ppen = pDC->SelectObject(&pen);
		pDC->MoveTo(rct.left - print_text_width_, rct.top);
		pDC->LineTo(rct.left + size.cx + print_text_width_, rct.top);
		pDC->LineTo(rct.left + size.cx + print_text_width_, rct.bottom);
		pDC->LineTo(rct.left - print_text_width_, rct.bottom);
		pDC->LineTo(rct.left - print_text_width_, rct.top);

#if 0
		// Draw line between address and hex areas
		size.cx = hex_pos(0, print_text_width_);
		size.cy = 0;
		pDC->MoveTo(rct.left + size.cx - print_text_width_, rct.top);
		pDC->LineTo(rct.left + size.cx - print_text_width_, rct.bottom);

		// Draw line between areas
		if (display_.hex_area && display_.char_area)
		{
			size.cx = hex_pos(rowsize_, print_text_width_);
			size.cy = 0;
			pDC->MoveTo(rct.left + size.cx - print_text_width_/2, rct.top);
			pDC->LineTo(rct.left + size.cx - print_text_width_/2, rct.bottom);
		}
#endif
		pDC->SelectObject(ppen);
	}

	// Do this last so pen changes etc do not affect header, footer etc drawing
	CScrView::OnPrint(pDC, pInfo);          // Calls OnDraw to print rest of page
}
Example #23
0
int tool_app_t::execute()
{
	tool_app_t opts;

	/* make SIGFPE actually deliver signals on supoorted platforms */
	plib::fpsignalenabler::global_enable(true);
	plib::fpsignalenabler sigen(plib::FP_ALL & ~plib::FP_INEXACT & ~plib::FP_UNDERFLOW);

	if (opt_help())
	{
		pout(usage());
		return 0;
	}

	if (opt_version())
	{
		pout(
			"nltool (netlist) " PSTRINGIFY(NLTOOL_VERSION) "\n"
			"Copyright (C) 2019 Couriersud\n"
			"License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>.\n"
			"This is free software: you are free to change and redistribute it.\n"
			"There is NO WARRANTY, to the extent permitted by law.\n\n"
			"Written by Couriersud.\n");
		if (opt_verb())
		{
			std::vector<std::pair<pstring, pstring>> defs;
			netlist::netlist_state_t::compile_defines(defs);
			pout("\nCompile defines:\n");
			for (auto &x : defs)
				pout("{1:-30} = {2}\n", x.first, x.second);

		}
		return 0;
	}

	m_options = opt_defines();
	m_options.emplace_back("NLTOOL_VERSION=" PSTRINGIFY(NLTOOL_VERSION));

	try
	{
		pstring cmd = opt_cmd.as_string();
		if (cmd == "listdevices")
			listdevices();
		else if (cmd == "run")
			run();
		else if (cmd == "validate")
			validate();
		else if (cmd == "static")
			static_compile();
		else if (cmd == "header")
			create_header();
		else if (cmd == "docheader")
			create_docheader();
		else if (cmd == "convert")
			convert();
		else
		{
			perr("Unknown command {}\n", cmd.c_str());
			//FIXME: usage_short
			perr(usage());
			return 1;
		}
	}
	catch (netlist::nl_exception &e)
	{
		perr("Netlist exception caught: {}\n", e.text());
		return 2;
	}
	catch (plib::pexception &e)
	{
		perr("plib exception caught: {}\n", e.text());
		return 2;
	}

	return 0;
}
Example #24
0
 std::string Client::get_header() const
 {
   return create_header("clnt", 2 + (its_ip.is_v4() ? 4 : 16) + its_name.length());
 }
Example #25
0
void elfio::create( unsigned char file_class, unsigned char encoding ) {
	clean();
	convertor.setup( encoding );
	header = create_header( file_class, encoding );
	create_mandatory_sections();
}
Example #26
0
 std::string Acknowledged::get_header() const
 {
   return create_header("ackn", 0);
 }
Example #27
0
void create_xosd_gui(Sven *sven,GtkWidget *vbox)
{
	GtkWidget  *hbox,*hbox1, *label,*unit_label,*button1;
	GtkWidget *table, **position_icons, *position_table,*sep,*button;
	GdkColor   *colors;
	gint n_colors;

	Gtk_Osd_Pos curr_pos;
	Gtk_Osd_Align curr_align;
	
	GSList *group = NULL;

	gtk_box_pack_start (GTK_BOX (vbox),(gpointer )create_header(_("XOSD")), FALSE, FALSE, 0);

	table = gtk_table_new (7,2, FALSE);
	gtk_table_set_row_spacings (GTK_TABLE (table), 12);
	gtk_table_set_col_spacings (GTK_TABLE (table), 12);
	gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
	
	// Font selector. 
	label = gtk_label_new (_("Font:"));
	gtk_misc_set_alignment (GTK_MISC (label), 1.0,0.5);
	gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
	gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
			GTK_FILL, GTK_FILL, 0, 0);
	
	if(sven->osd->font!=NULL)
		 font_entry = gtk_font_button_new_with_font (sven->osd->font);
	 else 
	  	font_entry = gtk_font_button_new_with_font ("Sans 18");
	gtk_table_attach (GTK_TABLE (table), font_entry, 1, 2, 0, 1,
			GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
	
	//Colour Selector
	label = gtk_label_new (_("Colour:"));
	gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
	gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
	gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
			GTK_FILL, GTK_FILL, 0, 0);
			
	gtk_color_selection_palette_from_string (sven->osd->color,&colors,&n_colors);
	colour_entry = gtk_color_button_new_with_color (colors);
	gtk_table_attach (GTK_TABLE (table), colour_entry, 1, 2, 1, 2,
			GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
	
	//Timeout
	label = gtk_label_new (_("Timeout:"));
	gtk_misc_set_alignment (GTK_MISC (label), 1.0,0.5);
	gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
	gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3,
			GTK_FILL, GTK_FILL, 0, 0);
	hbox = gtk_hbox_new (FALSE, 6);
	gtk_table_attach (GTK_TABLE (table), hbox, 1, 2, 2, 3,
			GTK_FILL, GTK_FILL, 0, 0);
	timeout_obj = gtk_adjustment_new (sven->osd->timeout, -1, 60, 1, 1, 1);
	timeout_spin = gtk_spin_button_new (GTK_ADJUSTMENT (timeout_obj), 1.0, 0);
	gtk_spin_button_set_value (GTK_SPIN_BUTTON (timeout_spin),
				(gfloat) sven->osd->timeout);
	gtk_box_pack_start (GTK_BOX (hbox), timeout_spin, FALSE, FALSE, 0);
	unit_label = gtk_label_new (_("seconds"));
	gtk_misc_set_alignment (GTK_MISC (unit_label),0.0, 0.0);
	gtk_label_set_justify (GTK_LABEL (unit_label), GTK_JUSTIFY_LEFT);
	gtk_box_pack_start (GTK_BOX (hbox), unit_label, FALSE, FALSE, 0);

	// Position 
	label = gtk_label_new (_("Position:"));
	gtk_misc_set_alignment (GTK_MISC (label), 1.0,0.5);
	gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
	gtk_table_attach (GTK_TABLE (table), label, 0, 1, 3,4,GTK_FILL, GTK_FILL, 0, 0);
	
	position_icons = position_icons_new ();
	position_table = gtk_table_new (3, 3, FALSE);
	gtk_table_set_row_spacings (GTK_TABLE (position_table), 6);
	gtk_table_set_col_spacings (GTK_TABLE (position_table), 6);
	gtk_table_attach (GTK_TABLE (table), position_table, 1, 2, 3,4,GTK_FILL, GTK_FILL, 0, 0);
	
	curr_pos = GTK_OSD_TOP;
	for (curr_align = GTK_OSD_LEFT; curr_align <= GTK_OSD_RIGHT; curr_align++)
	{
		positions[curr_pos][curr_align] = gtk_radio_button_new (group);
		gtk_container_add (GTK_CONTAINER (positions[curr_pos][curr_align]),position_icons[(curr_pos * 3) + curr_align]);
		
		gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON(positions[curr_pos][curr_align]), FALSE);
		group =gtk_radio_button_group (GTK_RADIO_BUTTON(positions[curr_pos][curr_align]));
	
		if (sven->osd->pos == curr_pos && sven->osd->align == curr_align)
		{
			gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(positions[curr_pos][curr_align]),TRUE);
		}
	
		gtk_table_attach (GTK_TABLE (position_table),positions[curr_pos][curr_align],curr_align, curr_align + 1,curr_pos, curr_pos + 1, GTK_FILL, GTK_FILL, 0, 0);
	}
	
	curr_pos = GTK_OSD_MIDDLE;
	for (curr_align = GTK_OSD_LEFT; curr_align <= GTK_OSD_RIGHT; curr_align++)
	{
		positions[curr_pos][curr_align] = gtk_radio_button_new (group);
		gtk_container_add (GTK_CONTAINER (positions[curr_pos][curr_align]),position_icons[(curr_pos * 3) + curr_align]);
	
		gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON(positions[curr_pos][curr_align]), FALSE);
		group =gtk_radio_button_group (GTK_RADIO_BUTTON(positions[curr_pos][curr_align]));
	
		if (sven->osd->pos == curr_pos && sven->osd->align == curr_align)
		{
			gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(positions[curr_pos][curr_align]),TRUE);
		}
	
		gtk_table_attach (GTK_TABLE (position_table),positions[curr_pos][curr_align],curr_align, curr_align + 1,1, 2, GTK_FILL, GTK_FILL, 0, 0);
	}
	
	curr_pos = GTK_OSD_BOTTOM;
	for (curr_align = GTK_OSD_LEFT; curr_align <= GTK_OSD_RIGHT; curr_align++)
	{
		positions[curr_pos][curr_align] = gtk_radio_button_new (group);
		gtk_container_add (GTK_CONTAINER (positions[curr_pos][curr_align]),position_icons[(curr_pos * 3) + curr_align]);
	
		gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON(positions[curr_pos][curr_align]), FALSE);
		group =gtk_radio_button_group (GTK_RADIO_BUTTON(positions[curr_pos][curr_align]));
	
		if (sven->osd->pos == curr_pos && sven->osd->align == curr_align)
		{
			gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(positions[curr_pos][curr_align]),TRUE);
		}
	
		gtk_table_attach (GTK_TABLE (position_table),positions[curr_pos][curr_align],curr_align, curr_align + 1,2, 3, GTK_FILL, GTK_FILL, 0, 0);
	}
	
	// Vertical Offset
	label = gtk_label_new (_("Vertical Offset:"));
	gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
	gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
	gtk_table_attach (GTK_TABLE (table), label, 0, 1, 4,5,GTK_FILL, GTK_FILL, 0, 0);
	
	hbox = gtk_hbox_new (FALSE, 6);
	gtk_table_attach (GTK_TABLE (table), hbox, 1, 2, 4, 5,GTK_FILL, GTK_FILL, 0, 0);
	
	offset_obj = gtk_adjustment_new (sven->osd->timeout, 0, 300, 1, 1, 1);
	offset_spin = gtk_spin_button_new (GTK_ADJUSTMENT (offset_obj), 1.0, 0);
	gtk_spin_button_set_value (GTK_SPIN_BUTTON (offset_spin), sven->osd->voffset);
	gtk_box_pack_start (GTK_BOX (hbox), offset_spin, FALSE, FALSE, 0);
	unit_label = gtk_label_new (_("pixels"));
	gtk_misc_set_alignment (GTK_MISC (unit_label), 0.0, 0.0);
	gtk_label_set_justify (GTK_LABEL (unit_label), GTK_JUSTIFY_LEFT);
	gtk_box_pack_start (GTK_BOX (hbox), unit_label, FALSE, FALSE, 0);
	
	// Horizontal Offset
	label = gtk_label_new (_("Horizontal Offset:"));
	gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
	gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
	gtk_table_attach (GTK_TABLE (table), label, 0, 1, 5,6,GTK_FILL, GTK_FILL, 0, 0);
	hbox = gtk_hbox_new (FALSE, 6);
	gtk_table_attach (GTK_TABLE (table), hbox, 1, 2, 5,6,GTK_FILL, GTK_FILL, 0, 0);
	
	h_offset_obj = gtk_adjustment_new (sven->osd->timeout, 0, 300, 1, 1, 1);
	h_offset_spin = gtk_spin_button_new (GTK_ADJUSTMENT (h_offset_obj), 1.0, 0);
	gtk_spin_button_set_value (GTK_SPIN_BUTTON (h_offset_spin), sven->osd->hoffset);
	gtk_box_pack_start (GTK_BOX (hbox), h_offset_spin, FALSE, FALSE, 0);
	unit_label = gtk_label_new (_("pixels"));
	gtk_misc_set_alignment (GTK_MISC (unit_label), 0.0, 0.0);
	gtk_label_set_justify (GTK_LABEL (unit_label), GTK_JUSTIFY_LEFT);
	gtk_box_pack_start (GTK_BOX (hbox), unit_label, FALSE, FALSE, 0);
	
	// Background color
	label = gtk_label_new (_("Background Color:"));
	gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
	gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
	gtk_table_attach (GTK_TABLE (table), label, 0, 1, 6,7,GTK_FILL, GTK_FILL, 0, 0);
	
	hbox = gtk_hbox_new (FALSE, 6);
	gtk_table_attach (GTK_TABLE (table), hbox, 1, 2, 6,7,GTK_FILL, GTK_FILL, 0, 0);
	
	bg_color_enable=gtk_check_button_new_with_mnemonic (_("Enable"));
	gtk_box_pack_start (GTK_BOX (hbox), bg_color_enable, FALSE, FALSE, 0);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bg_color_enable), sven->osd->bg_color_on);
	
	gtk_color_selection_palette_from_string (sven->osd->bg_color,&colors,&n_colors);
	bg_color = gtk_color_button_new_with_color (colors);
	
	gtk_box_pack_start (GTK_BOX (hbox), bg_color, FALSE, FALSE, 0);

	sep = gtk_hseparator_new ();
	gtk_box_pack_start (GTK_BOX (vbox), sep, FALSE, FALSE, 10);

	hbox1 = gtk_hbox_new (TRUE, 10);
	gtk_widget_show (hbox1);
	
	enable_xosd = gtk_check_button_new_with_mnemonic (_("Enable XOSD"));
	gtk_widget_show (enable_xosd);
	gtk_box_pack_start (GTK_BOX (hbox1), enable_xosd, FALSE, FALSE, 0);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_xosd), sven->osd->osd_on);
	
	enable_frame = gtk_check_button_new_with_mnemonic (_("Enable Frame"));
	gtk_widget_show (enable_frame);
	gtk_box_pack_start (GTK_BOX (hbox1), enable_frame, FALSE, FALSE, 0);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_frame), sven->osd->debug_frame);
	
	enable_shadow = gtk_check_button_new_with_mnemonic (_("Enable Shadow"));
	gtk_widget_show (enable_shadow);
	gtk_box_pack_start (GTK_BOX (hbox1), enable_shadow, FALSE, FALSE, 0);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_shadow), sven->osd->drop_shadow);
	
	gtk_box_pack_start (GTK_BOX (vbox), hbox1, FALSE, FALSE, 0);
	
	sep = gtk_hseparator_new ();
	gtk_box_pack_start (GTK_BOX (vbox), sep, FALSE, FALSE,5);

	button1 = gtk_button_new_with_mnemonic (_("Test OSD"));
	gtk_widget_show (button1);
	gtk_box_pack_start (GTK_BOX (vbox), button1, FALSE, FALSE, 5);
	g_signal_connect(button1, "clicked", G_CALLBACK(test_osd),sven);
	
	gtk_widget_show_all (vbox);
}
Example #28
0
void create_plugins_gui(Sven *sven,GtkWidget *vbox1)
{
	GtkTreeViewColumn *column;
	GtkCellRenderer *cell;
	GtkWidget *scrolled_win;
	GtkWidget *hbbox;
	GtkWidget *hbox;
	GtkWidget *frame;
	GtkWidget *alignment;
	GtkWidget *label;

	DEBUG_MSG("Start create_plugins_gui\n");

	gtk_box_pack_start (GTK_BOX (vbox1), create_header(_("Plugins")), FALSE, FALSE, 0);
  

	plugins_model = gtk_tree_store_new (3,G_TYPE_BOOLEAN,G_TYPE_STRING,G_TYPE_STRING);
	plugins_tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (plugins_model));
	gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (plugins_tree_view), TRUE);
	plugins_selection = G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (plugins_tree_view)));
	gtk_tree_selection_set_mode (GTK_TREE_SELECTION (plugins_selection), GTK_SELECTION_SINGLE);

	g_signal_connect (G_OBJECT (plugins_selection),"changed",G_CALLBACK (prefs_plugins_list_clicked),sven);
	g_signal_connect(G_OBJECT(plugins_tree_view), "button-press-event",G_CALLBACK(plugin_list_event_mouseclick), sven);

	scrolled_win = gtk_scrolled_window_new(NULL, NULL);
	gtk_container_add(GTK_CONTAINER(scrolled_win),  plugins_tree_view);
	gtk_container_border_width(GTK_CONTAINER(scrolled_win), 5);
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_win), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
	gtk_box_pack_start(GTK_BOX(vbox1), scrolled_win, TRUE, TRUE, 0);

	frame = gtk_frame_new (NULL);
	gtk_widget_show (frame);
	gtk_box_pack_start(GTK_BOX(vbox1), frame, TRUE, TRUE, 0);
	gtk_container_set_border_width (GTK_CONTAINER (frame), 2);
	gtk_frame_set_label_align (GTK_FRAME (frame), 0.05, 0.5);
	gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
	
	label = gtk_label_new (_("Description"));
	gtk_widget_show (label);
	gtk_frame_set_label_widget (GTK_FRAME (frame), label);
	gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
	
	alignment = gtk_alignment_new (0.5, 0.5, 1, 1);
	gtk_widget_show (alignment);
	gtk_container_add (GTK_CONTAINER (frame), alignment);
	gtk_container_set_border_width (GTK_CONTAINER (alignment), 2);
	gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 5, 5, 5, 5);

	infotext = gtk_label_new (_("Not information"));
	gtk_widget_show (infotext);
	gtk_container_add (GTK_CONTAINER (alignment), infotext);
	GTK_WIDGET_SET_FLAGS (infotext, GTK_CAN_FOCUS);
	gtk_label_set_line_wrap (GTK_LABEL (infotext), TRUE);
	gtk_label_set_selectable (GTK_LABEL (infotext), TRUE);
	
	
	hbox = gtk_hbox_new(FALSE, 0);
	gtk_box_pack_start(GTK_BOX(vbox1), hbox, FALSE, FALSE, 5);
	
	hbbox = gtk_hbutton_box_new();
	gtk_button_box_set_layout(GTK_BUTTON_BOX(hbbox), GTK_BUTTONBOX_START);
	gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbbox), 10);
	gtk_button_box_set_child_size(GTK_BUTTON_BOX(hbbox), 85, 17);
	gtk_box_pack_start(GTK_BOX(hbox), hbbox, TRUE, TRUE, 0);

	prefs_plugins_config_wid = gtk_button_new_with_label(_("Configure"));
	g_signal_connect(G_OBJECT(prefs_plugins_config_wid ), "clicked", G_CALLBACK(prefs_plugins_configure),sven);
	gtk_box_pack_start(GTK_BOX(hbbox), prefs_plugins_config_wid, TRUE, TRUE, 0);

	prefs_plugins_about_wid = gtk_button_new_with_label(_("About"));
	g_signal_connect(G_OBJECT(prefs_plugins_about_wid), "clicked", G_CALLBACK(prefs_plugins_about), sven);

	gtk_box_pack_start(GTK_BOX(hbbox), prefs_plugins_about_wid, TRUE, TRUE, 0);
	 
           	cell = gtk_cell_renderer_toggle_new ();
		  column = gtk_tree_view_column_new_with_attributes (_("Status"), cell, "active",0, NULL);
		  gtk_tree_view_column_set_clickable (column, TRUE);
		  g_signal_connect (G_OBJECT (cell), "toggled",G_CALLBACK (plugin_fixed_toggled),sven);
		  gtk_tree_view_column_set_resizable (column, TRUE);
		  gtk_tree_view_append_column (GTK_TREE_VIEW (plugins_tree_view), column);
		  
	        cell = gtk_cell_renderer_text_new ();
		  column = gtk_tree_view_column_new_with_attributes (_("Name"), cell, "markup", 1, NULL);
		  gtk_tree_view_column_set_sort_column_id (column, 0);
		  gtk_tree_view_column_set_resizable (column, TRUE);
		  gtk_tree_view_append_column (GTK_TREE_VIEW (plugins_tree_view), column);

		 cell = gtk_cell_renderer_text_new ();
		  column = gtk_tree_view_column_new_with_attributes (_("Module"), cell, "markup",2, NULL);
		  gtk_tree_view_column_set_sort_column_id (column, 1);
		  gtk_tree_view_column_set_resizable (column, TRUE);
		  gtk_tree_view_append_column (GTK_TREE_VIEW (plugins_tree_view), column);


		  gtk_widget_show(plugins_tree_view);

	add_print_plugins(GTK_TREE_VIEW (plugins_tree_view),sven);
}
Example #29
0
/**
 * Main routine. The main logic of ProbABEL can be found here
 *
 * \param argc Number of command line arguments
 * \param argv Vector containing the command line arguments
 *
 * \return 0 if all went well. Other integer numbers if an error
 * occurred
 */
int main(int argc, char * argv[])
{
    cmdvars input_var;
    input_var.set_variables(argc, argv);

    input_var.printinfo();

    cout << "Reading info data...\n" << flush;
    mlinfo mli(input_var.getMlinfofilename(), input_var.getMapfilename());
    int nsnps = mli.nsnps;
    phedata phd;
    cout << "Reading phenotype data...\n" << flush;
    int interaction_cox = create_phenotype(phd, input_var);

    masked_matrix invvarmatrix;

    if (input_var.getInverseFilename() != NULL)
    {
        loadInvSigma(input_var, phd, invvarmatrix);
    }

    gendata gtd;
    cout << "Reading genotype data... " << flush;
    if (!input_var.getIsFvf())
    {
        // TODO(maartenk): remove timing code
        // make clock to time loading of the non filevector file
        std::clock_t    start;
        start = std::clock();

        // use the non-filevector input format
        gtd.re_gendata(input_var.getGenfilename(), nsnps,
                       input_var.getNgpreds(), phd.nids_all, phd.nids,
                       phd.allmeasured, input_var.getSkipd(), phd.idnames);

        // TODO(maartenk): remove timing code
        double millisec=((std::clock() - start) / (double)(CLOCKS_PER_SEC / 1000))/1000;
        cout << "done in "<< millisec<< " seconds.\n" << flush;
    }
    else
    {
        // use the filevector input format (missing second last skipd
        // parameter)
        gtd.re_gendata(input_var.getStrGenfilename(), nsnps,
                       input_var.getNgpreds(), phd.nids_all, phd.nids,
                       phd.allmeasured, phd.idnames);
        cout << "done.\n" << flush;
    }


    // estimate null model
#if COXPH
    coxph_data nrgd = coxph_data(phd, gtd, -1);
#else
    regdata nrgd = regdata(phd, gtd, -1, input_var.isIsInteractionExcluded());
#endif

    std::cout << " loaded null data..." << std::flush;
#if LOGISTIC
    logistic_reg nrd = logistic_reg(nrgd);

    nrd.estimate(0, 0,
                 input_var.getInteraction(),
                 input_var.getNgpreds(),
                 invvarmatrix,
                 input_var.getRobust(),
                 1);
#elif LINEAR

    linear_reg nrd = linear_reg(nrgd);
#if DEBUG
    std::cout << "[DEBUG] linear_reg nrd = linear_reg(nrgd); DONE.";
#endif
    nrd.estimate(0, 0, input_var.getInteraction(),
                 input_var.getNgpreds(), invvarmatrix,
                 input_var.getRobust(), 1);
#elif COXPH
    coxph_reg nrd = coxph_reg(nrgd);
    nrd.estimate(nrgd, 0,
                 input_var.getInteraction(), input_var.getNgpreds(),
                 true, 1, mli, 0);
#endif
    double null_loglik = nrd.loglik;

    std::cout << " estimated null model...";
    // end null
#if COXPH
    coxph_data rgd(phd, gtd, 0);
#else
    regdata rgd(phd, gtd, 0, input_var.isIsInteractionExcluded());
#endif
    std::cout << " formed regression object...\n";


    // Open a vector of files that will be used for output. Depending
    // on the number of genomic predictors we either open 5 files (one
    // for each model if we have prob data) or one (if we have dosage
    // data).
    std::string outfilename_str(input_var.getOutfilename());
    std::vector<std::ofstream*> outfile;

    // Prob data: All models output. One file per model
    if (input_var.getNgpreds() == 2)
    {
        open_files_for_output(outfile, outfilename_str);
        if (input_var.getNohead() != 1)
        {
            create_header(outfile, input_var, phd, interaction_cox);
        }
    }
    else  // Dosage data: Only additive model => only one output file
    {
        outfile.push_back(
            new std::ofstream((outfilename_str + "_add.out.txt").c_str()));

        if (!outfile[0]->is_open())
        {
            std::cerr << "Cannot open file for writing: "
                      << outfilename_str
                      << "\n";
            exit(1);
        }
        if (input_var.getNohead() != 1)
        {
            create_header(outfile, input_var, phd, interaction_cox);
        }
    }  // END else: we have dosage data => only one file


    int maxmod = 5;             // Total number of models (in random
                                // order: additive, recessive,
                                // dominant, over_dominant, 2df). Only
                                // with dosage data can we run all of
                                // them. For dosage data we can only
                                // run the additive model.

    int start_pos, end_pos;

    std::vector<std::ostringstream *> beta_sebeta;
    // Han Chen
    std::vector<std::ostringstream *> covvalue;
    // Oct 26, 2009
    std::vector<std::ostringstream *> chi2;

    // Create string streams for betas, SEs, etc. These are used to
    // later store the various output values that will be written to
    // files.
    for (int i = 0; i < maxmod; i++)
    {
        beta_sebeta.push_back(new std::ostringstream());
        beta_sebeta[i]->precision(6);
        // *beta_sebeta[i] << scientific;
        // Han Chen
        covvalue.push_back(new std::ostringstream());
        covvalue[i]->precision(6);
        // *covvalue[i] << scientific;
        // Oct 26, 2009
        chi2.push_back(new std::ostringstream());
        chi2[i]->precision(6);
        // *chi2[i] << scientific;
    }


    // Here we start the analysis for each SNP.
    for (int csnp = 0; csnp < nsnps; csnp++)
    {
        rgd.update_snp(&gtd, csnp);


        int poly = 1;
        if (fabs(rgd.freq) < 1.e-16 || fabs(1. - rgd.freq) < 1.e-16)
        {
            poly = 0;
        }

        if (fabs(mli.Rsq[csnp]) < 1.e-16)
        {
            poly = 0;
        }

        // Write mlinfo information to the output file(s)
        // Prob data: All models output. One file per model
        if (input_var.getNgpreds() == 2)
        {
            for (unsigned int file = 0; file < outfile.size(); file++)
            {
                write_mlinfo(outfile, file, mli, csnp, input_var,
                             rgd.gcount, rgd.freq);
            }
        } else{
            // Dosage data: only additive model
            int file = 0;
            write_mlinfo(outfile, file, mli, csnp, input_var,
                         rgd.gcount, rgd.freq);
            maxmod = 1;         // We can only calculate the additive
                                // model with dosage data
        }

        // Run regression for each model for the current SNP
        for (int model = 0; model < maxmod; model++)
        {
            if (poly) // Allele freq is not too rare
            {
#if LOGISTIC
                logistic_reg rd(rgd);
#elif LINEAR
                linear_reg rd(rgd);
#elif COXPH
                coxph_reg rd(rgd);
#endif
#if !COXPH
                if (input_var.getScore())
                {
                    rd.score(nrd.residuals, model,
                             input_var.getInteraction(),
                             input_var.getNgpreds(),
                             invvarmatrix);
                }
                else
                {
                    rd.estimate(0, model,
                                input_var.getInteraction(),
                                input_var.getNgpreds(),
                                invvarmatrix,
                                input_var.getRobust());
                }
#else
                rd.estimate(rgd, model,
                            input_var.getInteraction(),
                            input_var.getNgpreds(), true, 0, mli, csnp);
#endif

                int number_of_rows_or_columns = rd.beta.nrow;
                start_pos = get_start_position(input_var, model,
                                               number_of_rows_or_columns);

                // The regression coefficients for the SNPs are in the
                // last rows of beta[] and sebeta[].
                for (int pos = start_pos; pos < rd.beta.nrow; pos++)
                {
                    *beta_sebeta[model] << input_var.getSep()
                                        << rd.beta[pos]
                                        << input_var.getSep()
                                        << rd.sebeta[pos];
                    // Han Chen
#if !COXPH
                    if (input_var.getInverseFilename() == NULL
                            && !input_var.getAllcov()
                            && input_var.getInteraction() != 0)
                    {
                        if (pos > start_pos)
                        {
                            if (model == 0)
                            {
                                if (input_var.getNgpreds() == 2)
                                {
                                    if (pos > start_pos + 2)
                                    {
                                        *covvalue[model]
                                            << rd.covariance[pos - 3]
                                            << input_var.getSep()
                                            << rd.covariance[pos - 2];
                                    }
                                }  // END ngpreds=2
                                else
                                {
                                    *covvalue[model] << rd.covariance[pos - 1];
                                }
                            }  // END model == 0
                            else
                            {
                                *covvalue[model] << rd.covariance[pos - 1];
                            }  // END model != 0
                        }  // END if pos > start_pos
                    }
#endif
                    // Oct 26, 2009
                }  // END for(pos = start_pos; pos < rd.beta.nrow; pos++)


                // calculate chi^2
                // ________________________________
                // cout <<  rd.loglik<<" "<<input_var.getNgpreds() << "\n";

                if (input_var.getInverseFilename() == NULL)
                { // Only if we don't have an inv.sigma file can we use LRT
                    if (input_var.getScore() == 0)
                    {
                        double loglik = rd.loglik;
                        if (rgd.gcount != gtd.nids)
                        {
                            // If SNP data is missing we didn't
                            // correctly compute the null likelihood

                            // Recalculate null likelihood by
                            // stripping the SNP data column(s) from
                            // the X matrix in the regression object
                            // and run the null model estimation again
                            // for this SNP.
#if !COXPH
                            regdata new_rgd = rgd;
#else
                            coxph_data new_rgd = rgd;
#endif

                            new_rgd.remove_snp_from_X();

#ifdef LINEAR
                            linear_reg new_null_rd(new_rgd);
#elif LOGISTIC
                            logistic_reg new_null_rd(new_rgd);
#endif
#if !COXPH
                            new_null_rd.estimate(0,
                                                 model,
                                                 input_var.getInteraction(),
                                                 input_var.getNgpreds(),
                                                 invvarmatrix,
                                                 input_var.getRobust(), 1);
#else
                            coxph_reg new_null_rd(new_rgd);
                            new_null_rd.estimate(new_rgd,
                                                 model,
                                                 input_var.getInteraction(),
                                                 input_var.getNgpreds(),
                                                 true, 1, mli, csnp);
#endif
                            *chi2[model] << 2. * (loglik - new_null_rd.loglik);
                        }
                        else
                        {
                            // No missing SNP data, we can compute the LRT
                            *chi2[model] << 2. * (loglik - null_loglik);
                        }
                    } else{
                        // We want score test output
                        *chi2[model] << rd.chi2_score;
                    }
                }  // END if( inv.sigma == NULL )
                else if (input_var.getInverseFilename() != NULL)
                {
                    // We can't use the LRT here, because mmscore is a
                    // REML method. Therefore go for the Wald test
                    if (input_var.getNgpreds() == 2 && model == 0)
                    {
                        /* For the 2df model we can't simply use the
                         * Wald statistic. This can be fixed using the
                         * equation just below Eq.(4) in the ProbABEL
                         * paper. TODO LCK
                         */
                        *chi2[model] << "NaN";
                    }
                    else
                    {
                        double Z = rd.beta[start_pos] / rd.sebeta[start_pos];
                        *chi2[model] << Z * Z;
                    }
                }
            }  // END first part of if(poly); allele not too rare
            else
            {   // SNP is rare: beta, sebeta, chi2 = NaN
                int number_of_rows_or_columns = rgd.X.ncol;
                start_pos = get_start_position(input_var, model,
                        number_of_rows_or_columns);

                if (input_var.getInteraction() != 0 && !input_var.getAllcov()
                    && input_var.getNgpreds() != 2)
                {
                    start_pos++;
                }

                if (input_var.getNgpreds() == 0)
                {
                    end_pos = rgd.X.ncol;
                } else{
                    end_pos = rgd.X.ncol - 1;
                }

                if (input_var.getInteraction() != 0)
                {
                    end_pos++;
                }

                for (int pos = start_pos; pos <= end_pos; pos++)
                {
                    *beta_sebeta[model] << input_var.getSep()
                            << "NaN"
                            << input_var.getSep()
                            << "NaN";
                }

                if (input_var.getNgpreds() == 2)
                {
                    // Han Chen
#if !COXPH
                    if (!input_var.getAllcov()
                            && input_var.getInteraction() != 0)
                    {
                        if (model == 0)
                        {
                            *covvalue[model] << "NaN"
                                             << input_var.getSep()
                                             << "NaN";
                        } else{
                            *covvalue[model] << "NaN";
                        }
                    }
#endif
                    // Oct 26, 2009
                    *chi2[model] << "NaN";
                } else{
                    // ngpreds==1 (and SNP is rare)
                    if (input_var.getInverseFilename() == NULL)
                    {
                        //                     Han Chen
#if !COXPH
                        if (!input_var.getAllcov()
                                && input_var.getInteraction() != 0)
                        {
                            *covvalue[model] << "NaN";
                        }
#endif
                        // Oct 26, 2009
                    }  // END if getInverseFilename == NULL
                    *chi2[model] << "NaN";
                }  // END ngpreds == 1 (and SNP is rare)
            }  // END else: SNP is rare
        }  // END of model cycle


        // Start writing beta's, se_beta's etc. to file
        if (input_var.getNgpreds() == 2)
        {
            for (int model = 0; model < maxmod; model++)
            {
                *outfile[model] << beta_sebeta[model]->str()
                                << input_var.getSep();
#if !COXPH
                if (!input_var.getAllcov() && input_var.getInteraction() != 0)
                {
                    *outfile[model] << covvalue[model]->str()
                                    << input_var.getSep();
                }
#endif
                *outfile[model] << chi2[model]->str()
                                << "\n";
            }  // END for loop over all models
        }
        else  // Dose data: only additive model. Only one output file
        {
            *outfile[0] << beta_sebeta[0]->str() << input_var.getSep();
#if !COXPH
            if (!input_var.getAllcov() && input_var.getInteraction() != 0)
            {
                *outfile[0] << covvalue[0]->str() << input_var.getSep();
            }
#endif
            *outfile[0] << chi2[0]->str() << "\n";
        }  // End ngpreds == 1 when writing output files


        // Clean chi2 and other streams
        for (int model = 0; model < maxmod; model++)
        {
            beta_sebeta[model]->str("");
            // Han Chen
            covvalue[model]->str("");
            // Oct 26, 2009
            chi2[model]->str("");
        }

        update_progress_to_cmd_line(csnp, nsnps);
    }  // END for loop over all SNPs


    // We're almost done. All computations have finished, time to
    // clean up.

    std::cout << setprecision(2) << fixed;
    std::cout << "\b\b\b\b\b\b\b\b\b" << 100.;
    std::cout << "%... done\n";

    // Close output files
    for (unsigned int i = 0; i < outfile.size(); i++)
    {
        outfile[i]->close();
        delete outfile[i];
    }

    // delete gtd;

    // Clean up a couple of vectors
    std::vector<std::ostringstream *>::iterator it = beta_sebeta.begin();
    while (it != beta_sebeta.end())
    {
        delete *it;
        ++it;
    }
    it = covvalue.begin();
    while (it != covvalue.end())
    {
        delete *it;
        ++it;
    }
    it = chi2.begin();
    while (it != chi2.end())
    {
        delete *it;
        ++it;
    }

    return (0);
}
Example #30
0
LRESULT playlist_view::on_message(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)
{
	switch (msg)
	{
	case WM_NCCREATE:
		wnd_playlist = wnd;
		initialised = true;
		list_playlist.add_item(this);
		g_playlist_message_window.add_ref();
		break;
	case WM_CREATE:
	{
		pfc::com_ptr_t<IDropTarget_playlist> IDT_playlist = new IDropTarget_playlist(this);
		RegisterDragDrop(wnd, IDT_playlist.get_ptr());
		if (true)
		{
			m_theme = IsThemeActive() && IsAppThemed() ? OpenThemeData(wnd, L"ListView") : NULL;
			SetWindowTheme(wnd, L"Explorer", NULL);
		}
		m_always_show_focus = config_object::g_get_data_bool_simple(standard_config_objects::bool_playback_follows_cursor, false);
		on_playlist_font_change();
		create_header(true);
		drawing_enabled = true;
		m_cache.initialise();
	}
	return 0;
	case WM_DESTROY:
		m_edit_save = false;
		exit_inline_edit();
		m_cache.deinitialise();
		RevokeDragDrop(wnd);
		SendMessage(wnd, WM_SETFONT, 0, 0);
		SendMessage(wnd_header, WM_SETFONT, 0, 0);
		{
			if (m_theme) CloseThemeData(m_theme);
			m_theme = NULL;
		}
		m_selection_holder.release();
		break;
	case WM_NCDESTROY:
		g_playlist_message_window.release();
		wnd_playlist = 0;
		initialised = false;
		list_playlist.remove_item(this);
		m_shown = false;
		//		if (!list_playlist.get_count())
		//		{
		//			g_playlist_entries.rebuild_all();
		//		}
		break;
	case WM_THEMECHANGED:
	{
		if (m_theme) CloseThemeData(m_theme);
		m_theme = IsThemeActive() && IsAppThemed() ? OpenThemeData(wnd, L"ListView") : 0;
	}
	break;
	case WM_SHOWWINDOW:
		if (wp == TRUE && lp == 0 && !m_shown)
		{
			static_api_ptr_t<playlist_manager> playlist_api;
			ensure_visible(playlist_api->activeplaylist_get_focus_item());
			m_shown = true;
		}
		break;
	case WM_WINDOWPOSCHANGED:
	{
		LPWINDOWPOS lpwp = (LPWINDOWPOS)lp;
		if (!(lpwp->flags & SWP_NOSIZE))
		{
			on_size(lpwp->cx, lpwp->cy);
		}
	}
	break;
	case WM_ERASEBKGND:
		return TRUE;
		break;
	case WM_PAINT:
	{
		PAINTSTRUCT ps;
		HDC dc_paint = BeginPaint(wnd, &ps);

		RECT rc_update, rc_playlist;
		get_playlist_rect(&rc_playlist);


		rc_update = ps.rcPaint;
		if (rc_update.top<rc_playlist.top) rc_update.top = rc_playlist.top;
		if (rc_update.bottom >= rc_update.top)
		{

			int item_height = get_item_height();

			int start_item = (rc_update.top - rc_playlist.top) / item_height;
			int end_item = (rc_update.bottom - rc_playlist.top) / item_height;

			if (((end_item - start_item) + 1)*item_height < rc_update.bottom - rc_update.top) end_item++;
			{
				draw_items(dc_paint, start_item, 1 + (end_item - start_item));
			}
		}
		EndPaint(wnd, &ps);
	}
	return 0;
	case WM_SETREDRAW:
		drawing_enabled = (wp != 0);
		return 0;
	case WM_MOUSEACTIVATE:
		if (GetFocus() != wnd)
			m_no_next_edit = true;
		return MA_ACTIVATE;
	case WM_UPDATEUISTATE:
		RedrawWindow(wnd_playlist, 0, 0, RDW_INVALIDATE);
		break;
	case WM_KILLFOCUS:
		RedrawWindow(wnd_playlist, 0, 0, RDW_INVALIDATE | RDW_UPDATENOW);
		m_selection_holder.release();
		break;
	case WM_SETFOCUS:
		//if (msg == WM_SETFOCUS && (HWND)wp != wnd)
		//m_no_next_edit = true;
		RedrawWindow(wnd_playlist, 0, 0, RDW_INVALIDATE | RDW_UPDATENOW);
		m_selection_holder = static_api_ptr_t<ui_selection_manager>()->acquire();
		m_selection_holder->set_playlist_selection_tracking();
		break;
	case WM_GETDLGCODE:
		return DLGC_WANTALLKEYS;
	case WM_KEYDOWN:
	{
		static_api_ptr_t<playlist_manager> playlist_api;
		uie::window_ptr p_this = this;
		//DWORD vk_slash = VkKeyScan('/');
		if (wp == VK_CONTROL) g_drag_lmb = true;
		if (m_prevent_wm_char_processing = process_keydown(msg, lp, wp, true)) return 0;
		else
		{
			SendMessage(wnd, WM_CHANGEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEFOCUS), NULL);
			if (wp == VK_HOME || wp == VK_DOWN || wp == VK_END || wp == VK_PRIOR || wp == VK_NEXT || wp == VK_UP)
			{
				int focus = playlist_api->activeplaylist_get_focus_item();
				int total = playlist_api->activeplaylist_get_item_count();

				if ((wp == VK_HOME || wp == VK_PRIOR || wp == VK_UP))
				{
					//	if (focus == 0) return 0;
				}
				if ((wp == VK_END || wp == VK_NEXT || wp == VK_DOWN))
				{
					//	if (focus == total - 1) return 0;
				}

				SCROLLINFO si;
				memset(&si, 0, sizeof(si));
				si.cbSize = sizeof(si);

				si.fMask = SIF_PAGE | SIF_POS;
				GetScrollInfo(wnd_playlist, SB_VERT, &si);

				int offset = 0;
				int scroll = scroll_item_offset;

				if (wp == VK_HOME)
					scroll = 0;
				else if (wp == VK_PRIOR && focus == scroll_item_offset)
					scroll -= si.nPage;
				else if (wp == VK_UP)
				{
					if (focus <= scroll_item_offset)
						scroll = focus - 1;
					else if (focus > si.nPos + si.nPage - 1)
						scroll = focus - 1 - si.nPage + 1;
				}
				else if (wp == VK_DOWN)
				{
					if (focus < scroll_item_offset)
						scroll = focus + 1;
					else if (focus >= si.nPos + si.nPage - 1)
						scroll = focus + 1 - si.nPage + 1;
				}
				else if (wp == VK_END)
					scroll = total - 1;
				else if (wp == VK_NEXT && focus == si.nPos + si.nPage - 1)
					scroll += si.nPage;

				drawing_enabled = false;

				si.nPos = scroll;
				si.fMask = SIF_POS;
				scroll_item_offset = SetScrollInfo(wnd_playlist, SB_VERT, &si, true);

				if (wp == VK_HOME)
					offset = 0 - focus;
				else if (wp == VK_PRIOR)
					offset = scroll_item_offset - focus;
				else if (wp == VK_END)
					offset = total - focus - 1;
				else if (wp == VK_NEXT)
					offset = get_last_viewable_item() - focus;
				else if (wp == VK_DOWN)
					offset = 1;
				else if (wp == VK_UP)
					offset = -1;


				//if (offset) 
				process_keydown(offset, ((HIWORD(lp) & KF_ALTDOWN) != 0), drawing_enabled, (HIWORD(lp) & KF_REPEAT) != 0);
				drawing_enabled = true;

				RedrawWindow(wnd_playlist, 0, 0, RDW_INVALIDATE | RDW_UPDATENOW);

				return 0;
			}
			else if (wp == VK_SPACE)
			{
				int focus = playlist_api->activeplaylist_get_focus_item();
				set_sel_single(focus, true, false, false);
				return 0;
			}
			else if (wp == VK_RETURN)
			{
				bool ctrl_down = 0 != (GetKeyState(VK_CONTROL) & KF_UP);
				int focus = playlist_api->activeplaylist_get_focus_item();
				unsigned active = playlist_api->get_active_playlist();
				if (ctrl_down)
				{
					if (active != -1 && focus != -1)
						playlist_api->queue_add_item_playlist(active, focus);
				}
				else
				{
					//					playlist_api->set_playing_playlist(active);
					unsigned focus = playlist_api->activeplaylist_get_focus_item();
					//unsigned active = playlist_api->get_active_playlist();
					//playlist_api->playlist_set_playback_cursor(active, focus);
					playlist_api->activeplaylist_execute_default_action(focus);
					//static_api_ptr_t<play_control>()->play_start(play_control::track_command_settrack);
				}
				return 0;
			}
			else if (wp == VK_SHIFT)
			{
				if (!(HIWORD(lp) & KF_REPEAT)) g_shift_item_start = playlist_api->activeplaylist_get_focus_item();
			}
			else if (wp == VK_F2)
			{
				unsigned count = g_get_cache().active_column_get_active_count();
				if (count)
				{
					unsigned focus = playlist_api->activeplaylist_get_focus_item();
					if (focus != pfc_infinite)
					{
						t_size i, pcount = playlist_api->activeplaylist_get_item_count();
						bit_array_bittable sel(pcount);
						playlist_api->activeplaylist_get_selection_mask(sel);

						pfc::list_t<t_size> indices;
						indices.prealloc(32);
						for (i = 0; i<pcount; i++)
							if (sel[i]) indices.add_item(i);

						/*t_size start = focus, end = focus;

						if (sel[start] && pcount)
						{
						while (start>0 && sel[start-1]) start--;
						while (end<pcount-1 && sel[end+1]) end++;
						}*/

						unsigned count = g_get_cache().active_column_get_active_count();
						unsigned column;
						for (column = 0; column<count; column++)
						{
							if (!g_get_columns()[g_get_cache().active_column_active_to_actual(column)]->edit_field.is_empty())
							{
								//create_inline_edit_v2(start, end-start+1, column);
								create_inline_edit_v2(indices, column);
								break;
							}
						}
					}
				}
			}
			else if (wp == VK_DELETE)
			{
				playlist_api->activeplaylist_undo_backup();
				playlist_api->activeplaylist_remove_selection();
			}
			else if (wp == VK_F3)
			{
				standard_commands::main_playlist_search();
			}
			/*else if (vk_slash != -1 && wp == LOWORD(vk_slash))
			{
			HWND wnd_search = m_searcher.create(wnd);
			on_size();
			ShowWindow(wnd_search, SW_SHOWNORMAL);
			;
			}*/
		}
	}
	break;
	case WM_CHAR:
		if (!m_prevent_wm_char_processing)
		{
			//if (!(HIWORD(lp) & KF_REPEAT))
			{
				if ((GetKeyState(VK_CONTROL) & KF_UP))
				{
					static_api_ptr_t<playlist_manager> playlist_api;
					if (wp == 1) //Ctrl-A
					{
						playlist_api->activeplaylist_set_selection(bit_array_true(), bit_array_true());
						return 0;
					}
					else if (wp == 26) //Ctrl-Z
					{
						playlist_api->activeplaylist_undo_restore();
						return 0;
					}
					else if (wp == 25) //Ctrl-Y
					{
						playlist_api->activeplaylist_redo_restore();
						return 0;
					}
					else if (wp == 24) //Ctrl-X
					{
						playlist_utils::cut();
						return 0;
					}
					else if (wp == 3) //Ctrl-C
					{
						playlist_utils::copy();
						return 0;
					}
					else if (wp == 6) //Ctrl-F
					{
						standard_commands::main_playlist_search();
						return 0;
					}
					else if (wp == 22) //Ctrl-V
					{
						playlist_utils::paste(wnd);
						return 0;
					}
				}
			}
		}
		break;
	case WM_KEYUP:
		if (process_keydown(msg, lp, wp, true)) return 0;
		break;
	case WM_SYSKEYUP:
		if (process_keydown(msg, lp, wp, true)) return 0;
		break;
	case WM_SYSKEYDOWN:
	{
		uie::window_ptr p_this = this;
		if (m_prevent_wm_char_processing = process_keydown(msg, lp, wp, true)) return 0;
	}
	break;
	case WM_LBUTTONDOWN:
	{
		if (0 && g_tooltip)
		{
			MSG message;
			memset(&message, 0, sizeof(MSG));
			message.hwnd = wnd;
			message.message = msg;
			message.wParam = wp;
			message.lParam = lp;

			uSendMessage(g_tooltip, TTM_RELAYEVENT, 0, (LPARAM)&message);
		}
		bool b_was_focused = GetFocus() == wnd;
		if (!b_was_focused)
			m_no_next_edit = true;
		//#ifdef INLINE_EDIT
		exit_inline_edit();
		//			g_no_next_edit = false;
		//#endif
		dragged = false;
		SetFocus(wnd);
		SetCapture(wnd);

		static_api_ptr_t<playlist_manager> playlist_api;
		g_drag_lmb = true;
		int focus = playlist_api->activeplaylist_get_focus_item();

		drag_start_lmb.x = GET_X_LPARAM(lp);
		drag_start_lmb.y = GET_Y_LPARAM(lp);

		int item_height = get_item_height();
		int idx = hittest_item(GET_X_LPARAM(lp), GET_Y_LPARAM(lp));
		//		int idx = ((GET_Y_LPARAM(lp) -get_header_height()) / item_height) + scroll_item_offset;
		//		if( idx >= 0 && idx <playlist_api->activeplaylist_get_item_count()  && GET_X_LPARAM(lp) < g_playlist_entries.get_total_width_actual())

		if (idx >= 0)
		{

			//		playlist_oper * playlist_api = playlist_api;
			//				playlist_api->set_playback_cursor(idx);
			//#ifdef INLINE_EDIT
			m_prev_sel = (playlist_api->activeplaylist_is_item_selected(idx) && !m_wnd_edit && (playlist_api->activeplaylist_get_selection_count(2) == 1));
			//#endif

			if (!is_visible(idx)) SendMessage(wnd_playlist, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), 0);

			if (wp & MK_CONTROL && wp & MK_SHIFT)
			{
				playlist_api->activeplaylist_move_selection(idx - focus);
				dragged = true;
				drag_type = 0;
			}
			else if (wp & MK_SHIFT)
			{
				drag_type = 2; dragitem = idx, dragstartitem = idx;

				int n = (cfg_alternative_sel ? focus : g_shift_item_start), t = idx;
				bool focus_sel = playlist_api->activeplaylist_is_item_selected(focus);


				set_sel_range(n, t, (cfg_alternative_sel != 0), (cfg_alternative_sel ? !focus_sel : false));
				playlist_api->activeplaylist_set_focus_item(idx);

				dragged = true;

			}
			else if (wp & MK_CONTROL)
			{
				/*			drag_type = 2; dragitem = idx,dragstartitem=idx;

				set_sel_single(idx, false, true, false);

				dragged = true;*/

			}
			else if (playlist_api->activeplaylist_is_item_selected(idx))
			{
				drag_type = 1; dragitem = idx, dragstartitem = idx;
				playlist_api->activeplaylist_undo_backup();
				playlist_api->activeplaylist_set_focus_item(idx);
				dragged = false;
			}
			else
			{
				drag_type = 2; dragitem = idx, dragstartitem = idx;//item irrelevant actually;

				set_sel_single(idx, false, true, true);

				/*			bit_array_bittable mask(playlist_api->activeplaylist_get_item_count());
				//		playlist_api->activeplaylist_is_item_selected_mask(mask);
				int n, t = playlist_api->activeplaylist_get_item_count();
				for (n = 0;n <t;n++) { if (n==idx) mask.set(n, true); else mask.set(n, false); }

				console::info("crap");
				playlist_api->set_sel_mask(mask);
				playlist_api->activeplaylist_set_focus_item(idx);*/

				dragged = false;
			}
		}
		else
		{
			//			console::info("wow");
			//				bit_array_bittable mask(playlist_api->activeplaylist_get_item_count());
			playlist_api->activeplaylist_set_selection(bit_array_true(), bit_array_false());
			dragged = true;
			drag_type = 0;
		}
	}

	break;
	case WM_RBUTTONUP:
		m_no_next_edit = false;
		break;
	case WM_MBUTTONUP:
	{
		m_no_next_edit = false;
		unsigned idx = hittest_item(GET_X_LPARAM(lp), GET_Y_LPARAM(lp));
		playlist_mclick_actions::run(cfg_playlist_middle_action, idx != -1, idx);
	}
	break;

	case WM_LBUTTONUP:
	{
		if (0 && g_tooltip)
		{
			MSG message;
			memset(&message, 0, sizeof(MSG));
			message.hwnd = wnd;
			message.message = msg;
			message.wParam = wp;
			message.lParam = lp;

			uSendMessage(g_tooltip, TTM_RELAYEVENT, 0, (LPARAM)&message);
		}
		ReleaseCapture();
		g_drag_lmb = false;
		int idx = hittest_item(GET_X_LPARAM(lp), GET_Y_LPARAM(lp), true);   //((GET_Y_LPARAM(lp) -get_header_height()) / get_item_height()) + scroll_item_offset;
		static_api_ptr_t<playlist_manager> playlist_api;
		if (!dragged)
		{
			if (wp & MK_CONTROL)
			{
				//			int idx_down = hittest_item(drag_start_lmb.x, drag_start_lmb.y);
				if (idx >= 0) set_sel_single(idx, true, true, false);
			}
			else
			{

				//				int item_height = get_item_height();

				//			int idx = ((GET_Y_LPARAM(lp) - get_header_height()) / item_height) + scroll_item_offset;
				if (idx >= 0 /*&& idx < playlist_api->activeplaylist_get_item_count() && (GET_X_LPARAM(lp) < g_playlist_entries.get_total_width_actual())*/)
				{



					if (!m_no_next_edit && cfg_inline_edit && playlist_api->activeplaylist_is_item_selected(idx) && m_prev_sel /*&& !dragged*/)
					{
						//if (m_no_next_edit && GetCapture() == wnd) ReleaseCapture();

						{
							exit_inline_edit();
							if (main_window::config_get_inline_metafield_edit_mode() != main_window::mode_disabled)
							{
								m_edit_index = idx;
								long width;
								m_edit_column = hittest_column(GET_X_LPARAM(lp), width);
								if (m_edit_column >= 0 && !g_get_columns()[g_get_cache().active_column_active_to_actual(m_edit_column)]->edit_field.is_empty())
								{
									m_edit_timer = (SetTimer(wnd, EDIT_TIMER_ID, GetDoubleClickTime(), 0) != 0);
								}
							}
						}

					}

					int focus = playlist_api->activeplaylist_get_focus_item();
					set_sel_single(focus, false, false, true);
				}


			}
		}
		dragged = true;
		drag_type = 0;
		dragstartitem = 0;
		dragitem = 0;
		//#ifdef INLINE_EDIT
		m_no_next_edit = false;
		//#endif
	}
	break;
	case WM_MOUSEMOVE:
	{
		if (0 && g_tooltip)
		{
			MSG message;
			memset(&message, 0, sizeof(MSG));
			message.hwnd = wnd;
			message.message = msg;
			message.wParam = wp;
			message.lParam = lp;

			uSendMessage(g_tooltip, TTM_RELAYEVENT, 0, (LPARAM)&message);
		}
		const unsigned cx_drag = (unsigned)abs(GetSystemMetrics(SM_CXDRAG));
		const unsigned cy_drag = (unsigned)abs(GetSystemMetrics(SM_CYDRAG));
		if (!g_dragging && ((g_dragging1 && wp & MK_RBUTTON && (abs(drag_start.x - GET_X_LPARAM(lp)) > cx_drag || abs(drag_start.y - GET_Y_LPARAM(lp)) > cy_drag)) || (g_drag_lmb && (wp & MK_LBUTTON) && (wp & MK_CONTROL) && (abs(drag_start_lmb.x - GET_X_LPARAM(lp)) > 3 || abs(drag_start_lmb.y - GET_Y_LPARAM(lp)) > 3))))
		{
			static_api_ptr_t<playlist_manager> playlist_api;
			metadb_handle_list data;
			playlist_api->activeplaylist_get_selected_items(data);
			if (data.get_count() > 0)
			{
				static_api_ptr_t<playlist_incoming_item_filter> incoming_api;
				IDataObject * pDataObject = incoming_api->create_dataobject(data);
				if (pDataObject)
				{
					//RegisterClipboardFormat(_T("foo_ui_columns");

					if (g_tooltip) { DestroyWindow(g_tooltip); g_tooltip = 0; last_idx = -1; last_column = -1; }
					DWORD blah;
					{
						pfc::com_ptr_t<IDropSource_playlist> p_IDropSource_playlist = new IDropSource_playlist(this);
						DoDragDrop(pDataObject, p_IDropSource_playlist.get_ptr(), DROPEFFECT_COPY, &blah);
					}
					pDataObject->Release();
				}
			}
			data.remove_all();
			g_dragging = false;
			g_dragging1 = false;
			g_drag_lmb = false;
			if (wp & MK_LBUTTON)
			{
				dragged = true;
				drag_type = 0;
				dragstartitem = 0;
				dragitem = 0;
			}
		}




		if (cfg_tooltip && (GET_Y_LPARAM(lp) > get_header_height()))
		{
			int item_height = get_item_height();
			int idx = hittest_item(GET_X_LPARAM(lp), GET_Y_LPARAM(lp));
			long cx;
			int column = hittest_column(GET_X_LPARAM(lp), cx);
			//			unsigned act_col = g_cache.active_column_active_to_actual(column);

			if (column >= 0 && idx >= 0)
			{
				if (last_idx != (idx) || last_column != column)
				{
					if (!cfg_tooltips_clipped || is_item_clipped(idx, column))
					{
						pfc::string8 src;
						g_cache.active_get_display_name(idx, column, src);
						pfc::string8 temp;
						titleformat_compiler::remove_color_marks(src, temp);
						temp.replace_char(9, 0x20);
						CreateToolTip(temp);
					}
					else { DestroyWindow(g_tooltip); g_tooltip = 0; last_idx = -1; last_column = -1; }

					POINT a;
					a.x = cx + 3;
					a.y = (idx - scroll_item_offset) * item_height + get_header_height();
					ClientToScreen(wnd_playlist, &a);

					tooltip.top = a.y;
					tooltip.bottom = a.y + item_height;
					tooltip.left = a.x;
					tooltip.right = a.x + get_column_width(column);

				}
				last_idx = idx;
				last_column = column;
			}
			else { DestroyWindow(g_tooltip); g_tooltip = 0; last_idx = -1; last_column = -1; }
		}


		if (drag_type && (wp & MK_LBUTTON) && !(GetKeyState(VK_SHIFT) & KF_UP) && !(GetKeyState(VK_CONTROL) & KF_UP))
		{
			RECT rc;
			get_playlist_rect(&rc);
			static_api_ptr_t<playlist_manager> playlist_api;

			int total = playlist_api->activeplaylist_get_item_count();

			int item_height = get_item_height();
			int valid_idx = hittest_item(GET_X_LPARAM(lp), GET_Y_LPARAM(lp), false);
			int idx = hittest_item_no_scroll(GET_X_LPARAM(lp), GET_Y_LPARAM(lp), false);
			//    (GET_Y_LPARAM(lp) - get_header_height()) / (item_height);

			int items_count = ((rc.bottom - rc.top) / item_height) + 1;


			if ((idx + scroll_item_offset) != dragitem || GET_Y_LPARAM(lp) < get_header_height()) //(idx + scroll_item_offset) < playlist_api->activeplaylist_get_item_count()
			{
				if (idx >= items_count - 1)
				{

					bool need_redrawing = false;

					int focus = playlist_api->activeplaylist_get_focus_item();

					SCROLLINFO si;
					memset(&si, 0, sizeof(si));
					si.cbSize = sizeof(si);
					si.fMask = SIF_POS;
					GetScrollInfo(wnd_playlist, SB_VERT, &si);

					int old_offset = si.nPos;
					si.nPos += 3;

					scroll_item_offset = SetScrollInfo(wnd_playlist, SB_VERT, &si, true);

					if (old_offset != scroll_item_offset) need_redrawing = true;

					int t = scroll_item_offset + items_count - 2; //n=dragitem,

					if (t > total) t = total - 1;


					if (t != dragitem)
					{

						drawing_enabled = false;
						if (drag_type == 1)
							playlist_api->activeplaylist_move_selection((rc.bottom - rc.top) / item_height + scroll_item_offset - focus - 1);
						else if (drag_type == 2)
						{

							set_sel_range(dragstartitem, t, false);
							playlist_api->activeplaylist_set_focus_item(t);
						}

						dragitem = t;
						drawing_enabled = true;
						need_redrawing = true;

					}
					if (need_redrawing) RedrawWindow(wnd_playlist, 0, 0, RDW_INVALIDATE | RDW_UPDATENOW);


				}
				else if (idx < 0 || GET_Y_LPARAM(lp) < get_header_height() || GET_Y_LPARAM(lp) < 0)
				{


					int focus = playlist_api->activeplaylist_get_focus_item();

					bool need_redrawing = false;

					SCROLLINFO si;
					memset(&si, 0, sizeof(si));
					si.cbSize = sizeof(si);
					si.fMask = SIF_POS;
					GetScrollInfo(wnd_playlist, SB_VERT, &si);
					int old_offset = si.nPos;
					si.nPos -= 3;
					scroll_item_offset = SetScrollInfo(wnd_playlist, SB_VERT, &si, true);

					if (old_offset != scroll_item_offset) need_redrawing = true;

					if (dragitem != scroll_item_offset)
					{
						drawing_enabled = false;
						if (drag_type == 1)
							playlist_api->activeplaylist_move_selection(scroll_item_offset - focus);
						else if (drag_type == 2)
						{

							set_sel_range(dragstartitem, scroll_item_offset, false);
							playlist_api->activeplaylist_set_focus_item(scroll_item_offset);
							RedrawWindow(wnd_playlist, 0, 0, RDW_INVALIDATE | RDW_UPDATENOW);
						}

						dragitem = scroll_item_offset;
						drawing_enabled = true;
						need_redrawing = true;
					}

					if (need_redrawing) RedrawWindow(wnd_playlist, 0, 0, RDW_INVALIDATE | RDW_UPDATENOW);


				}
				else
				{
					int focus = playlist_api->activeplaylist_get_focus_item();

					if (drag_type == 1)
						playlist_api->activeplaylist_move_selection(idx + scroll_item_offset - focus);
					else if (drag_type == 2)
					{
						if (valid_idx >= 0)
						{
							drawing_enabled = false;
							set_sel_range(dragstartitem, valid_idx, false);
							playlist_api->activeplaylist_set_focus_item(valid_idx);
							drawing_enabled = true;
							RedrawWindow(wnd_playlist, 0, 0, RDW_INVALIDATE | RDW_UPDATENOW);
						}

					}

					dragitem = valid_idx;
					dragged = true;
				}
			}

		}
		else if (!(wp & MK_LBUTTON)) drag_type = 0;
	}
	break;
	case WM_LBUTTONDBLCLK:
	{
		int idx = hittest_item(GET_X_LPARAM(lp), GET_Y_LPARAM(lp), true);

		if (idx >= 0)
		{
			//#ifdef INLINE_EDIT
			exit_inline_edit();
			m_no_next_edit = true;
			//#endif
			//if (!is_visible(idx)) uSendMessage(wnd_playlist, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0),0);

#if 0
			// DEATH's code
	case WM_LBUTTONDBLCLK:
	{
		int idx = item_from_point((short)HIWORD(lp));
		if (idx >= 0 && idx<(int)m_api->activeplaylist_get_item_count())
		{
			m_api->activeplaylist_set_focus_item(idx);
			static_api_ptr_t<play_control>()->play_start(play_control::TRACK_COMMAND_SETTRACK);
		}
	}
	return 0;
#endif
	static_api_ptr_t<playlist_manager> playlist_api;
	//unsigned active = playlist_api->get_active_playlist();
	//				playlist_api->set_playing_playlist(active);
	//playlist_api->playlist_set_playback_cursor(active, idx);
	//playlist_api->queue_flush();
	unsigned focus = playlist_api->activeplaylist_get_focus_item();
	playlist_api->activeplaylist_execute_default_action(focus);

		}
		else if (cfg_playlist_double.get_value().m_command != pfc::guid_null)
		{
			mainmenu_commands::g_execute(cfg_playlist_double.get_value().m_command);
		}

		dragged = true;
	}

	break;
	case WM_RBUTTONDOWN:
	{
		if (wnd_playlist) SetFocus(wnd_playlist);

		g_dragging1 = true;

		drag_start.x = GET_X_LPARAM(lp);
		drag_start.y = GET_Y_LPARAM(lp);

		static_api_ptr_t<playlist_manager> playlist_api;


		//		int item_height = get_item_height();
		//		int idx = ((GET_Y_LPARAM(lp) - get_header_height()) / item_height) + scroll_item_offset;
		int idx = hittest_item(GET_X_LPARAM(lp), GET_Y_LPARAM(lp), true);
		if (idx != -1 && !is_visible(idx))
			SendMessage(wnd_playlist, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), 0);

		if (idx >= 0 /*&& idx < playlist_api->activeplaylist_get_item_count() && (GET_X_LPARAM(lp) < g_playlist_entries.get_total_width_actual())*/)
		{

			if (!playlist_api->activeplaylist_is_item_selected(idx) && !(GetKeyState(VK_CONTROL) & KF_UP))
			{
				set_sel_single(idx, false, false, true);
			}
			playlist_api->activeplaylist_set_focus_item(idx);

		}


	}

	break;
	case WM_MOUSEWHEEL:
	{//GET_WHEEL_DELTA_WPARAM
		exit_inline_edit();
		if (1 || (wp & MK_CONTROL))
		{

			LONG_PTR style = GetWindowLongPtr(wnd_playlist, GWL_STYLE);
			if (!(style & WS_VSCROLL) || ((wp & MK_CONTROL) && (style & WS_HSCROLL)))
			{
				if ((style & WS_HSCROLL))
				{
					SCROLLINFO si;
					memset(&si, 0, sizeof(SCROLLINFO));
					si.fMask = SIF_PAGE;
					si.cbSize = sizeof(SCROLLINFO);
					GetScrollInfo(wnd, SB_HORZ, &si);

					int new_pos = horizontal_offset;
					int old_pos = horizontal_offset;

					unsigned scroll_lines = GetNumScrollLines();

					int zDelta = short(HIWORD(wp));

					if (scroll_lines == -1)
					{
						scroll_lines = si.nPage > 1 ? si.nPage - 1 : 1;
					}
					else scroll_lines *= 3;

					int delta = MulDiv(zDelta, scroll_lines, 120);

					if (!si.nPage) si.nPage++;

					if (delta < 0 && delta*-1 > si.nPage)
					{
						delta = si.nPage*-1;
						if (delta >1) delta--;
					}
					else if (delta > 0 && delta > si.nPage)
					{
						delta = si.nPage;
						if (delta >1) delta--;
					}

					scroll(scroll_horizontally, scroll_position_delta, -delta);

				}
				return 1;
			}
		}

		SCROLLINFO si;
		memset(&si, 0, sizeof(SCROLLINFO));
		si.fMask = SIF_PAGE;
		si.cbSize = sizeof(SCROLLINFO);
		GetScrollInfo(wnd, SB_VERT, &si);

		int new_pos = scroll_item_offset;
		int old_pos = scroll_item_offset;
		unsigned scroll_lines = GetNumScrollLines();

		int zDelta = short(HIWORD(wp));

		if (scroll_lines == -1)
		{
			scroll_lines = si.nPage > 1 ? si.nPage - 1 : 1;
		}

		int delta = MulDiv(zDelta, scroll_lines, 120);

		if (!si.nPage) si.nPage++;

		if (delta < 0 && delta*-1 > si.nPage)
		{
			delta = si.nPage*-1;
			if (delta >1) delta--;
		}
		else if (delta > 0 && delta > si.nPage)
		{
			delta = si.nPage;
			if (delta >1) delta--;
		}

		scroll(scroll_vertically, scroll_position_delta, -delta);
	}
	return 1;
	case WM_VSCROLL:
	{
		exit_inline_edit();
		scroll(scroll_vertically, scroll_sb, LOWORD(wp));
	}
	return 0;
	case WM_HSCROLL:
	{
		exit_inline_edit();
		scroll(scroll_horizontally, scroll_sb, LOWORD(wp));
	}
	return 0;
	case WM_MENUSELECT:
	{
		if (HIWORD(wp) & MF_POPUP)
		{
			m_status_override.release();
		}
		else
		{
			if (g_main_menu_a.is_valid() || g_main_menu_b.is_valid())
			{
				unsigned id = LOWORD(wp);

				bool set = false;

				pfc::string8 desc;

				if (g_main_menu_a.is_valid() && id < MENU_B_BASE)
				{
					set = g_main_menu_a->get_description(id - MENU_A_BASE, desc);
				}
				else if (g_main_menu_b.is_valid())
				{
					contextmenu_node * node = g_main_menu_b->find_by_id(id - MENU_B_BASE);
					if (node) set = node->get_description(desc);
				}

				service_ptr_t<ui_status_text_override> p_status_override;

				if (set)
				{
					get_host()->override_status_text_create(p_status_override);

					if (p_status_override.is_valid())
					{
						p_status_override->override_text(desc);
					}
				}
				m_status_override = p_status_override;
			}
		}
	}
	break;
	case WM_CONTEXTMENU:
	{
		uie::window_ptr p_this_temp = this;
		if ((HWND)wp == wnd_header)
		{
			POINT pt = { (short)LOWORD(lp), (short)HIWORD(lp) };
			POINT temp;
			temp.x = pt.x;
			temp.y = pt.y;
			ScreenToClient(wnd_header, &temp);
			HDHITTESTINFO hittest;
			hittest.pt.x = temp.x;
			hittest.pt.y = temp.y;


			uSendMessage(wnd_header, HDM_HITTEST, 0, (LPARAM)&hittest);

			enum { IDM_ASC = 1, IDM_DES = 2, IDM_SEL_ASC, IDM_SEL_DES, IDM_AUTOSIZE, IDM_PREFS, IDM_EDIT_COLUMN, IDM_CUSTOM_BASE };

			HMENU menu = CreatePopupMenu();
			HMENU selection_menu = CreatePopupMenu();
			if (!(hittest.flags & HHT_NOWHERE))
			{
				uAppendMenu(menu, (MF_STRING), IDM_ASC, "&Sort ascending");
				uAppendMenu(menu, (MF_STRING), IDM_DES, "Sort &descending");
				uAppendMenu(selection_menu, (MF_STRING), IDM_SEL_ASC, "Sort a&scending");
				uAppendMenu(selection_menu, (MF_STRING), IDM_SEL_DES, "Sort d&escending");
				uAppendMenu(menu, MF_STRING | MF_POPUP, (UINT)selection_menu, "Se&lection");
				uAppendMenu(menu, (MF_SEPARATOR), 0, "");
				uAppendMenu(menu, (MF_STRING), IDM_EDIT_COLUMN, "&Edit this column");
				uAppendMenu(menu, (MF_SEPARATOR), 0, "");
				uAppendMenu(menu, (MF_STRING | (cfg_nohscroll ? MF_CHECKED : MF_UNCHECKED)), IDM_AUTOSIZE, "&Auto-sizing columns");
				uAppendMenu(menu, (MF_STRING), IDM_PREFS, "&Preferences");
				uAppendMenu(menu, (MF_SEPARATOR), 0, "");

				pfc::string8 playlist_name;
				static_api_ptr_t<playlist_manager> playlist_api;
				playlist_api->activeplaylist_get_name(playlist_name);

				pfc::string8_fast_aggressive filter, name;

				int s, e = columns.get_count();
				for (s = 0; s<e; s++)
				{
					bool add = false;
					switch (columns[s]->filter_type)
					{
					case FILTER_NONE:
					{
						add = true;
						break;
					}
					case FILTER_SHOW:
					{
						if (wildcard_helper::test(playlist_name, columns[s]->filter, true))
						{
							add = true;
							/*				g_columns.get_string(s, name, STRING_NAME);
							uAppendMenu(menu,MF_STRING|MF_CHECKED,IDM_CUSTOM_BASE+s,name);*/
						}
					}
					break;
					case FILTER_HIDE:
					{
						if (!wildcard_helper::test(playlist_name, columns[s]->filter, true))
						{
							add = true;
							/*						g_columns.get_string(s, name, STRING_NAME);
							uAppendMenu(menu,MF_STRING|MF_CHECKED,IDM_CUSTOM_BASE+s,name);*/
						}
					}
					break;
					}
					if (add)
					{
						uAppendMenu(menu, MF_STRING | (columns[s]->show ? MF_CHECKED : MF_UNCHECKED), IDM_CUSTOM_BASE + s, columns[s]->name);
					}
				}


			}
			else
			{
				uAppendMenu(menu, (MF_STRING | (cfg_nohscroll ? MF_CHECKED : MF_UNCHECKED)), IDM_AUTOSIZE, "&Auto-sizing columns");
				uAppendMenu(menu, (MF_STRING), IDM_PREFS, "&Preferences");
			}


			menu_helpers::win32_auto_mnemonics(menu);

			int cmd = TrackPopupMenu(menu, TPM_RIGHTBUTTON | TPM_NONOTIFY | TPM_RETURNCMD, pt.x, pt.y, 0, wnd, 0);
			DestroyMenu(menu);

			if (cmd == IDM_ASC)
			{

				g_set_sort(hittest.iItem, false);
			}
			else if (cmd == IDM_DES)
			{
				g_set_sort(hittest.iItem, true);
			}
			else if (cmd == IDM_SEL_ASC)
			{
				g_set_sort(hittest.iItem, false, true);
			}
			else if (cmd == IDM_SEL_DES)
			{
				g_set_sort(hittest.iItem, true, true);
			}
			else if (cmd == IDM_EDIT_COLUMN)
			{
				g_set_tab("Columns");
				cfg_cur_prefs_col = g_cache.active_column_active_to_actual(hittest.iItem); //get_idx
				static_api_ptr_t<ui_control>()->show_preferences(columns::config_get_playlist_view_guid());
			}
			else if (cmd == IDM_AUTOSIZE)
			{
				cfg_nohscroll = cfg_nohscroll == 0;
				update_all_windows();
				pvt::ng_playlist_view_t::g_on_autosize_change();
			}
			else if (cmd == IDM_PREFS)
			{
				static_api_ptr_t<ui_control>()->show_preferences(columns::config_get_main_guid());
			}
			else if (cmd >= IDM_CUSTOM_BASE)
			{
				if (t_size(cmd - IDM_CUSTOM_BASE) < columns.get_count())
				{
					columns[cmd - IDM_CUSTOM_BASE]->show = !columns[cmd - IDM_CUSTOM_BASE]->show; //g_columns
					//if (!cfg_nohscroll) 
					g_save_columns();
					//g_cache.flush_all();
					g_reset_columns();
					update_all_windows();
					pvt::ng_playlist_view_t::g_on_columns_change();
				}

			}
			return 0;
		}
		else if ((HWND)wp == wnd)
		{
			//DWORD mp = GetMessagePos();
			POINT px, pt = { GET_X_LPARAM(lp), GET_Y_LPARAM(lp) };
			static_api_ptr_t<playlist_manager> playlist_api;
			if (playlist_api->activeplaylist_get_selection_count(1) > 0 && 1)
			{
				if (pt.x == -1 && pt.y == -1)
				{
					int focus = playlist_api->activeplaylist_get_focus_item();
					unsigned last = get_last_viewable_item();
					if (focus == -1 || focus < scroll_item_offset || focus > last)
					{
						px.x = 0;
						px.y = 0;
					}
					else
					{
						RECT rc;
						get_playlist_rect(&rc);
						px.x = 0;
						unsigned item_height = get_item_height();
						px.y = (focus - scroll_item_offset)*(item_height)+item_height / 2 + rc.top;
					}
					pt = px;
					MapWindowPoints(wnd, HWND_DESKTOP, &pt, 1);
				}
				else
				{
					px = pt;
					ScreenToClient(wnd, &px);
					//int idx = hittest_item(px.x, px.y);
					//if (!is_visible(idx))
					//	SendMessage(wnd_playlist, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0),0);

				}
				//			int idx = hittest_item(px.x, px.y);

				enum { ID_PLAY = 1, ID_CUT, ID_COPY, ID_PASTE, ID_SELECTION, ID_CUSTOM_BASE = 0x8000 };
				HMENU menu = CreatePopupMenu();//LoadMenu(core_api::get_my_instance(),MAKEINTRESOURCE(IDR_TREEPOPUP));

				service_ptr_t<mainmenu_manager> p_manager_selection;
				service_ptr_t<contextmenu_manager> p_manager_context;
				p_manager_selection = standard_api_create_t<mainmenu_manager>();
				contextmenu_manager::g_create(p_manager_context);
				if (p_manager_selection.is_valid())
				{
					p_manager_selection->instantiate(mainmenu_groups::edit_part2_selection);
					p_manager_selection->generate_menu_win32(menu, ID_SELECTION, ID_CUSTOM_BASE - ID_SELECTION, standard_config_objects::query_show_keyboard_shortcuts_in_menus() ? contextmenu_manager::FLAG_SHOW_SHORTCUTS : 0);
					if (GetMenuItemCount(menu) > 0) uAppendMenu(menu, MF_SEPARATOR, 0, "");
				}

				AppendMenu(menu, MF_STRING, ID_CUT, L"Cut");
				AppendMenu(menu, MF_STRING, ID_COPY, L"Copy");
				if (playlist_utils::check_clipboard())
					AppendMenu(menu, MF_STRING, ID_PASTE, L"Paste");
				AppendMenu(menu, MF_SEPARATOR, 0, NULL);
				if (p_manager_context.is_valid())
				{
					const keyboard_shortcut_manager::shortcut_type shortcuts[] = { keyboard_shortcut_manager::TYPE_CONTEXT_PLAYLIST, keyboard_shortcut_manager::TYPE_CONTEXT };
					p_manager_context->set_shortcut_preference(shortcuts, tabsize(shortcuts));
					p_manager_context->init_context_playlist(standard_config_objects::query_show_keyboard_shortcuts_in_menus() ? contextmenu_manager::FLAG_SHOW_SHORTCUTS : 0);

					p_manager_context->win32_build_menu(menu, ID_CUSTOM_BASE, -1);
				}
				menu_helpers::win32_auto_mnemonics(menu);
				MENU_A_BASE = ID_SELECTION;
				MENU_B_BASE = ID_CUSTOM_BASE;

				g_main_menu_a = p_manager_selection;
				g_main_menu_b = p_manager_context;

				int cmd = TrackPopupMenu(menu, TPM_RIGHTBUTTON | TPM_NONOTIFY | TPM_RETURNCMD, pt.x, pt.y, 0, wnd, 0);
				if (m_status_override.is_valid())
				{
					m_status_override.release();
				}

				DestroyMenu(menu);
				if (cmd)
				{
					if (cmd == ID_CUT)
					{
						playlist_utils::cut();
					}
					else if (cmd == ID_COPY)
					{
						playlist_utils::copy();
					}
					else if (cmd == ID_PASTE)
					{
						playlist_utils::paste(wnd);
					}
					else if (cmd >= ID_SELECTION && cmd<ID_CUSTOM_BASE)
					{
						if (p_manager_selection.is_valid())
						{
							p_manager_selection->execute_command(cmd - ID_SELECTION);
						}
					}
					else if (cmd >= ID_CUSTOM_BASE)
					{
						if (p_manager_context.is_valid())
						{
							p_manager_context->execute_by_id(cmd - ID_CUSTOM_BASE);
						}
					}
				}
				g_main_menu_a.release();
				g_main_menu_b.release();
			}


			//	contextmenu_manager::win32_run_menu_context_playlist(wnd, 0, config_object::g_get_data_bool_simple(standard_config_objects::bool_show_keyboard_shortcuts_in_menus, true) ? contextmenu_manager::FLAG_SHOW_SHORTCUTS : 0);
		}
	}
	return 0;

	//#ifdef INLINE_EDIT
	case WM_PARENTNOTIFY:
	{
		if (wp == WM_DESTROY)
		{
			if (m_wnd_edit && (HWND)lp == m_wnd_edit) m_wnd_edit = 0;
		}
	}
	break;
	case MSG_KILL_INLINE_EDIT:
		exit_inline_edit();
		return 0;

#if 1
	case WM_COMMAND:
		switch (wp)
		{
		case (EN_CHANGE << 16) | 667:
		{
			m_edit_changed = true;
		}
		break;
		}
		break;
#endif

	case WM_TIMER:
	{
		if (wp == EDIT_TIMER_ID)
		{
			create_inline_edit_v2(m_edit_index, m_edit_column);
			if (m_edit_timer)
			{
				KillTimer(wnd_playlist, EDIT_TIMER_ID);
				m_edit_timer = false;
			}
			return 0;
		}

	}
	break;

	//#endif
	case WM_NOTIFY:
		switch (((LPNMHDR)lp)->idFrom)
		{
		case ID_PLAYLIST_TOOLTIP:
			switch (((LPNMHDR)lp)->code)
			{
			case TTN_SHOW:

				RECT rc, rc_tt;

				rc = tooltip;
				GetWindowRect(g_tooltip, &rc_tt);

				int offset = MulDiv(get_item_height() - rc_tt.bottom + rc_tt.top, 1, 2);


				rc.top += offset;




				SetWindowPos(g_tooltip,
					NULL,
					rc.left, rc.top,
					0, 0,
					SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
				return TRUE;
			}
			break;
		case 5001:
			switch (((LPNMHDR)lp)->code)
			{
			case HDN_BEGINTRACKA:
			case HDN_BEGINTRACKW:
			{
				return (cfg_nohscroll ? TRUE : FALSE);
			}
			case HDN_ENDDRAG:
			{
				if (((LPNMHEADERA)lp)->iButton == 0)
				{

					if (((LPNMHEADERA)lp)->pitem && (((LPNMHEADERA)lp)->pitem->mask & HDI_ORDER))
					{

						int from = ((LPNMHEADERA)lp)->iItem;
						int to = ((LPNMHEADERA)lp)->pitem->iOrder;
						if (to >= 0 && from != to)
						{
							int act_from = g_cache.active_column_active_to_actual(from), act_to = g_cache.active_column_active_to_actual(to);

							columns.move(act_from, act_to);
							//if (!cfg_nohscroll) 
							g_save_columns();
							g_reset_columns();
							update_all_windows();
							pvt::ng_playlist_view_t::g_on_columns_change();
						}
					}
					else
					{
					}
				}
				return (TRUE);
			}
			case HDN_DIVIDERDBLCLICK:
				if (!cfg_nohscroll)
				{
					static_api_ptr_t<playlist_manager> playlist_api;
					HDC hdc;
					hdc = GetDC(wnd_playlist);
					int size;
					pfc::string8 text;

					SelectObject(hdc, g_font);


					int w = 0, n, t = playlist_api->activeplaylist_get_item_count();

					for (n = 0; n<t; n++)
					{
						//	playlist_api->format_title(n, text, g_playlist_entries.get_display_spec(((LPNMHEADER)lp)->iItem), NULL);
						g_cache.active_get_display_name(n, ((LPNMHEADER)lp)->iItem, text);
						size = ui_helpers::get_text_width_color(hdc, text, text.length());
						if (size > w) w = size;
					}

					//	g_playlist_entries.get_column(((LPNMHEADER)lp)->iItem)->_set_width(w+5);
					columns[g_cache.active_column_active_to_actual(((LPNMHEADER)lp)->iItem)]->width = w + 15;

					ReleaseDC(wnd_playlist, hdc);
					update_all_windows();
					g_save_columns();
					pvt::ng_playlist_view_t::g_on_column_widths_change();
				}

				return 0;
			case HDN_ITEMCLICK:
			{
				bool des = false;

				static_api_ptr_t<playlist_manager> playlist_api;

				unsigned col;
				bool descending;
				bool sorted = g_cache.active_get_playlist_sort(col, &descending);

				if (sorted && col == ((LPNMHEADER)lp)->iItem)
					des = !descending;

				g_set_sort(((LPNMHEADER)lp)->iItem, des /*, playlist_api->activeplaylist_get_selection_count(1) && cfg_sortsel != 0*/);

			}
			break;
			case HDN_ITEMCHANGED:
			{
				if (!cfg_nohscroll)
				{
					if (((LPNMHEADER)lp)->pitem->mask & HDI_WIDTH)
						columns[g_cache.active_column_active_to_actual(((LPNMHEADER)lp)->iItem)]->width = ((LPNMHEADER)lp)->pitem->cxy;
					update_all_windows(wnd_header);
					g_save_columns();
					pvt::ng_playlist_view_t::g_on_column_widths_change();
				}
			}
			break;
			}
			break;
		}

	}
	return uDefWindowProc(wnd, msg, wp, lp);
}