1. wxShell fixes: now really uses shell (it wasn't different from wxExecute!)

and also added a version which captures the programs output
2. fix for compilers which have void ftime() (my mingw does) in timercmn.cpp
3. updated console sample to test wxShell/wxExecute
4. treetest now can toggle images or change their size
5. wxTreeCtrl doesn't crash if it has no image list


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6404 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-03-03 10:31:34 +00:00
parent 914589c26c
commit 2c8e47380e
13 changed files with 380 additions and 204 deletions

View File

@@ -32,11 +32,13 @@
//#define TEST_ARRAYS
//#define TEST_CMDLINE
//#define TEST_DIR
//#define TEST_EXECUTE
#define TEST_FILECONF
#define TEST_EXECUTE
//#define TEST_FILECONF
//#define TEST_HASH
//#define TEST_LOG
//#define TEST_LONGLONG
//#define TEST_MIME
//#define TEST_SOCKETS
//#define TEST_STRINGS
//#define TEST_THREADS
//#define TEST_TIME
@@ -176,16 +178,55 @@ static void TestExecute()
#ifdef __UNIX__
#define COMMAND "echo hi"
#define SHELL_COMMAND "echo hi from shell"
#define REDIRECT_COMMAND "date"
#elif defined(__WXMSW__)
#define COMMAND "command.com -c 'echo hi'"
#define SHELL_COMMAND "echo hi"
#define REDIRECT_COMMAND COMMAND
#else
#error "no command to exec"
#endif // OS
if ( wxExecute(COMMAND) == 0 )
puts("\nOk.");
printf("Testing wxShell: ");
fflush(stdout);
if ( wxShell(SHELL_COMMAND) )
puts("Ok.");
else
puts("\nError.");
puts("ERROR.");
printf("Testing wxExecute: ");
fflush(stdout);
if ( wxExecute(COMMAND, TRUE /* sync */) == 0 )
puts("Ok.");
else
puts("ERROR.");
#if 0 // no, it doesn't work (yet?)
printf("Testing async wxExecute: ");
fflush(stdout);
if ( wxExecute(COMMAND) != 0 )
puts("Ok (command launched).");
else
puts("ERROR.");
#endif // 0
printf("Testing wxExecute with redirection:\n");
wxArrayString output;
if ( wxExecute(REDIRECT_COMMAND, output) != 0 )
{
puts("ERROR.");
}
else
{
size_t count = output.GetCount();
for ( size_t n = 0; n < count; n++ )
{
printf("\t%s\n", output[n].c_str());
}
puts("Ok.");
}
}
#endif // TEST_EXECUTE
@@ -253,6 +294,92 @@ static void TestFileConfRead()
#endif // TEST_FILECONF
// ----------------------------------------------------------------------------
// wxHashTable
// ----------------------------------------------------------------------------
#ifdef TEST_HASH
#include <wx/hash.h>
struct Foo
{
Foo(int n_) { n = n_; count++; }
~Foo() { count--; }
int n;
static size_t count;
};
size_t Foo::count = 0;
WX_DECLARE_LIST(Foo, wxListFoos);
WX_DECLARE_HASH(Foo, wxListFoos, wxHashFoos);
#include <wx/listimpl.cpp>
WX_DEFINE_LIST(wxListFoos);
static void TestHash()
{
puts("*** Testing wxHashTable ***\n");
{
wxHashFoos hash;
hash.DeleteContents(TRUE);
printf("Hash created: %u foos in hash, %u foos totally\n",
hash.GetCount(), Foo::count);
static const int hashTestData[] =
{
0, 1, 17, -2, 2, 4, -4, 345, 3, 3, 2, 1,
};
size_t n;
for ( n = 0; n < WXSIZEOF(hashTestData); n++ )
{
hash.Put(hashTestData[n], n, new Foo(n));
}
printf("Hash filled: %u foos in hash, %u foos totally\n",
hash.GetCount(), Foo::count);
puts("Hash access test:");
for ( n = 0; n < WXSIZEOF(hashTestData); n++ )
{
printf("\tGetting element with key %d, value %d: ",
hashTestData[n], n);
Foo *foo = hash.Get(hashTestData[n], n);
if ( !foo )
{
printf("ERROR, not found.\n");
}
else
{
printf("%d (%s)\n", foo->n,
(size_t)foo->n == n ? "ok" : "ERROR");
}
}
printf("\nTrying to get an element not in hash: ");
if ( hash.Get(1234) || hash.Get(1, 0) )
{
puts("ERROR: found!");
}
else
{
puts("ok (not found)");
}
}
printf("Hash destroyed: %u foos left\n", Foo::count);
}
#endif // TEST_HASH
// ----------------------------------------------------------------------------
// MIME types
// ----------------------------------------------------------------------------
@@ -555,6 +682,39 @@ static void TestBitOperations()
#endif // TEST_LONGLONG
// ----------------------------------------------------------------------------
// sockets
// ----------------------------------------------------------------------------
#ifdef TEST_SOCKETS
#include <wx/socket.h>
static void TestSocketClient()
{
puts("*** Testing wxSocketClient ***\n");
wxIPV4address addrDst;
addrDst.Hostname("www.wxwindows.org");
addrDst.Service(80);
wxSocketClient client;
if ( !client.Connect(addrDst) )
{
printf("ERROR: failed to connect to %s\n", addrDst.Hostname().c_str());
}
else
{
char buf[8192];
client.Write("get /front.htm\n", 17);
client.Read(buf, WXSIZEOF(buf));
printf("Server replied:\n%s", buf);
}
}
#endif // TEST_SOCKETS
// ----------------------------------------------------------------------------
// date time
// ----------------------------------------------------------------------------
@@ -2217,10 +2377,18 @@ int main(int argc, char **argv)
}
#endif // TEST_LONGLONG
#ifdef TEST_HASH
TestHash();
#endif // TEST_HASH
#ifdef TEST_MIME
TestMimeEnum();
#endif // TEST_MIME
#ifdef TEST_SOCKETS
TestSocketClient();
#endif // TEST_SOCKETS
#ifdef TEST_TIME
if ( 0 )
{

View File

@@ -1148,6 +1148,7 @@ void MyPanel::OnShowProgress( wxCommandEvent& WXUNUSED(event) )
max, // range
this, // parent
wxPD_CAN_ABORT |
wxPD_AUTO_HIDE |
wxPD_APP_MODAL |
wxPD_ELAPSED_TIME |
wxPD_ESTIMATED_TIME |

View File

@@ -242,9 +242,15 @@ void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) )
void MyFrame::LogDialog(wxCommandEvent& event)
{
wxLogMessage("This is some message - everything is ok so far.");
wxLogMessage("Another message...\n... this one is on multiple lines");
wxLogWarning("And then something went wrong!");
// calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
// being flushed -- test it
{
wxBusyCursor bc;
wxLogMessage("This is some message - everything is ok so far.");
wxLogMessage("Another message...\n... this one is on multiple lines");
wxLogWarning("And then something went wrong!");
}
wxLogError("Intermediary error handler decided to abort.");
wxLogError("The top level caller detected an unrecoverable error.");

View File

@@ -572,7 +572,9 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
m_horizontal = new MyTextCtrl( this, -1, "Multiline text control with a horizontal scrollbar.",
wxPoint(10,170), wxSize(140,70), wxTE_MULTILINE | wxHSCROLL );
m_horizontal->SetFont(wxFont(18, wxSWISS, wxNORMAL, wxNORMAL,
FALSE, "", wxFONTENCODING_KOI8));
FALSE, "", wxFONTENCODING_ISO8859_2)); //wxFONTENCODING_KOI8));
//m_horizontal->SetValue("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
m_horizontal->SetValue("<EFBFBD>lu<EFBFBD>ou<EFBFBD>k<EFBFBD> k<><6B> zb<7A>sile <20>e<EFBFBD>tina <20><>");
m_multitext = new MyTextCtrl( this, -1, "Multi line.",
wxPoint(180,10), wxSize(240,70), wxTE_MULTILINE );

