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.
51 static wxString wxPyEmptyStr("");
54 //---------------------------------------------------------------------------
57 wxString wxFileSelector(char* message,
58 char* default_path = NULL,
59 char* default_filename = NULL,
60 char* default_extension = NULL,
61 char* wildcard = "*.*",
63 wxWindow *parent = NULL,
64 int x = -1, int y = -1);
66 wxString wxGetTextFromUser(const wxString& message,
67 const wxString& caption = wxPyEmptyStr,
68 const wxString& default_value = wxPyEmptyStr,
69 wxWindow *parent = NULL,
70 int x = -1, int y = -1,
73 wxString wxGetPasswordFromUser(const wxString& message,
74 const wxString& caption = wxPyEmptyStr,
75 const wxString& default_value = wxPyEmptyStr,
76 wxWindow *parent = NULL);
79 // TODO: Need to custom wrap this one...
80 // int wxGetMultipleChoice(char* message, char* caption,
81 // int LCOUNT, char** choices,
82 // int nsel, int *selection,
83 // wxWindow *parent = NULL, int x = -1, int y = -1,
84 // bool centre = TRUE, int width=150, int height=200);
87 wxString wxGetSingleChoice(const wxString& message, const wxString& caption,
88 int LCOUNT, wxString* choices,
89 wxWindow *parent = NULL,
90 int x = -1, int y = -1,
92 int width=150, int height=200);
94 int wxGetSingleChoiceIndex(const wxString& message, const wxString& caption,
95 int LCOUNT, wxString* choices,
96 wxWindow *parent = NULL,
97 int x = -1, int y = -1,
99 int width=150, int height=200);
102 int wxMessageBox(const wxString& message,
103 const wxString& caption = wxPyEmptyStr,
104 int style = wxOK | wxCENTRE,
105 wxWindow *parent = NULL,
106 int x = -1, int y = -1);
108 long wxGetNumberFromUser(const wxString& message,
109 const wxString& prompt,
110 const wxString& caption,
112 long min = 0, long max = 100,
113 wxWindow *parent = NULL,
114 const wxPoint& pos = wxDefaultPosition);
116 //---------------------------------------------------------------------------
119 bool wxColourDisplay();
121 int wxDisplayDepth();
122 int wxGetDisplayDepth();
124 void wxDisplaySize(int* OUTPUT, int* OUTPUT);
125 wxSize wxGetDisplaySize();
127 void wxDisplaySizeMM(int* OUTPUT, int* OUTPUT);
128 wxSize wxGetDisplaySizeMM();
130 void wxClientDisplayRect(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT);
131 wxRect wxGetClientDisplayRect();
133 void wxSetCursor(wxCursor& cursor);
135 //----------------------------------------------------------------------
136 // Miscellaneous functions
138 wxWindow * wxFindWindowByLabel(const wxString& label, wxWindow *parent=NULL);
139 wxWindow * wxFindWindowByName(const wxString& name, wxWindow *parent=NULL);
141 void wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR);
142 wxWindow * wxGetActiveWindow();
144 wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt);
145 wxWindow* wxFindWindowAtPoint(const wxPoint& pt);
148 bool wxCheckForInterrupt(wxWindow *wnd);
149 void wxFlushEvents();
152 //---------------------------------------------------------------------------
155 bool wxResourceAddIdentifier(char *name, int value);
156 void wxResourceClear(void);
157 wxBitmap wxResourceCreateBitmap(char *resource);
158 wxIcon wxResourceCreateIcon(char *resource);
159 wxMenuBar * wxResourceCreateMenuBar(char *resource);
160 int wxResourceGetIdentifier(char *name);
161 bool wxResourceParseData(char *resource, wxResourceTable *table = NULL);
162 bool wxResourceParseFile(char *filename, wxResourceTable *table = NULL);
163 bool wxResourceParseString(char *resource, wxResourceTable *table = NULL);
165 //---------------------------------------------------------------------------
179 wxSYS_OEM_FIXED_FONT,
180 wxSYS_ANSI_FIXED_FONT,
183 wxSYS_DEVICE_DEFAULT_FONT,
184 wxSYS_DEFAULT_PALETTE,
185 wxSYS_SYSTEM_FIXED_FONT,
186 wxSYS_DEFAULT_GUI_FONT,
188 wxSYS_COLOUR_SCROLLBAR,
189 wxSYS_COLOUR_BACKGROUND,
190 wxSYS_COLOUR_ACTIVECAPTION,
191 wxSYS_COLOUR_INACTIVECAPTION,
194 wxSYS_COLOUR_WINDOWFRAME,
195 wxSYS_COLOUR_MENUTEXT,
196 wxSYS_COLOUR_WINDOWTEXT,
197 wxSYS_COLOUR_CAPTIONTEXT,
198 wxSYS_COLOUR_ACTIVEBORDER,
199 wxSYS_COLOUR_INACTIVEBORDER,
200 wxSYS_COLOUR_APPWORKSPACE,
201 wxSYS_COLOUR_HIGHLIGHT,
202 wxSYS_COLOUR_HIGHLIGHTTEXT,
203 wxSYS_COLOUR_BTNFACE,
204 wxSYS_COLOUR_BTNSHADOW,
205 wxSYS_COLOUR_GRAYTEXT,
206 wxSYS_COLOUR_BTNTEXT,
207 wxSYS_COLOUR_INACTIVECAPTIONTEXT,
208 wxSYS_COLOUR_BTNHIGHLIGHT,
210 wxSYS_COLOUR_3DDKSHADOW,
211 wxSYS_COLOUR_3DLIGHT,
212 wxSYS_COLOUR_INFOTEXT,
215 wxSYS_COLOUR_DESKTOP,
217 wxSYS_COLOUR_3DSHADOW,
218 wxSYS_COLOUR_3DHIGHLIGHT,
219 wxSYS_COLOUR_3DHILIGHT,
220 wxSYS_COLOUR_BTNHILIGHT,
233 wxSYS_HSCROLL_ARROW_X,
234 wxSYS_HSCROLL_ARROW_Y,
250 wxSYS_VSCROLL_ARROW_X,
251 wxSYS_VSCROLL_ARROW_Y,
255 wxSYS_NETWORK_PRESENT,
256 wxSYS_PENWINDOWS_PRESENT,
265 wxColour wxSystemSettings_GetSystemColour(int index) {
266 return wxSystemSettings::GetSystemColour(index);
269 wxFont wxSystemSettings_GetSystemFont(int index) {
270 return wxSystemSettings::GetSystemFont(index);
273 int wxSystemSettings_GetSystemMetric(int index) {
274 return wxSystemSettings::GetSystemMetric(index);
278 //---------------------------------------------------------------------------
281 class wxToolTip : public wxObject {
283 wxToolTip(const wxString &tip);
285 void SetTip(const wxString& tip);
287 // *** Not in the "public" interface void SetWindow(wxWindow *win);
288 wxWindow *GetWindow();
290 static void Enable(bool flag);
291 static void SetDelay(long milliseconds);
294 //----------------------------------------------------------------------
298 wxCaret(wxWindow* window, const wxSize& size);
303 %name(GetPositionTuple)void GetPosition(int *OUTPUT, int *OUTPUT);
304 wxPoint GetPosition();
305 %name(GetSizeTuple)void GetSize(int *OUTPUT, int *OUTPUT);
307 wxWindow *GetWindow();
308 %name(MoveXY)void Move(int x, int y);
309 void Move(const wxPoint& pt);
310 %name(SetSizeWH) void SetSize(int width, int height);
311 void SetSize(const wxSize& size);
312 void Show(int show = TRUE);
317 int wxCaret_GetBlinkTime() {
318 return wxCaret::GetBlinkTime();
321 void wxCaret_SetBlinkTime(int milliseconds) {
322 wxCaret::SetBlinkTime(milliseconds);
326 //----------------------------------------------------------------------
329 class wxPyFontEnumerator : public wxFontEnumerator {
331 wxPyFontEnumerator() {}
332 ~wxPyFontEnumerator() {}
334 DEC_PYCALLBACK_BOOL_STRING(OnFacename);
335 DEC_PYCALLBACK_BOOL_STRINGSTRING(OnFontEncoding);
340 IMP_PYCALLBACK_BOOL_STRING(wxPyFontEnumerator, wxFontEnumerator, OnFacename);
341 IMP_PYCALLBACK_BOOL_STRINGSTRING(wxPyFontEnumerator, wxFontEnumerator, OnFontEncoding);
345 %name(wxFontEnumerator) class wxPyFontEnumerator {
347 wxPyFontEnumerator();
348 ~wxPyFontEnumerator();
349 void _setCallbackInfo(PyObject* self, PyObject* _class);
350 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFontEnumerator)"
352 bool EnumerateFacenames(
353 wxFontEncoding encoding = wxFONTENCODING_SYSTEM, // all
354 bool fixedWidthOnly = FALSE);
355 bool EnumerateEncodings(const char* facename = "");
357 //wxArrayString* GetEncodings();
358 //wxArrayString* GetFacenames();
360 PyObject* GetEncodings() {
361 wxArrayString* arr = self->GetEncodings();
362 return wxArrayString2PyList_helper(arr);
365 PyObject* GetFacenames() {
366 wxArrayString* arr = self->GetFacenames();
367 return wxArrayString2PyList_helper(arr);
372 //----------------------------------------------------------------------
376 wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR);
380 //----------------------------------------------------------------------
382 class wxWindowDisabler {
384 wxWindowDisabler(wxWindow *winToSkip = NULL);
388 //----------------------------------------------------------------------
390 bool wxSafeYield(wxWindow* win=NULL);
391 void wxPostEvent(wxEvtHandler *dest, wxEvent& event);
396 void wxWakeUpMainThread();
399 void wxMutexGuiEnter();
400 void wxMutexGuiLeave();
403 class wxMutexGuiLocker {
411 bool wxThread_IsMain() {
412 return wxThread::IsMain();
416 //----------------------------------------------------------------------
422 // wxTipProvider(size_t currentTip); **** Abstract base class
425 virtual wxString GetTip() = 0;
426 size_t GetCurrentTip();
431 // The C++ version of wxPyTipProvider
433 class wxPyTipProvider : public wxTipProvider {
435 wxPyTipProvider(size_t currentTip)
436 : wxTipProvider(currentTip) {}
438 DEC_PYCALLBACK_STRING__pure(GetTip);
443 IMP_PYCALLBACK_STRING__pure( wxPyTipProvider, wxTipProvider, GetTip);
448 // Now let SWIG know about it
449 class wxPyTipProvider : public wxTipProvider {
451 wxPyTipProvider(size_t currentTip);
456 bool wxShowTip(wxWindow *parent, wxTipProvider *tipProvider, bool showAtStartup = TRUE);
457 %new wxTipProvider * wxCreateFileTipProvider(const wxString& filename, size_t currentTip);
460 //----------------------------------------------------------------------
463 #include <wx/generic/dragimgg.h>
466 %name (wxDragImage) class wxGenericDragImage : public wxObject
470 wxGenericDragImage(const wxBitmap& image,
471 const wxCursor& cursor = wxNullCursor);
472 %name(wxDragIcon)wxGenericDragImage(const wxIcon& image,
473 const wxCursor& cursor = wxNullCursor);
474 %name(wxDragString)wxGenericDragImage(const wxString& str,
475 const wxCursor& cursor = wxNullCursor);
476 %name(wxDragTreeItem)wxGenericDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
477 %name(wxDragListItem)wxGenericDragImage(const wxListCtrl& listCtrl, long id);
479 ~wxGenericDragImage();
481 void SetBackingBitmap(wxBitmap* bitmap);
482 bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
483 bool fullScreen = FALSE, wxRect* rect = NULL);
485 %name(BeginDrag2) bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
486 wxWindow* fullScreenRect);
489 bool Move(const wxPoint& pt);
493 wxRect GetImageRect(const wxPoint& pos) const;
494 bool RedrawImage(const wxPoint& oldPos, const wxPoint& newPos,
495 bool eraseOld, bool drawNew);
499 //----------------------------------------------------------------------
501 class wxPyTimer : public wxObject {
503 wxPyTimer(PyObject* notify);
508 void SetOwner(wxEvtHandler *owner, int id = -1);
509 void Start(int milliseconds=-1, int oneShot=FALSE);
517 // ctor starts the stop watch
519 void Start(long t = 0);
523 // get elapsed time since the last Start() or Pause() in milliseconds
528 //----------------------------------------------------------------------
529 //----------------------------------------------------------------------
534 wxLOG_FatalError, // program can't continue, abort immediately
535 wxLOG_Error, // a serious error, user must be informed about it
536 wxLOG_Warning, // user is normally informed about it but may be ignored
537 wxLOG_Message, // normal message (i.e. normal output of a non GUI app)
538 wxLOG_Info, // informational message (a.k.a. 'Verbose')
539 wxLOG_Status, // informational: might go to the status line of GUI app
540 wxLOG_Debug, // never shown to the user, disabled in release mode
541 wxLOG_Trace, // trace messages are also only enabled in debug mode
542 wxLOG_Progress, // used for progress indicator (not yet)
543 wxLOG_User = 100 // user defined levels start here
552 static bool IsEnabled();
553 static bool EnableLogging(bool doIt = TRUE);
554 static void OnLog(wxLogLevel level, const char *szString, int t=0);
556 virtual void Flush();
557 bool HasPendingMessages() const;
559 static void FlushActive();
560 static wxLog *GetActiveTarget();
561 static wxLog *SetActiveTarget(wxLog *pLogger);
563 static void Suspend();
564 static void Resume();
566 void SetVerbose(bool bVerbose = TRUE);
568 static void DontCreateOnDemand();
569 static void SetTraceMask(wxTraceMask ulMask);
570 static void AddTraceMask(const wxString& str);
571 static void RemoveTraceMask(const wxString& str);
572 static void ClearTraceMasks();
574 static void SetTimestamp(const wxChar *ts);
575 static const wxChar *GetTimestamp();
577 bool GetVerbose() const { return m_bVerbose; }
579 static wxTraceMask GetTraceMask();
580 static bool IsAllowedTraceMask(const char *mask);
582 // static void TimeStamp(wxString *str);
584 wxString TimeStamp() {
586 wxLog::TimeStamp(&msg);
593 class wxLogStderr : public wxLog
596 wxLogStderr(/* TODO: FILE *fp = (FILE *) NULL*/);
600 class wxLogTextCtrl : public wxLog
603 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
607 class wxLogGui : public wxLog
613 class wxLogWindow : public wxLog
616 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
617 const char *szTitle, // the title of the frame
618 bool bShow = TRUE, // show window immediately?
619 bool bPassToOld = TRUE); // pass log messages to the old target?
621 void Show(bool bShow = TRUE);
622 wxFrame *GetFrame() const;
623 wxLog *GetOldLog() const;
624 bool IsPassingMessages() const;
625 void PassMessages(bool bDoPass) { m_bPassMessages = 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 char* wxSysErrorMsg(unsigned long nErrCode = 0);
650 void wxLogFatalError(const char *szFormat);
651 void wxLogError(const char *szFormat);
652 void wxLogWarning(const char *szFormat);
653 void wxLogMessage(const char *szFormat);
654 void wxLogInfo(const char *szFormat);
655 void wxLogVerbose(const char *szFormat);
656 void wxLogStatus(const char *szFormat);
657 %name(wxLogStatusFrame)void wxLogStatus(wxFrame *pFrame, const char *szFormat);
658 void wxLogSysError(const char *szFormat);
662 // A Log class that can be derived from in wxPython
663 class wxPyLog : public wxLog {
665 wxPyLog() : wxLog() {}
667 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) {
669 wxPyTState* state = wxPyBeginBlockThreads();
670 if ((found = wxPyCBH_findCallback(m_myInst, "DoLog")))
671 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(isi)", level, szString, t));
672 wxPyEndBlockThreads(state);
674 wxLog::DoLog(level, szString, t);
677 virtual void DoLogString(const wxChar *szString, time_t t) {
679 wxPyTState* state = wxPyBeginBlockThreads();
680 if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString")))
681 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(si)", szString, t));
682 wxPyEndBlockThreads(state);
684 wxLog::DoLogString(szString, t);
691 // Now tell SWIG about it
692 class wxPyLog : public wxLog {
695 void _setCallbackInfo(PyObject* self, PyObject* _class);
696 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyLog)"
697 %addmethods { void Destroy() { delete self; } }
702 //----------------------------------------------------------------------
711 class wxProcessEvent : public wxEvent {
713 wxProcessEvent(int id = 0, int pid = 0, int exitcode = 0);
716 int m_pid, m_exitcode;
722 %{ // C++ version of wxProcess derived class
724 class wxPyProcess : public wxProcess {
726 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1)
727 : wxProcess(parent, id)
730 DEC_PYCALLBACK_VOID_INTINT(OnTerminate);
735 IMP_PYCALLBACK_VOID_INTINT( wxPyProcess, wxProcess, OnTerminate);
740 %name(wxProcess)class wxPyProcess : public wxEvtHandler {
742 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1);
743 %addmethods { void Destroy() { delete self; } }
745 void _setCallbackInfo(PyObject* self, PyObject* _class);
746 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxProcess)"
748 void base_OnTerminate(int pid, int status);
754 wxInputStream *GetInputStream();
755 wxInputStream *GetErrorStream();
756 wxOutputStream *GetOutputStream();
763 long wxExecute(const wxString& command,
765 wxPyProcess *process = NULL);
767 //----------------------------------------------------------------------
770 #if !wxUSE_JOYSTICK && !defined(__WXMSW__)
771 // A C++ stub class for wxJoystick for platforms that don't have it.
772 class wxJoystick : public wxObject {
774 wxJoystick(int joystick = wxJOYSTICK1) {
775 wxPyTState* state = wxPyBeginBlockThreads();
776 PyErr_SetString(PyExc_NotImplementedError, "wxJoystick is not available on this platform.");
777 wxPyEndBlockThreads(state);
779 wxPoint GetPosition() { return wxPoint(-1,-1); }
780 int GetZPosition() { return -1; }
781 int GetButtonState() { return -1; }
782 int GetPOVPosition() { return -1; }
783 int GetPOVCTSPosition() { return -1; }
784 int GetRudderPosition() { return -1; }
785 int GetUPosition() { return -1; }
786 int GetVPosition() { return -1; }
787 int GetMovementThreshold() { return -1; }
788 void SetMovementThreshold(int threshold) {}
790 bool IsOk(void) { return FALSE; }
791 int GetNumberJoysticks() { return -1; }
792 int GetManufacturerId() { return -1; }
793 int GetProductId() { return -1; }
794 wxString GetProductName() { return ""; }
795 int GetXMin() { return -1; }
796 int GetYMin() { return -1; }
797 int GetZMin() { return -1; }
798 int GetXMax() { return -1; }
799 int GetYMax() { return -1; }
800 int GetZMax() { return -1; }
801 int GetNumberButtons() { return -1; }
802 int GetNumberAxes() { return -1; }
803 int GetMaxButtons() { return -1; }
804 int GetMaxAxes() { return -1; }
805 int GetPollingMin() { return -1; }
806 int GetPollingMax() { return -1; }
807 int GetRudderMin() { return -1; }
808 int GetRudderMax() { return -1; }
809 int GetUMin() { return -1; }
810 int GetUMax() { return -1; }
811 int GetVMin() { return -1; }
812 int GetVMax() { return -1; }
814 bool HasRudder() { return FALSE; }
815 bool HasZ() { return FALSE; }
816 bool HasU() { return FALSE; }
817 bool HasV() { return FALSE; }
818 bool HasPOV() { return FALSE; }
819 bool HasPOV4Dir() { return FALSE; }
820 bool HasPOVCTS() { return FALSE; }
822 bool SetCapture(wxWindow* win, int pollingFreq = 0) { return FALSE; }
823 bool ReleaseCapture() { return FALSE; }
829 class wxJoystick : public wxObject {
831 wxJoystick(int joystick = wxJOYSTICK1);
834 wxPoint GetPosition();
836 int GetButtonState();
837 int GetPOVPosition();
838 int GetPOVCTSPosition();
839 int GetRudderPosition();
842 int GetMovementThreshold();
843 void SetMovementThreshold(int threshold) ;
846 int GetNumberJoysticks();
847 int GetManufacturerId();
849 wxString GetProductName();
856 int GetNumberButtons();
877 bool SetCapture(wxWindow* win, int pollingFreq = 0);
878 bool ReleaseCapture();
881 //----------------------------------------------------------------------
885 // A C++ stub class for wxWave for platforms that don't have it.
886 class wxWave : public wxObject
889 wxWave(const wxString& fileName, bool isResource = FALSE) {
890 wxPyTState* state = wxPyBeginBlockThreads();
891 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
892 wxPyEndBlockThreads(state);
894 wxWave(int size, const wxByte* data) {
895 wxPyTState* state = wxPyBeginBlockThreads();
896 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
897 wxPyEndBlockThreads(state);
902 bool IsOk() const { return FALSE; }
903 bool Play(bool async = TRUE, bool looped = FALSE) const { return FALSE; }
909 class wxWave : public wxObject
912 wxWave(const wxString& fileName, bool isResource = FALSE);
916 bool Play(bool async = TRUE, bool looped = FALSE) const;
919 %new wxWave* wxWaveData(const wxString& data);
920 %{ // Implementations of some alternate "constructors"
921 wxWave* wxWaveData(const wxString& data) {
922 return new wxWave(data.Len(), (wxByte*)data.c_str());
927 //----------------------------------------------------------------------
931 wxMAILCAP_STANDARD = 1,
932 wxMAILCAP_NETSCAPE = 2,
946 wxFileTypeInfo(const char *mimeType,
948 const char *printCmd,
952 // the array elements correspond to the parameters of the ctor above in
954 %name(wxFileTypeInfoSequence)wxFileTypeInfo(const wxArrayString& sArray);
956 // invalid item - use this to terminate the array passed to
957 // wxMimeTypesManager::AddFallbacks
958 %name(wxNullFileTypeInfo)wxFileTypeInfo();
961 // test if this object can be used
962 bool IsValid() const;
966 void SetIcon(const wxString& iconFile, int iconIndex = 0);
968 // set the short desc
969 void SetShortDesc(const wxString& shortDesc);
973 const wxString& GetMimeType() const;
974 // get the open command
975 const wxString& GetOpenCommand() const;
976 // get the print command
977 const wxString& GetPrintCommand() const;
978 // get the short description (only used under Win32 so far)
979 const wxString& GetShortDesc() const;
980 // get the long, user visible description
981 const wxString& GetDescription() const;
984 // get the array of all extensions
985 //const wxArrayString& GetExtensions() const;
987 PyObject* GetExtensions() {
988 wxArrayString& arr = (wxArrayString&)self->GetExtensions();
989 return wxArrayString2PyList_helper(arr);
993 int GetExtensionsCount() const;
996 const wxString& GetIconFile() const;
997 int GetIconIndex() const;
1007 // TODO: Make a wxPyMessageParameters with virtual GetParamValue...
1009 // An object of this class must be passed to Get{Open|Print}Command. The
1010 // default implementation is trivial and doesn't know anything at all about
1011 // parameters, only filename and MIME type are used (so it's probably ok for
1012 // Windows where %{param} is not used anyhow)
1013 class MessageParameters
1017 MessageParameters(const wxString& filename=wxPyEmptyStr,
1018 const wxString& mimetype=wxPyEmptyStr);
1020 // accessors (called by GetOpenCommand)
1022 const wxString& GetFileName() const;
1024 const wxString& GetMimeType() const;;
1026 // override this function in derived class
1027 virtual wxString GetParamValue(const wxString& name) const;
1029 // virtual dtor as in any base class
1030 virtual ~MessageParameters();
1034 // ctor from static data
1035 wxFileType(const wxFileTypeInfo& ftInfo);
1037 // return the MIME type for this file type
1039 PyObject* GetMimeType() {
1041 if (self->GetMimeType(&str))
1042 return PyString_FromString(str.c_str());
1046 PyObject* GetMimeTypes() {
1048 if (self->GetMimeTypes(arr))
1049 return wxArrayString2PyList_helper(arr);
1056 // Get all extensions associated with this file type
1058 PyObject* GetExtensions() {
1060 if (self->GetExtensions(arr))
1061 return wxArrayString2PyList_helper(arr);
1069 // Get the icon corresponding to this file type
1070 %new wxIcon* GetIcon() {
1072 if (self->GetIcon(&icon))
1073 return new wxIcon(icon);
1078 // Get the icon corresponding to this file type, the name of the file
1079 // where this icon resides, and its index in this file if applicable.
1080 PyObject* GetIconInfo() {
1084 if (self->GetIcon(&icon, &iconFile, &iconIndex)) {
1085 wxPyTState* state = wxPyBeginBlockThreads();
1086 PyObject* tuple = PyTuple_New(3);
1087 PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(icon),
1089 PyTuple_SetItem(tuple, 1, PyString_FromString(iconFile.c_str()));
1090 PyTuple_SetItem(tuple, 2, PyInt_FromLong(iconIndex));
1091 wxPyEndBlockThreads(state);
1100 // get a brief file type description ("*.txt" => "text document")
1101 PyObject* GetDescription() {
1103 if (self->GetDescription(&str))
1104 return PyString_FromString(str.c_str());
1111 // get the command to open/execute the file of given type
1113 PyObject* GetOpenCommand(const wxString& filename,
1114 const wxString& mimetype=wxPyEmptyStr) {
1116 if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype)))
1117 return PyString_FromString(str.c_str());
1124 // get the command to print the file of given type
1126 PyObject* GetPrintCommand(const wxString& filename,
1127 const wxString& mimetype=wxPyEmptyStr) {
1129 if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype)))
1130 return PyString_FromString(str.c_str());
1137 // Get all commands defined for this file type
1139 PyObject* GetAllCommands(const wxString& filename,
1140 const wxString& mimetype=wxPyEmptyStr) {
1141 wxArrayString verbs;
1142 wxArrayString commands;
1143 if (self->GetAllCommands(&verbs, &commands,
1144 wxFileType::MessageParameters(filename, mimetype))) {
1145 wxPyTState* state = wxPyBeginBlockThreads();
1146 PyObject* tuple = PyTuple_New(2);
1147 PyTuple_SetItem(tuple, 0, wxArrayString2PyList_helper(verbs));
1148 PyTuple_SetItem(tuple, 1, wxArrayString2PyList_helper(commands));
1149 wxPyEndBlockThreads(state);
1158 // set an arbitrary command, ask confirmation if it already exists and
1159 // overwriteprompt is TRUE
1160 bool SetCommand(const wxString& cmd, const wxString& verb,
1161 bool overwriteprompt = TRUE);
1163 bool SetDefaultIcon(const wxString& cmd = wxEmptyString, int index = 0);
1166 // remove the association for this filetype from the system MIME database:
1167 // notice that it will only work if the association is defined in the user
1168 // file/registry part, we will never modify the system-wide settings
1172 // expand a string in the format of GetOpenCommand (which may contain
1173 // '%s' and '%t' format specificators for the file name and mime type
1174 // and %{param} constructions).
1175 static wxString ExpandCommand(const wxString& command,
1176 const MessageParameters& params);
1178 // dtor (not virtual, shouldn't be derived from)
1186 class wxMimeTypesManager
1189 // static helper functions
1190 // -----------------------
1192 // check if the given MIME type is the same as the other one: the
1193 // second argument may contain wildcards ('*'), but not the first. If
1194 // the types are equal or if the mimeType matches wildcard the function
1195 // returns TRUE, otherwise it returns FALSE
1196 static bool IsOfType(const wxString& mimeType, const wxString& wildcard);
1199 wxMimeTypesManager();
1201 // loads data from standard files according to the mailcap styles
1202 // specified: this is a bitwise OR of wxMailcapStyle values
1204 // use the extraDir parameter if you want to look for files in another
1206 void Initialize(int mailcapStyle = wxMAILCAP_STANDARD,
1207 const wxString& extraDir = wxEmptyString);
1209 // and this function clears all the data from the manager
1212 // Database lookup: all functions return a pointer to wxFileType object
1213 // whose methods may be used to query it for the information you're
1214 // interested in. If the return value is !NULL, caller is responsible for
1216 // get file type from file extension
1217 %new wxFileType *GetFileTypeFromExtension(const wxString& ext);
1219 // get file type from MIME type (in format <category>/<format>)
1220 %new wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
1222 // other operations: return TRUE if there were no errors or FALSE if there
1223 // were some unreckognized entries (the good entries are always read anyhow)
1226 // read in additional file (the standard ones are read automatically)
1227 // in mailcap format (see mimetype.cpp for description)
1229 // 'fallback' parameter may be set to TRUE to avoid overriding the
1230 // settings from other, previously parsed, files by this one: normally,
1231 // the files read most recently would override the older files, but with
1232 // fallback == TRUE this won't happen
1233 bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
1235 // read in additional file in mime.types format
1236 bool ReadMimeTypes(const wxString& filename);
1238 // enumerate all known MIME types
1240 PyObject* EnumAllFileTypes() {
1242 self->EnumAllFileTypes(arr);
1243 return wxArrayString2PyList_helper(arr);
1247 // these functions can be used to provide default values for some of the
1248 // MIME types inside the program itself (you may also use
1249 // ReadMailcap(filenameWithDefaultTypes, TRUE /* use as fallback */) to
1250 // achieve the same goal, but this requires having this info in a file).
1252 void AddFallback(const wxFileTypeInfo& ft);
1255 // create or remove associations
1257 // create a new association using the fields of wxFileTypeInfo (at least
1258 // the MIME type and the extension should be set)
1259 // if the other fields are empty, the existing values should be left alone
1260 %new wxFileType *Associate(const wxFileTypeInfo& ftInfo);
1263 bool Unassociate(wxFileType *ft) ;
1265 // dtor (not virtual, shouldn't be derived from)
1266 ~wxMimeTypesManager();
1274 extern wxMimeTypesManager* wxTheMimeTypesManager;
1280 //----------------------------------------------------------------------
1281 //----------------------------------------------------------------------
1285 wxPyPtrTypeMap_Add("wxFontEnumerator", "wxPyFontEnumerator");
1286 wxPyPtrTypeMap_Add("wxDragImage", "wxGenericDragImage");
1287 wxPyPtrTypeMap_Add("wxProcess", "wxPyProcess");
1290 //----------------------------------------------------------------------