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);
351 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFontEnumerator)"
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 return wxThread::IsMain();
417 //----------------------------------------------------------------------
423 // wxTipProvider(size_t currentTip); **** Abstract base class
426 virtual wxString GetTip() = 0;
427 size_t GetCurrentTip();
432 // The C++ version of wxPyTipProvider
434 class wxPyTipProvider : public wxTipProvider {
436 wxPyTipProvider(size_t currentTip)
437 : wxTipProvider(currentTip) {}
439 DEC_PYCALLBACK_STRING__pure(GetTip);
444 IMP_PYCALLBACK_STRING__pure( wxPyTipProvider, wxTipProvider, GetTip);
449 // Now let SWIG know about it
450 class wxPyTipProvider : public wxTipProvider {
452 wxPyTipProvider(size_t currentTip);
457 bool wxShowTip(wxWindow *parent, wxTipProvider *tipProvider, bool showAtStartup = TRUE);
458 %new wxTipProvider * wxCreateFileTipProvider(const wxString& filename, size_t currentTip);
461 //----------------------------------------------------------------------
464 #include <wx/generic/dragimgg.h>
467 %name (wxDragImage) class wxGenericDragImage : public wxObject
471 wxGenericDragImage(const wxBitmap& image,
472 const wxCursor& cursor = wxNullCursor);
473 %name(wxDragIcon)wxGenericDragImage(const wxIcon& image,
474 const wxCursor& cursor = wxNullCursor);
475 %name(wxDragString)wxGenericDragImage(const wxString& str,
476 const wxCursor& cursor = wxNullCursor);
477 %name(wxDragTreeItem)wxGenericDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
478 %name(wxDragListItem)wxGenericDragImage(const wxListCtrl& listCtrl, long id);
480 ~wxGenericDragImage();
482 void SetBackingBitmap(wxBitmap* bitmap);
483 bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
484 bool fullScreen = FALSE, wxRect* rect = NULL);
486 %name(BeginDrag2) bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
487 wxWindow* fullScreenRect);
490 bool Move(const wxPoint& pt);
494 wxRect GetImageRect(const wxPoint& pos) const;
495 bool RedrawImage(const wxPoint& oldPos, const wxPoint& newPos,
496 bool eraseOld, bool drawNew);
500 //----------------------------------------------------------------------
502 class wxPyTimer : public wxObject {
504 wxPyTimer(PyObject* notify);
509 void SetOwner(wxEvtHandler *owner, int id = -1);
510 void Start(int milliseconds=-1, int oneShot=FALSE);
518 // ctor starts the stop watch
520 void Start(long t = 0);
524 // get elapsed time since the last Start() or Pause() in milliseconds
529 //----------------------------------------------------------------------
530 //----------------------------------------------------------------------
535 wxLOG_FatalError, // program can't continue, abort immediately
536 wxLOG_Error, // a serious error, user must be informed about it
537 wxLOG_Warning, // user is normally informed about it but may be ignored
538 wxLOG_Message, // normal message (i.e. normal output of a non GUI app)
539 wxLOG_Info, // informational message (a.k.a. 'Verbose')
540 wxLOG_Status, // informational: might go to the status line of GUI app
541 wxLOG_Debug, // never shown to the user, disabled in release mode
542 wxLOG_Trace, // trace messages are also only enabled in debug mode
543 wxLOG_Progress, // used for progress indicator (not yet)
544 wxLOG_User = 100 // user defined levels start here
553 static bool IsEnabled();
554 static bool EnableLogging(bool doIt = TRUE);
555 static void OnLog(wxLogLevel level, const char *szString, int t=0);
557 virtual void Flush();
558 bool HasPendingMessages() const;
560 static void FlushActive();
561 static wxLog *GetActiveTarget();
562 static wxLog *SetActiveTarget(wxLog *pLogger);
564 static void Suspend();
565 static void Resume();
567 void SetVerbose(bool bVerbose = TRUE);
569 static void DontCreateOnDemand();
570 static void SetTraceMask(wxTraceMask ulMask);
571 static void AddTraceMask(const wxString& str);
572 static void RemoveTraceMask(const wxString& str);
573 static void ClearTraceMasks();
575 static void SetTimestamp(const wxChar *ts);
576 static const wxChar *GetTimestamp();
578 bool GetVerbose() const { return m_bVerbose; }
580 static wxTraceMask GetTraceMask();
581 static bool IsAllowedTraceMask(const char *mask);
583 // static void TimeStamp(wxString *str);
585 wxString TimeStamp() {
587 wxLog::TimeStamp(&msg);
594 class wxLogStderr : public wxLog
597 wxLogStderr(/* TODO: FILE *fp = (FILE *) NULL*/);
601 class wxLogTextCtrl : public wxLog
604 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
608 class wxLogGui : public wxLog
614 class wxLogWindow : public wxLog
617 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
618 const char *szTitle, // the title of the frame
619 bool bShow = TRUE, // show window immediately?
620 bool bPassToOld = TRUE); // pass log messages to the old target?
622 void Show(bool bShow = TRUE);
623 wxFrame *GetFrame() const;
624 wxLog *GetOldLog() const;
625 bool IsPassingMessages() const;
626 void PassMessages(bool bDoPass) { m_bPassMessages = bDoPass; }
638 class wxLogChain : public wxLog
641 wxLogChain(wxLog *logger);
642 void SetLog(wxLog *logger);
643 void PassMessages(bool bDoPass);
644 bool IsPassingMessages();
649 unsigned long wxSysErrorCode();
650 const char* wxSysErrorMsg(unsigned long nErrCode = 0);
651 void wxLogFatalError(const char *szFormat);
652 void wxLogError(const char *szFormat);
653 void wxLogWarning(const char *szFormat);
654 void wxLogMessage(const char *szFormat);
655 void wxLogInfo(const char *szFormat);
656 void wxLogVerbose(const char *szFormat);
657 void wxLogStatus(const char *szFormat);
658 %name(wxLogStatusFrame)void wxLogStatus(wxFrame *pFrame, const char *szFormat);
659 void wxLogSysError(const char *szFormat);
663 // A Log class that can be derived from in wxPython
664 class wxPyLog : public wxLog {
666 wxPyLog() : wxLog() {}
668 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) {
670 wxPyTState* state = wxPyBeginBlockThreads();
671 if ((found = wxPyCBH_findCallback(m_myInst, "DoLog")))
672 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(isi)", level, szString, t));
673 wxPyEndBlockThreads(state);
675 wxLog::DoLog(level, szString, t);
678 virtual void DoLogString(const wxChar *szString, time_t t) {
680 wxPyTState* state = wxPyBeginBlockThreads();
681 if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString")))
682 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(si)", szString, t));
683 wxPyEndBlockThreads(state);
685 wxLog::DoLogString(szString, t);
692 // Now tell SWIG about it
693 class wxPyLog : public wxLog {
696 void _setCallbackInfo(PyObject* self, PyObject* _class);
697 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyLog)"
698 %addmethods { void Destroy() { delete self; } }
703 //----------------------------------------------------------------------
712 class wxProcessEvent : public wxEvent {
714 wxProcessEvent(int id = 0, int pid = 0, int exitcode = 0);
717 int m_pid, m_exitcode;
723 %{ // C++ version of wxProcess derived class
725 class wxPyProcess : public wxProcess {
727 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1)
728 : wxProcess(parent, id)
731 DEC_PYCALLBACK_VOID_INTINT(OnTerminate);
736 IMP_PYCALLBACK_VOID_INTINT( wxPyProcess, wxProcess, OnTerminate);
741 %name(wxProcess)class wxPyProcess : public wxEvtHandler {
743 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1);
744 %addmethods { void Destroy() { delete self; } }
746 void _setCallbackInfo(PyObject* self, PyObject* _class);
747 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxProcess)"
749 void base_OnTerminate(int pid, int status);
755 wxInputStream *GetInputStream();
756 wxInputStream *GetErrorStream();
757 wxOutputStream *GetOutputStream();
764 long wxExecute(const wxString& command,
766 wxPyProcess *process = NULL);
768 //----------------------------------------------------------------------
771 #if !wxUSE_JOYSTICK && !defined(__WXMSW__)
772 // A C++ stub class for wxJoystick for platforms that don't have it.
773 class wxJoystick : public wxObject {
775 wxJoystick(int joystick = wxJOYSTICK1) {
776 wxPyTState* state = wxPyBeginBlockThreads();
777 PyErr_SetString(PyExc_NotImplementedError, "wxJoystick is not available on this platform.");
778 wxPyEndBlockThreads(state);
780 wxPoint GetPosition() { return wxPoint(-1,-1); }
781 int GetZPosition() { return -1; }
782 int GetButtonState() { return -1; }
783 int GetPOVPosition() { return -1; }
784 int GetPOVCTSPosition() { return -1; }
785 int GetRudderPosition() { return -1; }
786 int GetUPosition() { return -1; }
787 int GetVPosition() { return -1; }
788 int GetMovementThreshold() { return -1; }
789 void SetMovementThreshold(int threshold) {}
791 bool IsOk(void) { return FALSE; }
792 int GetNumberJoysticks() { return -1; }
793 int GetManufacturerId() { return -1; }
794 int GetProductId() { return -1; }
795 wxString GetProductName() { return ""; }
796 int GetXMin() { return -1; }
797 int GetYMin() { return -1; }
798 int GetZMin() { return -1; }
799 int GetXMax() { return -1; }
800 int GetYMax() { return -1; }
801 int GetZMax() { return -1; }
802 int GetNumberButtons() { return -1; }
803 int GetNumberAxes() { return -1; }
804 int GetMaxButtons() { return -1; }
805 int GetMaxAxes() { return -1; }
806 int GetPollingMin() { return -1; }
807 int GetPollingMax() { return -1; }
808 int GetRudderMin() { return -1; }
809 int GetRudderMax() { return -1; }
810 int GetUMin() { return -1; }
811 int GetUMax() { return -1; }
812 int GetVMin() { return -1; }
813 int GetVMax() { return -1; }
815 bool HasRudder() { return FALSE; }
816 bool HasZ() { return FALSE; }
817 bool HasU() { return FALSE; }
818 bool HasV() { return FALSE; }
819 bool HasPOV() { return FALSE; }
820 bool HasPOV4Dir() { return FALSE; }
821 bool HasPOVCTS() { return FALSE; }
823 bool SetCapture(wxWindow* win, int pollingFreq = 0) { return FALSE; }
824 bool ReleaseCapture() { return FALSE; }
830 class wxJoystick : public wxObject {
832 wxJoystick(int joystick = wxJOYSTICK1);
835 wxPoint GetPosition();
837 int GetButtonState();
838 int GetPOVPosition();
839 int GetPOVCTSPosition();
840 int GetRudderPosition();
843 int GetMovementThreshold();
844 void SetMovementThreshold(int threshold) ;
847 int GetNumberJoysticks();
848 int GetManufacturerId();
850 wxString GetProductName();
857 int GetNumberButtons();
878 bool SetCapture(wxWindow* win, int pollingFreq = 0);
879 bool ReleaseCapture();
882 //----------------------------------------------------------------------
886 // A C++ stub class for wxWave for platforms that don't have it.
887 class wxWave : public wxObject
890 wxWave(const wxString& fileName, bool isResource = FALSE) {
891 wxPyTState* state = wxPyBeginBlockThreads();
892 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
893 wxPyEndBlockThreads(state);
895 wxWave(int size, const wxByte* data) {
896 wxPyTState* state = wxPyBeginBlockThreads();
897 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
898 wxPyEndBlockThreads(state);
903 bool IsOk() const { return FALSE; }
904 bool Play(bool async = TRUE, bool looped = FALSE) const { return FALSE; }
910 class wxWave : public wxObject
913 wxWave(const wxString& fileName, bool isResource = FALSE);
917 bool Play(bool async = TRUE, bool looped = FALSE) const;
920 %new wxWave* wxWaveData(const wxString& data);
921 %{ // Implementations of some alternate "constructors"
922 wxWave* wxWaveData(const wxString& data) {
923 return new wxWave(data.Len(), (wxByte*)data.c_str());
928 //----------------------------------------------------------------------
932 wxMAILCAP_STANDARD = 1,
933 wxMAILCAP_NETSCAPE = 2,
947 wxFileTypeInfo(const char *mimeType,
949 const char *printCmd,
953 // the array elements correspond to the parameters of the ctor above in
955 %name(wxFileTypeInfoSequence)wxFileTypeInfo(const wxArrayString& sArray);
957 // invalid item - use this to terminate the array passed to
958 // wxMimeTypesManager::AddFallbacks
959 %name(wxNullFileTypeInfo)wxFileTypeInfo();
962 // test if this object can be used
963 bool IsValid() const;
967 void SetIcon(const wxString& iconFile, int iconIndex = 0);
969 // set the short desc
970 void SetShortDesc(const wxString& shortDesc);
974 const wxString& GetMimeType() const;
975 // get the open command
976 const wxString& GetOpenCommand() const;
977 // get the print command
978 const wxString& GetPrintCommand() const;
979 // get the short description (only used under Win32 so far)
980 const wxString& GetShortDesc() const;
981 // get the long, user visible description
982 const wxString& GetDescription() const;
985 // get the array of all extensions
986 //const wxArrayString& GetExtensions() const;
988 PyObject* GetExtensions() {
989 wxArrayString& arr = (wxArrayString&)self->GetExtensions();
990 return wxArrayString2PyList_helper(arr);
994 int GetExtensionsCount() const;
997 const wxString& GetIconFile() const;
998 int GetIconIndex() const;
1008 // TODO: Make a wxPyMessageParameters with virtual GetParamValue...
1010 // An object of this class must be passed to Get{Open|Print}Command. The
1011 // default implementation is trivial and doesn't know anything at all about
1012 // parameters, only filename and MIME type are used (so it's probably ok for
1013 // Windows where %{param} is not used anyhow)
1014 class MessageParameters
1018 MessageParameters(const wxString& filename=wxPyEmptyStr,
1019 const wxString& mimetype=wxPyEmptyStr);
1021 // accessors (called by GetOpenCommand)
1023 const wxString& GetFileName() const;
1025 const wxString& GetMimeType() const;;
1027 // override this function in derived class
1028 virtual wxString GetParamValue(const wxString& name) const;
1030 // virtual dtor as in any base class
1031 virtual ~MessageParameters();
1035 // ctor from static data
1036 wxFileType(const wxFileTypeInfo& ftInfo);
1038 // return the MIME type for this file type
1040 PyObject* GetMimeType() {
1042 if (self->GetMimeType(&str))
1043 return PyString_FromString(str.c_str());
1047 PyObject* GetMimeTypes() {
1049 if (self->GetMimeTypes(arr))
1050 return wxArrayString2PyList_helper(arr);
1057 // Get all extensions associated with this file type
1059 PyObject* GetExtensions() {
1061 if (self->GetExtensions(arr))
1062 return wxArrayString2PyList_helper(arr);
1070 // Get the icon corresponding to this file type
1071 %new wxIcon* GetIcon() {
1073 if (self->GetIcon(&icon))
1074 return new wxIcon(icon);
1079 // Get the icon corresponding to this file type, the name of the file
1080 // where this icon resides, and its index in this file if applicable.
1081 PyObject* GetIconInfo() {
1085 if (self->GetIcon(&icon, &iconFile, &iconIndex)) {
1086 wxPyTState* state = wxPyBeginBlockThreads();
1087 PyObject* tuple = PyTuple_New(3);
1088 PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(icon),
1090 PyTuple_SetItem(tuple, 1, PyString_FromString(iconFile.c_str()));
1091 PyTuple_SetItem(tuple, 2, PyInt_FromLong(iconIndex));
1092 wxPyEndBlockThreads(state);
1101 // get a brief file type description ("*.txt" => "text document")
1102 PyObject* GetDescription() {
1104 if (self->GetDescription(&str))
1105 return PyString_FromString(str.c_str());
1112 // get the command to open/execute the file of given type
1114 PyObject* GetOpenCommand(const wxString& filename,
1115 const wxString& mimetype=wxPyEmptyStr) {
1117 if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype)))
1118 return PyString_FromString(str.c_str());
1125 // get the command to print the file of given type
1127 PyObject* GetPrintCommand(const wxString& filename,
1128 const wxString& mimetype=wxPyEmptyStr) {
1130 if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype)))
1131 return PyString_FromString(str.c_str());
1138 // Get all commands defined for this file type
1140 PyObject* GetAllCommands(const wxString& filename,
1141 const wxString& mimetype=wxPyEmptyStr) {
1142 wxArrayString verbs;
1143 wxArrayString commands;
1144 if (self->GetAllCommands(&verbs, &commands,
1145 wxFileType::MessageParameters(filename, mimetype))) {
1146 wxPyTState* state = wxPyBeginBlockThreads();
1147 PyObject* tuple = PyTuple_New(2);
1148 PyTuple_SetItem(tuple, 0, wxArrayString2PyList_helper(verbs));
1149 PyTuple_SetItem(tuple, 1, wxArrayString2PyList_helper(commands));
1150 wxPyEndBlockThreads(state);
1159 // set an arbitrary command, ask confirmation if it already exists and
1160 // overwriteprompt is TRUE
1161 bool SetCommand(const wxString& cmd, const wxString& verb,
1162 bool overwriteprompt = TRUE);
1164 bool SetDefaultIcon(const wxString& cmd = wxEmptyString, int index = 0);
1167 // remove the association for this filetype from the system MIME database:
1168 // notice that it will only work if the association is defined in the user
1169 // file/registry part, we will never modify the system-wide settings
1173 // expand a string in the format of GetOpenCommand (which may contain
1174 // '%s' and '%t' format specificators for the file name and mime type
1175 // and %{param} constructions).
1176 static wxString ExpandCommand(const wxString& command,
1177 const MessageParameters& params);
1179 // dtor (not virtual, shouldn't be derived from)
1187 class wxMimeTypesManager
1190 // static helper functions
1191 // -----------------------
1193 // check if the given MIME type is the same as the other one: the
1194 // second argument may contain wildcards ('*'), but not the first. If
1195 // the types are equal or if the mimeType matches wildcard the function
1196 // returns TRUE, otherwise it returns FALSE
1197 static bool IsOfType(const wxString& mimeType, const wxString& wildcard);
1200 wxMimeTypesManager();
1202 // loads data from standard files according to the mailcap styles
1203 // specified: this is a bitwise OR of wxMailcapStyle values
1205 // use the extraDir parameter if you want to look for files in another
1207 void Initialize(int mailcapStyle = wxMAILCAP_STANDARD,
1208 const wxString& extraDir = wxEmptyString);
1210 // and this function clears all the data from the manager
1213 // Database lookup: all functions return a pointer to wxFileType object
1214 // whose methods may be used to query it for the information you're
1215 // interested in. If the return value is !NULL, caller is responsible for
1217 // get file type from file extension
1218 %new wxFileType *GetFileTypeFromExtension(const wxString& ext);
1220 // get file type from MIME type (in format <category>/<format>)
1221 %new wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
1223 // other operations: return TRUE if there were no errors or FALSE if there
1224 // were some unreckognized entries (the good entries are always read anyhow)
1227 // read in additional file (the standard ones are read automatically)
1228 // in mailcap format (see mimetype.cpp for description)
1230 // 'fallback' parameter may be set to TRUE to avoid overriding the
1231 // settings from other, previously parsed, files by this one: normally,
1232 // the files read most recently would override the older files, but with
1233 // fallback == TRUE this won't happen
1234 bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
1236 // read in additional file in mime.types format
1237 bool ReadMimeTypes(const wxString& filename);
1239 // enumerate all known MIME types
1241 PyObject* EnumAllFileTypes() {
1243 self->EnumAllFileTypes(arr);
1244 return wxArrayString2PyList_helper(arr);
1248 // these functions can be used to provide default values for some of the
1249 // MIME types inside the program itself (you may also use
1250 // ReadMailcap(filenameWithDefaultTypes, TRUE /* use as fallback */) to
1251 // achieve the same goal, but this requires having this info in a file).
1253 void AddFallback(const wxFileTypeInfo& ft);
1256 // create or remove associations
1258 // create a new association using the fields of wxFileTypeInfo (at least
1259 // the MIME type and the extension should be set)
1260 // if the other fields are empty, the existing values should be left alone
1261 %new wxFileType *Associate(const wxFileTypeInfo& ftInfo);
1264 bool Unassociate(wxFileType *ft) ;
1266 // dtor (not virtual, shouldn't be derived from)
1267 ~wxMimeTypesManager();
1275 extern wxMimeTypesManager* wxTheMimeTypesManager;
1281 //----------------------------------------------------------------------
1284 #include <wx/docview.h>
1287 class wxFileHistory : public wxObject
1290 wxFileHistory(int maxFiles = 9);
1294 void AddFileToHistory(const wxString& file);
1295 void RemoveFileFromHistory(int i);
1296 int GetMaxFiles() const;
1297 void UseMenu(wxMenu *menu);
1299 // Remove menu from the list (MDI child may be closing)
1300 void RemoveMenu(wxMenu *menu);
1302 void Load(wxConfigBase& config);
1303 void Save(wxConfigBase& config);
1305 void AddFilesToMenu();
1306 %name(AddFilesToSingleMenu)void AddFilesToMenu(wxMenu* menu);
1309 wxString GetHistoryFile(int i) const;
1311 // A synonym for GetNoHistoryFiles
1312 int GetCount() const;
1313 int GetNoHistoryFiles() const;
1317 //----------------------------------------------------------------------
1318 //----------------------------------------------------------------------
1322 wxPyPtrTypeMap_Add("wxFontEnumerator", "wxPyFontEnumerator");
1323 wxPyPtrTypeMap_Add("wxDragImage", "wxGenericDragImage");
1324 wxPyPtrTypeMap_Add("wxProcess", "wxPyProcess");
1327 //----------------------------------------------------------------------