View File

@@ -33,27 +33,21 @@
#include "math.h"
#ifdef __WXMSW__
// this is not supported at all under MSW
#ifdef __WIN32__
// this is not supported by native control
#define NO_VARIABLE_HEIGHT
#define NO_MULTIPLE_SELECTION
// this is supported (so the next line may be uncommented) but not very
// well :-(
#undef NO_MULTIPLE_SELECTION
#endif
#include "treetest.h"
// under Windows the icons are in the .rc file
#ifndef __WXMSW__
#include "icon1.xpm"
#include "icon2.xpm"
#include "icon3.xpm"
#include "icon4.xpm"
#include "icon5.xpm"
#include "mondrian.xpm"
#include "icon1.xpm"
#include "icon2.xpm"
#include "icon3.xpm"
#include "icon4.xpm"
#include "icon5.xpm"
#include "mondrian.xpm"
#endif
// verify that the item is ok and insult the user if it is not
@@ -88,6 +82,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(TreeTest_DeleteChildren, MyFrame::OnDeleteChildren)
EVT_MENU(TreeTest_DeleteAll, MyFrame::OnDeleteAll)
EVT_MENU(TreeTest_Recreate, MyFrame::OnRecreate)
EVT_MENU(TreeTest_ToggleImages, MyFrame::OnToggleImages)
EVT_MENU(TreeTest_SetImageSize, MyFrame::OnSetImageSize)
EVT_MENU(TreeTest_CollapseAndReset, MyFrame::OnCollapseAndReset)
EVT_MENU(TreeTest_EnsureVisible, MyFrame::OnEnsureVisible)
EVT_MENU(TreeTest_AddItem, MyFrame::OnAddItem)
@@ -161,6 +157,8 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
#ifndef NO_MULTIPLE_SELECTION
tree_menu->Append(TreeTest_ToggleSel, "&Toggle selection mode");
#endif // NO_MULTIPLE_SELECTION
tree_menu->Append(TreeTest_ToggleImages, "&Show images", "", TRUE);
tree_menu->Append(TreeTest_SetImageSize, "Set image si&ze...");
tree_menu->Append(TreeTest_Recreate, "&Recreate the tree");
tree_menu->Append(TreeTest_CollapseAndReset, "C&ollapse and reset");
tree_menu->AppendSeparator();
@@ -206,6 +204,8 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
menu_bar->Append(item_menu, "&Item");
SetMenuBar(menu_bar);
menu_bar->Check(TreeTest_ToggleImages, TRUE);
m_treeCtrl = new MyTreeCtrl(this, TreeTest_Ctrl,
wxDefaultPosition, wxDefaultSize,
wxTR_HAS_BUTTONS |
@@ -412,6 +412,27 @@ void MyFrame::OnRecreate(wxCommandEvent& event)
m_treeCtrl->AddTestItemsToTree(3, 2);
}
void MyFrame::OnSetImageSize(wxCommandEvent& event)
{
long size = wxGetNumberFromUser("Enter the size for the images to use",
"Size: ",
"TreeCtrl sample",
32);
if ( size == -1 )
return;
m_treeCtrl->CreateImageList((int)size);
OnRecreate(event);
}
void MyFrame::OnToggleImages(wxCommandEvent& event)
{
wxGetApp().SetShowImages(!wxGetApp().ShowImages());
OnRecreate(event);
}
void MyFrame::OnCollapseAndReset(wxCommandEvent& event)
{
m_treeCtrl->CollapseAndReset(m_treeCtrl->GetRootItem());
@@ -424,7 +445,8 @@ void MyFrame::OnEnsureVisible(wxCommandEvent& event)
void MyFrame::OnInsertItem(wxCommandEvent& WXUNUSED(event))
{
m_treeCtrl->InsertItem(m_treeCtrl->GetRootItem(), 1, "2nd item");
int image = wxGetApp().ShowImages() ? MyTreeCtrl::TreeCtrlIcon_File : -1;
m_treeCtrl->InsertItem(m_treeCtrl->GetRootItem(), image, "2nd item");
}
void MyFrame::OnAddItem(wxCommandEvent& WXUNUSED(event))
@@ -484,49 +506,59 @@ MyTreeCtrl::MyTreeCtrl(wxWindow *parent, const wxWindowID id,
long style)
: wxTreeCtrl(parent, id, pos, size, style)
{
#ifndef NO_VARIABLE_HEIGHT
#if wxUSE_LIBJPEG
wxImage::AddHandler(new wxJPEGHandler);
wxImage image;
image.LoadFile(wxString("horse.jpg"), wxBITMAP_TYPE_JPEG );
#endif
#endif
m_reverseSort = FALSE;
CreateImageList();
// Add some items to the tree
AddTestItemsToTree(3, 2);
}
void MyTreeCtrl::CreateImageList(int size)
{
delete m_imageListNormal;
if ( size == -1 )
{
m_imageListNormal = NULL;
return;
}
// Make an image list containing small icons
m_imageListNormal = new wxImageList(16, 16, TRUE);
m_imageListNormal = new wxImageList(size, size, TRUE);
// should correspond to TreeCtrlIcon_xxx enum
#if defined(__WXMSW__) && defined(__WIN16__)
// This is required in 16-bit Windows mode only because we can't load a specific (16x16)
// icon image, so it comes out stretched
# ifndef NO_VARIABLE_HEIGHT
m_imageListNormal->Add(image.ConvertToBitmap());
# else
m_imageListNormal->Add(wxBitmap("bitmap1", wxBITMAP_TYPE_BMP_RESOURCE));
# endif
m_imageListNormal->Add(wxBitmap("bitmap2", wxBITMAP_TYPE_BMP_RESOURCE));
m_imageListNormal->Add(wxBitmap("bitmap3", wxBITMAP_TYPE_BMP_RESOURCE));
m_imageListNormal->Add(wxBitmap("bitmap4", wxBITMAP_TYPE_BMP_RESOURCE));
m_imageListNormal->Add(wxBitmap("bitmap5", wxBITMAP_TYPE_BMP_RESOURCE));
#else
# ifndef NO_VARIABLE_HEIGHT
m_imageListNormal->Add(image.ConvertToBitmap());
# else
m_imageListNormal->Add(wxICON(icon1));
# endif
m_imageListNormal->Add(wxICON(icon2));
m_imageListNormal->Add(wxICON(icon3));
m_imageListNormal->Add(wxICON(icon4));
m_imageListNormal->Add(wxICON(icon5));
wxIcon icons[5];
icons[0] = wxICON(icon1);
icons[1] = wxICON(icon2);
icons[2] = wxICON(icon3);
icons[3] = wxICON(icon4);
icons[4] = wxICON(icon5);
int sizeOrig = icons[0].GetWidth();
for ( size_t i = 0; i < WXSIZEOF(icons); i++ )
{
if ( size == sizeOrig )
{
m_imageListNormal->Add(icons[i]);
}
else
{
m_imageListNormal->Add(wxImage(icons[i]).Rescale(size, size).
ConvertToBitmap());
}
}
#endif
SetImageList(m_imageListNormal);
// Add some items to the tree
AddTestItemsToTree(3, 2);
}
MyTreeCtrl::~MyTreeCtrl()
@@ -568,12 +600,21 @@ void MyTreeCtrl::AddItemsRecursively(const wxTreeItemId& idParent,
// here we pass to AppendItem() normal and selected item images (we
// suppose that selected image follows the normal one in the enum)
int image = depth == 1 ? TreeCtrlIcon_File : TreeCtrlIcon_Folder;
wxTreeItemId id = AppendItem(idParent, str, image, image + 1,
int image, imageSel;
if ( wxGetApp().ShowImages() )
{
image = depth == 1 ? TreeCtrlIcon_File : TreeCtrlIcon_Folder;
imageSel = image + 1;
}
else
{
image = imageSel = -1;
}
wxTreeItemId id = AppendItem(idParent, str, image, imageSel,
new MyTreeItemData(str));
// and now we also set the expanded one (only for the folders)
if ( hasChildren )
if ( hasChildren && wxGetApp().ShowImages() )
{
SetItemImage(id, TreeCtrlIcon_FolderOpened,
wxTreeItemIcon_Expanded);
@@ -594,10 +635,14 @@ void MyTreeCtrl::AddItemsRecursively(const wxTreeItemId& idParent,
void MyTreeCtrl::AddTestItemsToTree(size_t numChildren,
size_t depth)
{
int image = wxGetApp().ShowImages() ? MyTreeCtrl::TreeCtrlIcon_Folder : -1;
wxTreeItemId rootId = AddRoot("Root",
TreeCtrlIcon_Folder, TreeCtrlIcon_Folder,
image, image,
new MyTreeItemData("Root item"));
SetItemImage(rootId, TreeCtrlIcon_FolderOpened, wxTreeItemIcon_Expanded);
if ( image != -1 )
{
SetItemImage(rootId, TreeCtrlIcon_FolderOpened, wxTreeItemIcon_Expanded);
}
AddItemsRecursively(rootId, numChildren, depth, 0);
@@ -714,7 +759,8 @@ void MyTreeCtrl::OnEndDrag(wxTreeEvent& event)
//
// Finally, we only copy one item here but we might copy the entire tree if
// we were dragging a folder.
AppendItem(itemDst, text, TreeCtrlIcon_File);
int image = wxGetApp().ShowImages() ? TreeCtrlIcon_File : -1;
AppendItem(itemDst, text, image);
}
void MyTreeCtrl::OnBeginLabelEdit(wxTreeEvent& event)

View File

@@ -13,7 +13,15 @@
class MyApp : public wxApp
{
public:
MyApp() { m_showImages = TRUE; }
bool OnInit();
void SetShowImages(bool show) { m_showImages = show; }
bool ShowImages() const { return m_showImages; }
private:
bool m_showImages;
};
class MyTreeItemData : public wxTreeItemData
@@ -66,6 +74,8 @@ public:
void GetItemsRecursively(const wxTreeItemId& idParent, long cookie);
void CreateImageList(int size = 32);
void AddTestItemsToTree(size_t numChildren, size_t depth);
void DoSortChildren(const wxTreeItemId& item, bool reverse = FALSE)
@@ -125,7 +135,10 @@ public:
void OnDelete(wxCommandEvent& event);
void OnDeleteChildren(wxCommandEvent& event);
void OnDeleteAll(wxCommandEvent& event);
void OnRecreate(wxCommandEvent& event);
void OnToggleImages(wxCommandEvent& event);
void OnSetImageSize(wxCommandEvent& event);
void OnCollapseAndReset(wxCommandEvent& event);
void OnSetBold(wxCommandEvent& WXUNUSED(event)) { DoSetBold(TRUE); }
@@ -184,6 +197,8 @@ enum
TreeTest_DeleteChildren,
TreeTest_DeleteAll,
TreeTest_Recreate,
TreeTest_ToggleImages,
TreeTest_SetImageSize,
TreeTest_ToggleSel,
TreeTest_CollapseAndReset,
TreeTest_EnsureVisible,