Changeset 351


Ignore:
Timestamp:
Apr 3, 2010, 8:28:09 PM (11 years ago)
Author:
dmik
Message:

branches/kmk: Ask the user to save the document if it was modified.

Location:
branches/kmk/Lucide
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/kmk/Lucide/gui/Makefile.kmk

    r318 r351  
    6969#
    7070Lucide_lng_INST          = $(notdir $(PATH_BIN))
    71 Lucide_lng_SOURCES       = $(wildcard $(PATH_SUB_CURRENT)/lng/*.lng)
     71Lucide_lng_SOURCES      := $(wildcard $(PATH_SUB_CURRENT)/../lng/*.lng)
    7272
    7373include $(FILE_KBUILD_SUB_FOOTER)
  • branches/kmk/Lucide/gui/docViewer.cpp

    r349 r351  
    7777    entry.type = field->getType( ev );
    7878    entry.supported = false;
     79    entry.modified = false;
    7980
    8081    switch( entry.type ) {
     
    119120    textField   = NULL;
    120121    textFieldPage = 0;
     122    textFieldIndex = 0;
    121123    doc         = NULL;
    122124    totalpages  = 0;
     
    258260void DocumentViewer::setDocument( LuDocument *_doc )
    259261{
    260     close();
     262    close( true );
    261263    doc = _doc;
    262264
     
    325327
    326328// closes the document
    327 void DocumentViewer::close()
     329bool DocumentViewer::close( bool force )
    328330{
    329331    if ( closed ) {
    330         return;
     332        return true;
     333    }
     334
     335    if ( !force ) {
     336        // check if the document was modified
     337        bool modified = false;
     338        if ( inputFields != NULL ) {
     339            for ( long pg = 0; pg < totalpages; ++pg ) {
     340                if ( inputFields[ pg ].fields == NULL )
     341                    continue;
     342                for ( unsigned long i = 0; i < inputFields[ pg ].fields->_length; ++i ) {
     343                    if ( inputFields[ pg ].cache[ i ].modified ) {
     344                        modified = true;
     345                        break;
     346                    }
     347                }
     348            }
     349        }
     350
     351        if ( modified ) {
     352            // ask for the confirmation to close the modified document
     353            char *t = newstrdupL( MSGS_WARNING );
     354            char *m = newstrdupL( MSGS_CLOSE_MODIFIED_DOCUMENT );
     355            ULONG response = WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, m, t,
     356                                            0, MB_YESNOCANCEL | MB_WARNING | MB_MOVEABLE );
     357            delete m;
     358            delete t;
     359            if ( response == MBID_CANCEL ) {
     360                return false;
     361            }
     362            if ( response == MBID_YES ) {
     363                if ( !Lucide::saveDocumentAs() )
     364                    return false;
     365            }
     366        }
    331367    }
    332368
     
    365401
    366402    WinInvalidateRect( hWndDocFrame, NULL, TRUE );
     403
     404    return true;
    367405}
    368406
     
    13171355}
    13181356
    1319 void DocumentViewer::showTextField( LuInputText *text, long page, PRECTL r )
     1357void DocumentViewer::showTextField( long page, long index, PRECTL r )
    13201358{
    13211359    // save the previous changes if any
     
    13231361        hideTextField();
    13241362
    1325     textField = text;
     1363    textField =
     1364        static_cast<LuInputText *>( inputFields[ page ].fields->_buffer[ index ] );
    13261365    textFieldPage = page;
     1366    textFieldIndex = index;
    13271367
    13281368    positionTextField( r );
     
    14151455            delete[] contents;
    14161456            delete[] str;
     1457            inputFields[ textFieldPage ].cache[ textFieldIndex ].modified = true;
    14171458        }
    14181459        textField = NULL;
     
    21332174                                        button->setState( ev, !state );
    21342175                                        WinInvalidateRect( hwnd, &r, FALSE );
     2176                                        entry.modified = true;
    21352177                                    }
    21362178                                    break;
     
    21382180                                case LuInputField_Text:
    21392181                                {
    2140                                     LuInputText *text = static_cast<LuInputText *>( field );
    2141                                     showTextField( text, pg, &r );
     2182                                    showTextField( pg, i, &r );
    21422183                                    break;
    21432184                                }
  • branches/kmk/Lucide/gui/docViewer.h

    r348 r351  
    6262        LuInputField_Type type;
    6363        bool supported;
     64        bool modified;
    6465    };
    6566
     
    8485
    8586        void setDocument( LuDocument *_doc );
    86         void close();
     87        bool close( bool force = false );
    8788        void goToPage( long page );
    8889        long getCurrentPage() { return currentpage; }  // Zero based
     
    146147        bool isRotated() { return ( (rotation==90) || (rotation==270) ); }
    147148        bool isContinuous() { return ( layout == Continuous ); };
    148         void showTextField( LuInputText *text, long page, PRECTL r = NULL );
     149        void showTextField( long page, long index, PRECTL r = NULL );
    149150        void positionTextField( PRECTL r = NULL );
    150151        void hideTextField( bool apply = true );
     
    166167        LuInputText *textField;
    167168        long textFieldPage;
     169        long textFieldIndex;
    168170        PFNWP oldFrameProc;
    169171        HWND hWndHscroll;
  • branches/kmk/Lucide/gui/lucide.cpp

    r334 r351  
    398398
    399399
    400 void Lucide::closeDocument()
     400bool Lucide::closeDocument( bool force )
    401401{
    402402    if ( doc != NULL ) {
    403         docViewer->close();
     403        if ( !docViewer->close( force ) && !force )
     404            return false;
    404405        delete doc;
    405406        doc = NULL;
     
    414415        thumbnailDataLen = 0;
    415416    }
     417
     418    return true;
    416419}
    417420
     
    437440void Lucide::loadDocument( const char *fn )
    438441{
    439     char *msg = newstrdupL( MSGS_NO_SUIT_PLUG );
    440 
    441442    // test if file supported and then close previous opened document
    442443    if ( pluginMan->createDocumentForFile( fn, true ) == NULL )
    443444    {
     445        char *msg = newstrdupL( MSGS_NO_SUIT_PLUG );
    444446        WinMessageBox( HWND_DESKTOP, hWndFrame, msg,
    445447                       NULL, 0, MB_OK | MB_ICONEXCLAMATION | MB_MOVEABLE );
     448        delete msg;
    446449    }
    447450    else
    448451    {
    449         closeDocument();
     452        if ( !closeDocument() )
     453            return;
    450454
    451455        doc = pluginMan->createDocumentForFile( fn, false );
    452456        if ( doc == NULL )
    453457        {
     458            char *msg = newstrdupL( MSGS_NO_SUIT_PLUG );
    454459            WinMessageBox( HWND_DESKTOP, hWndFrame, msg,
    455460                           NULL, 0, MB_OK | MB_ICONEXCLAMATION | MB_MOVEABLE );
     461            delete msg;
    456462        }
    457463        else
     
    578584        } // ( doc == NULL )
    579585    } // ( pluginMan->createDocumentForFile( fn, true ) == NULL )
    580     delete msg;
    581586
    582587    loadFileList();
     
    646651}
    647652
    648 void Lucide::saveDocumentAs()
    649 {
     653bool Lucide::saveDocumentAs()
     654{
     655    bool saved = false;
     656
    650657    char dirbuf[ CCHMAXPATH ];
    651658    PFILEDLG fd = new FILEDLG;
     
    677684        if ( doSave )
    678685        {
    679             if ( !doc->saveAs( ev, fd->szFullFile ) )
     686            if ( !( saved = doc->saveAs( ev, fd->szFullFile ) ) )
    680687            {
    681688                char *m = newstrdupL( MSGS_FILE_SAVE_ERROR );
     
    687694    }
    688695    delete fd;
     696
     697    return saved;
    689698}
    690699
     
    11961205        }
    11971206        break;
     1207
     1208        case WM_CLOSE:
     1209            if ( !Lucide::closeDocument() )
     1210                return (MRESULT)FALSE;
     1211        break;
    11981212    }
    11991213    return pOldSplProc( hwnd, msg, mp1, mp2 );
     
    12651279    WinSendMsg( hHorizSplitter, SBM_SETWINDOWS,
    12661280                MPFROMHWND( hVertSplitter ), MPFROMHWND( hToolBar ) );
    1267     // ãáâ ­®¢šâì 䚪ášà®¢ ­­ë© à §¬¥à €«ï âã«¡ à 
     1281    // ᅵᅵ⠭ᅵᅵᅵᅵᅵ 䚪ᅵ஢ᅵᅵᅵᅵ ࠧᅵᅵᅵ ᅵᅵᅵ ᅵ㫡ᅵᅵ
    12681282    WinSendMsg( hHorizSplitter, SBM_SETFIXEDSIZE,
    12691283                MPFROMSHORT( DEFAULT_PICTSIZE + TOOLBAR_HEIGHT_ADD ), MPVOID );
     
    12761290    recent  = new RecentFiles( hWndMenu );
    12771291
    1278     // ®ª § âì ®ª­® ¯à®£à ¬¬ë
     1292    // ᅵᅵᅵᅵᅵᅵᅵᅵ ᅵᅵᅵᅵ ᅵணࠬᅵᅵ
    12791293    if ( !PMRestoreWindowPos( NULL, appName, fwp, hWndFrame,
    12801294                              TRUE, TRUE, FALSE, FALSE, FALSE ) ) {
     
    13111325    recent->save();
    13121326
    1313     Lucide::closeDocument();
     1327    Lucide::closeDocument( true );
    13141328    delete docViewer;
    13151329    delete indexWin;
  • branches/kmk/Lucide/gui/lucide.h

    r309 r351  
    9898        static void newWindow( char *file, bool addDir );
    9999        static void openDocument();
    100         static void closeDocument();
     100        static bool closeDocument( bool force = false );
    101101        static void loadDocument( const char *fn );
    102         static void saveDocumentAs();
     102        static bool saveDocumentAs();
    103103        static void setDocument( LuDocument *_doc );
    104104        static void checkNavigationMenus();
  • branches/kmk/Lucide/gui/messages.cpp

    r238 r351  
    2222 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    2323 * in which case the provisions of the LGPL are applicable instead of those
    24  * above. If you wish to allow use of your version of this file only under the 
     24 * above. If you wish to allow use of your version of this file only under the
    2525 * terms of the LGPL, and not to allow others to use your version of this file
    2626 * under the terms of the CDDL, indicate your decision by deleting the
    2727 * provisions above and replace them with the notice and other provisions
    2828 * required by the LGPL. If you do not delete the provisions above, a recipient
    29  * may use your version of this file under the terms of any one of the CDDL 
     29 * may use your version of this file under the terms of any one of the CDDL
    3030 * or the LGPL.
    3131 *
     
    6767const char *MSGS_PAGE                     = "MSGS_PAGE";
    6868const char *MSGS_ERROR_STARTING_BROWSER   = "MSGS_ERROR_STARTING_BROWSER";
     69const char *MSGS_CLOSE_MODIFIED_DOCUMENT  = "MSGS_CLOSE_MODIFIED_DOCUMENT";
    6970
    7071const char *MSGS_LDERR                    = "MSGS_LDERR";
  • branches/kmk/Lucide/gui/messages.h

    r238 r351  
    2222 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    2323 * in which case the provisions of the LGPL are applicable instead of those
    24  * above. If you wish to allow use of your version of this file only under the 
     24 * above. If you wish to allow use of your version of this file only under the
    2525 * terms of the LGPL, and not to allow others to use your version of this file
    2626 * under the terms of the CDDL, indicate your decision by deleting the
    2727 * provisions above and replace them with the notice and other provisions
    2828 * required by the LGPL. If you do not delete the provisions above, a recipient
    29  * may use your version of this file under the terms of any one of the CDDL 
     29 * may use your version of this file under the terms of any one of the CDDL
    3030 * or the LGPL.
    3131 *
     
    6868extern const char *MSGS_PAGE;
    6969extern const char *MSGS_ERROR_STARTING_BROWSER;
     70extern const char *MSGS_CLOSE_MODIFIED_DOCUMENT;
    7071
    7172extern const char *MSGS_LDERR;
  • branches/kmk/Lucide/lng/Lucide.lng

    r267 r351  
    8686MSGS_PAGE=Page
    8787MSGS_ERROR_STARTING_BROWSER=Error starting browser!
     88MSGS_CLOSE_MODIFIED_DOCUMENT=Document has been modified. Save?
    8889
    8990MSGS_LDERR=File load error: %s!
Note: See TracChangeset for help on using the changeset viewer.