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 = wxDD_DEFAULT_STYLE,
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
306 // values for different screen designs
309 wxSYS_SCREEN_NONE = 0, // not yet defined
310 wxSYS_SCREEN_DESKTOP, // >= 800x600
311 wxSYS_SCREEN_SMALL, // >= 640x480
312 wxSYS_SCREEN_PDA, // >= 320x240
313 wxSYS_SCREEN_TINY // <
317 class wxSystemSettings {
319 // get a standard system colour
320 static wxColour GetColour(wxSystemColour index);
322 // get a standard system font
323 static wxFont GetFont(wxSystemFont index);
325 // get a system-dependent metric
326 static int GetMetric(wxSystemMetric index);
328 // return true if the port has certain feature
329 static bool HasFeature(wxSystemFeature index);
331 // // Get system screen design (desktop, pda, ..) used for
332 // // laying out various dialogs.
333 // static wxSystemScreen GetScreen();
335 // // Override default.
336 // static void SetScreen( wxSystemScreen screen );
342 //---------------------------------------------------------------------------
345 class wxToolTip : public wxObject {
347 wxToolTip(const wxString &tip);
349 void SetTip(const wxString& tip);
351 // *** Not in the "public" interface void SetWindow(wxWindow *win);
352 wxWindow *GetWindow();
354 static void Enable(bool flag);
355 static void SetDelay(long milliseconds);
358 //----------------------------------------------------------------------
362 wxCaret(wxWindow* window, const wxSize& size);
367 %name(GetPositionTuple)void GetPosition(int *OUTPUT, int *OUTPUT);
368 wxPoint GetPosition();
369 %name(GetSizeTuple)void GetSize(int *OUTPUT, int *OUTPUT);
371 wxWindow *GetWindow();
372 %name(MoveXY)void Move(int x, int y);
373 void Move(const wxPoint& pt);
374 %name(SetSizeWH) void SetSize(int width, int height);
375 void SetSize(const wxSize& size);
376 void Show(int show = TRUE);
381 int wxCaret_GetBlinkTime() {
382 return wxCaret::GetBlinkTime();
385 void wxCaret_SetBlinkTime(int milliseconds) {
386 wxCaret::SetBlinkTime(milliseconds);
390 //----------------------------------------------------------------------
394 wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR);
398 //----------------------------------------------------------------------
400 class wxWindowDisabler {
402 wxWindowDisabler(wxWindow *winToSkip = NULL);
406 //----------------------------------------------------------------------
408 bool wxSafeYield(wxWindow* win=NULL);
409 void wxPostEvent(wxEvtHandler *dest, wxEvent& event);
414 void wxWakeUpMainThread();
417 void wxMutexGuiEnter();
418 void wxMutexGuiLeave();
421 class wxMutexGuiLocker {
429 bool wxThread_IsMain() {
430 #ifdef WXP_WITH_THREAD
431 return wxThread::IsMain();
438 //----------------------------------------------------------------------
444 // wxTipProvider(size_t currentTip); **** Abstract base class
447 virtual wxString GetTip() = 0;
448 size_t GetCurrentTip();
453 // The C++ version of wxPyTipProvider
455 class wxPyTipProvider : public wxTipProvider {
457 wxPyTipProvider(size_t currentTip)
458 : wxTipProvider(currentTip) {}
460 DEC_PYCALLBACK_STRING__pure(GetTip);
465 IMP_PYCALLBACK_STRING__pure( wxPyTipProvider, wxTipProvider, GetTip);
470 // Now let SWIG know about it
471 class wxPyTipProvider : public wxTipProvider {
473 wxPyTipProvider(size_t currentTip);
478 bool wxShowTip(wxWindow *parent, wxTipProvider *tipProvider, bool showAtStartup = TRUE);
479 %new wxTipProvider * wxCreateFileTipProvider(const wxString& filename, size_t currentTip);
482 //----------------------------------------------------------------------
485 #include <wx/generic/dragimgg.h>
488 %name (wxDragImage) class wxGenericDragImage : public wxObject
492 wxGenericDragImage(const wxBitmap& image,
493 const wxCursor& cursor = wxNullCursor);
494 %name(wxDragIcon)wxGenericDragImage(const wxIcon& image,
495 const wxCursor& cursor = wxNullCursor);
496 %name(wxDragString)wxGenericDragImage(const wxString& str,
497 const wxCursor& cursor = wxNullCursor);
498 %name(wxDragTreeItem)wxGenericDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
499 %name(wxDragListItem)wxGenericDragImage(const wxListCtrl& listCtrl, long id);
501 ~wxGenericDragImage();
503 void SetBackingBitmap(wxBitmap* bitmap);
504 bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
505 bool fullScreen = FALSE, wxRect* rect = NULL);
507 %name(BeginDrag2) bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
508 wxWindow* fullScreenRect);
511 bool Move(const wxPoint& pt);
515 wxRect GetImageRect(const wxPoint& pos) const;
516 bool RedrawImage(const wxPoint& oldPos, const wxPoint& newPos,
517 bool eraseOld, bool drawNew);
521 //----------------------------------------------------------------------
523 class wxPyTimer : public wxObject {
525 wxPyTimer(PyObject* notify);
530 void SetOwner(wxEvtHandler *owner, int id = -1);
531 void Start(int milliseconds=-1, int oneShot=FALSE);
539 // ctor starts the stop watch
542 void Start(long t = 0);
546 // get elapsed time since the last Start() or Pause() in milliseconds
551 //----------------------------------------------------------------------
552 //----------------------------------------------------------------------
557 wxLOG_FatalError, // program can't continue, abort immediately
558 wxLOG_Error, // a serious error, user must be informed about it
559 wxLOG_Warning, // user is normally informed about it but may be ignored
560 wxLOG_Message, // normal message (i.e. normal output of a non GUI app)
561 wxLOG_Info, // informational message (a.k.a. 'Verbose')
562 wxLOG_Status, // informational: might go to the status line of GUI app
563 wxLOG_Debug, // never shown to the user, disabled in release mode
564 wxLOG_Trace, // trace messages are also only enabled in debug mode
565 wxLOG_Progress, // used for progress indicator (not yet)
566 wxLOG_User = 100 // user defined levels start here
575 static bool IsEnabled();
576 static bool EnableLogging(bool doIt = TRUE);
577 static void OnLog(wxLogLevel level, const wxString& szString, int t=0);
579 virtual void Flush();
580 bool HasPendingMessages() const;
582 static void FlushActive();
583 static wxLog *GetActiveTarget();
584 static wxLog *SetActiveTarget(wxLog *pLogger);
586 static void Suspend();
587 static void Resume();
589 static void SetVerbose(bool bVerbose = TRUE);
591 static void DontCreateOnDemand();
592 static void SetTraceMask(wxTraceMask ulMask);
593 static void AddTraceMask(const wxString& str);
594 static void RemoveTraceMask(const wxString& str);
595 static void ClearTraceMasks();
597 static void SetTimestamp(const wxString& ts);
598 static const wxString& GetTimestamp();
600 bool GetVerbose() const;
602 static wxTraceMask GetTraceMask();
603 static bool IsAllowedTraceMask(const wxString& mask);
605 // static void TimeStamp(wxString *str);
607 wxString TimeStamp() {
609 wxLog::TimeStamp(&msg);
617 class wxLogStderr : public wxLog
620 wxLogStderr(/* TODO: FILE *fp = (FILE *) NULL*/);
624 class wxLogTextCtrl : public wxLog
627 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
631 class wxLogGui : public wxLog
637 class wxLogWindow : public wxLog
640 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
641 const wxString& szTitle, // the title of the frame
642 bool bShow = TRUE, // show window immediately?
643 bool bPassToOld = TRUE); // pass log messages to the old target?
645 void Show(bool bShow = TRUE);
646 wxFrame *GetFrame() const;
647 wxLog *GetOldLog() const;
648 bool IsPassingMessages() const;
649 void PassMessages(bool bDoPass);
653 class wxLogChain : public wxLog
656 wxLogChain(wxLog *logger);
657 void SetLog(wxLog *logger);
658 void PassMessages(bool bDoPass);
659 bool IsPassingMessages();
664 unsigned long wxSysErrorCode();
665 const wxString wxSysErrorMsg(unsigned long nErrCode = 0);
666 void wxLogFatalError(const wxString& szFormat);
667 void wxLogError(const wxString& szFormat);
668 void wxLogWarning(const wxString& szFormat);
669 void wxLogMessage(const wxString& szFormat);
670 void wxLogInfo(const wxString& szFormat);
671 void wxLogVerbose(const wxString& szFormat);
672 void wxLogStatus(const wxString& szFormat);
673 %name(wxLogStatusFrame)void wxLogStatus(wxFrame *pFrame, const wxString& szFormat);
674 void wxLogSysError(const wxString& szFormat);
676 // Suspress logging while an instance of this class exists
688 // A wxLog class that can be derived from in wxPython
689 class wxPyLog : public wxLog {
691 wxPyLog() : wxLog() {}
693 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) {
695 wxPyBeginBlockThreads();
696 if ((found = wxPyCBH_findCallback(m_myInst, "DoLog")))
697 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iOi)", level,
698 wx2PyString(szString), t));
699 wxPyEndBlockThreads();
701 wxLog::DoLog(level, szString, t);
704 virtual void DoLogString(const wxChar *szString, time_t t) {
706 wxPyBeginBlockThreads();
707 if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString")))
708 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)",
709 wx2PyString(szString), t));
710 wxPyEndBlockThreads();
712 wxLog::DoLogString(szString, t);
719 // Now tell SWIG about it
720 class wxPyLog : public wxLog {
723 void _setCallbackInfo(PyObject* self, PyObject* _class);
724 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyLog)"
725 %addmethods { void Destroy() { delete self; } }
730 //----------------------------------------------------------------------
739 class wxProcessEvent : public wxEvent {
741 wxProcessEvent(int id = 0, int pid = 0, int exitcode = 0);
744 int m_pid, m_exitcode;
750 %{ // C++ version of wxProcess derived class
752 class wxPyProcess : public wxProcess {
754 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1)
755 : wxProcess(parent, id)
758 DEC_PYCALLBACK_VOID_INTINT(OnTerminate);
763 IMP_PYCALLBACK_VOID_INTINT( wxPyProcess, wxProcess, OnTerminate);
768 %name(wxProcess)class wxPyProcess : public wxEvtHandler {
770 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1);
771 %addmethods { void Destroy() { delete self; } }
773 void _setCallbackInfo(PyObject* self, PyObject* _class);
774 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxProcess)"
776 void base_OnTerminate(int pid, int status);
782 wxInputStream *GetInputStream();
783 wxInputStream *GetErrorStream();
784 wxOutputStream *GetOutputStream();
792 // execute the process asynchronously
795 // execute it synchronously, i.e. wait until it finishes
798 // under Windows, don't hide the child even if it's IO is redirected (this
799 // is done by default)
802 // under Unix, if the process is the group leader then killing -pid kills
803 // all children as well as pid
804 wxEXEC_MAKE_GROUP_LEADER = 4
808 long wxExecute(const wxString& command,
809 int flags = wxEXEC_ASYNC,
810 wxPyProcess *process = NULL);
812 //----------------------------------------------------------------------
815 #if !wxUSE_JOYSTICK && !defined(__WXMSW__)
816 // A C++ stub class for wxJoystick for platforms that don't have it.
817 class wxJoystick : public wxObject {
819 wxJoystick(int joystick = wxJOYSTICK1) {
820 wxPyBeginBlockThreads();
821 PyErr_SetString(PyExc_NotImplementedError, "wxJoystick is not available on this platform.");
822 wxPyEndBlockThreads();
824 wxPoint GetPosition() { return wxPoint(-1,-1); }
825 int GetZPosition() { return -1; }
826 int GetButtonState() { return -1; }
827 int GetPOVPosition() { return -1; }
828 int GetPOVCTSPosition() { return -1; }
829 int GetRudderPosition() { return -1; }
830 int GetUPosition() { return -1; }
831 int GetVPosition() { return -1; }
832 int GetMovementThreshold() { return -1; }
833 void SetMovementThreshold(int threshold) {}
835 bool IsOk(void) { return FALSE; }
836 int GetNumberJoysticks() { return -1; }
837 int GetManufacturerId() { return -1; }
838 int GetProductId() { return -1; }
839 wxString GetProductName() { return ""; }
840 int GetXMin() { return -1; }
841 int GetYMin() { return -1; }
842 int GetZMin() { return -1; }
843 int GetXMax() { return -1; }
844 int GetYMax() { return -1; }
845 int GetZMax() { return -1; }
846 int GetNumberButtons() { return -1; }
847 int GetNumberAxes() { return -1; }
848 int GetMaxButtons() { return -1; }
849 int GetMaxAxes() { return -1; }
850 int GetPollingMin() { return -1; }
851 int GetPollingMax() { return -1; }
852 int GetRudderMin() { return -1; }
853 int GetRudderMax() { return -1; }
854 int GetUMin() { return -1; }
855 int GetUMax() { return -1; }
856 int GetVMin() { return -1; }
857 int GetVMax() { return -1; }
859 bool HasRudder() { return FALSE; }
860 bool HasZ() { return FALSE; }
861 bool HasU() { return FALSE; }
862 bool HasV() { return FALSE; }
863 bool HasPOV() { return FALSE; }
864 bool HasPOV4Dir() { return FALSE; }
865 bool HasPOVCTS() { return FALSE; }
867 bool SetCapture(wxWindow* win, int pollingFreq = 0) { return FALSE; }
868 bool ReleaseCapture() { return FALSE; }
874 class wxJoystick : public wxObject {
876 wxJoystick(int joystick = wxJOYSTICK1);
879 wxPoint GetPosition();
881 int GetButtonState();
882 int GetPOVPosition();
883 int GetPOVCTSPosition();
884 int GetRudderPosition();
887 int GetMovementThreshold();
888 void SetMovementThreshold(int threshold) ;
891 int GetNumberJoysticks();
892 int GetManufacturerId();
894 wxString GetProductName();
901 int GetNumberButtons();
922 bool SetCapture(wxWindow* win, int pollingFreq = 0);
923 bool ReleaseCapture();
926 //----------------------------------------------------------------------
930 // A C++ stub class for wxWave for platforms that don't have it.
931 class wxWave : public wxObject
934 wxWave(const wxString& fileName, bool isResource = FALSE) {
935 wxPyBeginBlockThreads();
936 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
937 wxPyEndBlockThreads();
939 wxWave(int size, const wxByte* data) {
940 wxPyBeginBlockThreads();
941 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
942 wxPyEndBlockThreads();
947 bool IsOk() const { return FALSE; }
948 bool Play(bool async = TRUE, bool looped = FALSE) const { return FALSE; }
954 class wxWave : public wxObject
957 wxWave(const wxString& fileName, bool isResource = FALSE);
961 bool Play(bool async = TRUE, bool looped = FALSE) const;
964 %new wxWave* wxWaveData(const wxString& data);
965 %{ // Implementations of some alternate "constructors"
966 wxWave* wxWaveData(const wxString& data) {
967 return new wxWave(data.Len(), (wxByte*)data.c_str());
972 //----------------------------------------------------------------------
976 wxMAILCAP_STANDARD = 1,
977 wxMAILCAP_NETSCAPE = 2,
991 wxFileTypeInfo(const char* mimeType,
993 const char* printCmd,
997 // the array elements correspond to the parameters of the ctor above in
999 %name(wxFileTypeInfoSequence)wxFileTypeInfo(const wxArrayString& sArray);
1001 // invalid item - use this to terminate the array passed to
1002 // wxMimeTypesManager::AddFallbacks
1003 %name(wxNullFileTypeInfo)wxFileTypeInfo();
1006 // test if this object can be used
1007 bool IsValid() const;
1010 // set the icon info
1011 void SetIcon(const wxString& iconFile, int iconIndex = 0);
1013 // set the short desc
1014 void SetShortDesc(const wxString& shortDesc);
1017 // get the MIME type
1018 const wxString& GetMimeType() const;
1019 // get the open command
1020 const wxString& GetOpenCommand() const;
1021 // get the print command
1022 const wxString& GetPrintCommand() const;
1023 // get the short description (only used under Win32 so far)
1024 const wxString& GetShortDesc() const;
1025 // get the long, user visible description
1026 const wxString& GetDescription() const;
1029 // get the array of all extensions
1030 //const wxArrayString& GetExtensions() const;
1032 PyObject* GetExtensions() {
1033 wxArrayString& arr = (wxArrayString&)self->GetExtensions();
1034 return wxArrayString2PyList_helper(arr);
1038 int GetExtensionsCount() const;
1040 // get the icon info
1041 const wxString& GetIconFile() const;
1042 int GetIconIndex() const;
1052 // TODO: Make a wxPyMessageParameters with virtual GetParamValue...
1054 // An object of this class must be passed to Get{Open|Print}Command. The
1055 // default implementation is trivial and doesn't know anything at all about
1056 // parameters, only filename and MIME type are used (so it's probably ok for
1057 // Windows where %{param} is not used anyhow)
1058 class MessageParameters
1062 MessageParameters(const wxString& filename=wxPyEmptyString,
1063 const wxString& mimetype=wxPyEmptyString);
1065 // accessors (called by GetOpenCommand)
1067 const wxString& GetFileName() const;
1069 const wxString& GetMimeType() const;;
1071 // override this function in derived class
1072 virtual wxString GetParamValue(const wxString& name) const;
1074 // virtual dtor as in any base class
1075 virtual ~MessageParameters();
1079 // ctor from static data
1080 wxFileType(const wxFileTypeInfo& ftInfo);
1082 // return the MIME type for this file type
1084 PyObject* GetMimeType() {
1086 if (self->GetMimeType(&str)) {
1088 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1090 return PyString_FromStringAndSize(str.c_str(), str.Len());
1096 PyObject* GetMimeTypes() {
1098 if (self->GetMimeTypes(arr))
1099 return wxArrayString2PyList_helper(arr);
1106 // Get all extensions associated with this file type
1108 PyObject* GetExtensions() {
1110 if (self->GetExtensions(arr))
1111 return wxArrayString2PyList_helper(arr);
1119 // Get the icon corresponding to this file type
1120 %new wxIcon* GetIcon() {
1122 if (self->GetIcon(&icon))
1123 return new wxIcon(icon);
1128 // Get the icon corresponding to this file type, the name of the file
1129 // where this icon resides, and its index in this file if applicable.
1130 PyObject* GetIconInfo() {
1134 if (self->GetIcon(&icon, &iconFile, &iconIndex)) {
1135 wxPyBeginBlockThreads();
1136 PyObject* tuple = PyTuple_New(3);
1137 PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(icon),
1140 PyTuple_SetItem(tuple, 1, PyUnicode_FromUnicode(iconFile.c_str(), iconFile.Len()));
1142 PyTuple_SetItem(tuple, 1, PyString_FromStringAndSize(iconFile.c_str(), iconFile.Len()));
1144 PyTuple_SetItem(tuple, 2, PyInt_FromLong(iconIndex));
1145 wxPyEndBlockThreads();
1154 // get a brief file type description ("*.txt" => "text document")
1155 PyObject* GetDescription() {
1157 if (self->GetDescription(&str)) {
1159 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1161 return PyString_FromStringAndSize(str.c_str(), str.Len());
1169 // get the command to open/execute the file of given type
1171 PyObject* GetOpenCommand(const wxString& filename,
1172 const wxString& mimetype=wxPyEmptyString) {
1174 if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype))) {
1176 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1178 return PyString_FromStringAndSize(str.c_str(), str.Len());
1186 // get the command to print the file of given type
1188 PyObject* GetPrintCommand(const wxString& filename,
1189 const wxString& mimetype=wxPyEmptyString) {
1191 if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype))) {
1193 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1195 return PyString_FromStringAndSize(str.c_str(), str.Len());
1203 // Get all commands defined for this file type
1205 PyObject* GetAllCommands(const wxString& filename,
1206 const wxString& mimetype=wxPyEmptyString) {
1207 wxArrayString verbs;
1208 wxArrayString commands;
1209 if (self->GetAllCommands(&verbs, &commands,
1210 wxFileType::MessageParameters(filename, mimetype))) {
1211 wxPyBeginBlockThreads();
1212 PyObject* tuple = PyTuple_New(2);
1213 PyTuple_SetItem(tuple, 0, wxArrayString2PyList_helper(verbs));
1214 PyTuple_SetItem(tuple, 1, wxArrayString2PyList_helper(commands));
1215 wxPyEndBlockThreads();
1224 // set an arbitrary command, ask confirmation if it already exists and
1225 // overwriteprompt is TRUE
1226 bool SetCommand(const wxString& cmd, const wxString& verb,
1227 bool overwriteprompt = TRUE);
1229 bool SetDefaultIcon(const wxString& cmd = wxPyEmptyString, int index = 0);
1232 // remove the association for this filetype from the system MIME database:
1233 // notice that it will only work if the association is defined in the user
1234 // file/registry part, we will never modify the system-wide settings
1238 // expand a string in the format of GetOpenCommand (which may contain
1239 // '%s' and '%t' format specificators for the file name and mime type
1240 // and %{param} constructions).
1241 static wxString ExpandCommand(const wxString& command,
1242 const MessageParameters& params);
1244 // dtor (not virtual, shouldn't be derived from)
1252 class wxMimeTypesManager
1255 // static helper functions
1256 // -----------------------
1258 // check if the given MIME type is the same as the other one: the
1259 // second argument may contain wildcards ('*'), but not the first. If
1260 // the types are equal or if the mimeType matches wildcard the function
1261 // returns TRUE, otherwise it returns FALSE
1262 static bool IsOfType(const wxString& mimeType, const wxString& wildcard);
1265 wxMimeTypesManager();
1267 // loads data from standard files according to the mailcap styles
1268 // specified: this is a bitwise OR of wxMailcapStyle values
1270 // use the extraDir parameter if you want to look for files in another
1272 void Initialize(int mailcapStyle = wxMAILCAP_STANDARD,
1273 const wxString& extraDir = wxPyEmptyString);
1275 // and this function clears all the data from the manager
1278 // Database lookup: all functions return a pointer to wxFileType object
1279 // whose methods may be used to query it for the information you're
1280 // interested in. If the return value is !NULL, caller is responsible for
1282 // get file type from file extension
1283 %new wxFileType *GetFileTypeFromExtension(const wxString& ext);
1285 // get file type from MIME type (in format <category>/<format>)
1286 %new wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
1288 // other operations: return TRUE if there were no errors or FALSE if there
1289 // were some unreckognized entries (the good entries are always read anyhow)
1292 // read in additional file (the standard ones are read automatically)
1293 // in mailcap format (see mimetype.cpp for description)
1295 // 'fallback' parameter may be set to TRUE to avoid overriding the
1296 // settings from other, previously parsed, files by this one: normally,
1297 // the files read most recently would override the older files, but with
1298 // fallback == TRUE this won't happen
1299 bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
1301 // read in additional file in mime.types format
1302 bool ReadMimeTypes(const wxString& filename);
1304 // enumerate all known MIME types
1306 PyObject* EnumAllFileTypes() {
1308 self->EnumAllFileTypes(arr);
1309 return wxArrayString2PyList_helper(arr);
1313 // these functions can be used to provide default values for some of the
1314 // MIME types inside the program itself (you may also use
1315 // ReadMailcap(filenameWithDefaultTypes, TRUE /* use as fallback */) to
1316 // achieve the same goal, but this requires having this info in a file).
1318 void AddFallback(const wxFileTypeInfo& ft);
1321 // create or remove associations
1323 // create a new association using the fields of wxFileTypeInfo (at least
1324 // the MIME type and the extension should be set)
1325 // if the other fields are empty, the existing values should be left alone
1326 %new wxFileType *Associate(const wxFileTypeInfo& ftInfo);
1329 bool Unassociate(wxFileType *ft) ;
1331 // dtor (not virtual, shouldn't be derived from)
1332 ~wxMimeTypesManager();
1340 extern wxMimeTypesManager* wxTheMimeTypesManager;
1346 //----------------------------------------------------------------------
1349 #include <wx/docview.h>
1352 class wxFileHistory : public wxObject
1355 wxFileHistory(int maxFiles = 9);
1359 void AddFileToHistory(const wxString& file);
1360 void RemoveFileFromHistory(int i);
1361 int GetMaxFiles() const;
1362 void UseMenu(wxMenu *menu);
1364 // Remove menu from the list (MDI child may be closing)
1365 void RemoveMenu(wxMenu *menu);
1367 void Load(wxConfigBase& config);
1368 void Save(wxConfigBase& config);
1370 void AddFilesToMenu();
1371 %name(AddFilesToThisMenu)void AddFilesToMenu(wxMenu* menu);
1374 wxString GetHistoryFile(int i) const;
1376 // A synonym for GetNoHistoryFiles
1377 int GetCount() const;
1378 int GetNoHistoryFiles() const;
1382 //----------------------------------------------------------------------
1383 //----------------------------------------------------------------------
1387 wxPyPtrTypeMap_Add("wxDragImage", "wxGenericDragImage");
1388 wxPyPtrTypeMap_Add("wxProcess", "wxPyProcess");
1391 //----------------------------------------------------------------------