Esempio n. 1
0
bool MainBook::ClosePage(const wxString& text)
{
    int numPageClosed(0);
    bool closed = ClosePage(FindPage(text));
    while(closed) {
        ++numPageClosed;
        closed = ClosePage(FindPage(text));
    }
    return numPageClosed > 0;
}
Esempio n. 2
0
void Notebook::OnPageClose(wxAuiNotebookEvent& event)
{
  Edit* edit = static_cast<Edit*>(GetPage(GetSelection()));
  if (edit) {
    ClosePage(edit);
  }
}
Esempio n. 3
0
void Notebook::CloseAll()
{
  const size_t page_count = GetPageCount();
  for (size_t i = 0; i < page_count; ++i) {
    ClosePage(static_cast<Edit*>(GetPage(i)));
  }
}
Esempio n. 4
0
void MainBook::OnClosePage(wxBookCtrlEvent& e)
{
    clWindowUpdateLocker locker(this);
    int where = e.GetSelection();
    if(where == wxNOT_FOUND) {
        return;
    }
    wxWindow* page = m_book->GetPage((size_t)where);
    if(page) ClosePage(page);
}
//----------------------------------------------------------------------------------------------
//	wmNotify
//----------------------------------------------------------------------------------------------
VOID CControllerPage::wmNotify( NMHDR * Notify )
{
	//	通知メッセージによって処理を振り分ける
	switch( Notify->code )
	{
		case PSN_APPLY:
			//	互換性の設定が変わっていればダイアログを表示する
			if( ( DeviceSetting.ControllerCount	!= CurrentSetting->ControllerCount )
			||	( DeviceSetting.LimitationMode	!= CurrentSetting->LimitationMode ) )
			{
				ShowMessageBox(
					 IDS_RESTART_TITLE
					,IDS_RESTART_MESSAGE
					,NULL
					,MB_OK | MB_ICONINFORMATION );
			}

			//	コントローラーの設定を変更する
			Setting->SaveRegistry();
			Device->Apply();

			//	ステータス エリア アイコンに変更を通知する
			SendMessage(
				 FindWindow( X360WCSAI_CLASS_NAME, NULL )
				,WM_STATUS_AREA_ICON_NOTIFY
				,UPDATE_SETTING
				,NULL );

			//	プロパティ シートを閉じる
			if( ((PSHNOTIFY *)Notify)->lParam == TRUE )
			{
				ClosePage();
			}
			break;

		case PSN_RESET:
			//	プロパティ シートを閉じる
			ClosePage();
			break;
	}
}
Esempio n. 6
0
void wxSTEditorNotebook::OnMiddleUp(wxMouseEvent &event)
{
    wxPoint pos = event.GetPosition();
    long flags = 0;
    int page = HitTest(pos, &flags);

    if ((page != wxNOT_FOUND) && ((flags & wxBK_HITTEST_NOWHERE) == 0))
    {
        ClosePage(page, true);
    }
    else
        event.Skip();
}
Esempio n. 7
0
bool MainBook::AddPage(wxWindow *win, const wxString &text, const wxBitmap &bmp, bool selected, size_t insert_at_index /*=wxNOT_FOUND*/)
{
    if (m_book->GetPageIndex(win) != Notebook::npos)
        return false;

    long MaxBuffers = clConfig::Get().Read("MaxOpenedTabs", 15);
    bool closeLastTab = ((long)(m_book->GetPageCount()) >= MaxBuffers) && GetUseBuffereLimit();
    if ((insert_at_index == (size_t)wxNOT_FOUND) || (insert_at_index >= m_book->GetPageCount())) {

#if CL_USE_NATIVEBOOK
        // There seems to be a bug in wxGTK where we can't change
        // the selection programtically
        int next_pos = m_book->GetPageCount();
#endif
        m_book->AddPage(win, text, closeLastTab ? true : selected, bmp);

#if CL_USE_NATIVEBOOK
        // If the newly added page is expected to be the selected one
        // and it is NOT of type IEditor we provide a workaround that
        // uses direct gtk calls
        bool shouldSelect = (closeLastTab ? true : selected);
        IEditor *editor = dynamic_cast<IEditor*>(win);
        if(shouldSelect && (m_book->GetSelection() != (size_t)next_pos) && !editor) {
            // failed to insert the page AND the page is not of type
            // IEditor
            gtk_widget_show_all (win->m_widget);
            m_book->SetSelection(next_pos);
        }
#endif
    } else {
        m_book->InsertPage(insert_at_index, win, text, closeLastTab ? true : selected, bmp);
    }

    if( closeLastTab ) {
        // We have reached the limit of the number of open buffers
        // Close the last used buffer
        const wxArrayPtrVoid &arr = m_book->GetHistory();
        if ( arr.GetCount() ) {
            // We got at least one page, close the last used
            wxWindow *tab = static_cast<wxWindow*>(arr.Item(arr.GetCount()-1));
            ClosePage(tab);
        }
    }

#if !CL_USE_NATIVEBOOK
    if(m_book->GetPageCount() == 1) {
        m_book->GetSizer()->Layout();
    }
#endif
    return true;
}
Esempio n. 8
0
bool MainBook::AddPage(wxWindow* win,
    const wxString& text,
    const wxString& tooltip,
    const wxBitmap& bmp,
    bool selected,
    int insert_at_index /*=wxNOT_FOUND*/)
{
    if(m_book->GetPageIndex(win) != wxNOT_FOUND) return false;

    long MaxBuffers = clConfig::Get().Read(kConfigMaxOpenedTabs, 15);
    bool closeLastTab = ((long)(m_book->GetPageCount()) >= MaxBuffers) && GetUseBuffereLimit();
    if(insert_at_index == wxNOT_FOUND) {
        m_book->AddPage(win, text, selected, bmp);
    } else {
        if(!m_book->InsertPage(insert_at_index, win, text, selected, bmp)) {
            // failed to insert, append it
            m_book->AddPage(win, text, selected, bmp);
        }
    }

    if(closeLastTab) {
#if 0
        // We have reached the limit of the number of open buffers
        // Close the last used buffer
        const wxArrayPtrVoid& arr = m_book->GetHistory();
        if(arr.GetCount()) {
            // We got at least one page, close the last used
            wxWindow* tab = static_cast<wxWindow*>(arr.Item(arr.GetCount() - 1));
            ClosePage(tab);
        }
#endif
    }

#if !CL_USE_NATIVEBOOK
    if(m_book->GetPageCount() == 1) {
        m_book->GetSizer()->Layout();
    }
#endif
    if(!tooltip.IsEmpty()) {
        m_book->SetPageToolTip(m_book->GetPageIndex(win), tooltip);
    }
    return true;
}
Esempio n. 9
0
void MainBook::CloseTabsToTheRight(wxWindow* win)
{
    wxString text;

    // clWindowUpdateLocker locker(this);

    // Get list of tabs to close
    std::vector<wxWindow*> windows;
    bool currentWinFound(false);
    for(size_t i = 0; i < m_book->GetPageCount(); ++i) {
        if(currentWinFound) {
            windows.push_back(m_book->GetPage(i));
        } else {
            if(m_book->GetPage(i) == win) {
                currentWinFound = true;
            }
        }
    }

    // start from right to left
    if(windows.empty()) return;

    std::vector<wxWindow*> tabsToClose;
    for(int i = (int)(windows.size() - 1); i >= 0; --i) {
        if(windows.at(i) == win) {
            break;
        }
        tabsToClose.push_back(windows.at(i));
    }

    if(tabsToClose.empty()) return;

    for(size_t i = 0; i < tabsToClose.size(); ++i) {
        ClosePage(tabsToClose.at(i));
    }

#ifdef __WXMAC__
    m_book->GetSizer()->Layout();
#endif
}
Esempio n. 10
0
void MainBook::ClosePageVoid(wxWindow* win) { ClosePage(win); }
Esempio n. 11
0
bool wxSTEditorNotebook::HandleMenuEvent(wxCommandEvent &event)
{
    wxSTERecursionGuard guard(m_rGuard_HandleMenuEvent);
    if (guard.IsInside()) return false;

    int n_page = (int)GetPageCount();
    int win_id = event.GetId();

    switch (win_id)
    {
        case wxID_NEW:
        {
            NewPage();
            return true;
        }
        case wxID_OPEN:
        {
            LoadFiles();
            return true;
        }
        case wxID_SAVEAS:
        {
            wxSTEditor *editor = GetEditor();
            if (!editor) return true; // event handled, but we couldn't do anything with it.

            if (!editor->IsFileFromDisk())
            {
                editor->SaveFile(true);
            }
            else
            {
                wxFileName selectedFileName;
                wxString   selectedFileEncoding;
                bool       selected_file_bom = false;

                bool ok = editor->SaveFileDialog(true, wxEmptyString, &selectedFileName, &selectedFileEncoding, &selected_file_bom);
                if (!ok) return true; // they probably canceled the dialog

                if (selectedFileName == editor->GetFileName())
                {
                    // They want to save to the same filename, update current editor.
                    editor->SaveFile(selectedFileName, selectedFileEncoding, selected_file_bom);
                    return true;
                }
                else
                {
                    // Make a new editor for the new filename, leave the original editor as is.
                    wxSTEditorSplitter *splitter = CreateSplitter(wxID_ANY);
                    wxCHECK_MSG(splitter, true, wxT("Invalid splitter"));
                    wxSTEditor *newEditor = splitter->GetEditor();
                    wxCHECK_MSG(newEditor, true, wxT("Invalid splitter editor"));

                    // Make this new editor identical to the original one
                    // these are probably not necessary
                    //splitter->GetEditor()->SetOptions(editor->GetOptions());
                    //splitter->GetEditor()->RegisterPrefs(editor->GetEditorPrefs());
                    //splitter->GetEditor()->RegisterStyles(editor->GetEditorStyles());
                    //splitter->GetEditor()->RegisterLangs(editor->GetEditorLangs());

                    newEditor->SetLanguage(editor->GetLanguageId());
                    newEditor->SetFileName(editor->GetFileName());
                    newEditor->SetFileEncoding(editor->GetFileEncoding());
                    newEditor->SetFileBOM(editor->GetFileBOM());

                    newEditor->SetText(editor->GetText());
                    newEditor->ColouriseDocument();
                    newEditor->GotoPos(editor->PositionFromLine(editor->LineFromPosition(editor->GetCurrentPos())));
                    newEditor->GotoPos(editor->GetCurrentPos());
                    newEditor->ScrollToLine(editor->GetFirstVisibleLine());

                    // if we can save it, then add it to the notebook
                    if (newEditor->SaveFile(selectedFileName, selectedFileEncoding, selected_file_bom))
                    {
                        if (!InsertEditorSplitter(-1, splitter, true))
                            splitter->Destroy();
                    }
                    else
                        splitter->Destroy(); // problem saving, delete new editor
                }
            }
            return true;
        }
        case ID_STN_SAVE_ALL:
        {
            SaveAllFiles();
            return true;
        }
        case ID_STN_CLOSE_PAGE:
        {
            if ((GetSelection() != -1) && GetEditor(GetSelection()))
            {
                ClosePage(GetSelection(), true);
            }
            return true;
        }
        case ID_STN_CLOSE_ALL:
        {
            if (wxYES == wxMessageBox(_("Close all pages?"), _("Confim closing all pages"),
                                   wxICON_QUESTION|wxYES_NO, this))
            {
                CloseAllPages(true, -1);
            }
            return true;
        }
        case ID_STN_CLOSE_ALL_OTHERS:
        {
            CloseAllPages(true, GetSelection());
            return true;
        }
        case ID_STN_WIN_PREVIOUS:
        {
            if ((GetPageCount() > 0) && (GetSelection() - 1 >= 0))
                SetSelection(GetSelection() - 1);
            else if (GetPageCount() > 0)
                SetSelection((int)GetPageCount() - 1);
            return true;
        }
        case ID_STN_WIN_NEXT:
        {
            if ((GetPageCount() > 0) && (GetSelection() + 1 < (int)GetPageCount()))
                SetSelection(GetSelection() + 1);
            else if (GetPageCount() > 0)
                SetSelection(0);
            return true;
        }
        case ID_STN_WINDOWS:
        {
            wxSTEditorWindowsDialog(this, _("Windows"));
            return true;
        }
        case ID_STE_PASTE_NEW:
        {
            wxString text;
            if (wxSTEditor::GetClipboardText(&text))
            {
                NewPage();
                wxSTEditor* editor = GetEditor();
                if (editor)
                {
                    editor->SetText(text);
                    editor->SetModified(false);
                }
            }
            return true;
        }
        default:
        {
            if ((win_id >= ID_STN_GOTO_PAGE_START) && (win_id < ID_STN_GOTO_PAGE_START+n_page))
            {
                SetSelection(win_id - ID_STN_GOTO_PAGE_START);
                return true;
            }
            else if ((win_id >= ID_STN_CLOSE_PAGE_START) && (win_id < ID_STN_CLOSE_PAGE_START+n_page))
            {
                ClosePage(win_id - ID_STN_CLOSE_PAGE_START);
                return true;
            }
            break;
        }
    }
    return false;
}
Esempio n. 12
0
bool PDF_PLOTTER::EndPlot()
{
    wxASSERT( outputFile );

    // Close the current page (often the only one)
    ClosePage();

    /* We need to declare the resources we're using (fonts in particular)
       The useful standard one is the Helvetica family. Adding external fonts
       is *very* involved! */
    struct {
        const char *psname;
        const char *rsname;
        int font_handle;
    } fontdefs[4] = {
        { "/Helvetica",             "/KicadFont",   0 },
        { "/Helvetica-Oblique",     "/KicadFontI",  0 },
        { "/Helvetica-Bold",        "/KicadFontB",  0 },
        { "/Helvetica-BoldOblique", "/KicadFontBI", 0 }
    };

    /* Declare the font resources. Since they're builtin fonts, no descriptors (yay!)
       We'll need metrics anyway to do any aligment (these are in the shared with
       the postscript engine) */
    for( int i = 0; i < 4; i++ )
    {
        fontdefs[i].font_handle = startPdfObject();
        fprintf( outputFile,
                 "<< /BaseFont %s\n"
                 "   /Type /Font\n"
                 "   /Subtype /Type1\n"

                 /* Adobe is so Mac-based that the nearest thing to Latin1 is
                    the Windows ANSI encoding! */
                 "   /Encoding /WinAnsiEncoding\n"
                 ">>\n",
                 fontdefs[i].psname );
        closePdfObject();
    }

    // Named font dictionary (was allocated, now we emit it)
    startPdfObject( fontResDictHandle );
    fputs( "<<\n", outputFile );
    for( int i = 0; i < 4; i++ )
    {
        fprintf( outputFile, "    %s %d 0 R\n",
                fontdefs[i].rsname, fontdefs[i].font_handle );
    }
    fputs( ">>\n", outputFile );
    closePdfObject();

    /* The page tree: it's a B-tree but luckily we only have few pages!
       So we use just an array... The handle was allocated at the beginning,
       now we instantiate the corresponding object */
    startPdfObject( pageTreeHandle );
    fputs( "<<\n"
           "/Type /Pages\n"
           "/Kids [\n", outputFile );

    for( unsigned i = 0; i < pageHandles.size(); i++ )
        fprintf( outputFile, "%d 0 R\n", pageHandles[i] );

    fprintf( outputFile,
            "]\n"
            "/Count %ld\n"
             ">>\n", (long) pageHandles.size() );
    closePdfObject();


    // The info dictionary
    int infoDictHandle = startPdfObject();
    char date_buf[250];
    time_t ltime = time( NULL );
    strftime( date_buf, 250, "D:%Y%m%d%H%M%S",
              localtime( &ltime ) );
    fprintf( outputFile,
             "<<\n"
             "/Producer (KiCAD PDF)\n"
             "/CreationDate (%s)\n"
             "/Creator (%s)\n"
             "/Title (%s)\n"
             "/Trapped false\n",
             date_buf,
             TO_UTF8( creator ),
             TO_UTF8( filename ) );

    fputs( ">>\n", outputFile );
    closePdfObject();

    // The catalog, at last
    int catalogHandle = startPdfObject();
    fprintf( outputFile,
             "<<\n"
             "/Type /Catalog\n"
             "/Pages %d 0 R\n"
             "/Version /1.5\n"
             "/PageMode /UseNone\n"
             "/PageLayout /SinglePage\n"
             ">>\n", pageTreeHandle );
    closePdfObject();

    /* Emit the xref table (format is crucial to the byte, each entry must
       be 20 bytes long, and object zero must be done in that way). Also
       the offset must be kept along for the trailer */
    long xref_start = ftell( outputFile );
    fprintf( outputFile,
             "xref\n"
             "0 %ld\n"
             "0000000000 65535 f \n", (long) xrefTable.size() );
    for( unsigned i = 1; i < xrefTable.size(); i++ )
    {
        fprintf( outputFile, "%010ld 00000 n \n", xrefTable[i] );
    }

    // Done the xref, go for the trailer
    fprintf( outputFile,
             "trailer\n"
             "<< /Size %lu /Root %d 0 R /Info %d 0 R >>\n"
             "startxref\n"
             "%ld\n" // The offset we saved before
             "%%%%EOF\n",
             (unsigned long) xrefTable.size(), catalogHandle, infoDictHandle, xref_start );

    fclose( outputFile );
    outputFile = NULL;

    return true;
}