当前位置: 首页>>代码示例>>C++>>正文


C++ TextView::GetSelectionBounds方法代码示例

本文整理汇总了C++中TextView::GetSelectionBounds方法的典型用法代码示例。如果您正苦于以下问题:C++ TextView::GetSelectionBounds方法的具体用法?C++ TextView::GetSelectionBounds怎么用?C++ TextView::GetSelectionBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TextView的用法示例。


在下文中一共展示了TextView::GetSelectionBounds方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Exec

void DocActionPix::Exec(bool bInteractive)
{
	DocumentIterator it(*m_pDoc);

	if(bInteractive)
	{
		FileDialog dlg(true);
		dlg.SetTitle(_("Open picture"));

		//define file filters
		dlg.AddFilter(_("All supported image formats (*.png,*.jpg,*.gif)"), "*.png|*.jpg|*.gif");
		dlg.AddFilter(_("PNG format (*.png)"), "*.png");
		dlg.AddFilter(_("JPG format (*.jpg)"), "*.jpg");
		dlg.AddFilter(_("GIF format (*.gif)"), "*.gif");
		dlg.AddFilter(_("All files (*)"), "*");

		//set initial directory from INI (store last used)
		std::string strDefaultDir;
		std::string strDir;
		g_objIni.GetValue("Cache", "LastPictureDir", strDir, "");
		if(!strDir.empty() && 0 == access(strDir.c_str(), 00))
			strDefaultDir = strDir;
		else
			strDefaultDir = GetHomeDir();

		dlg.SetDirectory(strDefaultDir.c_str());

		if(dlg.DoModal())
		{
			const gchar *filename = dlg.GetFilename();
			strDefaultDir = dlg.GetDirectory();
			dlg.Close();

			//store last open directory
			g_objIni.SetValue("Cache", "LastPictureDir", strDefaultDir.c_str());
			g_objIni.Save();

			GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(filename, NULL);

			PixPropertiesDlg dlg1;
			dlg1.m_nOrigWidth  = gdk_pixbuf_get_width(pixbuf);
			dlg1.m_nOrigHeight = gdk_pixbuf_get_height(pixbuf);
			dlg1.m_bUsePNG = false;
			dlg1.Create();
			if(GTK_RESPONSE_OK != dlg1.ShowModal()){
				g_object_unref (G_OBJECT (pixbuf));
				return;
			}

			GdkPixbuf *destpix = gdk_pixbuf_scale_simple(pixbuf, dlg1.m_nNewWidth, dlg1.m_nNewHeight, GDK_INTERP_BILINEAR);
			g_object_unref (G_OBJECT (pixbuf));
			pixbuf = destpix;

			UpdateTextFromScreen();

			//search from last result selection (or start)
			int cursor = -1;
			int selection = -1;
			g_text.GetSelectionBounds(cursor, selection);
			if(selection >= 0)
				cursor = selection;

			//get the iterator
			GtkTextBuffer* buffer1 = gtk_text_view_get_buffer((GtkTextView *)g_text.m_pWidget);
			GtkTextIter cursIter;
			gtk_text_buffer_get_iter_at_offset(buffer1, &cursIter, cursor);

			gtk_text_buffer_insert_pixbuf(buffer1, &cursIter, pixbuf);

			//store base name for the picture (with changed extension if required)
			std::string strName = GetBaseName(filename);
			EnsureExtension(strName, dlg1.m_bUsePNG ? ".png" : ".jpg");

			PixInfo info;
			info.bUsePNG = dlg1.m_bUsePNG;
			info.nOffset = cursor;
			info.pixbuf  = pixbuf;
			info.strName = strName;
			g_doc.GetNodeByIdx(m_nNodeIdx).m_lstPictures.push_back(info);
			std::sort(g_doc.GetNodeByIdx(m_nNodeIdx).m_lstPictures.begin(), g_doc.GetNodeByIdx(m_nNodeIdx).m_lstPictures.end());

			m_nOffset = cursor;
			m_pixbuf  = pixbuf;
			m_bUsePNG = dlg1.m_bUsePNG;

			//increment offsets for all formatting marks
			int nSize = g_doc.GetNodeByIdx(m_nNodeIdx).m_lstTxtFmt.size();
			int i;
			for(i=0; i<nSize; i++){
				if(g_doc.GetNodeByIdx(m_nNodeIdx).m_lstTxtFmt[i].nOffset >= m_nOffset)
					g_doc.GetNodeByIdx(m_nNodeIdx).m_lstTxtFmt[i].nOffset ++;
			}

			//increment all the pictures after this one
			nSize = g_doc.GetNodeByIdx(m_nNodeIdx).m_lstPictures.size();
			for(i=0; i<nSize; i++){
				if(g_doc.GetNodeByIdx(m_nNodeIdx).m_lstPictures[i].nOffset > m_nOffset)
					g_doc.GetNodeByIdx(m_nNodeIdx).m_lstPictures[i].nOffset ++;
			}
		}
//.........这里部分代码省略.........
开发者ID:ellysh,项目名称:notecase,代码行数:101,代码来源:DocActionPix.cpp

示例2: Exec

void DocActionFmt::Exec(bool bInteractive)
{
	bool bExists = false;

	if(bInteractive)
	{
		m_lstFmt = g_doc.GetNodeByIdx(m_nNodeIdx).m_lstTxtFmt;

		int nCursor = 0;
		int nSelection = 0;

		g_text.GetSelectionBounds(nCursor, nSelection);
		if(nCursor != nSelection)
		{
			int nStart  = min(nCursor, nSelection);
			int nEnd    = max(nCursor, nSelection);

			m_nStartOffset = nStart;
			m_nEndOffset   = nEnd;

			bExists = g_doc.GetNodeByIdx(m_nNodeIdx).m_lstTxtFmt.IsRangeFormatted(m_nStartOffset, m_nEndOffset, m_nOperationTag);

			//start color picker if required
			GdkColor color;
			if( (!bExists || m_bCtrlPressed) &&
				(FMT_TXT_COLOR_BEGIN == m_nOperationTag || FMT_TXT_BKG_COLOR_BEGIN == m_nOperationTag))
			{
				if(m_bCtrlPressed)
				{
					if(FMT_TXT_COLOR_BEGIN == m_nOperationTag)
						color = g_rgbTextColor;
					else
						color = g_rgbTextBgColor;
				}
				else
				{
					GtkWidget *picker = gtk_color_selection_dialog_new  (_("Pick text color"));
					gtk_window_set_modal (GTK_WINDOW (picker), TRUE);
					gtk_window_set_destroy_with_parent (GTK_WINDOW (picker), TRUE);
				#ifndef _WIN32  //TOFIX API is buggy on Win32 (kills modal dialog state)
					gtk_window_set_skip_taskbar_hint (GTK_WINDOW (picker), TRUE);
				#endif
					gtk_window_set_skip_pager_hint (GTK_WINDOW (picker), TRUE);
					gtk_window_set_type_hint (GTK_WINDOW (picker), GDK_WINDOW_TYPE_HINT_DIALOG);
					gtk_window_set_transient_for(GTK_WINDOW (picker), GTK_WINDOW(window1));   //set parent
				#if GTK_CHECK_VERSION(2,4,0) //new API TOFIX set proper version
					#ifndef _WIN32  //TOFIX API is buggy on Win32 (kills modal dialog state)
					  //gtk_window_set_keep_above(GTK_WINDOW (picker), TRUE);
					#endif
				#endif
					gtk_widget_realize(picker);
					gdk_window_set_decorations(picker->window, (GdkWMDecoration)(GDK_DECOR_BORDER|GDK_DECOR_TITLE));

					GtkColorSelection *colorsel = GTK_COLOR_SELECTION (GTK_COLOR_SELECTION_DIALOG (picker)->colorsel);
					if(FMT_TXT_COLOR_BEGIN == m_nOperationTag){
						gtk_color_selection_set_previous_color(GTK_COLOR_SELECTION(colorsel), &g_rgbTextColor);
						gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel), &g_rgbTextColor);
					}
					else
					{
						gtk_color_selection_set_previous_color(GTK_COLOR_SELECTION(colorsel), &g_rgbTextBgColor);
						gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel), &g_rgbTextBgColor);
					}
					gtk_color_selection_set_has_palette (GTK_COLOR_SELECTION(colorsel), TRUE);

					if(GTK_RESPONSE_OK != gtk_dialog_run(GTK_DIALOG(picker))){
						gtk_widget_destroy(picker);
						return;
					}
					gtk_color_selection_get_current_color(colorsel, &color);
					gtk_widget_destroy(picker);
				}

				m_color = color;
				if(FMT_TXT_COLOR_BEGIN == m_nOperationTag)
					g_rgbTextColor = color;		//remember last used color
				else
					g_rgbTextBgColor = color;		//remember last used color
			}
		}
	}

	bExists = g_doc.GetNodeByIdx(m_nNodeIdx).m_lstTxtFmt.IsRangeFormatted(m_nStartOffset, m_nEndOffset, m_nOperationTag);
	if(bExists){
		g_doc.GetNodeByIdx(m_nNodeIdx).m_lstTxtFmt.ClearFormatRange(m_nStartOffset, m_nEndOffset, m_nOperationTag);
		RefreshTextFormat(g_doc.GetNodeByIdx(m_nNodeIdx), false, m_nStartOffset, m_nEndOffset);
	}
	else{
		g_doc.GetNodeByIdx(m_nNodeIdx).m_lstTxtFmt.AddFormatRange(m_nStartOffset, m_nEndOffset, m_nOperationTag, m_color);
		if(FMT_NONE == m_nOperationTag)
			RefreshTextFormat(g_doc.GetNodeByIdx(m_nNodeIdx), false, m_nStartOffset, m_nEndOffset);
	}

	textview_selection_changed(NULL, NULL, NULL, NULL);

	TRACE("DocActionFmt::Exec\n");
}
开发者ID:ellysh,项目名称:notecase,代码行数:97,代码来源:DocActionFmt.cpp


注:本文中的TextView::GetSelectionBounds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。