1. wxStaticLine implemented (generic (ugly) and MSW versions)
2. wxTextDialog looks fine under MSW again 3. startup tips added: code, sample, docs 4. read-only text controls don't participate in TAB traversal git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2919 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -769,7 +769,6 @@ void MyPanel::OnShowProgress( wxCommandEvent& WXUNUSED(event) )
|
||||
{
|
||||
cont = dialog.Update(i);
|
||||
}
|
||||
wxYield();
|
||||
}
|
||||
|
||||
if ( !cont )
|
||||
|
@@ -6,7 +6,7 @@
|
||||
// Created: 04/01/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart and Markus Holzem
|
||||
// Licence: wxWindows license
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <wx/dirdlg.h>
|
||||
#include <wx/fontdlg.h>
|
||||
#include <wx/choicdlg.h>
|
||||
#include <wx/tipdlg.h>
|
||||
|
||||
#define wxTEST_GENERIC_DIALOGS_IN_MSW 0
|
||||
|
||||
@@ -78,6 +79,8 @@ bool MyApp::OnInit(void)
|
||||
file_menu->Append(DIALOGS_TEXT_ENTRY, "Text &entry");
|
||||
file_menu->Append(DIALOGS_SINGLE_CHOICE, "&Single choice");
|
||||
file_menu->AppendSeparator();
|
||||
file_menu->Append(DIALOGS_TIP, "&Tip of the day");
|
||||
file_menu->AppendSeparator();
|
||||
file_menu->Append(DIALOGS_FILE_OPEN, "&Open file");
|
||||
file_menu->Append(DIALOGS_FILE_SAVE, "Sa&ve file");
|
||||
file_menu->Append(DIALOGS_DIR_CHOOSE, "&Choose a directory");
|
||||
@@ -190,23 +193,20 @@ void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) )
|
||||
void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) )
|
||||
{
|
||||
wxMessageDialog dialog(NULL, "This is a message box\nA long, long string to test out the message box properly",
|
||||
"Message box text", wxYES_NO|wxCANCEL);
|
||||
"Message box text", wxYES_NO|wxCANCEL|wxICON_INFORMATION);
|
||||
|
||||
dialog.ShowModal();
|
||||
|
||||
::wxMessageBox("MsgBox with a really long long string",
|
||||
"this is the text", wxYES_NO|wxICON_EXCLAMATION);
|
||||
}
|
||||
|
||||
void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event) )
|
||||
{
|
||||
wxTextEntryDialog dialog(this, "This is a small sample\nA long, long string to test out the text entrybox",
|
||||
"Please enter a string", "Default value", wxOK|wxCANCEL);
|
||||
"Please enter a string", "Default value", wxOK|wxCANCEL);
|
||||
|
||||
if (dialog.ShowModal() == wxID_OK)
|
||||
{
|
||||
wxMessageDialog dialog2(this, dialog.GetValue(), "Got string");
|
||||
dialog2.ShowModal();
|
||||
wxMessageDialog dialog2(this, dialog.GetValue(), "Got string");
|
||||
dialog2.ShowModal();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,10 +229,10 @@ void MyFrame::SingleChoice(wxCommandEvent& WXUNUSED(event) )
|
||||
|
||||
void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) )
|
||||
{
|
||||
wxFileDialog dialog(this, "Testing open file dialog", "", "", "*.txt", 0);
|
||||
wxFileDialog dialog(this, "Testing open file dialog", "", "", "*.txt", 0);
|
||||
|
||||
if (dialog.ShowModal() == wxID_OK)
|
||||
{
|
||||
if (dialog.ShowModal() == wxID_OK)
|
||||
{
|
||||
wxString info;
|
||||
info.Printf(_T("Full file name: %s\n")
|
||||
_T("Path: %s\n")
|
||||
@@ -240,45 +240,72 @@ void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) )
|
||||
dialog.GetPath().c_str(),
|
||||
dialog.GetDirectory().c_str(),
|
||||
dialog.GetFilename().c_str());
|
||||
wxMessageDialog dialog2(this, info, "Selected file");
|
||||
dialog2.ShowModal();
|
||||
}
|
||||
wxMessageDialog dialog2(this, info, "Selected file");
|
||||
dialog2.ShowModal();
|
||||
}
|
||||
}
|
||||
|
||||
void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) )
|
||||
{
|
||||
wxFileDialog dialog(this, "Testing save file dialog", "", "",
|
||||
"Text files (*.txt)|*.txt|Document files (*.doc)|*.doc",
|
||||
wxSAVE|wxOVERWRITE_PROMPT);
|
||||
wxFileDialog dialog(this, "Testing save file dialog", "", "",
|
||||
"Text files (*.txt)|*.txt|Document files (*.doc)|*.doc",
|
||||
wxSAVE|wxOVERWRITE_PROMPT);
|
||||
|
||||
if (dialog.ShowModal() == wxID_OK)
|
||||
{
|
||||
wxChar buf[400];
|
||||
wxSprintf(buf, _T("%s, filter %d"), (const wxChar*)dialog.GetPath(), dialog.GetFilterIndex());
|
||||
wxMessageDialog dialog2(this, wxString(buf), "Selected path");
|
||||
dialog2.ShowModal();
|
||||
}
|
||||
if (dialog.ShowModal() == wxID_OK)
|
||||
{
|
||||
wxChar buf[400];
|
||||
wxSprintf(buf, _T("%s, filter %d"), (const wxChar*)dialog.GetPath(), dialog.GetFilterIndex());
|
||||
wxMessageDialog dialog2(this, wxString(buf), "Selected path");
|
||||
dialog2.ShowModal();
|
||||
}
|
||||
}
|
||||
|
||||
void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) )
|
||||
{
|
||||
wxDirDialog dialog(this, "Testing directory picker", "");
|
||||
wxDirDialog dialog(this, "Testing directory picker", "");
|
||||
|
||||
if (dialog.ShowModal() == wxID_OK)
|
||||
{
|
||||
wxMessageDialog dialog2(this, dialog.GetPath(), "Selected path");
|
||||
dialog2.ShowModal();
|
||||
}
|
||||
if (dialog.ShowModal() == wxID_OK)
|
||||
{
|
||||
wxMessageDialog dialog2(this, dialog.GetPath(), "Selected path");
|
||||
dialog2.ShowModal();
|
||||
}
|
||||
}
|
||||
|
||||
void MyFrame::ShowTip(wxCommandEvent& event)
|
||||
{
|
||||
static size_t s_index = (size_t)-1;
|
||||
|
||||
if ( s_index == (size_t)-1 )
|
||||
{
|
||||
srand(time(NULL));
|
||||
|
||||
// this is completely bogus, we don't know how many lines are there
|
||||
// in the file, but who cares, it's a demo only...
|
||||
s_index = rand() % 5;
|
||||
}
|
||||
|
||||
wxTipProvider *tipProvider = wxCreateFileTipProvider("tips.txt", s_index);
|
||||
|
||||
bool showAtStartup = wxShowTip(this, tipProvider);
|
||||
|
||||
if ( showAtStartup )
|
||||
{
|
||||
wxMessageBox("Will show tips on startup", "Tips dialog",
|
||||
wxOK | wxICON_INFORMATION, this);
|
||||
}
|
||||
|
||||
s_index = tipProvider->GetCurrentTip();
|
||||
delete tipProvider;
|
||||
}
|
||||
|
||||
void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) )
|
||||
{
|
||||
Close(TRUE);
|
||||
Close(TRUE);
|
||||
}
|
||||
|
||||
void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) )
|
||||
{
|
||||
wxPaintDC dc(this);
|
||||
wxPaintDC dc(this);
|
||||
dc.SetFont(wxGetApp().m_canvasFont);
|
||||
dc.SetTextForeground(wxGetApp().m_canvasTextColour);
|
||||
dc.SetBackgroundMode(wxTRANSPARENT);
|
||||
@@ -286,22 +313,23 @@ void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) )
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
|
||||
EVT_PAINT(MyCanvas::OnPaint)
|
||||
EVT_PAINT(MyCanvas::OnPaint)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour)
|
||||
EVT_MENU(DIALOGS_CHOOSE_FONT, MyFrame::ChooseFont)
|
||||
EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox)
|
||||
EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry)
|
||||
EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice)
|
||||
EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen)
|
||||
EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave)
|
||||
EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose)
|
||||
EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour)
|
||||
EVT_MENU(DIALOGS_CHOOSE_FONT, MyFrame::ChooseFont)
|
||||
EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox)
|
||||
EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry)
|
||||
EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice)
|
||||
EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen)
|
||||
EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave)
|
||||
EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose)
|
||||
EVT_MENU(DIALOGS_TIP, MyFrame::ShowTip)
|
||||
#if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
|
||||
EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric)
|
||||
EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC, MyFrame::ChooseFontGeneric)
|
||||
EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric)
|
||||
EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC, MyFrame::ChooseFontGeneric)
|
||||
#endif
|
||||
EVT_MENU(wxID_EXIT, MyFrame::OnExit)
|
||||
EVT_MENU(wxID_EXIT, MyFrame::OnExit)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
|
@@ -35,6 +35,7 @@ class MyFrame: public wxFrame
|
||||
void FileOpen(wxCommandEvent& event);
|
||||
void FileSave(wxCommandEvent& event);
|
||||
void DirChoose(wxCommandEvent& event);
|
||||
void ShowTip(wxCommandEvent& event);
|
||||
|
||||
#if !defined(__WXMSW__) || wxTEST_GENERIC_DIALOGS_IN_MSW
|
||||
void ChooseColourGeneric(wxCommandEvent& event);
|
||||
@@ -67,6 +68,7 @@ DECLARE_EVENT_TABLE()
|
||||
#define DIALOGS_FILE_OPEN 8
|
||||
#define DIALOGS_FILE_SAVE 9
|
||||
#define DIALOGS_DIR_CHOOSE 10
|
||||
#define DIALOGS_TIP 11
|
||||
|
||||
#endif
|
||||
|
||||
|
5
samples/dialogs/tips.txt
Normal file
5
samples/dialogs/tips.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
Startup tips are documented in "Startup tips overview" section of wxWindows documentation.
|
||||
This is the first tip!
|
||||
And this is another great tip...
|
||||
And here is a very very very very very very very very very very very long one.
|
||||
If you have something useful to add to this file, please do.
|
@@ -9,29 +9,31 @@
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <wx/wxprec.h>
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include <wx/wx.h>
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
|
||||
#include <wx/intl.h>
|
||||
#include <wx/log.h>
|
||||
#include "wx/intl.h"
|
||||
#include "wx/log.h"
|
||||
|
||||
#include <wx/dnd.h>
|
||||
#include "wx/dnd.h"
|
||||
|
||||
#ifdef __WXMOTIF__
|
||||
#error Sorry, drag and drop is not yet implemented on wxMotif.
|
||||
#error Sorry, drag and drop is not yet implemented on wxMotif.
|
||||
#endif
|
||||
|
||||
#if defined(__WXGTK__) || defined(__WXMOTIF__)
|
||||
#include "mondrian.xpm"
|
||||
#include "mondrian.xpm"
|
||||
#endif
|
||||
|
||||
#include "wx/clipbrd.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Derive two simple classes which just put in the listbox the strings (text or
|
||||
// file names) we drop on them
|
||||
@@ -47,24 +49,25 @@
|
||||
class DnDText : public wxTextDropTarget
|
||||
{
|
||||
public:
|
||||
DnDText(wxListBox *pOwner) { m_pOwner = pOwner; }
|
||||
DnDText(wxListBox *pOwner) { m_pOwner = pOwner; }
|
||||
|
||||
virtual bool OnDropText(wxDropPointCoord x, wxDropPointCoord y, const wxChar* psz );
|
||||
virtual bool OnDropText(wxDropPointCoord x, wxDropPointCoord y,
|
||||
const wxChar* psz);
|
||||
|
||||
private:
|
||||
wxListBox *m_pOwner;
|
||||
wxListBox *m_pOwner;
|
||||
};
|
||||
|
||||
class DnDFile : public wxFileDropTarget
|
||||
{
|
||||
public:
|
||||
DnDFile(wxListBox *pOwner) { m_pOwner = pOwner; }
|
||||
DnDFile(wxListBox *pOwner) { m_pOwner = pOwner; }
|
||||
|
||||
virtual bool OnDropFiles(wxDropPointCoord x, wxDropPointCoord y,
|
||||
size_t nFiles, const wxChar* const aszFiles[] );
|
||||
|
||||
private:
|
||||
wxListBox *m_pOwner;
|
||||
wxListBox *m_pOwner;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -74,7 +77,7 @@ private:
|
||||
class DnDApp : public wxApp
|
||||
{
|
||||
public:
|
||||
bool OnInit();
|
||||
bool OnInit();
|
||||
};
|
||||
|
||||
IMPLEMENT_APP(DnDApp);
|
||||
@@ -85,29 +88,31 @@ IMPLEMENT_APP(DnDApp);
|
||||
class DnDFrame : public wxFrame
|
||||
{
|
||||
public:
|
||||
DnDFrame(wxFrame *frame, char *title, int x, int y, int w, int h);
|
||||
~DnDFrame();
|
||||
DnDFrame(wxFrame *frame, char *title, int x, int y, int w, int h);
|
||||
~DnDFrame();
|
||||
|
||||
void OnPaint(wxPaintEvent& event);
|
||||
void OnQuit (wxCommandEvent& event);
|
||||
void OnAbout(wxCommandEvent& event);
|
||||
void OnDrag (wxCommandEvent& event);
|
||||
void OnHelp (wxCommandEvent& event);
|
||||
void OnLogClear(wxCommandEvent& event);
|
||||
void OnPaint(wxPaintEvent& event);
|
||||
void OnQuit (wxCommandEvent& event);
|
||||
void OnAbout(wxCommandEvent& event);
|
||||
void OnDrag (wxCommandEvent& event);
|
||||
void OnHelp (wxCommandEvent& event);
|
||||
void OnLogClear(wxCommandEvent& event);
|
||||
void OnCopy(wxCommandEvent& event);
|
||||
void OnPaste(wxCommandEvent& event);
|
||||
|
||||
void OnLeftDown(wxMouseEvent& event);
|
||||
void OnRightDown(wxMouseEvent& event);
|
||||
void OnLeftDown(wxMouseEvent& event);
|
||||
void OnRightDown(wxMouseEvent& event);
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
DECLARE_EVENT_TABLE()
|
||||
|
||||
private:
|
||||
wxListBox *m_ctrlFile,
|
||||
*m_ctrlText;
|
||||
wxTextCtrl *m_ctrlLog;
|
||||
wxListBox *m_ctrlFile,
|
||||
*m_ctrlText;
|
||||
wxTextCtrl *m_ctrlLog;
|
||||
|
||||
wxLog *m_pLog, *m_pLogPrev;
|
||||
wxLog *m_pLog, *m_pLogPrev;
|
||||
|
||||
wxString m_strText;
|
||||
wxString m_strText;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -116,37 +121,43 @@ private:
|
||||
|
||||
enum
|
||||
{
|
||||
Menu_Quit = 1,
|
||||
Menu_Drag,
|
||||
Menu_About = 101,
|
||||
Menu_Help,
|
||||
Menu_Clear,
|
||||
Menu_Quit = 1,
|
||||
Menu_Drag,
|
||||
Menu_About = 101,
|
||||
Menu_Help,
|
||||
Menu_Clear,
|
||||
Menu_Copy,
|
||||
Menu_Paste
|
||||
};
|
||||
|
||||
BEGIN_EVENT_TABLE(DnDFrame, wxFrame)
|
||||
EVT_MENU(Menu_Quit, DnDFrame::OnQuit)
|
||||
EVT_MENU(Menu_About, DnDFrame::OnAbout)
|
||||
EVT_MENU(Menu_Drag, DnDFrame::OnDrag)
|
||||
EVT_MENU(Menu_Help, DnDFrame::OnHelp)
|
||||
EVT_MENU(Menu_Clear, DnDFrame::OnLogClear)
|
||||
EVT_LEFT_DOWN( DnDFrame::OnLeftDown)
|
||||
EVT_RIGHT_DOWN( DnDFrame::OnRightDown)
|
||||
EVT_PAINT( DnDFrame::OnPaint)
|
||||
EVT_MENU(Menu_Quit, DnDFrame::OnQuit)
|
||||
EVT_MENU(Menu_About, DnDFrame::OnAbout)
|
||||
EVT_MENU(Menu_Drag, DnDFrame::OnDrag)
|
||||
EVT_MENU(Menu_Help, DnDFrame::OnHelp)
|
||||
EVT_MENU(Menu_Clear, DnDFrame::OnLogClear)
|
||||
EVT_MENU(Menu_Copy, DnDFrame::OnCopy)
|
||||
EVT_MENU(Menu_Paste, DnDFrame::OnPaste)
|
||||
|
||||
EVT_LEFT_DOWN( DnDFrame::OnLeftDown)
|
||||
EVT_RIGHT_DOWN( DnDFrame::OnRightDown)
|
||||
EVT_PAINT( DnDFrame::OnPaint)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
// `Main program' equivalent, creating windows and returning main app frame
|
||||
// `Main program' equivalent, creating windows and returning main app frame
|
||||
bool DnDApp::OnInit()
|
||||
{
|
||||
// create the main frame window
|
||||
DnDFrame *frame = new DnDFrame((wxFrame *) NULL, "Drag & Drop wxWindows App",
|
||||
50, 50, 450, 340);
|
||||
// create the main frame window
|
||||
DnDFrame *frame = new DnDFrame((wxFrame *) NULL,
|
||||
"Drag-and-Drop/Clipboard wxWindows Sample",
|
||||
50, 50, 450, 340);
|
||||
|
||||
// activate it
|
||||
frame->Show(TRUE);
|
||||
// activate it
|
||||
frame->Show(TRUE);
|
||||
|
||||
SetTopWindow(frame);
|
||||
SetTopWindow(frame);
|
||||
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
DnDFrame::DnDFrame(wxFrame *frame, char *title, int x, int y, int w, int h)
|
||||
@@ -154,13 +165,83 @@ DnDFrame::DnDFrame(wxFrame *frame, char *title, int x, int y, int w, int h)
|
||||
m_strText("wxWindows drag & drop works :-)")
|
||||
|
||||
{
|
||||
// SetBackgroundColour(* wxWHITE);
|
||||
// frame icon and status bar
|
||||
SetIcon(wxICON(mondrian));
|
||||
|
||||
// frame icon and status bar
|
||||
SetIcon(wxICON(mondrian));
|
||||
CreateStatusBar();
|
||||
|
||||
// const int widths[] = { -1 };
|
||||
CreateStatusBar();
|
||||
// construct menu
|
||||
wxMenu *file_menu = new wxMenu;
|
||||
file_menu->Append(Menu_Drag, "&Test drag...");
|
||||
file_menu->AppendSeparator();
|
||||
file_menu->Append(Menu_Quit, "E&xit");
|
||||
|
||||
wxMenu *log_menu = new wxMenu;
|
||||
log_menu->Append(Menu_Clear, "Clear");
|
||||
|
||||
wxMenu *help_menu = new wxMenu;
|
||||
help_menu->Append(Menu_Help, "&Help...");
|
||||
help_menu->AppendSeparator();
|
||||
help_menu->Append(Menu_About, "&About");
|
||||
|
||||
wxMenu *clip_menu = new wxMenu;
|
||||
clip_menu->Append(Menu_Copy, "&Copy\tCtrl+C");
|
||||
clip_menu->Append(Menu_Paste, "&Paste\tCtrl+V");
|
||||
|
||||
wxMenuBar *menu_bar = new wxMenuBar;
|
||||
menu_bar->Append(file_menu, "&File");
|
||||
menu_bar->Append(log_menu, "&Log");
|
||||
menu_bar->Append(clip_menu, "&Clipboard");
|
||||
menu_bar->Append(help_menu, "&Help");
|
||||
|
||||
SetMenuBar(menu_bar);
|
||||
|
||||
// make a panel with 3 subwindows
|
||||
wxPoint pos(0, 0);
|
||||
wxSize size(400, 200);
|
||||
|
||||
wxString strFile("Drop files here!"), strText("Drop text on me");
|
||||
|
||||
m_ctrlFile = new wxListBox(this, -1, pos, size, 1, &strFile, wxLB_HSCROLL);
|
||||
m_ctrlText = new wxListBox(this, -1, pos, size, 1, &strText, wxLB_HSCROLL);
|
||||
|
||||
m_ctrlLog = new wxTextCtrl(this, -1, "", pos, size,
|
||||
wxTE_MULTILINE | wxTE_READONLY |
|
||||
wxSUNKEN_BORDER );
|
||||
|
||||
// redirect log messages to the text window (don't forget to delete it!)
|
||||
m_pLog = new wxLogTextCtrl(m_ctrlLog);
|
||||
m_pLogPrev = wxLog::SetActiveTarget(m_pLog);
|
||||
|
||||
// associate drop targets with 2 text controls
|
||||
m_ctrlFile->SetDropTarget(new DnDFile(m_ctrlFile));
|
||||
m_ctrlText->SetDropTarget( new DnDText(m_ctrlText) );
|
||||
|
||||
wxLayoutConstraints *c;
|
||||
|
||||
// Top-left listbox
|
||||
c = new wxLayoutConstraints;
|
||||
c->left.SameAs(this, wxLeft);
|
||||
c->top.SameAs(this, wxTop);
|
||||
c->right.PercentOf(this, wxRight, 50);
|
||||
c->height.PercentOf(this, wxHeight, 40);
|
||||
m_ctrlFile->SetConstraints(c);
|
||||
|
||||
// Top-right listbox
|
||||
c = new wxLayoutConstraints;
|
||||
c->left.SameAs (m_ctrlFile, wxRight);
|
||||
c->top.SameAs (this, wxTop);
|
||||
c->right.SameAs (this, wxRight);
|
||||
c->height.PercentOf(this, wxHeight, 40);
|
||||
m_ctrlText->SetConstraints(c);
|
||||
|
||||
// Lower text control
|
||||
c = new wxLayoutConstraints;
|
||||
c->left.SameAs (this, wxLeft);
|
||||
c->right.SameAs (this, wxRight);
|
||||
c->height.PercentOf(this, wxHeight, 40);
|
||||
c->top.SameAs(m_ctrlText, wxBottom);
|
||||
m_ctrlLog->SetConstraints(c);
|
||||
|
||||
// construct menu
|
||||
wxMenu *file_menu = new wxMenu;
|
||||
@@ -235,122 +316,176 @@ DnDFrame::DnDFrame(wxFrame *frame, char *title, int x, int y, int w, int h)
|
||||
|
||||
void DnDFrame::OnQuit(wxCommandEvent& /* event */)
|
||||
{
|
||||
Close(TRUE);
|
||||
Close(TRUE);
|
||||
}
|
||||
|
||||
void DnDFrame::OnPaint(wxPaintEvent& /*event*/)
|
||||
{
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
GetClientSize( &w, &h );
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
GetClientSize( &w, &h );
|
||||
|
||||
wxPaintDC dc(this);
|
||||
dc.SetFont( wxFont( 24, wxDECORATIVE, wxNORMAL, wxNORMAL, FALSE, "charter" ) );
|
||||
dc.DrawText( "Drag text from here!", 20, h-35 );
|
||||
wxPaintDC dc(this);
|
||||
dc.SetFont( wxFont( 24, wxDECORATIVE, wxNORMAL, wxNORMAL, FALSE, "charter" ) );
|
||||
dc.DrawText( "Drag text from here!", 20, h-35 );
|
||||
}
|
||||
|
||||
void DnDFrame::OnDrag(wxCommandEvent& /* event */)
|
||||
{
|
||||
wxString strText = wxGetTextFromUser
|
||||
(
|
||||
"After you enter text in this dialog, press any mouse\n"
|
||||
"button in the bottom (empty) part of the frame and \n"
|
||||
"drag it anywhere - you will be in fact dragging the\n"
|
||||
"text object containing this text",
|
||||
"Please enter some text", m_strText, this
|
||||
);
|
||||
wxString strText = wxGetTextFromUser
|
||||
(
|
||||
"After you enter text in this dialog, press any mouse\n"
|
||||
"button in the bottom (empty) part of the frame and \n"
|
||||
"drag it anywhere - you will be in fact dragging the\n"
|
||||
"text object containing this text",
|
||||
"Please enter some text", m_strText, this
|
||||
);
|
||||
|
||||
m_strText = strText;
|
||||
m_strText = strText;
|
||||
}
|
||||
|
||||
void DnDFrame::OnAbout(wxCommandEvent& /* event */)
|
||||
{
|
||||
wxMessageDialog dialog(this,
|
||||
"Drag-&-Drop Demo\n"
|
||||
"Please see \"Help|Help...\" for details\n"
|
||||
"Copyright (c) 1998 Vadim Zeitlin",
|
||||
"About wxDnD");
|
||||
|
||||
dialog.ShowModal();
|
||||
wxMessageBox("Drag-&-Drop Demo\n"
|
||||
"Please see \"Help|Help...\" for details\n"
|
||||
"Copyright (c) 1998 Vadim Zeitlin",
|
||||
"About wxDnD",
|
||||
wxICON_INFORMATION | wxOK,
|
||||
this);
|
||||
}
|
||||
|
||||
void DnDFrame::OnHelp(wxCommandEvent& /* event */)
|
||||
{
|
||||
wxMessageDialog dialog(this,
|
||||
"This small program demonstrates drag & drop support in wxWindows. The program window\n"
|
||||
"consists of 3 parts: the bottom pane is for debug messages, so that you can see what's\n"
|
||||
"going on inside. The top part is split into 2 listboxes, the left one accepts files\n"
|
||||
"and the right one accepts text.\n"
|
||||
"\n"
|
||||
"To test wxDropTarget: open wordpad (write.exe), select some text in it and drag it to\n"
|
||||
"the right listbox (you'll notice the usual visual feedback, i.e. the cursor will change).\n"
|
||||
"Also, try dragging some files (you can select several at once) from Windows Explorer (or \n"
|
||||
"File Manager) to the left pane. Hold down Ctrl/Shift keys when you drop text (doesn't \n"
|
||||
"work with files) and see what changes.\n"
|
||||
"\n"
|
||||
"To test wxDropSource: just press any mouse button on the empty zone of the window and drag\n"
|
||||
"it to wordpad or any other droptarget accepting text (and of course you can just drag it\n"
|
||||
"to the right pane). Due to a lot of trace messages, the cursor might take some time to \n"
|
||||
"change, don't release the mouse button until it does. You can change the string being\n"
|
||||
"dragged in in \"File|Test drag...\" dialog.\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"Please send all questions/bug reports/suggestions &c to \n"
|
||||
"Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>",
|
||||
"wxDnD Help");
|
||||
wxMessageDialog dialog(this,
|
||||
"This small program demonstrates drag & drop support in wxWindows. The program window\n"
|
||||
"consists of 3 parts: the bottom pane is for debug messages, so that you can see what's\n"
|
||||
"going on inside. The top part is split into 2 listboxes, the left one accepts files\n"
|
||||
"and the right one accepts text.\n"
|
||||
"\n"
|
||||
"To test wxDropTarget: open wordpad (write.exe), select some text in it and drag it to\n"
|
||||
"the right listbox (you'll notice the usual visual feedback, i.e. the cursor will change).\n"
|
||||
"Also, try dragging some files (you can select several at once) from Windows Explorer (or \n"
|
||||
"File Manager) to the left pane. Hold down Ctrl/Shift keys when you drop text (doesn't \n"
|
||||
"work with files) and see what changes.\n"
|
||||
"\n"
|
||||
"To test wxDropSource: just press any mouse button on the empty zone of the window and drag\n"
|
||||
"it to wordpad or any other droptarget accepting text (and of course you can just drag it\n"
|
||||
"to the right pane). Due to a lot of trace messages, the cursor might take some time to \n"
|
||||
"change, don't release the mouse button until it does. You can change the string being\n"
|
||||
"dragged in in \"File|Test drag...\" dialog.\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"Please send all questions/bug reports/suggestions &c to \n"
|
||||
"Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>",
|
||||
"wxDnD Help");
|
||||
|
||||
dialog.ShowModal();
|
||||
dialog.ShowModal();
|
||||
}
|
||||
|
||||
void DnDFrame::OnLogClear(wxCommandEvent& /* event */ )
|
||||
{
|
||||
m_ctrlLog->Clear();
|
||||
m_ctrlLog->Clear();
|
||||
}
|
||||
|
||||
void DnDFrame::OnLeftDown(wxMouseEvent &WXUNUSED(event) )
|
||||
{
|
||||
if ( !m_strText.IsEmpty() )
|
||||
{
|
||||
// start drag operation
|
||||
#ifdef __WXMSW__
|
||||
wxTextDataObject textData(m_strText);
|
||||
wxDropSource dragSource( textData, this );
|
||||
#else
|
||||
wxDropSource dragSource( new wxTextDataObject (m_strText), this, wxIcon(mondrian_xpm) );
|
||||
#endif
|
||||
const char *pc;
|
||||
|
||||
switch ( dragSource.DoDragDrop(TRUE) )
|
||||
if ( !m_strText.IsEmpty() )
|
||||
{
|
||||
case wxDragError: pc = "Error!"; break;
|
||||
case wxDragNone: pc = "Nothing"; break;
|
||||
case wxDragCopy: pc = "Copied"; break;
|
||||
case wxDragMove: pc = "Moved"; break;
|
||||
case wxDragCancel: pc = "Cancelled"; break;
|
||||
default: pc = "Huh?"; break;
|
||||
}
|
||||
// start drag operation
|
||||
#ifdef __WXMSW__
|
||||
wxTextDataObject textData(m_strText);
|
||||
wxDropSource dragSource( textData, this );
|
||||
#else
|
||||
wxDropSource dragSource( new wxTextDataObject (m_strText), this, wxIcon(mondrian_xpm) );
|
||||
#endif
|
||||
const char *pc;
|
||||
|
||||
SetStatusText(wxString("Drag result: ") + pc);
|
||||
}
|
||||
switch ( dragSource.DoDragDrop(TRUE) )
|
||||
{
|
||||
case wxDragError: pc = "Error!"; break;
|
||||
case wxDragNone: pc = "Nothing"; break;
|
||||
case wxDragCopy: pc = "Copied"; break;
|
||||
case wxDragMove: pc = "Moved"; break;
|
||||
case wxDragCancel: pc = "Cancelled"; break;
|
||||
default: pc = "Huh?"; break;
|
||||
}
|
||||
|
||||
SetStatusText(wxString("Drag result: ") + pc);
|
||||
}
|
||||
}
|
||||
|
||||
void DnDFrame::OnRightDown(wxMouseEvent &event )
|
||||
{
|
||||
wxMenu *menu = new wxMenu;
|
||||
wxMenu *menu = new wxMenu;
|
||||
|
||||
menu->Append(Menu_Drag, "&Test drag...");
|
||||
menu->Append(Menu_About, "&About");
|
||||
menu->Append(Menu_Quit, "E&xit");
|
||||
menu->Append(Menu_Drag, "&Test drag...");
|
||||
menu->Append(Menu_About, "&About");
|
||||
menu->Append(Menu_Quit, "E&xit");
|
||||
|
||||
PopupMenu( menu, event.GetX(), event.GetY() );
|
||||
PopupMenu( menu, event.GetX(), event.GetY() );
|
||||
}
|
||||
|
||||
DnDFrame::~DnDFrame()
|
||||
{
|
||||
if ( m_pLog != NULL ) {
|
||||
if ( wxLog::SetActiveTarget(m_pLogPrev) == m_pLog )
|
||||
delete m_pLog;
|
||||
}
|
||||
if ( m_pLog != NULL ) {
|
||||
if ( wxLog::SetActiveTarget(m_pLogPrev) == m_pLog )
|
||||
delete m_pLog;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// clipboard
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void DnDFrame::OnCopy(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
if ( !wxTheClipboard->Open() )
|
||||
{
|
||||
wxLogError("Can't open clipboard.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !wxTheClipboard->AddData(new wxTextDataObject(m_strText)) )
|
||||
{
|
||||
wxLogError("Can't copy data to the clipboard");
|
||||
}
|
||||
else
|
||||
{
|
||||
wxLogMessage("Text '%s' put on the clipboard", m_strText.c_str());
|
||||
}
|
||||
|
||||
wxTheClipboard->Close();
|
||||
}
|
||||
|
||||
void DnDFrame::OnPaste(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
if ( !wxTheClipboard->Open() )
|
||||
{
|
||||
wxLogError("Can't open clipboard.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !wxTheClipboard->IsSupported(wxDF_TEXT) )
|
||||
{
|
||||
wxLogWarning("No text data on clipboard");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
wxTextDataObject text;
|
||||
if ( !wxTheClipboard->GetData(&text) )
|
||||
{
|
||||
wxLogError("Can't paste data from the clipboard");
|
||||
}
|
||||
else
|
||||
{
|
||||
wxLogMessage("Text '%s' pasted from the clipboard",
|
||||
text.GetText().c_str());
|
||||
}
|
||||
|
||||
wxTheClipboard->Close();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -358,20 +493,20 @@ DnDFrame::~DnDFrame()
|
||||
// ----------------------------------------------------------------------------
|
||||
bool DnDText::OnDropText( wxDropPointCoord, wxDropPointCoord, const wxChar *psz )
|
||||
{
|
||||
m_pOwner->Append(psz);
|
||||
m_pOwner->Append(psz);
|
||||
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool DnDFile::OnDropFiles( wxDropPointCoord, wxDropPointCoord, size_t nFiles,
|
||||
const wxChar* const aszFiles[])
|
||||
{
|
||||
wxString str;
|
||||
str.Printf( _T("%d files dropped"), nFiles);
|
||||
m_pOwner->Append(str);
|
||||
for ( size_t n = 0; n < nFiles; n++ ) {
|
||||
m_pOwner->Append(aszFiles[n]);
|
||||
}
|
||||
wxString str;
|
||||
str.Printf( _T("%d files dropped"), nFiles);
|
||||
m_pOwner->Append(str);
|
||||
for ( size_t n = 0; n < nFiles; n++ ) {
|
||||
m_pOwner->Append(aszFiles[n]);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
@@ -235,6 +235,7 @@ void MyFrame::OnListView(wxCommandEvent& WXUNUSED(event))
|
||||
void MyFrame::OnReportView(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
m_listCtrl->DeleteAllItems();
|
||||
m_listCtrl->DeleteAllColumns();
|
||||
m_logWindow->Clear();
|
||||
|
||||
m_listCtrl->SetSingleStyle(wxLC_REPORT);
|
||||
|
@@ -69,6 +69,9 @@ public:
|
||||
// event handlers (these functions should _not_ be virtual)
|
||||
void OnQuit(wxCommandEvent& event);
|
||||
void OnAbout(wxCommandEvent& event);
|
||||
void OnTest(wxCommandEvent& event);
|
||||
|
||||
void OnPaint(wxPaintEvent& event);
|
||||
|
||||
private:
|
||||
// any class wishing to process wxWindows events must use this macro
|
||||
@@ -85,8 +88,7 @@ enum
|
||||
// menu items
|
||||
Minimal_Quit = 1,
|
||||
Minimal_About,
|
||||
Minimal_Test1,
|
||||
Minimal_Test2,
|
||||
Minimal_Test,
|
||||
|
||||
// controls start here (the numbers are, of course, arbitrary)
|
||||
Minimal_Text = 1000,
|
||||
@@ -102,6 +104,10 @@ enum
|
||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
|
||||
EVT_MENU(Minimal_About, MyFrame::OnAbout)
|
||||
|
||||
EVT_BUTTON(-1, MyFrame::OnTest)
|
||||
|
||||
EVT_PAINT(MyFrame::OnPaint)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
// Create a new application object: this macro will allow wxWindows to create
|
||||
@@ -163,9 +169,11 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
||||
// ... and attach this menu bar to the frame
|
||||
SetMenuBar(menuBar);
|
||||
|
||||
#if wxUSE_STATUSBAR
|
||||
// create a status bar just for fun (by default with 1 pane only)
|
||||
CreateStatusBar(2);
|
||||
SetStatusText("Welcome to wxWindows!");
|
||||
#endif // wxUSE_STATUSBAR
|
||||
}
|
||||
|
||||
|
||||
@@ -193,3 +201,28 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
||||
|
||||
wxMessageBox(msg, "About Minimal", wxOK | wxICON_INFORMATION, this);
|
||||
}
|
||||
|
||||
void MyFrame::OnTest(wxCommandEvent& event)
|
||||
{
|
||||
}
|
||||
|
||||
void MyFrame::OnPaint(wxPaintEvent& event)
|
||||
{
|
||||
wxPaintDC dc(this);
|
||||
|
||||
wxMemoryDC dcMem;
|
||||
wxSize size(GetClientSize());
|
||||
dcMem.SelectObject(wxBitmap(size.x, size.y, -1));
|
||||
|
||||
dcMem.SetBackground(wxBrush(wxColour(0, 0, 255), wxSOLID));
|
||||
dcMem.SetTextForeground(wxColour(0, 255, 0));
|
||||
dcMem.SetTextBackground(wxColour(0, 0, 0));
|
||||
dcMem.SetBackgroundMode(wxSOLID);
|
||||
dcMem.Clear();
|
||||
dcMem.DrawText("Hello, wxWindows!", 10, 10);
|
||||
|
||||
wxPoint ptOrig(0, 0);
|
||||
dc.Blit(ptOrig, size, &dcMem, ptOrig);
|
||||
|
||||
dcMem.SelectObject(wxNullBitmap);
|
||||
}
|
||||
|
@@ -238,7 +238,7 @@ MyFrame::AddSampleText(wxLayoutList *llist)
|
||||
void
|
||||
MyFrame::Clear(void)
|
||||
{
|
||||
wxColour colBg(0, 255, 255);
|
||||
wxColour colBg(0, 0, 0);
|
||||
|
||||
m_lwin->Clear(wxROMAN,16,wxNORMAL,wxNORMAL, false, wxRED, &colBg);
|
||||
}
|
||||
|
Reference in New Issue
Block a user