コード例 #1
0
ファイル: HtmlDialog.cpp プロジェクト: tea/wxcocoadialog
HtmlDialog::HtmlDialog(wxWindow* parent, const OptionDict& options) 
: wxDialog(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER),
  m_optionDict(options) {
	// Set the dialog title
	const wxString title = options.GetOption(wxT("title"));
	SetTitle(options.GetOption(wxT("title")));

	// IE Control
	m_ie = new wxIEHtmlWin(this, ID_MSHTML);

	// Load html from file
	if (options.HasOption(wxT("html-from-file")))
	{
		wxString htmlFile = options.GetOption(wxT("html-from-file"));
#ifdef __WXMSW__
		if (!htmlFile.empty()) {
			htmlFile = CygwinPathToWin(htmlFile);
		}
#endif // __WXMSW__
		
		// We need an absolute path
		wxFileName path(htmlFile);
		path.MakeAbsolute();

		m_ie->LoadUrl(path.GetFullPath());
	}
	else { // Load html for stdin
		// Create temp file
		m_tempPath = wxFileName::CreateTempFileName(wxEmptyString) + wxT(".html");
		wxFFile tempFile(m_tempPath, wxT("wb"));
		if (!tempFile.IsOpened()) {
			Close();
			return;
		}
		
		// Load html from stdin to temp file
		int c;
		FILE* fp = tempFile.fp();
		while ((c = getc(stdin)) != EOF) putc(c, fp);
		tempFile.Close();

		m_ie->LoadUrl(m_tempPath);
	}

	// Create layout
	wxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
	mainSizer->Add(m_ie, 1, wxEXPAND);
	SetSizer(mainSizer);

	int width;
	int height;
	if (options.GetIntegerOption(wxT("width"), width) &&
		options.GetIntegerOption(wxT("height"), height)) {
		SetSize(width, height);
	}

	Centre();
	Show();
}
コード例 #2
0
ファイル: InputBox.cpp プロジェクト: panoti/DACK_CTDL_G1
InputBox::InputBox(wxWindow* parent, const OptionDict& options, bool doFloat) 
: wxDialog(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, doFloat ? wxDEFAULT_DIALOG_STYLE|wxSTAY_ON_TOP : wxDEFAULT_DIALOG_STYLE), m_options(options) {
	// Set the dialog title
	const wxString title = options.GetOption(wxT("title"));
	SetTitle(options.GetOption(wxT("title")));

	wxSize textSize = wxDefaultSize;

	int textStyle = 0;
	if (options.HasOption(wxT("no-show"))) textStyle |= wxTE_PASSWORD;

	//Set textStyle to multiline, in case runmode is textbox
	const wxString runmode = options.GetRunmode();
	if (runmode == wxT("textbox")) 
	{
		textSize = wxSize(-1,250);
		textStyle |= wxTE_MULTILINE|wxTE_READONLY;
	}
	
	// Create controls
	wxStaticText* informativeText = new wxStaticText(this, wxID_ANY, options.GetOption(wxT("informative-text")));
	m_inputBox = new wxTextCtrl(this, wxID_ANY, options.GetOption(wxT("text")), wxDefaultPosition, textSize, textStyle);

	//Set text selected
	m_inputBox->SetSelection(5,7);

	//Set cursor at last position
	if (options.GetOption(wxT("scroll-to")) == wxT("bottom")) m_inputBox->ShowPosition(m_inputBox->GetLastPosition());
	
	//Set text editable
	if (options.HasOption(wxT("editable"))) m_inputBox->SetEditable(true);

	//Load text from file
	if (options.HasOption(wxT("text-from-file")))
	{
		const wxString textFromFile = options.GetOption(wxT("text-from-file"));
		m_inputBox->LoadFile(textFromFile);
	}

	m_inputBox->SetInsertionPoint(0);

	m_button3 = new wxButton(this, CTRL_BUTTON3, options.GetOption(wxT("button3")));
	m_button2 = new wxButton(this, CTRL_BUTTON2, options.GetOption(wxT("button2")));
	m_button1 = new wxButton(this, CTRL_BUTTON1, options.GetOption(wxT("button1")));
	SetDefaultItem(m_button1);

	// Create layout
	wxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
		mainSizer->Add(informativeText, 0, wxALL, 5);
		mainSizer->Add(m_inputBox, 0, wxEXPAND|wxALL, 5);
		wxSizer* buttonSizer = new wxBoxSizer(wxHORIZONTAL);
			buttonSizer->Add(m_button3, 0, wxALL, 5);
			buttonSizer->Add(m_button2, 0, wxALL, 5);
			buttonSizer->Add(m_button1, 0, wxALL, 5);
			mainSizer->Add(buttonSizer, 0, wxALIGN_RIGHT);

	// Hide unneeded controls
	if (!options.HasOption(wxT("informative-text"))) mainSizer->Hide(informativeText);
	if (!options.HasOption(wxT("button2"))) buttonSizer->Hide(m_button2);
	if (!options.HasOption(wxT("button3"))) buttonSizer->Hide(m_button3);

	// Set timeout timer
	int interval;
	if (options.GetIntegerOption(wxT("timeout"), interval)) {
		m_timer.SetOwner(this, TIMEOUT_TIMER);
		m_timer.Start(interval*1000, true);
	}
	
	SetSizerAndFit(mainSizer);
	
	// Make sure dialog does not get too small
	const wxSize size = GetSize();
	if (size.x < 300) SetSize(300, -1);

	Centre();
	Show();
}