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/fontenum.h>
24 #include <wx/tipdlg.h>
25 #include <wx/process.h>
27 #if wxUSE_JOYSTICK || defined(__WXMSW__)
28 #include <wx/joystick.h>
31 #if wxUSE_WAVE || defined(__WXMSW__)
35 #include <wx/mimetype.h>
38 //----------------------------------------------------------------------
41 %include my_typemaps.i
43 // Import some definitions of other classes, etc.
53 //---------------------------------------------------------------------------
56 wxString wxFileSelector(const wxChar* message = wxFileSelectorPromptStr,
57 const wxChar* default_path = NULL,
58 const wxChar* default_filename = NULL,
59 const wxChar* default_extension = NULL,
60 const wxChar* wildcard = wxFileSelectorDefaultWildcardStr,
62 wxWindow *parent = NULL,
63 int x = -1, int y = -1);
65 // Ask for filename to load
66 wxString wxLoadFileSelector(const wxChar *what,
67 const wxChar *extension,
68 const wxChar *default_name = NULL,
69 wxWindow *parent = NULL);
71 // Ask for filename to save
72 wxString wxSaveFileSelector(const wxChar *what,
73 const wxChar *extension,
74 const wxChar *default_name = NULL,
75 wxWindow *parent = NULL);
77 wxString wxGetTextFromUser(const wxString& message,
78 const wxString& caption = wxEmptyString,
79 const wxString& default_value = wxEmptyString,
80 wxWindow *parent = NULL,
81 int x = -1, int y = -1,
84 wxString wxGetPasswordFromUser(const wxString& message,
85 const wxString& caption = wxEmptyString,
86 const wxString& default_value = wxEmptyString,
87 wxWindow *parent = NULL);
90 // TODO: Need to custom wrap this one...
91 // int wxGetMultipleChoice(char* message, char* caption,
92 // int LCOUNT, char** choices,
93 // int nsel, int *selection,
94 // wxWindow *parent = NULL, int x = -1, int y = -1,
95 // bool centre = TRUE, int width=150, int height=200);
98 wxString wxGetSingleChoice(const wxString& message, const wxString& caption,
99 int LCOUNT, wxString* choices,
100 wxWindow *parent = NULL,
101 int x = -1, int y = -1,
103 int width=150, int height=200);
105 int wxGetSingleChoiceIndex(const wxString& message, const wxString& caption,
106 int LCOUNT, wxString* choices,
107 wxWindow *parent = NULL,
108 int x = -1, int y = -1,
110 int width=150, int height=200);
113 int wxMessageBox(const wxString& message,
114 const wxString& caption = wxEmptyString,
115 int style = wxOK | wxCENTRE,
116 wxWindow *parent = NULL,
117 int x = -1, int y = -1);
119 long wxGetNumberFromUser(const wxString& message,
120 const wxString& prompt,
121 const wxString& caption,
123 long min = 0, long max = 100,
124 wxWindow *parent = NULL,
125 const wxPoint& pos = wxDefaultPosition);
127 //---------------------------------------------------------------------------
130 bool wxColourDisplay();
132 int wxDisplayDepth();
133 int wxGetDisplayDepth();
135 void wxDisplaySize(int* OUTPUT, int* OUTPUT);
136 wxSize wxGetDisplaySize();
138 void wxDisplaySizeMM(int* OUTPUT, int* OUTPUT);
139 wxSize wxGetDisplaySizeMM();
141 void wxClientDisplayRect(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT);
142 wxRect wxGetClientDisplayRect();
144 void wxSetCursor(wxCursor& cursor);
146 //----------------------------------------------------------------------
147 // Miscellaneous functions
149 wxWindow * wxFindWindowByLabel(const wxString& label, wxWindow *parent=NULL);
150 wxWindow * wxFindWindowByName(const wxString& name, wxWindow *parent=NULL);
152 void wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR);
153 wxWindow * wxGetActiveWindow();
155 wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt);
156 wxWindow* wxFindWindowAtPoint(const wxPoint& pt);
159 bool wxCheckForInterrupt(wxWindow *wnd);
160 void wxFlushEvents();
163 //---------------------------------------------------------------------------
166 bool wxResourceAddIdentifier(char *name, int value);
167 void wxResourceClear(void);
168 wxBitmap wxResourceCreateBitmap(char *resource);
169 wxIcon wxResourceCreateIcon(char *resource);
170 wxMenuBar * wxResourceCreateMenuBar(char *resource);
171 int wxResourceGetIdentifier(char *name);
172 bool wxResourceParseData(char *resource, wxResourceTable *table = NULL);
173 bool wxResourceParseFile(char *filename, wxResourceTable *table = NULL);
174 bool wxResourceParseString(char *resource, wxResourceTable *table = NULL);
176 //---------------------------------------------------------------------------
179 // possible values for wxSystemSettings::GetFont() parameter
183 wxSYS_OEM_FIXED_FONT = 10,
184 wxSYS_ANSI_FIXED_FONT,
187 wxSYS_DEVICE_DEFAULT_FONT,
188 wxSYS_DEFAULT_PALETTE,
189 wxSYS_SYSTEM_FIXED_FONT,
190 wxSYS_DEFAULT_GUI_FONT
193 // possible values for wxSystemSettings::GetColour() parameter
197 wxSYS_COLOUR_SCROLLBAR,
198 wxSYS_COLOUR_BACKGROUND,
199 wxSYS_COLOUR_DESKTOP = wxSYS_COLOUR_BACKGROUND,
200 wxSYS_COLOUR_ACTIVECAPTION,
201 wxSYS_COLOUR_INACTIVECAPTION,
204 wxSYS_COLOUR_WINDOWFRAME,
205 wxSYS_COLOUR_MENUTEXT,
206 wxSYS_COLOUR_WINDOWTEXT,
207 wxSYS_COLOUR_CAPTIONTEXT,
208 wxSYS_COLOUR_ACTIVEBORDER,
209 wxSYS_COLOUR_INACTIVEBORDER,
210 wxSYS_COLOUR_APPWORKSPACE,
211 wxSYS_COLOUR_HIGHLIGHT,
212 wxSYS_COLOUR_HIGHLIGHTTEXT,
213 wxSYS_COLOUR_BTNFACE,
214 wxSYS_COLOUR_3DFACE = wxSYS_COLOUR_BTNFACE,
215 wxSYS_COLOUR_BTNSHADOW,
216 wxSYS_COLOUR_3DSHADOW = wxSYS_COLOUR_BTNSHADOW,
217 wxSYS_COLOUR_GRAYTEXT,
218 wxSYS_COLOUR_BTNTEXT,
219 wxSYS_COLOUR_INACTIVECAPTIONTEXT,
220 wxSYS_COLOUR_BTNHIGHLIGHT,
221 wxSYS_COLOUR_BTNHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
222 wxSYS_COLOUR_3DHIGHLIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
223 wxSYS_COLOUR_3DHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
224 wxSYS_COLOUR_3DDKSHADOW,
225 wxSYS_COLOUR_3DLIGHT,
226 wxSYS_COLOUR_INFOTEXT,
228 wxSYS_COLOUR_LISTBOX,
229 wxSYS_COLOUR_HOTLIGHT,
230 wxSYS_COLOUR_GRADIENTACTIVECAPTION,
231 wxSYS_COLOUR_GRADIENTINACTIVECAPTION,
232 wxSYS_COLOUR_MENUHILIGHT,
233 wxSYS_COLOUR_MENUBAR,
238 // possible values for wxSystemSettings::GetMetric() parameter
242 wxSYS_MOUSE_BUTTONS = 1,
253 wxSYS_HSCROLL_ARROW_X,
254 wxSYS_HSCROLL_ARROW_Y,
270 wxSYS_VSCROLL_ARROW_X,
271 wxSYS_VSCROLL_ARROW_Y,
275 wxSYS_NETWORK_PRESENT,
276 wxSYS_PENWINDOWS_PRESENT,
281 // possible values for wxSystemSettings::HasFeature() parameter
284 wxSYS_CAN_DRAW_FRAME_DECORATIONS = 1,
285 wxSYS_CAN_ICONIZE_FRAME
290 class wxSystemSettings {
292 // get a standard system colour
293 static wxColour GetColour(wxSystemColour index);
295 // get a standard system font
296 static wxFont GetFont(wxSystemFont index);
298 // get a system-dependent metric
299 static int GetMetric(wxSystemMetric index);
301 // return true if the port has certain feature
302 static bool HasFeature(wxSystemFeature index);
308 //---------------------------------------------------------------------------
311 class wxToolTip : public wxObject {
313 wxToolTip(const wxString &tip);
315 void SetTip(const wxString& tip);
317 // *** Not in the "public" interface void SetWindow(wxWindow *win);
318 wxWindow *GetWindow();
320 static void Enable(bool flag);
321 static void SetDelay(long milliseconds);
324 //----------------------------------------------------------------------
328 wxCaret(wxWindow* window, const wxSize& size);
333 %name(GetPositionTuple)void GetPosition(int *OUTPUT, int *OUTPUT);
334 wxPoint GetPosition();
335 %name(GetSizeTuple)void GetSize(int *OUTPUT, int *OUTPUT);
337 wxWindow *GetWindow();
338 %name(MoveXY)void Move(int x, int y);
339 void Move(const wxPoint& pt);
340 %name(SetSizeWH) void SetSize(int width, int height);
341 void SetSize(const wxSize& size);
342 void Show(int show = TRUE);
347 int wxCaret_GetBlinkTime() {
348 return wxCaret::GetBlinkTime();
351 void wxCaret_SetBlinkTime(int milliseconds) {
352 wxCaret::SetBlinkTime(milliseconds);
356 //----------------------------------------------------------------------
359 class wxPyFontEnumerator : public wxFontEnumerator {
361 wxPyFontEnumerator() {}
362 ~wxPyFontEnumerator() {}
364 DEC_PYCALLBACK_BOOL_STRING(OnFacename);
365 DEC_PYCALLBACK_BOOL_STRINGSTRING(OnFontEncoding);
370 IMP_PYCALLBACK_BOOL_STRING(wxPyFontEnumerator, wxFontEnumerator, OnFacename);
371 IMP_PYCALLBACK_BOOL_STRINGSTRING(wxPyFontEnumerator, wxFontEnumerator, OnFontEncoding);
375 %name(wxFontEnumerator) class wxPyFontEnumerator {
377 wxPyFontEnumerator();
378 ~wxPyFontEnumerator();
379 void _setCallbackInfo(PyObject* self, PyObject* _class, bool incref);
380 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFontEnumerator, 0)"
382 bool EnumerateFacenames(
383 wxFontEncoding encoding = wxFONTENCODING_SYSTEM, // all
384 bool fixedWidthOnly = FALSE);
385 bool EnumerateEncodings(const char* facename = "");
387 //wxArrayString* GetEncodings();
388 //wxArrayString* GetFacenames();
390 PyObject* GetEncodings() {
391 wxArrayString* arr = self->GetEncodings();
392 return wxArrayString2PyList_helper(*arr);
395 PyObject* GetFacenames() {
396 wxArrayString* arr = self->GetFacenames();
397 return wxArrayString2PyList_helper(*arr);
402 //----------------------------------------------------------------------
406 wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR);
410 //----------------------------------------------------------------------
412 class wxWindowDisabler {
414 wxWindowDisabler(wxWindow *winToSkip = NULL);
418 //----------------------------------------------------------------------
420 bool wxSafeYield(wxWindow* win=NULL);
421 void wxPostEvent(wxEvtHandler *dest, wxEvent& event);
426 void wxWakeUpMainThread();
429 void wxMutexGuiEnter();
430 void wxMutexGuiLeave();
433 class wxMutexGuiLocker {
441 bool wxThread_IsMain() {
442 #ifdef WXP_WITH_THREAD
443 return wxThread::IsMain();
450 //----------------------------------------------------------------------
456 // wxTipProvider(size_t currentTip); **** Abstract base class
459 virtual wxString GetTip() = 0;
460 size_t GetCurrentTip();
465 // The C++ version of wxPyTipProvider
467 class wxPyTipProvider : public wxTipProvider {
469 wxPyTipProvider(size_t currentTip)
470 : wxTipProvider(currentTip) {}
472 DEC_PYCALLBACK_STRING__pure(GetTip);
477 IMP_PYCALLBACK_STRING__pure( wxPyTipProvider, wxTipProvider, GetTip);
482 // Now let SWIG know about it
483 class wxPyTipProvider : public wxTipProvider {
485 wxPyTipProvider(size_t currentTip);
490 bool wxShowTip(wxWindow *parent, wxTipProvider *tipProvider, bool showAtStartup = TRUE);
491 %new wxTipProvider * wxCreateFileTipProvider(const wxString& filename, size_t currentTip);
494 //----------------------------------------------------------------------
497 #include <wx/generic/dragimgg.h>
500 %name (wxDragImage) class wxGenericDragImage : public wxObject
504 wxGenericDragImage(const wxBitmap& image,
505 const wxCursor& cursor = wxNullCursor);
506 %name(wxDragIcon)wxGenericDragImage(const wxIcon& image,
507 const wxCursor& cursor = wxNullCursor);
508 %name(wxDragString)wxGenericDragImage(const wxString& str,
509 const wxCursor& cursor = wxNullCursor);
510 %name(wxDragTreeItem)wxGenericDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
511 %name(wxDragListItem)wxGenericDragImage(const wxListCtrl& listCtrl, long id);
513 ~wxGenericDragImage();
515 void SetBackingBitmap(wxBitmap* bitmap);
516 bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
517 bool fullScreen = FALSE, wxRect* rect = NULL);
519 %name(BeginDrag2) bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
520 wxWindow* fullScreenRect);
523 bool Move(const wxPoint& pt);
527 wxRect GetImageRect(const wxPoint& pos) const;
528 bool RedrawImage(const wxPoint& oldPos, const wxPoint& newPos,
529 bool eraseOld, bool drawNew);
533 //----------------------------------------------------------------------
535 class wxPyTimer : public wxObject {
537 wxPyTimer(PyObject* notify);
542 void SetOwner(wxEvtHandler *owner, int id = -1);
543 void Start(int milliseconds=-1, int oneShot=FALSE);
551 // ctor starts the stop watch
554 void Start(long t = 0);
558 // get elapsed time since the last Start() or Pause() in milliseconds
563 //----------------------------------------------------------------------
564 //----------------------------------------------------------------------
569 wxLOG_FatalError, // program can't continue, abort immediately
570 wxLOG_Error, // a serious error, user must be informed about it
571 wxLOG_Warning, // user is normally informed about it but may be ignored
572 wxLOG_Message, // normal message (i.e. normal output of a non GUI app)
573 wxLOG_Info, // informational message (a.k.a. 'Verbose')
574 wxLOG_Status, // informational: might go to the status line of GUI app
575 wxLOG_Debug, // never shown to the user, disabled in release mode
576 wxLOG_Trace, // trace messages are also only enabled in debug mode
577 wxLOG_Progress, // used for progress indicator (not yet)
578 wxLOG_User = 100 // user defined levels start here
587 static bool IsEnabled();
588 static bool EnableLogging(bool doIt = TRUE);
589 static void OnLog(wxLogLevel level, const wxString& szString, int t=0);
591 virtual void Flush();
592 bool HasPendingMessages() const;
594 static void FlushActive();
595 static wxLog *GetActiveTarget();
596 static wxLog *SetActiveTarget(wxLog *pLogger);
598 static void Suspend();
599 static void Resume();
601 void SetVerbose(bool bVerbose = TRUE);
603 static void DontCreateOnDemand();
604 static void SetTraceMask(wxTraceMask ulMask);
605 static void AddTraceMask(const wxString& str);
606 static void RemoveTraceMask(const wxString& str);
607 static void ClearTraceMasks();
609 static void SetTimestamp(const wxChar *ts);
610 static const wxChar *GetTimestamp();
612 bool GetVerbose() const { return m_bVerbose; }
614 static wxTraceMask GetTraceMask();
615 static bool IsAllowedTraceMask(const wxString& mask);
617 // static void TimeStamp(wxString *str);
619 wxString TimeStamp() {
621 wxLog::TimeStamp(&msg);
628 class wxLogStderr : public wxLog
631 wxLogStderr(/* TODO: FILE *fp = (FILE *) NULL*/);
635 class wxLogTextCtrl : public wxLog
638 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
642 class wxLogGui : public wxLog
648 class wxLogWindow : public wxLog
651 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
652 const wxString& szTitle, // the title of the frame
653 bool bShow = TRUE, // show window immediately?
654 bool bPassToOld = TRUE); // pass log messages to the old target?
656 void Show(bool bShow = TRUE);
657 wxFrame *GetFrame() const;
658 wxLog *GetOldLog() const;
659 bool IsPassingMessages() const;
660 void PassMessages(bool bDoPass);
672 class wxLogChain : public wxLog
675 wxLogChain(wxLog *logger);
676 void SetLog(wxLog *logger);
677 void PassMessages(bool bDoPass);
678 bool IsPassingMessages();
683 unsigned long wxSysErrorCode();
684 const wxString wxSysErrorMsg(unsigned long nErrCode = 0);
685 void wxLogFatalError(const wxString& szFormat);
686 void wxLogError(const wxString& szFormat);
687 void wxLogWarning(const wxString& szFormat);
688 void wxLogMessage(const wxString& szFormat);
689 void wxLogInfo(const wxString& szFormat);
690 void wxLogVerbose(const wxString& szFormat);
691 void wxLogStatus(const wxString& szFormat);
692 %name(wxLogStatusFrame)void wxLogStatus(wxFrame *pFrame, const wxString& szFormat);
693 void wxLogSysError(const wxString& szFormat);
697 // A Log class that can be derived from in wxPython
698 class wxPyLog : public wxLog {
700 wxPyLog() : wxLog() {}
702 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) {
704 wxPyBeginBlockThreads();
705 if ((found = wxPyCBH_findCallback(m_myInst, "DoLog")))
706 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iOi)", level,
707 wx2PyString(szString), t));
708 wxPyEndBlockThreads();
710 wxLog::DoLog(level, szString, t);
713 virtual void DoLogString(const wxChar *szString, time_t t) {
715 wxPyBeginBlockThreads();
716 if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString")))
717 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)",
718 wx2PyString(szString), t));
719 wxPyEndBlockThreads();
721 wxLog::DoLogString(szString, t);
728 // Now tell SWIG about it
729 class wxPyLog : public wxLog {
732 void _setCallbackInfo(PyObject* self, PyObject* _class);
733 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyLog)"
734 %addmethods { void Destroy() { delete self; } }
739 //----------------------------------------------------------------------
748 class wxProcessEvent : public wxEvent {
750 wxProcessEvent(int id = 0, int pid = 0, int exitcode = 0);
753 int m_pid, m_exitcode;
759 %{ // C++ version of wxProcess derived class
761 class wxPyProcess : public wxProcess {
763 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1)
764 : wxProcess(parent, id)
767 DEC_PYCALLBACK_VOID_INTINT(OnTerminate);
772 IMP_PYCALLBACK_VOID_INTINT( wxPyProcess, wxProcess, OnTerminate);
777 %name(wxProcess)class wxPyProcess : public wxEvtHandler {
779 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1);
780 %addmethods { void Destroy() { delete self; } }
782 void _setCallbackInfo(PyObject* self, PyObject* _class);
783 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxProcess)"
785 void base_OnTerminate(int pid, int status);
791 wxInputStream *GetInputStream();
792 wxInputStream *GetErrorStream();
793 wxOutputStream *GetOutputStream();
800 long wxExecute(const wxString& command,
802 wxPyProcess *process = NULL);
804 //----------------------------------------------------------------------
807 #if !wxUSE_JOYSTICK && !defined(__WXMSW__)
808 // A C++ stub class for wxJoystick for platforms that don't have it.
809 class wxJoystick : public wxObject {
811 wxJoystick(int joystick = wxJOYSTICK1) {
812 wxPyBeginBlockThreads();
813 PyErr_SetString(PyExc_NotImplementedError, "wxJoystick is not available on this platform.");
814 wxPyEndBlockThreads();
816 wxPoint GetPosition() { return wxPoint(-1,-1); }
817 int GetZPosition() { return -1; }
818 int GetButtonState() { return -1; }
819 int GetPOVPosition() { return -1; }
820 int GetPOVCTSPosition() { return -1; }
821 int GetRudderPosition() { return -1; }
822 int GetUPosition() { return -1; }
823 int GetVPosition() { return -1; }
824 int GetMovementThreshold() { return -1; }
825 void SetMovementThreshold(int threshold) {}
827 bool IsOk(void) { return FALSE; }
828 int GetNumberJoysticks() { return -1; }
829 int GetManufacturerId() { return -1; }
830 int GetProductId() { return -1; }
831 wxString GetProductName() { return ""; }
832 int GetXMin() { return -1; }
833 int GetYMin() { return -1; }
834 int GetZMin() { return -1; }
835 int GetXMax() { return -1; }
836 int GetYMax() { return -1; }
837 int GetZMax() { return -1; }
838 int GetNumberButtons() { return -1; }
839 int GetNumberAxes() { return -1; }
840 int GetMaxButtons() { return -1; }
841 int GetMaxAxes() { return -1; }
842 int GetPollingMin() { return -1; }
843 int GetPollingMax() { return -1; }
844 int GetRudderMin() { return -1; }
845 int GetRudderMax() { return -1; }
846 int GetUMin() { return -1; }
847 int GetUMax() { return -1; }
848 int GetVMin() { return -1; }
849 int GetVMax() { return -1; }
851 bool HasRudder() { return FALSE; }
852 bool HasZ() { return FALSE; }
853 bool HasU() { return FALSE; }
854 bool HasV() { return FALSE; }
855 bool HasPOV() { return FALSE; }
856 bool HasPOV4Dir() { return FALSE; }
857 bool HasPOVCTS() { return FALSE; }
859 bool SetCapture(wxWindow* win, int pollingFreq = 0) { return FALSE; }
860 bool ReleaseCapture() { return FALSE; }
866 class wxJoystick : public wxObject {
868 wxJoystick(int joystick = wxJOYSTICK1);
871 wxPoint GetPosition();
873 int GetButtonState();
874 int GetPOVPosition();
875 int GetPOVCTSPosition();
876 int GetRudderPosition();
879 int GetMovementThreshold();
880 void SetMovementThreshold(int threshold) ;
883 int GetNumberJoysticks();
884 int GetManufacturerId();
886 wxString GetProductName();
893 int GetNumberButtons();
914 bool SetCapture(wxWindow* win, int pollingFreq = 0);
915 bool ReleaseCapture();
918 //----------------------------------------------------------------------
922 // A C++ stub class for wxWave for platforms that don't have it.
923 class wxWave : public wxObject
926 wxWave(const wxString& fileName, bool isResource = FALSE) {
927 wxPyBeginBlockThreads();
928 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
929 wxPyEndBlockThreads();
931 wxWave(int size, const wxByte* data) {
932 wxPyBeginBlockThreads();
933 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
934 wxPyEndBlockThreads();
939 bool IsOk() const { return FALSE; }
940 bool Play(bool async = TRUE, bool looped = FALSE) const { return FALSE; }
946 class wxWave : public wxObject
949 wxWave(const wxString& fileName, bool isResource = FALSE);
953 bool Play(bool async = TRUE, bool looped = FALSE) const;
956 %new wxWave* wxWaveData(const wxString& data);
957 %{ // Implementations of some alternate "constructors"
958 wxWave* wxWaveData(const wxString& data) {
959 return new wxWave(data.Len(), (wxByte*)data.c_str());
964 //----------------------------------------------------------------------
968 wxMAILCAP_STANDARD = 1,
969 wxMAILCAP_NETSCAPE = 2,
983 wxFileTypeInfo(const char *mimeType,
985 const char *printCmd,
989 // the array elements correspond to the parameters of the ctor above in
991 %name(wxFileTypeInfoSequence)wxFileTypeInfo(const wxArrayString& sArray);
993 // invalid item - use this to terminate the array passed to
994 // wxMimeTypesManager::AddFallbacks
995 %name(wxNullFileTypeInfo)wxFileTypeInfo();
998 // test if this object can be used
999 bool IsValid() const;
1002 // set the icon info
1003 void SetIcon(const wxString& iconFile, int iconIndex = 0);
1005 // set the short desc
1006 void SetShortDesc(const wxString& shortDesc);
1009 // get the MIME type
1010 const wxString& GetMimeType() const;
1011 // get the open command
1012 const wxString& GetOpenCommand() const;
1013 // get the print command
1014 const wxString& GetPrintCommand() const;
1015 // get the short description (only used under Win32 so far)
1016 const wxString& GetShortDesc() const;
1017 // get the long, user visible description
1018 const wxString& GetDescription() const;
1021 // get the array of all extensions
1022 //const wxArrayString& GetExtensions() const;
1024 PyObject* GetExtensions() {
1025 wxArrayString& arr = (wxArrayString&)self->GetExtensions();
1026 return wxArrayString2PyList_helper(arr);
1030 int GetExtensionsCount() const;
1032 // get the icon info
1033 const wxString& GetIconFile() const;
1034 int GetIconIndex() const;
1044 // TODO: Make a wxPyMessageParameters with virtual GetParamValue...
1046 // An object of this class must be passed to Get{Open|Print}Command. The
1047 // default implementation is trivial and doesn't know anything at all about
1048 // parameters, only filename and MIME type are used (so it's probably ok for
1049 // Windows where %{param} is not used anyhow)
1050 class MessageParameters
1054 MessageParameters(const wxString& filename=wxEmptyString,
1055 const wxString& mimetype=wxEmptyString);
1057 // accessors (called by GetOpenCommand)
1059 const wxString& GetFileName() const;
1061 const wxString& GetMimeType() const;;
1063 // override this function in derived class
1064 virtual wxString GetParamValue(const wxString& name) const;
1066 // virtual dtor as in any base class
1067 virtual ~MessageParameters();
1071 // ctor from static data
1072 wxFileType(const wxFileTypeInfo& ftInfo);
1074 // return the MIME type for this file type
1076 PyObject* GetMimeType() {
1078 if (self->GetMimeType(&str)) {
1080 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1082 return PyString_FromStringAndSize(str.c_str(), str.Len());
1088 PyObject* GetMimeTypes() {
1090 if (self->GetMimeTypes(arr))
1091 return wxArrayString2PyList_helper(arr);
1098 // Get all extensions associated with this file type
1100 PyObject* GetExtensions() {
1102 if (self->GetExtensions(arr))
1103 return wxArrayString2PyList_helper(arr);
1111 // Get the icon corresponding to this file type
1112 %new wxIcon* GetIcon() {
1114 if (self->GetIcon(&icon))
1115 return new wxIcon(icon);
1120 // Get the icon corresponding to this file type, the name of the file
1121 // where this icon resides, and its index in this file if applicable.
1122 PyObject* GetIconInfo() {
1126 if (self->GetIcon(&icon, &iconFile, &iconIndex)) {
1127 wxPyBeginBlockThreads();
1128 PyObject* tuple = PyTuple_New(3);
1129 PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(icon),
1132 PyTuple_SetItem(tuple, 1, PyUnicode_FromUnicode(iconFile.c_str(), iconFile.Len()));
1134 PyTuple_SetItem(tuple, 1, PyString_FromStringAndSize(iconFile.c_str(), iconFile.Len()));
1136 PyTuple_SetItem(tuple, 2, PyInt_FromLong(iconIndex));
1137 wxPyEndBlockThreads();
1146 // get a brief file type description ("*.txt" => "text document")
1147 PyObject* GetDescription() {
1149 if (self->GetDescription(&str)) {
1151 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1153 return PyString_FromStringAndSize(str.c_str(), str.Len());
1161 // get the command to open/execute the file of given type
1163 PyObject* GetOpenCommand(const wxString& filename,
1164 const wxString& mimetype=wxEmptyString) {
1166 if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype))) {
1168 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1170 return PyString_FromStringAndSize(str.c_str(), str.Len());
1178 // get the command to print the file of given type
1180 PyObject* GetPrintCommand(const wxString& filename,
1181 const wxString& mimetype=wxEmptyString) {
1183 if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype))) {
1185 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1187 return PyString_FromStringAndSize(str.c_str(), str.Len());
1195 // Get all commands defined for this file type
1197 PyObject* GetAllCommands(const wxString& filename,
1198 const wxString& mimetype=wxEmptyString) {
1199 wxArrayString verbs;
1200 wxArrayString commands;
1201 if (self->GetAllCommands(&verbs, &commands,
1202 wxFileType::MessageParameters(filename, mimetype))) {
1203 wxPyBeginBlockThreads();
1204 PyObject* tuple = PyTuple_New(2);
1205 PyTuple_SetItem(tuple, 0, wxArrayString2PyList_helper(verbs));
1206 PyTuple_SetItem(tuple, 1, wxArrayString2PyList_helper(commands));
1207 wxPyEndBlockThreads();
1216 // set an arbitrary command, ask confirmation if it already exists and
1217 // overwriteprompt is TRUE
1218 bool SetCommand(const wxString& cmd, const wxString& verb,
1219 bool overwriteprompt = TRUE);
1221 bool SetDefaultIcon(const wxString& cmd = wxEmptyString, int index = 0);
1224 // remove the association for this filetype from the system MIME database:
1225 // notice that it will only work if the association is defined in the user
1226 // file/registry part, we will never modify the system-wide settings
1230 // expand a string in the format of GetOpenCommand (which may contain
1231 // '%s' and '%t' format specificators for the file name and mime type
1232 // and %{param} constructions).
1233 static wxString ExpandCommand(const wxString& command,
1234 const MessageParameters& params);
1236 // dtor (not virtual, shouldn't be derived from)
1244 class wxMimeTypesManager
1247 // static helper functions
1248 // -----------------------
1250 // check if the given MIME type is the same as the other one: the
1251 // second argument may contain wildcards ('*'), but not the first. If
1252 // the types are equal or if the mimeType matches wildcard the function
1253 // returns TRUE, otherwise it returns FALSE
1254 static bool IsOfType(const wxString& mimeType, const wxString& wildcard);
1257 wxMimeTypesManager();
1259 // loads data from standard files according to the mailcap styles
1260 // specified: this is a bitwise OR of wxMailcapStyle values
1262 // use the extraDir parameter if you want to look for files in another
1264 void Initialize(int mailcapStyle = wxMAILCAP_STANDARD,
1265 const wxString& extraDir = wxEmptyString);
1267 // and this function clears all the data from the manager
1270 // Database lookup: all functions return a pointer to wxFileType object
1271 // whose methods may be used to query it for the information you're
1272 // interested in. If the return value is !NULL, caller is responsible for
1274 // get file type from file extension
1275 %new wxFileType *GetFileTypeFromExtension(const wxString& ext);
1277 // get file type from MIME type (in format <category>/<format>)
1278 %new wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
1280 // other operations: return TRUE if there were no errors or FALSE if there
1281 // were some unreckognized entries (the good entries are always read anyhow)
1284 // read in additional file (the standard ones are read automatically)
1285 // in mailcap format (see mimetype.cpp for description)
1287 // 'fallback' parameter may be set to TRUE to avoid overriding the
1288 // settings from other, previously parsed, files by this one: normally,
1289 // the files read most recently would override the older files, but with
1290 // fallback == TRUE this won't happen
1291 bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
1293 // read in additional file in mime.types format
1294 bool ReadMimeTypes(const wxString& filename);
1296 // enumerate all known MIME types
1298 PyObject* EnumAllFileTypes() {
1300 self->EnumAllFileTypes(arr);
1301 return wxArrayString2PyList_helper(arr);
1305 // these functions can be used to provide default values for some of the
1306 // MIME types inside the program itself (you may also use
1307 // ReadMailcap(filenameWithDefaultTypes, TRUE /* use as fallback */) to
1308 // achieve the same goal, but this requires having this info in a file).
1310 void AddFallback(const wxFileTypeInfo& ft);
1313 // create or remove associations
1315 // create a new association using the fields of wxFileTypeInfo (at least
1316 // the MIME type and the extension should be set)
1317 // if the other fields are empty, the existing values should be left alone
1318 %new wxFileType *Associate(const wxFileTypeInfo& ftInfo);
1321 bool Unassociate(wxFileType *ft) ;
1323 // dtor (not virtual, shouldn't be derived from)
1324 ~wxMimeTypesManager();
1332 extern wxMimeTypesManager* wxTheMimeTypesManager;
1338 //----------------------------------------------------------------------
1341 #include <wx/docview.h>
1344 class wxFileHistory : public wxObject
1347 wxFileHistory(int maxFiles = 9);
1351 void AddFileToHistory(const wxString& file);
1352 void RemoveFileFromHistory(int i);
1353 int GetMaxFiles() const;
1354 void UseMenu(wxMenu *menu);
1356 // Remove menu from the list (MDI child may be closing)
1357 void RemoveMenu(wxMenu *menu);
1359 void Load(wxConfigBase& config);
1360 void Save(wxConfigBase& config);
1362 void AddFilesToMenu();
1363 %name(AddFilesToSingleMenu)void AddFilesToMenu(wxMenu* menu);
1366 wxString GetHistoryFile(int i) const;
1368 // A synonym for GetNoHistoryFiles
1369 int GetCount() const;
1370 int GetNoHistoryFiles() const;
1374 //----------------------------------------------------------------------
1375 //----------------------------------------------------------------------
1379 wxPyPtrTypeMap_Add("wxFontEnumerator", "wxPyFontEnumerator");
1380 wxPyPtrTypeMap_Add("wxDragImage", "wxGenericDragImage");
1381 wxPyPtrTypeMap_Add("wxProcess", "wxPyProcess");
1384 //----------------------------------------------------------------------