1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Definitions of miscelaneous functions and classes that need
4 // to know about wxWindow. (So they can't be in misc.i or an
5 // import loop will happen.)
9 // Created: 18-June-1999
11 // Copyright: (c) 1998 by Total Control Software
12 // Licence: wxWindows license
13 /////////////////////////////////////////////////////////////////////////////
19 #include "pyistream.h"
20 #include <wx/resource.h>
21 #include <wx/tooltip.h>
23 #include <wx/tipdlg.h>
24 #include <wx/process.h>
26 #if wxUSE_JOYSTICK || defined(__WXMSW__)
27 #include <wx/joystick.h>
30 #if wxUSE_WAVE || defined(__WXMSW__)
34 #include <wx/mimetype.h>
37 //----------------------------------------------------------------------
40 %include my_typemaps.i
42 // Import some definitions of other classes, etc.
52 //----------------------------------------------------------------------
55 // Put some wx default wxChar* values into wxStrings.
56 DECLARE_DEF_STRING(FileSelectorPromptStr);
57 DECLARE_DEF_STRING(FileSelectorDefaultWildcardStr);
58 DECLARE_DEF_STRING(DirSelectorPromptStr);
59 static const wxString wxPyEmptyString(wxT(""));
62 //---------------------------------------------------------------------------
65 wxString wxFileSelector(const wxString& message = wxPyFileSelectorPromptStr,
66 const wxString& default_path = wxPyEmptyString,
67 const wxString& default_filename = wxPyEmptyString,
68 const wxString& default_extension = wxPyEmptyString,
69 const wxString& wildcard = wxPyFileSelectorDefaultWildcardStr,
71 wxWindow *parent = NULL,
72 int x = -1, int y = -1);
74 // Ask for filename to load
75 wxString wxLoadFileSelector(const wxString& what,
76 const wxString& extension,
77 const wxString& default_name = wxPyEmptyString,
78 wxWindow *parent = NULL);
80 // Ask for filename to save
81 wxString wxSaveFileSelector(const wxString& what,
82 const wxString& extension,
83 const wxString& default_name = wxPyEmptyString,
84 wxWindow *parent = NULL);
87 wxString wxDirSelector(const wxString& message = wxPyDirSelectorPromptStr,
88 const wxString& defaultPath = wxPyEmptyString,
89 long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxDD_NEW_DIR_BUTTON,
90 const wxPoint& pos = wxDefaultPosition,
91 wxWindow *parent = NULL);
93 wxString wxGetTextFromUser(const wxString& message,
94 const wxString& caption = wxPyEmptyString,
95 const wxString& default_value = wxPyEmptyString,
96 wxWindow *parent = NULL,
97 int x = -1, int y = -1,
100 wxString wxGetPasswordFromUser(const wxString& message,
101 const wxString& caption = wxPyEmptyString,
102 const wxString& default_value = wxPyEmptyString,
103 wxWindow *parent = NULL);
106 // TODO: Need to custom wrap this one...
107 // int wxGetMultipleChoice(char* message, char* caption,
108 // int LCOUNT, char** choices,
109 // int nsel, int *selection,
110 // wxWindow *parent = NULL, int x = -1, int y = -1,
111 // bool centre = TRUE, int width=150, int height=200);
114 wxString wxGetSingleChoice(const wxString& message, const wxString& caption,
115 int LCOUNT, wxString* choices,
116 wxWindow *parent = NULL,
117 int x = -1, int y = -1,
119 int width=150, int height=200);
121 int wxGetSingleChoiceIndex(const wxString& message, const wxString& caption,
122 int LCOUNT, wxString* choices,
123 wxWindow *parent = NULL,
124 int x = -1, int y = -1,
126 int width=150, int height=200);
129 int wxMessageBox(const wxString& message,
130 const wxString& caption = wxPyEmptyString,
131 int style = wxOK | wxCENTRE,
132 wxWindow *parent = NULL,
133 int x = -1, int y = -1);
135 long wxGetNumberFromUser(const wxString& message,
136 const wxString& prompt,
137 const wxString& caption,
139 long min = 0, long max = 100,
140 wxWindow *parent = NULL,
141 const wxPoint& pos = wxDefaultPosition);
143 //---------------------------------------------------------------------------
146 bool wxColourDisplay();
148 int wxDisplayDepth();
149 int wxGetDisplayDepth();
151 void wxDisplaySize(int* OUTPUT, int* OUTPUT);
152 wxSize wxGetDisplaySize();
154 void wxDisplaySizeMM(int* OUTPUT, int* OUTPUT);
155 wxSize wxGetDisplaySizeMM();
157 void wxClientDisplayRect(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT);
158 wxRect wxGetClientDisplayRect();
160 void wxSetCursor(wxCursor& cursor);
162 //----------------------------------------------------------------------
163 // Miscellaneous functions
165 wxWindow * wxFindWindowByLabel(const wxString& label, wxWindow *parent=NULL);
166 wxWindow * wxFindWindowByName(const wxString& name, wxWindow *parent=NULL);
168 void wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR);
169 wxWindow * wxGetActiveWindow();
171 wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt);
172 wxWindow* wxFindWindowAtPoint(const wxPoint& pt);
175 bool wxCheckForInterrupt(wxWindow *wnd);
176 void wxFlushEvents();
179 //---------------------------------------------------------------------------
182 bool wxResourceAddIdentifier(char* name, int value);
183 void wxResourceClear(void);
184 wxBitmap wxResourceCreateBitmap(char* resource);
185 wxIcon wxResourceCreateIcon(char* resource);
186 wxMenuBar * wxResourceCreateMenuBar(char* resource);
187 int wxResourceGetIdentifier(char* name);
188 bool wxResourceParseData(char* resource, wxResourceTable *table = NULL);
189 bool wxResourceParseFile(char* filename, wxResourceTable *table = NULL);
190 bool wxResourceParseString(char* resource, wxResourceTable *table = NULL);
192 //---------------------------------------------------------------------------
195 // possible values for wxSystemSettings::GetFont() parameter
199 wxSYS_OEM_FIXED_FONT = 10,
200 wxSYS_ANSI_FIXED_FONT,
203 wxSYS_DEVICE_DEFAULT_FONT,
204 wxSYS_DEFAULT_PALETTE,
205 wxSYS_SYSTEM_FIXED_FONT,
206 wxSYS_DEFAULT_GUI_FONT
209 // possible values for wxSystemSettings::GetColour() parameter
213 wxSYS_COLOUR_SCROLLBAR,
214 wxSYS_COLOUR_BACKGROUND,
215 wxSYS_COLOUR_DESKTOP = wxSYS_COLOUR_BACKGROUND,
216 wxSYS_COLOUR_ACTIVECAPTION,
217 wxSYS_COLOUR_INACTIVECAPTION,
220 wxSYS_COLOUR_WINDOWFRAME,
221 wxSYS_COLOUR_MENUTEXT,
222 wxSYS_COLOUR_WINDOWTEXT,
223 wxSYS_COLOUR_CAPTIONTEXT,
224 wxSYS_COLOUR_ACTIVEBORDER,
225 wxSYS_COLOUR_INACTIVEBORDER,
226 wxSYS_COLOUR_APPWORKSPACE,
227 wxSYS_COLOUR_HIGHLIGHT,
228 wxSYS_COLOUR_HIGHLIGHTTEXT,
229 wxSYS_COLOUR_BTNFACE,
230 wxSYS_COLOUR_3DFACE = wxSYS_COLOUR_BTNFACE,
231 wxSYS_COLOUR_BTNSHADOW,
232 wxSYS_COLOUR_3DSHADOW = wxSYS_COLOUR_BTNSHADOW,
233 wxSYS_COLOUR_GRAYTEXT,
234 wxSYS_COLOUR_BTNTEXT,
235 wxSYS_COLOUR_INACTIVECAPTIONTEXT,
236 wxSYS_COLOUR_BTNHIGHLIGHT,
237 wxSYS_COLOUR_BTNHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
238 wxSYS_COLOUR_3DHIGHLIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
239 wxSYS_COLOUR_3DHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
240 wxSYS_COLOUR_3DDKSHADOW,
241 wxSYS_COLOUR_3DLIGHT,
242 wxSYS_COLOUR_INFOTEXT,
244 wxSYS_COLOUR_LISTBOX,
245 wxSYS_COLOUR_HOTLIGHT,
246 wxSYS_COLOUR_GRADIENTACTIVECAPTION,
247 wxSYS_COLOUR_GRADIENTINACTIVECAPTION,
248 wxSYS_COLOUR_MENUHILIGHT,
249 wxSYS_COLOUR_MENUBAR,
254 // possible values for wxSystemSettings::GetMetric() parameter
258 wxSYS_MOUSE_BUTTONS = 1,
269 wxSYS_HSCROLL_ARROW_X,
270 wxSYS_HSCROLL_ARROW_Y,
286 wxSYS_VSCROLL_ARROW_X,
287 wxSYS_VSCROLL_ARROW_Y,
291 wxSYS_NETWORK_PRESENT,
292 wxSYS_PENWINDOWS_PRESENT,
297 // possible values for wxSystemSettings::HasFeature() parameter
300 wxSYS_CAN_DRAW_FRAME_DECORATIONS = 1,
301 wxSYS_CAN_ICONIZE_FRAME
306 class wxSystemSettings {
308 // get a standard system colour
309 static wxColour GetColour(wxSystemColour index);
311 // get a standard system font
312 static wxFont GetFont(wxSystemFont index);
314 // get a system-dependent metric
315 static int GetMetric(wxSystemMetric index);
317 // return true if the port has certain feature
318 static bool HasFeature(wxSystemFeature index);
324 //---------------------------------------------------------------------------
327 class wxToolTip : public wxObject {
329 wxToolTip(const wxString &tip);
331 void SetTip(const wxString& tip);
333 // *** Not in the "public" interface void SetWindow(wxWindow *win);
334 wxWindow *GetWindow();
336 static void Enable(bool flag);
337 static void SetDelay(long milliseconds);
340 //----------------------------------------------------------------------
344 wxCaret(wxWindow* window, const wxSize& size);
349 %name(GetPositionTuple)void GetPosition(int *OUTPUT, int *OUTPUT);
350 wxPoint GetPosition();
351 %name(GetSizeTuple)void GetSize(int *OUTPUT, int *OUTPUT);
353 wxWindow *GetWindow();
354 %name(MoveXY)void Move(int x, int y);
355 void Move(const wxPoint& pt);
356 %name(SetSizeWH) void SetSize(int width, int height);
357 void SetSize(const wxSize& size);
358 void Show(int show = TRUE);
363 int wxCaret_GetBlinkTime() {
364 return wxCaret::GetBlinkTime();
367 void wxCaret_SetBlinkTime(int milliseconds) {
368 wxCaret::SetBlinkTime(milliseconds);
372 //----------------------------------------------------------------------
376 wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR);
380 //----------------------------------------------------------------------
382 class wxWindowDisabler {
384 wxWindowDisabler(wxWindow *winToSkip = NULL);
388 //----------------------------------------------------------------------
390 bool wxSafeYield(wxWindow* win=NULL);
391 void wxPostEvent(wxEvtHandler *dest, wxEvent& event);
396 void wxWakeUpMainThread();
399 void wxMutexGuiEnter();
400 void wxMutexGuiLeave();
403 class wxMutexGuiLocker {
411 bool wxThread_IsMain() {
412 #ifdef WXP_WITH_THREAD
413 return wxThread::IsMain();
420 //----------------------------------------------------------------------
426 // wxTipProvider(size_t currentTip); **** Abstract base class
429 virtual wxString GetTip() = 0;
430 size_t GetCurrentTip();
435 // The C++ version of wxPyTipProvider
437 class wxPyTipProvider : public wxTipProvider {
439 wxPyTipProvider(size_t currentTip)
440 : wxTipProvider(currentTip) {}
442 DEC_PYCALLBACK_STRING__pure(GetTip);
447 IMP_PYCALLBACK_STRING__pure( wxPyTipProvider, wxTipProvider, GetTip);
452 // Now let SWIG know about it
453 class wxPyTipProvider : public wxTipProvider {
455 wxPyTipProvider(size_t currentTip);
460 bool wxShowTip(wxWindow *parent, wxTipProvider *tipProvider, bool showAtStartup = TRUE);
461 %new wxTipProvider * wxCreateFileTipProvider(const wxString& filename, size_t currentTip);
464 //----------------------------------------------------------------------
467 #include <wx/generic/dragimgg.h>
470 %name (wxDragImage) class wxGenericDragImage : public wxObject
474 wxGenericDragImage(const wxBitmap& image,
475 const wxCursor& cursor = wxNullCursor);
476 %name(wxDragIcon)wxGenericDragImage(const wxIcon& image,
477 const wxCursor& cursor = wxNullCursor);
478 %name(wxDragString)wxGenericDragImage(const wxString& str,
479 const wxCursor& cursor = wxNullCursor);
480 %name(wxDragTreeItem)wxGenericDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
481 %name(wxDragListItem)wxGenericDragImage(const wxListCtrl& listCtrl, long id);
483 ~wxGenericDragImage();
485 void SetBackingBitmap(wxBitmap* bitmap);
486 bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
487 bool fullScreen = FALSE, wxRect* rect = NULL);
489 %name(BeginDrag2) bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
490 wxWindow* fullScreenRect);
493 bool Move(const wxPoint& pt);
497 wxRect GetImageRect(const wxPoint& pos) const;
498 bool RedrawImage(const wxPoint& oldPos, const wxPoint& newPos,
499 bool eraseOld, bool drawNew);
503 //----------------------------------------------------------------------
505 class wxPyTimer : public wxObject {
507 wxPyTimer(PyObject* notify);
512 void SetOwner(wxEvtHandler *owner, int id = -1);
513 void Start(int milliseconds=-1, int oneShot=FALSE);
521 // ctor starts the stop watch
524 void Start(long t = 0);
528 // get elapsed time since the last Start() or Pause() in milliseconds
533 //----------------------------------------------------------------------
534 //----------------------------------------------------------------------
539 wxLOG_FatalError, // program can't continue, abort immediately
540 wxLOG_Error, // a serious error, user must be informed about it
541 wxLOG_Warning, // user is normally informed about it but may be ignored
542 wxLOG_Message, // normal message (i.e. normal output of a non GUI app)
543 wxLOG_Info, // informational message (a.k.a. 'Verbose')
544 wxLOG_Status, // informational: might go to the status line of GUI app
545 wxLOG_Debug, // never shown to the user, disabled in release mode
546 wxLOG_Trace, // trace messages are also only enabled in debug mode
547 wxLOG_Progress, // used for progress indicator (not yet)
548 wxLOG_User = 100 // user defined levels start here
557 static bool IsEnabled();
558 static bool EnableLogging(bool doIt = TRUE);
559 static void OnLog(wxLogLevel level, const wxString& szString, int t=0);
561 virtual void Flush();
562 bool HasPendingMessages() const;
564 static void FlushActive();
565 static wxLog *GetActiveTarget();
566 static wxLog *SetActiveTarget(wxLog *pLogger);
568 static void Suspend();
569 static void Resume();
571 static void SetVerbose(bool bVerbose = TRUE);
573 static void DontCreateOnDemand();
574 static void SetTraceMask(wxTraceMask ulMask);
575 static void AddTraceMask(const wxString& str);
576 static void RemoveTraceMask(const wxString& str);
577 static void ClearTraceMasks();
579 static void SetTimestamp(const wxString& ts);
580 static const wxString& GetTimestamp();
582 bool GetVerbose() const;
584 static wxTraceMask GetTraceMask();
585 static bool IsAllowedTraceMask(const wxString& mask);
587 // static void TimeStamp(wxString *str);
589 wxString TimeStamp() {
591 wxLog::TimeStamp(&msg);
599 class wxLogStderr : public wxLog
602 wxLogStderr(/* TODO: FILE *fp = (FILE *) NULL*/);
606 class wxLogTextCtrl : public wxLog
609 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
613 class wxLogGui : public wxLog
619 class wxLogWindow : public wxLog
622 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
623 const wxString& szTitle, // the title of the frame
624 bool bShow = TRUE, // show window immediately?
625 bool bPassToOld = TRUE); // pass log messages to the old target?
627 void Show(bool bShow = TRUE);
628 wxFrame *GetFrame() const;
629 wxLog *GetOldLog() const;
630 bool IsPassingMessages() const;
631 void PassMessages(bool bDoPass);
635 class wxLogChain : public wxLog
638 wxLogChain(wxLog *logger);
639 void SetLog(wxLog *logger);
640 void PassMessages(bool bDoPass);
641 bool IsPassingMessages();
646 unsigned long wxSysErrorCode();
647 const wxString wxSysErrorMsg(unsigned long nErrCode = 0);
648 void wxLogFatalError(const wxString& szFormat);
649 void wxLogError(const wxString& szFormat);
650 void wxLogWarning(const wxString& szFormat);
651 void wxLogMessage(const wxString& szFormat);
652 void wxLogInfo(const wxString& szFormat);
653 void wxLogVerbose(const wxString& szFormat);
654 void wxLogStatus(const wxString& szFormat);
655 %name(wxLogStatusFrame)void wxLogStatus(wxFrame *pFrame, const wxString& szFormat);
656 void wxLogSysError(const wxString& szFormat);
658 // Suspress logging while an instance of this class exists
670 // A wxLog class that can be derived from in wxPython
671 class wxPyLog : public wxLog {
673 wxPyLog() : wxLog() {}
675 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) {
677 wxPyBeginBlockThreads();
678 if ((found = wxPyCBH_findCallback(m_myInst, "DoLog")))
679 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iOi)", level,
680 wx2PyString(szString), t));
681 wxPyEndBlockThreads();
683 wxLog::DoLog(level, szString, t);
686 virtual void DoLogString(const wxChar *szString, time_t t) {
688 wxPyBeginBlockThreads();
689 if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString")))
690 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)",
691 wx2PyString(szString), t));
692 wxPyEndBlockThreads();
694 wxLog::DoLogString(szString, t);
701 // Now tell SWIG about it
702 class wxPyLog : public wxLog {
705 void _setCallbackInfo(PyObject* self, PyObject* _class);
706 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyLog)"
707 %addmethods { void Destroy() { delete self; } }
712 //----------------------------------------------------------------------
721 class wxProcessEvent : public wxEvent {
723 wxProcessEvent(int id = 0, int pid = 0, int exitcode = 0);
726 int m_pid, m_exitcode;
732 %{ // C++ version of wxProcess derived class
734 class wxPyProcess : public wxProcess {
736 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1)
737 : wxProcess(parent, id)
740 DEC_PYCALLBACK_VOID_INTINT(OnTerminate);
745 IMP_PYCALLBACK_VOID_INTINT( wxPyProcess, wxProcess, OnTerminate);
750 %name(wxProcess)class wxPyProcess : public wxEvtHandler {
752 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1);
753 %addmethods { void Destroy() { delete self; } }
755 void _setCallbackInfo(PyObject* self, PyObject* _class);
756 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxProcess)"
758 void base_OnTerminate(int pid, int status);
764 wxInputStream *GetInputStream();
765 wxInputStream *GetErrorStream();
766 wxOutputStream *GetOutputStream();
774 // execute the process asynchronously
777 // execute it synchronously, i.e. wait until it finishes
780 // under Windows, don't hide the child even if it's IO is redirected (this
781 // is done by default)
784 // under Unix, if the process is the group leader then killing -pid kills
785 // all children as well as pid
786 wxEXEC_MAKE_GROUP_LEADER = 4
790 long wxExecute(const wxString& command,
791 int flags = wxEXEC_ASYNC,
792 wxPyProcess *process = NULL);
794 //----------------------------------------------------------------------
797 #if !wxUSE_JOYSTICK && !defined(__WXMSW__)
798 // A C++ stub class for wxJoystick for platforms that don't have it.
799 class wxJoystick : public wxObject {
801 wxJoystick(int joystick = wxJOYSTICK1) {
802 wxPyBeginBlockThreads();
803 PyErr_SetString(PyExc_NotImplementedError, "wxJoystick is not available on this platform.");
804 wxPyEndBlockThreads();
806 wxPoint GetPosition() { return wxPoint(-1,-1); }
807 int GetZPosition() { return -1; }
808 int GetButtonState() { return -1; }
809 int GetPOVPosition() { return -1; }
810 int GetPOVCTSPosition() { return -1; }
811 int GetRudderPosition() { return -1; }
812 int GetUPosition() { return -1; }
813 int GetVPosition() { return -1; }
814 int GetMovementThreshold() { return -1; }
815 void SetMovementThreshold(int threshold) {}
817 bool IsOk(void) { return FALSE; }
818 int GetNumberJoysticks() { return -1; }
819 int GetManufacturerId() { return -1; }
820 int GetProductId() { return -1; }
821 wxString GetProductName() { return ""; }
822 int GetXMin() { return -1; }
823 int GetYMin() { return -1; }
824 int GetZMin() { return -1; }
825 int GetXMax() { return -1; }
826 int GetYMax() { return -1; }
827 int GetZMax() { return -1; }
828 int GetNumberButtons() { return -1; }
829 int GetNumberAxes() { return -1; }
830 int GetMaxButtons() { return -1; }
831 int GetMaxAxes() { return -1; }
832 int GetPollingMin() { return -1; }
833 int GetPollingMax() { return -1; }
834 int GetRudderMin() { return -1; }
835 int GetRudderMax() { return -1; }
836 int GetUMin() { return -1; }
837 int GetUMax() { return -1; }
838 int GetVMin() { return -1; }
839 int GetVMax() { return -1; }
841 bool HasRudder() { return FALSE; }
842 bool HasZ() { return FALSE; }
843 bool HasU() { return FALSE; }
844 bool HasV() { return FALSE; }
845 bool HasPOV() { return FALSE; }
846 bool HasPOV4Dir() { return FALSE; }
847 bool HasPOVCTS() { return FALSE; }
849 bool SetCapture(wxWindow* win, int pollingFreq = 0) { return FALSE; }
850 bool ReleaseCapture() { return FALSE; }
856 class wxJoystick : public wxObject {
858 wxJoystick(int joystick = wxJOYSTICK1);
861 wxPoint GetPosition();
863 int GetButtonState();
864 int GetPOVPosition();
865 int GetPOVCTSPosition();
866 int GetRudderPosition();
869 int GetMovementThreshold();
870 void SetMovementThreshold(int threshold) ;
873 int GetNumberJoysticks();
874 int GetManufacturerId();
876 wxString GetProductName();
883 int GetNumberButtons();
904 bool SetCapture(wxWindow* win, int pollingFreq = 0);
905 bool ReleaseCapture();
908 //----------------------------------------------------------------------
912 // A C++ stub class for wxWave for platforms that don't have it.
913 class wxWave : public wxObject
916 wxWave(const wxString& fileName, bool isResource = FALSE) {
917 wxPyBeginBlockThreads();
918 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
919 wxPyEndBlockThreads();
921 wxWave(int size, const wxByte* data) {
922 wxPyBeginBlockThreads();
923 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
924 wxPyEndBlockThreads();
929 bool IsOk() const { return FALSE; }
930 bool Play(bool async = TRUE, bool looped = FALSE) const { return FALSE; }
936 class wxWave : public wxObject
939 wxWave(const wxString& fileName, bool isResource = FALSE);
943 bool Play(bool async = TRUE, bool looped = FALSE) const;
946 %new wxWave* wxWaveData(const wxString& data);
947 %{ // Implementations of some alternate "constructors"
948 wxWave* wxWaveData(const wxString& data) {
949 return new wxWave(data.Len(), (wxByte*)data.c_str());
954 //----------------------------------------------------------------------
958 wxMAILCAP_STANDARD = 1,
959 wxMAILCAP_NETSCAPE = 2,
973 wxFileTypeInfo(const char* mimeType,
975 const char* printCmd,
979 // the array elements correspond to the parameters of the ctor above in
981 %name(wxFileTypeInfoSequence)wxFileTypeInfo(const wxArrayString& sArray);
983 // invalid item - use this to terminate the array passed to
984 // wxMimeTypesManager::AddFallbacks
985 %name(wxNullFileTypeInfo)wxFileTypeInfo();
988 // test if this object can be used
989 bool IsValid() const;
993 void SetIcon(const wxString& iconFile, int iconIndex = 0);
995 // set the short desc
996 void SetShortDesc(const wxString& shortDesc);
1000 const wxString& GetMimeType() const;
1001 // get the open command
1002 const wxString& GetOpenCommand() const;
1003 // get the print command
1004 const wxString& GetPrintCommand() const;
1005 // get the short description (only used under Win32 so far)
1006 const wxString& GetShortDesc() const;
1007 // get the long, user visible description
1008 const wxString& GetDescription() const;
1011 // get the array of all extensions
1012 //const wxArrayString& GetExtensions() const;
1014 PyObject* GetExtensions() {
1015 wxArrayString& arr = (wxArrayString&)self->GetExtensions();
1016 return wxArrayString2PyList_helper(arr);
1020 int GetExtensionsCount() const;
1022 // get the icon info
1023 const wxString& GetIconFile() const;
1024 int GetIconIndex() const;
1034 // TODO: Make a wxPyMessageParameters with virtual GetParamValue...
1036 // An object of this class must be passed to Get{Open|Print}Command. The
1037 // default implementation is trivial and doesn't know anything at all about
1038 // parameters, only filename and MIME type are used (so it's probably ok for
1039 // Windows where %{param} is not used anyhow)
1040 class MessageParameters
1044 MessageParameters(const wxString& filename=wxPyEmptyString,
1045 const wxString& mimetype=wxPyEmptyString);
1047 // accessors (called by GetOpenCommand)
1049 const wxString& GetFileName() const;
1051 const wxString& GetMimeType() const;;
1053 // override this function in derived class
1054 virtual wxString GetParamValue(const wxString& name) const;
1056 // virtual dtor as in any base class
1057 virtual ~MessageParameters();
1061 // ctor from static data
1062 wxFileType(const wxFileTypeInfo& ftInfo);
1064 // return the MIME type for this file type
1066 PyObject* GetMimeType() {
1068 if (self->GetMimeType(&str)) {
1070 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1072 return PyString_FromStringAndSize(str.c_str(), str.Len());
1078 PyObject* GetMimeTypes() {
1080 if (self->GetMimeTypes(arr))
1081 return wxArrayString2PyList_helper(arr);
1088 // Get all extensions associated with this file type
1090 PyObject* GetExtensions() {
1092 if (self->GetExtensions(arr))
1093 return wxArrayString2PyList_helper(arr);
1101 // Get the icon corresponding to this file type
1102 %new wxIcon* GetIcon() {
1104 if (self->GetIcon(&icon))
1105 return new wxIcon(icon);
1110 // Get the icon corresponding to this file type, the name of the file
1111 // where this icon resides, and its index in this file if applicable.
1112 PyObject* GetIconInfo() {
1116 if (self->GetIcon(&icon, &iconFile, &iconIndex)) {
1117 wxPyBeginBlockThreads();
1118 PyObject* tuple = PyTuple_New(3);
1119 PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(icon),
1122 PyTuple_SetItem(tuple, 1, PyUnicode_FromUnicode(iconFile.c_str(), iconFile.Len()));
1124 PyTuple_SetItem(tuple, 1, PyString_FromStringAndSize(iconFile.c_str(), iconFile.Len()));
1126 PyTuple_SetItem(tuple, 2, PyInt_FromLong(iconIndex));
1127 wxPyEndBlockThreads();
1136 // get a brief file type description ("*.txt" => "text document")
1137 PyObject* GetDescription() {
1139 if (self->GetDescription(&str)) {
1141 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1143 return PyString_FromStringAndSize(str.c_str(), str.Len());
1151 // get the command to open/execute the file of given type
1153 PyObject* GetOpenCommand(const wxString& filename,
1154 const wxString& mimetype=wxPyEmptyString) {
1156 if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype))) {
1158 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1160 return PyString_FromStringAndSize(str.c_str(), str.Len());
1168 // get the command to print the file of given type
1170 PyObject* GetPrintCommand(const wxString& filename,
1171 const wxString& mimetype=wxPyEmptyString) {
1173 if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype))) {
1175 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1177 return PyString_FromStringAndSize(str.c_str(), str.Len());
1185 // Get all commands defined for this file type
1187 PyObject* GetAllCommands(const wxString& filename,
1188 const wxString& mimetype=wxPyEmptyString) {
1189 wxArrayString verbs;
1190 wxArrayString commands;
1191 if (self->GetAllCommands(&verbs, &commands,
1192 wxFileType::MessageParameters(filename, mimetype))) {
1193 wxPyBeginBlockThreads();
1194 PyObject* tuple = PyTuple_New(2);
1195 PyTuple_SetItem(tuple, 0, wxArrayString2PyList_helper(verbs));
1196 PyTuple_SetItem(tuple, 1, wxArrayString2PyList_helper(commands));
1197 wxPyEndBlockThreads();
1206 // set an arbitrary command, ask confirmation if it already exists and
1207 // overwriteprompt is TRUE
1208 bool SetCommand(const wxString& cmd, const wxString& verb,
1209 bool overwriteprompt = TRUE);
1211 bool SetDefaultIcon(const wxString& cmd = wxPyEmptyString, int index = 0);
1214 // remove the association for this filetype from the system MIME database:
1215 // notice that it will only work if the association is defined in the user
1216 // file/registry part, we will never modify the system-wide settings
1220 // expand a string in the format of GetOpenCommand (which may contain
1221 // '%s' and '%t' format specificators for the file name and mime type
1222 // and %{param} constructions).
1223 static wxString ExpandCommand(const wxString& command,
1224 const MessageParameters& params);
1226 // dtor (not virtual, shouldn't be derived from)
1234 class wxMimeTypesManager
1237 // static helper functions
1238 // -----------------------
1240 // check if the given MIME type is the same as the other one: the
1241 // second argument may contain wildcards ('*'), but not the first. If
1242 // the types are equal or if the mimeType matches wildcard the function
1243 // returns TRUE, otherwise it returns FALSE
1244 static bool IsOfType(const wxString& mimeType, const wxString& wildcard);
1247 wxMimeTypesManager();
1249 // loads data from standard files according to the mailcap styles
1250 // specified: this is a bitwise OR of wxMailcapStyle values
1252 // use the extraDir parameter if you want to look for files in another
1254 void Initialize(int mailcapStyle = wxMAILCAP_STANDARD,
1255 const wxString& extraDir = wxPyEmptyString);
1257 // and this function clears all the data from the manager
1260 // Database lookup: all functions return a pointer to wxFileType object
1261 // whose methods may be used to query it for the information you're
1262 // interested in. If the return value is !NULL, caller is responsible for
1264 // get file type from file extension
1265 %new wxFileType *GetFileTypeFromExtension(const wxString& ext);
1267 // get file type from MIME type (in format <category>/<format>)
1268 %new wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
1270 // other operations: return TRUE if there were no errors or FALSE if there
1271 // were some unreckognized entries (the good entries are always read anyhow)
1274 // read in additional file (the standard ones are read automatically)
1275 // in mailcap format (see mimetype.cpp for description)
1277 // 'fallback' parameter may be set to TRUE to avoid overriding the
1278 // settings from other, previously parsed, files by this one: normally,
1279 // the files read most recently would override the older files, but with
1280 // fallback == TRUE this won't happen
1281 bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
1283 // read in additional file in mime.types format
1284 bool ReadMimeTypes(const wxString& filename);
1286 // enumerate all known MIME types
1288 PyObject* EnumAllFileTypes() {
1290 self->EnumAllFileTypes(arr);
1291 return wxArrayString2PyList_helper(arr);
1295 // these functions can be used to provide default values for some of the
1296 // MIME types inside the program itself (you may also use
1297 // ReadMailcap(filenameWithDefaultTypes, TRUE /* use as fallback */) to
1298 // achieve the same goal, but this requires having this info in a file).
1300 void AddFallback(const wxFileTypeInfo& ft);
1303 // create or remove associations
1305 // create a new association using the fields of wxFileTypeInfo (at least
1306 // the MIME type and the extension should be set)
1307 // if the other fields are empty, the existing values should be left alone
1308 %new wxFileType *Associate(const wxFileTypeInfo& ftInfo);
1311 bool Unassociate(wxFileType *ft) ;
1313 // dtor (not virtual, shouldn't be derived from)
1314 ~wxMimeTypesManager();
1322 extern wxMimeTypesManager* wxTheMimeTypesManager;
1328 //----------------------------------------------------------------------
1331 #include <wx/docview.h>
1334 class wxFileHistory : public wxObject
1337 wxFileHistory(int maxFiles = 9);
1341 void AddFileToHistory(const wxString& file);
1342 void RemoveFileFromHistory(int i);
1343 int GetMaxFiles() const;
1344 void UseMenu(wxMenu *menu);
1346 // Remove menu from the list (MDI child may be closing)
1347 void RemoveMenu(wxMenu *menu);
1349 void Load(wxConfigBase& config);
1350 void Save(wxConfigBase& config);
1352 void AddFilesToMenu();
1353 %name(AddFilesToThisMenu)void AddFilesToMenu(wxMenu* menu);
1356 wxString GetHistoryFile(int i) const;
1358 // A synonym for GetNoHistoryFiles
1359 int GetCount() const;
1360 int GetNoHistoryFiles() const;
1364 //----------------------------------------------------------------------
1365 //----------------------------------------------------------------------
1369 wxPyPtrTypeMap_Add("wxDragImage", "wxGenericDragImage");
1370 wxPyPtrTypeMap_Add("wxProcess", "wxPyProcess");
1373 //----------------------------------------------------------------------