]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/misc2.i
added a comment about the default button handling
[wxWidgets.git] / wxPython / src / misc2.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: misc2.i
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.)
6 //
7 // Author: Robin Dunn
8 //
9 // Created: 18-June-1999
10 // RCS-ID: $Id$
11 // Copyright: (c) 1998 by Total Control Software
12 // Licence: wxWindows license
13 /////////////////////////////////////////////////////////////////////////////
14
15 %module misc2
16
17 %{
18 #include "helpers.h"
19 #include "pyistream.h"
20 #include <wx/resource.h>
21 #include <wx/tooltip.h>
22 #include <wx/caret.h>
23 #include <wx/tipdlg.h>
24 #include <wx/process.h>
25
26 #if wxUSE_JOYSTICK || defined(__WXMSW__)
27 #include <wx/joystick.h>
28 #endif
29
30 #if wxUSE_WAVE || defined(__WXMSW__)
31 #include <wx/wave.h>
32 #endif
33
34 #include <wx/mimetype.h>
35 %}
36
37 //----------------------------------------------------------------------
38
39 %include typemaps.i
40 %include my_typemaps.i
41
42 // Import some definitions of other classes, etc.
43 %import _defs.i
44 %import windows.i
45 %import misc.i
46 %import gdi.i
47 %import events.i
48 %import streams.i
49 %import utils.i
50
51
52 //----------------------------------------------------------------------
53
54 %{
55 // Put some wx default wxChar* values into wxStrings.
56 DECLARE_DEF_STRING(FileSelectorPromptStr);
57 DECLARE_DEF_STRING(FileSelectorDefaultWildcardStr);
58 DECLARE_DEF_STRING(DirSelectorPromptStr);
59 static const wxString wxPyEmptyString(wxT(""));
60 %}
61
62 //---------------------------------------------------------------------------
63 // Dialog Functions
64
65 wxString wxFileSelector(const wxString& message = wxPyFileSelectorPromptStr,
66 const wxString& default_path = wxPyEmptyString,
67 const wxString& default_filename = wxPyEmptyString,
68 const wxString& default_extension = wxPyEmptyString,
69 const wxString& wildcard = wxPyFileSelectorDefaultWildcardStr,
70 int flags = 0,
71 wxWindow *parent = NULL,
72 int x = -1, int y = -1);
73
74 // Ask for filename to load
75 wxString wxLoadFileSelector(const wxString& what,
76 const wxString& extension,
77 const wxString& default_name = wxPyEmptyString,
78 wxWindow *parent = NULL);
79
80 // Ask for filename to save
81 wxString wxSaveFileSelector(const wxString& what,
82 const wxString& extension,
83 const wxString& default_name = wxPyEmptyString,
84 wxWindow *parent = NULL);
85
86
87 wxString wxDirSelector(const wxString& message = wxPyDirSelectorPromptStr,
88 const wxString& defaultPath = wxPyEmptyString,
89 long style = wxDD_DEFAULT_STYLE,
90 const wxPoint& pos = wxDefaultPosition,
91 wxWindow *parent = NULL);
92
93 wxString wxGetTextFromUser(const wxString& message,
94 const wxString& caption = wxPyEmptyString,
95 const wxString& default_value = wxPyEmptyString,
96 wxWindow *parent = NULL,
97 int x = -1, int y = -1,
98 bool centre = TRUE);
99
100 wxString wxGetPasswordFromUser(const wxString& message,
101 const wxString& caption = wxPyEmptyString,
102 const wxString& default_value = wxPyEmptyString,
103 wxWindow *parent = NULL);
104
105
106 // TODO: Need to custom wrap this one...
107 // int wxGetMultipleChoice(char* message, char* caption,
108 // int LCOUNT, char** choices,
109 // int nsel, int *selection,
110 // wxWindow *parent = NULL, int x = -1, int y = -1,
111 // bool centre = TRUE, int width=150, int height=200);
112
113
114 wxString wxGetSingleChoice(const wxString& message, const wxString& caption,
115 int LCOUNT, wxString* choices,
116 wxWindow *parent = NULL,
117 int x = -1, int y = -1,
118 bool centre = TRUE,
119 int width=150, int height=200);
120
121 int wxGetSingleChoiceIndex(const wxString& message, const wxString& caption,
122 int LCOUNT, wxString* choices,
123 wxWindow *parent = NULL,
124 int x = -1, int y = -1,
125 bool centre = TRUE,
126 int width=150, int height=200);
127
128
129 int wxMessageBox(const wxString& message,
130 const wxString& caption = wxPyEmptyString,
131 int style = wxOK | wxCENTRE,
132 wxWindow *parent = NULL,
133 int x = -1, int y = -1);
134
135 long wxGetNumberFromUser(const wxString& message,
136 const wxString& prompt,
137 const wxString& caption,
138 long value,
139 long min = 0, long max = 100,
140 wxWindow *parent = NULL,
141 const wxPoint& pos = wxDefaultPosition);
142
143 //---------------------------------------------------------------------------
144 // GDI Functions
145
146 bool wxColourDisplay();
147
148 int wxDisplayDepth();
149 int wxGetDisplayDepth();
150
151 void wxDisplaySize(int* OUTPUT, int* OUTPUT);
152 wxSize wxGetDisplaySize();
153
154 void wxDisplaySizeMM(int* OUTPUT, int* OUTPUT);
155 wxSize wxGetDisplaySizeMM();
156
157 void wxClientDisplayRect(int *OUTPUT, int *OUTPUT, int *OUTPUT, int *OUTPUT);
158 wxRect wxGetClientDisplayRect();
159
160 void wxSetCursor(wxCursor& cursor);
161
162 //----------------------------------------------------------------------
163 // Miscellaneous functions
164
165 wxWindow * wxFindWindowByLabel(const wxString& label, wxWindow *parent=NULL);
166 wxWindow * wxFindWindowByName(const wxString& name, wxWindow *parent=NULL);
167
168 void wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR);
169 wxWindow * wxGetActiveWindow();
170
171 wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt);
172 wxWindow* wxFindWindowAtPoint(const wxPoint& pt);
173
174 #ifdef __WXMSW__
175 bool wxCheckForInterrupt(wxWindow *wnd);
176 void wxFlushEvents();
177 #endif
178
179 wxWindow* wxGetTopLevelParent(wxWindow *win);
180
181 //---------------------------------------------------------------------------
182 // Resource System
183
184 bool wxResourceAddIdentifier(char* name, int value);
185 void wxResourceClear(void);
186 wxBitmap wxResourceCreateBitmap(char* resource);
187 wxIcon wxResourceCreateIcon(char* resource);
188 wxMenuBar * wxResourceCreateMenuBar(char* resource);
189 int wxResourceGetIdentifier(char* name);
190 bool wxResourceParseData(char* resource, wxResourceTable *table = NULL);
191 bool wxResourceParseFile(char* filename, wxResourceTable *table = NULL);
192 bool wxResourceParseString(char* resource, wxResourceTable *table = NULL);
193
194 //---------------------------------------------------------------------------
195 // System Settings
196
197 // possible values for wxSystemSettings::GetFont() parameter
198 //
199 enum wxSystemFont
200 {
201 wxSYS_OEM_FIXED_FONT = 10,
202 wxSYS_ANSI_FIXED_FONT,
203 wxSYS_ANSI_VAR_FONT,
204 wxSYS_SYSTEM_FONT,
205 wxSYS_DEVICE_DEFAULT_FONT,
206 wxSYS_DEFAULT_PALETTE,
207 wxSYS_SYSTEM_FIXED_FONT,
208 wxSYS_DEFAULT_GUI_FONT
209 };
210
211 // possible values for wxSystemSettings::GetColour() parameter
212 //
213 enum wxSystemColour
214 {
215 wxSYS_COLOUR_SCROLLBAR,
216 wxSYS_COLOUR_BACKGROUND,
217 wxSYS_COLOUR_DESKTOP = wxSYS_COLOUR_BACKGROUND,
218 wxSYS_COLOUR_ACTIVECAPTION,
219 wxSYS_COLOUR_INACTIVECAPTION,
220 wxSYS_COLOUR_MENU,
221 wxSYS_COLOUR_WINDOW,
222 wxSYS_COLOUR_WINDOWFRAME,
223 wxSYS_COLOUR_MENUTEXT,
224 wxSYS_COLOUR_WINDOWTEXT,
225 wxSYS_COLOUR_CAPTIONTEXT,
226 wxSYS_COLOUR_ACTIVEBORDER,
227 wxSYS_COLOUR_INACTIVEBORDER,
228 wxSYS_COLOUR_APPWORKSPACE,
229 wxSYS_COLOUR_HIGHLIGHT,
230 wxSYS_COLOUR_HIGHLIGHTTEXT,
231 wxSYS_COLOUR_BTNFACE,
232 wxSYS_COLOUR_3DFACE = wxSYS_COLOUR_BTNFACE,
233 wxSYS_COLOUR_BTNSHADOW,
234 wxSYS_COLOUR_3DSHADOW = wxSYS_COLOUR_BTNSHADOW,
235 wxSYS_COLOUR_GRAYTEXT,
236 wxSYS_COLOUR_BTNTEXT,
237 wxSYS_COLOUR_INACTIVECAPTIONTEXT,
238 wxSYS_COLOUR_BTNHIGHLIGHT,
239 wxSYS_COLOUR_BTNHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
240 wxSYS_COLOUR_3DHIGHLIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
241 wxSYS_COLOUR_3DHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT,
242 wxSYS_COLOUR_3DDKSHADOW,
243 wxSYS_COLOUR_3DLIGHT,
244 wxSYS_COLOUR_INFOTEXT,
245 wxSYS_COLOUR_INFOBK,
246 wxSYS_COLOUR_LISTBOX,
247 wxSYS_COLOUR_HOTLIGHT,
248 wxSYS_COLOUR_GRADIENTACTIVECAPTION,
249 wxSYS_COLOUR_GRADIENTINACTIVECAPTION,
250 wxSYS_COLOUR_MENUHILIGHT,
251 wxSYS_COLOUR_MENUBAR,
252
253 wxSYS_COLOUR_MAX
254 };
255
256 // possible values for wxSystemSettings::GetMetric() parameter
257 //
258 enum wxSystemMetric
259 {
260 wxSYS_MOUSE_BUTTONS = 1,
261 wxSYS_BORDER_X,
262 wxSYS_BORDER_Y,
263 wxSYS_CURSOR_X,
264 wxSYS_CURSOR_Y,
265 wxSYS_DCLICK_X,
266 wxSYS_DCLICK_Y,
267 wxSYS_DRAG_X,
268 wxSYS_DRAG_Y,
269 wxSYS_EDGE_X,
270 wxSYS_EDGE_Y,
271 wxSYS_HSCROLL_ARROW_X,
272 wxSYS_HSCROLL_ARROW_Y,
273 wxSYS_HTHUMB_X,
274 wxSYS_ICON_X,
275 wxSYS_ICON_Y,
276 wxSYS_ICONSPACING_X,
277 wxSYS_ICONSPACING_Y,
278 wxSYS_WINDOWMIN_X,
279 wxSYS_WINDOWMIN_Y,
280 wxSYS_SCREEN_X,
281 wxSYS_SCREEN_Y,
282 wxSYS_FRAMESIZE_X,
283 wxSYS_FRAMESIZE_Y,
284 wxSYS_SMALLICON_X,
285 wxSYS_SMALLICON_Y,
286 wxSYS_HSCROLL_Y,
287 wxSYS_VSCROLL_X,
288 wxSYS_VSCROLL_ARROW_X,
289 wxSYS_VSCROLL_ARROW_Y,
290 wxSYS_VTHUMB_Y,
291 wxSYS_CAPTION_Y,
292 wxSYS_MENU_Y,
293 wxSYS_NETWORK_PRESENT,
294 wxSYS_PENWINDOWS_PRESENT,
295 wxSYS_SHOW_SOUNDS,
296 wxSYS_SWAP_BUTTONS
297 };
298
299 // possible values for wxSystemSettings::HasFeature() parameter
300 enum wxSystemFeature
301 {
302 wxSYS_CAN_DRAW_FRAME_DECORATIONS = 1,
303 wxSYS_CAN_ICONIZE_FRAME
304 };
305
306 // values for different screen designs
307 enum wxSystemScreen
308 {
309 wxSYS_SCREEN_NONE = 0, // not yet defined
310 wxSYS_SCREEN_DESKTOP, // >= 800x600
311 wxSYS_SCREEN_SMALL, // >= 640x480
312 wxSYS_SCREEN_PDA, // >= 320x240
313 wxSYS_SCREEN_TINY // <
314 };
315
316
317 class wxSystemSettings {
318 public:
319 // get a standard system colour
320 static wxColour GetColour(wxSystemColour index);
321
322 // get a standard system font
323 static wxFont GetFont(wxSystemFont index);
324
325 // get a system-dependent metric
326 static int GetMetric(wxSystemMetric index);
327
328 // return true if the port has certain feature
329 static bool HasFeature(wxSystemFeature index);
330
331 // // Get system screen design (desktop, pda, ..) used for
332 // // laying out various dialogs.
333 // static wxSystemScreen GetScreen();
334
335 // // Override default.
336 // static void SetScreen( wxSystemScreen screen );
337
338 };
339
340
341
342 //---------------------------------------------------------------------------
343 // wxToolTip
344
345 class wxToolTip : public wxObject {
346 public:
347 wxToolTip(const wxString &tip);
348
349 void SetTip(const wxString& tip);
350 wxString GetTip();
351 // *** Not in the "public" interface void SetWindow(wxWindow *win);
352 wxWindow *GetWindow();
353
354 static void Enable(bool flag);
355 static void SetDelay(long milliseconds);
356 };
357
358 //----------------------------------------------------------------------
359
360 class wxCaret {
361 public:
362 wxCaret(wxWindow* window, const wxSize& size);
363 ~wxCaret();
364
365 bool IsOk();
366 bool IsVisible();
367 %name(GetPositionTuple)void GetPosition(int *OUTPUT, int *OUTPUT);
368 wxPoint GetPosition();
369 %name(GetSizeTuple)void GetSize(int *OUTPUT, int *OUTPUT);
370 wxSize GetSize();
371 wxWindow *GetWindow();
372 %name(MoveXY)void Move(int x, int y);
373 void Move(const wxPoint& pt);
374 %name(SetSizeWH) void SetSize(int width, int height);
375 void SetSize(const wxSize& size);
376 void Show(int show = TRUE);
377 void Hide();
378 };
379
380 %inline %{
381 int wxCaret_GetBlinkTime() {
382 return wxCaret::GetBlinkTime();
383 }
384
385 void wxCaret_SetBlinkTime(int milliseconds) {
386 wxCaret::SetBlinkTime(milliseconds);
387 }
388 %}
389
390 //----------------------------------------------------------------------
391
392 class wxBusyCursor {
393 public:
394 wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR);
395 ~wxBusyCursor();
396 };
397
398 //----------------------------------------------------------------------
399
400 class wxWindowDisabler {
401 public:
402 wxWindowDisabler(wxWindow *winToSkip = NULL);
403 ~wxWindowDisabler();
404 };
405
406 //----------------------------------------------------------------------
407
408 bool wxSafeYield(wxWindow* win=NULL);
409 void wxPostEvent(wxEvtHandler *dest, wxEvent& event);
410 void wxWakeUpIdle();
411
412
413 #ifdef __WXMSW__
414 void wxWakeUpMainThread();
415 #endif
416
417 void wxMutexGuiEnter();
418 void wxMutexGuiLeave();
419
420
421 class wxMutexGuiLocker {
422 public:
423 wxMutexGuiLocker();
424 ~wxMutexGuiLocker();
425 };
426
427
428 %inline %{
429 bool wxThread_IsMain() {
430 #ifdef WXP_WITH_THREAD
431 return wxThread::IsMain();
432 #else
433 return TRUE;
434 #endif
435 }
436 %}
437
438 //----------------------------------------------------------------------
439
440
441 class wxTipProvider
442 {
443 public:
444 // wxTipProvider(size_t currentTip); **** Abstract base class
445 ~wxTipProvider();
446
447 virtual wxString GetTip() = 0;
448 size_t GetCurrentTip();
449
450 };
451
452
453 // The C++ version of wxPyTipProvider
454 %{
455 class wxPyTipProvider : public wxTipProvider {
456 public:
457 wxPyTipProvider(size_t currentTip)
458 : wxTipProvider(currentTip) {}
459
460 DEC_PYCALLBACK_STRING__pure(GetTip);
461
462 PYPRIVATE;
463 };
464
465 IMP_PYCALLBACK_STRING__pure( wxPyTipProvider, wxTipProvider, GetTip);
466
467 %}
468
469
470 // Now let SWIG know about it
471 class wxPyTipProvider : public wxTipProvider {
472 public:
473 wxPyTipProvider(size_t currentTip);
474 };
475
476
477
478 bool wxShowTip(wxWindow *parent, wxTipProvider *tipProvider, bool showAtStartup = TRUE);
479 %new wxTipProvider * wxCreateFileTipProvider(const wxString& filename, size_t currentTip);
480
481
482 //----------------------------------------------------------------------
483
484 %{
485 #include <wx/generic/dragimgg.h>
486 %}
487
488 %name (wxDragImage) class wxGenericDragImage : public wxObject
489 {
490 public:
491
492 wxGenericDragImage(const wxBitmap& image,
493 const wxCursor& cursor = wxNullCursor);
494 %name(wxDragIcon)wxGenericDragImage(const wxIcon& image,
495 const wxCursor& cursor = wxNullCursor);
496 %name(wxDragString)wxGenericDragImage(const wxString& str,
497 const wxCursor& cursor = wxNullCursor);
498 %name(wxDragTreeItem)wxGenericDragImage(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
499 %name(wxDragListItem)wxGenericDragImage(const wxListCtrl& listCtrl, long id);
500
501 ~wxGenericDragImage();
502
503 void SetBackingBitmap(wxBitmap* bitmap);
504 bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
505 bool fullScreen = FALSE, wxRect* rect = NULL);
506
507 %name(BeginDrag2) bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
508 wxWindow* fullScreenRect);
509
510 bool EndDrag();
511 bool Move(const wxPoint& pt);
512 bool Show();
513 bool Hide();
514
515 wxRect GetImageRect(const wxPoint& pos) const;
516 bool RedrawImage(const wxPoint& oldPos, const wxPoint& newPos,
517 bool eraseOld, bool drawNew);
518 };
519
520
521 //----------------------------------------------------------------------
522
523 class wxPyTimer : public wxObject {
524 public:
525 wxPyTimer(PyObject* notify);
526 ~wxPyTimer();
527 int GetInterval();
528 bool IsOneShot();
529 bool IsRunning();
530 void SetOwner(wxEvtHandler *owner, int id = -1);
531 void Start(int milliseconds=-1, int oneShot=FALSE);
532 void Stop();
533 };
534
535
536 class wxStopWatch
537 {
538 public:
539 // ctor starts the stop watch
540 wxStopWatch();
541 ~wxStopWatch();
542 void Start(long t = 0);
543 void Pause();
544 void Resume();
545
546 // get elapsed time since the last Start() or Pause() in milliseconds
547 long Time() const;
548 };
549
550
551 //----------------------------------------------------------------------
552 //----------------------------------------------------------------------
553
554
555 enum
556 {
557 wxLOG_FatalError, // program can't continue, abort immediately
558 wxLOG_Error, // a serious error, user must be informed about it
559 wxLOG_Warning, // user is normally informed about it but may be ignored
560 wxLOG_Message, // normal message (i.e. normal output of a non GUI app)
561 wxLOG_Info, // informational message (a.k.a. 'Verbose')
562 wxLOG_Status, // informational: might go to the status line of GUI app
563 wxLOG_Debug, // never shown to the user, disabled in release mode
564 wxLOG_Trace, // trace messages are also only enabled in debug mode
565 wxLOG_Progress, // used for progress indicator (not yet)
566 wxLOG_User = 100 // user defined levels start here
567 };
568
569
570 class wxLog
571 {
572 public:
573 wxLog();
574
575 static bool IsEnabled();
576 static bool EnableLogging(bool doIt = TRUE);
577 static void OnLog(wxLogLevel level, const wxString& szString, int t=0);
578
579 virtual void Flush();
580 bool HasPendingMessages() const;
581
582 static void FlushActive();
583 static wxLog *GetActiveTarget();
584 static wxLog *SetActiveTarget(wxLog *pLogger);
585
586 static void Suspend();
587 static void Resume();
588
589 static void SetVerbose(bool bVerbose = TRUE);
590
591 static void DontCreateOnDemand();
592 static void SetTraceMask(wxTraceMask ulMask);
593 static void AddTraceMask(const wxString& str);
594 static void RemoveTraceMask(const wxString& str);
595 static void ClearTraceMasks();
596
597 static void SetTimestamp(const wxString& ts);
598 static const wxString& GetTimestamp();
599
600 bool GetVerbose() const;
601
602 static wxTraceMask GetTraceMask();
603 static bool IsAllowedTraceMask(const wxString& mask);
604
605 // static void TimeStamp(wxString *str);
606 %addmethods {
607 wxString TimeStamp() {
608 wxString msg;
609 wxLog::TimeStamp(&msg);
610 return msg;
611 }
612 }
613
614 };
615
616
617 class wxLogStderr : public wxLog
618 {
619 public:
620 wxLogStderr(/* TODO: FILE *fp = (FILE *) NULL*/);
621 };
622
623
624 class wxLogTextCtrl : public wxLog
625 {
626 public:
627 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
628 };
629
630
631 class wxLogGui : public wxLog
632 {
633 public:
634 wxLogGui();
635 };
636
637 class wxLogWindow : public wxLog
638 {
639 public:
640 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
641 const wxString& szTitle, // the title of the frame
642 bool bShow = TRUE, // show window immediately?
643 bool bPassToOld = TRUE); // pass log messages to the old target?
644
645 void Show(bool bShow = TRUE);
646 wxFrame *GetFrame() const;
647 wxLog *GetOldLog() const;
648 bool IsPassingMessages() const;
649 void PassMessages(bool bDoPass);
650 };
651
652
653 class wxLogChain : public wxLog
654 {
655 public:
656 wxLogChain(wxLog *logger);
657 void SetLog(wxLog *logger);
658 void PassMessages(bool bDoPass);
659 bool IsPassingMessages();
660 wxLog *GetOldLog();
661 };
662
663
664 unsigned long wxSysErrorCode();
665 const wxString wxSysErrorMsg(unsigned long nErrCode = 0);
666 void wxLogFatalError(const wxString& szFormat);
667 void wxLogError(const wxString& szFormat);
668 void wxLogWarning(const wxString& szFormat);
669 void wxLogMessage(const wxString& szFormat);
670 void wxLogInfo(const wxString& szFormat);
671 void wxLogVerbose(const wxString& szFormat);
672 void wxLogStatus(const wxString& szFormat);
673 %name(wxLogStatusFrame)void wxLogStatus(wxFrame *pFrame, const wxString& szFormat);
674 void wxLogSysError(const wxString& szFormat);
675
676
677 // wxLogFatalError helper: show the (fatal) error to the user in a safe way,
678 // i.e. without using wxMessageBox() for example because it could crash
679
680 // TODO: Why am I getting a link error on this???
681 // void wxSafeShowMessage(const wxString& title, const wxString& text);
682
683
684
685 // Suspress logging while an instance of this class exists
686 class wxLogNull
687 {
688 public:
689 wxLogNull();
690 ~wxLogNull();
691 };
692
693
694
695
696 %{
697 // A wxLog class that can be derived from in wxPython
698 class wxPyLog : public wxLog {
699 public:
700 wxPyLog() : wxLog() {}
701
702 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) {
703 bool found;
704 wxPyBeginBlockThreads();
705 if ((found = wxPyCBH_findCallback(m_myInst, "DoLog")))
706 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iOi)", level,
707 wx2PyString(szString), t));
708 wxPyEndBlockThreads();
709 if (! found)
710 wxLog::DoLog(level, szString, t);
711 }
712
713 virtual void DoLogString(const wxChar *szString, time_t t) {
714 bool found;
715 wxPyBeginBlockThreads();
716 if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString")))
717 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)",
718 wx2PyString(szString), t));
719 wxPyEndBlockThreads();
720 if (! found)
721 wxLog::DoLogString(szString, t);
722 }
723
724 PYPRIVATE;
725 };
726 %}
727
728 // Now tell SWIG about it
729 class wxPyLog : public wxLog {
730 public:
731 wxPyLog();
732 void _setCallbackInfo(PyObject* self, PyObject* _class);
733 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyLog)"
734 %addmethods { void Destroy() { delete self; } }
735
736 };
737
738
739 //----------------------------------------------------------------------
740
741
742 enum {
743 /* event type */
744 wxEVT_END_PROCESS
745 };
746
747
748 class wxProcessEvent : public wxEvent {
749 public:
750 wxProcessEvent(int id = 0, int pid = 0, int exitcode = 0);
751 int GetPid();
752 int GetExitCode();
753 int m_pid, m_exitcode;
754 };
755
756
757
758
759 %{ // C++ version of wxProcess derived class
760
761 class wxPyProcess : public wxProcess {
762 public:
763 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1)
764 : wxProcess(parent, id)
765 {}
766
767 DEC_PYCALLBACK_VOID_INTINT(OnTerminate);
768
769 PYPRIVATE;
770 };
771
772 IMP_PYCALLBACK_VOID_INTINT( wxPyProcess, wxProcess, OnTerminate);
773
774 %}
775
776
777 %name(wxProcess)class wxPyProcess : public wxEvtHandler {
778 public:
779 wxPyProcess(wxEvtHandler *parent = NULL, int id = -1);
780 %addmethods { void Destroy() { delete self; } }
781
782 void _setCallbackInfo(PyObject* self, PyObject* _class);
783 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxProcess)"
784
785 void base_OnTerminate(int pid, int status);
786
787 void Redirect();
788 bool IsRedirected();
789 void Detach();
790
791 wxInputStream *GetInputStream();
792 wxInputStream *GetErrorStream();
793 wxOutputStream *GetOutputStream();
794
795 void CloseOutput();
796 };
797
798
799 enum
800 {
801 // execute the process asynchronously
802 wxEXEC_ASYNC = 0,
803
804 // execute it synchronously, i.e. wait until it finishes
805 wxEXEC_SYNC = 1,
806
807 // under Windows, don't hide the child even if it's IO is redirected (this
808 // is done by default)
809 wxEXEC_NOHIDE = 2,
810
811 // under Unix, if the process is the group leader then killing -pid kills
812 // all children as well as pid
813 wxEXEC_MAKE_GROUP_LEADER = 4
814 };
815
816
817 long wxExecute(const wxString& command,
818 int flags = wxEXEC_ASYNC,
819 wxPyProcess *process = NULL);
820
821 //----------------------------------------------------------------------
822
823 %{
824 #if !wxUSE_JOYSTICK && !defined(__WXMSW__)
825 // A C++ stub class for wxJoystick for platforms that don't have it.
826 class wxJoystick : public wxObject {
827 public:
828 wxJoystick(int joystick = wxJOYSTICK1) {
829 wxPyBeginBlockThreads();
830 PyErr_SetString(PyExc_NotImplementedError, "wxJoystick is not available on this platform.");
831 wxPyEndBlockThreads();
832 }
833 wxPoint GetPosition() { return wxPoint(-1,-1); }
834 int GetZPosition() { return -1; }
835 int GetButtonState() { return -1; }
836 int GetPOVPosition() { return -1; }
837 int GetPOVCTSPosition() { return -1; }
838 int GetRudderPosition() { return -1; }
839 int GetUPosition() { return -1; }
840 int GetVPosition() { return -1; }
841 int GetMovementThreshold() { return -1; }
842 void SetMovementThreshold(int threshold) {}
843
844 bool IsOk(void) { return FALSE; }
845 int GetNumberJoysticks() { return -1; }
846 int GetManufacturerId() { return -1; }
847 int GetProductId() { return -1; }
848 wxString GetProductName() { return ""; }
849 int GetXMin() { return -1; }
850 int GetYMin() { return -1; }
851 int GetZMin() { return -1; }
852 int GetXMax() { return -1; }
853 int GetYMax() { return -1; }
854 int GetZMax() { return -1; }
855 int GetNumberButtons() { return -1; }
856 int GetNumberAxes() { return -1; }
857 int GetMaxButtons() { return -1; }
858 int GetMaxAxes() { return -1; }
859 int GetPollingMin() { return -1; }
860 int GetPollingMax() { return -1; }
861 int GetRudderMin() { return -1; }
862 int GetRudderMax() { return -1; }
863 int GetUMin() { return -1; }
864 int GetUMax() { return -1; }
865 int GetVMin() { return -1; }
866 int GetVMax() { return -1; }
867
868 bool HasRudder() { return FALSE; }
869 bool HasZ() { return FALSE; }
870 bool HasU() { return FALSE; }
871 bool HasV() { return FALSE; }
872 bool HasPOV() { return FALSE; }
873 bool HasPOV4Dir() { return FALSE; }
874 bool HasPOVCTS() { return FALSE; }
875
876 bool SetCapture(wxWindow* win, int pollingFreq = 0) { return FALSE; }
877 bool ReleaseCapture() { return FALSE; }
878 };
879 #endif
880 %}
881
882
883 class wxJoystick : public wxObject {
884 public:
885 wxJoystick(int joystick = wxJOYSTICK1);
886 ~wxJoystick();
887
888 wxPoint GetPosition();
889 int GetZPosition();
890 int GetButtonState();
891 int GetPOVPosition();
892 int GetPOVCTSPosition();
893 int GetRudderPosition();
894 int GetUPosition();
895 int GetVPosition();
896 int GetMovementThreshold();
897 void SetMovementThreshold(int threshold) ;
898
899 bool IsOk(void);
900 int GetNumberJoysticks();
901 int GetManufacturerId();
902 int GetProductId();
903 wxString GetProductName();
904 int GetXMin();
905 int GetYMin();
906 int GetZMin();
907 int GetXMax();
908 int GetYMax();
909 int GetZMax();
910 int GetNumberButtons();
911 int GetNumberAxes();
912 int GetMaxButtons();
913 int GetMaxAxes();
914 int GetPollingMin();
915 int GetPollingMax();
916 int GetRudderMin();
917 int GetRudderMax();
918 int GetUMin();
919 int GetUMax();
920 int GetVMin();
921 int GetVMax();
922
923 bool HasRudder();
924 bool HasZ();
925 bool HasU();
926 bool HasV();
927 bool HasPOV();
928 bool HasPOV4Dir();
929 bool HasPOVCTS();
930
931 bool SetCapture(wxWindow* win, int pollingFreq = 0);
932 bool ReleaseCapture();
933 };
934
935 //----------------------------------------------------------------------
936
937 %{
938 #if !wxUSE_WAVE
939 // A C++ stub class for wxWave for platforms that don't have it.
940 class wxWave : public wxObject
941 {
942 public:
943 wxWave(const wxString& fileName, bool isResource = FALSE) {
944 wxPyBeginBlockThreads();
945 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
946 wxPyEndBlockThreads();
947 }
948 wxWave(int size, const wxByte* data) {
949 wxPyBeginBlockThreads();
950 PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform.");
951 wxPyEndBlockThreads();
952 }
953
954 ~wxWave() {}
955
956 bool IsOk() const { return FALSE; }
957 bool Play(bool async = TRUE, bool looped = FALSE) const { return FALSE; }
958 };
959
960 #endif
961 %}
962
963 class wxWave : public wxObject
964 {
965 public:
966 wxWave(const wxString& fileName, bool isResource = FALSE);
967 ~wxWave();
968
969 bool IsOk() const;
970 bool Play(bool async = TRUE, bool looped = FALSE) const;
971 };
972
973 %new wxWave* wxWaveData(const wxString& data);
974 %{ // Implementations of some alternate "constructors"
975 wxWave* wxWaveData(const wxString& data) {
976 return new wxWave(data.Len(), (wxByte*)data.c_str());
977 }
978 %}
979
980
981 //----------------------------------------------------------------------
982
983 enum wxMailcapStyle
984 {
985 wxMAILCAP_STANDARD = 1,
986 wxMAILCAP_NETSCAPE = 2,
987 wxMAILCAP_KDE = 4,
988 wxMAILCAP_GNOME = 8,
989
990 wxMAILCAP_ALL = 15
991 };
992
993
994
995 class wxFileTypeInfo
996 {
997 public:
998 // ctors
999 // a normal item
1000 wxFileTypeInfo(const char* mimeType,
1001 const char* openCmd,
1002 const char* printCmd,
1003 const char* desc);
1004
1005
1006 // the array elements correspond to the parameters of the ctor above in
1007 // the same order
1008 %name(wxFileTypeInfoSequence)wxFileTypeInfo(const wxArrayString& sArray);
1009
1010 // invalid item - use this to terminate the array passed to
1011 // wxMimeTypesManager::AddFallbacks
1012 %name(wxNullFileTypeInfo)wxFileTypeInfo();
1013
1014
1015 // test if this object can be used
1016 bool IsValid() const;
1017
1018 // setters
1019 // set the icon info
1020 void SetIcon(const wxString& iconFile, int iconIndex = 0);
1021
1022 // set the short desc
1023 void SetShortDesc(const wxString& shortDesc);
1024
1025 // accessors
1026 // get the MIME type
1027 const wxString& GetMimeType() const;
1028 // get the open command
1029 const wxString& GetOpenCommand() const;
1030 // get the print command
1031 const wxString& GetPrintCommand() const;
1032 // get the short description (only used under Win32 so far)
1033 const wxString& GetShortDesc() const;
1034 // get the long, user visible description
1035 const wxString& GetDescription() const;
1036
1037
1038 // get the array of all extensions
1039 //const wxArrayString& GetExtensions() const;
1040 %addmethods {
1041 PyObject* GetExtensions() {
1042 wxArrayString& arr = (wxArrayString&)self->GetExtensions();
1043 return wxArrayString2PyList_helper(arr);
1044 }
1045 }
1046
1047 int GetExtensionsCount() const;
1048
1049 // get the icon info
1050 const wxString& GetIconFile() const;
1051 int GetIconIndex() const;
1052 };
1053
1054
1055
1056
1057 class wxFileType
1058 {
1059 public:
1060
1061 // TODO: Make a wxPyMessageParameters with virtual GetParamValue...
1062
1063 // An object of this class must be passed to Get{Open|Print}Command. The
1064 // default implementation is trivial and doesn't know anything at all about
1065 // parameters, only filename and MIME type are used (so it's probably ok for
1066 // Windows where %{param} is not used anyhow)
1067 class MessageParameters
1068 {
1069 public:
1070 // ctors
1071 MessageParameters(const wxString& filename=wxPyEmptyString,
1072 const wxString& mimetype=wxPyEmptyString);
1073
1074 // accessors (called by GetOpenCommand)
1075 // filename
1076 const wxString& GetFileName() const;
1077 // mime type
1078 const wxString& GetMimeType() const;;
1079
1080 // override this function in derived class
1081 virtual wxString GetParamValue(const wxString& name) const;
1082
1083 // virtual dtor as in any base class
1084 virtual ~MessageParameters();
1085 };
1086
1087
1088 // ctor from static data
1089 wxFileType(const wxFileTypeInfo& ftInfo);
1090
1091 // return the MIME type for this file type
1092 %addmethods {
1093 PyObject* GetMimeType() {
1094 wxString str;
1095 if (self->GetMimeType(&str)) {
1096 #if wxUSE_UNICODE
1097 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1098 #else
1099 return PyString_FromStringAndSize(str.c_str(), str.Len());
1100 #endif
1101 }
1102 else
1103 RETURN_NONE();
1104 }
1105 PyObject* GetMimeTypes() {
1106 wxArrayString arr;
1107 if (self->GetMimeTypes(arr))
1108 return wxArrayString2PyList_helper(arr);
1109 else
1110 RETURN_NONE();
1111 }
1112 }
1113
1114
1115 // Get all extensions associated with this file type
1116 %addmethods {
1117 PyObject* GetExtensions() {
1118 wxArrayString arr;
1119 if (self->GetExtensions(arr))
1120 return wxArrayString2PyList_helper(arr);
1121 else
1122 RETURN_NONE();
1123 }
1124 }
1125
1126
1127 %addmethods {
1128 // Get the icon corresponding to this file type
1129 %new wxIcon* GetIcon() {
1130 wxIcon icon;
1131 if (self->GetIcon(&icon))
1132 return new wxIcon(icon);
1133 else
1134 return NULL;
1135 }
1136
1137 // Get the icon corresponding to this file type, the name of the file
1138 // where this icon resides, and its index in this file if applicable.
1139 PyObject* GetIconInfo() {
1140 wxIcon icon;
1141 wxString iconFile;
1142 int iconIndex;
1143 if (self->GetIcon(&icon, &iconFile, &iconIndex)) {
1144 wxPyBeginBlockThreads();
1145 PyObject* tuple = PyTuple_New(3);
1146 PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(icon),
1147 "wxIcon", TRUE));
1148 #if wxUSE_UNICODE
1149 PyTuple_SetItem(tuple, 1, PyUnicode_FromUnicode(iconFile.c_str(), iconFile.Len()));
1150 #else
1151 PyTuple_SetItem(tuple, 1, PyString_FromStringAndSize(iconFile.c_str(), iconFile.Len()));
1152 #endif
1153 PyTuple_SetItem(tuple, 2, PyInt_FromLong(iconIndex));
1154 wxPyEndBlockThreads();
1155 return tuple;
1156 }
1157 else
1158 RETURN_NONE();
1159 }
1160 }
1161
1162 %addmethods {
1163 // get a brief file type description ("*.txt" => "text document")
1164 PyObject* GetDescription() {
1165 wxString str;
1166 if (self->GetDescription(&str)) {
1167 #if wxUSE_UNICODE
1168 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1169 #else
1170 return PyString_FromStringAndSize(str.c_str(), str.Len());
1171 #endif
1172 } else
1173 RETURN_NONE();
1174 }
1175 }
1176
1177
1178 // get the command to open/execute the file of given type
1179 %addmethods {
1180 PyObject* GetOpenCommand(const wxString& filename,
1181 const wxString& mimetype=wxPyEmptyString) {
1182 wxString str;
1183 if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype))) {
1184 #if wxUSE_UNICODE
1185 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1186 #else
1187 return PyString_FromStringAndSize(str.c_str(), str.Len());
1188 #endif
1189 } else
1190 RETURN_NONE();
1191 }
1192 }
1193
1194
1195 // get the command to print the file of given type
1196 %addmethods {
1197 PyObject* GetPrintCommand(const wxString& filename,
1198 const wxString& mimetype=wxPyEmptyString) {
1199 wxString str;
1200 if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype))) {
1201 #if wxUSE_UNICODE
1202 return PyUnicode_FromUnicode(str.c_str(), str.Len());
1203 #else
1204 return PyString_FromStringAndSize(str.c_str(), str.Len());
1205 #endif
1206 } else
1207 RETURN_NONE();
1208 }
1209 }
1210
1211
1212 // Get all commands defined for this file type
1213 %addmethods {
1214 PyObject* GetAllCommands(const wxString& filename,
1215 const wxString& mimetype=wxPyEmptyString) {
1216 wxArrayString verbs;
1217 wxArrayString commands;
1218 if (self->GetAllCommands(&verbs, &commands,
1219 wxFileType::MessageParameters(filename, mimetype))) {
1220 wxPyBeginBlockThreads();
1221 PyObject* tuple = PyTuple_New(2);
1222 PyTuple_SetItem(tuple, 0, wxArrayString2PyList_helper(verbs));
1223 PyTuple_SetItem(tuple, 1, wxArrayString2PyList_helper(commands));
1224 wxPyEndBlockThreads();
1225 return tuple;
1226 }
1227 else
1228 RETURN_NONE();
1229 }
1230 }
1231
1232
1233 // set an arbitrary command, ask confirmation if it already exists and
1234 // overwriteprompt is TRUE
1235 bool SetCommand(const wxString& cmd, const wxString& verb,
1236 bool overwriteprompt = TRUE);
1237
1238 bool SetDefaultIcon(const wxString& cmd = wxPyEmptyString, int index = 0);
1239
1240
1241 // remove the association for this filetype from the system MIME database:
1242 // notice that it will only work if the association is defined in the user
1243 // file/registry part, we will never modify the system-wide settings
1244 bool Unassociate();
1245
1246 // operations
1247 // expand a string in the format of GetOpenCommand (which may contain
1248 // '%s' and '%t' format specificators for the file name and mime type
1249 // and %{param} constructions).
1250 static wxString ExpandCommand(const wxString& command,
1251 const MessageParameters& params);
1252
1253 // dtor (not virtual, shouldn't be derived from)
1254 ~wxFileType();
1255
1256 };
1257
1258
1259
1260
1261 class wxMimeTypesManager
1262 {
1263 public:
1264 // static helper functions
1265 // -----------------------
1266
1267 // check if the given MIME type is the same as the other one: the
1268 // second argument may contain wildcards ('*'), but not the first. If
1269 // the types are equal or if the mimeType matches wildcard the function
1270 // returns TRUE, otherwise it returns FALSE
1271 static bool IsOfType(const wxString& mimeType, const wxString& wildcard);
1272
1273 // ctor
1274 wxMimeTypesManager();
1275
1276 // loads data from standard files according to the mailcap styles
1277 // specified: this is a bitwise OR of wxMailcapStyle values
1278 //
1279 // use the extraDir parameter if you want to look for files in another
1280 // directory
1281 void Initialize(int mailcapStyle = wxMAILCAP_STANDARD,
1282 const wxString& extraDir = wxPyEmptyString);
1283
1284 // and this function clears all the data from the manager
1285 void ClearData();
1286
1287 // Database lookup: all functions return a pointer to wxFileType object
1288 // whose methods may be used to query it for the information you're
1289 // interested in. If the return value is !NULL, caller is responsible for
1290 // deleting it.
1291 // get file type from file extension
1292 %new wxFileType *GetFileTypeFromExtension(const wxString& ext);
1293
1294 // get file type from MIME type (in format <category>/<format>)
1295 %new wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
1296
1297 // other operations: return TRUE if there were no errors or FALSE if there
1298 // were some unreckognized entries (the good entries are always read anyhow)
1299 //
1300
1301 // read in additional file (the standard ones are read automatically)
1302 // in mailcap format (see mimetype.cpp for description)
1303 //
1304 // 'fallback' parameter may be set to TRUE to avoid overriding the
1305 // settings from other, previously parsed, files by this one: normally,
1306 // the files read most recently would override the older files, but with
1307 // fallback == TRUE this won't happen
1308 bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
1309
1310 // read in additional file in mime.types format
1311 bool ReadMimeTypes(const wxString& filename);
1312
1313 // enumerate all known MIME types
1314 %addmethods {
1315 PyObject* EnumAllFileTypes() {
1316 wxArrayString arr;
1317 self->EnumAllFileTypes(arr);
1318 return wxArrayString2PyList_helper(arr);
1319 }
1320 }
1321
1322 // these functions can be used to provide default values for some of the
1323 // MIME types inside the program itself (you may also use
1324 // ReadMailcap(filenameWithDefaultTypes, TRUE /* use as fallback */) to
1325 // achieve the same goal, but this requires having this info in a file).
1326 //
1327 void AddFallback(const wxFileTypeInfo& ft);
1328
1329
1330 // create or remove associations
1331
1332 // create a new association using the fields of wxFileTypeInfo (at least
1333 // the MIME type and the extension should be set)
1334 // if the other fields are empty, the existing values should be left alone
1335 %new wxFileType *Associate(const wxFileTypeInfo& ftInfo);
1336
1337 // undo Associate()
1338 bool Unassociate(wxFileType *ft) ;
1339
1340 // dtor (not virtual, shouldn't be derived from)
1341 ~wxMimeTypesManager();
1342 };
1343
1344
1345 %readonly
1346 %{
1347 #if 0
1348 %}
1349 extern wxMimeTypesManager* wxTheMimeTypesManager;
1350 %{
1351 #endif
1352 %}
1353 %readwrite
1354
1355 //----------------------------------------------------------------------
1356
1357 %{
1358 #include <wx/docview.h>
1359 %}
1360
1361 class wxFileHistory : public wxObject
1362 {
1363 public:
1364 wxFileHistory(int maxFiles = 9);
1365 ~wxFileHistory();
1366
1367 // Operations
1368 void AddFileToHistory(const wxString& file);
1369 void RemoveFileFromHistory(int i);
1370 int GetMaxFiles() const;
1371 void UseMenu(wxMenu *menu);
1372
1373 // Remove menu from the list (MDI child may be closing)
1374 void RemoveMenu(wxMenu *menu);
1375
1376 void Load(wxConfigBase& config);
1377 void Save(wxConfigBase& config);
1378
1379 void AddFilesToMenu();
1380 %name(AddFilesToThisMenu)void AddFilesToMenu(wxMenu* menu);
1381
1382 // Accessors
1383 wxString GetHistoryFile(int i) const;
1384
1385 // A synonym for GetNoHistoryFiles
1386 int GetCount() const;
1387 int GetNoHistoryFiles() const;
1388
1389 };
1390
1391 //----------------------------------------------------------------------
1392 //----------------------------------------------------------------------
1393
1394
1395 %init %{
1396 wxPyPtrTypeMap_Add("wxDragImage", "wxGenericDragImage");
1397 wxPyPtrTypeMap_Add("wxProcess", "wxPyProcess");
1398 %}
1399
1400 //----------------------------------------------------------------------
1401