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 //---------------------------------------------------------------------------
180 wxSYS_OEM_FIXED_FONT,
181 wxSYS_ANSI_FIXED_FONT,
184 wxSYS_DEVICE_DEFAULT_FONT,
185 wxSYS_DEFAULT_PALETTE,
186 wxSYS_SYSTEM_FIXED_FONT,
187 wxSYS_DEFAULT_GUI_FONT,
189 wxSYS_COLOUR_SCROLLBAR,
190 wxSYS_COLOUR_BACKGROUND,
191 wxSYS_COLOUR_ACTIVECAPTION,
192 wxSYS_COLOUR_INACTIVECAPTION,
195 wxSYS_COLOUR_WINDOWFRAME,
196 wxSYS_COLOUR_MENUTEXT,
197 wxSYS_COLOUR_WINDOWTEXT,
198 wxSYS_COLOUR_CAPTIONTEXT,
199 wxSYS_COLOUR_ACTIVEBORDER,
200 wxSYS_COLOUR_INACTIVEBORDER,
201 wxSYS_COLOUR_APPWORKSPACE,
202 wxSYS_COLOUR_HIGHLIGHT,
203 wxSYS_COLOUR_HIGHLIGHTTEXT,
204 wxSYS_COLOUR_BTNFACE,
205 wxSYS_COLOUR_BTNSHADOW,
206 wxSYS_COLOUR_GRAYTEXT,
207 wxSYS_COLOUR_BTNTEXT,
208 wxSYS_COLOUR_INACTIVECAPTIONTEXT,
209 wxSYS_COLOUR_BTNHIGHLIGHT,
211 wxSYS_COLOUR_3DDKSHADOW,
212 wxSYS_COLOUR_3DLIGHT,
213 wxSYS_COLOUR_INFOTEXT,
216 wxSYS_COLOUR_DESKTOP,
218 wxSYS_COLOUR_3DSHADOW,
219 wxSYS_COLOUR_3DHIGHLIGHT,
220 wxSYS_COLOUR_3DHILIGHT,
221 wxSYS_COLOUR_BTNHILIGHT,
234 wxSYS_HSCROLL_ARROW_X,
235 wxSYS_HSCROLL_ARROW_Y,
251 wxSYS_VSCROLL_ARROW_X,
252 wxSYS_VSCROLL_ARROW_Y,
256 wxSYS_NETWORK_PRESENT,
257 wxSYS_PENWINDOWS_PRESENT,
266 wxColour wxSystemSettings_GetSystemColour(int index) {
267 return wxSystemSettings::GetSystemColour(index);
270 wxFont wxSystemSettings_GetSystemFont(int index) {
271 return wxSystemSettings::GetSystemFont(index);
274 int wxSystemSettings_GetSystemMetric(int index) {
275 return wxSystemSettings::GetSystemMetric(index);
279 //---------------------------------------------------------------------------
282 class wxToolTip : public wxObject {
284 wxToolTip(const wxString &tip);
286 void SetTip(const wxString& tip);
288 // *** Not in the "public" interface void SetWindow(wxWindow *win);
289 wxWindow *GetWindow();
291 static void Enable(bool flag);
292 static void SetDelay(long milliseconds);
295 //----------------------------------------------------------------------
299 wxCaret(wxWindow* window, const wxSize& size);
304 %name(GetPositionTuple)void GetPosition(int *OUTPUT, int *OUTPUT);
305 wxPoint GetPosition();
306 %name(GetSizeTuple)void GetSize(int *OUTPUT, int *OUTPUT);
308 wxWindow *GetWindow();
309 %name(MoveXY)void Move(int x, int y);
310 void Move(const wxPoint& pt);
311 %name(SetSizeWH) void SetSize(int width, int height);
312 void SetSize(const wxSize& size);
313 void Show(int show = TRUE);
318 int wxCaret_GetBlinkTime() {
319 return wxCaret::GetBlinkTime();
322 void wxCaret_SetBlinkTime(int milliseconds) {
323 wxCaret::SetBlinkTime(milliseconds);
327 //----------------------------------------------------------------------
330 class wxPyFontEnumerator : public wxFontEnumerator {
332 wxPyFontEnumerator() {}
333 ~wxPyFontEnumerator() {}
335 DEC_PYCALLBACK_BOOL_STRING(OnFacename);
336 DEC_PYCALLBACK_BOOL_STRINGSTRING(OnFontEncoding);
341 IMP_PYCALLBACK_BOOL_STRING(wxPyFontEnumerator, wxFontEnumerator, OnFacename);
342 IMP_PYCALLBACK_BOOL_STRINGSTRING(wxPyFontEnumerator, wxFontEnumerator, OnFontEncoding);
346 %name(wxFontEnumerator) class wxPyFontEnumerator {
348 wxPyFontEnumerator();
349 ~wxPyFontEnumerator();
350 void _setCallbackInfo(PyObject* self, PyObject* _class, bool incref);
351 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFontEnumerator, 0)"
353 bool EnumerateFacenames(
354 wxFontEncoding encoding = wxFONTENCODING_SYSTEM, // all
355 bool fixedWidthOnly = FALSE);
356 bool EnumerateEncodings(const char* facename = "");
358 //wxArrayString* GetEncodings();
359 //wxArrayString* GetFacenames();
361 PyObject* GetEncodings() {
362 wxArrayString* arr = self->GetEncodings();
363 return wxArrayString2PyList_helper(*arr);
366 PyObject* GetFacenames() {
367 wxArrayString* arr = self->GetFacenames();
368 return wxArrayString2PyList_helper(*arr);
373 //----------------------------------------------------------------------
377 wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR);
381 //----------------------------------------------------------------------
383 class wxWindowDisabler {
385 wxWindowDisabler(wxWindow *winToSkip = NULL);
389 //----------------------------------------------------------------------
391 bool wxSafeYield(wxWindow* win=NULL);
392 void wxPostEvent(wxEvtHandler *dest, wxEvent& event);
397 void wxWakeUpMainThread();
400 void wxMutexGuiEnter();
401 void wxMutexGuiLeave();
404 class wxMutexGuiLocker {
412 bool wxThread_IsMain() {
413 #ifdef WXP_WITH_THREAD
414 return wxThread::IsMain();
421 //----------------------------------------------------------------------
427 // wxTipProvider(size_t currentTip); **** Abstract base class
430 virtual wxString GetTip() = 0;
431 size_t GetCurrentTip();
436 // The C++ version of wxPyTipProvider
438 class wxPyTipProvider : public wxTipProvider {
440 wxPyTipProvider(size_t currentTip)
441 : wxTipProvider(currentTip) {}
443 DEC_PYCALLBACK_STRING__pure(GetTip);
448 IMP_PYCALLBACK_STRING__pure( wxPyTipProvider, wxTipProvider, GetTip);
453 // Now let SWIG know about it
454 class wxPyTipProvider : public wxTipProvider {
456 wxPyTipProvider(size_t currentTip);
461 bool wxShowTip(wxWindow *parent, wxTipProvider *tipProvider, bool showAtStartup = TRUE);
462 %new wxTipProvider * wxCreateFileTipProvider(const wxString& filename, size_t currentTip);
465 //----------------------------------------------------------------------
468 #include <wx/generic/dragimgg.h>
471 %name (wxDragImage) class wxGenericDragImage : public wxObject
475 wxGenericDragImage(const wxBitmap& image,
476 const wxCursor& cursor = wxNullCursor);
477 %name(wxDragIcon)wxGenericDragImage(const wxIcon& image,
478 const wxCursor& cursor = wxNullCursor);
479 %name(wxDragString)wxGenericDragImage(const wxString& str,
480 const wxCursor& cursor = wxNullCursor);
481 %name(wxDragTreeItem)wxGenericDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
482 %name(wxDragListItem)wxGenericDragImage(const wxListCtrl& listCtrl, long id);
484 ~wxGenericDragImage();
486 void SetBackingBitmap(wxBitmap* bitmap);
487 bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
488 bool fullScreen = FALSE, wxRect* rect = NULL);
490 %name(BeginDrag2) bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
491 wxWindow* fullScreenRect);
494 bool Move(const wxPoint& pt);
498 wxRect GetImageRect(const wxPoint& pos) const;
499 bool RedrawImage(const wxPoint& oldPos, const wxPoint& newPos,
500 bool eraseOld, bool drawNew);
504 //----------------------------------------------------------------------
506 class wxPyTimer : public wxObject {
508 wxPyTimer(PyObject* notify);
513 void SetOwner(wxEvtHandler *owner, int id = -1);
514 void Start(int milliseconds=-1, int oneShot=FALSE);
522 // ctor starts the stop watch
524 void Start(long t = 0);
528 // get elapsed time since the last Start() or Pause() in milliseconds
533 //----------------------------------------------------------------------
534 //----------------------------------------------------------------------
539 wxLOG_FatalError, // program can't continue, abort immediately
540 wxLOG_Error, // a serious error, user must be informed about it
541 wxLOG_Warning, // user is normally informed about it but may be ignored
542 wxLOG_Message, // normal message (i.e. normal output of a non GUI app)
543 wxLOG_Info, // informational message (a.k.a. 'Verbose')
544 wxLOG_Status, // informational: might go to the status line of GUI app
545 wxLOG_Debug, // never shown to the user, disabled in release mode
546 wxLOG_Trace, // trace messages are also only enabled in debug mode
547 wxLOG_Progress, // used for progress indicator (not yet)
548 wxLOG_User = 100 // user defined levels start here
557 static bool IsEnabled();
558 static bool EnableLogging(bool doIt = TRUE);
559 static void OnLog(wxLogLevel level, const char *szString, int t=0);
561 virtual void Flush();
562 bool HasPendingMessages() const;
564 static void FlushActive();
565 static wxLog *GetActiveTarget();
566 static wxLog *SetActiveTarget(wxLog *pLogger);
568 static void Suspend();
569 static void Resume();
571 void SetVerbose(bool bVerbose = TRUE);
573 static void DontCreateOnDemand();
574 static void SetTraceMask(wxTraceMask ulMask);
575 static void AddTraceMask(const wxString& str);
576 static void RemoveTraceMask(const wxString& str);
577 static void ClearTraceMasks();
579 static void SetTimestamp(const wxChar *ts);
580 static const wxChar *GetTimestamp();
582 bool GetVerbose() const { return m_bVerbose; }
584 static wxTraceMask GetTraceMask();
585 static bool IsAllowedTraceMask(const char *mask);
587 // static void TimeStamp(wxString *str);
589 wxString TimeStamp() {
591 wxLog::TimeStamp(&msg);
598 class wxLogStderr : public wxLog
601 wxLogStderr(/* TODO: FILE *fp = (FILE *) NULL*/);
605 class wxLogTextCtrl : public wxLog
608 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
612 class wxLogGui : public wxLog
618 class wxLogWindow : public wxLog
621 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
622 const char *szTitle, // the title of the frame
623 bool bShow = TRUE, // show window immediately?
624 bool bPassToOld = TRUE); // pass log messages to the old target?
626 void Show(bool bShow = TRUE);
627 wxFrame *GetFrame() const;
628 wxLog *GetOldLog() const;
629 bool IsPassingMessages() const;
630 void PassMessages(bool bDoPass) { m_bPassMessages = bDoPass; }
642 class wxLogChain : public wxLog
645 wxLogChain(wxLog *logger);
646 void SetLog(wxLog *logger);
647 void PassMessages(bool bDoPass);
648 bool IsPassingMessages();
653 unsigned long wxSysErrorCode();
654 const char* wxSysErrorMsg(unsigned long nErrCode = 0);
655 void wxLogFatalError(const char *szFormat);
656 void wxLogError(const char *szFormat);
657 void wxLogWarning(const char *szFormat);
658 void wxLogMessage(const char *szFormat);
659 void wxLogInfo(const char *szFormat);
660 void wxLogVerbose(const char *szFormat);
661 void wxLogStatus(const char *szFormat);
662 %name(wxLogStatusFrame)void wxLogStatus(wxFrame *pFrame, const char *szFormat);
663 void wxLogSysError(const char *szFormat);
667 // A Log class that can be derived from in wxPython
668 class wxPyLog : public wxLog {
670 wxPyLog() : wxLog() {}
672 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) {
674 wxPyBeginBlockThreads();
675 if ((found = wxPyCBH_findCallback(m_myInst, "DoLog")))
676 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(isi)", level, szString, t));
677 wxPyEndBlockThreads();
679 wxLog::DoLog(level, szString, t);
682 virtual void DoLogString(const wxChar *szString, time_t t) {
684 wxPyBeginBlockThreads();
685 if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString")))
686 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(si)", szString, t));
687 wxPyEndBlockThreads();
689 wxLog::DoLogString(szString, t);
696 // Now tell SWIG about it
697 class wxPyLog : public wxLog {
700 void _setCallbackInfo(PyObject* self, PyObject* _class);
701 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyLog)"
702 %addmethods { void Destroy() { delete self; } }
707 //----------------------------------------------------------------------
716 class wxProcessEvent : public wxEvent {
718 wxProcessEvent(int id = 0, int pid = 0, int exitcode = 0);
721 int m_pid, m_exitcode;
727 %{ // C++ version of wxProcess derived class
729 class wxPyProcess : public wxProcess {
731 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1)
732 : wxProcess(parent, id)
735 DEC_PYCALLBACK_VOID_INTINT(OnTerminate);
740 IMP_PYCALLBACK_VOID_INTINT( wxPyProcess, wxProcess, OnTerminate);
745 %name(wxProcess)class wxPyProcess : public wxEvtHandler {
747 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1);
748 %addmethods { void Destroy() { delete self; } }
750 void _setCallbackInfo(PyObject* self, PyObject* _class);
751 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxProcess)"
753 void base_OnTerminate(int pid, int status);
759 wxInputStream *GetInputStream();
760 wxInputStream *GetErrorStream();
761 wxOutputStream *GetOutputStream();
768 long wxExecute(const wxString& command,
770 wxPyProcess *process = NULL);
772 //----------------------------------------------------------------------
775 #if !wxUSE_JOYSTICK && !defined(__WXMSW__)
776 // A C++ stub class for wxJoystick for platforms that don't have it.
777 class wxJoystick : public wxObject {
779 wxJoystick(int joystick = wxJOYSTICK1) {
780 wxPyBeginBlockThreads();
781 PyErr_SetString(PyExc_NotImplementedError, "wxJoystick is not available on this platform.");
782 wxPyEndBlockThreads();
784 wxPoint GetPosition() { return wxPoint(-1,-1); }
785 int GetZPosition() { return -1; }
786 int GetButtonState() { return -1; }
787 int GetPOVPosition() { return -1; }
788 int GetPOVCTSPosition() { return -1; }
789 int GetRudderPosition() { return -1; }
790 int GetUPosition() { return -1; }
791 int GetVPosition() { return -1; }
792 int GetMovementThreshold() { return -1; }
793 void SetMovementThreshold(int threshold) {}
795 bool IsOk(void) { return FALSE; }
796 int GetNumberJoysticks() { return -1; }
797 int GetManufacturerId() { return -1; }
798 int GetProductId() { return -1; }
799 wxString GetProductName() { return ""; }
800 int GetXMin() { return -1; }
801 int GetYMin() { return -1; }
802 int GetZMin() { return -1; }
803 int GetXMax() { return -1; }
804 int GetYMax() { return -1; }
805 int GetZMax() { return -1; }
806 int GetNumberButtons() { return -1; }
807 int GetNumberAxes() { return -1; }
808 int GetMaxButtons() { return -1; }
809 int GetMaxAxes() { return -1; }
810 int GetPollingMin() { return -1; }
811 int GetPollingMax() { return -1; }
812 int GetRudderMin() { return -1; }
813 int GetRudderMax() { return -1; }
814 int GetUMin() { return -1; }
815 int GetUMax() { return -1; }
816 int GetVMin() { return -1; }
817 int GetVMax() { return -1; }
819 bool HasRudder() { return FALSE; }
820 bool HasZ() { return FALSE; }
821 bool HasU() { return FALSE; }
822 bool HasV() { return FALSE; }
823 bool HasPOV() { return FALSE; }
824 bool HasPOV4Dir() { return FALSE; }
825 bool HasPOVCTS() { return FALSE; }
827 bool SetCapture(wxWindow* win, int pollingFreq = 0) { return FALSE; }
828 bool ReleaseCapture() { return FALSE; }
834 class wxJoystick : public wxObject {
836 wxJoystick(int joystick = wxJOYSTICK1);
839 wxPoint GetPosition();
841 int GetButtonState();
842 int GetPOVPosition();
843 int GetPOVCTSPosition();
844 int GetRudderPosition();
847 int GetMovementThreshold();
848 void SetMovementThreshold(int threshold) ;
851 int GetNumberJoysticks();
852 int GetManufacturerId();
854 wxString GetProductName();
861 int GetNumberButtons();
882 bool SetCapture(wxWindow* win, int pollingFreq = 0);
883 bool ReleaseCapture();
886 //----------------------------------------------------------------------
890 // A C++ stub class for wxWave for platforms that don't have it.
891 class wxWave : public wxObject
894 wxWave(const wxString& fileName, bool isResource = FALSE) {
895 wxPyBeginBlockThreads();
896 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
897 wxPyEndBlockThreads();
899 wxWave(int size, const wxByte* data) {
900 wxPyBeginBlockThreads();
901 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
902 wxPyEndBlockThreads();
907 bool IsOk() const { return FALSE; }
908 bool Play(bool async = TRUE, bool looped = FALSE) const { return FALSE; }
914 class wxWave : public wxObject
917 wxWave(const wxString& fileName, bool isResource = FALSE);
921 bool Play(bool async = TRUE, bool looped = FALSE) const;
924 %new wxWave* wxWaveData(const wxString& data);
925 %{ // Implementations of some alternate "constructors"
926 wxWave* wxWaveData(const wxString& data) {
927 return new wxWave(data.Len(), (wxByte*)data.c_str());
932 //----------------------------------------------------------------------
936 wxMAILCAP_STANDARD = 1,
937 wxMAILCAP_NETSCAPE = 2,
951 wxFileTypeInfo(const char *mimeType,
953 const char *printCmd,
957 // the array elements correspond to the parameters of the ctor above in
959 %name(wxFileTypeInfoSequence)wxFileTypeInfo(const wxArrayString& sArray);
961 // invalid item - use this to terminate the array passed to
962 // wxMimeTypesManager::AddFallbacks
963 %name(wxNullFileTypeInfo)wxFileTypeInfo();
966 // test if this object can be used
967 bool IsValid() const;
971 void SetIcon(const wxString& iconFile, int iconIndex = 0);
973 // set the short desc
974 void SetShortDesc(const wxString& shortDesc);
978 const wxString& GetMimeType() const;
979 // get the open command
980 const wxString& GetOpenCommand() const;
981 // get the print command
982 const wxString& GetPrintCommand() const;
983 // get the short description (only used under Win32 so far)
984 const wxString& GetShortDesc() const;
985 // get the long, user visible description
986 const wxString& GetDescription() const;
989 // get the array of all extensions
990 //const wxArrayString& GetExtensions() const;
992 PyObject* GetExtensions() {
993 wxArrayString& arr = (wxArrayString&)self->GetExtensions();
994 return wxArrayString2PyList_helper(arr);
998 int GetExtensionsCount() const;
1000 // get the icon info
1001 const wxString& GetIconFile() const;
1002 int GetIconIndex() const;
1012 // TODO: Make a wxPyMessageParameters with virtual GetParamValue...
1014 // An object of this class must be passed to Get{Open|Print}Command. The
1015 // default implementation is trivial and doesn't know anything at all about
1016 // parameters, only filename and MIME type are used (so it's probably ok for
1017 // Windows where %{param} is not used anyhow)
1018 class MessageParameters
1022 MessageParameters(const wxString& filename=wxPyEmptyStr,
1023 const wxString& mimetype=wxPyEmptyStr);
1025 // accessors (called by GetOpenCommand)
1027 const wxString& GetFileName() const;
1029 const wxString& GetMimeType() const;;
1031 // override this function in derived class
1032 virtual wxString GetParamValue(const wxString& name) const;
1034 // virtual dtor as in any base class
1035 virtual ~MessageParameters();
1039 // ctor from static data
1040 wxFileType(const wxFileTypeInfo& ftInfo);
1042 // return the MIME type for this file type
1044 PyObject* GetMimeType() {
1046 if (self->GetMimeType(&str))
1047 return PyString_FromString(str.c_str());
1051 PyObject* GetMimeTypes() {
1053 if (self->GetMimeTypes(arr))
1054 return wxArrayString2PyList_helper(arr);
1061 // Get all extensions associated with this file type
1063 PyObject* GetExtensions() {
1065 if (self->GetExtensions(arr))
1066 return wxArrayString2PyList_helper(arr);
1074 // Get the icon corresponding to this file type
1075 %new wxIcon* GetIcon() {
1077 if (self->GetIcon(&icon))
1078 return new wxIcon(icon);
1083 // Get the icon corresponding to this file type, the name of the file
1084 // where this icon resides, and its index in this file if applicable.
1085 PyObject* GetIconInfo() {
1089 if (self->GetIcon(&icon, &iconFile, &iconIndex)) {
1090 wxPyBeginBlockThreads();
1091 PyObject* tuple = PyTuple_New(3);
1092 PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(icon),
1094 PyTuple_SetItem(tuple, 1, PyString_FromString(iconFile.c_str()));
1095 PyTuple_SetItem(tuple, 2, PyInt_FromLong(iconIndex));
1096 wxPyEndBlockThreads();
1105 // get a brief file type description ("*.txt" => "text document")
1106 PyObject* GetDescription() {
1108 if (self->GetDescription(&str))
1109 return PyString_FromString(str.c_str());
1116 // get the command to open/execute the file of given type
1118 PyObject* GetOpenCommand(const wxString& filename,
1119 const wxString& mimetype=wxPyEmptyStr) {
1121 if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype)))
1122 return PyString_FromString(str.c_str());
1129 // get the command to print the file of given type
1131 PyObject* GetPrintCommand(const wxString& filename,
1132 const wxString& mimetype=wxPyEmptyStr) {
1134 if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype)))
1135 return PyString_FromString(str.c_str());
1142 // Get all commands defined for this file type
1144 PyObject* GetAllCommands(const wxString& filename,
1145 const wxString& mimetype=wxPyEmptyStr) {
1146 wxArrayString verbs;
1147 wxArrayString commands;
1148 if (self->GetAllCommands(&verbs, &commands,
1149 wxFileType::MessageParameters(filename, mimetype))) {
1150 wxPyBeginBlockThreads();
1151 PyObject* tuple = PyTuple_New(2);
1152 PyTuple_SetItem(tuple, 0, wxArrayString2PyList_helper(verbs));
1153 PyTuple_SetItem(tuple, 1, wxArrayString2PyList_helper(commands));
1154 wxPyEndBlockThreads();
1163 // set an arbitrary command, ask confirmation if it already exists and
1164 // overwriteprompt is TRUE
1165 bool SetCommand(const wxString& cmd, const wxString& verb,
1166 bool overwriteprompt = TRUE);
1168 bool SetDefaultIcon(const wxString& cmd = wxEmptyString, int index = 0);
1171 // remove the association for this filetype from the system MIME database:
1172 // notice that it will only work if the association is defined in the user
1173 // file/registry part, we will never modify the system-wide settings
1177 // expand a string in the format of GetOpenCommand (which may contain
1178 // '%s' and '%t' format specificators for the file name and mime type
1179 // and %{param} constructions).
1180 static wxString ExpandCommand(const wxString& command,
1181 const MessageParameters& params);
1183 // dtor (not virtual, shouldn't be derived from)
1191 class wxMimeTypesManager
1194 // static helper functions
1195 // -----------------------
1197 // check if the given MIME type is the same as the other one: the
1198 // second argument may contain wildcards ('*'), but not the first. If
1199 // the types are equal or if the mimeType matches wildcard the function
1200 // returns TRUE, otherwise it returns FALSE
1201 static bool IsOfType(const wxString& mimeType, const wxString& wildcard);
1204 wxMimeTypesManager();
1206 // loads data from standard files according to the mailcap styles
1207 // specified: this is a bitwise OR of wxMailcapStyle values
1209 // use the extraDir parameter if you want to look for files in another
1211 void Initialize(int mailcapStyle = wxMAILCAP_STANDARD,
1212 const wxString& extraDir = wxEmptyString);
1214 // and this function clears all the data from the manager
1217 // Database lookup: all functions return a pointer to wxFileType object
1218 // whose methods may be used to query it for the information you're
1219 // interested in. If the return value is !NULL, caller is responsible for
1221 // get file type from file extension
1222 %new wxFileType *GetFileTypeFromExtension(const wxString& ext);
1224 // get file type from MIME type (in format <category>/<format>)
1225 %new wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
1227 // other operations: return TRUE if there were no errors or FALSE if there
1228 // were some unreckognized entries (the good entries are always read anyhow)
1231 // read in additional file (the standard ones are read automatically)
1232 // in mailcap format (see mimetype.cpp for description)
1234 // 'fallback' parameter may be set to TRUE to avoid overriding the
1235 // settings from other, previously parsed, files by this one: normally,
1236 // the files read most recently would override the older files, but with
1237 // fallback == TRUE this won't happen
1238 bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
1240 // read in additional file in mime.types format
1241 bool ReadMimeTypes(const wxString& filename);
1243 // enumerate all known MIME types
1245 PyObject* EnumAllFileTypes() {
1247 self->EnumAllFileTypes(arr);
1248 return wxArrayString2PyList_helper(arr);
1252 // these functions can be used to provide default values for some of the
1253 // MIME types inside the program itself (you may also use
1254 // ReadMailcap(filenameWithDefaultTypes, TRUE /* use as fallback */) to
1255 // achieve the same goal, but this requires having this info in a file).
1257 void AddFallback(const wxFileTypeInfo& ft);
1260 // create or remove associations
1262 // create a new association using the fields of wxFileTypeInfo (at least
1263 // the MIME type and the extension should be set)
1264 // if the other fields are empty, the existing values should be left alone
1265 %new wxFileType *Associate(const wxFileTypeInfo& ftInfo);
1268 bool Unassociate(wxFileType *ft) ;
1270 // dtor (not virtual, shouldn't be derived from)
1271 ~wxMimeTypesManager();
1279 extern wxMimeTypesManager* wxTheMimeTypesManager;
1285 //----------------------------------------------------------------------
1288 #include <wx/docview.h>
1291 class wxFileHistory : public wxObject
1294 wxFileHistory(int maxFiles = 9);
1298 void AddFileToHistory(const wxString& file);
1299 void RemoveFileFromHistory(int i);
1300 int GetMaxFiles() const;
1301 void UseMenu(wxMenu *menu);
1303 // Remove menu from the list (MDI child may be closing)
1304 void RemoveMenu(wxMenu *menu);
1306 void Load(wxConfigBase& config);
1307 void Save(wxConfigBase& config);
1309 void AddFilesToMenu();
1310 %name(AddFilesToSingleMenu)void AddFilesToMenu(wxMenu* menu);
1313 wxString GetHistoryFile(int i) const;
1315 // A synonym for GetNoHistoryFiles
1316 int GetCount() const;
1317 int GetNoHistoryFiles() const;
1321 //----------------------------------------------------------------------
1322 //----------------------------------------------------------------------
1326 wxPyPtrTypeMap_Add("wxFontEnumerator", "wxPyFontEnumerator");
1327 wxPyPtrTypeMap_Add("wxDragImage", "wxGenericDragImage");
1328 wxPyPtrTypeMap_Add("wxProcess", "wxPyProcess");
1331 //----------------------------------------------------------------------