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 <wx/resource.h>
20 #include <wx/tooltip.h>
22 #include <wx/fontenum.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 static wxString wxPyEmptyStr("");
55 //---------------------------------------------------------------------------
58 wxString wxFileSelector(char* message,
59 char* default_path = NULL,
60 char* default_filename = NULL,
61 char* default_extension = NULL,
62 char* wildcard = "*.*",
64 wxWindow *parent = NULL,
65 int x = -1, int y = -1);
67 wxString wxGetTextFromUser(const wxString& message,
68 const wxString& caption = wxPyEmptyStr,
69 const wxString& default_value = wxPyEmptyStr,
70 wxWindow *parent = NULL,
71 int x = -1, int y = -1,
74 wxString wxGetPasswordFromUser(const wxString& message,
75 const wxString& caption = wxPyEmptyStr,
76 const wxString& default_value = wxPyEmptyStr,
77 wxWindow *parent = NULL);
80 // TODO: Need to custom wrap this one...
81 // int wxGetMultipleChoice(char* message, char* caption,
82 // int LCOUNT, char** choices,
83 // int nsel, int *selection,
84 // wxWindow *parent = NULL, int x = -1, int y = -1,
85 // bool centre = TRUE, int width=150, int height=200);
88 wxString wxGetSingleChoice(const wxString& message, const wxString& caption,
89 int LCOUNT, wxString* choices,
90 wxWindow *parent = NULL,
91 int x = -1, int y = -1,
93 int width=150, int height=200);
95 int wxGetSingleChoiceIndex(const wxString& message, const wxString& caption,
96 int LCOUNT, wxString* choices,
97 wxWindow *parent = NULL,
98 int x = -1, int y = -1,
100 int width=150, int height=200);
103 int wxMessageBox(const wxString& message,
104 const wxString& caption = wxPyEmptyStr,
105 int style = wxOK | wxCENTRE,
106 wxWindow *parent = NULL,
107 int x = -1, int y = -1);
109 long wxGetNumberFromUser(const wxString& message,
110 const wxString& prompt,
111 const wxString& caption,
113 long min = 0, long max = 100,
114 wxWindow *parent = NULL,
115 const wxPoint& pos = wxDefaultPosition);
117 //---------------------------------------------------------------------------
120 bool wxColourDisplay();
122 int wxDisplayDepth();
123 int wxGetDisplayDepth();
125 void wxDisplaySize(int* OUTPUT, int* OUTPUT);
126 wxSize wxGetDisplaySize();
128 void wxDisplaySizeMM(int* OUTPUT, int* OUTPUT);
129 wxSize wxGetDisplaySizeMM();
131 void wxClientDisplayRect(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT);
132 wxRect wxGetClientDisplayRect();
134 void wxSetCursor(wxCursor& cursor);
136 //----------------------------------------------------------------------
137 // Miscellaneous functions
139 wxWindow * wxFindWindowByLabel(const wxString& label, wxWindow *parent=NULL);
140 wxWindow * wxFindWindowByName(const wxString& name, wxWindow *parent=NULL);
142 void wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR);
143 wxWindow * wxGetActiveWindow();
145 wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt);
146 wxWindow* wxFindWindowAtPoint(const wxPoint& pt);
149 bool wxCheckForInterrupt(wxWindow *wnd);
150 void wxFlushEvents();
153 //---------------------------------------------------------------------------
156 bool wxResourceAddIdentifier(char *name, int value);
157 void wxResourceClear(void);
158 wxBitmap wxResourceCreateBitmap(char *resource);
159 wxIcon wxResourceCreateIcon(char *resource);
160 wxMenuBar * wxResourceCreateMenuBar(char *resource);
161 int wxResourceGetIdentifier(char *name);
162 bool wxResourceParseData(char *resource, wxResourceTable *table = NULL);
163 bool wxResourceParseFile(char *filename, wxResourceTable *table = NULL);
164 bool wxResourceParseString(char *resource, wxResourceTable *table = NULL);
166 //---------------------------------------------------------------------------
169 // possible values for wxSystemSettings::GetFont() parameter
173 wxSYS_OEM_FIXED_FONT = 10,
174 wxSYS_ANSI_FIXED_FONT,
177 wxSYS_DEVICE_DEFAULT_FONT,
178 wxSYS_DEFAULT_PALETTE,
179 wxSYS_SYSTEM_FIXED_FONT,
180 wxSYS_DEFAULT_GUI_FONT
183 // possible values for wxSystemSettings::GetColour() parameter
187 wxSYS_COLOUR_SCROLLBAR,
188 wxSYS_COLOUR_BACKGROUND,
189 wxSYS_COLOUR_ACTIVECAPTION,
190 wxSYS_COLOUR_INACTIVECAPTION,
193 wxSYS_COLOUR_WINDOWFRAME,
194 wxSYS_COLOUR_MENUTEXT,
195 wxSYS_COLOUR_WINDOWTEXT,
196 wxSYS_COLOUR_CAPTIONTEXT,
197 wxSYS_COLOUR_ACTIVEBORDER,
198 wxSYS_COLOUR_INACTIVEBORDER,
199 wxSYS_COLOUR_APPWORKSPACE,
200 wxSYS_COLOUR_HIGHLIGHT,
201 wxSYS_COLOUR_HIGHLIGHTTEXT,
202 wxSYS_COLOUR_BTNFACE,
203 wxSYS_COLOUR_BTNSHADOW,
204 wxSYS_COLOUR_GRAYTEXT,
205 wxSYS_COLOUR_BTNTEXT,
206 wxSYS_COLOUR_INACTIVECAPTIONTEXT,
207 wxSYS_COLOUR_BTNHIGHLIGHT,
208 wxSYS_COLOUR_3DDKSHADOW,
209 wxSYS_COLOUR_3DLIGHT,
210 wxSYS_COLOUR_INFOTEXT,
212 wxSYS_COLOUR_LISTBOX,
214 wxSYS_COLOUR_DESKTOP = wxSYS_COLOUR_BACKGROUND,
215 wxSYS_COLOUR_3DFACE = wxSYS_COLOUR_BTNFACE,
216 wxSYS_COLOUR_3DSHADOW = wxSYS_COLOUR_BTNSHADOW,
217 wxSYS_COLOUR_3DHIGHLIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
218 wxSYS_COLOUR_3DHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
219 wxSYS_COLOUR_BTNHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT
222 // possible values for wxSystemSettings::GetMetric() parameter
226 wxSYS_MOUSE_BUTTONS = 1,
237 wxSYS_HSCROLL_ARROW_X,
238 wxSYS_HSCROLL_ARROW_Y,
254 wxSYS_VSCROLL_ARROW_X,
255 wxSYS_VSCROLL_ARROW_Y,
259 wxSYS_NETWORK_PRESENT,
260 wxSYS_PENWINDOWS_PRESENT,
265 // possible values for wxSystemSettings::HasFeature() parameter
268 wxSYS_CAN_DRAW_FRAME_DECORATIONS = 1,
269 wxSYS_CAN_ICONIZE_FRAME
274 class wxSystemSettings {
276 // get a standard system colour
277 static wxColour GetColour(wxSystemColour index);
279 // get a standard system font
280 static wxFont GetFont(wxSystemFont index);
282 // get a system-dependent metric
283 static int GetMetric(wxSystemMetric index);
285 // return true if the port has certain feature
286 static bool HasFeature(wxSystemFeature index);
289 // the backwards compatible versions, don't use these methods in the new
291 static wxColour GetSystemColour(int index);
292 static wxFont GetSystemFont(int index);
293 static int GetSystemMetric(int index);
299 //---------------------------------------------------------------------------
302 class wxToolTip : public wxObject {
304 wxToolTip(const wxString &tip);
306 void SetTip(const wxString& tip);
308 // *** Not in the "public" interface void SetWindow(wxWindow *win);
309 wxWindow *GetWindow();
311 static void Enable(bool flag);
312 static void SetDelay(long milliseconds);
315 //----------------------------------------------------------------------
319 wxCaret(wxWindow* window, const wxSize& size);
324 %name(GetPositionTuple)void GetPosition(int *OUTPUT, int *OUTPUT);
325 wxPoint GetPosition();
326 %name(GetSizeTuple)void GetSize(int *OUTPUT, int *OUTPUT);
328 wxWindow *GetWindow();
329 %name(MoveXY)void Move(int x, int y);
330 void Move(const wxPoint& pt);
331 %name(SetSizeWH) void SetSize(int width, int height);
332 void SetSize(const wxSize& size);
333 void Show(int show = TRUE);
338 int wxCaret_GetBlinkTime() {
339 return wxCaret::GetBlinkTime();
342 void wxCaret_SetBlinkTime(int milliseconds) {
343 wxCaret::SetBlinkTime(milliseconds);
347 //----------------------------------------------------------------------
350 class wxPyFontEnumerator : public wxFontEnumerator {
352 wxPyFontEnumerator() {}
353 ~wxPyFontEnumerator() {}
355 DEC_PYCALLBACK_BOOL_STRING(OnFacename);
356 DEC_PYCALLBACK_BOOL_STRINGSTRING(OnFontEncoding);
361 IMP_PYCALLBACK_BOOL_STRING(wxPyFontEnumerator, wxFontEnumerator, OnFacename);
362 IMP_PYCALLBACK_BOOL_STRINGSTRING(wxPyFontEnumerator, wxFontEnumerator, OnFontEncoding);
366 %name(wxFontEnumerator) class wxPyFontEnumerator {
368 wxPyFontEnumerator();
369 ~wxPyFontEnumerator();
370 void _setCallbackInfo(PyObject* self, PyObject* _class, bool incref);
371 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFontEnumerator, 0)"
373 bool EnumerateFacenames(
374 wxFontEncoding encoding = wxFONTENCODING_SYSTEM, // all
375 bool fixedWidthOnly = FALSE);
376 bool EnumerateEncodings(const char* facename = "");
378 //wxArrayString* GetEncodings();
379 //wxArrayString* GetFacenames();
381 PyObject* GetEncodings() {
382 wxArrayString* arr = self->GetEncodings();
383 return wxArrayString2PyList_helper(*arr);
386 PyObject* GetFacenames() {
387 wxArrayString* arr = self->GetFacenames();
388 return wxArrayString2PyList_helper(*arr);
393 //----------------------------------------------------------------------
397 wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR);
401 //----------------------------------------------------------------------
403 class wxWindowDisabler {
405 wxWindowDisabler(wxWindow *winToSkip = NULL);
409 //----------------------------------------------------------------------
411 bool wxSafeYield(wxWindow* win=NULL);
412 void wxPostEvent(wxEvtHandler *dest, wxEvent& event);
417 void wxWakeUpMainThread();
420 void wxMutexGuiEnter();
421 void wxMutexGuiLeave();
424 class wxMutexGuiLocker {
432 bool wxThread_IsMain() {
433 #ifdef WXP_WITH_THREAD
434 return wxThread::IsMain();
441 //----------------------------------------------------------------------
447 // wxTipProvider(size_t currentTip); **** Abstract base class
450 virtual wxString GetTip() = 0;
451 size_t GetCurrentTip();
456 // The C++ version of wxPyTipProvider
458 class wxPyTipProvider : public wxTipProvider {
460 wxPyTipProvider(size_t currentTip)
461 : wxTipProvider(currentTip) {}
463 DEC_PYCALLBACK_STRING__pure(GetTip);
468 IMP_PYCALLBACK_STRING__pure( wxPyTipProvider, wxTipProvider, GetTip);
473 // Now let SWIG know about it
474 class wxPyTipProvider : public wxTipProvider {
476 wxPyTipProvider(size_t currentTip);
481 bool wxShowTip(wxWindow *parent, wxTipProvider *tipProvider, bool showAtStartup = TRUE);
482 %new wxTipProvider * wxCreateFileTipProvider(const wxString& filename, size_t currentTip);
485 //----------------------------------------------------------------------
488 #include <wx/generic/dragimgg.h>
491 %name (wxDragImage) class wxGenericDragImage : public wxObject
495 wxGenericDragImage(const wxBitmap& image,
496 const wxCursor& cursor = wxNullCursor);
497 %name(wxDragIcon)wxGenericDragImage(const wxIcon& image,
498 const wxCursor& cursor = wxNullCursor);
499 %name(wxDragString)wxGenericDragImage(const wxString& str,
500 const wxCursor& cursor = wxNullCursor);
501 %name(wxDragTreeItem)wxGenericDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
502 %name(wxDragListItem)wxGenericDragImage(const wxListCtrl& listCtrl, long id);
504 ~wxGenericDragImage();
506 void SetBackingBitmap(wxBitmap* bitmap);
507 bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
508 bool fullScreen = FALSE, wxRect* rect = NULL);
510 %name(BeginDrag2) bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
511 wxWindow* fullScreenRect);
514 bool Move(const wxPoint& pt);
518 wxRect GetImageRect(const wxPoint& pos) const;
519 bool RedrawImage(const wxPoint& oldPos, const wxPoint& newPos,
520 bool eraseOld, bool drawNew);
524 //----------------------------------------------------------------------
526 class wxPyTimer : public wxObject {
528 wxPyTimer(PyObject* notify);
533 void SetOwner(wxEvtHandler *owner, int id = -1);
534 void Start(int milliseconds=-1, int oneShot=FALSE);
542 // ctor starts the stop watch
544 void Start(long t = 0);
548 // get elapsed time since the last Start() or Pause() in milliseconds
553 //----------------------------------------------------------------------
554 //----------------------------------------------------------------------
559 wxLOG_FatalError, // program can't continue, abort immediately
560 wxLOG_Error, // a serious error, user must be informed about it
561 wxLOG_Warning, // user is normally informed about it but may be ignored
562 wxLOG_Message, // normal message (i.e. normal output of a non GUI app)
563 wxLOG_Info, // informational message (a.k.a. 'Verbose')
564 wxLOG_Status, // informational: might go to the status line of GUI app
565 wxLOG_Debug, // never shown to the user, disabled in release mode
566 wxLOG_Trace, // trace messages are also only enabled in debug mode
567 wxLOG_Progress, // used for progress indicator (not yet)
568 wxLOG_User = 100 // user defined levels start here
577 static bool IsEnabled();
578 static bool EnableLogging(bool doIt = TRUE);
579 static void OnLog(wxLogLevel level, const char *szString, int t=0);
581 virtual void Flush();
582 bool HasPendingMessages() const;
584 static void FlushActive();
585 static wxLog *GetActiveTarget();
586 static wxLog *SetActiveTarget(wxLog *pLogger);
588 static void Suspend();
589 static void Resume();
591 void SetVerbose(bool bVerbose = TRUE);
593 static void DontCreateOnDemand();
594 static void SetTraceMask(wxTraceMask ulMask);
595 static void AddTraceMask(const wxString& str);
596 static void RemoveTraceMask(const wxString& str);
597 static void ClearTraceMasks();
599 static void SetTimestamp(const wxChar *ts);
600 static const wxChar *GetTimestamp();
602 bool GetVerbose() const { return m_bVerbose; }
604 static wxTraceMask GetTraceMask();
605 static bool IsAllowedTraceMask(const char *mask);
607 // static void TimeStamp(wxString *str);
609 wxString TimeStamp() {
611 wxLog::TimeStamp(&msg);
618 class wxLogStderr : public wxLog
621 wxLogStderr(/* TODO: FILE *fp = (FILE *) NULL*/);
625 class wxLogTextCtrl : public wxLog
628 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
632 class wxLogGui : public wxLog
638 class wxLogWindow : public wxLog
641 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
642 const char *szTitle, // the title of the frame
643 bool bShow = TRUE, // show window immediately?
644 bool bPassToOld = TRUE); // pass log messages to the old target?
646 void Show(bool bShow = TRUE);
647 wxFrame *GetFrame() const;
648 wxLog *GetOldLog() const;
649 bool IsPassingMessages() const;
650 void PassMessages(bool bDoPass) { m_bPassMessages = bDoPass; }
662 class wxLogChain : public wxLog
665 wxLogChain(wxLog *logger);
666 void SetLog(wxLog *logger);
667 void PassMessages(bool bDoPass);
668 bool IsPassingMessages();
673 unsigned long wxSysErrorCode();
674 const char* wxSysErrorMsg(unsigned long nErrCode = 0);
675 void wxLogFatalError(const char *szFormat);
676 void wxLogError(const char *szFormat);
677 void wxLogWarning(const char *szFormat);
678 void wxLogMessage(const char *szFormat);
679 void wxLogInfo(const char *szFormat);
680 void wxLogVerbose(const char *szFormat);
681 void wxLogStatus(const char *szFormat);
682 %name(wxLogStatusFrame)void wxLogStatus(wxFrame *pFrame, const char *szFormat);
683 void wxLogSysError(const char *szFormat);
687 // A Log class that can be derived from in wxPython
688 class wxPyLog : public wxLog {
690 wxPyLog() : wxLog() {}
692 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) {
694 wxPyBeginBlockThreads();
695 if ((found = wxPyCBH_findCallback(m_myInst, "DoLog")))
696 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(isi)", level, szString, t));
697 wxPyEndBlockThreads();
699 wxLog::DoLog(level, szString, t);
702 virtual void DoLogString(const wxChar *szString, time_t t) {
704 wxPyBeginBlockThreads();
705 if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString")))
706 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(si)", szString, t));
707 wxPyEndBlockThreads();
709 wxLog::DoLogString(szString, t);
716 // Now tell SWIG about it
717 class wxPyLog : public wxLog {
720 void _setCallbackInfo(PyObject* self, PyObject* _class);
721 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyLog)"
722 %addmethods { void Destroy() { delete self; } }
727 //----------------------------------------------------------------------
736 class wxProcessEvent : public wxEvent {
738 wxProcessEvent(int id = 0, int pid = 0, int exitcode = 0);
741 int m_pid, m_exitcode;
747 %{ // C++ version of wxProcess derived class
749 class wxPyProcess : public wxProcess {
751 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1)
752 : wxProcess(parent, id)
755 DEC_PYCALLBACK_VOID_INTINT(OnTerminate);
760 IMP_PYCALLBACK_VOID_INTINT( wxPyProcess, wxProcess, OnTerminate);
765 %name(wxProcess)class wxPyProcess : public wxEvtHandler {
767 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1);
768 %addmethods { void Destroy() { delete self; } }
770 void _setCallbackInfo(PyObject* self, PyObject* _class);
771 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxProcess)"
773 void base_OnTerminate(int pid, int status);
779 wxInputStream *GetInputStream();
780 wxInputStream *GetErrorStream();
781 wxOutputStream *GetOutputStream();
788 long wxExecute(const wxString& command,
790 wxPyProcess *process = NULL);
792 //----------------------------------------------------------------------
795 #if !wxUSE_JOYSTICK && !defined(__WXMSW__)
796 // A C++ stub class for wxJoystick for platforms that don't have it.
797 class wxJoystick : public wxObject {
799 wxJoystick(int joystick = wxJOYSTICK1) {
800 wxPyBeginBlockThreads();
801 PyErr_SetString(PyExc_NotImplementedError, "wxJoystick is not available on this platform.");
802 wxPyEndBlockThreads();
804 wxPoint GetPosition() { return wxPoint(-1,-1); }
805 int GetZPosition() { return -1; }
806 int GetButtonState() { return -1; }
807 int GetPOVPosition() { return -1; }
808 int GetPOVCTSPosition() { return -1; }
809 int GetRudderPosition() { return -1; }
810 int GetUPosition() { return -1; }
811 int GetVPosition() { return -1; }
812 int GetMovementThreshold() { return -1; }
813 void SetMovementThreshold(int threshold) {}
815 bool IsOk(void) { return FALSE; }
816 int GetNumberJoysticks() { return -1; }
817 int GetManufacturerId() { return -1; }
818 int GetProductId() { return -1; }
819 wxString GetProductName() { return ""; }
820 int GetXMin() { return -1; }
821 int GetYMin() { return -1; }
822 int GetZMin() { return -1; }
823 int GetXMax() { return -1; }
824 int GetYMax() { return -1; }
825 int GetZMax() { return -1; }
826 int GetNumberButtons() { return -1; }
827 int GetNumberAxes() { return -1; }
828 int GetMaxButtons() { return -1; }
829 int GetMaxAxes() { return -1; }
830 int GetPollingMin() { return -1; }
831 int GetPollingMax() { return -1; }
832 int GetRudderMin() { return -1; }
833 int GetRudderMax() { return -1; }
834 int GetUMin() { return -1; }
835 int GetUMax() { return -1; }
836 int GetVMin() { return -1; }
837 int GetVMax() { return -1; }
839 bool HasRudder() { return FALSE; }
840 bool HasZ() { return FALSE; }
841 bool HasU() { return FALSE; }
842 bool HasV() { return FALSE; }
843 bool HasPOV() { return FALSE; }
844 bool HasPOV4Dir() { return FALSE; }
845 bool HasPOVCTS() { return FALSE; }
847 bool SetCapture(wxWindow* win, int pollingFreq = 0) { return FALSE; }
848 bool ReleaseCapture() { return FALSE; }
854 class wxJoystick : public wxObject {
856 wxJoystick(int joystick = wxJOYSTICK1);
859 wxPoint GetPosition();
861 int GetButtonState();
862 int GetPOVPosition();
863 int GetPOVCTSPosition();
864 int GetRudderPosition();
867 int GetMovementThreshold();
868 void SetMovementThreshold(int threshold) ;
871 int GetNumberJoysticks();
872 int GetManufacturerId();
874 wxString GetProductName();
881 int GetNumberButtons();
902 bool SetCapture(wxWindow* win, int pollingFreq = 0);
903 bool ReleaseCapture();
906 //----------------------------------------------------------------------
910 // A C++ stub class for wxWave for platforms that don't have it.
911 class wxWave : public wxObject
914 wxWave(const wxString& fileName, bool isResource = FALSE) {
915 wxPyBeginBlockThreads();
916 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
917 wxPyEndBlockThreads();
919 wxWave(int size, const wxByte* data) {
920 wxPyBeginBlockThreads();
921 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
922 wxPyEndBlockThreads();
927 bool IsOk() const { return FALSE; }
928 bool Play(bool async = TRUE, bool looped = FALSE) const { return FALSE; }
934 class wxWave : public wxObject
937 wxWave(const wxString& fileName, bool isResource = FALSE);
941 bool Play(bool async = TRUE, bool looped = FALSE) const;
944 %new wxWave* wxWaveData(const wxString& data);
945 %{ // Implementations of some alternate "constructors"
946 wxWave* wxWaveData(const wxString& data) {
947 return new wxWave(data.Len(), (wxByte*)data.c_str());
952 //----------------------------------------------------------------------
956 wxMAILCAP_STANDARD = 1,
957 wxMAILCAP_NETSCAPE = 2,
971 wxFileTypeInfo(const char *mimeType,
973 const char *printCmd,
977 // the array elements correspond to the parameters of the ctor above in
979 %name(wxFileTypeInfoSequence)wxFileTypeInfo(const wxArrayString& sArray);
981 // invalid item - use this to terminate the array passed to
982 // wxMimeTypesManager::AddFallbacks
983 %name(wxNullFileTypeInfo)wxFileTypeInfo();
986 // test if this object can be used
987 bool IsValid() const;
991 void SetIcon(const wxString& iconFile, int iconIndex = 0);
993 // set the short desc
994 void SetShortDesc(const wxString& shortDesc);
998 const wxString& GetMimeType() const;
999 // get the open command
1000 const wxString& GetOpenCommand() const;
1001 // get the print command
1002 const wxString& GetPrintCommand() const;
1003 // get the short description (only used under Win32 so far)
1004 const wxString& GetShortDesc() const;
1005 // get the long, user visible description
1006 const wxString& GetDescription() const;
1009 // get the array of all extensions
1010 //const wxArrayString& GetExtensions() const;
1012 PyObject* GetExtensions() {
1013 wxArrayString& arr = (wxArrayString&)self->GetExtensions();
1014 return wxArrayString2PyList_helper(arr);
1018 int GetExtensionsCount() const;
1020 // get the icon info
1021 const wxString& GetIconFile() const;
1022 int GetIconIndex() const;
1032 // TODO: Make a wxPyMessageParameters with virtual GetParamValue...
1034 // An object of this class must be passed to Get{Open|Print}Command. The
1035 // default implementation is trivial and doesn't know anything at all about
1036 // parameters, only filename and MIME type are used (so it's probably ok for
1037 // Windows where %{param} is not used anyhow)
1038 class MessageParameters
1042 MessageParameters(const wxString& filename=wxPyEmptyStr,
1043 const wxString& mimetype=wxPyEmptyStr);
1045 // accessors (called by GetOpenCommand)
1047 const wxString& GetFileName() const;
1049 const wxString& GetMimeType() const;;
1051 // override this function in derived class
1052 virtual wxString GetParamValue(const wxString& name) const;
1054 // virtual dtor as in any base class
1055 virtual ~MessageParameters();
1059 // ctor from static data
1060 wxFileType(const wxFileTypeInfo& ftInfo);
1062 // return the MIME type for this file type
1064 PyObject* GetMimeType() {
1066 if (self->GetMimeType(&str))
1067 return PyString_FromString(str.c_str());
1071 PyObject* GetMimeTypes() {
1073 if (self->GetMimeTypes(arr))
1074 return wxArrayString2PyList_helper(arr);
1081 // Get all extensions associated with this file type
1083 PyObject* GetExtensions() {
1085 if (self->GetExtensions(arr))
1086 return wxArrayString2PyList_helper(arr);
1094 // Get the icon corresponding to this file type
1095 %new wxIcon* GetIcon() {
1097 if (self->GetIcon(&icon))
1098 return new wxIcon(icon);
1103 // Get the icon corresponding to this file type, the name of the file
1104 // where this icon resides, and its index in this file if applicable.
1105 PyObject* GetIconInfo() {
1109 if (self->GetIcon(&icon, &iconFile, &iconIndex)) {
1110 wxPyBeginBlockThreads();
1111 PyObject* tuple = PyTuple_New(3);
1112 PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(icon),
1114 PyTuple_SetItem(tuple, 1, PyString_FromString(iconFile.c_str()));
1115 PyTuple_SetItem(tuple, 2, PyInt_FromLong(iconIndex));
1116 wxPyEndBlockThreads();
1125 // get a brief file type description ("*.txt" => "text document")
1126 PyObject* GetDescription() {
1128 if (self->GetDescription(&str))
1129 return PyString_FromString(str.c_str());
1136 // get the command to open/execute the file of given type
1138 PyObject* GetOpenCommand(const wxString& filename,
1139 const wxString& mimetype=wxPyEmptyStr) {
1141 if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype)))
1142 return PyString_FromString(str.c_str());
1149 // get the command to print the file of given type
1151 PyObject* GetPrintCommand(const wxString& filename,
1152 const wxString& mimetype=wxPyEmptyStr) {
1154 if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype)))
1155 return PyString_FromString(str.c_str());
1162 // Get all commands defined for this file type
1164 PyObject* GetAllCommands(const wxString& filename,
1165 const wxString& mimetype=wxPyEmptyStr) {
1166 wxArrayString verbs;
1167 wxArrayString commands;
1168 if (self->GetAllCommands(&verbs, &commands,
1169 wxFileType::MessageParameters(filename, mimetype))) {
1170 wxPyBeginBlockThreads();
1171 PyObject* tuple = PyTuple_New(2);
1172 PyTuple_SetItem(tuple, 0, wxArrayString2PyList_helper(verbs));
1173 PyTuple_SetItem(tuple, 1, wxArrayString2PyList_helper(commands));
1174 wxPyEndBlockThreads();
1183 // set an arbitrary command, ask confirmation if it already exists and
1184 // overwriteprompt is TRUE
1185 bool SetCommand(const wxString& cmd, const wxString& verb,
1186 bool overwriteprompt = TRUE);
1188 bool SetDefaultIcon(const wxString& cmd = wxEmptyString, int index = 0);
1191 // remove the association for this filetype from the system MIME database:
1192 // notice that it will only work if the association is defined in the user
1193 // file/registry part, we will never modify the system-wide settings
1197 // expand a string in the format of GetOpenCommand (which may contain
1198 // '%s' and '%t' format specificators for the file name and mime type
1199 // and %{param} constructions).
1200 static wxString ExpandCommand(const wxString& command,
1201 const MessageParameters& params);
1203 // dtor (not virtual, shouldn't be derived from)
1211 class wxMimeTypesManager
1214 // static helper functions
1215 // -----------------------
1217 // check if the given MIME type is the same as the other one: the
1218 // second argument may contain wildcards ('*'), but not the first. If
1219 // the types are equal or if the mimeType matches wildcard the function
1220 // returns TRUE, otherwise it returns FALSE
1221 static bool IsOfType(const wxString& mimeType, const wxString& wildcard);
1224 wxMimeTypesManager();
1226 // loads data from standard files according to the mailcap styles
1227 // specified: this is a bitwise OR of wxMailcapStyle values
1229 // use the extraDir parameter if you want to look for files in another
1231 void Initialize(int mailcapStyle = wxMAILCAP_STANDARD,
1232 const wxString& extraDir = wxEmptyString);
1234 // and this function clears all the data from the manager
1237 // Database lookup: all functions return a pointer to wxFileType object
1238 // whose methods may be used to query it for the information you're
1239 // interested in. If the return value is !NULL, caller is responsible for
1241 // get file type from file extension
1242 %new wxFileType *GetFileTypeFromExtension(const wxString& ext);
1244 // get file type from MIME type (in format <category>/<format>)
1245 %new wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
1247 // other operations: return TRUE if there were no errors or FALSE if there
1248 // were some unreckognized entries (the good entries are always read anyhow)
1251 // read in additional file (the standard ones are read automatically)
1252 // in mailcap format (see mimetype.cpp for description)
1254 // 'fallback' parameter may be set to TRUE to avoid overriding the
1255 // settings from other, previously parsed, files by this one: normally,
1256 // the files read most recently would override the older files, but with
1257 // fallback == TRUE this won't happen
1258 bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
1260 // read in additional file in mime.types format
1261 bool ReadMimeTypes(const wxString& filename);
1263 // enumerate all known MIME types
1265 PyObject* EnumAllFileTypes() {
1267 self->EnumAllFileTypes(arr);
1268 return wxArrayString2PyList_helper(arr);
1272 // these functions can be used to provide default values for some of the
1273 // MIME types inside the program itself (you may also use
1274 // ReadMailcap(filenameWithDefaultTypes, TRUE /* use as fallback */) to
1275 // achieve the same goal, but this requires having this info in a file).
1277 void AddFallback(const wxFileTypeInfo& ft);
1280 // create or remove associations
1282 // create a new association using the fields of wxFileTypeInfo (at least
1283 // the MIME type and the extension should be set)
1284 // if the other fields are empty, the existing values should be left alone
1285 %new wxFileType *Associate(const wxFileTypeInfo& ftInfo);
1288 bool Unassociate(wxFileType *ft) ;
1290 // dtor (not virtual, shouldn't be derived from)
1291 ~wxMimeTypesManager();
1299 extern wxMimeTypesManager* wxTheMimeTypesManager;
1305 //----------------------------------------------------------------------
1308 #include <wx/docview.h>
1311 class wxFileHistory : public wxObject
1314 wxFileHistory(int maxFiles = 9);
1318 void AddFileToHistory(const wxString& file);
1319 void RemoveFileFromHistory(int i);
1320 int GetMaxFiles() const;
1321 void UseMenu(wxMenu *menu);
1323 // Remove menu from the list (MDI child may be closing)
1324 void RemoveMenu(wxMenu *menu);
1326 void Load(wxConfigBase& config);
1327 void Save(wxConfigBase& config);
1329 void AddFilesToMenu();
1330 %name(AddFilesToSingleMenu)void AddFilesToMenu(wxMenu* menu);
1333 wxString GetHistoryFile(int i) const;
1335 // A synonym for GetNoHistoryFiles
1336 int GetCount() const;
1337 int GetNoHistoryFiles() const;
1341 //----------------------------------------------------------------------
1342 //----------------------------------------------------------------------
1346 wxPyPtrTypeMap_Add("wxFontEnumerator", "wxPyFontEnumerator");
1347 wxPyPtrTypeMap_Add("wxDragImage", "wxGenericDragImage");
1348 wxPyPtrTypeMap_Add("wxProcess", "wxPyProcess");
1351 //----------------------------------------------------------------------