virtual void Command(wxCommandEvent &event);
protected:
- // creates the controls (invokes wxWindowBase::CreateBase) and adds it to
- // the list of parents children
+ // creates the control (calls wxWindowBase::CreateBase inside) and adds it
+ // to the list of parents children
bool CreateControl(wxWindowBase *parent,
wxWindowID id,
const wxPoint& pos,
#endif
const wxString& name);
+ // an overloaded version for the controls without validators
+ bool CreateControl(wxWindowBase *parent,
+ wxWindowID id,
+ const wxPoint& pos,
+ const wxSize& size,
+ long style,
+ const wxString& name)
+ {
+ return CreateControl(parent, id, pos, size, style,
+ wxDefaultValidator, name);
+ }
+
// inherit colour and font settings from the parent window
void InheritAttributes();
};
bool MSWCreateControl(const wxChar *classname, WXDWORD style);
// determine the extended styles combination for this window (may slightly
- // modify styl parameter)
- WXDWORD GetExStyle(WXDWORD& style) const;
+ // modify style parameter, this is why it's non const)
+ WXDWORD GetExStyle(WXDWORD& style, bool *want3D) const;
private:
DECLARE_EVENT_TABLE()
void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) )
{
- wxDirDialog dialog(this, "Testing directory picker", "");
+ // pass some initial dir to wxDirDialog
+ wxString dirHome;
+ wxGetHomeDir(&dirHome);
+
+ wxDirDialog dialog(this, "Testing directory picker", dirHome);
if (dialog.ShowModal() == wxID_OK)
{
textData.AddFile( "/file2.txt" );
*/
wxDropSource source(textData, this
+
#ifdef __WXMSW__
,wxCURSOR_PENCIL, // for copy
wxCURSOR_SPRAYCAN, // for move
void DnDFrame::OnCopyFiles(wxCommandEvent& WXUNUSED(event))
{
#ifdef __WXMSW__
- wxFileDataObject *dobj = new wxFileDataObject;
-
wxFileDialog dialog(this, "Select a file to copy", "", "",
"All files (*.*)|*.*", 0);
- if ( dialog.ShowModal() == wxID_OK )
+ wxArrayString filenames;
+ while ( dialog.ShowModal() == wxID_OK )
+ {
+ filenames.Add(dialog.GetPath());
+ }
+
+ if ( !filenames.IsEmpty() )
{
- wxString filename = dialog.GetPath();
- dobj->AddFile(filename);
+ wxFileDataObject *dobj = new wxFileDataObject;
+ size_t count = filenames.GetCount();
+ for ( size_t n = 0; n < count; n++ )
+ {
+ dobj->AddFile(filenames[n]);
+ }
wxClipboardLocker locker;
if ( !locker )
{
if ( !wxTheClipboard->AddData(dobj) )
{
- wxLogError("Can't copy file to the clipboard");
+ wxLogError("Can't copy file(s) to the clipboard");
}
else
{
- wxLogStatus(this, "File '%s' copied to the clipboard",
- filename.c_str());
+ wxLogStatus(this, "%d file%s copied to the clipboard",
+ count, count == 1 ? "" : "s");
}
}
}
// Item members
wxControl::wxControl()
{
- m_backgroundColour = *wxWHITE;
- m_foregroundColour = *wxBLACK;
+ m_backgroundColour = *wxWHITE;
+ m_foregroundColour = *wxBLACK;
#if WXWIN_COMPATIBILITY
- m_callback = 0;
+ m_callback = 0;
#endif // WXWIN_COMPATIBILITY
}
bool wxControl::MSWCreateControl(const wxChar *classname, WXDWORD style)
{
+ // VZ: if someone could put a comment here explaining what exactly this is
+ // needed for, it would be nice...
+ bool want3D;
+
+ // all controls have these childs (wxWindows creates all controls visible
+ // by default)
+ style |= WS_CHILD | WS_VISIBLE;
+
m_hWnd = (WXHWND)::CreateWindowEx
(
- GetExStyle(style), // extended style
+ GetExStyle(style, &want3D), // extended style
classname, // the kind of control to create
NULL, // the window name
style, // the window style
return FALSE;
}
+#if wxUSE_CTL3D
+ if ( want3D )
+ {
+ Ctl3dSubclassCtl(GetHwnd());
+ m_useCtl3D = TRUE;
+ }
+#endif // wxUSE_CTL3D
+
// subclass again for purposes of dialog editing mode
SubclassWin(m_hWnd);
// might flicker.
RECT rect;
- ::GetClientRect((HWND) GetHWND(), &rect);
+ ::GetClientRect(GetHwnd(), &rect);
- HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(),
- GetBackgroundColour().Green(),
- GetBackgroundColour().Blue()));
- int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
+ HBRUSH hBrush = ::CreateSolidBrush(wxColourToRGB(GetBackgroundColour()));
- ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
+ HDC hdc = GetHdcOf((*event.GetDC()));
+ int mode = ::SetMapMode(hdc, MM_TEXT);
+
+ ::FillRect(hdc, &rect, hBrush);
::DeleteObject(hBrush);
- ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
+ ::SetMapMode(hdc, mode);
}
-WXDWORD wxControl::GetExStyle(WXDWORD& style) const
+WXDWORD wxControl::GetExStyle(WXDWORD& style, bool *want3D) const
{
- bool want3D;
- WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ;
+ WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, want3D);
- // Even with extended styles, need to combine with WS_BORDER
- // for them to look right.
- if ( want3D || wxStyleHasBorder(m_windowStyle) )
+ // Even with extended styles, need to combine with WS_BORDER for them to
+ // look right.
+ if ( *want3D || wxStyleHasBorder(m_windowStyle) )
style |= WS_BORDER;
return exStyle;
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
-// Licence: wxWindows licence
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
+// ============================================================================
+// declarations
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
#ifdef __GNUG__
-#pragma implementation "dirdlg.h"
+ #pragma implementation "dirdlg.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
-#pragma hdrstop
+ #pragma hdrstop
#endif
#ifndef WX_PRECOMP
-#include <stdio.h>
-#include "wx/defs.h"
-#include "wx/utils.h"
-#include "wx/dialog.h"
-#include "wx/dirdlg.h"
+ #include "wx/utils.h"
+ #include "wx/dialog.h"
+ #include "wx/dirdlg.h"
#endif
-#if (defined(__WIN95__) && !defined(__GNUWIN32__))||defined(wxUSE_NORLANDER_HEADERS)
-#include "shlobj.h" // Win95 shell
+#include "wx/msw/private.h"
+
+#if defined(__WIN95__) && \
+ (!defined(__GNUWIN32__) || defined(wxUSE_NORLANDER_HEADERS))
+ #define CAN_COMPILE_DIRDLG
+//#else: we provide a stub version which doesn't do anything
#endif
-#include "wx/msw/private.h"
-#include "wx/cmndata.h"
+#ifdef CAN_COMPILE_DIRDLG
+ #include "shlobj.h" // Win95 shell
+#endif
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+// ----------------------------------------------------------------------------
+// constants
+// ----------------------------------------------------------------------------
-#define wxDIALOG_DEFAULT_X 300
-#define wxDIALOG_DEFAULT_Y 300
+#ifndef MAX_PATH
+ #define MAX_PATH 4096 // be generuous
+#endif
+
+// ----------------------------------------------------------------------------
+// wxWindows macros
+// ----------------------------------------------------------------------------
#if !USE_SHARED_LIBRARY
-IMPLEMENT_CLASS(wxDirDialog, wxDialog)
+ IMPLEMENT_CLASS(wxDirDialog, wxDialog)
#endif
-static int CALLBACK
-BrowseCallbackProc(HWND hwnd,UINT uMsg,LPARAM lp, LPARAM pData)
- {
- TCHAR szDir[MAX_PATH];
-
- switch(uMsg)
- {
- case BFFM_INITIALIZED:
- // We have put m_path into pData.
- // TRUE -> passing char *, not dir id.
- SendMessage(hwnd,BFFM_SETSELECTION,TRUE,pData);
- break;
-
- case BFFM_SELCHANGED:
- // Set the status window to the currently selected path.
- if (SHGetPathFromIDList((LPITEMIDLIST) lp ,szDir))
- {
- SendMessage(hwnd,BFFM_SETSTATUSTEXT,0,(LPARAM)szDir);
- }
- break;
+// ----------------------------------------------------------------------------
+// private functions prototypes
+// ----------------------------------------------------------------------------
+
+// free the parameter
+static void ItemListFree(LPITEMIDLIST pidl);
- default:
- break;
- }
- return 0;
- }
+// the callback proc for the dir dlg
+static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp,
+ LPARAM pData);
+// ============================================================================
+// implementation
+// ============================================================================
-wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message,
-// const wxString& caption,
- const wxString& defaultPath,
- long style, const wxPoint& pos)
+// ----------------------------------------------------------------------------
+// wxDirDialog
+// ----------------------------------------------------------------------------
+
+wxDirDialog::wxDirDialog(wxWindow *parent,
+ const wxString& message,
+ const wxString& defaultPath,
+ long WXUNUSED(style),
+ const wxPoint& WXUNUSED(pos))
{
m_message = message;
-// m_caption = caption;
- m_dialogStyle = style;
m_parent = parent;
- m_path = defaultPath;
+ m_path = defaultPath;
}
-int wxDirDialog::ShowModal(void)
+int wxDirDialog::ShowModal()
{
- // Unfortunately Gnu-Win32 doesn't yet have COM support
-#if (defined(__WIN95__) && !defined(__GNUWIN32__))||defined(wxUSE_NORLANDER_HEADERS)
- HWND hWnd = 0;
- if (m_parent) hWnd = (HWND) m_parent->GetHWND();
-
+#ifdef CAN_COMPILE_DIRDLG
BROWSEINFO bi;
- LPTSTR lpBuffer;
-// LPITEMIDLIST pidlPrograms; // PIDL for Programs folder
- LPITEMIDLIST pidlBrowse; // PIDL selected by user
- LPMALLOC pMalloc = NULL;
-
- HRESULT result = ::SHGetMalloc(&pMalloc);
-
- if (result != NOERROR)
- return wxID_CANCEL;
-
- // Allocate a buffer to receive browse information.
- if ((lpBuffer = (LPTSTR) pMalloc->Alloc(MAX_PATH)) == NULL)
+ bi.hwndOwner = m_parent ? GetHwndOf(m_parent) : NULL;
+ bi.pidlRoot = NULL;
+ bi.pszDisplayName = NULL;
+ bi.lpszTitle = m_message.c_str();
+ bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
+ bi.lpfn = BrowseCallbackProc;
+ bi.lParam = (LPARAM)m_path.c_str(); // param for the callback
+
+ LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
+
+ if ( bi.pidlRoot )
+ {
+ ItemListFree((LPITEMIDLIST)bi.pidlRoot);
+ }
+
+ if ( !pidl )
{
- pMalloc->Release();
+ // Cancel button pressed
return wxID_CANCEL;
}
-/*
- // Get the PIDL for the Programs folder.
- if (!SUCCEEDED(SHGetSpecialFolderLocation(
- parent->GetSafeHwnd(), CSIDL_PROGRAMS, &pidlPrograms))) {
- pMalloc->Free(lpBuffer);
- pMalloc->Release();
+ BOOL ok = SHGetPathFromIDList(pidl, m_path.GetWriteBuf(MAX_PATH));
+ m_path.UngetWriteBuf();
+
+ ItemListFree(pidl);
+
+ if ( !ok )
+ {
+ wxLogLastError("SHGetPathFromIDList");
+
return wxID_CANCEL;
- }
-*/
-
- // Fill in the BROWSEINFO structure.
- bi.hwndOwner = hWnd;
- bi.pidlRoot = NULL; // pidlPrograms;
- bi.pszDisplayName = lpBuffer;
- bi.lpszTitle = m_message; // BC++ 4.52 says LPSTR, not LPTSTR?
- bi.ulFlags = 0;
- bi.lpfn = BrowseCallbackProc;
- bi.lParam = (LPARAM)m_path.c_str();
-
- // Browse for a folder and return its PIDL.
- pidlBrowse = SHBrowseForFolder(&bi);
-
- int id = wxID_OK;
- if (pidlBrowse != NULL) {
-
- // Show the display name, title, and file system path.
- if (SHGetPathFromIDList(pidlBrowse, lpBuffer))
- m_path = lpBuffer;
-
- // Free the PIDL returned by SHBrowseForFolder.
- pMalloc->Free(pidlBrowse);
}
- else
- id = wxID_CANCEL;
-
- // Clean up.
-// pMalloc->Free(pidlPrograms);
- pMalloc->Free(lpBuffer);
- pMalloc->Release();
-
- return id;
-#else
- return wxID_CANCEL;
-#endif
+
+ return wxID_OK;
+#else // !CAN_COMPILE_DIRDLG
+ return wxID_CANCEL;
+#endif // CAN_COMPILE_DIRDLG/!CAN_COMPILE_DIRDLG
+}
+
+// ----------------------------------------------------------------------------
+// private functions
+// ----------------------------------------------------------------------------
+
+static int CALLBACK
+BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData)
+{
+ switch(uMsg)
+ {
+ case BFFM_INITIALIZED:
+ // sent immediately after initialisation and so we may set the
+ // initial selection here
+ //
+ // wParam = TRUE => lParam is a string and not a PIDL
+ SendMessage(hwnd, BFFM_SETSELECTION, TRUE, pData);
+ break;
+
+ case BFFM_SELCHANGED:
+ {
+ // Set the status window to the currently selected path.
+ TCHAR szDir[MAX_PATH];
+ if ( SHGetPathFromIDList((LPITEMIDLIST)lp, szDir) )
+ {
+ SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)szDir);
+ }
+ }
+ break;
+
+ //case BFFM_VALIDATEFAILED: -- might be used to provide custom message
+ // if the user types in invalid dir name
+ }
+
+ return 0;
+}
+
+
+static void ItemListFree(LPITEMIDLIST pidl)
+{
+ if ( pidl )
+ {
+ LPMALLOC pMalloc;
+ SHGetMalloc(&pMalloc);
+ if ( pMalloc )
+ {
+ pMalloc->Free(pidl);
+ pMalloc->Release();
+ }
+ else
+ {
+ wxLogLastError("SHGetMalloc");
+ }
+ }
}
/////////////////////////////////////////////////////////////////////////////
-// Name: statbox.cpp
+// Name: msw/statbox.cpp
// Purpose: wxStaticBox
// Author: Julian Smart
// Modified by:
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
+// ============================================================================
+// declarations
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
#ifdef __GNUG__
-#pragma implementation "statbox.h"
+ #pragma implementation "statbox.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
-#pragma hdrstop
+ #pragma hdrstop
#endif
-#include "wx/window.h"
-#include "wx/msw/private.h"
-
#ifndef WX_PRECOMP
-#include "wx/app.h"
-#include "wx/dcclient.h"
+ #include "wx/app.h"
+ #include "wx/dcclient.h"
#endif
#include "wx/statbox.h"
+#include "wx/msw/private.h"
+
+// ----------------------------------------------------------------------------
+// wxWin macros
+// ----------------------------------------------------------------------------
+
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
#endif
-/*
- * Group box
- */
-
-bool wxStaticBox::Create(wxWindow *parent, wxWindowID id,
- const wxString& label,
- const wxPoint& pos,
- const wxSize& size,
- long style,
- const wxString& name)
+// ============================================================================
+// implementation
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// wxStaticBox
+// ----------------------------------------------------------------------------
+
+bool wxStaticBox::Create(wxWindow *parent,
+ wxWindowID id,
+ const wxString& label,
+ const wxPoint& pos,
+ const wxSize& size,
+ long style,
+ const wxString& name)
{
- SetName(name);
-
- if (parent) parent->AddChild(this);
-
- SetBackgroundColour(parent->GetBackgroundColour()) ;
- SetForegroundColour(parent->GetForegroundColour()) ;
-
- if ( id == -1 )
- m_windowId = (int)NewControlId();
- else
- m_windowId = id;
-
- int x = pos.x;
- int y = pos.y;
- int width = size.x;
- int height = size.y;
-
- m_windowStyle = style;
-
- long msStyle = BS_GROUPBOX | WS_CHILD | WS_VISIBLE ; // GROUP_FLAGS;
-
- bool want3D;
- WXDWORD exStyle = Determine3DEffects(0, &want3D) ;
+ if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) )
+ return FALSE;
- HWND wx_button =
- CreateWindowEx(exStyle, wxT("BUTTON"), (const wxChar *)label, msStyle,
- 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
- wxGetInstance(), NULL);
-#if wxUSE_CTL3D
- if (want3D)
- {
- Ctl3dSubclassCtl(wx_button);
- m_useCtl3D = TRUE;
- }
-#endif
-
- m_hWnd = (WXHWND)wx_button;
-
- // Subclass again for purposes of dialog editing mode
- SubclassWin(GetHWND());
+ if ( !MSWCreateControl(wxT("BUTTON"), BS_GROUPBOX) )
+ return FALSE;
- SetFont(parent->GetFont());
+ SetSize(pos.x, pos.y, size.x, size.y);
- SetSize(x, y, width, height);
- ShowWindow(wx_button, SW_SHOW);
-
- return TRUE;
+ return TRUE;
}
wxSize wxStaticBox::DoGetBestSize()
WXLPARAM lParam)
{
#if wxUSE_CTL3D
- if ( m_useCtl3D )
- {
- HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
- return (WXHBRUSH) hbrush;
- }
-#endif
+ if ( m_useCtl3D )
+ {
+ HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
+ return (WXHBRUSH) hbrush;
+ }
+#endif // wxUSE_CTL3D
- if (GetParent()->GetTransparentBackground())
- SetBkMode((HDC) pDC, TRANSPARENT);
- else
- SetBkMode((HDC) pDC, OPAQUE);
+ HDC hdc = (HDC)pDC;
+ if (GetParent()->GetTransparentBackground())
+ SetBkMode(hdc, TRANSPARENT);
+ else
+ SetBkMode(hdc, OPAQUE);
- ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
- ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
+ const wxColour& colBack = GetBackgroundColour();
+ ::SetBkColor(hdc, wxColourToRGB(colBack));
+ ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour()));
- wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
+ wxBrush *brush= wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID);
- // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
- // has a zero usage count.
-// backgroundBrush->RealizeResource();
- return (WXHBRUSH) backgroundBrush->GetResourceHandle();
+ return (WXHBRUSH)brush->GetResourceHandle();
}
+// VZ: this is probably the most commented function in wxWindows, but I still
+// don't understand what it does and why. Wouldn't it be better to _never_
+// erase the background here? What would we lose if we didn't do it?
+// (FIXME)
+
// Shouldn't erase the whole window, since the static box must only paint its
// outline.
void wxStaticBox::OnEraseBackground(wxEraseEvent& event)
// few other circumstances where it matters about child clipping. But what about painting onto
// to panel, inside a groupbox? Doesn't appear, because the box wipes it out.
wxWindow *parent = GetParent();
- if ( parent && parent->GetHWND() && (::GetWindowLong((HWND) parent->GetHWND(), GWL_STYLE) & WS_CLIPCHILDREN) )
+ if ( parent && parent->GetHWND() &&
+ (::GetWindowLong(GetHwndOf(parent), GWL_STYLE) & WS_CLIPCHILDREN) )
{
// TODO: May in fact need to generate a paint event for inside this
// control's rectangle, otherwise all controls are going to be clipped -
// ugh.
- HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
- int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
-
- RECT rect;
- ::GetClientRect(GetHwnd(), &rect);
- ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
- ::DeleteObject(hBrush);
- ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
- }
- else
- {
+ // let wxControl::OnEraseBackground() do the job
event.Skip();
}
+ //else: do *not* call event.Skip() or wxControl will erase the background
}
long wxStaticBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)