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);
292 //---------------------------------------------------------------------------
295 class wxToolTip : public wxObject {
297 wxToolTip(const wxString &tip);
299 void SetTip(const wxString& tip);
301 // *** Not in the "public" interface void SetWindow(wxWindow *win);
302 wxWindow *GetWindow();
304 static void Enable(bool flag);
305 static void SetDelay(long milliseconds);
308 //----------------------------------------------------------------------
312 wxCaret(wxWindow* window, const wxSize& size);
317 %name(GetPositionTuple)void GetPosition(int *OUTPUT, int *OUTPUT);
318 wxPoint GetPosition();
319 %name(GetSizeTuple)void GetSize(int *OUTPUT, int *OUTPUT);
321 wxWindow *GetWindow();
322 %name(MoveXY)void Move(int x, int y);
323 void Move(const wxPoint& pt);
324 %name(SetSizeWH) void SetSize(int width, int height);
325 void SetSize(const wxSize& size);
326 void Show(int show = TRUE);
331 int wxCaret_GetBlinkTime() {
332 return wxCaret::GetBlinkTime();
335 void wxCaret_SetBlinkTime(int milliseconds) {
336 wxCaret::SetBlinkTime(milliseconds);
340 //----------------------------------------------------------------------
343 class wxPyFontEnumerator : public wxFontEnumerator {
345 wxPyFontEnumerator() {}
346 ~wxPyFontEnumerator() {}
348 DEC_PYCALLBACK_BOOL_STRING(OnFacename);
349 DEC_PYCALLBACK_BOOL_STRINGSTRING(OnFontEncoding);
354 IMP_PYCALLBACK_BOOL_STRING(wxPyFontEnumerator, wxFontEnumerator, OnFacename);
355 IMP_PYCALLBACK_BOOL_STRINGSTRING(wxPyFontEnumerator, wxFontEnumerator, OnFontEncoding);
359 %name(wxFontEnumerator) class wxPyFontEnumerator {
361 wxPyFontEnumerator();
362 ~wxPyFontEnumerator();
363 void _setCallbackInfo(PyObject* self, PyObject* _class, bool incref);
364 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFontEnumerator, 0)"
366 bool EnumerateFacenames(
367 wxFontEncoding encoding = wxFONTENCODING_SYSTEM, // all
368 bool fixedWidthOnly = FALSE);
369 bool EnumerateEncodings(const char* facename = "");
371 //wxArrayString* GetEncodings();
372 //wxArrayString* GetFacenames();
374 PyObject* GetEncodings() {
375 wxArrayString* arr = self->GetEncodings();
376 return wxArrayString2PyList_helper(*arr);
379 PyObject* GetFacenames() {
380 wxArrayString* arr = self->GetFacenames();
381 return wxArrayString2PyList_helper(*arr);
386 //----------------------------------------------------------------------
390 wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR);
394 //----------------------------------------------------------------------
396 class wxWindowDisabler {
398 wxWindowDisabler(wxWindow *winToSkip = NULL);
402 //----------------------------------------------------------------------
404 bool wxSafeYield(wxWindow* win=NULL);
405 void wxPostEvent(wxEvtHandler *dest, wxEvent& event);
410 void wxWakeUpMainThread();
413 void wxMutexGuiEnter();
414 void wxMutexGuiLeave();
417 class wxMutexGuiLocker {
425 bool wxThread_IsMain() {
426 #ifdef WXP_WITH_THREAD
427 return wxThread::IsMain();
434 //----------------------------------------------------------------------
440 // wxTipProvider(size_t currentTip); **** Abstract base class
443 virtual wxString GetTip() = 0;
444 size_t GetCurrentTip();
449 // The C++ version of wxPyTipProvider
451 class wxPyTipProvider : public wxTipProvider {
453 wxPyTipProvider(size_t currentTip)
454 : wxTipProvider(currentTip) {}
456 DEC_PYCALLBACK_STRING__pure(GetTip);
461 IMP_PYCALLBACK_STRING__pure( wxPyTipProvider, wxTipProvider, GetTip);
466 // Now let SWIG know about it
467 class wxPyTipProvider : public wxTipProvider {
469 wxPyTipProvider(size_t currentTip);
474 bool wxShowTip(wxWindow *parent, wxTipProvider *tipProvider, bool showAtStartup = TRUE);
475 %new wxTipProvider * wxCreateFileTipProvider(const wxString& filename, size_t currentTip);
478 //----------------------------------------------------------------------
481 #include <wx/generic/dragimgg.h>
484 %name (wxDragImage) class wxGenericDragImage : public wxObject
488 wxGenericDragImage(const wxBitmap& image,
489 const wxCursor& cursor = wxNullCursor);
490 %name(wxDragIcon)wxGenericDragImage(const wxIcon& image,
491 const wxCursor& cursor = wxNullCursor);
492 %name(wxDragString)wxGenericDragImage(const wxString& str,
493 const wxCursor& cursor = wxNullCursor);
494 %name(wxDragTreeItem)wxGenericDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
495 %name(wxDragListItem)wxGenericDragImage(const wxListCtrl& listCtrl, long id);
497 ~wxGenericDragImage();
499 void SetBackingBitmap(wxBitmap* bitmap);
500 bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
501 bool fullScreen = FALSE, wxRect* rect = NULL);
503 %name(BeginDrag2) bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
504 wxWindow* fullScreenRect);
507 bool Move(const wxPoint& pt);
511 wxRect GetImageRect(const wxPoint& pos) const;
512 bool RedrawImage(const wxPoint& oldPos, const wxPoint& newPos,
513 bool eraseOld, bool drawNew);
517 //----------------------------------------------------------------------
519 class wxPyTimer : public wxObject {
521 wxPyTimer(PyObject* notify);
526 void SetOwner(wxEvtHandler *owner, int id = -1);
527 void Start(int milliseconds=-1, int oneShot=FALSE);
535 // ctor starts the stop watch
538 void Start(long t = 0);
542 // get elapsed time since the last Start() or Pause() in milliseconds
547 //----------------------------------------------------------------------
548 //----------------------------------------------------------------------
553 wxLOG_FatalError, // program can't continue, abort immediately
554 wxLOG_Error, // a serious error, user must be informed about it
555 wxLOG_Warning, // user is normally informed about it but may be ignored
556 wxLOG_Message, // normal message (i.e. normal output of a non GUI app)
557 wxLOG_Info, // informational message (a.k.a. 'Verbose')
558 wxLOG_Status, // informational: might go to the status line of GUI app
559 wxLOG_Debug, // never shown to the user, disabled in release mode
560 wxLOG_Trace, // trace messages are also only enabled in debug mode
561 wxLOG_Progress, // used for progress indicator (not yet)
562 wxLOG_User = 100 // user defined levels start here
571 static bool IsEnabled();
572 static bool EnableLogging(bool doIt = TRUE);
573 static void OnLog(wxLogLevel level, const char *szString, int t=0);
575 virtual void Flush();
576 bool HasPendingMessages() const;
578 static void FlushActive();
579 static wxLog *GetActiveTarget();
580 static wxLog *SetActiveTarget(wxLog *pLogger);
582 static void Suspend();
583 static void Resume();
585 void SetVerbose(bool bVerbose = TRUE);
587 static void DontCreateOnDemand();
588 static void SetTraceMask(wxTraceMask ulMask);
589 static void AddTraceMask(const wxString& str);
590 static void RemoveTraceMask(const wxString& str);
591 static void ClearTraceMasks();
593 static void SetTimestamp(const wxChar *ts);
594 static const wxChar *GetTimestamp();
596 bool GetVerbose() const { return m_bVerbose; }
598 static wxTraceMask GetTraceMask();
599 static bool IsAllowedTraceMask(const char *mask);
601 // static void TimeStamp(wxString *str);
603 wxString TimeStamp() {
605 wxLog::TimeStamp(&msg);
612 class wxLogStderr : public wxLog
615 wxLogStderr(/* TODO: FILE *fp = (FILE *) NULL*/);
619 class wxLogTextCtrl : public wxLog
622 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
626 class wxLogGui : public wxLog
632 class wxLogWindow : public wxLog
635 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
636 const char *szTitle, // the title of the frame
637 bool bShow = TRUE, // show window immediately?
638 bool bPassToOld = TRUE); // pass log messages to the old target?
640 void Show(bool bShow = TRUE);
641 wxFrame *GetFrame() const;
642 wxLog *GetOldLog() const;
643 bool IsPassingMessages() const;
644 void PassMessages(bool bDoPass) { m_bPassMessages = bDoPass; }
656 class wxLogChain : public wxLog
659 wxLogChain(wxLog *logger);
660 void SetLog(wxLog *logger);
661 void PassMessages(bool bDoPass);
662 bool IsPassingMessages();
667 unsigned long wxSysErrorCode();
668 const char* wxSysErrorMsg(unsigned long nErrCode = 0);
669 void wxLogFatalError(const char *szFormat);
670 void wxLogError(const char *szFormat);
671 void wxLogWarning(const char *szFormat);
672 void wxLogMessage(const char *szFormat);
673 void wxLogInfo(const char *szFormat);
674 void wxLogVerbose(const char *szFormat);
675 void wxLogStatus(const char *szFormat);
676 %name(wxLogStatusFrame)void wxLogStatus(wxFrame *pFrame, const char *szFormat);
677 void wxLogSysError(const char *szFormat);
681 // A Log class that can be derived from in wxPython
682 class wxPyLog : public wxLog {
684 wxPyLog() : wxLog() {}
686 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) {
688 wxPyBeginBlockThreads();
689 if ((found = wxPyCBH_findCallback(m_myInst, "DoLog")))
690 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(isi)", level, szString, t));
691 wxPyEndBlockThreads();
693 wxLog::DoLog(level, szString, t);
696 virtual void DoLogString(const wxChar *szString, time_t t) {
698 wxPyBeginBlockThreads();
699 if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString")))
700 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(si)", szString, t));
701 wxPyEndBlockThreads();
703 wxLog::DoLogString(szString, t);
710 // Now tell SWIG about it
711 class wxPyLog : public wxLog {
714 void _setCallbackInfo(PyObject* self, PyObject* _class);
715 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyLog)"
716 %addmethods { void Destroy() { delete self; } }
721 //----------------------------------------------------------------------
730 class wxProcessEvent : public wxEvent {
732 wxProcessEvent(int id = 0, int pid = 0, int exitcode = 0);
735 int m_pid, m_exitcode;
741 %{ // C++ version of wxProcess derived class
743 class wxPyProcess : public wxProcess {
745 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1)
746 : wxProcess(parent, id)
749 DEC_PYCALLBACK_VOID_INTINT(OnTerminate);
754 IMP_PYCALLBACK_VOID_INTINT( wxPyProcess, wxProcess, OnTerminate);
759 %name(wxProcess)class wxPyProcess : public wxEvtHandler {
761 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1);
762 %addmethods { void Destroy() { delete self; } }
764 void _setCallbackInfo(PyObject* self, PyObject* _class);
765 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxProcess)"
767 void base_OnTerminate(int pid, int status);
773 wxInputStream *GetInputStream();
774 wxInputStream *GetErrorStream();
775 wxOutputStream *GetOutputStream();
782 long wxExecute(const wxString& command,
784 wxPyProcess *process = NULL);
786 //----------------------------------------------------------------------
789 #if !wxUSE_JOYSTICK && !defined(__WXMSW__)
790 // A C++ stub class for wxJoystick for platforms that don't have it.
791 class wxJoystick : public wxObject {
793 wxJoystick(int joystick = wxJOYSTICK1) {
794 wxPyBeginBlockThreads();
795 PyErr_SetString(PyExc_NotImplementedError, "wxJoystick is not available on this platform.");
796 wxPyEndBlockThreads();
798 wxPoint GetPosition() { return wxPoint(-1,-1); }
799 int GetZPosition() { return -1; }
800 int GetButtonState() { return -1; }
801 int GetPOVPosition() { return -1; }
802 int GetPOVCTSPosition() { return -1; }
803 int GetRudderPosition() { return -1; }
804 int GetUPosition() { return -1; }
805 int GetVPosition() { return -1; }
806 int GetMovementThreshold() { return -1; }
807 void SetMovementThreshold(int threshold) {}
809 bool IsOk(void) { return FALSE; }
810 int GetNumberJoysticks() { return -1; }
811 int GetManufacturerId() { return -1; }
812 int GetProductId() { return -1; }
813 wxString GetProductName() { return ""; }
814 int GetXMin() { return -1; }
815 int GetYMin() { return -1; }
816 int GetZMin() { return -1; }
817 int GetXMax() { return -1; }
818 int GetYMax() { return -1; }
819 int GetZMax() { return -1; }
820 int GetNumberButtons() { return -1; }
821 int GetNumberAxes() { return -1; }
822 int GetMaxButtons() { return -1; }
823 int GetMaxAxes() { return -1; }
824 int GetPollingMin() { return -1; }
825 int GetPollingMax() { return -1; }
826 int GetRudderMin() { return -1; }
827 int GetRudderMax() { return -1; }
828 int GetUMin() { return -1; }
829 int GetUMax() { return -1; }
830 int GetVMin() { return -1; }
831 int GetVMax() { return -1; }
833 bool HasRudder() { return FALSE; }
834 bool HasZ() { return FALSE; }
835 bool HasU() { return FALSE; }
836 bool HasV() { return FALSE; }
837 bool HasPOV() { return FALSE; }
838 bool HasPOV4Dir() { return FALSE; }
839 bool HasPOVCTS() { return FALSE; }
841 bool SetCapture(wxWindow* win, int pollingFreq = 0) { return FALSE; }
842 bool ReleaseCapture() { return FALSE; }
848 class wxJoystick : public wxObject {
850 wxJoystick(int joystick = wxJOYSTICK1);
853 wxPoint GetPosition();
855 int GetButtonState();
856 int GetPOVPosition();
857 int GetPOVCTSPosition();
858 int GetRudderPosition();
861 int GetMovementThreshold();
862 void SetMovementThreshold(int threshold) ;
865 int GetNumberJoysticks();
866 int GetManufacturerId();
868 wxString GetProductName();
875 int GetNumberButtons();
896 bool SetCapture(wxWindow* win, int pollingFreq = 0);
897 bool ReleaseCapture();
900 //----------------------------------------------------------------------
904 // A C++ stub class for wxWave for platforms that don't have it.
905 class wxWave : public wxObject
908 wxWave(const wxString& fileName, bool isResource = FALSE) {
909 wxPyBeginBlockThreads();
910 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
911 wxPyEndBlockThreads();
913 wxWave(int size, const wxByte* data) {
914 wxPyBeginBlockThreads();
915 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
916 wxPyEndBlockThreads();
921 bool IsOk() const { return FALSE; }
922 bool Play(bool async = TRUE, bool looped = FALSE) const { return FALSE; }
928 class wxWave : public wxObject
931 wxWave(const wxString& fileName, bool isResource = FALSE);
935 bool Play(bool async = TRUE, bool looped = FALSE) const;
938 %new wxWave* wxWaveData(const wxString& data);
939 %{ // Implementations of some alternate "constructors"
940 wxWave* wxWaveData(const wxString& data) {
941 return new wxWave(data.Len(), (wxByte*)data.c_str());
946 //----------------------------------------------------------------------
950 wxMAILCAP_STANDARD = 1,
951 wxMAILCAP_NETSCAPE = 2,
965 wxFileTypeInfo(const char *mimeType,
967 const char *printCmd,
971 // the array elements correspond to the parameters of the ctor above in
973 %name(wxFileTypeInfoSequence)wxFileTypeInfo(const wxArrayString& sArray);
975 // invalid item - use this to terminate the array passed to
976 // wxMimeTypesManager::AddFallbacks
977 %name(wxNullFileTypeInfo)wxFileTypeInfo();
980 // test if this object can be used
981 bool IsValid() const;
985 void SetIcon(const wxString& iconFile, int iconIndex = 0);
987 // set the short desc
988 void SetShortDesc(const wxString& shortDesc);
992 const wxString& GetMimeType() const;
993 // get the open command
994 const wxString& GetOpenCommand() const;
995 // get the print command
996 const wxString& GetPrintCommand() const;
997 // get the short description (only used under Win32 so far)
998 const wxString& GetShortDesc() const;
999 // get the long, user visible description
1000 const wxString& GetDescription() const;
1003 // get the array of all extensions
1004 //const wxArrayString& GetExtensions() const;
1006 PyObject* GetExtensions() {
1007 wxArrayString& arr = (wxArrayString&)self->GetExtensions();
1008 return wxArrayString2PyList_helper(arr);
1012 int GetExtensionsCount() const;
1014 // get the icon info
1015 const wxString& GetIconFile() const;
1016 int GetIconIndex() const;
1026 // TODO: Make a wxPyMessageParameters with virtual GetParamValue...
1028 // An object of this class must be passed to Get{Open|Print}Command. The
1029 // default implementation is trivial and doesn't know anything at all about
1030 // parameters, only filename and MIME type are used (so it's probably ok for
1031 // Windows where %{param} is not used anyhow)
1032 class MessageParameters
1036 MessageParameters(const wxString& filename=wxPyEmptyStr,
1037 const wxString& mimetype=wxPyEmptyStr);
1039 // accessors (called by GetOpenCommand)
1041 const wxString& GetFileName() const;
1043 const wxString& GetMimeType() const;;
1045 // override this function in derived class
1046 virtual wxString GetParamValue(const wxString& name) const;
1048 // virtual dtor as in any base class
1049 virtual ~MessageParameters();
1053 // ctor from static data
1054 wxFileType(const wxFileTypeInfo& ftInfo);
1056 // return the MIME type for this file type
1058 PyObject* GetMimeType() {
1060 if (self->GetMimeType(&str))
1061 return PyString_FromString(str.c_str());
1065 PyObject* GetMimeTypes() {
1067 if (self->GetMimeTypes(arr))
1068 return wxArrayString2PyList_helper(arr);
1075 // Get all extensions associated with this file type
1077 PyObject* GetExtensions() {
1079 if (self->GetExtensions(arr))
1080 return wxArrayString2PyList_helper(arr);
1088 // Get the icon corresponding to this file type
1089 %new wxIcon* GetIcon() {
1091 if (self->GetIcon(&icon))
1092 return new wxIcon(icon);
1097 // Get the icon corresponding to this file type, the name of the file
1098 // where this icon resides, and its index in this file if applicable.
1099 PyObject* GetIconInfo() {
1103 if (self->GetIcon(&icon, &iconFile, &iconIndex)) {
1104 wxPyBeginBlockThreads();
1105 PyObject* tuple = PyTuple_New(3);
1106 PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(icon),
1108 PyTuple_SetItem(tuple, 1, PyString_FromString(iconFile.c_str()));
1109 PyTuple_SetItem(tuple, 2, PyInt_FromLong(iconIndex));
1110 wxPyEndBlockThreads();
1119 // get a brief file type description ("*.txt" => "text document")
1120 PyObject* GetDescription() {
1122 if (self->GetDescription(&str))
1123 return PyString_FromString(str.c_str());
1130 // get the command to open/execute the file of given type
1132 PyObject* GetOpenCommand(const wxString& filename,
1133 const wxString& mimetype=wxPyEmptyStr) {
1135 if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype)))
1136 return PyString_FromString(str.c_str());
1143 // get the command to print the file of given type
1145 PyObject* GetPrintCommand(const wxString& filename,
1146 const wxString& mimetype=wxPyEmptyStr) {
1148 if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype)))
1149 return PyString_FromString(str.c_str());
1156 // Get all commands defined for this file type
1158 PyObject* GetAllCommands(const wxString& filename,
1159 const wxString& mimetype=wxPyEmptyStr) {
1160 wxArrayString verbs;
1161 wxArrayString commands;
1162 if (self->GetAllCommands(&verbs, &commands,
1163 wxFileType::MessageParameters(filename, mimetype))) {
1164 wxPyBeginBlockThreads();
1165 PyObject* tuple = PyTuple_New(2);
1166 PyTuple_SetItem(tuple, 0, wxArrayString2PyList_helper(verbs));
1167 PyTuple_SetItem(tuple, 1, wxArrayString2PyList_helper(commands));
1168 wxPyEndBlockThreads();
1177 // set an arbitrary command, ask confirmation if it already exists and
1178 // overwriteprompt is TRUE
1179 bool SetCommand(const wxString& cmd, const wxString& verb,
1180 bool overwriteprompt = TRUE);
1182 bool SetDefaultIcon(const wxString& cmd = wxEmptyString, int index = 0);
1185 // remove the association for this filetype from the system MIME database:
1186 // notice that it will only work if the association is defined in the user
1187 // file/registry part, we will never modify the system-wide settings
1191 // expand a string in the format of GetOpenCommand (which may contain
1192 // '%s' and '%t' format specificators for the file name and mime type
1193 // and %{param} constructions).
1194 static wxString ExpandCommand(const wxString& command,
1195 const MessageParameters& params);
1197 // dtor (not virtual, shouldn't be derived from)
1205 class wxMimeTypesManager
1208 // static helper functions
1209 // -----------------------
1211 // check if the given MIME type is the same as the other one: the
1212 // second argument may contain wildcards ('*'), but not the first. If
1213 // the types are equal or if the mimeType matches wildcard the function
1214 // returns TRUE, otherwise it returns FALSE
1215 static bool IsOfType(const wxString& mimeType, const wxString& wildcard);
1218 wxMimeTypesManager();
1220 // loads data from standard files according to the mailcap styles
1221 // specified: this is a bitwise OR of wxMailcapStyle values
1223 // use the extraDir parameter if you want to look for files in another
1225 void Initialize(int mailcapStyle = wxMAILCAP_STANDARD,
1226 const wxString& extraDir = wxEmptyString);
1228 // and this function clears all the data from the manager
1231 // Database lookup: all functions return a pointer to wxFileType object
1232 // whose methods may be used to query it for the information you're
1233 // interested in. If the return value is !NULL, caller is responsible for
1235 // get file type from file extension
1236 %new wxFileType *GetFileTypeFromExtension(const wxString& ext);
1238 // get file type from MIME type (in format <category>/<format>)
1239 %new wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
1241 // other operations: return TRUE if there were no errors or FALSE if there
1242 // were some unreckognized entries (the good entries are always read anyhow)
1245 // read in additional file (the standard ones are read automatically)
1246 // in mailcap format (see mimetype.cpp for description)
1248 // 'fallback' parameter may be set to TRUE to avoid overriding the
1249 // settings from other, previously parsed, files by this one: normally,
1250 // the files read most recently would override the older files, but with
1251 // fallback == TRUE this won't happen
1252 bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
1254 // read in additional file in mime.types format
1255 bool ReadMimeTypes(const wxString& filename);
1257 // enumerate all known MIME types
1259 PyObject* EnumAllFileTypes() {
1261 self->EnumAllFileTypes(arr);
1262 return wxArrayString2PyList_helper(arr);
1266 // these functions can be used to provide default values for some of the
1267 // MIME types inside the program itself (you may also use
1268 // ReadMailcap(filenameWithDefaultTypes, TRUE /* use as fallback */) to
1269 // achieve the same goal, but this requires having this info in a file).
1271 void AddFallback(const wxFileTypeInfo& ft);
1274 // create or remove associations
1276 // create a new association using the fields of wxFileTypeInfo (at least
1277 // the MIME type and the extension should be set)
1278 // if the other fields are empty, the existing values should be left alone
1279 %new wxFileType *Associate(const wxFileTypeInfo& ftInfo);
1282 bool Unassociate(wxFileType *ft) ;
1284 // dtor (not virtual, shouldn't be derived from)
1285 ~wxMimeTypesManager();
1293 extern wxMimeTypesManager* wxTheMimeTypesManager;
1299 //----------------------------------------------------------------------
1302 #include <wx/docview.h>
1305 class wxFileHistory : public wxObject
1308 wxFileHistory(int maxFiles = 9);
1312 void AddFileToHistory(const wxString& file);
1313 void RemoveFileFromHistory(int i);
1314 int GetMaxFiles() const;
1315 void UseMenu(wxMenu *menu);
1317 // Remove menu from the list (MDI child may be closing)
1318 void RemoveMenu(wxMenu *menu);
1320 void Load(wxConfigBase& config);
1321 void Save(wxConfigBase& config);
1323 void AddFilesToMenu();
1324 %name(AddFilesToSingleMenu)void AddFilesToMenu(wxMenu* menu);
1327 wxString GetHistoryFile(int i) const;
1329 // A synonym for GetNoHistoryFiles
1330 int GetCount() const;
1331 int GetNoHistoryFiles() const;
1335 //----------------------------------------------------------------------
1336 //----------------------------------------------------------------------
1340 wxPyPtrTypeMap_Add("wxFontEnumerator", "wxPyFontEnumerator");
1341 wxPyPtrTypeMap_Add("wxDragImage", "wxGenericDragImage");
1342 wxPyPtrTypeMap_Add("wxProcess", "wxPyProcess");
1345 //----------------------------------------------------------------------