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 wxWindow* wxGetTopLevelParent(wxWindow *win);
181 //---------------------------------------------------------------------------
184 bool wxResourceAddIdentifier(char* name, int value);
185 void wxResourceClear(void);
186 wxBitmap wxResourceCreateBitmap(char* resource);
187 wxIcon wxResourceCreateIcon(char* resource);
188 wxMenuBar * wxResourceCreateMenuBar(char* resource);
189 int wxResourceGetIdentifier(char* name);
190 bool wxResourceParseData(char* resource, wxResourceTable *table = NULL);
191 bool wxResourceParseFile(char* filename, wxResourceTable *table = NULL);
192 bool wxResourceParseString(char* resource, wxResourceTable *table = NULL);
194 //---------------------------------------------------------------------------
197 // possible values for wxSystemSettings::GetFont() parameter
201 wxSYS_OEM_FIXED_FONT = 10,
202 wxSYS_ANSI_FIXED_FONT,
205 wxSYS_DEVICE_DEFAULT_FONT,
206 wxSYS_DEFAULT_PALETTE,
207 wxSYS_SYSTEM_FIXED_FONT,
208 wxSYS_DEFAULT_GUI_FONT
211 // possible values for wxSystemSettings::GetColour() parameter
215 wxSYS_COLOUR_SCROLLBAR,
216 wxSYS_COLOUR_BACKGROUND,
217 wxSYS_COLOUR_DESKTOP = wxSYS_COLOUR_BACKGROUND,
218 wxSYS_COLOUR_ACTIVECAPTION,
219 wxSYS_COLOUR_INACTIVECAPTION,
222 wxSYS_COLOUR_WINDOWFRAME,
223 wxSYS_COLOUR_MENUTEXT,
224 wxSYS_COLOUR_WINDOWTEXT,
225 wxSYS_COLOUR_CAPTIONTEXT,
226 wxSYS_COLOUR_ACTIVEBORDER,
227 wxSYS_COLOUR_INACTIVEBORDER,
228 wxSYS_COLOUR_APPWORKSPACE,
229 wxSYS_COLOUR_HIGHLIGHT,
230 wxSYS_COLOUR_HIGHLIGHTTEXT,
231 wxSYS_COLOUR_BTNFACE,
232 wxSYS_COLOUR_3DFACE = wxSYS_COLOUR_BTNFACE,
233 wxSYS_COLOUR_BTNSHADOW,
234 wxSYS_COLOUR_3DSHADOW = wxSYS_COLOUR_BTNSHADOW,
235 wxSYS_COLOUR_GRAYTEXT,
236 wxSYS_COLOUR_BTNTEXT,
237 wxSYS_COLOUR_INACTIVECAPTIONTEXT,
238 wxSYS_COLOUR_BTNHIGHLIGHT,
239 wxSYS_COLOUR_BTNHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
240 wxSYS_COLOUR_3DHIGHLIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
241 wxSYS_COLOUR_3DHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
242 wxSYS_COLOUR_3DDKSHADOW,
243 wxSYS_COLOUR_3DLIGHT,
244 wxSYS_COLOUR_INFOTEXT,
246 wxSYS_COLOUR_LISTBOX,
247 wxSYS_COLOUR_HOTLIGHT,
248 wxSYS_COLOUR_GRADIENTACTIVECAPTION,
249 wxSYS_COLOUR_GRADIENTINACTIVECAPTION,
250 wxSYS_COLOUR_MENUHILIGHT,
251 wxSYS_COLOUR_MENUBAR,
256 // possible values for wxSystemSettings::GetMetric() parameter
260 wxSYS_MOUSE_BUTTONS = 1,
271 wxSYS_HSCROLL_ARROW_X,
272 wxSYS_HSCROLL_ARROW_Y,
288 wxSYS_VSCROLL_ARROW_X,
289 wxSYS_VSCROLL_ARROW_Y,
293 wxSYS_NETWORK_PRESENT,
294 wxSYS_PENWINDOWS_PRESENT,
299 // possible values for wxSystemSettings::HasFeature() parameter
302 wxSYS_CAN_DRAW_FRAME_DECORATIONS = 1,
303 wxSYS_CAN_ICONIZE_FRAME
308 class wxSystemSettings {
310 // get a standard system colour
311 static wxColour GetColour(wxSystemColour index);
313 // get a standard system font
314 static wxFont GetFont(wxSystemFont index);
316 // get a system-dependent metric
317 static int GetMetric(wxSystemMetric index);
319 // return true if the port has certain feature
320 static bool HasFeature(wxSystemFeature index);
326 //---------------------------------------------------------------------------
329 class wxToolTip : public wxObject {
331 wxToolTip(const wxString &tip);
333 void SetTip(const wxString& tip);
335 // *** Not in the "public" interface void SetWindow(wxWindow *win);
336 wxWindow *GetWindow();
338 static void Enable(bool flag);
339 static void SetDelay(long milliseconds);
342 //----------------------------------------------------------------------
346 wxCaret(wxWindow* window, const wxSize& size);
351 %name(GetPositionTuple)void GetPosition(int *OUTPUT, int *OUTPUT);
352 wxPoint GetPosition();
353 %name(GetSizeTuple)void GetSize(int *OUTPUT, int *OUTPUT);
355 wxWindow *GetWindow();
356 %name(MoveXY)void Move(int x, int y);
357 void Move(const wxPoint& pt);
358 %name(SetSizeWH) void SetSize(int width, int height);
359 void SetSize(const wxSize& size);
360 void Show(int show = TRUE);
365 int wxCaret_GetBlinkTime() {
366 return wxCaret::GetBlinkTime();
369 void wxCaret_SetBlinkTime(int milliseconds) {
370 wxCaret::SetBlinkTime(milliseconds);
374 //----------------------------------------------------------------------
378 wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR);
382 //----------------------------------------------------------------------
384 class wxWindowDisabler {
386 wxWindowDisabler(wxWindow *winToSkip = NULL);
390 //----------------------------------------------------------------------
392 bool wxSafeYield(wxWindow* win=NULL);
393 void wxPostEvent(wxEvtHandler *dest, wxEvent& event);
398 void wxWakeUpMainThread();
401 void wxMutexGuiEnter();
402 void wxMutexGuiLeave();
405 class wxMutexGuiLocker {
413 bool wxThread_IsMain() {
414 #ifdef WXP_WITH_THREAD
415 return wxThread::IsMain();
422 //----------------------------------------------------------------------
428 // wxTipProvider(size_t currentTip); **** Abstract base class
431 virtual wxString GetTip() = 0;
432 size_t GetCurrentTip();
437 // The C++ version of wxPyTipProvider
439 class wxPyTipProvider : public wxTipProvider {
441 wxPyTipProvider(size_t currentTip)
442 : wxTipProvider(currentTip) {}
444 DEC_PYCALLBACK_STRING__pure(GetTip);
449 IMP_PYCALLBACK_STRING__pure( wxPyTipProvider, wxTipProvider, GetTip);
454 // Now let SWIG know about it
455 class wxPyTipProvider : public wxTipProvider {
457 wxPyTipProvider(size_t currentTip);
462 bool wxShowTip(wxWindow *parent, wxTipProvider *tipProvider, bool showAtStartup = TRUE);
463 %new wxTipProvider * wxCreateFileTipProvider(const wxString& filename, size_t currentTip);
466 //----------------------------------------------------------------------
469 #include <wx/generic/dragimgg.h>
472 %name (wxDragImage) class wxGenericDragImage : public wxObject
476 wxGenericDragImage(const wxBitmap& image,
477 const wxCursor& cursor = wxNullCursor);
478 %name(wxDragIcon)wxGenericDragImage(const wxIcon& image,
479 const wxCursor& cursor = wxNullCursor);
480 %name(wxDragString)wxGenericDragImage(const wxString& str,
481 const wxCursor& cursor = wxNullCursor);
482 %name(wxDragTreeItem)wxGenericDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
483 %name(wxDragListItem)wxGenericDragImage(const wxListCtrl& listCtrl, long id);
485 ~wxGenericDragImage();
487 void SetBackingBitmap(wxBitmap* bitmap);
488 bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
489 bool fullScreen = FALSE, wxRect* rect = NULL);
491 %name(BeginDrag2) bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
492 wxWindow* fullScreenRect);
495 bool Move(const wxPoint& pt);
499 wxRect GetImageRect(const wxPoint& pos) const;
500 bool RedrawImage(const wxPoint& oldPos, const wxPoint& newPos,
501 bool eraseOld, bool drawNew);
505 //----------------------------------------------------------------------
507 class wxPyTimer : public wxObject {
509 wxPyTimer(PyObject* notify);
514 void SetOwner(wxEvtHandler *owner, int id = -1);
515 void Start(int milliseconds=-1, int oneShot=FALSE);
523 // ctor starts the stop watch
526 void Start(long t = 0);
530 // get elapsed time since the last Start() or Pause() in milliseconds
535 //----------------------------------------------------------------------
536 //----------------------------------------------------------------------
541 wxLOG_FatalError, // program can't continue, abort immediately
542 wxLOG_Error, // a serious error, user must be informed about it
543 wxLOG_Warning, // user is normally informed about it but may be ignored
544 wxLOG_Message, // normal message (i.e. normal output of a non GUI app)
545 wxLOG_Info, // informational message (a.k.a. 'Verbose')
546 wxLOG_Status, // informational: might go to the status line of GUI app
547 wxLOG_Debug, // never shown to the user, disabled in release mode
548 wxLOG_Trace, // trace messages are also only enabled in debug mode
549 wxLOG_Progress, // used for progress indicator (not yet)
550 wxLOG_User = 100 // user defined levels start here
559 static bool IsEnabled();
560 static bool EnableLogging(bool doIt = TRUE);
561 static void OnLog(wxLogLevel level, const wxString& szString, int t=0);
563 virtual void Flush();
564 bool HasPendingMessages() const;
566 static void FlushActive();
567 static wxLog *GetActiveTarget();
568 static wxLog *SetActiveTarget(wxLog *pLogger);
570 static void Suspend();
571 static void Resume();
573 static void SetVerbose(bool bVerbose = TRUE);
575 static void DontCreateOnDemand();
576 static void SetTraceMask(wxTraceMask ulMask);
577 static void AddTraceMask(const wxString& str);
578 static void RemoveTraceMask(const wxString& str);
579 static void ClearTraceMasks();
581 static void SetTimestamp(const wxString& ts);
582 static const wxString& GetTimestamp();
584 bool GetVerbose() const;
586 static wxTraceMask GetTraceMask();
587 static bool IsAllowedTraceMask(const wxString& mask);
589 // static void TimeStamp(wxString *str);
591 wxString TimeStamp() {
593 wxLog::TimeStamp(&msg);
601 class wxLogStderr : public wxLog
604 wxLogStderr(/* TODO: FILE *fp = (FILE *) NULL*/);
608 class wxLogTextCtrl : public wxLog
611 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
615 class wxLogGui : public wxLog
621 class wxLogWindow : public wxLog
624 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
625 const wxString& szTitle, // the title of the frame
626 bool bShow = TRUE, // show window immediately?
627 bool bPassToOld = TRUE); // pass log messages to the old target?
629 void Show(bool bShow = TRUE);
630 wxFrame *GetFrame() const;
631 wxLog *GetOldLog() const;
632 bool IsPassingMessages() const;
633 void PassMessages(bool bDoPass);
637 class wxLogChain : public wxLog
640 wxLogChain(wxLog *logger);
641 void SetLog(wxLog *logger);
642 void PassMessages(bool bDoPass);
643 bool IsPassingMessages();
648 unsigned long wxSysErrorCode();
649 const wxString wxSysErrorMsg(unsigned long nErrCode = 0);
650 void wxLogFatalError(const wxString& szFormat);
651 void wxLogError(const wxString& szFormat);
652 void wxLogWarning(const wxString& szFormat);
653 void wxLogMessage(const wxString& szFormat);
654 void wxLogInfo(const wxString& szFormat);
655 void wxLogVerbose(const wxString& szFormat);
656 void wxLogStatus(const wxString& szFormat);
657 %name(wxLogStatusFrame)void wxLogStatus(wxFrame *pFrame, const wxString& szFormat);
658 void wxLogSysError(const wxString& szFormat);
660 // Suspress logging while an instance of this class exists
672 // A wxLog class that can be derived from in wxPython
673 class wxPyLog : public wxLog {
675 wxPyLog() : wxLog() {}
677 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) {
679 wxPyBeginBlockThreads();
680 if ((found = wxPyCBH_findCallback(m_myInst, "DoLog")))
681 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iOi)", level,
682 wx2PyString(szString), t));
683 wxPyEndBlockThreads();
685 wxLog::DoLog(level, szString, t);
688 virtual void DoLogString(const wxChar *szString, time_t t) {
690 wxPyBeginBlockThreads();
691 if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString")))
692 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)",
693 wx2PyString(szString), t));
694 wxPyEndBlockThreads();
696 wxLog::DoLogString(szString, t);
703 // Now tell SWIG about it
704 class wxPyLog : public wxLog {
707 void _setCallbackInfo(PyObject* self, PyObject* _class);
708 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyLog)"
709 %addmethods { void Destroy() { delete self; } }
714 //----------------------------------------------------------------------
723 class wxProcessEvent : public wxEvent {
725 wxProcessEvent(int id = 0, int pid = 0, int exitcode = 0);
728 int m_pid, m_exitcode;
734 %{ // C++ version of wxProcess derived class
736 class wxPyProcess : public wxProcess {
738 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1)
739 : wxProcess(parent, id)
742 DEC_PYCALLBACK_VOID_INTINT(OnTerminate);
747 IMP_PYCALLBACK_VOID_INTINT( wxPyProcess, wxProcess, OnTerminate);
752 %name(wxProcess)class wxPyProcess : public wxEvtHandler {
754 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1);
755 %addmethods { void Destroy() { delete self; } }
757 void _setCallbackInfo(PyObject* self, PyObject* _class);
758 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxProcess)"
760 void base_OnTerminate(int pid, int status);
766 wxInputStream *GetInputStream();
767 wxInputStream *GetErrorStream();
768 wxOutputStream *GetOutputStream();
776 // execute the process asynchronously
779 // execute it synchronously, i.e. wait until it finishes
782 // under Windows, don't hide the child even if it's IO is redirected (this
783 // is done by default)
786 // under Unix, if the process is the group leader then killing -pid kills
787 // all children as well as pid
788 wxEXEC_MAKE_GROUP_LEADER = 4
792 long wxExecute(const wxString& command,
793 int flags = wxEXEC_ASYNC,
794 wxPyProcess *process = NULL);
796 //----------------------------------------------------------------------
799 #if !wxUSE_JOYSTICK && !defined(__WXMSW__)
800 // A C++ stub class for wxJoystick for platforms that don't have it.
801 class wxJoystick : public wxObject {
803 wxJoystick(int joystick = wxJOYSTICK1) {
804 wxPyBeginBlockThreads();
805 PyErr_SetString(PyExc_NotImplementedError, "wxJoystick is not available on this platform.");
806 wxPyEndBlockThreads();
808 wxPoint GetPosition() { return wxPoint(-1,-1); }
809 int GetZPosition() { return -1; }
810 int GetButtonState() { return -1; }
811 int GetPOVPosition() { return -1; }
812 int GetPOVCTSPosition() { return -1; }
813 int GetRudderPosition() { return -1; }
814 int GetUPosition() { return -1; }
815 int GetVPosition() { return -1; }
816 int GetMovementThreshold() { return -1; }
817 void SetMovementThreshold(int threshold) {}
819 bool IsOk(void) { return FALSE; }
820 int GetNumberJoysticks() { return -1; }
821 int GetManufacturerId() { return -1; }
822 int GetProductId() { return -1; }
823 wxString GetProductName() { return ""; }
824 int GetXMin() { return -1; }
825 int GetYMin() { return -1; }
826 int GetZMin() { return -1; }
827 int GetXMax() { return -1; }
828 int GetYMax() { return -1; }
829 int GetZMax() { return -1; }
830 int GetNumberButtons() { return -1; }
831 int GetNumberAxes() { return -1; }
832 int GetMaxButtons() { return -1; }
833 int GetMaxAxes() { return -1; }
834 int GetPollingMin() { return -1; }
835 int GetPollingMax() { return -1; }
836 int GetRudderMin() { return -1; }
837 int GetRudderMax() { return -1; }
838 int GetUMin() { return -1; }
839 int GetUMax() { return -1; }
840 int GetVMin() { return -1; }
841 int GetVMax() { return -1; }
843 bool HasRudder() { return FALSE; }
844 bool HasZ() { return FALSE; }
845 bool HasU() { return FALSE; }
846 bool HasV() { return FALSE; }
847 bool HasPOV() { return FALSE; }
848 bool HasPOV4Dir() { return FALSE; }
849 bool HasPOVCTS() { return FALSE; }
851 bool SetCapture(wxWindow* win, int pollingFreq = 0) { return FALSE; }
852 bool ReleaseCapture() { return FALSE; }
858 class wxJoystick : public wxObject {
860 wxJoystick(int joystick = wxJOYSTICK1);
863 wxPoint GetPosition();
865 int GetButtonState();
866 int GetPOVPosition();
867 int GetPOVCTSPosition();
868 int GetRudderPosition();
871 int GetMovementThreshold();
872 void SetMovementThreshold(int threshold) ;
875 int GetNumberJoysticks();
876 int GetManufacturerId();
878 wxString GetProductName();
885 int GetNumberButtons();
906 bool SetCapture(wxWindow* win, int pollingFreq = 0);
907 bool ReleaseCapture();
910 //----------------------------------------------------------------------
914 // A C++ stub class for wxWave for platforms that don't have it.
915 class wxWave : public wxObject
918 wxWave(const wxString& fileName, bool isResource = FALSE) {
919 wxPyBeginBlockThreads();
920 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
921 wxPyEndBlockThreads();
923 wxWave(int size, const wxByte* data) {
924 wxPyBeginBlockThreads();
925 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
926 wxPyEndBlockThreads();
931 bool IsOk() const { return FALSE; }
932 bool Play(bool async = TRUE, bool looped = FALSE) const { return FALSE; }
938 class wxWave : public wxObject
941 wxWave(const wxString& fileName, bool isResource = FALSE);
945 bool Play(bool async = TRUE, bool looped = FALSE) const;
948 %new wxWave* wxWaveData(const wxString& data);
949 %{ // Implementations of some alternate "constructors"
950 wxWave* wxWaveData(const wxString& data) {
951 return new wxWave(data.Len(), (wxByte*)data.c_str());
956 //----------------------------------------------------------------------
960 wxMAILCAP_STANDARD = 1,
961 wxMAILCAP_NETSCAPE = 2,
975 wxFileTypeInfo(const char* mimeType,
977 const char* printCmd,
981 // the array elements correspond to the parameters of the ctor above in
983 %name(wxFileTypeInfoSequence)wxFileTypeInfo(const wxArrayString& sArray);
985 // invalid item - use this to terminate the array passed to
986 // wxMimeTypesManager::AddFallbacks
987 %name(wxNullFileTypeInfo)wxFileTypeInfo();
990 // test if this object can be used
991 bool IsValid() const;
995 void SetIcon(const wxString& iconFile, int iconIndex = 0);
997 // set the short desc
998 void SetShortDesc(const wxString& shortDesc);
1001 // get the MIME type
1002 const wxString& GetMimeType() const;
1003 // get the open command
1004 const wxString& GetOpenCommand() const;
1005 // get the print command
1006 const wxString& GetPrintCommand() const;
1007 // get the short description (only used under Win32 so far)
1008 const wxString& GetShortDesc() const;
1009 // get the long, user visible description
1010 const wxString& GetDescription() const;
1013 // get the array of all extensions
1014 //const wxArrayString& GetExtensions() const;
1016 PyObject* GetExtensions() {
1017 wxArrayString& arr = (wxArrayString&)self->GetExtensions();
1018 return wxArrayString2PyList_helper(arr);
1022 int GetExtensionsCount() const;
1024 // get the icon info
1025 const wxString& GetIconFile() const;
1026 int GetIconIndex() const;
1036 // TODO: Make a wxPyMessageParameters with virtual GetParamValue...
1038 // An object of this class must be passed to Get{Open|Print}Command. The
1039 // default implementation is trivial and doesn't know anything at all about
1040 // parameters, only filename and MIME type are used (so it's probably ok for
1041 // Windows where %{param} is not used anyhow)
1042 class MessageParameters
1046 MessageParameters(const wxString& filename=wxPyEmptyString,
1047 const wxString& mimetype=wxPyEmptyString);
1049 // accessors (called by GetOpenCommand)
1051 const wxString& GetFileName() const;
1053 const wxString& GetMimeType() const;;
1055 // override this function in derived class
1056 virtual wxString GetParamValue(const wxString& name) const;
1058 // virtual dtor as in any base class
1059 virtual ~MessageParameters();
1063 // ctor from static data
1064 wxFileType(const wxFileTypeInfo& ftInfo);
1066 // return the MIME type for this file type
1068 PyObject* GetMimeType() {
1070 if (self->GetMimeType(&str)) {
1072 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1074 return PyString_FromStringAndSize(str.c_str(), str.Len());
1080 PyObject* GetMimeTypes() {
1082 if (self->GetMimeTypes(arr))
1083 return wxArrayString2PyList_helper(arr);
1090 // Get all extensions associated with this file type
1092 PyObject* GetExtensions() {
1094 if (self->GetExtensions(arr))
1095 return wxArrayString2PyList_helper(arr);
1103 // Get the icon corresponding to this file type
1104 %new wxIcon* GetIcon() {
1106 if (self->GetIcon(&icon))
1107 return new wxIcon(icon);
1112 // Get the icon corresponding to this file type, the name of the file
1113 // where this icon resides, and its index in this file if applicable.
1114 PyObject* GetIconInfo() {
1118 if (self->GetIcon(&icon, &iconFile, &iconIndex)) {
1119 wxPyBeginBlockThreads();
1120 PyObject* tuple = PyTuple_New(3);
1121 PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(icon),
1124 PyTuple_SetItem(tuple, 1, PyUnicode_FromUnicode(iconFile.c_str(), iconFile.Len()));
1126 PyTuple_SetItem(tuple, 1, PyString_FromStringAndSize(iconFile.c_str(), iconFile.Len()));
1128 PyTuple_SetItem(tuple, 2, PyInt_FromLong(iconIndex));
1129 wxPyEndBlockThreads();
1138 // get a brief file type description ("*.txt" => "text document")
1139 PyObject* GetDescription() {
1141 if (self->GetDescription(&str)) {
1143 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1145 return PyString_FromStringAndSize(str.c_str(), str.Len());
1153 // get the command to open/execute the file of given type
1155 PyObject* GetOpenCommand(const wxString& filename,
1156 const wxString& mimetype=wxPyEmptyString) {
1158 if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype))) {
1160 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1162 return PyString_FromStringAndSize(str.c_str(), str.Len());
1170 // get the command to print the file of given type
1172 PyObject* GetPrintCommand(const wxString& filename,
1173 const wxString& mimetype=wxPyEmptyString) {
1175 if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype))) {
1177 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1179 return PyString_FromStringAndSize(str.c_str(), str.Len());
1187 // Get all commands defined for this file type
1189 PyObject* GetAllCommands(const wxString& filename,
1190 const wxString& mimetype=wxPyEmptyString) {
1191 wxArrayString verbs;
1192 wxArrayString commands;
1193 if (self->GetAllCommands(&verbs, &commands,
1194 wxFileType::MessageParameters(filename, mimetype))) {
1195 wxPyBeginBlockThreads();
1196 PyObject* tuple = PyTuple_New(2);
1197 PyTuple_SetItem(tuple, 0, wxArrayString2PyList_helper(verbs));
1198 PyTuple_SetItem(tuple, 1, wxArrayString2PyList_helper(commands));
1199 wxPyEndBlockThreads();
1208 // set an arbitrary command, ask confirmation if it already exists and
1209 // overwriteprompt is TRUE
1210 bool SetCommand(const wxString& cmd, const wxString& verb,
1211 bool overwriteprompt = TRUE);
1213 bool SetDefaultIcon(const wxString& cmd = wxPyEmptyString, int index = 0);
1216 // remove the association for this filetype from the system MIME database:
1217 // notice that it will only work if the association is defined in the user
1218 // file/registry part, we will never modify the system-wide settings
1222 // expand a string in the format of GetOpenCommand (which may contain
1223 // '%s' and '%t' format specificators for the file name and mime type
1224 // and %{param} constructions).
1225 static wxString ExpandCommand(const wxString& command,
1226 const MessageParameters& params);
1228 // dtor (not virtual, shouldn't be derived from)
1236 class wxMimeTypesManager
1239 // static helper functions
1240 // -----------------------
1242 // check if the given MIME type is the same as the other one: the
1243 // second argument may contain wildcards ('*'), but not the first. If
1244 // the types are equal or if the mimeType matches wildcard the function
1245 // returns TRUE, otherwise it returns FALSE
1246 static bool IsOfType(const wxString& mimeType, const wxString& wildcard);
1249 wxMimeTypesManager();
1251 // loads data from standard files according to the mailcap styles
1252 // specified: this is a bitwise OR of wxMailcapStyle values
1254 // use the extraDir parameter if you want to look for files in another
1256 void Initialize(int mailcapStyle = wxMAILCAP_STANDARD,
1257 const wxString& extraDir = wxPyEmptyString);
1259 // and this function clears all the data from the manager
1262 // Database lookup: all functions return a pointer to wxFileType object
1263 // whose methods may be used to query it for the information you're
1264 // interested in. If the return value is !NULL, caller is responsible for
1266 // get file type from file extension
1267 %new wxFileType *GetFileTypeFromExtension(const wxString& ext);
1269 // get file type from MIME type (in format <category>/<format>)
1270 %new wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
1272 // other operations: return TRUE if there were no errors or FALSE if there
1273 // were some unreckognized entries (the good entries are always read anyhow)
1276 // read in additional file (the standard ones are read automatically)
1277 // in mailcap format (see mimetype.cpp for description)
1279 // 'fallback' parameter may be set to TRUE to avoid overriding the
1280 // settings from other, previously parsed, files by this one: normally,
1281 // the files read most recently would override the older files, but with
1282 // fallback == TRUE this won't happen
1283 bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
1285 // read in additional file in mime.types format
1286 bool ReadMimeTypes(const wxString& filename);
1288 // enumerate all known MIME types
1290 PyObject* EnumAllFileTypes() {
1292 self->EnumAllFileTypes(arr);
1293 return wxArrayString2PyList_helper(arr);
1297 // these functions can be used to provide default values for some of the
1298 // MIME types inside the program itself (you may also use
1299 // ReadMailcap(filenameWithDefaultTypes, TRUE /* use as fallback */) to
1300 // achieve the same goal, but this requires having this info in a file).
1302 void AddFallback(const wxFileTypeInfo& ft);
1305 // create or remove associations
1307 // create a new association using the fields of wxFileTypeInfo (at least
1308 // the MIME type and the extension should be set)
1309 // if the other fields are empty, the existing values should be left alone
1310 %new wxFileType *Associate(const wxFileTypeInfo& ftInfo);
1313 bool Unassociate(wxFileType *ft) ;
1315 // dtor (not virtual, shouldn't be derived from)
1316 ~wxMimeTypesManager();
1324 extern wxMimeTypesManager* wxTheMimeTypesManager;
1330 //----------------------------------------------------------------------
1333 #include <wx/docview.h>
1336 class wxFileHistory : public wxObject
1339 wxFileHistory(int maxFiles = 9);
1343 void AddFileToHistory(const wxString& file);
1344 void RemoveFileFromHistory(int i);
1345 int GetMaxFiles() const;
1346 void UseMenu(wxMenu *menu);
1348 // Remove menu from the list (MDI child may be closing)
1349 void RemoveMenu(wxMenu *menu);
1351 void Load(wxConfigBase& config);
1352 void Save(wxConfigBase& config);
1354 void AddFilesToMenu();
1355 %name(AddFilesToThisMenu)void AddFilesToMenu(wxMenu* menu);
1358 wxString GetHistoryFile(int i) const;
1360 // A synonym for GetNoHistoryFiles
1361 int GetCount() const;
1362 int GetNoHistoryFiles() const;
1366 //----------------------------------------------------------------------
1367 //----------------------------------------------------------------------
1371 wxPyPtrTypeMap_Add("wxDragImage", "wxGenericDragImage");
1372 wxPyPtrTypeMap_Add("wxProcess", "wxPyProcess");
1375 //----------------------------------------------------------------------